GRAPHICS: Inherit FrameBuffer from Texture

This commit is contained in:
Dries Harnie 2015-03-05 18:04:54 +01:00
parent 3bbdc2ea06
commit bc80a12978
5 changed files with 9 additions and 40 deletions

View File

@ -611,7 +611,7 @@ void SurfaceSdlGraphicsManager::drawFramebufferOpenGL() {
glColor4f(1.0, 1.0, 1.0, 1.0);
glBindTexture(GL_TEXTURE_2D, _frameBuffer->getColorTextureName());
glBindTexture(GL_TEXTURE_2D, _frameBuffer->getTextureName());
glBegin(GL_QUADS);
glTexCoord2f(0, texcropY);
glVertex2f(offsetX, offsetY);
@ -667,7 +667,7 @@ void SurfaceSdlGraphicsManager::drawOverlayOpenGLShaders() {
}
void SurfaceSdlGraphicsManager::drawFramebufferOpenGLShaders() {
glBindTexture(GL_TEXTURE_2D, _frameBuffer->getColorTextureName());
glBindTexture(GL_TEXTURE_2D, _frameBuffer->getTextureName());
_boxShader->use();
float texcropX = _frameBuffer->getWidth() / float(_frameBuffer->getTexWidth());

View File

@ -98,17 +98,6 @@ static void grabFramebufferObjectPointers() {
}
#endif // defined(SDL_BACKEND) && !defined(USE_OPENGL_SHADERS)
template<class T>
static T nextHigher2(T k) {
if (k == 0)
return 1;
--k;
for (uint i = 1; i < sizeof(T) * 8; i <<= 1)
k = k | k >> i;
return k + 1;
}
static bool usePackedBuffer() {
@ -122,8 +111,7 @@ static bool usePackedBuffer() {
}
FrameBuffer::FrameBuffer(uint width, uint height) :
_managedTexture(true), _width(width), _height(height),
_texWidth(nextHigher2(width)), _texHeight(nextHigher2(height)) {
Texture(width, height) {
#ifdef SDL_BACKEND
if (!Graphics::isExtensionSupported("GL_EXT_framebuffer_object")) {
error("GL_EXT_framebuffer_object extension is not supported!");
@ -132,28 +120,18 @@ FrameBuffer::FrameBuffer(uint width, uint height) :
#if defined(SDL_BACKEND) && !defined(USE_GLEW)
grabFramebufferObjectPointers();
#endif
glGenTextures(1, &_colorTexture);
glBindTexture(GL_TEXTURE_2D, _colorTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _texWidth, _texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
init();
}
FrameBuffer::FrameBuffer(GLuint texture_name, uint width, uint height, uint texture_width, uint texture_height) :
_managedTexture(false), _colorTexture(texture_name), _width(width), _height(height),
_texWidth(texture_width), _texHeight(texture_height) {
Texture(texture_name, width, height, texture_width, texture_height) {
init();
}
FrameBuffer::~FrameBuffer() {
glDeleteRenderbuffers(2, _renderBuffers);
glDeleteFramebuffers(1, &_frameBuffer);
if (_managedTexture)
glDeleteTextures(1, &_colorTexture);
}
void FrameBuffer::init() {
@ -161,7 +139,7 @@ void FrameBuffer::init() {
glGenRenderbuffers(2, _renderBuffers);
glBindFramebuffer(GL_FRAMEBUFFER, _frameBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _colorTexture, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0);
if (usePackedBuffer()) {
glBindRenderbuffer(GL_RENDERBUFFER, _renderBuffers[0]);

View File

@ -24,10 +24,11 @@
#define GRAPHICS_FRAMEBUFFER_H
#include "graphics/opengles2/system_headers.h"
#include "graphics/opengles2/texture.h"
namespace Graphics {
class FrameBuffer {
class FrameBuffer : public Texture {
public:
FrameBuffer(uint width, uint height);
FrameBuffer(GLuint texture_name, uint width, uint height, uint texture_width, uint texture_height);
@ -43,20 +44,10 @@ public:
void detach();
#endif
GLuint getColorTextureName() const { return _colorTexture; }
uint getWidth() const { return _width; }
uint getHeight() const { return _height; }
uint getTexWidth() const { return _texWidth; }
uint getTexHeight() const { return _texHeight; }
private:
void init();
bool _managedTexture;
GLuint _colorTexture;
GLuint _renderBuffers[2];
GLuint _frameBuffer;
uint _width, _height;
uint _texWidth, _texHeight;
};
}

View File

@ -41,7 +41,7 @@ static T nextHigher2(T k) {
return k + 1;
}
Texture::Texture(const Surface& srf) :
Texture::Texture(const Surface &srf) :
_managedTexture(true), _width(srf.w), _height(srf.h),
_texWidth(nextHigher2(_width)), _texHeight(nextHigher2(_height)) {
glGenTextures(1, &_texture);

View File

@ -31,7 +31,7 @@ namespace Graphics {
class Texture {
public:
Texture(const Surface& srf);
Texture(const Surface &srf);
Texture(uint width, uint height);
Texture(GLuint texture_name, uint width, uint height, uint texture_width, uint texture_height);
~Texture();