Просмотр исходного кода

Added a couple methods to FrameBuffer for querying render target info.

Steve Grenier 13 лет назад
Родитель
Сommit
33c732e775
2 измененных файлов с 33 добавлено и 2 удалено
  1. 18 2
      gameplay/src/FrameBuffer.cpp
  2. 15 0
      gameplay/src/FrameBuffer.h

+ 18 - 2
gameplay/src/FrameBuffer.cpp

@@ -14,7 +14,7 @@ FrameBuffer* FrameBuffer::_currentFrameBuffer = NULL;
 
 FrameBuffer::FrameBuffer(const char* id, unsigned int width, unsigned int height, FrameBufferHandle handle) :
     _id(id ? id : ""), _width(width), _height(height), _handle(handle), 
-    _renderTargets(NULL), _depthStencilTarget(NULL)
+    _renderTargets(NULL), _renderTargetCount(0), _depthStencilTarget(NULL)
 {
 }
 
@@ -162,7 +162,11 @@ void FrameBuffer::setRenderTarget(RenderTarget* target, unsigned int index)
         return;
 
     // Release our reference to the current RenderTarget at this index.
-    SAFE_RELEASE(_renderTargets[index]);
+    if (_renderTargets[index])
+    {
+        SAFE_RELEASE(_renderTargets[index]);
+        --_renderTargetCount;
+    }
 
     _renderTargets[index] = target;
 
@@ -170,6 +174,8 @@ void FrameBuffer::setRenderTarget(RenderTarget* target, unsigned int index)
     {
         GP_ASSERT( _renderTargets[index]->getTexture() );
 
+        ++_renderTargetCount;
+
         // This FrameBuffer now references the RenderTarget.
         target->addRef();
 
@@ -199,6 +205,11 @@ RenderTarget* FrameBuffer::getRenderTarget(unsigned int index) const
     return NULL;
 }
 
+unsigned int FrameBuffer::getRenderTargetCount() const
+{
+    return _renderTargetCount;
+}
+
 void FrameBuffer::setDepthStencilTarget(DepthStencilTarget* target)
 {
     if (_depthStencilTarget == target)
@@ -245,6 +256,11 @@ DepthStencilTarget* FrameBuffer::getDepthStencilTarget() const
     return _depthStencilTarget;
 }
 
+bool FrameBuffer::isDefault() const
+{
+    return (this == _defaultFrameBuffer);
+}
+
 FrameBuffer* FrameBuffer::bind()
 {
     GL_ASSERT( glBindFramebuffer(GL_FRAMEBUFFER, _handle) );

+ 15 - 0
gameplay/src/FrameBuffer.h

@@ -113,6 +113,13 @@ public:
      * @return The RenderTarget attached at the specified index.
      */
     RenderTarget* getRenderTarget(unsigned int index = 0) const;
+
+    /**
+     * Returns the current number of render targets attached to this frame buffer.
+     *
+     * @return The number of render targets attached.
+     */
+    unsigned int getRenderTargetCount() const;
  
     /**
      * Set this FrameBuffer's DepthStencilTarget.
@@ -128,6 +135,13 @@ public:
      */
     DepthStencilTarget* getDepthStencilTarget() const;
  
+    /**
+     * Determines whether this is the default frame bufffer.
+     *
+     * @return true if this is the default frame buffer, false otherwise.
+     */
+    bool isDefault() const;
+
     /**
      * Binds this FrameBuffer for off-screen rendering and return you the curently bound one.
      *
@@ -172,6 +186,7 @@ private:
     unsigned int _height;
     FrameBufferHandle _handle;
     RenderTarget** _renderTargets;
+    unsigned int _renderTargetCount;
     DepthStencilTarget* _depthStencilTarget;
 
     static unsigned int _maxRenderTargets;