Browse Source

More documentation

Marko Pintera 11 years ago
parent
commit
fc8f2b1eaf

+ 11 - 1
BansheeCore/Include/BsPixelBuffer.h

@@ -16,7 +16,17 @@ namespace BansheeEngine
     class BS_CORE_EXPORT PixelBuffer : public HardwareBuffer
     {
     public:
-        PixelBuffer(UINT32 mWidth, UINT32 mHeight, UINT32 mDepth, PixelFormat mFormat, 
+		/**
+		 * @brief	Constructs a new pixel buffer with the provided settings.
+		 *
+		 * @param	width			Width of the pixel buffer in pixels.
+		 * @param	height			Height of the pixel buffer in pixels.
+		 * @param	depth			Depth of the pixel buffer in pixels (number of 2D slices).
+		 * @param	format			Format of each pixel in the buffer.
+		 * @param	usage			Usage signaling the render system how we plan on using the buffer.
+		 * @param	useSystemMemory	True if buffer should be allocated in system memory.
+		 */
+        PixelBuffer(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format, 
 			GpuBufferUsage usage, bool useSystemMemory);
         ~PixelBuffer();
 

+ 3 - 3
BansheeGLRenderSystem/BansheeGLRenderSystem.vcxproj.filters

@@ -114,9 +114,6 @@
     <ClInclude Include="Include\BsWin32Context.h">
       <Filter>Header Files\Win32</Filter>
     </ClInclude>
-    <ClInclude Include="Source\win32\BsGLUtil.h">
-      <Filter>Header Files\Win32</Filter>
-    </ClInclude>
     <ClInclude Include="Include\BsGLSLGpuProgramRTTI.h">
       <Filter>Header Files\RTTI</Filter>
     </ClInclude>
@@ -132,6 +129,9 @@
     <ClInclude Include="Source\GLSL\include\BsGLSLGpuProgram.h">
       <Filter>Header Files\GLSL</Filter>
     </ClInclude>
+    <ClInclude Include="Source\win32\BsGLUtil.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\glew.cpp">

+ 50 - 38
BansheeGLRenderSystem/Include/BsGLFrameBufferObject.h

@@ -7,73 +7,85 @@
 
 namespace BansheeEngine 
 {
-	/** GL surface descriptor. Points to a 2D surface that can be rendered to. 
-    */
+	/**
+	 * @brief	Describes OpenGL frame buffer surface.
+	 */
     struct BS_RSGL_EXPORT GLSurfaceDesc
     {
     public:
-        GLPixelBufferPtr buffer;
-        UINT32 zoffset;
-		UINT32 numSamples;
+		GLSurfaceDesc() 
+			:zoffset(0), numSamples(0) 
+		{ }
 
-		GLSurfaceDesc() :buffer(0), zoffset(0), numSamples(0) {}
+		GLPixelBufferPtr buffer;
+		UINT32 zoffset;
+		UINT32 numSamples;
     };
 
-    /** Frame Buffer Object abstraction.
-    */
+	/**
+	 * @brief	Manages an OpenGL frame-buffer object. Frame buffer object
+	 *			is used as a rendering destination in the render system pipeline,
+	 *			and it may consist out of one or multiple color surfaces and an optional
+	 *			depth/stencil surface.
+	 */
     class BS_RSGL_EXPORT GLFrameBufferObject
     {
     public:
-        GLFrameBufferObject(UINT32 multisampleCount);
+        GLFrameBufferObject();
         ~GLFrameBufferObject();
 
-        /** Bind a surface to a certain attachment point.
-            attachment: 0..BS_MAX_MULTIPLE_RENDER_TARGETS-1
-        */
-        void bindSurface(UINT32 attachment, const GLSurfaceDesc &target);
+		/**
+		 * @brief	Binds a color surface to the specific attachment point.
+		 *
+		 * @param	attachment	Attachment point index in the range [0, BS_MAX_MULTIPLE_RENDER_TARGETS).
+		 * @param	target		Description of the color surface to attach.
+		 *
+		 * @note	Multisample counts of all surfaces must match.
+		 *			0th attachment must be bound in order for the object to be usable, rest are optional.
+		 */
+        void bindSurface(UINT32 attachment, const GLSurfaceDesc& target);
 
-        /** Unbind attachment
-        */
+		/**
+		 * @brief	Unbinds the attachment at the specified attachment index.
+		 *
+		 * @param	attachment	Attachment point index in the range [0, BS_MAX_MULTIPLE_RENDER_TARGETS).
+		 */
         void unbindSurface(UINT32 attachment);
 
 		/**
-		 * @brief	Bind depth stencil buffer.
+		 * @brief	Binds a depth/stencil buffer.
+		 *
+		 * @note	Multisample counts of depth/stencil and color surfaces must match.
+		 *			Binding a depth/stencil buffer is optional.
 		 */
 		void bindDepthStencil(GLPixelBufferPtr depthStencilBuffer);
 
 		/**
-		 * @brief	Unbinds depth stencil buffer.
+		 * @brief	Unbinds a depth stencil buffer.
 		 */
 		void unbindDepthStencil();
         
-        /** Bind FrameBufferObject
-        */
+		/**
+		 * @brief	Binds the frame buffer object to the OpenGL pipeline, making it used
+		 *			for any further rendering operations.
+		 */
         void bind();
 
-		/// Get the GL id for the FBO
+		/**
+		 * @brief	Returns internal OpenGL frame buffer id.
+		 */
 		GLuint getGLFBOID() const { return mFB; }
 
-        /// Accessors
-        UINT32 getWidth();
-        UINT32 getHeight();
-        PixelFormat getFormat();
-        
-		const GLSurfaceDesc &getSurface(UINT32 attachment) { return mColor[attachment]; }
     private:
-		GLsizei mNumSamples;
+		/**
+		 * @brief	Rebuilds internal frame buffer object. Should be called whenever surfaces change.
+		 */
+        void rebuild();
+
+	private:
         GLuint mFB;
 
-        GLPixelBufferPtr mDepthStencilBuffer;
-        // Arbitrary number of texture surfaces
         GLSurfaceDesc mColor[BS_MAX_MULTIPLE_RENDER_TARGETS];
-
-		/** Initialise object (find suitable depth and stencil format).
-            Must be called every time the bindings change.
-            It fails with an exception (ERR_INVALIDPARAMS) if:
-            - Attachment point 0 has no binding
-            - Not all bound surfaces have the same size
-            - Not all bound surfaces have the same internal format
-        */
-        void initialize();
+		GLPixelBufferPtr mDepthStencilBuffer;
     };
 }

+ 19 - 8
BansheeGLRenderSystem/Include/BsGLGpuBuffer.h

@@ -5,34 +5,38 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	OpenGL implementation of a generic GPU buffer.
+	 */
+	// TODO - Not implemented, just a dummy class for now
 	class BS_RSGL_EXPORT GLGpuBuffer : public GpuBuffer
 	{
 	public:
         ~GLGpuBuffer();
 
 		/**
-		 * @copydoc GenericBuffer::lockImpl
+		 * @copydoc GpuBuffer::lockImpl
 		 */
 		virtual void* lock(UINT32 offset, UINT32 length, GpuLockOptions options);
 
 		/**
-		 * @copydoc GenericBuffer::unlockImpl
+		 * @copydoc GpuBuffer::unlockImpl
 		 */
 		virtual void unlock();
 
 		/**
-		 * @copydoc GenericBuffer::readData
+		 * @copydoc GpuBuffer::readData
 		 */
         virtual void readData(UINT32 offset, UINT32 length, void* pDest);
 
 		/**
-		 * @copydoc GenericBuffer::writeData
+		 * @copydoc GpuBuffer::writeData
 		 */
         virtual void writeData(UINT32 offset, UINT32 length, const void* pSource,
 				BufferWriteType writeFlags = BufferWriteType::Normal);
 
 		/**
-		 * @copydoc GenericBuffer::copyData
+		 * @copydoc GpuBuffer::copyData
 		 */
 		void copyData(GpuBuffer& srcBuffer, UINT32 srcOffset, 
 			UINT32 dstOffset, UINT32 length, bool discardWholeBuffer = false);
@@ -42,12 +46,19 @@ namespace BansheeEngine
 
 		GLGpuBuffer(UINT32 elementCount, UINT32 elementSize, GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);
 
+		/**
+		 * @copydoc GpuBuffer::initialize_internal
+		 */
+		void initialize_internal();	
+
+		/**
+		 * @copydoc GpuBuffer::createView
+		 */
 		virtual GpuBufferView* createView();
-		virtual void destroyView(GpuBufferView* view);
 
 		/**
-		 * @copydoc GpuBuffer::initialize_internal()
+		 * @copydoc GpuBuffer::destroyView
 		 */
-		void initialize_internal();	
+		virtual void destroyView(GpuBufferView* view);
 	};
 }

+ 6 - 0
BansheeGLRenderSystem/Include/BsGLGpuParamBlockBuffer.h

@@ -5,6 +5,9 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	OpenGL implementation of a GPU parameter buffer (Uniform buffer).
+	 */
 	class BS_RSGL_EXPORT GLGpuParamBlockBuffer : public GpuParamBlockBuffer
 	{
 	public:
@@ -20,6 +23,9 @@ namespace BansheeEngine
 		 */
 		void readData(UINT8* data) const;
 
+		/**
+		 * @brief	Returns internal OpenGL uniform buffer handle.
+		 */
 		GLuint getGLHandle() const { return mGLHandle; }
 	protected:
 		/**

+ 13 - 37
BansheeGLRenderSystem/Include/BsGLHardwareBufferManager.h

@@ -3,47 +3,25 @@
 #include "BsGLPrerequisites.h"
 #include "BsHardwareBufferManager.h"
 
-namespace BansheeEngine {
-
-// Default threshold at which glMapBuffer becomes more efficient than glBufferSubData (32k?)
-#	define BS_GL_DEFAULT_MAP_BUFFER_THRESHOLD (1024 * 32)
-
-
-    /** Implementation of HardwareBufferManager for OpenGL. */
+namespace BansheeEngine 
+{
+	/**
+	 * @brief	Handles creation of OpenGL specific hardware buffers.
+	 */
     class BS_RSGL_EXPORT GLHardwareBufferManager : public HardwareBufferManager
     {
     public:
-        GLHardwareBufferManager();
-        ~GLHardwareBufferManager();
-
-        /// Utility function to get the correct GL usage based on HBU's
-        static GLenum getGLUsage(unsigned int usage);
-
-        /// Utility function to get the correct GL type based on VET's
-        static GLenum getGLType(unsigned int type);
-
-		/** Allocator method to allow us to use a pool of memory as a scratch
-			area for hardware buffers. This is because glMapBuffer is incredibly
-			inefficient, seemingly no matter what options we give it. So for the
-			period of lock/unlock, we will instead allocate a section of a local
-			memory pool, and use glBufferSubDataARB / glGetBufferSubDataARB
-			instead.
-		*/
-		void* allocateScratch(UINT32 size);
-
-		/// @see allocateScratch
-		void deallocateScratch(void* ptr);
+		/**
+		 * @brief	Converts engine buffer usage flags into OpenGL specific flags.
+		 */
+		static GLenum getGLUsage(GpuBufferUsage usage);
 
-		/** Threshold after which glMapBuffer is used and not glBufferSubData
-		*/
-		const UINT32 getGLMapBufferThreshold() const;
-		void setGLMapBufferThreshold( const UINT32 value );
+		/**
+		 * @brief	Converts vertex element type into OpenGL specific type.
+		 */
+        static GLenum getGLType(VertexElementType type);
 
 	protected:
-		char* mScratchBufferPool;
-		BS_MUTEX(mScratchMutex);
-		UINT32 mMapBufferThreshold;
-
 		/**
 		 * @copydoc HardwareBufferManager::createVertexBufferImpl
 		 */
@@ -62,8 +40,6 @@ namespace BansheeEngine {
 
 		/**
 		 * @copydoc HardwareBufferManager::createGenericBufferImpl
-		 *
-		 * OpenGL does not support generic buffers so this method will return a dummy instance.
 		 */
 		GpuBufferPtr createGpuBufferImpl(UINT32 elementCount, UINT32 elementSize, 
 			GpuBufferType type, GpuBufferUsage usage, bool randomGpuWrite = false, bool useCounter = false);

+ 29 - 12
BansheeGLRenderSystem/Include/BsGLIndexBuffer.h

@@ -5,17 +5,29 @@
 
 namespace BansheeEngine 
 { 
+	/**
+	 * @brief	OpenGL implementation of an index buffer.
+	 */
     class BS_RSGL_EXPORT GLIndexBuffer : public IndexBuffer
     {
     public:
         ~GLIndexBuffer();
-        /** See HardwareBuffer. */
+
+		/**
+		 * @copydoc IndexBuffer::readData
+		 */
         void readData(UINT32 offset, UINT32 length, void* pDest);
-        /** See HardwareBuffer. */
-        void writeData(UINT32 offset, UINT32 length, 
-			const void* pSource, BufferWriteType writeFlags = BufferWriteType::Normal);
 
-        GLuint getGLBufferId(void) const { return mBufferId; }
+		/**
+		 * @copydoc IndexBuffer::writeData
+		 */
+        void writeData(UINT32 offset, UINT32 length, const void* pSource, 
+			BufferWriteType writeFlags = BufferWriteType::Normal);
+
+		/**
+		 * @brief	Returns internal OpenGL index buffer handle.
+		 */
+        GLuint getGLBufferId() const { return mBufferId; }
 
 	protected:
 		friend class GLHardwareBufferManager;
@@ -23,21 +35,26 @@ namespace BansheeEngine
 		GLIndexBuffer(IndexType idxType, UINT32 numIndexes, 
 			GpuBufferUsage usage); 
 
-		/** See HardwareBuffer. */
-		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
-		/** See HardwareBuffer. */
-		void unlockImpl(void);
-
 		/**
-		 * @copydoc IndexBuffer::initialize_internal()
+		 * @copydoc IndexBuffer::initialize_internal
 		 */
 		void initialize_internal();	
 		
 		/**
-		 * @copydoc IndexBuffer::destroy_internal()
+		 * @copydoc IndexBuffer::destroy_internal
 		 */
 		void destroy_internal();
 
+		/**
+		 * @copydoc IndexBuffer::lockImpl
+		 */
+		void* lockImpl(UINT32 offset, UINT32 length, GpuLockOptions options);
+
+		/**
+		 * @copydoc IndexBuffer::unlockImpl
+		 */
+		void unlockImpl();
+
 	private:
 		GLuint mBufferId;
     };

+ 12 - 2
BansheeGLRenderSystem/Include/BsGLMultiRenderTexture.h

@@ -6,12 +6,22 @@
 
 namespace BansheeEngine
 {
+	/**
+	 * @brief	OpenGL implementation of a render texture with multiple color surfaces.
+	 */
 	class BS_RSGL_EXPORT GLMultiRenderTexture : public MultiRenderTexture
 	{
 	public:
 		virtual ~GLMultiRenderTexture();
 
+		/**
+		 * @copydoc MultiRenderTexture::requiresTextureFlipping
+		 */
 		bool requiresTextureFlipping() const { return true; }
+
+		/**
+		 * @copydoc MultiRenderTexture::getCustomAttribute
+		 */
 		void getCustomAttribute(const String& name, void* pData) const;
 	protected:
 		friend class GLTextureManager;
@@ -19,12 +29,12 @@ namespace BansheeEngine
 		GLMultiRenderTexture();
 
 		/**
-		 * @copydoc MultiRenderTexture::initialize_internal().
+		 * @copydoc MultiRenderTexture::initialize_internal
 		 */
 		void initialize_internal();
 
 		/**
-		 * @copydoc MultiRenderTexture::destroy_internal().
+		 * @copydoc MultiRenderTexture::destroy_internal
 		 */
 		void destroy_internal();
 	private:

+ 8 - 3
BansheeGLRenderSystem/Include/BsGLOcclusionQuery.h

@@ -6,7 +6,7 @@
 namespace BansheeEngine
 {
 	/**
-	 * @copydoc OcclusionQuery
+	 * @brief	OpenGL implementation of an occlusion query.
 	 */
 	class BS_RSGL_EXPORT GLOcclusionQuery : public OcclusionQuery
 	{
@@ -37,11 +37,16 @@ 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 mQueryObj;
 		bool mFinalized;
 
 		UINT32 mNumSamples;
-
-		void finalize();
 	};
 }

+ 132 - 50
BansheeGLRenderSystem/Include/BsGLPixelBuffer.h

@@ -7,89 +7,171 @@ namespace BansheeEngine
 {
 	class GLTextureBuffer;
 
-	class BS_RSGL_EXPORT GLPixelBuffer: public PixelBuffer
+	/**
+	 * @brief	OpenGL implementation of a pixel buffer. Represents a hardware buffer
+	 *			containing a surface of pixels.
+	 */
+	class BS_RSGL_EXPORT GLPixelBuffer : public PixelBuffer
 	{
 	public:
-		// Upload a box of pixels to this buffer on the card
-		virtual void upload(const PixelData &data, const PixelVolume &dest);
-		// Download a box of pixels from the card
-		virtual void download(const PixelData &data);
+		/**
+		 * @brief	Constructs a new pixel buffer with the provided settings.
+		 *
+		 * @param	width			Width of the pixel buffer in pixels.
+		 * @param	height			Height of the pixel buffer in pixels.
+		 * @param	depth			Depth of the pixel buffer in pixels (number of 2D slices).
+		 * @param	format			Format of each pixel in the buffer.
+		 * @param	usage			Usage signaling the render system how we plan on using the buffer.
+		 */
+		GLPixelBuffer(UINT32 mWidth, UINT32 mHeight, UINT32 mDepth,
+			PixelFormat mFormat, GpuBufferUsage usage);
+
+		~GLPixelBuffer();
+
+		/**
+		 * @brief	Upload some pixel data to the buffer.
+		 *
+		 * @param	data	Data to upload.
+		 * @param	dest	Coordinates to which to upload the data.
+		 */
+		virtual void upload(const PixelData& data, const PixelVolume& dest);
+
+		/**
+		 * @brief	Reads data from the pixel buffer into the provided object.
+		 *			Caller must ensure the data object is of adequate size.
+		 */
+		virtual void download(const PixelData& data);
+
+		/**
+		 * @brief	Binds the buffers to a frame buffer object at the specified attachment point.
+		 *
+		 * @param	attachment	Attachment point index in the range [0, BS_MAX_MULTIPLE_RENDER_TARGETS).
+		 * @param	zoffset		Depth slice to bind, in the case of a 3D texture.
+		 */
+		virtual void bindToFramebuffer(GLenum attachment, UINT32 zoffset);
 
-		virtual void blitFromTexture(GLTextureBuffer *src);
-		virtual void blitFromTexture(GLTextureBuffer *src, const PixelVolume &srcBox, const PixelVolume &dstBox);
+		/**
+		 * @brief	Returns internal OpenGL pixel format used by the buffer.
+		 */
+		GLenum getGLFormat() { return mGLInternalFormat; }
+
+		/**
+		 * @brief	Blits the contents of the provided buffer into this pixel buffer.
+		 *			Data is bilinearily interpolated in case buffer sizes don't match.
+		 */
+		virtual void blitFromTexture(GLTextureBuffer* src);
+
+		/**
+		 * @brief	Blits contents of a sub-region of the provided buffer into a sub-region of this pixel buffer.
+		 *			Data is bilinearily interpolated in case source and destination sizes don't match.
+		 */
+		virtual void blitFromTexture(GLTextureBuffer* src, const PixelVolume& srcBox, const PixelVolume& dstBox);
 
 	protected:  
-		/// Lock a box
-		PixelData lockImpl(PixelVolume lockBox,  GpuLockOptions options);
+		/**
+		 * @copydoc	PixelBuffer::lockImpl
+		 */
+		PixelData lockImpl(PixelVolume lockBox, GpuLockOptions options);
 
-		/// Unlock a box
-		void unlockImpl(void);
-        
-		// Internal buffer; either on-card or in system memory, freed/allocated on demand
-		// depending on buffer usage
-		PixelData mBuffer;
-        GLenum mGLInternalFormat; // GL internal format
-		GpuLockOptions mCurrentLockOptions;
-		
-		// Buffer allocation/freeage
+		/**
+		 * @copydoc	PixelBuffer::unlockImpl
+		 */
+		void unlockImpl();
+
+		/**
+		 * @brief	Allocates an internal buffer on the CPU, the size of the hardware buffer.
+		 */
 		void allocateBuffer();
+
+		/**
+		 * @brief	Deallocates the internal CPU buffer.
+		 */
 		void freeBuffer();
-	public:
-        /// Should be called by HardwareBufferManager
-        GLPixelBuffer(UINT32 mWidth, UINT32 mHeight, UINT32 mDepth,
-                PixelFormat mFormat,
-                GpuBufferUsage usage);
-		
-		~GLPixelBuffer();
-        
-        /** Bind surface to frame buffer. Needs FBO extension.
-        */
-        virtual void bindToFramebuffer(GLenum attachment, UINT32 zoffset);
-        GLenum getGLFormat() { return mGLInternalFormat; }
+
+	protected:
+		PixelData mBuffer;
+		GLenum mGLInternalFormat;
+		GpuLockOptions mCurrentLockOptions;
 	};
 
-    /** Texture surface.
-    */
-    class BS_RSGL_EXPORT GLTextureBuffer: public GLPixelBuffer
+	/**
+	 * @brief	Pixel buffer specialization that represents a single surface in a texture.
+	 */
+    class BS_RSGL_EXPORT GLTextureBuffer : public GLPixelBuffer
 	{
     public:
-        /** Texture constructor */
-		GLTextureBuffer(const String &baseName, GLenum target, GLuint id, GLint face, 
-			GLint level, GpuBufferUsage usage, bool softwareMipmap, bool writeGamma, UINT32 multisampleCount);
+		/**
+		 * @brief	Constructs a new texture buffer from a specific surface in the provided texture.
+		 *
+		 * @param	target				OpenGL type of the texture to retrieve the surface from.
+		 * @param	id					OpenGL handle to the texture to retrieve the surface from.
+		 * @param	face				Face index of the texture in the case of cube textures or texture arrays.
+		 * @param	level				Mip level of the texture.
+		 * @param	usage				Usage signaling the render system how we plan on using the buffer.
+		 * @param	writeGamma			True if the parent texture was created with SRGB support.
+		 * @param	multisampleCount	Number of samples the parent texture was created with.
+		 */
+		GLTextureBuffer(GLenum target, GLuint id, GLint face, 
+			GLint level, GpuBufferUsage usage, bool writeGamma, UINT32 multisampleCount);
         ~GLTextureBuffer();
         
-        /// @copydoc HardwarePixelBuffer::bindToFramebuffer
+		/**
+		 * @copydoc	GLPixelBuffer::bindToFramebuffer
+		 */
         virtual void bindToFramebuffer(GLenum attachment, UINT32 zoffset);
-        /// Upload a box of pixels to this buffer on the card
+
+		/**
+		 * @copydoc	GLPixelBuffer::upload
+		 */
 		virtual void upload(const PixelData &data, const PixelVolume &dest);
-		// Download a box of pixels from the card
+
+		/**
+		 * @copydoc	GLPixelBuffer::download
+		 */
 		virtual void download(const PixelData &data);
   
-        /// Copy from framebuffer
+		/**
+		 * @copydoc	GLPixelBuffer::blitFromTexture
+		 */
+		void blitFromTexture(GLTextureBuffer *src, const PixelVolume &srcBox, const PixelVolume &dstBox);
+
+        /**
+         * @brief	Populate texture buffer with the data in the currently attached frame buffer.
+		 *
+		 * @param	zoffset		3D slice of the texture to copy to. 0 if texture is not 3D.
+         */
         void copyFromFramebuffer(UINT32 zoffset);
 
-		void blitFromTexture(GLTextureBuffer *src, const PixelVolume &srcBox, const PixelVolume &dstBox);
     protected:
-        // In case this is a texture level
 		GLenum mTarget;
-		GLenum mFaceTarget; // same as mTarget in case of GL_TEXTURE_xD, but cubemap face for cubemaps
+		GLenum mFaceTarget;
 		GLuint mTextureID;
 		GLint mFace;
 		GLint mLevel;
-		bool mSoftwareMipmap;		// Use GLU for mip mapping
     };
-     /** Renderbuffer surface.  Needs FBO extension.
-     */
-    class BS_RSGL_EXPORT GLRenderBuffer: public GLPixelBuffer
+
+	/**
+	 * @brief	Pixel buffer specialization that represents a render buffer.
+	 */
+    class BS_RSGL_EXPORT GLRenderBuffer : public GLPixelBuffer
 	{
     public:
+		/**
+		 * @brief	Initializes a new render buffer.
+		 *
+		 * @param	format		OpenGL pixel format.
+		 * @param	width		Width of the render buffer in pixels.
+		 * @param	height		Height of the render buffer in pixels.
+		 * @param	numSamples	Number of samples to support.
+		 */
         GLRenderBuffer(GLenum format, UINT32 width, UINT32 height, GLsizei numSamples);
         ~GLRenderBuffer();
         
-        /// @copydoc GLHardwarePixelBuffer::bindToFramebuffer
+		/**
+		 * @copydoc	GLPixelBuffer::bindToFramebuffer
+		 */
         virtual void bindToFramebuffer(GLenum attachment, UINT32 zoffset);
     protected:
-        // In case this is a render buffer
         GLuint mRenderbufferID;
     };
 };

+ 18 - 63
BansheeGLRenderSystem/Source/BsGLFrameBufferObject.cpp

@@ -5,34 +5,16 @@
 
 namespace BansheeEngine 
 {
-    GLFrameBufferObject::GLFrameBufferObject(UINT32 multisampleCount)
-		:mNumSamples(multisampleCount)
+    GLFrameBufferObject::GLFrameBufferObject()
     {
-        /// Generate framebuffer object
         glGenFramebuffersEXT(1, &mFB);
-		// check multisampling
-		if (GLEW_EXT_framebuffer_blit && GLEW_EXT_framebuffer_multisample)
-		{
-			// check samples supported
-			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFB);
-			GLint maxSamples;
-			glGetIntegerv(GL_MAX_SAMPLES_EXT, &maxSamples);
-			glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-			mNumSamples = std::min(mNumSamples, (GLsizei)maxSamples);
-		}
-		else
-		{
-			mNumSamples = 0;
-		}
 
-        /// Initialise state
         for(UINT32 x = 0; x < BS_MAX_MULTIPLE_RENDER_TARGETS; ++x)
             mColor[x].buffer = nullptr;
     }
 
     GLFrameBufferObject::~GLFrameBufferObject()
     {
-        /// Delete framebuffer object
         glDeleteFramebuffersEXT(1, &mFB);        
     }
 
@@ -41,9 +23,8 @@ namespace BansheeEngine
         assert(attachment < BS_MAX_MULTIPLE_RENDER_TARGETS);
         mColor[attachment] = target;
 
-		// Re-initialise
 		if(mColor[0].buffer)
-			initialize();
+			rebuild();
     }
 
     void GLFrameBufferObject::unbindSurface(UINT32 attachment)
@@ -51,11 +32,8 @@ namespace BansheeEngine
         assert(attachment < BS_MAX_MULTIPLE_RENDER_TARGETS);
         mColor[attachment].buffer = nullptr;
 
-		// Re-initialise if buffer 0 still bound
 		if(mColor[0].buffer)
-		{
-			initialize();
-		}
+			rebuild();
     }
 
 	void GLFrameBufferObject::bindDepthStencil(GLPixelBufferPtr depthStencilBuffer)
@@ -68,23 +46,23 @@ namespace BansheeEngine
 		mDepthStencilBuffer = nullptr;
 	}
 
-    void GLFrameBufferObject::initialize()
+    void GLFrameBufferObject::rebuild()
     {
-        /// First buffer must be bound
+        // First buffer must be bound
         if(!mColor[0].buffer)
 			BS_EXCEPT(InvalidParametersException, "Attachment 0 must have surface attached");
 
-        /// Store basic stats
+        // Store basic stats
         UINT32 width = mColor[0].buffer->getWidth();
         UINT32 height = mColor[0].buffer->getHeight();
         GLuint glformat = mColor[0].buffer->getGLFormat();
         PixelFormat format = mColor[0].buffer->getFormat();
         UINT16 maxSupportedMRTs = BansheeEngine::RenderSystem::instancePtr()->getCapabilities()->getNumMultiRenderTargets();
 
-		// Bind simple buffer to add colour attachments
+		// Bind simple buffer to add color attachments
 		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFB);
 
-        /// Bind all attachment points to frame buffer
+        // Bind all attachment points to frame buffer
         for(UINT16 x = 0; x < maxSupportedMRTs; ++x)
         {
             if(mColor[x].buffer)
@@ -107,20 +85,19 @@ namespace BansheeEngine
                     BS_EXCEPT(InvalidParametersException, ss.str());
                 }
 
-	            mColor[x].buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0_EXT+x, mColor[x].zoffset);
+	            mColor[x].buffer->bindToFramebuffer(GL_COLOR_ATTACHMENT0_EXT + x, mColor[x].zoffset);
             }
             else
             {
                 // Detach
-                glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT+x,
-                    GL_RENDERBUFFER_EXT, 0);
+                glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + x, GL_RENDERBUFFER_EXT, 0);
             }
         }
 
 		if(mDepthStencilBuffer != nullptr)
 			mDepthStencilBuffer->bindToFramebuffer(GL_DEPTH_STENCIL_ATTACHMENT, 0);
 
