Compare commits
No commits in common. "1cc3549d008fe12f63d8782ffff6fda1ce56a8b4" and "17cb40c0ec5b6d60eee3aa844af46ce906125d06" have entirely different histories.
1cc3549d00
...
17cb40c0ec
@ -7,7 +7,6 @@
|
|||||||
#include <ox/std/array.hpp>
|
#include <ox/std/array.hpp>
|
||||||
#include <ox/std/fmt.hpp>
|
#include <ox/std/fmt.hpp>
|
||||||
|
|
||||||
#include <nostalgia/geo/vec.hpp>
|
|
||||||
#include <nostalgia/glutils/glutils.hpp>
|
#include <nostalgia/glutils/glutils.hpp>
|
||||||
|
|
||||||
#include <nostalgia/core/context.hpp>
|
#include <nostalgia/core/context.hpp>
|
||||||
@ -28,7 +27,7 @@ constexpr uint64_t BgVertexVboRows = 4;
|
|||||||
constexpr uint64_t BgVertexVboRowLength = 4;
|
constexpr uint64_t BgVertexVboRowLength = 4;
|
||||||
constexpr uint64_t BgVertexVboLength = BgVertexVboRows * BgVertexVboRowLength;
|
constexpr uint64_t BgVertexVboLength = BgVertexVboRows * BgVertexVboRowLength;
|
||||||
constexpr uint64_t BgVertexEboLength = 6;
|
constexpr uint64_t BgVertexEboLength = 6;
|
||||||
constexpr uint64_t SpriteVertexVboRows = 256;
|
constexpr uint64_t SpriteVertexVboRows = 4;
|
||||||
constexpr uint64_t SpriteVertexVboRowLength = 5;
|
constexpr uint64_t SpriteVertexVboRowLength = 5;
|
||||||
constexpr uint64_t SpriteVertexVboLength = SpriteVertexVboRows * SpriteVertexVboRowLength;
|
constexpr uint64_t SpriteVertexVboLength = SpriteVertexVboRows * SpriteVertexVboRowLength;
|
||||||
constexpr uint64_t SpriteVertexEboLength = 6;
|
constexpr uint64_t SpriteVertexEboLength = 6;
|
||||||
@ -104,7 +103,17 @@ constexpr ox::StringView spritevshadTmpl = R"(
|
|||||||
fTexCoord = vTexCoord * vec2(1, vTileHeight) * vec2(vEnabled, vEnabled);
|
fTexCoord = vTexCoord * vec2(1, vTileHeight) * vec2(vEnabled, vEnabled);
|
||||||
})";
|
})";
|
||||||
|
|
||||||
constexpr ox::StringView spritefshadTmpl = bgfshadTmpl;
|
constexpr ox::StringView spritefshadTmpl = R"(
|
||||||
|
{}
|
||||||
|
out vec4 outColor;
|
||||||
|
in vec2 fTexCoord;
|
||||||
|
uniform sampler2D image;
|
||||||
|
uniform vec4 fPalette[256];
|
||||||
|
void main() {
|
||||||
|
int idx = int(texture(image, fTexCoord).rgb.r * 256);
|
||||||
|
outColor = fPalette[idx];
|
||||||
|
//outColor = vec4(0.0, 0.7, 1.0, 1.0);
|
||||||
|
})";
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static constexpr auto bgVertexRow(unsigned x, unsigned y) noexcept {
|
static constexpr auto bgVertexRow(unsigned x, unsigned y) noexcept {
|
||||||
@ -261,9 +270,9 @@ static void tickFps(GlImplData *id) noexcept {
|
|||||||
const auto duration = static_cast<double>(now - id->prevFpsCheckTime) / 1000.0;
|
const auto duration = static_cast<double>(now - id->prevFpsCheckTime) / 1000.0;
|
||||||
const auto fps = static_cast<int>(static_cast<double>(id->draws) / duration);
|
const auto fps = static_cast<int>(static_cast<double>(id->draws) / duration);
|
||||||
if constexpr(config::UserlandFpsPrint) {
|
if constexpr(config::UserlandFpsPrint) {
|
||||||
oxOutf("FPS: {}\n", fps);
|
oxInfof("FPS: {}", fps);
|
||||||
}
|
}
|
||||||
oxTracef("nostalgia::core::gfx::fps", "FPS: {}", fps);
|
oxTracef("nostalgia::core::gfx::gl::fps", "FPS: {}", fps);
|
||||||
id->prevFpsCheckTime = now;
|
id->prevFpsCheckTime = now;
|
||||||
id->draws = 0;
|
id->draws = 0;
|
||||||
}
|
}
|
||||||
@ -423,9 +432,7 @@ void draw(Context *ctx) noexcept {
|
|||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
// render
|
// render
|
||||||
renderer::drawBackgrounds(id);
|
renderer::drawBackgrounds(id);
|
||||||
if (id->spriteBlocks.tex) {
|
renderer::drawSprites(id);
|
||||||
renderer::drawSprites(id);
|
|
||||||
}
|
|
||||||
for (const auto cd : ctx->drawers) {
|
for (const auto cd : ctx->drawers) {
|
||||||
cd->draw(ctx);
|
cd->draw(ctx);
|
||||||
}
|
}
|
||||||
@ -459,59 +466,17 @@ void setSprite(Context *ctx,
|
|||||||
[[maybe_unused]] unsigned spriteShape,
|
[[maybe_unused]] unsigned spriteShape,
|
||||||
[[maybe_unused]] unsigned spriteSize,
|
[[maybe_unused]] unsigned spriteSize,
|
||||||
unsigned flipX) noexcept {
|
unsigned flipX) noexcept {
|
||||||
//oxTracef("nostalgia::core::gfx::gl", "setSprite(ctx, {}, {}, {}, {}, {}, {}, {})",
|
const auto uX = static_cast<unsigned>(x) % 255;
|
||||||
// idx, x, y, tileIdx, spriteShape, spriteSize, flipX);
|
const auto uY = static_cast<unsigned>(y) % 127;
|
||||||
// Tonc Table 8.4
|
|
||||||
static constexpr ox::Array<geo::Vec<unsigned>, 12> dimensions{
|
|
||||||
// col 0
|
|
||||||
{1, 1}, // 0, 0
|
|
||||||
{2, 2}, // 0, 1
|
|
||||||
{4, 4}, // 0, 2
|
|
||||||
{8, 8}, // 0, 3
|
|
||||||
// col 1
|
|
||||||
{2, 1}, // 1, 0
|
|
||||||
{4, 1}, // 1, 1
|
|
||||||
{4, 2}, // 1, 2
|
|
||||||
{8, 4}, // 1, 3
|
|
||||||
// col 2
|
|
||||||
{1, 1}, // 2, 0
|
|
||||||
{1, 4}, // 2, 1
|
|
||||||
{2, 4}, // 2, 2
|
|
||||||
{4, 8}, // 2, 3
|
|
||||||
};
|
|
||||||
const auto dim = dimensions[(spriteShape << 2) | spriteSize];
|
|
||||||
const auto uX = static_cast<int>(x) % 255;
|
|
||||||
const auto uY = static_cast<int>(y + 8) % 255 - 8;
|
|
||||||
auto &id = *ctx->rendererData<renderer::GlImplData>();
|
auto &id = *ctx->rendererData<renderer::GlImplData>();
|
||||||
auto i = 0u;
|
auto vbo = &id.spriteBlocks.vertices[idx * renderer::SpriteVertexVboLength];
|
||||||
const auto set = [&](int xIt, int yIt) {
|
auto ebo = &id.spriteBlocks.elements[idx * renderer::SpriteVertexEboLength];
|
||||||
const auto fX = static_cast<float>(uX + xIt * 8) / 8;
|
renderer::setSpriteBufferObject(ctx, idx * renderer::SpriteVertexVboRows, 1,
|
||||||
const auto fY = static_cast<float>(uY + yIt * 8) / 8;
|
static_cast<float>(uX) / 8, static_cast<float>(uY) / 8, tileIdx, flipX, vbo, ebo);
|
||||||
const auto cidx = idx + i;
|
|
||||||
auto vbo = &id.spriteBlocks.vertices[cidx * renderer::SpriteVertexVboLength];
|
|
||||||
auto ebo = &id.spriteBlocks.elements[cidx * renderer::SpriteVertexEboLength];
|
|
||||||
renderer::setSpriteBufferObject(ctx, cidx * renderer::SpriteVertexVboRows, 1,
|
|
||||||
fX, fY, tileIdx + i, flipX, vbo, ebo);
|
|
||||||
++i;
|
|
||||||
};
|
|
||||||
if (!flipX) {
|
|
||||||
for (auto yIt = 0; yIt < static_cast<int>(dim.y); ++yIt) {
|
|
||||||
for (auto xIt = 0u; xIt < dim.x; ++xIt) {
|
|
||||||
set(static_cast<int>(xIt), static_cast<int>(yIt));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (auto yIt = 0u; yIt < dim.y; ++yIt) {
|
|
||||||
for (auto xIt = dim.x - 1; xIt < ~0u; --xIt) {
|
|
||||||
set(static_cast<int>(xIt), static_cast<int>(yIt));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
id.spriteBlocks.updated = true;
|
id.spriteBlocks.updated = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept {
|
void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) noexcept {
|
||||||
//oxTracef("nostalgia::core::gfx::gl", "setTile(ctx, {}, {}, {}, {})", bgIdx, column, row, tile);
|
|
||||||
const auto id = ctx->rendererData<renderer::GlImplData>();
|
const auto id = ctx->rendererData<renderer::GlImplData>();
|
||||||
const auto z = static_cast<unsigned>(bgIdx);
|
const auto z = static_cast<unsigned>(bgIdx);
|
||||||
const auto y = static_cast<unsigned>(row);
|
const auto y = static_cast<unsigned>(row);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user