Browse Source

More documentation

Marko Pintera 11 years ago
parent
commit
03ea4c331d

+ 6 - 6
BansheeCore/Include/BsPixelData.h

@@ -8,7 +8,7 @@
 namespace BansheeEngine
 {
 	/**
-	 * @brief	The pixel format used for images, textures, and render surfaces
+	 * @brief	The pixel format usable by images, textures and render surfaces.
 	 */
     enum PixelFormat
     {
@@ -94,17 +94,17 @@ namespace BansheeEngine
 	 */
     enum PixelFormatFlags {
         // This format has an alpha channel
-        PFF_HASALPHA        = 0x00000001,      
+        PFF_HASALPHA = 0x00000001,      
         // This format is compressed. This invalidates the values in elemBytes,
         // elemBits and the bit counts as these might not be fixed in a compressed format.
-        PFF_COMPRESSED    = 0x00000002,
+        PFF_COMPRESSED = 0x00000002,
         // This is a floating point format
-        PFF_FLOAT           = 0x00000004,         
+        PFF_FLOAT = 0x00000004,         
         // This is a depth format (for depth textures)
-        PFF_DEPTH           = 0x00000008,
+        PFF_DEPTH = 0x00000008,
         // Format is in native endian. Generally true for the 16, 24 and 32 bits
         // formats which can be represented as machine integers.
-        PFF_NATIVEENDIAN    = 0x00000010
+        PFF_NATIVEENDIAN = 0x00000010
     };
     
 	/**

+ 2 - 1
BansheeCore/Include/BsTexture.h

@@ -41,7 +41,8 @@ namespace BansheeEngine
 
 	/**
 	 * @brief	Abstract class representing a texture. Specific render systems have their
-	 *			own Texture implementations.
+	 *			own Texture implementations. Internally represented as one or more surfaces
+	 *			with pixels in a certain number of dimensions, backed by a hardware buffer.
 	 *
 	 * @note	Core thread unless specified otherwise.
 	 */

+ 27 - 37
BansheeGLRenderSystem/Include/BsGLPixelFormat.h

@@ -6,65 +6,55 @@
 namespace BansheeEngine 
 {
 	/**
-	* Class to do pixel format mapping between GL and OGRE
-	*/
+	 * @brief	Converts pixel formats to OpenGL formats
+	 */
 	class BS_RSGL_EXPORT GLPixelUtil
 	{
 	public:
-		/** Takes the engine pixel format and returns the appropriate GL one
-			@returns a GLenum describing the format, or 0 if there is no exactly matching 
-			one (and conversion is needed)
-		*/
+		/**
+		 * @brief	Returns matching OpenGL base pixel format type if one is found,
+		 *			zero otherwise.
+		 */
 		static GLenum getGLOriginFormat(PixelFormat mFormat);
 	
-		/** Takes the engine pixel format and returns type that must be provided
-			to GL as data type for reading it into the GPU
-			@returns a GLenum describing the data type, or 0 if there is no exactly matching 
-			one (and conversion is needed)
-		*/
+		/**
+		 * @brief	Returns OpenGL data type used in the provided format.
+		 */
 		static GLenum getGLOriginDataType(PixelFormat mFormat);
         
-        /**	Takes the engine pixel format and returns the type that must be provided
-			to GL as internal format. GL_NONE if no match exists.
-		@param mFormat The pixel format
-		@param hwGamma Whether a hardware gamma-corrected version is requested
-		*/
+		/**
+		 * @brief	Returns matching OpenGL internal pixel format type if one is found,
+		 *			zero otherwise. Optionally returns an SRGB format if "hwGamma" is specified
+		 *			and such format exists.
+		 */
 		static GLenum getGLInternalFormat(PixelFormat mFormat, bool hwGamma = false);
 	
-		/**	Takes the OGRE pixel format and returns the type that must be provided
-			to GL as internal format. If no match exists, returns the closest match.
-		@param mFormat The pixel format
-		@param hwGamma Whether a hardware gamma-corrected version is requested
-		*/
+		/**
+		 * @brief	Returns matching OpenGL internal pixel format type if one is found,
+		 *			otherwise it returns the closest matching format. Optionally returns an 
+		 *			SRGB format if "hwGamma" is specified and such format exists.
+		 */
 		static GLenum getClosestGLInternalFormat(PixelFormat mFormat, bool hwGamma = false);
 		
 		/**
-		 * @brief	Returns a valid type that should be used for creating a buffer for the specified
+		 * @brief	Returns an OpenGL type that should be used for creating a buffer for the specified
 		 * 			depth/stencil format.
 		 */
 		static GLenum getDepthStencilTypeFromFormat(PixelFormat mFormat);
 
-		/**	Function to get the closest matching engine format to an internal GL format. To be
-			precise, the format will be chosen that is most efficient to transfer to the card 
-			without losing precision.
-			@remarks It is valid for this function to always return PF_A8R8G8B8.
-		*/
+		/**
+		 * @brief	Returns pixel format closest to the provided internal OpenGL format.
+		 */
 		static PixelFormat getClosestEngineFormat(GLenum fmt);
 
-		/**	Function to get the closest valid matching engine format to another engine format. 
-		*/
+		/**
+		 * @brief	Returns closest supported format to the provided format.
+		 */
 		static PixelFormat getClosestValidFormat(PixelFormat fmt);
 
 		/**
-		 * @brief	Gets OpenGL format based on a compressed OpenGL internal format.
-		 * 			e.g. GL_COMPRESSED_RGBA_S3TC_DXT1_EXT will return GL_RGBA
-		 *
+		 * @brief	Converts an OpenGL internal format into base format.
 		 */
 		static GLenum getBaseFormatFromCompressedInternalFormat(GLenum internalFormat);
-	        
-        /** Returns next power-of-two size if required by render system, in case
-            RSC_NON_POWER_OF_2_TEXTURES is supported it returns value as-is.
-        */
-        static UINT32 optionalPO2(UINT32 value);
 	};
 };

+ 1 - 2
BansheeGLRenderSystem/Include/BsGLPrerequisites.h

@@ -6,7 +6,6 @@ namespace BansheeEngine
 {
 	extern String MODULE_NAME;
 
-    // Forward declarations
     class GLSupport;
     class GLRenderSystem;
     class GLTexture;
@@ -66,7 +65,7 @@ namespace BansheeEngine
 
 #endif
 
-/// Lots of generated code in here which triggers the new VC CRT security warnings
+// Lots of generated code in here which triggers the new VC CRT security warnings
 #if !defined( _CRT_SECURE_NO_DEPRECATE )
 #define _CRT_SECURE_NO_DEPRECATE
 #endif

+ 6 - 3
BansheeGLRenderSystem/Include/BsGLQueryManager.h

@@ -5,21 +5,24 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Handles creation and life of OpenGL queries.
+	 */
 	class BS_RSGL_EXPORT GLQueryManager : public QueryManager
 	{
 	public:
 		/**
-		 * @copydoc		QueryManager::createEventQuery
+		 * @copydoc	QueryManager::createEventQuery
 		 */
 		EventQueryPtr createEventQuery() const;
 
 		/**
-		 * @copydoc		QueryManager::createTimerQuery
+		 * @copydoc	QueryManager::createTimerQuery
 		 */
 		TimerQueryPtr createTimerQuery() const;
 
 		/**
-		 * @copydoc		QueryManager::createOcclusionQuery
+		 * @copydoc	QueryManager::createOcclusionQuery
 		 */
 		OcclusionQueryPtr createOcclusionQuery(bool binary) const;
 	};

+ 2 - 1
BansheeGLRenderSystem/Include/BsGLRenderSystem.h

@@ -9,7 +9,8 @@
 namespace BansheeEngine 
 {
 	/**
-	 * @brief	Implementation of a render system using OpenGL.
+	 * @brief	Implementation of a render system using OpenGL. Provides abstracted
+	 *			access to various low level OpenGL methods.
 	 */
     class BS_RSGL_EXPORT GLRenderSystem : public RenderSystem
     {

+ 14 - 1
BansheeGLRenderSystem/Include/BsGLRenderSystemFactory.h

@@ -9,13 +9,26 @@ namespace BansheeEngine
 {
 	const String SystemName = "BansheeGLRenderSystem";
 
+	/**
+	 * @brief Handles creation of the OpenGL render system.
+	 */
 	class GLRenderSystemFactory : public RenderSystemFactory
 	{
 	public:
+		/**
+		 * @copydoc	RenderSystemFactory::create
+		 */
 		virtual void create();
+
+		/**
+		 * @copydoc	RenderSystemFactory::name
+		 */
 		virtual const String& name() const { return SystemName; }
 
 	private:
+		/**
+		 * @brief	Registers the factory with the render system manager when constructed.
+		 */
 		class InitOnStart
 		{
 		public:
@@ -30,6 +43,6 @@ namespace BansheeEngine
 			}
 		};
 
-		static InitOnStart initOnStart; // Makes sure factory is registered on program start
+		static InitOnStart initOnStart; // Makes sure factory is registered on library load
 	};
 }

+ 39 - 27
BansheeGLRenderSystem/Include/BsGLRenderTexture.h

@@ -5,19 +5,26 @@
 #include "BsGLFrameBufferObject.h"
 #include "BsModule.h"
 
-// Extra GL constants
 #define GL_DEPTH24_STENCIL8_EXT 0x88F0
 
 namespace BansheeEngine 
 {  
-    /** Base class for GL Render Textures
-    */
+	/**
+	 * @brief	OpenGL implementation of a render texture.
+	 */
     class BS_RSGL_EXPORT GLRenderTexture: public RenderTexture
     {
 	public:
 		virtual ~GLRenderTexture();
 
+		/**
+		 * @copydoc	RenderTexture::requiresTextureFlipping
+		 */
 		bool requiresTextureFlipping() const { return true; }
+
+		/**
+		 * @copydoc	RenderTexture::getCustomAttribute
+		 */
 		virtual void getCustomAttribute(const String& name, void* pData) const;
 
 	protected:
@@ -26,12 +33,12 @@ namespace BansheeEngine
 		GLRenderTexture();
 
 		/**
-		 * @copydoc RenderTexture::initialize_internal().
+		 * @copydoc RenderTexture::initialize_internal
 		 */
 		void initialize_internal();
 
 		/**
-		 * @copydoc RenderTexture::destroy_internal().
+		 * @copydoc RenderTexture::destroy_internal
 		 */
 		void destroy_internal();
 
@@ -39,7 +46,7 @@ namespace BansheeEngine
     };
 
     /**
-     * @brief	Manager/factory for RenderTextures.
+     * @brief	Manager that handles valid render texture formats.
      * 			
 	 * @note	Must be initialized when RenderSystem is first started.
      */
@@ -50,50 +57,55 @@ namespace BansheeEngine
 		~GLRTTManager();
         
         /**
-         * @brief	Check if a certain format is usable as FBO rendertarget format.
+         * @brief	Check if a certain format is usable as a render target format.
          *
          * @note	Thread safe.
          */
         bool checkFormat(PixelFormat format) { return mProps[format].valid; }
         
-        /** Get a FBO without depth/stencil for temporary use, like blitting between textures.
-        */
-        GLuint getTemporaryFBO() { return mTempFBO; }
-
         /**
          * @brief	Get the closest supported alternative format. If format is supported, returns format.
          *
-         * @note	Thread safe
+         * @note	Thread safe.
          */
         virtual PixelFormat getSupportedAlternative(PixelFormat format);
     private:
-        /** Frame Buffer Object properties for a certain texture format.
-        */
+        /** 
+		 * Frame buffer object properties for a certain texture format.
+         */
         struct FormatProperties
         {
-            bool valid; // This format can be used as RTT (FBO)
-            
-            /** Allowed modes/properties for this pixel format
-            */
+            /** 
+			 * Allowed modes/properties for this pixel format
+             */
             struct Mode
             {
-                UINT32 depth;     // Depth format (0=no depth)
-                UINT32 stencil;   // Stencil format (0=no stencil)
+                UINT32 depth;     /**< Depth format (0 = no depth). */
+                UINT32 stencil;   /**< Stencil format (0 = no stencil). */
             };
             
             Vector<Mode> modes;
+			bool valid;
         };
-        /** Properties for all internal formats defined by the engine
-        */
-        FormatProperties mProps[PF_COUNT];
 
-        /** Temporary FBO identifier
-         */
+        FormatProperties mProps[PF_COUNT];
         GLuint mTempFBO;
         
-        /** Detect allowed FBO formats */
+		/**
+		 * @brief	Detect which internal formats are allowed to be used on render target 
+		 *			color or depth/stencil surfaces.
+		 */
         void detectFBOFormats();
-        GLuint _tryFormat(GLenum depthFormat, GLenum stencilFormat);
+
+		/**
+		 * @brief	Checks are the specified depth & stencil formats compatible.
+		 */
+		bool _tryFormat(GLenum depthFormat, GLenum stencilFormat);
+
+		/**
+		 * @brief	Checks is the specified packed format valid for using
+		 *			in the render target.
+		 */
         bool _tryPackedFormat(GLenum packedFormat);
     };
 }

+ 3 - 0
BansheeGLRenderSystem/Include/BsGLRenderWindowManager.h

@@ -5,6 +5,9 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	Manager that handles window creation for OpenGL.
+	 */
 	class BS_RSGL_EXPORT GLRenderWindowManager : public RenderWindowManager
 	{
 	public:

+ 26 - 25
BansheeGLRenderSystem/Include/BsGLTexture.h

@@ -8,43 +8,47 @@
 
 namespace BansheeEngine 
 {
+	/**
+	 * @brief	OpenGL implementation of a texture.
+	 */
     class BS_RSGL_EXPORT GLTexture : public Texture
     {
     public:
         virtual ~GLTexture();      
 
-        // Takes the engine texture type (1d/2d/3d/cube) and returns the appropriate GL one
-        GLenum getGLTextureTarget(void) const;
+		/**
+		 * @brief	Returns OpenGL texture target type
+		 */
+        GLenum getGLTextureTarget() const;
 
+		/**
+		 * @brief	Returns internal OpenGL texture handle.
+		 */
         GLuint getGLID() const;
 		
-		/** Return hardware pixel buffer for a surface. This buffer can then
-			be used to copy data from and to a particular level of the texture.
-			@param face 	Face number, in case of a cubemap texture. Must be 0
-							for other types of textures.
-                            For cubemaps, this is one of 
-                            +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
-			@param mipmap	Mipmap level. This goes from 0 for the first, largest
-							mipmap level to getNumMipmaps()-1 for the smallest.
-			@returns	A shared pointer to a hardware pixel buffer
-			@remarks	The buffer is invalidated when the resource is unloaded or destroyed.
-						Do not use it after the lifetime of the containing texture.
-		*/
+		/**
+		 * @brief	Returns a hardware pixel buffer for a certain face and level of the texture.
+		 * 
+		 * @param	face	Index of the texture face, if texture has more than one. Array index for
+		 *					texture arrays and a cube face for cube textures.
+		 * @param	mipmap	Index of the mip level. 0 being the largest mip level.
+		 *
+		 * @note	Cube face indices: +X (0), -X (1), +Y (2), -Y (3), +Z (4), -Z (5)
+		 */
 		std::shared_ptr<GLPixelBuffer> getBuffer(UINT32 face, UINT32 mipmap);
 
     protected:
 		friend class GLTextureManager;
 
-		// Constructor
 		GLTexture(GLSupport& support);
 
 		/**
-		 * @copydoc Texture::initialize_internal()
+		 * @copydoc Texture::initialize_internal
 		 */
 		void initialize_internal();
 
 		/**
-		 * @copydoc Texture::destroy_internal()
+		 * @copydoc Texture::destroy_internal
 		 */
 		void destroy_internal();
 
@@ -73,11 +77,10 @@ namespace BansheeEngine
 		 */
 		void writeData(const PixelData& src, UINT32 mipLevel = 0, UINT32 face = 0, bool discardWholeBuffer = false);
 
-		/** internal method, create GLHardwarePixelBuffers for every face and
-			 mipmap level. This method must be called after the GL texture object was created,
-			the number of mipmaps was set (GL_TEXTURE_MAX_LEVEL) and glTexImageXD was called to
-			actually allocate the buffer
-		*/
+		/**
+		 * @brief	Creates pixel buffers for each face and mip level. Texture must 
+		 *			have been created previously.
+		 */
 		void createSurfaceList();
 
     private:
@@ -85,9 +88,7 @@ namespace BansheeEngine
         GLSupport& mGLSupport;
 		std::shared_ptr<GLPixelBuffer> mLockedBuffer;
 		
-		/// Vector of pointers to subsurfaces
-		typedef Vector<std::shared_ptr<GLPixelBuffer>> SurfaceList;
-		SurfaceList	mSurfaceList;
+		Vector<std::shared_ptr<GLPixelBuffer>>mSurfaceList;
     };
 
 	typedef std::shared_ptr<GLTexture> GLTexturePtr;

+ 19 - 3
BansheeGLRenderSystem/Include/BsGLTextureManager.h

@@ -7,19 +7,35 @@
 
 namespace BansheeEngine 
 {
-    /** GL-specific implementation of a TextureManager */
+	/**
+	 * @brief	Handles creation of OpenGL textures.
+	 */
     class BS_RSGL_EXPORT GLTextureManager : public TextureManager
     {
     public:
         GLTextureManager(GLSupport& support);
         virtual ~GLTextureManager();
 
-		/// @copydoc TextureManager::getNativeFormat
+		/**
+		 * @brief	Converts the provided format for the specified texture type and usage
+		 *			into a format that is supported by OpenGL.
+		 */
 		PixelFormat getNativeFormat(TextureType ttype, PixelFormat format, int usage);
 
-	protected:		
+	protected:
+		/**
+		 * @copydoc	TextureManager::createTextureImpl
+		 */
 		TexturePtr createTextureImpl();
+
+		/**
+		 * @copydoc	TextureManager::createRenderTextureImpl
+		 */
 		RenderTexturePtr createRenderTextureImpl();
+
+		/**
+		 * @copydoc	TextureManager::createMultiRenderTextureImpl
+		 */
 		MultiRenderTexturePtr createMultiRenderTextureImpl();
 
         GLSupport& mGLSupport;

+ 8 - 3
BansheeGLRenderSystem/Include/BsGLTimerQuery.h

@@ -6,7 +6,7 @@
 namespace BansheeEngine
 {
 	/**
-	 * @copydoc TimerQuery
+	 * @brief	OpenGL implementation of a timer query.
 	 */
 	class BS_RSGL_EXPORT GLTimerQuery : public TimerQuery
 	{
@@ -37,12 +37,17 @@ namespace BansheeEngine
 	private:
 		friend class QueryManager;
 
+		/**
+		 * @brief	Processes query results and saves them for later use. To be called
+		 *			when query has completed.
+		 */
+		void finalize();
+
+	private:
 		GLuint mQueryStartObj;
 		GLuint mQueryEndObj;
 		bool mFinalized;
 
 		float mTimeDelta;
-
-		void finalize();
 	};
 }

+ 7 - 1
BansheeGLRenderSystem/Include/BsGLVertexArrayObjectManager.h

@@ -12,12 +12,18 @@ namespace BansheeEngine
 	class BS_RSGL_EXPORT GLVertexArrayObject
 	{
 	private:
+		/**
+		 * @brief	Generates hash value for the VAO object.
+		 */
 		class Hash
 		{
 		public:
-			::std::size_t operator()(const GLVertexArrayObject &vao) const;
+			::std::size_t operator()(const GLVertexArrayObject& vao) const;
 		};
 
+		/**
+		 * @brief	Checks if two VAO objects are equal.
+		 */
 		class Equal
 		{
 		public:

+ 1 - 1
BansheeGLRenderSystem/Include/BsGLVertexBuffer.h

@@ -7,7 +7,7 @@
 namespace BansheeEngine 
 {
 	/**
-	 * @copydoc	VertexBuffer
+	 * @brief	OpenGL implementation of a vertex buffer.
 	 */
     class BS_RSGL_EXPORT GLVertexBuffer : public VertexBuffer 
     {

+ 0 - 9
BansheeGLRenderSystem/Source/BsGLPixelFormat.cpp

@@ -313,13 +313,4 @@ namespace BansheeEngine
 			return PF_UNKNOWN;
 		}
 	}
-
-    UINT32 GLPixelUtil::optionalPO2(UINT32 value)
-    {
-        const RenderSystemCapabilities *caps = BansheeEngine::RenderSystem::instancePtr()->getCapabilities();
-        if(caps->hasCapability(RSC_NON_POWER_OF_2_TEXTURES))
-            return value;
-        else
-            return Bitwise::firstPO2From((UINT32)value);
-    }
 };

+ 59 - 54
BansheeGLRenderSystem/Source/BsGLRenderTexture.cpp

@@ -5,6 +5,25 @@
 
 namespace BansheeEngine 
 {
+#define PROBE_SIZE 16
+
+	static const GLenum depthFormats[] =
+	{
+		GL_NONE,
+		GL_DEPTH_COMPONENT16,
+		GL_DEPTH_COMPONENT32,
+		GL_DEPTH24_STENCIL8,
+		GL_DEPTH32F_STENCIL8
+	};
+
+	static const UINT32 depthBits[] =
+	{
+		0, 16, 32, 24, 32
+	};
+
+#define DEPTHFORMAT_COUNT (sizeof(depthFormats)/sizeof(GLenum))
+
+
 	GLRenderTexture::GLRenderTexture()
 		:mFB(nullptr)
 	{
@@ -60,23 +79,6 @@ namespace BansheeEngine
 		}
 	}
 
-/// Size of probe texture
-#define PROBE_SIZE 16
-
-static const GLenum depthFormats[] =
-{
-    GL_NONE,
-    GL_DEPTH_COMPONENT16,
-    GL_DEPTH_COMPONENT32,
-    GL_DEPTH24_STENCIL8, // packed depth / stencil
-	GL_DEPTH32F_STENCIL8
-};
-static const UINT32 depthBits[] =
-{
-    0,16,32,24,32
-};
-#define DEPTHFORMAT_COUNT (sizeof(depthFormats)/sizeof(GLenum))
-
 	GLRTTManager::GLRTTManager()
     {
 		detectFBOFormats();
@@ -89,97 +91,99 @@ static const UINT32 depthBits[] =
         glDeleteFramebuffersEXT(1, &mTempFBO);      
 	}
 
-    /** Try a certain FBO format, and return the status. Also sets mDepthRB and mStencilRB.
-        @returns true    if this combo is supported
-                 false   if this combo is not supported
-    */
-    GLuint GLRTTManager::_tryFormat(GLenum depthFormat, GLenum stencilFormat)
+	bool GLRTTManager::_tryFormat(GLenum depthFormat, GLenum stencilFormat)
     {
         GLuint status, depthRB = 0, stencilRB = 0;
-        bool failed = false; // flag on GL errors
+        bool failed = false;
 
         if(depthFormat != GL_NONE)
         {
-            /// Generate depth renderbuffer
+            // Generate depth renderbuffer
             glGenRenderbuffersEXT(1, &depthRB);
-            /// Bind it to FBO
+
+            // Bind it to FBO
             glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthRB);
             
-            /// Allocate storage for depth buffer
+            // Allocate storage for depth buffer
             glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, depthFormat,
                                 PROBE_SIZE, PROBE_SIZE);
             
-            /// Attach depth
+            // Attach depth
             glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
                                     GL_RENDERBUFFER_EXT, depthRB);
         }
 
         if(stencilFormat != GL_NONE)
         {
-            /// Generate stencil renderbuffer
+            // Generate stencil renderbuffer
             glGenRenderbuffersEXT(1, &stencilRB);
-            /// Bind it to FBO
+
+            // Bind it to FBO
             glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, stencilRB);
-            glGetError(); // NV hack
-            /// Allocate storage for stencil buffer
+            glGetError(); 
+
+            // Allocate storage for stencil buffer
             glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, stencilFormat,
                                 PROBE_SIZE, PROBE_SIZE); 
-            if(glGetError() != GL_NO_ERROR) // NV hack
+
+            if(glGetError() != GL_NO_ERROR)
                 failed = true;
-            /// Attach stencil
+
+            // Attach stencil
             glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
                             GL_RENDERBUFFER_EXT, stencilRB);
-            if(glGetError() != GL_NO_ERROR) // NV hack
+
+            if(glGetError() != GL_NO_ERROR)
                 failed = true;
         }
         
         status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
-        /// If status is negative, clean up
+
         // Detach and destroy
         glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
         glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
+
         if (depthRB)
             glDeleteRenderbuffersEXT(1, &depthRB);
+
         if (stencilRB)
             glDeleteRenderbuffersEXT(1, &stencilRB);
         
         return status == GL_FRAMEBUFFER_COMPLETE_EXT && !failed;
     }
     
-    /** Try a certain packed depth/stencil format, and return the status.
-        @returns true    if this combo is supported
-                 false   if this combo is not supported
-    */
     bool GLRTTManager::_tryPackedFormat(GLenum packedFormat)
     {
         GLuint packedRB = 0;
         bool failed = false; // flag on GL errors
 
-        /// Generate renderbuffer
+        // Generate renderbuffer
         glGenRenderbuffersEXT(1, &packedRB);
 
-        /// Bind it to FBO
+        // Bind it to FBO
         glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, packedRB);
 
-        /// Allocate storage for buffer
+        // Allocate storage for buffer
         glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, packedFormat, PROBE_SIZE, PROBE_SIZE);
-        glGetError(); // NV hack
+        glGetError();
 
-        /// Attach depth
+        // Attach depth
         glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT,
             GL_RENDERBUFFER_EXT, packedRB);
