[nostalgia/core] Remove renderer funcions from Context friends

This commit is contained in:
Gary Talent 2022-02-03 20:48:58 -06:00
parent 8174d04b06
commit c7cd54ae52
6 changed files with 22 additions and 24 deletions

View File

@ -23,12 +23,6 @@ class Drawer {
virtual void draw(Context*) noexcept = 0; virtual void draw(Context*) noexcept = 0;
}; };
namespace renderer {
ox::Error init(Context *ctx) noexcept;
ox::Error shutdown(Context *ctx) noexcept;
ox::Error loadBgTexture(Context *ctx, int section, void *pixels, int w, int h) noexcept;
}
// User Input Output // User Input Output
class Context { class Context {
friend bool bgStatus(Context *ctx, unsigned bg) noexcept; friend bool bgStatus(Context *ctx, unsigned bg) noexcept;
@ -36,9 +30,10 @@ class Context {
friend int getScreenHeight(Context *ctx) noexcept; friend int getScreenHeight(Context *ctx) noexcept;
friend int getScreenWidth(Context *ctx) noexcept; friend int getScreenWidth(Context *ctx) noexcept;
friend ox::Error initGfx(Context *ctx) noexcept; friend ox::Error initGfx(Context *ctx) noexcept;
friend ox::Error renderer::init(Context *ctx) noexcept; friend ox::Error loadBgTileSheet(Context *ctx,
friend ox::Error renderer::loadBgTexture(Context *ctx, int section, void *pixels, int w, int h) noexcept; int section,
friend ox::Error renderer::shutdown(Context *ctx) noexcept; const ox::FileAddress &tilesheetPath,
const ox::FileAddress &palettePath) noexcept;
friend ox::Error run(Context *ctx) noexcept; friend ox::Error run(Context *ctx) noexcept;
friend ox::Error shutdown(Context *ctx) noexcept; friend ox::Error shutdown(Context *ctx) noexcept;
friend ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName) noexcept; friend ox::Result<ox::UniquePtr<Context>> init(ox::UniquePtr<ox::FileSystem> fs, const char *appName) noexcept;

View File

@ -45,7 +45,7 @@ ox::Error run(Context *ctx) noexcept {
glfwSwapBuffers(id->window); glfwSwapBuffers(id->window);
} }
// destroy GLFW window // destroy GLFW window
oxReturnError(renderer::shutdown(ctx)); oxReturnError(renderer::shutdown(ctx, ctx->rendererData<void>()));
glfwDestroyWindow(id->window); glfwDestroyWindow(id->window);
ctx->setWindowerData(nullptr); ctx->setWindowerData(nullptr);
delete id; delete id;

View File

@ -66,7 +66,10 @@ ox::Error initGfx(Context *ctx) noexcept {
//io.MouseDrawCursor = true; //io.MouseDrawCursor = true;
ImGui_ImplGlfw_InitForOpenGL(id->window, true); ImGui_ImplGlfw_InitForOpenGL(id->window, true);
} }
return renderer::init(ctx); void *rendererData = nullptr;
oxReturnError(renderer::init(ctx, &rendererData));
ctx->setRendererData(rendererData);
return OxError(0);
} }
void setWindowTitle(Context *ctx, const char *title) noexcept { void setWindowTitle(Context *ctx, const char *title) noexcept {

View File

@ -46,7 +46,7 @@ ox::Error loadBgTileSheet(Context *ctx,
pixels[i * 2 + 1] = toColor32(palette->colors[tilesheet->pixels[i] >> 4]); pixels[i * 2 + 1] = toColor32(palette->colors[tilesheet->pixels[i] >> 4]);
} }
} }
return renderer::loadBgTexture(ctx, section, pixels.data(), width, height); return renderer::loadBgTexture(ctx->rendererData<void>(), section, pixels.data(), width, height);
} }
void puts(Context *ctx, int column, int row, const char *str) noexcept { void puts(Context *ctx, int column, int row, const char *str) noexcept {

View File

@ -10,10 +10,10 @@
namespace nostalgia::core::renderer { namespace nostalgia::core::renderer {
ox::Error init(Context *ctx) noexcept; ox::Error init(Context *ctx, void **rendererData) noexcept;
ox::Error shutdown(Context *ctx) noexcept; ox::Error shutdown(Context *ctx, void *rendererData) noexcept;
ox::Error loadBgTexture(Context *ctx, int section, void *bytes, int w, int h) noexcept; ox::Error loadBgTexture(void *rendererData, int section, void *pixels, int w, int h) noexcept;
} }

View File

@ -181,12 +181,13 @@ static void drawBackgrounds(GlImplData *id) noexcept {
} }
} }
ox::Error init(Context *ctx) noexcept { ox::Error init(Context *ctx, void **rendererData) noexcept {
const auto id = new GlImplData;
ctx->setRendererData(id);
const auto vshad = ox::sfmt(bgvshad, glutils::GlslVersion); const auto vshad = ox::sfmt(bgvshad, glutils::GlslVersion);
const auto fshad = ox::sfmt(bgfshad, glutils::GlslVersion); const auto fshad = ox::sfmt(bgfshad, glutils::GlslVersion);
oxReturnError(glutils::buildShaderProgram(vshad.c_str(), fshad.c_str()).moveTo(&id->bgShader)); oxRequireM(bgShader, glutils::buildShaderProgram(vshad.c_str(), fshad.c_str()));
const auto id = new GlImplData;
*rendererData = id;
id->bgShader = std::move(bgShader);
for (auto &bg : id->backgrounds) { for (auto &bg : id->backgrounds) {
initBackgroundBufferset(ctx, id->bgShader, &bg); initBackgroundBufferset(ctx, id->bgShader, &bg);
} }
@ -194,16 +195,15 @@ ox::Error init(Context *ctx) noexcept {
return OxError(0); return OxError(0);
} }
ox::Error shutdown(Context *ctx) noexcept { ox::Error shutdown(Context*, void *rendererData) noexcept {
const auto id = ctx->rendererData<GlImplData>(); const auto id = reinterpret_cast<GlImplData*>(rendererData);
ctx->setRendererData(nullptr);
delete id; delete id;
return OxError(0); return OxError(0);
} }
ox::Error loadBgTexture(Context *ctx, int section, void *pixels, int w, int h) noexcept { ox::Error loadBgTexture(void *rendererData, int section, void *pixels, int w, int h) noexcept {
oxTracef("nostalgia::core::gfx::gl", "loadBgTexture: { section: {}, w: {}, h: {} }", section, w, h); oxTracef("nostalgia::core::gfx::gl", "loadBgTexture: { section: {}, w: {}, h: {} }", section, w, h);
const auto id = ctx->rendererData<GlImplData>(); const auto id = static_cast<GlImplData*>(rendererData);
auto &tex = id->backgrounds[static_cast<std::size_t>(section)].tex; auto &tex = id->backgrounds[static_cast<std::size_t>(section)].tex;
tex = loadTexture(w, h, pixels); tex = loadTexture(w, h, pixels);
return OxError(0); return OxError(0);