From c6a43e16be0827df938922166268f8dcbef06e65 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 13 Jan 2024 15:34:51 +0100 Subject: [PATCH] Don't mess with render state in AppWindow. --- sfw/game_scene.cpp | 15 ++++++++--- sfw/render_core/window.cpp | 51 +++----------------------------------- sfw/render_core/window.h | 2 ++ 3 files changed, 18 insertions(+), 50 deletions(-) diff --git a/sfw/game_scene.cpp b/sfw/game_scene.cpp index 2158682..d604634 100644 --- a/sfw/game_scene.cpp +++ b/sfw/game_scene.cpp @@ -7,6 +7,7 @@ #include "render_core/keyboard.h" #include "render_core/mesh_utils.h" #include "render_immediate/renderer.h" +#include "render_core/window.h" //#include "render_core/font.h" void GameScene::input_event(const Ref &event) { @@ -79,6 +80,17 @@ void GameScene::update(float delta) { } void GameScene::render() { + glEnable(GL_BLEND); + glEnable(GL_DEPTH_TEST); + + AppWindow::get_singleton()->reset_viewport(); + + glClearColor(0.0f, 0.0f, 0.0f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + + + static float rotmi = 0; if (render_type == 0) { @@ -269,9 +281,6 @@ void GameScene::render_immediate() { } void GameScene::render_obj() { - glClearColor(0.0f, 0.0f, 0.0f, 1.0f); - glClear(GL_COLOR_BUFFER_BIT); - //static float rot = 0; //Transform t = camera->get_camera_transform(); //t.basis = Basis(Vector3(0, 1, 0), rot); diff --git a/sfw/render_core/window.cpp b/sfw/render_core/window.cpp index 7e4e926..f2c73e0 100644 --- a/sfw/render_core/window.cpp +++ b/sfw/render_core/window.cpp @@ -250,31 +250,7 @@ void AppWindow::glNewFrame() { AppWindow::get_singleton()->width = w; AppWindow::get_singleton()->height = h; - // blending defaults - glEnable(GL_BLEND); - - // culling defaults - // glEnable(GL_CULL_FACE); - // glCullFace(GL_BACK); - // glFrontFace(GL_CCW); - - // depth-testing defaults - glEnable(GL_DEPTH_TEST); - // glDepthFunc(GL_LESS); - - // depth-writing defaults - // glDepthMask(GL_TRUE); - - // seamless cubemaps - // glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); - glViewport(0, 0, width, height); - - // GLfloat bgColor[4]; glGetFloatv(GL_COLOR_CLEAR_VALUE, bgColor); - glClearColor(winbgcolor.r, winbgcolor.g, winbgcolor.b, has_transparent() ? 0 : winbgcolor.a); // @transparent - //glClearColor(0.15,0.15,0.15,1); - //glClearColor( clearColor.r, clearColor.g, clearColor.b, clearColor.a ); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } bool AppWindow::create_from_handle(void *handle, bool full_Screen, float canvas_scale, unsigned int flags, float window_scale) { @@ -510,32 +486,9 @@ int AppWindow::frame_begin() { } void AppWindow::frame_end() { - // flush batching systems that need to be rendered before frame swapping. order matters. - { - /* - font_goto(0, 0); - touch_flush(); - sprite_flush(); - - // flush all debugdraw calls before swap - dd_ontop = 0; - ddraw_flush(); - glClear(GL_DEPTH_BUFFER_BIT); - dd_ontop = 1; - ddraw_flush(); - - ui_render(); - */ - } } void AppWindow::frame_swap() { - // glFinish(); - /* -#ifndef __EMSCRIPTEN__ - vsync(hz); -#endif - */ glfwSwapBuffers(_window); // emscripten_webgl_commit_frame(); } @@ -544,6 +497,10 @@ void AppWindow::shutdown() { loop_exit(); // finish emscripten loop automatically } +void AppWindow::reset_viewport() { + glViewport(0, 0, width, height); +} + int AppWindow::swap() { // end frame if (frame_count > 0) { diff --git a/sfw/render_core/window.h b/sfw/render_core/window.h index 342ab37..58f850c 100644 --- a/sfw/render_core/window.h +++ b/sfw/render_core/window.h @@ -107,6 +107,8 @@ public: void shutdown(); + void reset_viewport(); + Vector2 dpi(); enum CURSOR_SHAPES {