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