-        if(glGetError() != GL_NO_ERROR) // NV hack
+
+        if(glGetError() != GL_NO_ERROR)
             failed = true;
 
-        /// Attach stencil
+        // Attach stencil
         glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT,
             GL_RENDERBUFFER_EXT, packedRB);
-        if(glGetError() != GL_NO_ERROR) // NV hack
+
+        if(glGetError() != GL_NO_ERROR)
             failed = true;
 
         GLuint status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
 
-        /// Detach and destroy
+        // Detach and destroy
         glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
         glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
         glDeleteRenderbuffersEXT(1, &packedRB);
@@ -187,10 +191,6 @@ static const UINT32 depthBits[] =
         return status == GL_FRAMEBUFFER_COMPLETE_EXT && !failed;
     }
 
-    /** Detect which internal formats are allowed as RTT
-        Also detect what combinations of stencil and depth are allowed with this internal
-        format.
-    */
     void GLRTTManager::detectFBOFormats()
     {
         // Try all formats, and report which ones work as target
@@ -241,6 +241,7 @@ static const UINT32 depthBits[] =
 				glDrawBuffer(GL_NONE);
 				glReadBuffer(GL_NONE);
 			}
+
             // Check status
             GLuint status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
 
@@ -279,6 +280,7 @@ static const UINT32 depthBits[] =
                     }
                 }
             }
