Split Texture into Texture and RenderTexture.

This commit is contained in:
Relintai 2023-12-31 11:36:18 +01:00
parent feec0785bc
commit bf7856c9e4
2 changed files with 33 additions and 17 deletions

View File

@ -5,16 +5,6 @@
#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<Image> &img) {
if (_image == img) {
return;
@ -269,10 +259,6 @@ Texture::Texture() {
_flags = 0;
_texture_format = Image::FORMAT_RGBA8;
_fbo_width = 0;
_fbo_height = 0;
_fbo = 0;
}
Texture::~Texture() {
@ -280,3 +266,25 @@ Texture::~Texture() {
glDeleteTextures(1, &_texture);
}
}
//RenderTexture
void RenderTexture::set_as_render_target() {
glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
glViewport(0, 0, _fbo_width, _fbo_height);
}
void RenderTexture::unset_render_target() {
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, AppWindow::get_singleton()->get_width(), AppWindow::get_singleton()->get_height());
}
RenderTexture::RenderTexture() :
Texture() {
_fbo_width = 0;
_fbo_height = 0;
_fbo = 0;
}
RenderTexture::~RenderTexture() {
}

View File

@ -17,9 +17,6 @@ public:
return _texture;
}
void set_as_render_target();
void unset_render_target();
void create_from_image(const Ref<Image> &img);
Ref<Image> get_data();
@ -44,7 +41,18 @@ protected:
int _mipmaps;
GLuint _texture;
};
//TODO
class RenderTexture : public Texture {
public:
void set_as_render_target();
void unset_render_target();
RenderTexture();
virtual ~RenderTexture();
protected:
int _fbo_width;
int _fbo_height;
GLuint _fbo;