[nostalgia/core/userland] Add bg control functions for GL
This commit is contained in:
parent
ba91de90fc
commit
e36b123b33
@ -31,6 +31,7 @@ ox::Result<T> readObj(Context *ctx, const ox::FileAddress &file) {
|
|||||||
|
|
||||||
ox::Error initConsole(Context *ctx) {
|
ox::Error initConsole(Context *ctx) {
|
||||||
constexpr auto TilesheetAddr = "/TileSheets/Charset.ng";
|
constexpr auto TilesheetAddr = "/TileSheets/Charset.ng";
|
||||||
|
setBgStatus(ctx, 0b0001);
|
||||||
return loadBgTileSheet(ctx, 0, TilesheetAddr);
|
return loadBgTileSheet(ctx, 0, TilesheetAddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@ constexpr auto BgVertexVboLength = BgVertexVboRows * BgVertexVboRowLength;
|
|||||||
constexpr auto BgVertexEboLength = 6;
|
constexpr auto BgVertexEboLength = 6;
|
||||||
|
|
||||||
struct Background: public Bufferset {
|
struct Background: public Bufferset {
|
||||||
|
bool enabled = false;
|
||||||
bool updated = false;
|
bool updated = false;
|
||||||
std::array<float, TileCount * BgVertexVboLength> bgVertices;
|
std::array<float, TileCount * BgVertexVboLength> bgVertices;
|
||||||
std::array<GLuint, TileCount * BgVertexEboLength> bgEbos;
|
std::array<GLuint, TileCount * BgVertexEboLength> bgEbos;
|
||||||
@ -185,6 +186,32 @@ ox::Error loadBgTexture(Context *ctx, int section, void *pixels, int w, int h) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t bgStatus(Context *ctx) {
|
||||||
|
const auto &id = ctx->rendererData<renderer::GlImplData>();
|
||||||
|
uint8_t out = 0;
|
||||||
|
for (unsigned i = 0; i < id->backgrounds.size(); ++i) {
|
||||||
|
out |= id->backgrounds[i].enabled << i;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBgStatus(Context *ctx, uint32_t status) {
|
||||||
|
const auto &id = ctx->rendererData<renderer::GlImplData>();
|
||||||
|
for (unsigned i = 0; i < id->backgrounds.size(); ++i) {
|
||||||
|
id->backgrounds[i].enabled = (status >> i) & 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bgStatus(Context *ctx, unsigned bg) {
|
||||||
|
const auto &id = ctx->rendererData<renderer::GlImplData>();
|
||||||
|
return id->backgrounds[bg].enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setBgStatus(Context *ctx, unsigned bg, bool status) {
|
||||||
|
const auto &id = ctx->rendererData<renderer::GlImplData>();
|
||||||
|
id->backgrounds[bg].enabled = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void draw(Context *ctx) {
|
void draw(Context *ctx) {
|
||||||
const auto id = ctx->rendererData<renderer::GlImplData>();
|
const auto id = ctx->rendererData<renderer::GlImplData>();
|
||||||
@ -208,6 +235,7 @@ void draw(Context *ctx) {
|
|||||||
glUseProgram(id->bgShader);
|
glUseProgram(id->bgShader);
|
||||||
const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(id->bgShader, "vTileHeight"));
|
const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(id->bgShader, "vTileHeight"));
|
||||||
for (auto &bg : id->backgrounds) {
|
for (auto &bg : id->backgrounds) {
|
||||||
|
if (bg.enabled) {
|
||||||
glBindVertexArray(bg.vao);
|
glBindVertexArray(bg.vao);
|
||||||
if (bg.updated) {
|
if (bg.updated) {
|
||||||
bg.updated = false;
|
bg.updated = false;
|
||||||
@ -217,6 +245,7 @@ void draw(Context *ctx) {
|
|||||||
glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(bg.tex.height / 8));
|
glUniform1f(uniformTileHeight, 1.0f / static_cast<float>(bg.tex.height / 8));
|
||||||
glDrawElements(GL_TRIANGLES, bg.bgEbos.size(), GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, bg.bgEbos.size(), GL_UNSIGNED_INT, 0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearTileLayer(Context *ctx, int layer) {
|
void clearTileLayer(Context *ctx, int layer) {
|
||||||
|
Loading…
Reference in New Issue
Block a user