2 * Mesa 3-D graphics library
4 * Copyright (C) 2013 Timothy Arceri All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
27 #include "bufferobj.h"
32 #include "objectlabel.h"
33 #include "pipelineobj.h"
35 #include "samplerobj.h"
36 #include "shaderobj.h"
39 #include "transformfeedback.h"
43 * Helper for _mesa_ObjectLabel() and _mesa_ObjectPtrLabel().
46 set_label(struct gl_context
*ctx
, char **labelPtr
, const char *label
,
47 int length
, const char *caller
)
52 /* set new label string */
55 if (length
>= MAX_LABEL_LENGTH
)
56 _mesa_error(ctx
, GL_INVALID_VALUE
,
57 "%s(length=%d, which is not less than "
58 "GL_MAX_LABEL_LENGTH=%d)", caller
, length
,
62 *labelPtr
= malloc(length
+1);
64 memcpy(*labelPtr
, label
, length
);
65 /* length is not required to include the null terminator so
66 * add one just in case
68 (*labelPtr
)[length
] = '\0';
72 int len
= strlen(label
);
73 if (len
>= MAX_LABEL_LENGTH
)
74 _mesa_error(ctx
, GL_INVALID_VALUE
,
75 "%s(label length=%d, which is not less than "
76 "GL_MAX_LABEL_LENGTH=%d)", caller
, len
,
79 /* null-terminated string */
80 *labelPtr
= strdup(label
);
86 * Helper for _mesa_GetObjectLabel() and _mesa_GetObjectPtrLabel().
87 * \param src the src label (may be null)
88 * \param dst pointer to dest buffer (may be null)
89 * \param length returns length of label (may be null)
90 * \param bufsize size of dst buffer
93 copy_label(const GLchar
*src
, GLchar
*dst
, GLsizei
*length
, GLsizei bufSize
)
97 /* From http://www.opengl.org/registry/specs/KHR/debug.txt:
98 * "If <length> is NULL, no length is returned. The maximum number of
99 * characters that may be written into <label>, including the null
100 * terminator, is specified by <bufSize>. If no debug label was specified
101 * for the object then <label> will contain a null-terminated empty string,
102 * and zero will be returned in <length>. If <label> is NULL and <length>
103 * is non-NULL then no string will be returned and the length of the label
104 * will be returned in <length>."
108 labelLen
= strlen(src
);
118 if (bufSize
<= labelLen
)
119 labelLen
= bufSize
- 1;
121 memcpy(dst
, src
, labelLen
);
124 dst
[labelLen
] = '\0';
132 * Helper for _mesa_ObjectLabel() and _mesa_GetObjectLabel().
135 get_label_pointer(struct gl_context
*ctx
, GLenum identifier
, GLuint name
,
138 char **labelPtr
= NULL
;
140 switch (identifier
) {
143 struct gl_buffer_object
*bufObj
= _mesa_lookup_bufferobj(ctx
, name
);
145 labelPtr
= &bufObj
->Label
;
150 struct gl_shader
*shader
= _mesa_lookup_shader(ctx
, name
);
152 labelPtr
= &shader
->Label
;
157 struct gl_shader_program
*program
=
158 _mesa_lookup_shader_program(ctx
, name
);
160 labelPtr
= &program
->Label
;
163 case GL_VERTEX_ARRAY
:
165 struct gl_vertex_array_object
*obj
= _mesa_lookup_vao(ctx
, name
);
167 labelPtr
= &obj
->Label
;
172 struct gl_query_object
*query
= _mesa_lookup_query_object(ctx
, name
);
174 labelPtr
= &query
->Label
;
177 case GL_TRANSFORM_FEEDBACK
:
179 /* From the GL 4.5 specification, page 536:
180 * "An INVALID_VALUE error is generated if name is not the name of a
181 * valid object of the type specified by identifier."
183 struct gl_transform_feedback_object
*tfo
=
184 _mesa_lookup_transform_feedback_object(ctx
, name
);
185 if (tfo
&& tfo
->EverBound
)
186 labelPtr
= &tfo
->Label
;
191 struct gl_sampler_object
*so
= _mesa_lookup_samplerobj(ctx
, name
);
193 labelPtr
= &so
->Label
;
198 struct gl_texture_object
*texObj
= _mesa_lookup_texture(ctx
, name
);
199 if (texObj
&& texObj
->Target
)
200 labelPtr
= &texObj
->Label
;
203 case GL_RENDERBUFFER
:
205 struct gl_renderbuffer
*rb
= _mesa_lookup_renderbuffer(ctx
, name
);
207 labelPtr
= &rb
->Label
;
212 struct gl_framebuffer
*rb
= _mesa_lookup_framebuffer(ctx
, name
);
214 labelPtr
= &rb
->Label
;
217 case GL_DISPLAY_LIST
:
218 if (ctx
->API
== API_OPENGL_COMPAT
) {
219 struct gl_display_list
*list
= _mesa_lookup_list(ctx
, name
);
221 labelPtr
= &list
->Label
;
227 case GL_PROGRAM_PIPELINE
:
229 struct gl_pipeline_object
*pipe
=
230 _mesa_lookup_pipeline_object(ctx
, name
);
232 labelPtr
= &pipe
->Label
;
239 if (NULL
== labelPtr
) {
240 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(name = %u)", caller
, name
);
246 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(identifier = %s)",
247 caller
, _mesa_enum_to_string(identifier
));
252 _mesa_ObjectLabel(GLenum identifier
, GLuint name
, GLsizei length
,
255 GET_CURRENT_CONTEXT(ctx
);
256 const char *callerstr
;
259 if (_mesa_is_desktop_gl(ctx
))
260 callerstr
= "glObjectLabel";
262 callerstr
= "glObjectLabelKHR";
264 labelPtr
= get_label_pointer(ctx
, identifier
, name
, callerstr
);
268 set_label(ctx
, labelPtr
, label
, length
, callerstr
);
272 _mesa_GetObjectLabel(GLenum identifier
, GLuint name
, GLsizei bufSize
,
273 GLsizei
*length
, GLchar
*label
)
275 GET_CURRENT_CONTEXT(ctx
);
276 const char *callerstr
;
279 if (_mesa_is_desktop_gl(ctx
))
280 callerstr
= "glGetObjectLabel";
282 callerstr
= "glGetObjectLabelKHR";
285 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(bufSize = %d)", callerstr
,
290 labelPtr
= get_label_pointer(ctx
, identifier
, name
, callerstr
);
294 copy_label(*labelPtr
, label
, length
, bufSize
);
298 _mesa_ObjectPtrLabel(const void *ptr
, GLsizei length
, const GLchar
*label
)
300 GET_CURRENT_CONTEXT(ctx
);
301 struct gl_sync_object
*syncObj
;
302 const char *callerstr
;
305 syncObj
= _mesa_get_and_ref_sync(ctx
, (void*)ptr
, true);
307 if (_mesa_is_desktop_gl(ctx
))
308 callerstr
= "glObjectPtrLabel";
310 callerstr
= "glObjectPtrLabelKHR";
313 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s (not a valid sync object)",
318 labelPtr
= &syncObj
->Label
;
320 set_label(ctx
, labelPtr
, label
, length
, callerstr
);
321 _mesa_unref_sync_object(ctx
, syncObj
, 1);
325 _mesa_GetObjectPtrLabel(const void *ptr
, GLsizei bufSize
, GLsizei
*length
,
328 GET_CURRENT_CONTEXT(ctx
);
329 struct gl_sync_object
*syncObj
;
330 const char *callerstr
;
333 if (_mesa_is_desktop_gl(ctx
))
334 callerstr
= "glGetObjectPtrLabel";
336 callerstr
= "glGetObjectPtrLabelKHR";
339 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(bufSize = %d)", callerstr
,
344 syncObj
= _mesa_get_and_ref_sync(ctx
, (void*)ptr
, true);
346 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s (not a valid sync object)",
351 labelPtr
= &syncObj
->Label
;
353 copy_label(*labelPtr
, label
, length
, bufSize
);
354 _mesa_unref_sync_object(ctx
, syncObj
, 1);