13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _GLUOBJECTWRAPPER_HPP
23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _GLUOBJECTWRAPPER_HPP
33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*-------------------------------------------------------------------------
43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program OpenGL ES Utilities
53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ------------------------------------------------
63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project
83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License");
103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License.
113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at
123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *      http://www.apache.org/licenses/LICENSE-2.0
143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software
163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS,
173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and
193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License.
203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*!
223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file
233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief API object wrapper.
243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluDefs.hpp"
273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "gluRenderContext.hpp"
283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "glwFunctions.hpp"
293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector>
313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace glu
333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*!
363c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief API object type.
373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *
383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * API object type is used to choose allocation and deallocation routines
393c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * for objects.
403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
413c827367444ee418f129b2c238299f49d3264554Jarkko Poyryenum ObjectType
423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OBJECTTYPE_TEXTURE = 0,
443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OBJECTTYPE_BUFFER,
453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OBJECTTYPE_RENDERBUFFER,
463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OBJECTTYPE_FRAMEBUFFER,
473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OBJECTTYPE_TRANSFORM_FEEDBACK,
483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OBJECTTYPE_VERTEX_ARRAY,
493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OBJECTTYPE_QUERY,
507af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyry	OBJECTTYPE_SAMPLER,
513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	OBJECTTYPE_LAST
533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
553c827367444ee418f129b2c238299f49d3264554Jarkko Poyrystruct ObjectTraits
563c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const char*					name;
583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::glGenBuffersFunc		glw::Functions::*genFunc;
593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	glw::glDeleteBuffersFunc	glw::Functions::*deleteFunc;
603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
623c827367444ee418f129b2c238299f49d3264554Jarkko Poyryconst ObjectTraits& objectTraits (ObjectType type);
633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ObjectWrapper
653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
663c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							ObjectWrapper		(const glw::Functions& gl, const ObjectTraits& traits);
6853365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi							ObjectWrapper		(const glw::Functions& gl, const ObjectTraits& traits, deUint32 object);
693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							~ObjectWrapper		(void);
703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	inline deUint32			get					(void) const { return m_object; }
723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	inline deUint32			operator*			(void) const { return m_object; }
733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprotected:
753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&	m_gl;
763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const ObjectTraits&		m_traits;
773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32				m_object;
783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
793c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
803c827367444ee418f129b2c238299f49d3264554Jarkko Poyry							ObjectWrapper		(const ObjectWrapper& other);
813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ObjectWrapper&			operator=			(const ObjectWrapper& other);
8293df37596ea66700965094b3aa2830cf4f2ca5aaJarkko Pöyry} DE_WARN_UNUSED_TYPE;
833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*!
853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief API object wrapper template.
863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
873c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<ObjectType Type> class TypedObjectWrapper : public ObjectWrapper
883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
893c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
9053365959f2740e7b9ed59c51adbb73372f908a09Mika Isojärvi				TypedObjectWrapper (const glw::Functions& gl, deUint32 object) : ObjectWrapper(gl, objectTraits(Type), object) {}
913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	explicit	TypedObjectWrapper (const RenderContext& context) : ObjectWrapper(context.getFunctions(), objectTraits(Type)) {}
928852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	explicit	TypedObjectWrapper (const glw::Functions& gl) : ObjectWrapper(gl, objectTraits(Type)) {}
9393df37596ea66700965094b3aa2830cf4f2ca5aaJarkko Pöyry} DE_WARN_UNUSED_TYPE;
943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*--------------------------------------------------------------------*//*!
963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief API object vector.
973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/
983c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ObjectVector
993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										ObjectVector		(const glw::Functions& gl, const ObjectTraits& traits, size_t numObjects = 0);
1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										~ObjectVector		(void);
1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	size_t								size				(void) const		{ return m_objects.size();	}
1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void								resize				(size_t newSize);
1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	void								clear				(void);
1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	bool								empty				(void) const		{ return m_objects.empty();	}
1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32							get					(size_t ndx) const	{ return m_objects[ndx];	}
1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	deUint32							operator[]			(size_t ndx) const	{ return get(ndx);			}
1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate:
1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry										ObjectVector		(const ObjectVector& other);
1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	ObjectVector&						operator=			(const ObjectVector& other);
1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const glw::Functions&				m_gl;
1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	const ObjectTraits&					m_traits;
1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	std::vector<deUint32>				m_objects;
12193df37596ea66700965094b3aa2830cf4f2ca5aaJarkko Pöyry} DE_WARN_UNUSED_TYPE;
1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytemplate<ObjectType Type> class TypedObjectVector : public ObjectVector
1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{
1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic:
1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry	explicit	TypedObjectVector (const RenderContext& context, size_t numObjects = 0) : ObjectVector(context.getFunctions(), objectTraits(Type), numObjects) {}
1278852c82a1ffa4760985c17cc6875d5d521daf343Jarkko Poyry	explicit	TypedObjectVector (const glw::Functions& gl, size_t numObjects = 0) : ObjectVector(gl, objectTraits(Type), numObjects) {}
1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry};
1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry// Typedefs for simple wrappers without functionality.
1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef TypedObjectWrapper<OBJECTTYPE_TEXTURE>				Texture;
1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef TypedObjectWrapper<OBJECTTYPE_BUFFER>				Buffer;
1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef TypedObjectWrapper<OBJECTTYPE_RENDERBUFFER>			Renderbuffer;
1353c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef TypedObjectWrapper<OBJECTTYPE_FRAMEBUFFER>			Framebuffer;
1363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef TypedObjectWrapper<OBJECTTYPE_TRANSFORM_FEEDBACK>	TransformFeedback;
1373c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef TypedObjectWrapper<OBJECTTYPE_VERTEX_ARRAY>			VertexArray;
1383c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef TypedObjectWrapper<OBJECTTYPE_QUERY>				Query;
1397af3c6f58d3b9426227e4354bf0109028560b6d9Jarkko Pöyrytypedef TypedObjectWrapper<OBJECTTYPE_SAMPLER>				Sampler;
1403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef TypedObjectVector<OBJECTTYPE_TEXTURE>				TextureVector;
1423c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef TypedObjectVector<OBJECTTYPE_BUFFER>				BufferVector;
1433c827367444ee418f129b2c238299f49d3264554Jarkko Poyrytypedef TypedObjectVector<OBJECTTYPE_RENDERBUFFER>			RenderbufferVector;
1443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // glu
1463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry
1473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _GLUOBJECTWRAPPER_HPP
148