[nostalgia] Make drawMainView render size seting come from function param
This commit is contained in:
parent
022f148701
commit
db3f29d52f
@ -19,7 +19,6 @@ endif()
|
|||||||
|
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
NostalgiaCore PUBLIC
|
NostalgiaCore PUBLIC
|
||||||
Keel
|
|
||||||
Turbine
|
Turbine
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,10 +19,8 @@ class Context;
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace nostalgia::core::gl {
|
namespace nostalgia::core::gl {
|
||||||
|
void drawMainView(core::Context*, ox::Size const&) noexcept;
|
||||||
void drawMainView(core::Context*) noexcept;
|
void drawMainView(core::Context*) noexcept;
|
||||||
void setRenderSize(core::Context*, int width, int height) noexcept;
|
|
||||||
ox::Size getRenderSize(core::Context*) noexcept;
|
|
||||||
void clearRenderSize(core::Context *ctx) noexcept;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace nostalgia::core {
|
namespace nostalgia::core {
|
||||||
@ -57,10 +55,8 @@ class Context {
|
|||||||
unsigned spriteSize,
|
unsigned spriteSize,
|
||||||
unsigned flipX) noexcept;
|
unsigned flipX) noexcept;
|
||||||
friend void hideSprite(Context *ctx, unsigned idx) noexcept;
|
friend void hideSprite(Context *ctx, unsigned idx) noexcept;
|
||||||
|
friend void gl::drawMainView(core::Context*, ox::Size const&) noexcept;
|
||||||
friend void gl::drawMainView(core::Context*) noexcept;
|
friend void gl::drawMainView(core::Context*) noexcept;
|
||||||
friend void gl::setRenderSize(core::Context*, int width, int height) noexcept;
|
|
||||||
friend ox::Size gl::getRenderSize(core::Context*) noexcept;
|
|
||||||
friend void gl::clearRenderSize(core::Context *ctx) noexcept;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
turbine::Context *turbineCtx = nullptr;
|
turbine::Context *turbineCtx = nullptr;
|
||||||
|
@ -227,12 +227,12 @@ static void drawBackground(CBB *cbb) noexcept {
|
|||||||
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(cbb->elements.size()), GL_UNSIGNED_INT, nullptr);
|
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(cbb->elements.size()), GL_UNSIGNED_INT, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drawBackgrounds(GlContext *gctx) noexcept {
|
static void drawBackgrounds(GlContext *gctx, 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 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] = gl::getRenderSize(gctx);
|
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);
|
||||||
glUniform1f(uniformXScale, hf / wf);
|
glUniform1f(uniformXScale, hf / wf);
|
||||||
@ -246,12 +246,12 @@ static void drawBackgrounds(GlContext *gctx) noexcept {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void drawSprites(GlContext *gctx) 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 = static_cast<GLint>(glGetUniformLocation(gctx->bgShader, "vXScale"));
|
||||||
const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(gctx->spriteShader, "vTileHeight"));
|
const auto uniformTileHeight = static_cast<GLint>(glGetUniformLocation(gctx->spriteShader, "vTileHeight"));
|
||||||
const auto [wi, hi] = gl::getRenderSize(gctx);
|
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);
|
||||||
glUniform1f(uniformXScale, hf / wf);
|
glUniform1f(uniformXScale, hf / wf);
|
||||||
@ -537,34 +537,19 @@ void setTile(Context *ctx, unsigned bgIdx, int column, int row, uint8_t tile) no
|
|||||||
|
|
||||||
namespace gl {
|
namespace gl {
|
||||||
|
|
||||||
void drawMainView(core::Context *ctx) noexcept {
|
void drawMainView(core::Context *ctx, ox::Size const&renderSz) noexcept {
|
||||||
// clear screen
|
// clear screen
|
||||||
glClearColor(0, 0, 0, 1);
|
glClearColor(0, 0, 0, 1);
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
auto &gctx = static_cast<GlContext&>(*ctx);
|
||||||
renderer::drawBackgrounds(gctx);
|
renderer::drawBackgrounds(&gctx, renderSz);
|
||||||
if (gctx->spriteBlocks.tex) {
|
if (gctx.spriteBlocks.tex) {
|
||||||
renderer::drawSprites(gctx);
|
renderer::drawSprites(&gctx, renderSz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setRenderSize(core::Context *ctx, int width, int height) noexcept {
|
void drawMainView(core::Context *ctx) noexcept {
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
drawMainView(ctx, getScreenSize(*ctx->turbineCtx));
|
||||||
gctx->renderSize.emplace(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearRenderSize(core::Context *ctx) noexcept {
|
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
|
||||||
gctx->renderSize.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
ox::Size getRenderSize(core::Context *ctx) noexcept {
|
|
||||||
const auto gctx = static_cast<GlContext*>(ctx);
|
|
||||||
if (gctx->renderSize.has_value()) {
|
|
||||||
return gctx->renderSize.value();
|
|
||||||
} else {
|
|
||||||
return turbine::getScreenSize(*ctx->turbineCtx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,7 @@ void SceneEditorView::draw(int width, int height) noexcept {
|
|||||||
glutils::resizeInitFrameBuffer(&m_frameBuffer, width, height);
|
glutils::resizeInitFrameBuffer(&m_frameBuffer, width, height);
|
||||||
}
|
}
|
||||||
glutils::bind(m_frameBuffer);
|
glutils::bind(m_frameBuffer);
|
||||||
core::gl::setRenderSize(m_cctx.get(), width, height);
|
core::gl::drawMainView(m_cctx.get(), {width, height});
|
||||||
core::gl::drawMainView(m_cctx.get());
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user