+
             // Delete texture and framebuffer
             glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
             glDeleteFramebuffersEXT(1, &fb);
@@ -306,7 +308,8 @@ static const UINT32 depthBits[] =
     {
         if(checkFormat(format))
             return format;
-        /// Find first alternative
+
+        // Find first alternative
         PixelComponentType pct = PixelUtil::getElementType(format);
         switch(pct)
         {
@@ -315,9 +318,11 @@ static const UINT32 depthBits[] =
         case PCT_FLOAT32: format = PF_FLOAT32_RGBA; break;
         case PCT_COUNT: break;
         }
+
         if(checkFormat(format))
             return format;
-        /// If none at all, return to default
+
+        // If none at all, return to default
         return PF_A8R8G8B8;
     }
 }

+ 31 - 33
BansheeGLRenderSystem/Source/BsGLTexture.cpp

@@ -7,20 +7,16 @@
 #include "BsBitwise.h"
 #include "BsCoreThread.h"
 #include "BsTextureManager.h"
-
 #include "BsGLRenderTexture.h"
 
 namespace BansheeEngine 
 {
     GLTexture::GLTexture(GLSupport& support) 
-        : Texture(),
-        mTextureID(0), mGLSupport(support)
-    {
-    }
+        : Texture(), mTextureID(0), mGLSupport(support)
+    { }
 
     GLTexture::~GLTexture()
-    {
-    }
+    { }
 
 	void GLTexture::initialize_internal()
 	{
@@ -44,14 +40,14 @@ namespace BansheeEngine
 				BS_EXCEPT(NotImplementedException, "Supplied format is not a depth stencil format. Format: " + toString(mFormat));
 		}
 
-		// Generate texture name
-		glGenTextures( 1, &mTextureID );
+		// Generate texture handle
+		glGenTextures(1, &mTextureID);
 
 		// Set texture type
-		glBindTexture( getGLTextureTarget(), mTextureID );
+		glBindTexture(getGLTextureTarget(), mTextureID);
 
 		// This needs to be set otherwise the texture doesn't get rendered
-		glTexParameteri( getGLTextureTarget(), GL_TEXTURE_MAX_LEVEL, mNumMipmaps );
+		glTexParameteri(getGLTextureTarget(), GL_TEXTURE_MAX_LEVEL, mNumMipmaps);
 
 		// Set some misc default parameters so NVidia won't complain, these can of course be changed later
 		glTexParameteri(getGLTextureTarget(), GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -63,7 +59,6 @@ namespace BansheeEngine
 		}
 
 		// Allocate internal buffer so that glTexSubImageXD can be used
-		// Internal format
 		GLenum format = GLPixelUtil::getClosestGLInternalFormat(mFormat, mHwGamma);
 		UINT32 width = mWidth;
 		UINT32 height = mHeight;
@@ -80,8 +75,7 @@ namespace BansheeEngine
 
 		if((mUsage & TU_RENDERTARGET) != 0 && mTextureType == TEX_TYPE_2D && mMultisampleCount > 0)
 		{
-			glTexImage2DMultisample(GL_TEXTURE_2D, mMultisampleCount, format,
-				width, height, GL_FALSE);
+			glTexImage2DMultisample(GL_TEXTURE_2D, mMultisampleCount, format, width, height, GL_FALSE);
 		}
 		else if((mUsage & TU_DEPTHSTENCIL) != 0)
 		{
@@ -101,38 +95,41 @@ namespace BansheeEngine
 		}
 		else
 		{
-			// Run through this process to pregenerate mipmap piramid
-			for(UINT32 mip=0; mip<=mNumMipmaps; mip++)
+			// Run through this process to pre-generate mipmap pyramid
+			for(UINT32 mip = 0; mip <= mNumMipmaps; mip++)
 			{
-				// Normal formats
 				switch(mTextureType)
 				{
 				case TEX_TYPE_1D:
-					glTexImage1D(GL_TEXTURE_1D, mip, format,
-						width, 0, 
+					glTexImage1D(GL_TEXTURE_1D, mip, format, width, 0, 
 						GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
 
 					break;
 				case TEX_TYPE_2D:
 					glTexImage2D(GL_TEXTURE_2D, mip, format,
-						width, height, 0, 
-						GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
+						width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
 					break;
 				case TEX_TYPE_3D:
-					glTexImage3D(GL_TEXTURE_3D, mip, format,
-						width, height, depth, 0, 
-						GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
+					glTexImage3D(GL_TEXTURE_3D, mip, format, width, height, 
+						depth, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
 					break;
 				case TEX_TYPE_CUBE_MAP:
-					for(int face=0; face<6; face++) {
+					for(UINT32 face = 0; face < 6; face++) 
+					{
 						glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, mip, format,
 							width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
 					}
 					break;
 				};
-				if(width>1)		width = width/2;
-				if(height>1)	height = height/2;
-				if(depth>1)		depth = depth/2;
+
+				if(width > 1)
+					width = width/2;
+
+				if(height > 1)
+					height = height/2;
+
+				if(depth > 1)	
+					depth = depth/2;
 			}
 		}
 
@@ -156,7 +153,7 @@ namespace BansheeEngine
 	void GLTexture::destroy_internal()
 	{
 		mSurfaceList.clear();
-		glDeleteTextures( 1, &mTextureID );
+		glDeleteTextures(1, &mTextureID);
 
 		clearBufferViews();
 
@@ -232,9 +229,9 @@ namespace BansheeEngine
 		size_t numMips = std::min(getNumMipmaps(), target->getNumMipmaps());
 
 		GLTexture* glTexture = static_cast<GLTexture*>(target.get());
-		for(unsigned int face=0; face<getNumFaces(); face++)
+		for (UINT32 face = 0; face < getNumFaces(); face++)
 		{
-			for(unsigned int mip=0; mip<=numMips; mip++)
+			for(UINT32 mip = 0; mip <= numMips; mip++)
 			{
 				GLTextureBuffer *src = static_cast<GLTextureBuffer*>(getBuffer(face, mip).get());
 
@@ -255,8 +252,7 @@ namespace BansheeEngine
 						static_cast<GpuBufferUsage>(mUsage), mHwGamma, mMultisampleCount);
 				mSurfaceList.push_back(bs_shared_ptr<GLPixelBuffer, PoolAlloc>(buf));
                 
-                /// Check for error
-                if(buf->getWidth()==0 || buf->getHeight()==0 || buf->getDepth()==0)
+                if(buf->getWidth() == 0 || buf->getHeight() == 0 || buf->getDepth() == 0)
                 {
 					BS_EXCEPT(RenderingAPIException, 
                         "Zero sized texture surface on texture face "
@@ -274,8 +270,10 @@ namespace BansheeEngine
 
 		if(face >= getNumFaces())
 			BS_EXCEPT(InvalidParametersException, "Face index out of range");
+
 		if(mipmap > mNumMipmaps)
 			BS_EXCEPT(InvalidParametersException, "Mipmap index out of range");
+
 		unsigned int idx = face*(mNumMipmaps+1) + mipmap;
 		assert(idx < mSurfaceList.size());
 		return mSurfaceList[idx];