1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES Utilities
3 * ------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Buffer object wrapper.
22 *//*--------------------------------------------------------------------*/
24 #include "gluObjectWrapper.hpp"
25 #include "gluRenderContext.hpp"
26 #include "gluStrUtil.hpp"
27 #include "glwFunctions.hpp"
28 #include "glwEnums.hpp"
29 #include "deArrayUtil.hpp"
36 ObjectWrapper::ObjectWrapper (const glw::Functions& gl, const ObjectTraits& traits)
41 (gl.*traits.genFunc)(1, &m_object);
45 const deUint32 err = gl.getError();
46 const char* objectName = traits.name;
47 std::ostringstream msg;
49 msg << "Failed to create " << objectName << " object, got " << getErrorStr((int)err);
51 if (err == GL_OUT_OF_MEMORY)
52 throw OutOfMemoryError(msg.str());
54 throw Error((int)err, msg.str());
58 ObjectWrapper::ObjectWrapper (const glw::Functions& gl, const ObjectTraits& traits, deUint32 object)
63 DE_ASSERT(object != 0);
66 ObjectWrapper::~ObjectWrapper (void)
68 (m_gl.*m_traits.deleteFunc)(1, &m_object);
71 static const ObjectTraits s_objectTraits[OBJECTTYPE_LAST] =
73 { "texture", &glw::Functions::genTextures, &glw::Functions::deleteTextures },
74 { "buffer", &glw::Functions::genBuffers, &glw::Functions::deleteBuffers },
75 { "renderbuffer", &glw::Functions::genRenderbuffers, &glw::Functions::deleteRenderbuffers },
76 { "framebuffer", &glw::Functions::genFramebuffers, &glw::Functions::deleteFramebuffers },
77 { "transform feedback", &glw::Functions::genTransformFeedbacks, &glw::Functions::deleteTransformFeedbacks },
78 { "vertex array", &glw::Functions::genVertexArrays, &glw::Functions::deleteVertexArrays },
79 { "query", &glw::Functions::genQueries, &glw::Functions::deleteQueries },
80 { "sampler", &glw::Functions::genSamplers, &glw::Functions::deleteSamplers },
83 const ObjectTraits& objectTraits (ObjectType type)
85 return de::getSizedArrayElement<OBJECTTYPE_LAST>(s_objectTraits, type);
88 ObjectVector::ObjectVector (const glw::Functions& gl, const ObjectTraits& traits, size_t numObjects)
96 ObjectVector::~ObjectVector (void)
101 void ObjectVector::resize (size_t newSize)
103 const size_t oldSize = m_objects.size();
107 clear(); // Avoid size_t (unsigned) overflow issues in delete path.
109 if (oldSize < newSize)
111 m_objects.resize(newSize, 0);
112 (m_gl.*m_traits.genFunc)(glw::GLsizei(newSize - oldSize), &m_objects[oldSize]);
114 else if (oldSize > newSize)
116 (m_gl.*m_traits.deleteFunc)(glw::GLsizei(oldSize - newSize), &m_objects[newSize]);
117 m_objects.resize(newSize);
121 void ObjectVector::clear (void)
123 (m_gl.*m_traits.deleteFunc)(glw::GLsizei(m_objects.size()), &m_objects.front());