Home | History | Annotate | Download | only in opengl
      1 #ifndef _GLUOBJECTWRAPPER_HPP
      2 #define _GLUOBJECTWRAPPER_HPP
      3 /*-------------------------------------------------------------------------
      4  * drawElements Quality Program OpenGL ES Utilities
      5  * ------------------------------------------------
      6  *
      7  * Copyright 2014 The Android Open Source Project
      8  *
      9  * Licensed under the Apache License, Version 2.0 (the "License");
     10  * you may not use this file except in compliance with the License.
     11  * You may obtain a copy of the License at
     12  *
     13  *      http://www.apache.org/licenses/LICENSE-2.0
     14  *
     15  * Unless required by applicable law or agreed to in writing, software
     16  * distributed under the License is distributed on an "AS IS" BASIS,
     17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     18  * See the License for the specific language governing permissions and
     19  * limitations under the License.
     20  *
     21  *//*!
     22  * \file
     23  * \brief API object wrapper.
     24  *//*--------------------------------------------------------------------*/
     25 
     26 #include "gluDefs.hpp"
     27 #include "gluRenderContext.hpp"
     28 #include "glwFunctions.hpp"
     29 
     30 #include <vector>
     31 
     32 namespace glu
     33 {
     34 
     35 /*--------------------------------------------------------------------*//*!
     36  * \brief API object type.
     37  *
     38  * API object type is used to choose allocation and deallocation routines
     39  * for objects.
     40  *//*--------------------------------------------------------------------*/
     41 enum ObjectType
     42 {
     43 	OBJECTTYPE_TEXTURE = 0,
     44 	OBJECTTYPE_BUFFER,
     45 	OBJECTTYPE_RENDERBUFFER,
     46 	OBJECTTYPE_FRAMEBUFFER,
     47 	OBJECTTYPE_TRANSFORM_FEEDBACK,
     48 	OBJECTTYPE_VERTEX_ARRAY,
     49 	OBJECTTYPE_QUERY,
     50 
     51 	OBJECTTYPE_LAST
     52 };
     53 
     54 struct ObjectTraits
     55 {
     56 	const char*					name;
     57 	glw::glGenBuffersFunc		glw::Functions::*genFunc;
     58 	glw::glDeleteBuffersFunc	glw::Functions::*deleteFunc;
     59 };
     60 
     61 const ObjectTraits& objectTraits (ObjectType type);
     62 
     63 class ObjectWrapper
     64 {
     65 public:
     66 							ObjectWrapper		(const glw::Functions& gl, const ObjectTraits& traits);
     67 							~ObjectWrapper		(void);
     68 
     69 	inline deUint32			get					(void) const { return m_object; }
     70 	inline deUint32			operator*			(void) const { return m_object; }
     71 
     72 protected:
     73 	const glw::Functions&	m_gl;
     74 	const ObjectTraits&		m_traits;
     75 	deUint32				m_object;
     76 
     77 private:
     78 							ObjectWrapper		(const ObjectWrapper& other);
     79 	ObjectWrapper&			operator=			(const ObjectWrapper& other);
     80 };
     81 
     82 /*--------------------------------------------------------------------*//*!
     83  * \brief API object wrapper template.
     84  *//*--------------------------------------------------------------------*/
     85 template<ObjectType Type> class TypedObjectWrapper : public ObjectWrapper
     86 {
     87 public:
     88 	explicit	TypedObjectWrapper (const RenderContext& context) : ObjectWrapper(context.getFunctions(), objectTraits(Type)) {}
     89 	explicit	TypedObjectWrapper (const glw::Functions& gl) : ObjectWrapper(gl, objectTraits(Type)) {}
     90 };
     91 
     92 /*--------------------------------------------------------------------*//*!
     93  * \brief API object vector.
     94  *//*--------------------------------------------------------------------*/
     95 class ObjectVector
     96 {
     97 public:
     98 										ObjectVector		(const glw::Functions& gl, const ObjectTraits& traits, size_t numObjects = 0);
     99 										~ObjectVector		(void);
    100 
    101 	size_t								size				(void) const		{ return m_objects.size();	}
    102 
    103 	void								resize				(size_t newSize);
    104 	void								clear				(void);
    105 
    106 	bool								empty				(void) const		{ return m_objects.empty();	}
    107 
    108 	deUint32							get					(size_t ndx) const	{ return m_objects[ndx];	}
    109 	deUint32							operator[]			(size_t ndx) const	{ return get(ndx);			}
    110 
    111 private:
    112 										ObjectVector		(const ObjectVector& other);
    113 	ObjectVector&						operator=			(const ObjectVector& other);
    114 
    115 	const glw::Functions&				m_gl;
    116 	const ObjectTraits&					m_traits;
    117 	std::vector<deUint32>				m_objects;
    118 };
    119 
    120 template<ObjectType Type> class TypedObjectVector : public ObjectVector
    121 {
    122 public:
    123 	explicit	TypedObjectVector (const RenderContext& context, size_t numObjects = 0) : ObjectVector(context.getFunctions(), objectTraits(Type), numObjects) {}
    124 	explicit	TypedObjectVector (const glw::Functions& gl, size_t numObjects = 0) : ObjectVector(gl, objectTraits(Type), numObjects) {}
    125 };
    126 
    127 // Typedefs for simple wrappers without functionality.
    128 
    129 typedef TypedObjectWrapper<OBJECTTYPE_TEXTURE>				Texture;
    130 typedef TypedObjectWrapper<OBJECTTYPE_BUFFER>				Buffer;
    131 typedef TypedObjectWrapper<OBJECTTYPE_RENDERBUFFER>			Renderbuffer;
    132 typedef TypedObjectWrapper<OBJECTTYPE_FRAMEBUFFER>			Framebuffer;
    133 typedef TypedObjectWrapper<OBJECTTYPE_TRANSFORM_FEEDBACK>	TransformFeedback;
    134 typedef TypedObjectWrapper<OBJECTTYPE_VERTEX_ARRAY>			VertexArray;
    135 typedef TypedObjectWrapper<OBJECTTYPE_QUERY>				Query;
    136 
    137 typedef TypedObjectVector<OBJECTTYPE_TEXTURE>				TextureVector;
    138 typedef TypedObjectVector<OBJECTTYPE_BUFFER>				BufferVector;
    139 typedef TypedObjectVector<OBJECTTYPE_RENDERBUFFER>			RenderbufferVector;
    140 
    141 } // glu
    142 
    143 #endif // _GLUOBJECTWRAPPER_HPP
    144