]> git.cworth.org Git - vogl/blob - src/voglcommon/vogl_gl_object.cpp
Initial vogl checkin
[vogl] / src / voglcommon / vogl_gl_object.cpp
1 /**************************************************************************
2  *
3  * Copyright 2013-2014 RAD Game Tools and Valve Software
4  * All Rights Reserved.
5  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
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
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26 // File: vogl_gl_object.cpp
27 #include "vogl_gl_object.h"
28
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"
42
43 void vogl_handle_remapper::delete_handle_and_object(vogl_namespace_t handle_namespace, uint64_t from_handle, uint64_t to_handle)
44 {
45     VOGL_FUNC_TRACER
46
47     //VOGL_NOTE_UNUSED(handle_namespace);
48     VOGL_NOTE_UNUSED(from_handle);
49     //VOGL_NOTE_UNUSED(to_handle);
50
51     vogl_destroy_gl_object(handle_namespace, to_handle);
52 }
53
54 const char *get_gl_object_state_type_str(vogl_gl_object_state_type type)
55 {
56     VOGL_FUNC_TRACER
57
58     switch (type)
59     {
60 #define DEF(x)     \
61     case cGLST##x: \
62         return #x;
63         VOGL_GL_OBJECT_STATE_TYPES
64 #undef DEF
65         default:
66             break;
67     }
68     return "";
69 }
70
71 vogl_gl_object_state_type determine_gl_object_state_type_from_str(const char *pStr)
72 {
73     VOGL_FUNC_TRACER
74
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);
78     return cGLSTInvalid;
79 }
80
81 void vogl_destroy_gl_object(vogl_namespace_t handle_namespace, GLuint64 handle)
82 {
83     VOGL_FUNC_TRACER
84
85     if (!handle)
86         return;
87
88     GLuint handle32 = static_cast<GLuint>(handle);
89
90     switch (handle_namespace)
91     {
92         case VOGL_NAMESPACE_FRAMEBUFFERS:
93         {
94             VOGL_ASSERT(handle == handle32);
95             GL_ENTRYPOINT(glDeleteFramebuffers)(1, &handle32);
96             break;
97         }
98         case VOGL_NAMESPACE_TEXTURES:
99         {
100             VOGL_ASSERT(handle == handle32);
101             GL_ENTRYPOINT(glDeleteTextures)(1, &handle32);
102             break;
103         }
104         case VOGL_NAMESPACE_RENDER_BUFFERS:
105         {
106             VOGL_ASSERT(handle == handle32);
107             GL_ENTRYPOINT(glDeleteRenderbuffers)(1, &handle32);
108             break;
109         }
110         case VOGL_NAMESPACE_QUERIES:
111         {
112             VOGL_ASSERT(handle == handle32);
113             GL_ENTRYPOINT(glDeleteQueries)(1, &handle32);
114             break;
115         }
116         case VOGL_NAMESPACE_SAMPLERS:
117         {
118             VOGL_ASSERT(handle == handle32);
119             GL_ENTRYPOINT(glDeleteSamplers)(1, &handle32);
120             break;
121         }
122         case VOGL_NAMESPACE_PROGRAM_ARB:
123         {
124             VOGL_ASSERT(handle == handle32);
125             GL_ENTRYPOINT(glDeleteProgramsARB)(1, &handle32);
126             break;
127         }
128         case VOGL_NAMESPACE_PROGRAMS:
129         {
130             VOGL_ASSERT(handle == handle32);
131             GL_ENTRYPOINT(glDeleteProgram)(handle32);
132             break;
133         }
134         case VOGL_NAMESPACE_VERTEX_ARRAYS:
135         {
136             VOGL_ASSERT(handle == handle32);
137             GL_ENTRYPOINT(glDeleteVertexArrays)(1, &handle32);
138             break;
139         }
140         case VOGL_NAMESPACE_LISTS:
141         {
142             VOGL_ASSERT(handle == handle32);
143             GL_ENTRYPOINT(glDeleteLists)(handle32, 1);
144             break;
145         }
146         case VOGL_NAMESPACE_SYNCS:
147         {
148             GLsync sync = vogl_handle_to_sync(handle);
149             GL_ENTRYPOINT(glDeleteSync)(sync);
150             break;
151         }
152         case VOGL_NAMESPACE_PIPELINES:
153         {
154             VOGL_ASSERT(handle == handle32);
155             GL_ENTRYPOINT(glDeleteProgramPipelines)(1, &handle32);
156             break;
157         }
158         case VOGL_NAMESPACE_SHADERS:
159         {
160             VOGL_ASSERT(handle == handle32);
161             GL_ENTRYPOINT(glDeleteShader)(handle32);
162             break;
163         }
164         case VOGL_NAMESPACE_BUFFERS:
165         {
166             VOGL_ASSERT(handle == handle32);
167             GL_ENTRYPOINT(glDeleteBuffers)(1, &handle32);
168             break;
169         }
170         case VOGL_NAMESPACE_FEEDBACKS:
171         {
172             VOGL_ASSERT(handle == handle32);
173             GL_ENTRYPOINT(glDeleteTransformFeedbacks)(1, &handle32);
174             break;
175         }
176         default:
177         {
178             VOGL_ASSERT_ALWAYS;
179             break;
180         }
181     }
182
183     VOGL_CHECK_GL_ERROR;
184 }
185
186 void vogl_destroy_gl_object(vogl_gl_object_state_type type, GLuint64 handle)
187 {
188     VOGL_FUNC_TRACER
189
190     if (!handle)
191         return;
192
193     GLuint handle32 = static_cast<GLuint>(handle);
194
195     switch (type)
196     {
197         case cGLSTTexture:
198         {
199             VOGL_ASSERT(handle == handle32);
200             GL_ENTRYPOINT(glDeleteTextures)(1, &handle32);
201             break;
202         }
203         case cGLSTRenderbuffer:
204         {
205             VOGL_ASSERT(handle == handle32);
206             GL_ENTRYPOINT(glDeleteRenderbuffers)(1, &handle32);
207             break;
208         }
209         case cGLSTBuffer:
210         {
211             VOGL_ASSERT(handle == handle32);
212             GL_ENTRYPOINT(glDeleteBuffers)(1, &handle32);
213             break;
214         }
215         case cGLSTFramebuffer:
216         {
217             VOGL_ASSERT(handle == handle32);
218             GL_ENTRYPOINT(glDeleteFramebuffers)(1, &handle32);
219             break;
220         }
221         case cGLSTQuery:
222         {
223             VOGL_ASSERT(handle == handle32);
224             GL_ENTRYPOINT(glDeleteQueries)(1, &handle32);
225             break;
226         }
227         case cGLSTShader:
228         {
229             VOGL_ASSERT(handle == handle32);
230             GL_ENTRYPOINT(glDeleteShader)(handle32);
231             break;
232         }
233         case cGLSTProgram:
234         {
235             VOGL_ASSERT(handle == handle32);
236             GL_ENTRYPOINT(glDeleteProgram)(handle32);
237             break;
238         }
239         case cGLSTSampler:
240         {
241             VOGL_ASSERT(handle == handle32);
242             GL_ENTRYPOINT(glDeleteSamplers)(1, &handle32);
243             break;
244         }
245         case cGLSTVertexArray:
246         {
247             VOGL_ASSERT(handle == handle32);
248             GL_ENTRYPOINT(glDeleteVertexArrays)(1, &handle32);
249             break;
250         }
251         case cGLSTSync:
252         {
253             GLsync sync = vogl_handle_to_sync(handle);
254             GL_ENTRYPOINT(glDeleteSync)(sync);
255             break;
256         }
257         case cGLSTARBProgram:
258         {
259             VOGL_ASSERT(handle == handle32);
260             GL_ENTRYPOINT(glDeleteProgramsARB)(1, &handle32);
261             break;
262         }
263         default:
264             VOGL_ASSERT_ALWAYS;
265             break;
266     }
267     VOGL_CHECK_GL_ERROR;
268 }
269
270 vogl_gl_object_state *vogl_gl_object_state_factory(vogl_gl_object_state_type type)
271 {
272     VOGL_FUNC_TRACER
273
274     switch (type)
275     {
276         case cGLSTTexture:
277             return vogl_new(vogl_texture_state);
278         case cGLSTRenderbuffer:
279             return vogl_new(vogl_renderbuffer_state);
280         case cGLSTBuffer:
281             return vogl_new(vogl_buffer_state);
282         case cGLSTFramebuffer:
283             return vogl_new(vogl_framebuffer_state);
284         case cGLSTQuery:
285             return vogl_new(vogl_query_state);
286         case cGLSTShader:
287             return vogl_new(vogl_shader_state);
288         case cGLSTProgram:
289             return vogl_new(vogl_program_state);
290         case cGLSTSampler:
291             return vogl_new(vogl_sampler_state);
292         case cGLSTVertexArray:
293             return vogl_new(vogl_vao_state);
294         case cGLSTSync:
295             return vogl_new(vogl_sync_state);
296         case cGLSTARBProgram:
297             return vogl_new(vogl_arb_program_state);
298         default:
299             VOGL_ASSERT_ALWAYS;
300             break;
301     }
302     return NULL;
303 }