diff --git a/sfw/render_core/app_window.cpp b/sfw/render_core/app_window.cpp index ccd93d0..05bbdb5 100644 --- a/sfw/render_core/app_window.cpp +++ b/sfw/render_core/app_window.cpp @@ -39,6 +39,7 @@ #include "core/vector4.h" #include "render_core/application.h" #include "render_core/input.h" +#include "render_core/render_state.h" //--STRIP /* @@ -425,7 +426,9 @@ bool AppWindow::create_from_handle(void *handle, bool full_Screen, float canvas_ width = get_width(); height = get_height(); - + + RenderState::window_update_render_rect_size(width, height); + // cursor(flags & WINDOW_NO_MOUSE ? false : true); glfwSetDropCallback(_window, drop_callback); diff --git a/sfw/render_core/frame_buffer.cpp b/sfw/render_core/frame_buffer.cpp index cb16250..970544e 100644 --- a/sfw/render_core/frame_buffer.cpp +++ b/sfw/render_core/frame_buffer.cpp @@ -5,6 +5,7 @@ #include #include "render_core/app_window.h" +#include "render_core/render_state.h" //--STRIP int FrameBuffer::get_texture_flags() const { @@ -285,11 +286,15 @@ void FrameBuffer::blit_depth_to(const uint32_t p_destination_framebuffer, const } void FrameBuffer::set_as_viewport() { - glViewport(0, 0, _fbo_width, _fbo_height); + RenderState::current_framebuffer = Ref(this); + RenderState::render_rect = Rect2i(0, 0, _fbo_width, _fbo_height); + RenderState::apply_render_rect(); } void FrameBuffer::reset_as_viewport() { - glViewport(0, 0, AppWindow::get_singleton()->get_width(), AppWindow::get_singleton()->get_height()); + RenderState::current_framebuffer.unref(); + RenderState::render_rect = Rect2i(0, 0, AppWindow::get_singleton()->get_width(), AppWindow::get_singleton()->get_height()); + RenderState::apply_render_rect(); } float FrameBuffer::get_aspect() const { diff --git a/sfw/render_core/render_state.cpp b/sfw/render_core/render_state.cpp index 2a94803..55f88c0 100644 --- a/sfw/render_core/render_state.cpp +++ b/sfw/render_core/render_state.cpp @@ -1,5 +1,6 @@ //--STRIP #include "render_core/render_state.h" +#include "render_core/frame_buffer.h" //--STRIP Transform RenderState::camera_transform_3d; @@ -8,3 +9,24 @@ Projection RenderState::projection_matrix_3d; Transform2D RenderState::model_view_matrix_2d; Transform RenderState::projection_matrix_2d; + +Rect2i RenderState::render_rect; + +Ref RenderState::current_framebuffer; + +void RenderState::apply_render_rect() { + glViewport(render_rect.position.x, render_rect.position.y, render_rect.size.x, render_rect.size.y); +} + +void RenderState::window_update_render_rect_size(const int p_width, const int p_height) { + if (current_framebuffer.is_valid()) { + return; + } + + render_rect = Rect2i(0, 0, p_width, p_height); +} + +RenderState::RenderState() { +} +RenderState::~RenderState() { +} diff --git a/sfw/render_core/render_state.h b/sfw/render_core/render_state.h index 9515a79..e61baa1 100644 --- a/sfw/render_core/render_state.h +++ b/sfw/render_core/render_state.h @@ -5,12 +5,16 @@ //--STRIP #include "core/projection.h" +#include "core/rect2i.h" #include "core/transform.h" -#include "core/vector3.h" #include "core/transform_2d.h" #include "core/vector2.h" +#include "core/vector3.h" +#include "object/reference.h" //--STRIP +class FrameBuffer; + class RenderState { public: static Transform camera_transform_3d; @@ -20,7 +24,17 @@ public: static Transform2D model_view_matrix_2d; static Transform projection_matrix_2d; - //TODO should probably add the current shader here, and active material etc. + static Rect2i render_rect; + static Ref current_framebuffer; + + //TODO should probably add the current shader here, and active material etc. + + static void apply_render_rect(); + + static void window_update_render_rect_size(const int p_width, const int p_height); + + RenderState(); + ~RenderState(); }; //--STRIP