00001 #include "GLFrameTextureBuffer.h"
00002
00003 #include <QDebug>
00004
00005 GLFrameTextureBuffer::GLFrameTextureBuffer()
00006 {
00007 texture = 0;
00008 buffer = 0;
00009 }
00010
00011 GLuint GLFrameTextureBuffer::getBuffer()
00012 {
00013 return buffer;
00014 }
00015
00016 GLuint GLFrameTextureBuffer::getTexture()
00017 {
00018 return texture;
00019 }
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 void GLFrameTextureBuffer::create(GLuint width, GLuint height, GLuint textureColorType, GLuint filterType)
00032 {
00033 free();
00034
00035 GLenum glError;
00036
00037
00038
00039
00040
00041 GLint cs2DTexture, csBuffer;
00042
00043 glGetIntegerv(GL_TEXTURE_BINDING_2D, &cs2DTexture);
00044 glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &csBuffer);
00045
00046 glGenTextures(1, &texture);
00047 glBindTexture(GL_TEXTURE_2D, texture);
00048 glTexImage2D(GL_TEXTURE_2D, 0, textureColorType, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
00049
00050 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filterType);
00051 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filterType);
00052
00053
00054
00055 glError = glGetError();
00056 if(glError != GL_NO_ERROR)
00057 {
00058 qDebug() << "create FrameTextureBuffer error / generate texture: " << (char*)gluErrorString(glError);
00059 }
00060
00061 glGenFramebuffersEXT(1, &buffer);
00062 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, buffer);
00063
00064 glError = glGetError();
00065 if(glError != GL_NO_ERROR)
00066 {
00067 qDebug() << "create FrameTextureBuffer error / generate buffer: " << (char*)gluErrorString(glError);
00068 }
00069
00070 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, texture, 0);
00071
00072 glError = glGetError();
00073 if(glError != GL_NO_ERROR)
00074 {
00075 qDebug() << "create FrameTextureBuffer error / attach: " << (char*)gluErrorString(glError);
00076 }
00077
00078
00079 glBindTexture(GL_TEXTURE_2D, cs2DTexture);
00080 glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, csBuffer);
00081
00082 glError = glGetError();
00083 if(glError != GL_NO_ERROR)
00084 {
00085 qDebug() << "create FrameTextureBuffer error / unbind: " << (char*)gluErrorString(glError);
00086 }
00087 }
00088
00089 void GLFrameTextureBuffer::free()
00090 {
00091 if(buffer != 0)
00092 {
00093 glDeleteFramebuffersEXT(1, &buffer);
00094 buffer = 0;
00095 }
00096 if(texture != 0)
00097 {
00098 glDeleteTextures(1, &texture);
00099 texture = 0;
00100 }
00101
00102 GLenum glError;
00103
00104 glError = glGetError();
00105 if(glError != GL_NO_ERROR)
00106 {
00107 qDebug() << "free FrameTextureBuffer error: " << (char*)gluErrorString(glError);
00108 }
00109 }