#include <gl_framebuffer.h>
Public Member Functions | |
void | attach (const Texture *texture) |
void | bind () |
Bind our object. | |
void | checkErrors (const std::string &where) |
void | detach (const Texture *texture) |
void | drawBuffer (const Texture *RenderTarget) |
const std::string & | getClassName () const |
Returns name of class of our object. | |
void | getData (Data &data, const Texture *from) |
const std::string & | getObjectName () const |
Returns name of our object. | |
void | getSpecificParameter (const std::string &ParameterName, void *ParameterValue) |
Method for obtaining some specific parameters, such as texture specific params, and so on. | |
void | initialize () |
bool | isActive () const |
bool | isLocked () const |
returns state of object. | |
void | unbind () |
Unbind our object. | |
~GLFrameBuffer () | |
Protected Member Functions | |
void | addSpecificParameter (const std::string &ParameterName, void *ParameterValue, size_t Size) |
void | lock () |
void | unlock () |
Protected Attributes | |
GraphicCore * | mDefaultGraphicCore |
Private Types | |
typedef std::vector< const Texture * > | AttachmentList |
Private Member Functions | |
GLint | getFirstFreeAttachment () const |
GLint | getIndexByTexture (const Texture *texture) const |
GLint | getIndexByTextureName (const std::string &TextureName) const |
GLFrameBuffer (const std::string &FrameBufferName, GLint MaxNumberOfAttachments, GraphicCore *DefaultGLGraphicCore) | |
Private Attributes | |
AttachmentList | mAttachmentList |
GLenum | mGLFrameBufferFormat |
GLint | mGLFrameBufferHeight |
GLuint | mGLFrameBufferID |
GLenum | mGLFrameBufferType |
GLint | mGLFrameBufferWidth |
GLint | mMaxNumberOfAttachment |
Friends | |
class | GLGraphicCore |
Definition at line 112 of file gl_framebuffer.h.
typedef std::vector<const Texture *> gpucalc::GLFrameBuffer::AttachmentList [private] |
Definition at line 178 of file gl_framebuffer.h.
gpucalc::GLFrameBuffer::~GLFrameBuffer | ( | ) | [inline] |
Definition at line 122 of file gl_framebuffer.h.
00123 { 00124 glDeleteFramebuffersEXT(1, &mGLFrameBufferID); 00125 LogManager::getSingleton().logMessage(this, "FrameBuffer ID deleted for OpenGL memory.", LML_Normal); 00126 }
gpucalc::GLFrameBuffer::GLFrameBuffer | ( | const std::string & | FrameBufferName, | |
GLint | MaxNumberOfAttachments, | |||
GraphicCore * | DefaultGLGraphicCore | |||
) | [inline, private] |
Definition at line 184 of file gl_framebuffer.h.
00184 : 00185 Object(_GLFrameBufferClassName, FrameBufferName), FrameBuffer(_GLFrameBufferClassName, FrameBufferName, DefaultGLGraphicCore), 00186 mGLFrameBufferID(0), mGLFrameBufferWidth(0), mGLFrameBufferHeight(0), mGLFrameBufferFormat(0), mGLFrameBufferType(0), 00187 mMaxNumberOfAttachment(MaxNumberOfAttachments), mAttachmentList(MaxNumberOfAttachments) 00188 { 00189 }
void gpucalc::Object::addSpecificParameter | ( | const std::string & | ParameterName, | |
void * | ParameterValue, | |||
size_t | Size | |||
) | [inline, protected, inherited] |
Definition at line 254 of file object.h.
00255 { 00256 SpecificParametersMap::iterator i = mSpecificParameters.find(ParameterName); 00257 if (i != mSpecificParameters.end()) 00258 { 00259 mSpecificParameters.erase(i); 00260 } 00261 mSpecificParameters[ParameterName] = Any(ParameterValue, Size); 00262 }
void gpucalc::GLFrameBuffer::attach | ( | const Texture * | texture | ) | [virtual] |
Attach Texture to FrameBuffer.
texture | - Texture for rendering into it, or reading data. |
Implements gpucalc::FrameBuffer.
Definition at line 96 of file gl_framebuffer.cpp.
00097 { 00098 GLint Index = getFirstFreeAttachment(); 00099 mAttachmentList[Index] = texture; 00100 00101 00102 const GLTexture * gl_texture = dynamic_cast<const GLTexture *>(texture); 00103 00104 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + Index, 00105 gl_texture->getGLTextureTarget(), gl_texture->getGLTextureID(), 0); 00106 00107 this->mGLFrameBufferWidth = gl_texture->getSizeX(); 00108 this->mGLFrameBufferHeight = gl_texture->getSizeY(); 00109 this->mGLFrameBufferFormat = gl_texture->getGLTextureFormat(); 00110 this->mGLFrameBufferType = gl_texture->getGLTextureType(); 00111 00112 this->checkErrors("GLFrameBuffer::attach()"); 00113 mDefaultGraphicCore->checkErrors("GLFrameBuffer::attach()"); 00114 }
void gpucalc::FrameBuffer::bind | ( | ) | [inline, virtual, inherited] |
Bind our object.
For example, set in some active state (Texture, Shader and so on)
Implements gpucalc::Bindable.
Definition at line 107 of file framebuffer.h.
00108 { 00109 mDefaultGraphicCore->bind(this); 00110 }
void gpucalc::GLFrameBuffer::checkErrors | ( | const std::string & | where | ) |
Definition at line 168 of file gl_framebuffer.cpp.
00169 { 00170 GLenum status; 00171 status = (GLenum) glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); 00172 switch (status) 00173 { 00174 case GL_FRAMEBUFFER_COMPLETE_EXT: 00175 return; 00176 00177 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT: 00178 Except<ERR_RENDERINGAPI_ERROR>(this, "Framebuffer incomplete, incomplete attachment.", where, __FILE__, __LINE__); 00179 return; 00180 00181 case GL_FRAMEBUFFER_UNSUPPORTED_EXT: 00182 Except<ERR_RENDERINGAPI_ERROR>(this, "Unsupported framebuffer format.", where, __FILE__, __LINE__); 00183 return; 00184 00185 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT: 00186 Except<ERR_RENDERINGAPI_ERROR>(this, "Framebuffer incomplete, missing attachment.", where, __FILE__, __LINE__); 00187 return; 00188 00189 case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT: 00190 Except<ERR_RENDERINGAPI_ERROR>(this, "Framebuffer incomplete, attached images must have same dimensions.", where, __FILE__, __LINE__); 00191 return; 00192 00193 case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT: 00194 Except<ERR_RENDERINGAPI_ERROR>(this, "Framebuffer incomplete, attached images must have same format.", where, __FILE__, __LINE__); 00195 return; 00196 00197 case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT: 00198 Except<ERR_RENDERINGAPI_ERROR>(this, "Framebuffer incomplete, missing draw buffer.", where, __FILE__, __LINE__); 00199 return; 00200 00201 case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT: 00202 Except<ERR_RENDERINGAPI_ERROR>(this, "Framebuffer incomplete, missing read buffer.", where, __FILE__, __LINE__); 00203 return; 00204 00205 default: 00206 Except<ERR_RENDERINGAPI_ERROR>(this, "Unknown error.", where, __FILE__, __LINE__); 00207 } 00208 }
void gpucalc::GLFrameBuffer::detach | ( | const Texture * | texture | ) | [virtual] |
Detach Texture from FrameBuffer.
texture | - Texture for rendering into it, or reading data. |
Implements gpucalc::FrameBuffer.
Definition at line 117 of file gl_framebuffer.cpp.
00118 { 00119 GLint Index = 0; 00120 for ( ; Index < mMaxNumberOfAttachment; ++Index) 00121 { 00122 if (mAttachmentList[Index] == texture) 00123 { 00124 mAttachmentList[Index] = 0; 00125 } 00126 } 00127 if (Index < mMaxNumberOfAttachment) 00128 { 00129 glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + Index, 00130 dynamic_cast<const GLTexture *>(texture)->getGLTextureTarget(), 0, 0); 00131 } 00132 }
void gpucalc::GLFrameBuffer::drawBuffer | ( | const Texture * | RenderTarget | ) | [virtual] |
Set render destination.
RenderTarget | - texture for rendering into it. |
Implements gpucalc::FrameBuffer.
Definition at line 135 of file gl_framebuffer.cpp.
00136 { 00138 00139 LogManager::getSingleton().logMessage(this, "Starting rendering into texture(s)...", LML_Trivial); 00140 00141 GLint Index = getIndexByTexture(RenderTarget); 00142 if (Index == mMaxNumberOfAttachment) 00143 { 00144 attach(RenderTarget); 00145 } 00146 Index = getIndexByTexture(RenderTarget); 00147 00148 glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + Index); 00149 this->checkErrors("GLFrameBuffer::drawBuffer"); 00150 mDefaultGraphicCore->checkErrors("GLFrameBuffer::drawBuffer"); 00151 }
const std::string& gpucalc::Object::getClassName | ( | ) | const [inline, inherited] |
Returns name of class of our object.
Definition at line 92 of file object.h.
00093 { 00094 return mClassName; 00095 }
get results from GPU side to CPU side
to | - contains pointer to data in CPU-side memory and other useful members. | |
from | - rendering target. |
Implements gpucalc::FrameBuffer.
Definition at line 154 of file gl_framebuffer.cpp.
00155 { 00156 LogManager::getSingleton().logMessage(this, "Reading data from framebuffer...", LML_Trivial); 00157 00158 GLint Index = getIndexByTexture(from); 00159 glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + Index); 00160 glReadPixels(0, 0, this->mGLFrameBufferWidth, this->mGLFrameBufferHeight, 00161 this->mGLFrameBufferFormat, this->mGLFrameBufferType, to.pointer()); 00162 00163 Application::getSingleton().getDefaultGraphicCore()->checkErrors("GLFrameBuffer::getDataFromRenderedTexture"); 00164 this->checkErrors("GLFrameBuffer::getDataFromRenderedTexture"); 00165 }
GLint gpucalc::GLFrameBuffer::getFirstFreeAttachment | ( | ) | const [private] |
Definition at line 52 of file gl_framebuffer.cpp.
00053 { 00054 for (GLint i = 0; i < mMaxNumberOfAttachment; ++i) 00055 { 00056 if (mAttachmentList[i] == 0) 00057 { 00058 return i; 00059 } 00060 } 00061 00062 Except<ERR_ITEM_NOT_FOUND>(this, "this framebuffer does not have any free attachment point.", "GLFrameBuffer::getFirstFreeAttachment()", __FILE__, __LINE__); 00063 return mMaxNumberOfAttachment; 00064 }
GLint gpucalc::GLFrameBuffer::getIndexByTexture | ( | const Texture * | texture | ) | const [private] |
Definition at line 67 of file gl_framebuffer.cpp.
00068 { 00069 for (GLint i = 0; i < mMaxNumberOfAttachment; ++i) 00070 { 00071 if (mAttachmentList[i] == texture) 00072 { 00073 return i; 00074 } 00075 } 00076 return mMaxNumberOfAttachment; 00077 }
GLint gpucalc::GLFrameBuffer::getIndexByTextureName | ( | const std::string & | TextureName | ) | const [private] |
Definition at line 80 of file gl_framebuffer.cpp.
00081 { 00082 for (GLint i = 0; i < mMaxNumberOfAttachment; ++i) 00083 { 00084 if (mAttachmentList[i] != 0) 00085 { 00086 if (mAttachmentList[i]->getObjectName() == TextureName) 00087 { 00088 return i; 00089 } 00090 } 00091 } 00092 return mMaxNumberOfAttachment; 00093 }
const std::string& gpucalc::Object::getObjectName | ( | ) | const [inline, inherited] |
Returns name of our object.
Definition at line 101 of file object.h.
00102 { 00103 return mObjectName; 00104 }
void gpucalc::Object::getSpecificParameter | ( | const std::string & | ParameterName, | |
void * | ParameterValue | |||
) | [inline, inherited] |
Method for obtaining some specific parameters, such as texture specific params, and so on.
ParameterName | - name of parameter, usually it similar to specific method of some object (for example, GLTextureID) | |
ParameterValue | - contain value of named parameter, it must be allocated and have sufficient size. |
Definition at line 128 of file object.h.
00129 { 00130 SpecificParametersMap::iterator i = mSpecificParameters.find(ParameterName); 00131 if (i != mSpecificParameters.end()) 00132 { 00133 i->second.copyValue(ParameterValue); 00134 } 00135 else 00136 { 00137 Except<ERR_ITEM_NOT_FOUND>(this, "Parameter \"" + ParameterName + "\" does not exists.", "Object::getSpecificParameter()", __FILE__, __LINE__); 00138 } 00139 }
void gpucalc::GLFrameBuffer::initialize | ( | ) | [virtual] |
Implements gpucalc::FrameBuffer.
Definition at line 45 of file gl_framebuffer.cpp.
00046 { 00047 glGenFramebuffersEXT(1, &mGLFrameBufferID); 00048 LogManager::getSingleton().logMessage(this, "Successfully initialized.", LML_Trivial); 00049 }
bool gpucalc::FrameBuffer::isActive | ( | ) | const [inline, virtual, inherited] |
Implements gpucalc::Bindable.
Definition at line 119 of file framebuffer.h.
00120 { 00121 return (this == mDefaultGraphicCore->getActiveFrameBuffer()); 00122 }
bool gpucalc::Object::isLocked | ( | ) | const [inline, inherited] |
void gpucalc::Object::lock | ( | ) | [inline, protected, inherited] |
void gpucalc::FrameBuffer::unbind | ( | ) | [inline, virtual, inherited] |
Unbind our object.
For example, set in some inactive state (Texture, Shader and so on)
Implements gpucalc::Bindable.
Definition at line 113 of file framebuffer.h.
00114 { 00115 mDefaultGraphicCore->unbind(this); 00116 }
void gpucalc::Object::unlock | ( | ) | [inline, protected, inherited] |
friend class GLGraphicCore [friend] |
Definition at line 118 of file gl_framebuffer.h.
Definition at line 181 of file gl_framebuffer.h.
GraphicCore* gpucalc::FrameBuffer::mDefaultGraphicCore [protected, inherited] |
Definition at line 125 of file framebuffer.h.
GLenum gpucalc::GLFrameBuffer::mGLFrameBufferFormat [private] |
Definition at line 169 of file gl_framebuffer.h.
GLint gpucalc::GLFrameBuffer::mGLFrameBufferHeight [private] |
Definition at line 166 of file gl_framebuffer.h.
GLuint gpucalc::GLFrameBuffer::mGLFrameBufferID [private] |
Definition at line 160 of file gl_framebuffer.h.
GLenum gpucalc::GLFrameBuffer::mGLFrameBufferType [private] |
Definition at line 172 of file gl_framebuffer.h.
GLint gpucalc::GLFrameBuffer::mGLFrameBufferWidth [private] |
Definition at line 163 of file gl_framebuffer.h.
GLint gpucalc::GLFrameBuffer::mMaxNumberOfAttachment [private] |
Definition at line 175 of file gl_framebuffer.h.