diff --git a/sfw/render_core/texture.cpp b/sfw/render_core/texture.cpp index 9715f60..f72f983 100644 --- a/sfw/render_core/texture.cpp +++ b/sfw/render_core/texture.cpp @@ -3,6 +3,18 @@ #include "memory.h" #include +#include "window.h" + +void Texture::set_as_render_target() { + glBindFramebuffer(GL_FRAMEBUFFER, _fbo); + glViewport(0, 0, _fbo_width, _fbo_height); +} + +void Texture::unset_render_target() { + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glViewport(0, 0, AppWindow::get_singleton()->get_width(), AppWindow::get_singleton()->get_height()); +} + void Texture::create_from_image(const Ref &img) { if (_image == img) { return; @@ -28,7 +40,6 @@ void Texture::create_from_image(const Ref &img) { Ref Texture::get_data() { ERR_FAIL_COND_V(!_texture, Ref()); ERR_FAIL_COND_V(_data_size == 0, Ref()); - //TODO Error if not render target //GLES @@ -256,8 +267,12 @@ Texture::Texture() { _data_size = 0; _texture_index = 0; _flags = 0; - _render_target = false; + _texture_format = Image::FORMAT_RGBA8; + + _fbo_width = 0; + _fbo_height = 0; + _fbo = 0; } Texture::~Texture() { diff --git a/sfw/render_core/texture.h b/sfw/render_core/texture.h index 09ea094..01db7db 100644 --- a/sfw/render_core/texture.h +++ b/sfw/render_core/texture.h @@ -17,9 +17,8 @@ public: return _texture; } - //TODO - //set_as_render_target() - //unset_render_target() + void set_as_render_target(); + void unset_render_target(); void create_from_image(const Ref &img); @@ -43,8 +42,12 @@ protected: int _texture_index; int _data_size; int _mipmaps; - bool _render_target; + GLuint _texture; + + int _fbo_width; + int _fbo_height; + GLuint _fbo; }; #endif // TEXTURE_H