-		/// Do glDrawBuffer calls
+		// Do glDrawBuffer calls
 		GLenum bufs[BS_MAX_MULTIPLE_RENDER_TARGETS];
 		GLsizei n=0;
 		for(UINT32 x=0; x<BS_MAX_MULTIPLE_RENDER_TARGETS; ++x)
@@ -140,60 +117,38 @@ namespace BansheeEngine
 
 		if(glDrawBuffers)
 		{
-			/// Drawbuffer extension supported, use it
+			// Drawbuffer extension supported, use it
 			glDrawBuffers(n, bufs);
 		}
 		else
 		{
-			/// In this case, the capabilities will not show more than 1 simultaneaous render target.
+			// In this case, the capabilities will not show more than 1 simultaneaous render target.
 			glDrawBuffer(bufs[0]);
 		}
 
-		/// No read buffer, by default, if we want to read anyway we must not forget to set this.
+		// No read buffer, by default, if we want to read anyway we must not forget to set this.
 		glReadBuffer(GL_NONE);
 
-        /// Check status
+        // Check status
         GLuint status;
         status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
         
-        /// Bind main buffer
+        // Bind main buffer
         glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
         
         switch(status)
         {
         case GL_FRAMEBUFFER_COMPLETE_EXT:
-            // All is good
             break;
         case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
-            BS_EXCEPT(InvalidParametersException, 
-            "All framebuffer formats with this texture internal format unsupported");
+            BS_EXCEPT(InvalidParametersException, "All framebuffer formats with this texture internal format unsupported");
         default:
-            BS_EXCEPT(InvalidParametersException, 
-            "Framebuffer incomplete or other FBO status error");
+            BS_EXCEPT(InvalidParametersException, "Framebuffer incomplete or other FBO status error");
         }
     }
 
     void GLFrameBufferObject::bind()
     {
-        /// Bind it to FBO
 		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, mFB);
     }
