[keel,nostalgia,turbine] Change log channel delimiter from :: to .
This commit is contained in:
parent
ecc49a63b0
commit
540ed9b3f9
@ -107,7 +107,7 @@ static ox::Error doTransformations(
|
|||||||
// transformations need to be done after the copy to the new FS is complete
|
// transformations need to be done after the copy to the new FS is complete
|
||||||
static ox::Error transformClaw(keel::Context *ctx, ox::TypeStore *ts, ox::FileSystem *dest, ox::CRStringView path) noexcept {
|
static ox::Error transformClaw(keel::Context *ctx, ox::TypeStore *ts, ox::FileSystem *dest, ox::CRStringView path) noexcept {
|
||||||
// copy
|
// copy
|
||||||
oxTracef("pack::transformClaw", "path: {}", path);
|
oxTracef("pack.transformClaw", "path: {}", path);
|
||||||
oxRequire(fileList, dest->ls(path));
|
oxRequire(fileList, dest->ls(path));
|
||||||
for (const auto &name : fileList) {
|
for (const auto &name : fileList) {
|
||||||
const auto filePath = ox::sfmt("{}{}", path, name);
|
const auto filePath = ox::sfmt("{}{}", path, name);
|
||||||
|
@ -116,7 +116,7 @@ ox::Error preloadDir(
|
|||||||
ox::Preloader<PlatSpec> *pl,
|
ox::Preloader<PlatSpec> *pl,
|
||||||
ox::CRStringView path) noexcept {
|
ox::CRStringView path) noexcept {
|
||||||
// copy
|
// copy
|
||||||
oxTracef("pack::preload", "path: {}", path);
|
oxTracef("pack.preload", "path: {}", path);
|
||||||
oxRequire(fileList, romFs->ls(path));
|
oxRequire(fileList, romFs->ls(path));
|
||||||
for (const auto &name : fileList) {
|
for (const auto &name : fileList) {
|
||||||
const auto filePath = ox::sfmt("{}{}", path, name);
|
const auto filePath = ox::sfmt("{}{}", path, name);
|
||||||
|
@ -27,6 +27,8 @@ inline GlContext &glctx(Context &ctx) noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr auto Scale = 5;
|
||||||
|
|
||||||
namespace renderer {
|
namespace renderer {
|
||||||
|
|
||||||
Drawer::Drawer(Context &ctx) noexcept: m_ctx(ctx) {}
|
Drawer::Drawer(Context &ctx) noexcept: m_ctx(ctx) {}
|
||||||
@ -47,7 +49,7 @@ constexpr ox::StringView bgvshadTmpl = R"(
|
|||||||
gl_Position = vec4(
|
gl_Position = vec4(
|
||||||
vPosition.x * vXScale - xScaleInvert, vPosition.y,
|
vPosition.x * vXScale - xScaleInvert, vPosition.y,
|
||||||
0.0, 1.0);
|
0.0, 1.0);
|
||||||
fTexCoord = vTexCoord * vec2(1, vTileHeight);
|
fTexCoord = vTexCoord;
|
||||||
})";
|
})";
|
||||||
|
|
||||||
constexpr ox::StringView bgfshadTmpl = R"(
|
constexpr ox::StringView bgfshadTmpl = R"(
|
||||||
@ -55,10 +57,28 @@ constexpr ox::StringView bgfshadTmpl = R"(
|
|||||||
out vec4 outColor;
|
out vec4 outColor;
|
||||||
in vec2 fTexCoord;
|
in vec2 fTexCoord;
|
||||||
uniform sampler2D image;
|
uniform sampler2D image;
|
||||||
|
uniform vec2 fSrcImgSz;
|
||||||
uniform vec4 fPalette[256];
|
uniform vec4 fPalette[256];
|
||||||
|
vec2 pixelSz;
|
||||||
|
vec4 getColor(vec2 offset) {
|
||||||
|
vec2 p = fTexCoord + pixelSz * offset;
|
||||||
|
int idx = int(texture(image, p).rgb.r * 256);
|
||||||
|
return fPalette[idx];
|
||||||
|
}
|
||||||
void main() {
|
void main() {
|
||||||
int idx = int(texture(image, fTexCoord).rgb.r * 256);
|
pixelSz = vec2(1, 1) / (fSrcImgSz);
|
||||||
outColor = fPalette[idx];
|
vec2 pixelCoord = floor(fTexCoord / pixelSz) * pixelSz;
|
||||||
|
vec4 c0 = getColor(pixelCoord + pixelSz * vec2(0, 0));
|
||||||
|
vec4 c1 = getColor(pixelCoord + pixelSz * vec2(0.75, 0));
|
||||||
|
vec4 c2 = getColor(pixelCoord + pixelSz * vec2(0, 0.75));
|
||||||
|
vec4 c3 = getColor(pixelCoord + pixelSz * vec2(0.75, 0.75));
|
||||||
|
float u = fTexCoord.x - fTexCoord.x / pixelSz.x;
|
||||||
|
float v = fTexCoord.y - fTexCoord.y / pixelSz.y;
|
||||||
|
vec4 b0 = (1.0 - u) * c0 + u * c1;
|
||||||
|
vec4 b1 = (1.0 - u) * c2 + u * c3;
|
||||||
|
outColor = (1.0 - v) * b0 + u * b1;
|
||||||
|
outColor = fPalette[int(texture(image, fTexCoord).rgb.r * 256)];
|
||||||
|
//outColor = fPalette[int(texture(image, pixelCoord).rgb.r * 256)];
|
||||||
//outColor = vec4(0.0, 0.7, 1.0, 1.0);
|
//outColor = vec4(0.0, 0.7, 1.0, 1.0);
|
||||||
})";
|
})";
|
||||||
|
|
||||||
@ -118,11 +138,12 @@ static void setSpriteBufferObject(
|
|||||||
memcpy(ebo, elms.data(), sizeof(elms));
|
memcpy(ebo, elms.data(), sizeof(elms));
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTileBufferObject(
|
static void setTileBufferObject(
|
||||||
uint_t vi,
|
uint_t vi,
|
||||||
float x,
|
float x,
|
||||||
float y,
|
float y,
|
||||||
uint_t textureRow,
|
float textureYOffset,
|
||||||
|
float tileHeight,
|
||||||
float *vbo,
|
float *vbo,
|
||||||
GLuint *ebo) noexcept {
|
GLuint *ebo) noexcept {
|
||||||
// don't worry, this memcpy gets optimized to something much more ideal
|
// don't worry, this memcpy gets optimized to something much more ideal
|
||||||
@ -132,12 +153,11 @@ void setTileBufferObject(
|
|||||||
y *= -ymod;
|
y *= -ymod;
|
||||||
x -= 1.0f;
|
x -= 1.0f;
|
||||||
y += 1.0f - ymod;
|
y += 1.0f - ymod;
|
||||||
const auto textureRowf = static_cast<float>(textureRow);
|
|
||||||
const ox::Array<float, BgVertexVboLength> vertices {
|
const ox::Array<float, BgVertexVboLength> vertices {
|
||||||
x, y, 0, textureRowf + 1, // bottom left
|
x, y, 0, tileHeight + textureYOffset, // bottom left
|
||||||
x + xmod, y, 1, textureRowf + 1, // bottom right
|
x + xmod, y, 1, tileHeight + textureYOffset, // bottom right
|
||||||
x + xmod, y + ymod, 1, textureRowf + 0, // top right
|
x + xmod, y + ymod, 1, 0 + textureYOffset, // top right
|
||||||
x, y + ymod, 0, textureRowf + 0, // top left
|
x, y + ymod, 0, 0 + textureYOffset, // top left
|
||||||
};
|
};
|
||||||
memcpy(vbo, vertices.data(), sizeof(vertices));
|
memcpy(vbo, vertices.data(), sizeof(vertices));
|
||||||
const ox::Array<GLuint, BgVertexEboLength> elms {
|
const ox::Array<GLuint, BgVertexEboLength> elms {
|
||||||
@ -166,6 +186,7 @@ static void initBackgroundBufferObjects(glutils::BufferSet &bg) noexcept {
|
|||||||
static_cast<float>(x),
|
static_cast<float>(x),
|
||||||
static_cast<float>(y),
|
static_cast<float>(y),
|
||||||
0,
|
0,
|
||||||
|
0,
|
||||||
vbo,
|
vbo,
|
||||||
ebo);
|
ebo);
|
||||||
}
|
}
|
||||||
@ -231,8 +252,8 @@ static glutils::GLTexture loadTexture(
|
|||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, tex.id);
|
glBindTexture(GL_TEXTURE_2D, tex.id);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width, tex.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.width, tex.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
return tex;
|
return tex;
|
||||||
@ -253,6 +274,7 @@ static void drawBackgrounds(
|
|||||||
ox::Size const&renderSz) noexcept {
|
ox::Size const&renderSz) noexcept {
|
||||||
// load background shader and its uniforms
|
// load background shader and its uniforms
|
||||||
glUseProgram(gctx.bgShader);
|
glUseProgram(gctx.bgShader);
|
||||||
|
const auto uniformSrcImgSz = glGetUniformLocation(gctx.bgShader, "fSrcImgSz");
|
||||||
const auto uniformXScale = static_cast<GLint>(glGetUniformLocation(gctx.bgShader, "vXScale"));
|
const auto uniformXScale = static_cast<GLint>(glGetUniformLocation(gctx.bgShader, "vXScale"));
|
||||||
const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(gctx.bgShader, "vTileHeight"));
|
const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(gctx.bgShader, "vTileHeight"));
|
||||||
const auto [wi, hi] = renderSz;
|
const auto [wi, hi] = renderSz;
|
||||||
@ -262,8 +284,12 @@ static void drawBackgrounds(
|
|||||||
for (const auto &bg : gctx.backgrounds) {
|
for (const auto &bg : gctx.backgrounds) {
|
||||||
if (bg.enabled) {
|
if (bg.enabled) {
|
||||||
auto &cbb = gctx.cbbs[bg.cbbIdx];
|
auto &cbb = gctx.cbbs[bg.cbbIdx];
|
||||||
const auto tileRows = cbb.tex.height / TileHeight;
|
const auto tileRows = cbb.tex.height / (TileHeight * Scale);
|
||||||
glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(tileRows));
|
glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(tileRows));
|
||||||
|
glUniform2f(
|
||||||
|
uniformSrcImgSz,
|
||||||
|
static_cast<float>(cbb.tex.width),
|
||||||
|
static_cast<float>(cbb.tex.height));
|
||||||
drawBackground(cbb);
|
drawBackground(cbb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -272,8 +298,8 @@ static void drawBackgrounds(
|
|||||||
static void drawSprites(GlContext &gctx, ox::Size const&renderSz) noexcept {
|
static void drawSprites(GlContext &gctx, ox::Size const&renderSz) noexcept {
|
||||||
glUseProgram(gctx.spriteShader);
|
glUseProgram(gctx.spriteShader);
|
||||||
auto &sb = gctx.spriteBlocks;
|
auto &sb = gctx.spriteBlocks;
|
||||||
const auto uniformXScale = static_cast<GLint>(glGetUniformLocation(gctx.bgShader, "vXScale"));
|
const auto uniformXScale = glGetUniformLocation(gctx.bgShader, "vXScale");
|
||||||
const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(gctx.spriteShader, "vTileHeight"));
|
const auto uniformTileHeight = glGetUniformLocation(gctx.spriteShader, "vTileHeight");
|
||||||
const auto [wi, hi] = renderSz;
|
const auto [wi, hi] = renderSz;
|
||||||
const auto wf = static_cast<float>(wi);
|
const auto wf = static_cast<float>(wi);
|
||||||
const auto hf = static_cast<float>(hi);
|
const auto hf = static_cast<float>(hi);
|
||||||
@ -285,7 +311,7 @@ static void drawSprites(GlContext &gctx, ox::Size const&renderSz) noexcept {
|
|||||||
glutils::sendVbo(sb);
|
glutils::sendVbo(sb);
|
||||||
}
|
}
|
||||||
// set vTileHeight uniform
|
// set vTileHeight uniform
|
||||||
const auto tileRows = sb.tex.height / TileHeight;
|
const auto tileRows = sb.tex.height / (TileHeight * Scale);
|
||||||
glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(tileRows));
|
glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(tileRows));
|
||||||
// draw
|
// draw
|
||||||
glBindTexture(GL_TEXTURE_2D, sb.tex);
|
glBindTexture(GL_TEXTURE_2D, sb.tex);
|
||||||
@ -326,7 +352,7 @@ static void loadBgTexture(
|
|||||||
const void *pixels,
|
const void *pixels,
|
||||||
int w,
|
int w,
|
||||||
int h) noexcept {
|
int h) noexcept {
|
||||||
oxTracef("nostalgia::core::gfx::gl", "loadBgTexture: { cbbIdx: {}, w: {}, h: {} }", cbbIdx, w, h);
|
oxTracef("nostalgia.core.gfx.gl", "loadBgTexture: { cbbIdx: {}, w: {}, h: {} }", cbbIdx, w, h);
|
||||||
gctx.cbbs[cbbIdx].tex = loadTexture(w, h, pixels);
|
gctx.cbbs[cbbIdx].tex = loadTexture(w, h, pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,7 +361,7 @@ static void loadSpriteTexture(
|
|||||||
const void *pixels,
|
const void *pixels,
|
||||||
int w,
|
int w,
|
||||||
int h) noexcept {
|
int h) noexcept {
|
||||||
oxTracef("nostalgia::core::gfx::gl", "loadSpriteTexture: { w: {}, h: {} }", w, h);
|
oxTracef("nostalgia.core.gfx.gl", "loadSpriteTexture: { w: {}, h: {} }", w, h);
|
||||||
gctx.spriteBlocks.tex = loadTexture(w, h, pixels);
|
gctx.spriteBlocks.tex = loadTexture(w, h, pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,6 +399,10 @@ struct TileSheetData {
|
|||||||
ox::Vector<uint32_t> pixels;
|
ox::Vector<uint32_t> pixels;
|
||||||
int width = 0;
|
int width = 0;
|
||||||
int height = 0;
|
int height = 0;
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr ox::Size size() const noexcept {
|
||||||
|
return {width, height};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static ox::Result<TileSheetData> loadTileSheet(
|
static ox::Result<TileSheetData> loadTileSheet(
|
||||||
@ -408,7 +438,13 @@ ox::Error loadBgTileSheet(
|
|||||||
auto &kctx = gctx.turbineCtx.keelCtx;
|
auto &kctx = gctx.turbineCtx.keelCtx;
|
||||||
oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr));
|
oxRequire(tilesheet, readObj<CompactTileSheet>(&kctx, tilesheetAddr));
|
||||||
oxRequire(palette, readObj<Palette>(&kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
oxRequire(palette, readObj<Palette>(&kctx, paletteAddr ? paletteAddr : tilesheet->defaultPalette));
|
||||||
oxRequire(tsd, loadTileSheet(*ctx, *tilesheet));
|
oxRequire(tsd, loadTileSheet(*ctx, *tilesheet).to([](TileSheetData const&t) -> TileSheetData {
|
||||||
|
return {
|
||||||
|
.pixels = resizeTileSheetData(t.pixels, t.size(), Scale),
|
||||||
|
.width = t.width * Scale,
|
||||||
|
.height = t.height * Scale,
|
||||||
|
};
|
||||||
|
}));
|
||||||
renderer::loadBgTexture(gctx, cbb, tsd.pixels.data(), tsd.width, tsd.height);
|
renderer::loadBgTexture(gctx, cbb, tsd.pixels.data(), tsd.width, tsd.height);
|
||||||
renderer::loadBgPalette(gctx, *palette);
|
renderer::loadBgPalette(gctx, *palette);
|
||||||
return {};
|
return {};
|
||||||
@ -537,8 +573,15 @@ void setSprite(
|
|||||||
const auto cidx = idx + i;
|
const auto cidx = idx + i;
|
||||||
auto vbo = &gctx.spriteBlocks.vertices[cidx * renderer::SpriteVertexVboLength];
|
auto vbo = &gctx.spriteBlocks.vertices[cidx * renderer::SpriteVertexVboLength];
|
||||||
auto ebo = &gctx.spriteBlocks.elements[cidx * renderer::SpriteVertexEboLength];
|
auto ebo = &gctx.spriteBlocks.elements[cidx * renderer::SpriteVertexEboLength];
|
||||||
renderer::setSpriteBufferObject(cidx * renderer::SpriteVertexVboRows, 1,
|
renderer::setSpriteBufferObject(
|
||||||
fX, fY, tileIdx + i, flipX, vbo, ebo);
|
cidx * renderer::SpriteVertexVboRows,
|
||||||
|
1,
|
||||||
|
fX,
|
||||||
|
fY,
|
||||||
|
tileIdx + i,
|
||||||
|
flipX,
|
||||||
|
vbo,
|
||||||
|
ebo);
|
||||||
++i;
|
++i;
|
||||||
};
|
};
|
||||||
if (!flipX) {
|
if (!flipX) {
|
||||||
@ -564,7 +607,7 @@ void setTile(
|
|||||||
int row,
|
int row,
|
||||||
uint8_t tile) noexcept {
|
uint8_t tile) noexcept {
|
||||||
oxTracef(
|
oxTracef(
|
||||||
"nostalgia::core::gfx::setTile",
|
"nostalgia.core.gfx.setTile",
|
||||||
"bgIdx: {}, column: {}, row: {}, tile: {}",
|
"bgIdx: {}, column: {}, row: {}, tile: {}",
|
||||||
bgIdx, column, row, tile);
|
bgIdx, column, row, tile);
|
||||||
auto &gctx = glctx(*ctx);
|
auto &gctx = glctx(*ctx);
|
||||||
@ -573,13 +616,16 @@ void setTile(
|
|||||||
const auto x = static_cast<uint_t>(column);
|
const auto x = static_cast<uint_t>(column);
|
||||||
const auto i = renderer::bgVertexRow(x, y);
|
const auto i = renderer::bgVertexRow(x, y);
|
||||||
auto &bg = gctx.cbbs[z];
|
auto &bg = gctx.cbbs[z];
|
||||||
auto vbo = &bg.vertices[i * renderer::BgVertexVboLength];
|
const auto vbo = &bg.vertices[i * renderer::BgVertexVboLength];
|
||||||
auto ebo = &bg.elements[i * renderer::BgVertexEboLength];
|
const auto ebo = &bg.elements[i * renderer::BgVertexEboLength];
|
||||||
|
const auto tileHeight = static_cast<float>(TileHeight * Scale) / static_cast<float>(bg.tex.height);
|
||||||
|
const auto tileOffset = tileHeight * static_cast<float>(tile);
|
||||||
renderer::setTileBufferObject(
|
renderer::setTileBufferObject(
|
||||||
static_cast<uint_t>(i * renderer::BgVertexVboRows),
|
static_cast<uint_t>(i * renderer::BgVertexVboRows),
|
||||||
static_cast<float>(x),
|
static_cast<float>(x),
|
||||||
static_cast<float>(y),
|
static_cast<float>(y),
|
||||||
tile,
|
tileOffset,
|
||||||
|
tileHeight,
|
||||||
vbo,
|
vbo,
|
||||||
ebo);
|
ebo);
|
||||||
bg.updated = true;
|
bg.updated = true;
|
||||||
|
@ -56,7 +56,7 @@ static void tickFps(GlfwContext &gctx, uint64_t nowMs) noexcept {
|
|||||||
if constexpr(config::GlFpsPrint) {
|
if constexpr(config::GlFpsPrint) {
|
||||||
oxOutf("FPS: {}\n", fps);
|
oxOutf("FPS: {}\n", fps);
|
||||||
}
|
}
|
||||||
oxTracef("turbine::fps", "FPS: {}", fps);
|
oxTracef("turbine.fps", "FPS: {}", fps);
|
||||||
gctx.prevFpsCheckTime = nowMs;
|
gctx.prevFpsCheckTime = nowMs;
|
||||||
gctx.draws = 0;
|
gctx.draws = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user