1 /**************************************************************************
3 * Copyright 2013-2014 RAD Game Tools and Valve Software
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 **************************************************************************/
26 // File: vogl_gl_object.cpp
27 #include "vogl_gl_object.h"
29 #include "vogl_general_context_state.h"
30 #include "vogl_texture_state.h"
31 #include "vogl_buffer_state.h"
32 #include "vogl_fbo_state.h"
33 #include "vogl_sampler_state.h"
34 #include "vogl_shader_state.h"
35 #include "vogl_program_state.h"
36 #include "vogl_renderbuffer_state.h"
37 #include "vogl_query_state.h"
38 #include "vogl_vao_state.h"
39 #include "vogl_sync_object.h"
40 #include "vogl_gl_state_snapshot.h"
41 #include "vogl_arb_program_state.h"
43 void vogl_handle_remapper::delete_handle_and_object(vogl_namespace_t handle_namespace, uint64_t from_handle, uint64_t to_handle)
47 //VOGL_NOTE_UNUSED(handle_namespace);
48 VOGL_NOTE_UNUSED(from_handle);
49 //VOGL_NOTE_UNUSED(to_handle);
51 vogl_destroy_gl_object(handle_namespace, to_handle);
54 const char *get_gl_object_state_type_str(vogl_gl_object_state_type type)
63 VOGL_GL_OBJECT_STATE_TYPES
71 vogl_gl_object_state_type determine_gl_object_state_type_from_str(const char *pStr)
75 for (uint i = 0; i < cGLSTTotalTypes; i++)
76 if (!vogl_stricmp(pStr, get_gl_object_state_type_str(static_cast<vogl_gl_object_state_type>(i))))
77 return static_cast<vogl_gl_object_state_type>(i);
81 void vogl_destroy_gl_object(vogl_namespace_t handle_namespace, GLuint64 handle)
88 GLuint handle32 = static_cast<GLuint>(handle);
90 switch (handle_namespace)
92 case VOGL_NAMESPACE_FRAMEBUFFERS:
94 VOGL_ASSERT(handle == handle32);
95 GL_ENTRYPOINT(glDeleteFramebuffers)(1, &handle32);
98 case VOGL_NAMESPACE_TEXTURES:
100 VOGL_ASSERT(handle == handle32);
101 GL_ENTRYPOINT(glDeleteTextures)(1, &handle32);
104 case VOGL_NAMESPACE_RENDER_BUFFERS:
106 VOGL_ASSERT(handle == handle32);
107 GL_ENTRYPOINT(glDeleteRenderbuffers)(1, &handle32);
110 case VOGL_NAMESPACE_QUERIES:
112 VOGL_ASSERT(handle == handle32);
113 GL_ENTRYPOINT(glDeleteQueries)(1, &handle32);
116 case VOGL_NAMESPACE_SAMPLERS:
118 VOGL_ASSERT(handle == handle32);
119 GL_ENTRYPOINT(glDeleteSamplers)(1, &handle32);
122 case VOGL_NAMESPACE_PROGRAM_ARB:
124 VOGL_ASSERT(handle == handle32);
125 GL_ENTRYPOINT(glDeleteProgramsARB)(1, &handle32);
128 case VOGL_NAMESPACE_PROGRAMS:
130 VOGL_ASSERT(handle == handle32);
131 GL_ENTRYPOINT(glDeleteProgram)(handle32);
134 case VOGL_NAMESPACE_VERTEX_ARRAYS:
136 VOGL_ASSERT(handle == handle32);
137 GL_ENTRYPOINT(glDeleteVertexArrays)(1, &handle32);
140 case VOGL_NAMESPACE_LISTS:
142 VOGL_ASSERT(handle == handle32);
143 GL_ENTRYPOINT(glDeleteLists)(handle32, 1);
146 case VOGL_NAMESPACE_SYNCS:
148 GLsync sync = vogl_handle_to_sync(handle);
149 GL_ENTRYPOINT(glDeleteSync)(sync);
152 case VOGL_NAMESPACE_PIPELINES:
154 VOGL_ASSERT(handle == handle32);
155 GL_ENTRYPOINT(glDeleteProgramPipelines)(1, &handle32);
158 case VOGL_NAMESPACE_SHADERS:
160 VOGL_ASSERT(handle == handle32);
161 GL_ENTRYPOINT(glDeleteShader)(handle32);
164 case VOGL_NAMESPACE_BUFFERS:
166 VOGL_ASSERT(handle == handle32);
167 GL_ENTRYPOINT(glDeleteBuffers)(1, &handle32);
170 case VOGL_NAMESPACE_FEEDBACKS:
172 VOGL_ASSERT(handle == handle32);
173 GL_ENTRYPOINT(glDeleteTransformFeedbacks)(1, &handle32);
186 void vogl_destroy_gl_object(vogl_gl_object_state_type type, GLuint64 handle)
193 GLuint handle32 = static_cast<GLuint>(handle);
199 VOGL_ASSERT(handle == handle32);
200 GL_ENTRYPOINT(glDeleteTextures)(1, &handle32);
203 case cGLSTRenderbuffer:
205 VOGL_ASSERT(handle == handle32);
206 GL_ENTRYPOINT(glDeleteRenderbuffers)(1, &handle32);
211 VOGL_ASSERT(handle == handle32);
212 GL_ENTRYPOINT(glDeleteBuffers)(1, &handle32);
215 case cGLSTFramebuffer:
217 VOGL_ASSERT(handle == handle32);
218 GL_ENTRYPOINT(glDeleteFramebuffers)(1, &handle32);
223 VOGL_ASSERT(handle == handle32);
224 GL_ENTRYPOINT(glDeleteQueries)(1, &handle32);
229 VOGL_ASSERT(handle == handle32);
230 GL_ENTRYPOINT(glDeleteShader)(handle32);
235 VOGL_ASSERT(handle == handle32);
236 GL_ENTRYPOINT(glDeleteProgram)(handle32);
241 VOGL_ASSERT(handle == handle32);
242 GL_ENTRYPOINT(glDeleteSamplers)(1, &handle32);
245 case cGLSTVertexArray:
247 VOGL_ASSERT(handle == handle32);
248 GL_ENTRYPOINT(glDeleteVertexArrays)(1, &handle32);
253 GLsync sync = vogl_handle_to_sync(handle);
254 GL_ENTRYPOINT(glDeleteSync)(sync);
257 case cGLSTARBProgram:
259 VOGL_ASSERT(handle == handle32);
260 GL_ENTRYPOINT(glDeleteProgramsARB)(1, &handle32);
270 vogl_gl_object_state *vogl_gl_object_state_factory(vogl_gl_object_state_type type)
277 return vogl_new(vogl_texture_state);
278 case cGLSTRenderbuffer:
279 return vogl_new(vogl_renderbuffer_state);
281 return vogl_new(vogl_buffer_state);
282 case cGLSTFramebuffer:
283 return vogl_new(vogl_framebuffer_state);
285 return vogl_new(vogl_query_state);
287 return vogl_new(vogl_shader_state);
289 return vogl_new(vogl_program_state);
291 return vogl_new(vogl_sampler_state);
292 case cGLSTVertexArray:
293 return vogl_new(vogl_vao_state);
295 return vogl_new(vogl_sync_state);
296 case cGLSTARBProgram:
297 return vogl_new(vogl_arb_program_state);