-
-    UINT32 GLFrameBufferObject::getWidth()
-    {
-        assert(mColor[0].buffer);
-        return mColor[0].buffer->getWidth();
-    }
-
-    UINT32 GLFrameBufferObject::getHeight()
-    {
-        assert(mColor[0].buffer);
-        return mColor[0].buffer->getHeight();
-    }
-
-    PixelFormat GLFrameBufferObject::getFormat()
-    {
-        assert(mColor[0].buffer);
-        return mColor[0].buffer->getFormat();
-    }
 }

+ 2 - 162
BansheeGLRenderSystem/Source/BsGLHardwareBufferManager.cpp

@@ -9,50 +9,6 @@
 
 namespace BansheeEngine 
 {
-	struct GLScratchBufferAlloc
-	{
-		/// Size in bytes
-		UINT32 size: 31;
-		/// Free? (pack with size)
-		UINT32 free: 1;
-	};
-
-	#define SCRATCH_POOL_SIZE 1 * 1024 * 1024
-	#define SCRATCH_ALIGNMENT 32
-
-    GLHardwareBufferManager::GLHardwareBufferManager() 
-		: mScratchBufferPool(NULL), mMapBufferThreshold(BS_GL_DEFAULT_MAP_BUFFER_THRESHOLD)
-    {
-		// Init scratch pool
-		// TODO make it a configurable size?
-		// 32-bit aligned buffer
-		mScratchBufferPool = static_cast<char*>(_aligned_malloc(SCRATCH_POOL_SIZE, SCRATCH_ALIGNMENT));
-		GLScratchBufferAlloc* ptrAlloc = (GLScratchBufferAlloc*)mScratchBufferPool;
-		ptrAlloc->size = SCRATCH_POOL_SIZE - sizeof(GLScratchBufferAlloc);
-		ptrAlloc->free = 1;
-
-		// non-Win32 machines are having issues glBufferSubData, looks like buffer corruption
-		// disable for now until we figure out where the problem lies			
-#	if BS_PLATFORM != BS_PLATFORM_WIN32
-		mMapBufferThreshold = 0;
-#	endif
-
-		// Win32 machines with ATI GPU are having issues glMapBuffer, looks like buffer corruption
-		// disable for now until we figure out where the problem lies			
-#	if BS_PLATFORM == BS_PLATFORM_WIN32
-		if (BansheeEngine::RenderSystem::instancePtr()->getCapabilities()->getVendor() == GPU_AMD) 
-		{
-			mMapBufferThreshold = 0xffffffffUL  /* maximum unsigned long value */;
-		}
-#	endif
-
-    }
-
-    GLHardwareBufferManager::~GLHardwareBufferManager()
-    {
-		_aligned_free(mScratchBufferPool);
-    }
-
     VertexBufferPtr GLHardwareBufferManager::createVertexBufferImpl(
         UINT32 vertexSize, UINT32 numVerts, GpuBufferUsage usage, bool streamOut)
     {
@@ -75,7 +31,7 @@ namespace BansheeEngine
 		return bs_core_ptr<GLGpuBuffer, PoolAlloc>(new (bs_alloc<GLGpuBuffer, PoolAlloc>()) GLGpuBuffer(elementCount, elementSize, type, usage, randomGpuWrite, useCounter));
 	}
 
-    GLenum GLHardwareBufferManager::getGLUsage(unsigned int usage)
+    GLenum GLHardwareBufferManager::getGLUsage(GpuBufferUsage usage)
     {
         switch(usage)
         {
@@ -88,7 +44,7 @@ namespace BansheeEngine
         };
     }
 
-    GLenum GLHardwareBufferManager::getGLType(unsigned int type)
+    GLenum GLHardwareBufferManager::getGLType(VertexElementType type)
     {
         switch(type)
         {
@@ -111,120 +67,4 @@ namespace BansheeEngine
                 return 0;
         };
     }
-
-	void* GLHardwareBufferManager::allocateScratch(UINT32 size)
-	{
-		// simple forward link search based on alloc sizes
-		// not that fast but the list should never get that long since not many
-		// locks at once (hopefully)
-		BS_LOCK_MUTEX(mScratchMutex)
-
-
-		// Alignment - round up the size to 32 bits
-		// control blocks are 32 bits too so this packs nicely
-		if (size % 4 != 0)
-		{
-			size += 4 - (size % 4);
-		}
-
-		UINT32 bufferPos = 0;
-		while (bufferPos < SCRATCH_POOL_SIZE)
-		{
-			GLScratchBufferAlloc* pNext = (GLScratchBufferAlloc*)(mScratchBufferPool + bufferPos);
-			// Big enough?
-			if (pNext->free && pNext->size >= size)
-			{
-				// split? And enough space for control block
-				if(pNext->size > size + sizeof(GLScratchBufferAlloc))
-				{
-					UINT32 offset = (UINT32)sizeof(GLScratchBufferAlloc) + size;
-
-					GLScratchBufferAlloc* pSplitAlloc = (GLScratchBufferAlloc*)
-						(mScratchBufferPool + bufferPos + offset);
-					pSplitAlloc->free = 1;
-					// split size is remainder minus new control block
-					pSplitAlloc->size = pNext->size - size - sizeof(GLScratchBufferAlloc);
-
-					// New size of current
-					pNext->size = size;
-				}
-				// allocate and return
-				pNext->free = 0;
-
-				// return pointer just after this control block (++ will do that for us)
-				return ++pNext;
-
-			}
-
-			bufferPos += (UINT32)sizeof(GLScratchBufferAlloc) + pNext->size;
-
-		}
-
-		// no available alloc
-		return 0;
-
-	}
-
-	void GLHardwareBufferManager::deallocateScratch(void* ptr)
-	{
-		BS_LOCK_MUTEX(mScratchMutex)
-
-		// Simple linear search dealloc
-		UINT32 bufferPos = 0;
-		GLScratchBufferAlloc* pLast = 0;
-		while (bufferPos < SCRATCH_POOL_SIZE)
-		{
-			GLScratchBufferAlloc* pCurrent = (GLScratchBufferAlloc*)(mScratchBufferPool + bufferPos);
-			
-			// Pointers match?
-			if ((mScratchBufferPool + bufferPos + sizeof(GLScratchBufferAlloc))
-				== ptr)
-			{
-				// dealloc
-				pCurrent->free = 1;
-				
-				// merge with previous
-				if (pLast && pLast->free)
-				{
-					// adjust buffer pos
-					bufferPos -= (pLast->size + (UINT32)sizeof(GLScratchBufferAlloc));
-					// merge free space
-					pLast->size += pCurrent->size + sizeof(GLScratchBufferAlloc);
-					pCurrent = pLast;
-				}
-
-				// merge with next
-				UINT32 offset = bufferPos + pCurrent->size + (UINT32)sizeof(GLScratchBufferAlloc);
-				if (offset < SCRATCH_POOL_SIZE)
-				{
-					GLScratchBufferAlloc* pNext = (GLScratchBufferAlloc*)(
-						mScratchBufferPool + offset);
-					if (pNext->free)
-					{
-						pCurrent->size += pNext->size + sizeof(GLScratchBufferAlloc);
-					}
-				}
-
-				// done
-				return;
-			}
-
-			bufferPos += (UINT32)sizeof(GLScratchBufferAlloc) + pCurrent->size;
-			pLast = pCurrent;
-
-		}
-
-		// Should never get here unless there's a corruption
-		assert (false && "Memory deallocation error");
-	}
-
-	const UINT32 GLHardwareBufferManager::getGLMapBufferThreshold() const
-	{
-		return mMapBufferThreshold;
-	}
-
-	void GLHardwareBufferManager::setGLMapBufferThreshold(const UINT32 value)
-	{
-		mMapBufferThreshold = value;
-	}
 }

