1 #ifndef _GLUOBJECTWRAPPER_HPP
2 #define _GLUOBJECTWRAPPER_HPP
3 /*-------------------------------------------------------------------------
4 * drawElements Quality Program OpenGL ES Utilities
5 * ------------------------------------------------
7 * Copyright 2014 The Android Open Source Project
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 * \brief API object wrapper.
24 *//*--------------------------------------------------------------------*/
26 #include "gluDefs.hpp"
27 #include "gluRenderContext.hpp"
28 #include "glwFunctions.hpp"
35 /*--------------------------------------------------------------------*//*!
36 * \brief API object type.
38 * API object type is used to choose allocation and deallocation routines
40 *//*--------------------------------------------------------------------*/
43 OBJECTTYPE_TEXTURE = 0,
45 OBJECTTYPE_RENDERBUFFER,
46 OBJECTTYPE_FRAMEBUFFER,
47 OBJECTTYPE_TRANSFORM_FEEDBACK,
48 OBJECTTYPE_VERTEX_ARRAY,
57 glw::glGenBuffersFunc glw::Functions::*genFunc;
58 glw::glDeleteBuffersFunc glw::Functions::*deleteFunc;
61 const ObjectTraits& objectTraits (ObjectType type);
66 ObjectWrapper (const glw::Functions& gl, const ObjectTraits& traits);
67 ObjectWrapper (const glw::Functions& gl, const ObjectTraits& traits, deUint32 object);
68 ~ObjectWrapper (void);
70 inline deUint32 get (void) const { return m_object; }
71 inline deUint32 operator* (void) const { return m_object; }
74 const glw::Functions& m_gl;
75 const ObjectTraits& m_traits;
79 ObjectWrapper (const ObjectWrapper& other);
80 ObjectWrapper& operator= (const ObjectWrapper& other);
83 /*--------------------------------------------------------------------*//*!
84 * \brief API object wrapper template.
85 *//*--------------------------------------------------------------------*/
86 template<ObjectType Type> class TypedObjectWrapper : public ObjectWrapper
89 TypedObjectWrapper (const glw::Functions& gl, deUint32 object) : ObjectWrapper(gl, objectTraits(Type), object) {}
90 explicit TypedObjectWrapper (const RenderContext& context) : ObjectWrapper(context.getFunctions(), objectTraits(Type)) {}
91 explicit TypedObjectWrapper (const glw::Functions& gl) : ObjectWrapper(gl, objectTraits(Type)) {}
94 /*--------------------------------------------------------------------*//*!
95 * \brief API object vector.
96 *//*--------------------------------------------------------------------*/
100 ObjectVector (const glw::Functions& gl, const ObjectTraits& traits, size_t numObjects = 0);
101 ~ObjectVector (void);
103 size_t size (void) const { return m_objects.size(); }
105 void resize (size_t newSize);
108 bool empty (void) const { return m_objects.empty(); }
110 deUint32 get (size_t ndx) const { return m_objects[ndx]; }
111 deUint32 operator[] (size_t ndx) const { return get(ndx); }
114 ObjectVector (const ObjectVector& other);
115 ObjectVector& operator= (const ObjectVector& other);
117 const glw::Functions& m_gl;
118 const ObjectTraits& m_traits;
119 std::vector<deUint32> m_objects;
122 template<ObjectType Type> class TypedObjectVector : public ObjectVector
125 explicit TypedObjectVector (const RenderContext& context, size_t numObjects = 0) : ObjectVector(context.getFunctions(), objectTraits(Type), numObjects) {}
126 explicit TypedObjectVector (const glw::Functions& gl, size_t numObjects = 0) : ObjectVector(gl, objectTraits(Type), numObjects) {}
129 // Typedefs for simple wrappers without functionality.
131 typedef TypedObjectWrapper<OBJECTTYPE_TEXTURE> Texture;
132 typedef TypedObjectWrapper<OBJECTTYPE_BUFFER> Buffer;
133 typedef TypedObjectWrapper<OBJECTTYPE_RENDERBUFFER> Renderbuffer;
134 typedef TypedObjectWrapper<OBJECTTYPE_FRAMEBUFFER> Framebuffer;
135 typedef TypedObjectWrapper<OBJECTTYPE_TRANSFORM_FEEDBACK> TransformFeedback;
136 typedef TypedObjectWrapper<OBJECTTYPE_VERTEX_ARRAY> VertexArray;
137 typedef TypedObjectWrapper<OBJECTTYPE_QUERY> Query;
139 typedef TypedObjectVector<OBJECTTYPE_TEXTURE> TextureVector;
140 typedef TypedObjectVector<OBJECTTYPE_BUFFER> BufferVector;
141 typedef TypedObjectVector<OBJECTTYPE_RENDERBUFFER> RenderbufferVector;
145 #endif // _GLUOBJECTWRAPPER_HPP