1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4     (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2013 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 
29 #ifndef __GLES2HardwareBufferManager_H__
30 #define __GLES2HardwareBufferManager_H__
31 
32 #include "OgreGLES2Prerequisites.h"
33 #include "OgreHardwareBufferManager.h"
34 
35 namespace Ogre {
36 	class GLES2StateCacheManager;
37 
38     /** Implementation of HardwareBufferManager for OpenGL ES. */
39     class _OgreGLES2Export GLES2HardwareBufferManagerBase : public HardwareBufferManagerBase
40     {
41         protected:
42 			GLES2StateCacheManager* mStateCacheManager;
43             /// Internal method for creates a new vertex declaration, may be overridden by certain rendering APIs
44             VertexDeclaration* createVertexDeclarationImpl(void);
45             /// Internal method for destroys a vertex declaration, may be overridden by certain rendering APIs
46             void destroyVertexDeclarationImpl(VertexDeclaration* decl);
47 
48         public:
49             GLES2HardwareBufferManagerBase();
50             virtual ~GLES2HardwareBufferManagerBase();
51             /// Creates a vertex buffer
52             HardwareVertexBufferSharedPtr createVertexBuffer(size_t vertexSize,
53                 size_t numVerts, HardwareBuffer::Usage usage, bool useShadowBuffer = false);
54             /// Create a hardware vertex buffer
55             HardwareIndexBufferSharedPtr createIndexBuffer(
56                 HardwareIndexBuffer::IndexType itype, size_t numIndexes,
57                 HardwareBuffer::Usage usage, bool useShadowBuffer = false);
58 	        /// Create a render to vertex buffer
59     	    RenderToVertexBufferSharedPtr createRenderToVertexBuffer();
60             HardwareUniformBufferSharedPtr
61             createUniformBuffer(size_t sizeBytes, HardwareBuffer::Usage usage, bool useShadowBuffer, const String& name = "");
62             /// Create a uniform buffer
63             HardwareUniformBufferSharedPtr createUniformBuffer(size_t sizeBytes, HardwareBuffer::Usage usage,
64                                                                bool useShadowBuffer, size_t binding, const String& name = "");
65             HardwareCounterBufferSharedPtr createCounterBuffer(size_t sizeBytes,
66                                                                HardwareBuffer::Usage usage = HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY_DISCARDABLE,
67                                                                bool useShadowBuffer = false, const String& name = "");
68 
69             /// Utility function to get the correct GL usage based on HBU's
70             static GLenum getGLUsage(unsigned int usage);
71 
72             /// Utility function to get the correct GL type based on VET's
73             static GLenum getGLType(unsigned int type);
74 
getStateCacheManager()75 			GLES2StateCacheManager * getStateCacheManager() { return mStateCacheManager; }
76     };
77 
78 	/// GLES2HardwareBufferManagerBase as a Singleton
79 	class _OgreGLES2Export GLES2HardwareBufferManager : public HardwareBufferManager
80 	{
81 	public:
GLES2HardwareBufferManager()82 		GLES2HardwareBufferManager()
83 			: HardwareBufferManager(OGRE_NEW GLES2HardwareBufferManagerBase())
84 		{
85 
86 		}
~GLES2HardwareBufferManager()87 		~GLES2HardwareBufferManager()
88 		{
89 			OGRE_DELETE mImpl;
90 		}
91 
92 		/// Utility function to get the correct GL usage based on HBU's
getGLUsage(unsigned int usage)93 		static GLenum getGLUsage(unsigned int usage)
94             { return GLES2HardwareBufferManagerBase::getGLUsage(usage); }
95 
96 		/// Utility function to get the correct GL type based on VET's
getGLType(unsigned int type)97 		static GLenum getGLType(unsigned int type)
98             { return GLES2HardwareBufferManagerBase::getGLType(type); }
99 	};
100 
101 }
102 
103 #endif
104