+ 0 - 1
BansheeGLRenderSystem/Source/BsGLIndexBuffer.cpp

@@ -23,7 +23,6 @@ namespace BansheeEngine
 
 		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mBufferId);
 
-		// Initialise buffer and set usage
 		glBufferData(GL_ELEMENT_ARRAY_BUFFER, mSizeInBytes, NULL, 
 			GLHardwareBufferManager::getGLUsage(mUsage));
 

+ 1 - 1
BansheeGLRenderSystem/Source/BsGLMultiRenderTexture.cpp

@@ -19,7 +19,7 @@ namespace BansheeEngine
 		if(mFB != nullptr)
 			bs_delete(mFB);
 
-		mFB = bs_new<GLFrameBufferObject, PoolAlloc>(mMultisampleCount);
+		mFB = bs_new<GLFrameBufferObject, PoolAlloc>();
 
 		for(size_t i = 0; i < mColorSurfaces.size(); i++)
 		{

+ 42 - 239
BansheeGLRenderSystem/Source/BsGLPixelBuffer.cpp

@@ -9,24 +9,22 @@
 namespace BansheeEngine 
 {
 	GLPixelBuffer::GLPixelBuffer(UINT32 inWidth, UINT32 inHeight, UINT32 inDepth,
-					PixelFormat inFormat, GpuBufferUsage usage):
-		  PixelBuffer(inWidth, inHeight, inDepth, inFormat, usage, false),
-		  mBuffer(inWidth, inHeight, inDepth, inFormat),
-		  mGLInternalFormat(GL_NONE)
+					PixelFormat inFormat, GpuBufferUsage usage)
+					: PixelBuffer(inWidth, inHeight, inDepth, inFormat, usage, false),
+					  mBuffer(inWidth, inHeight, inDepth, inFormat),
+					  mGLInternalFormat(GL_NONE)
 	{
 		mCurrentLockOptions = (GpuLockOptions)0;
 	}
 
 	GLPixelBuffer::~GLPixelBuffer()
 	{
-		// Force free buffer
 		mBuffer.freeInternalBuffer();
 	}
 
 	void GLPixelBuffer::allocateBuffer()
 	{
 		if(mBuffer.getData())
-			// Already allocated
 			return;
 
 		mBuffer.allocateInternalBuffer();
@@ -35,21 +33,22 @@ namespace BansheeEngine
 
 	void GLPixelBuffer::freeBuffer()
 	{
-		// Free buffer if we're STATIC to save memory
 		if(mUsage & GBU_STATIC)
 		{
 			mBuffer.freeInternalBuffer();
 		}
 	}
 
-	PixelData GLPixelBuffer::lockImpl(PixelVolume lockBox,  GpuLockOptions options)
+	PixelData GLPixelBuffer::lockImpl(PixelVolume lockBox, GpuLockOptions options)
 	{
 		allocateBuffer();
+
 		if(options != GBL_WRITE_ONLY_DISCARD) 
 		{
 			// Download the old contents of the texture
 			download(mBuffer);
 		}
+
 		mCurrentLockOptions = options;
 		mLockedBox = lockBox;
 		return mBuffer.getSubVolume(lockBox);
@@ -66,46 +65,43 @@ namespace BansheeEngine
 		freeBuffer();
 	}
 
-	void GLPixelBuffer::upload(const PixelData &data, const PixelVolume &dest)
+	void GLPixelBuffer::upload(const PixelData& data, const PixelVolume& dest)
 	{
-		BS_EXCEPT(RenderingAPIException, 
-			"Upload not possible for this pixelbuffer type");
+		BS_EXCEPT(RenderingAPIException, "Upload not possible for this pixel buffer type");
 	}
 
-	void GLPixelBuffer::download(const PixelData &data)
+	void GLPixelBuffer::download(const PixelData& data)
 	{
-		BS_EXCEPT(RenderingAPIException, "Download not possible for this pixelbuffer type");
+		BS_EXCEPT(RenderingAPIException, "Download not possible for this pixel buffer type");
 	}
 
-	void GLPixelBuffer::blitFromTexture(GLTextureBuffer *src)
+	void GLPixelBuffer::blitFromTexture(GLTextureBuffer* src)
 	{
 		blitFromTexture(src, 
-			PixelVolume(0,0,0,src->getWidth(),src->getHeight(),src->getDepth()), 
-			PixelVolume(0,0,0,mWidth,mHeight,mDepth)
+			PixelVolume(0, 0, 0, src->getWidth(), src->getHeight(), src->getDepth()), 
+			PixelVolume(0, 0, 0, mWidth, mHeight, mDepth)
 			);
 	}
 
-	void GLPixelBuffer::blitFromTexture(GLTextureBuffer *src, const PixelVolume &srcBox, const PixelVolume &dstBox)
+	void GLPixelBuffer::blitFromTexture(GLTextureBuffer* src, const PixelVolume& srcBox, const PixelVolume& dstBox)
 	{
-		BS_EXCEPT(RenderingAPIException, "BlitFromTexture not possible for this pixelbuffer type");
+		BS_EXCEPT(RenderingAPIException, "BlitFromTexture not possible for this pixel buffer type");
 	}
 
 	void GLPixelBuffer::bindToFramebuffer(GLenum attachment, UINT32 zoffset)
 	{
-		BS_EXCEPT(RenderingAPIException, "Framebuffer bind not possible for this pixelbuffer type");
+		BS_EXCEPT(RenderingAPIException, "Framebuffer bind not possible for this pixel buffer type");
 	}
 
-	GLTextureBuffer::GLTextureBuffer(const String &baseName, GLenum target, GLuint id, 
-									 GLint face, GLint level, GpuBufferUsage usage, bool crappyCard, 
+	GLTextureBuffer::GLTextureBuffer(GLenum target, GLuint id, 
+									 GLint face, GLint level, GpuBufferUsage usage, 
 									 bool writeGamma, UINT32 multisampleCount):
 		GLPixelBuffer(0, 0, 0, PF_UNKNOWN, usage),
-		mTarget(target), mFaceTarget(0), mTextureID(id), mFace(face), mLevel(level),
-		mSoftwareMipmap(crappyCard)
+		mTarget(target), mFaceTarget(0), mTextureID(id), mFace(face), mLevel(level)
 	{
-		// devise mWidth, mHeight and mDepth and mFormat
 		GLint value = 0;
 	
-		glBindTexture( mTarget, mTextureID );
+		glBindTexture(mTarget, mTextureID);
 	
 		// Get face identifier
 		mFaceTarget = mTarget;
@@ -142,10 +138,6 @@ namespace BansheeEngine
 	
 		// Set up pixel box
 		mBuffer = PixelData(mWidth, mHeight, mDepth, mFormat);
-	
-		if(mWidth==0 || mHeight==0 || mDepth==0)
-			/// We are invalid, do not allocate a buffer
-			return;
 	}
 
 	GLTextureBuffer::~GLTextureBuffer()
@@ -162,13 +154,10 @@ namespace BansheeEngine
 			if(data.getFormat() != mFormat || !data.isConsecutive())
 				BS_EXCEPT(InvalidParametersException, 
 				"Compressed images must be consecutive, in the source format");
+
 			GLenum format = GLPixelUtil::getClosestGLInternalFormat(mFormat);
-			// Data must be consecutive and at beginning of buffer as PixelStorei not allowed
-			// for compressed formats
 			switch(mTarget) {
 				case GL_TEXTURE_1D:
-					// some systems (e.g. old Apple) don't like compressed subimage calls
-					// so prefer non-sub versions
 					if (dest.left == 0)
 					{
 						glCompressedTexImage1D(GL_TEXTURE_1D, mLevel,
@@ -189,8 +178,6 @@ namespace BansheeEngine
 					break;
 				case GL_TEXTURE_2D:
 				case GL_TEXTURE_CUBE_MAP:
-					// some systems (e.g. old Apple) don't like compressed subimage calls
-					// so prefer non-sub versions
 					if (dest.left == 0 && dest.top == 0)
 					{
 						glCompressedTexImage2D(mFaceTarget, mLevel,
@@ -211,8 +198,6 @@ namespace BansheeEngine
 					}
 					break;
 				case GL_TEXTURE_3D:
-					// some systems (e.g. old Apple) don't like compressed subimage calls
-					// so prefer non-sub versions
 					if (dest.left == 0 && dest.top == 0 && dest.front == 0)
 					{
 						glCompressedTexImage3D(GL_TEXTURE_3D, mLevel,
@@ -240,14 +225,16 @@ namespace BansheeEngine
 		{
 			if(data.getWidth() != data.getRowPitch())
 				glPixelStorei(GL_UNPACK_ROW_LENGTH, data.getRowPitch());
+
 			if(data.getHeight()*data.getWidth() != data.getSlicePitch())
 				glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, (data.getSlicePitch()/data.getWidth()));
+
 			if(data.getLeft() > 0 || data.getTop() > 0 || data.getFront() > 0)
 				glPixelStorei(GL_UNPACK_SKIP_PIXELS, data.getLeft() + data.getRowPitch() * data.getTop() + data.getSlicePitch() * data.getFront());
-			if((data.getWidth()*PixelUtil::getNumElemBytes(data.getFormat())) & 3) {
-				// Standard alignment of 4 is not right
+
+			if((data.getWidth()*PixelUtil::getNumElemBytes(data.getFormat())) & 3)
 				glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
-			}
+
 			switch(mTarget) {
 				case GL_TEXTURE_1D:
 					glTexSubImage1D(GL_TEXTURE_1D, mLevel, 
@@ -274,10 +261,10 @@ namespace BansheeEngine
 					break;
 			}	
 		}
+
 		// Restore defaults
 		glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
-		if (GLEW_VERSION_1_2)
-			glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
+		glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
 		glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
 		glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
 	}
@@ -290,16 +277,16 @@ namespace BansheeEngine
 		if((mUsage & TU_DEPTHSTENCIL) != 0)
 			BS_EXCEPT(NotImplementedException, "Reading from depth stencil texture to CPU not supported."); // TODO: This needs to be implemented
 
-		if(data.getWidth() != getWidth() ||
-			data.getHeight() != getHeight() ||
-			data.getDepth() != getDepth())
+		if(data.getWidth() != getWidth() || data.getHeight() != getHeight() || data.getDepth() != getDepth())
 			BS_EXCEPT(InvalidParametersException, "only download of entire buffer is supported by GL");
+
 		glBindTexture( mTarget, mTextureID );
 		if(PixelUtil::isCompressed(data.getFormat()))
 		{
 			if(data.getFormat() != mFormat || !data.isConsecutive())
 				BS_EXCEPT(InvalidParametersException, 
 				"Compressed images must be consecutive, in the source format");
+
 			// Data must be consecutive and at beginning of buffer as PixelStorei not allowed
 			// for compressed formate
 			glGetCompressedTexImage(mFaceTarget, mLevel, data.getData());
@@ -308,18 +295,20 @@ namespace BansheeEngine
 		{
 			if(data.getWidth() != data.getRowPitch())
 				glPixelStorei(GL_PACK_ROW_LENGTH, data.getRowPitch());
+
 			if(data.getHeight()*data.getWidth() != data.getSlicePitch())
 				glPixelStorei(GL_PACK_IMAGE_HEIGHT, (data.getSlicePitch()/data.getWidth()));
+
 			if(data.getLeft() > 0 || data.getTop() > 0 || data.getFront() > 0)
 				glPixelStorei(GL_PACK_SKIP_PIXELS, data.getLeft() + data.getRowPitch() * data.getTop() + data.getSlicePitch() * data.getFront());
-			if((data.getWidth()*PixelUtil::getNumElemBytes(data.getFormat())) & 3) {
-				// Standard alignment of 4 is not right
+
+			if((data.getWidth()*PixelUtil::getNumElemBytes(data.getFormat())) & 3)
 				glPixelStorei(GL_PACK_ALIGNMENT, 1);
-			}
+
 			// We can only get the entire texture
-			glGetTexImage(mFaceTarget, mLevel, 
-				GLPixelUtil::getGLOriginFormat(data.getFormat()), GLPixelUtil::getGLOriginDataType(data.getFormat()),
-				data.getData());
+			glGetTexImage(mFaceTarget, mLevel, GLPixelUtil::getGLOriginFormat(data.getFormat()), 
+				GLPixelUtil::getGLOriginDataType(data.getFormat()), data.getData());
+
 			// Restore defaults
 			glPixelStorei(GL_PACK_ROW_LENGTH, 0);
 			glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
@@ -372,192 +361,9 @@ namespace BansheeEngine
 		}
 	}
 
-	/// Very fast texture-to-texture blitter and hardware bi/trilinear scaling implementation using FBO
-	/// Destination texture must be 1D, 2D, 3D, or Cube
-	/// Source texture must be 1D, 2D or 3D
-	/// Supports compressed formats as both source and destination format, it will use the hardware DXT compressor
-	/// if available.
-	/// @author W.J. van der Laan
-	void GLTextureBuffer::blitFromTexture(GLTextureBuffer *src, const PixelVolume &srcBox, const PixelVolume &dstBox)
+	void GLTextureBuffer::blitFromTexture(GLTextureBuffer* src, const PixelVolume& srcBox, const PixelVolume& dstBox)
 	{
-		//std::cerr << "GLTextureBuffer::blitFromTexture " <<
-		//src->mTextureID << ":" << srcBox.left << "," << srcBox.top << "," << srcBox.right << "," << srcBox.bottom << " " << 
-		//mTextureID << ":" << dstBox.left << "," << dstBox.top << "," << dstBox.right << "," << dstBox.bottom << std::endl;
-		/// Store reference to FBO manager
-		GLRTTManager *fboMan = static_cast<GLRTTManager *>(GLRTTManager::instancePtr());
-
-		/// Save and clear GL state for rendering
-		glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | 
-			GL_FOG_BIT | GL_LIGHTING_BIT | GL_POLYGON_BIT | GL_SCISSOR_BIT | GL_STENCIL_BUFFER_BIT |
-			GL_TEXTURE_BIT | GL_VIEWPORT_BIT);
-
-		// Important to disable all other texture units
-		if (GLEW_VERSION_1_2)
-		{
-			glActiveTextureARB(GL_TEXTURE0);
-		}
-
-
-		/// Disable alpha, depth and scissor testing, disable blending, 
-		/// disable culling, disble lighting, disable fog and reset foreground
-		/// colour.
-		glDisable(GL_ALPHA_TEST);
-		glDisable(GL_DEPTH_TEST);
-		glDisable(GL_SCISSOR_TEST);
-		glDisable(GL_BLEND);
-		glDisable(GL_CULL_FACE);
-		glDisable(GL_LIGHTING);
-		glDisable(GL_FOG);
-		glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
-
-		/// Save and reset matrices
-		glMatrixMode(GL_MODELVIEW);
-		glPushMatrix();
-		glLoadIdentity();
-		glMatrixMode(GL_PROJECTION);
-		glPushMatrix();
-		glLoadIdentity();
-		glMatrixMode(GL_TEXTURE);
-		glPushMatrix();
-		glLoadIdentity();
-
-		/// Set up source texture
-		glBindTexture(src->mTarget, src->mTextureID);
-
-		/// Set filtering modes depending on the dimensions and source
-		if(srcBox.getWidth()==dstBox.getWidth() &&
-			srcBox.getHeight()==dstBox.getHeight() &&
-			srcBox.getDepth()==dstBox.getDepth())
-		{
-			/// Dimensions match -- use nearest filtering (fastest and pixel correct)
-			glTexParameteri(src->mTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-			glTexParameteri(src->mTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-		}
-		else
-		{
-			/// Manual mipmaps, stay safe with bilinear filtering so that no
-			/// intermipmap leakage occurs.
-			glTexParameteri(src->mTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-			glTexParameteri(src->mTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-		}
-		/// Clamp to edge (fastest)
-		glTexParameteri(src->mTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-		glTexParameteri(src->mTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-		glTexParameteri(src->mTarget, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
-
-		/// Set origin base level mipmap to make sure we source from the right mip
-		/// level.
-		glTexParameteri(src->mTarget, GL_TEXTURE_BASE_LEVEL, src->mLevel);
-
-		/// Store old binding so it can be restored later
-		GLint oldfb;
-		glGetIntegerv(GL_FRAMEBUFFER_BINDING_EXT, &oldfb);
-
-		/// Set up temporary FBO
-		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboMan->getTemporaryFBO());
-
-		GLuint tempTex = 0;
-		if(!fboMan->checkFormat(mFormat))
-		{
-			/// If target format not directly supported, create intermediate texture
-			GLenum tempFormat = GLPixelUtil::getClosestGLInternalFormat(fboMan->getSupportedAlternative(mFormat));
-			glGenTextures(1, &tempTex);
-			glBindTexture(GL_TEXTURE_2D, tempTex);
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
-			/// Allocate temporary texture of the size of the destination area
-			glTexImage2D(GL_TEXTURE_2D, 0, tempFormat, 
-				GLPixelUtil::optionalPO2(dstBox.getWidth()), GLPixelUtil::optionalPO2(dstBox.getHeight()), 
-				0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
-			glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
-				GL_TEXTURE_2D, tempTex, 0);
-			/// Set viewport to size of destination slice
-			glViewport(0, 0, dstBox.getWidth(), dstBox.getHeight());
-		}
-		else
-		{
-			/// We are going to bind directly, so set viewport to size and position of destination slice
-			glViewport(dstBox.left, dstBox.top, dstBox.getWidth(), dstBox.getHeight());
-		}
-
-		/// Process each destination slice
-		for(UINT32 slice=dstBox.front; slice<dstBox.back; ++slice)
-		{
-			if(!tempTex)
-			{
-				/// Bind directly
-				bindToFramebuffer(GL_COLOR_ATTACHMENT0_EXT, slice);
-			}
-			/// Calculate source texture coordinates
-			float u1 = (float)srcBox.left / (float)src->mWidth;
-			float v1 = (float)srcBox.top / (float)src->mHeight;
-			float u2 = (float)srcBox.right / (float)src->mWidth;
-			float v2 = (float)srcBox.bottom / (float)src->mHeight;
-			/// Calculate source slice for this destination slice
-			float w = (float)(slice - dstBox.front) / (float)dstBox.getDepth();
-			/// Get slice # in source
-			w = w * (float)(srcBox.getDepth() + srcBox.front);
-			/// Normalise to texture coordinate in 0.0 .. 1.0
-			w = (w+0.5f) / (float)src->mDepth;
-
-			/// Finally we're ready to rumble	
-			glBindTexture(src->mTarget, src->mTextureID);
-			glEnable(src->mTarget);
-			glBegin(GL_QUADS);
-			glTexCoord3f(u1, v1, w);
-			glVertex2f(-1.0f, -1.0f);
-			glTexCoord3f(u2, v1, w);
-			glVertex2f(1.0f, -1.0f);
-			glTexCoord3f(u2, v2, w);
-			glVertex2f(1.0f, 1.0f);
-			glTexCoord3f(u1, v2, w);
-			glVertex2f(-1.0f, 1.0f);
-			glEnd();
-			glDisable(src->mTarget);
-
-			if(tempTex)
-			{
-				/// Copy temporary texture
-				glBindTexture(mTarget, mTextureID);
-				switch(mTarget)
-				{
-				case GL_TEXTURE_1D:
-					glCopyTexSubImage1D(mFaceTarget, mLevel, 
-						dstBox.left, 
-						0, 0, dstBox.getWidth());
-					break;
-				case GL_TEXTURE_2D:
-				case GL_TEXTURE_CUBE_MAP:
-					glCopyTexSubImage2D(mFaceTarget, mLevel, 
-						dstBox.left, dstBox.top, 
-						0, 0, dstBox.getWidth(), dstBox.getHeight());
-					break;
-				case GL_TEXTURE_3D:
-					glCopyTexSubImage3D(mFaceTarget, mLevel, 
-						dstBox.left, dstBox.top, slice, 
-						0, 0, dstBox.getWidth(), dstBox.getHeight());
-					break;
-				}
-			}
-		}
-
-		/// Reset source texture to sane state
-		glBindTexture(src->mTarget, src->mTextureID);
-		glTexParameteri(src->mTarget, GL_TEXTURE_BASE_LEVEL, 0);
-
-		/// Detach texture from temporary framebuffer
-		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
-			GL_RENDERBUFFER_EXT, 0);
-		/// Restore old framebuffer
-		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, oldfb);
-		/// Restore matrix stacks and render state
-		glMatrixMode(GL_TEXTURE);
-		glPopMatrix();
-		glMatrixMode(GL_PROJECTION);
-		glPopMatrix();
-		glMatrixMode(GL_MODELVIEW);
-		glPopMatrix();
-		glPopAttrib();
-		glDeleteTextures(1, &tempTex);
+		BS_EXCEPT(NotImplementedException, "Not implemented.");
 	}
 	
 	GLRenderBuffer::GLRenderBuffer(GLenum format, UINT32 width, UINT32 height, GLsizei numSamples):
@@ -565,9 +371,7 @@ namespace BansheeEngine
 		mRenderbufferID(0)
 	{
 		mGLInternalFormat = format;
-		/// Generate renderbuffer
 		glGenRenderbuffersEXT(1, &mRenderbufferID);
-		/// Bind it to FBO
 		glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, mRenderbufferID);
     
 		/// Allocate storage for depth buffer
@@ -585,7 +389,6 @@ namespace BansheeEngine
 
 	GLRenderBuffer::~GLRenderBuffer()
 	{
-		/// Generate renderbuffer
 		glDeleteRenderbuffersEXT(1, &mRenderbufferID);
 	}
 

+ 1 - 1
BansheeGLRenderSystem/Source/BsGLRenderTexture.cpp

@@ -28,7 +28,7 @@ namespace BansheeEngine
 		if(mFB != nullptr)
 			bs_delete<PoolAlloc>(mFB);
 
-		mFB = bs_new<GLFrameBufferObject, PoolAlloc>(mMultisampleCount);
+		mFB = bs_new<GLFrameBufferObject, PoolAlloc>();
 
 		GLSurfaceDesc surfaceDesc;
 		surfaceDesc.numSamples = mMultisampleCount;

+ 2 - 2
BansheeGLRenderSystem/Source/BsGLTexture.cpp

@@ -251,8 +251,8 @@ namespace BansheeEngine
 		{
 			for(UINT32 mip=0; mip<=getNumMipmaps(); mip++)
 			{
-                GLPixelBuffer *buf = bs_new<GLTextureBuffer, PoolAlloc>("", getGLTextureTarget(), mTextureID, face, mip,
-						static_cast<GpuBufferUsage>(mUsage), false, mHwGamma, mMultisampleCount);
+                GLPixelBuffer *buf = bs_new<GLTextureBuffer, PoolAlloc>(getGLTextureTarget(), mTextureID, face, mip,
+						static_cast<GpuBufferUsage>(mUsage), mHwGamma, mMultisampleCount);
 				mSurfaceList.push_back(bs_shared_ptr<GLPixelBuffer, PoolAlloc>(buf));
                 
                 /// Check for error