Commit 3b361f96 authored by Robert Menzel's avatar Robert Menzel

ObjectLabel and ObjectPtrLabel are working

parent 294b0abb
......@@ -447,6 +447,11 @@ void KHR_DEBUG_EMULATOR_ObjectLabel(GLenum identifier, GLuint name, GLsizei leng
void KHR_DEBUG_EMULATOR_GetObjectLabel(GLenum identifier, GLuint name, GLsizei bufSize, GLsizei * length, GLchar * label)
{
if ( !isValidObjectLabelNamespace(identifier) ) {
INSERT_API_ERROR( GL_INVALID_ENUM, "invalid enum in glObjectGetLabel" );
return;
}
ObjectLabel *thelabel = findObjectLabel( identifier, name );
if (thelabel == NULL) {
// label not found:
......@@ -472,14 +477,120 @@ void KHR_DEBUG_EMULATOR_GetObjectLabel(GLenum identifier, GLuint name, GLsizei b
///
///////////////////////////////////////////////////////////////////////////////////////////////////
typedef struct ObjectPtrLabel {
const void * ptr;
GLsizei length;
GLchar * label;
ObjectPtrLabel *nextLabel;
ObjectPtrLabel *previousLabel;
} ObjectPtrLabel;
ObjectPtrLabel *g_ObjectPtrLabels = NULL;
ObjectPtrLabel *findObjectPtrLabel(const void * ptr)
{
ObjectPtrLabel *l = g_ObjectPtrLabels;
while ( l != NULL ) {
if (l->ptr == ptr) return l;
l = l->nextLabel;
}
// none found:
return NULL;
}
void insertObjectPtrLabel(const void * ptr, GLsizei length, const GLchar * label)
{
ObjectPtrLabel *l = (ObjectPtrLabel *) malloc( sizeof(ObjectPtrLabel) );
l->ptr = ptr;
l->length = length;
l->label = (GLchar *) malloc( length+1 );
l->nextLabel = NULL;
l->previousLabel = NULL;
strncpy( l->label , label, length );
l->label[ length ] = 0;
// find last label
ObjectPtrLabel *last = g_ObjectPtrLabels;
if (last == NULL) {
// first label:
g_ObjectPtrLabels = l;
return;
}
while ( last->nextLabel != NULL ) { last = last->nextLabel; }
last->nextLabel = l;
l->previousLabel = last;
}
void KHR_DEBUG_EMULATOR_ObjectPtrLabel(const void * ptr, GLsizei length, const GLchar * label)
{
KHR_DEBUG_EMULATOR_insertMissingFeatureError( "function not simulated yet - ignored" );
if (length < 0) {
length = strlen( label );
}
if (length >= KHR_DEBUG_EMULATOR_MAX_LABEL_LENGTH) {
INSERT_API_ERROR( GL_INVALID_VALUE, "invalid value in glObjectPtrLabel: label too long" );
return;
}
ObjectPtrLabel *thelabel = findObjectPtrLabel( ptr );
if (thelabel == NULL) {
insertObjectPtrLabel( ptr, length, label );
} else {
// update
if (length == 0) {
// delete
ObjectPtrLabel *pre = thelabel->previousLabel;
ObjectPtrLabel *next = thelabel->nextLabel;
if (pre) pre->nextLabel = next;
if (next) next->previousLabel = pre;
if (!pre) g_ObjectPtrLabels = next; // this was the first label
free( (void*) thelabel->label );
free( (void*) thelabel );
} else {
// update name & length:
if (length < 0) {
length = strlen( label );
}
free( (void*) thelabel->label );
thelabel->label = (GLchar *) malloc( length+1 );
strncpy( thelabel->label , label, length );
thelabel->label[ length ] = 0;
thelabel->length = length;
}
}
}
void KHR_DEBUG_EMULATOR_GetObjectPtrLabel(const void * ptr, GLsizei bufSize, GLsizei * length, GLchar * label)
{
KHR_DEBUG_EMULATOR_insertMissingFeatureError( "function not simulated yet - ignored" );
ObjectPtrLabel *thelabel = findObjectPtrLabel( ptr );
if (thelabel == NULL) {
// label not found:
label[0] = 0;
*length = 0;
return;
}
size_t size = thelabel->length + 1;
if (bufSize-1 < size) size = bufSize-1;
if (label != NULL) {
strncpy( label, thelabel->label, size );
label[size] = 0;
}
*length = size;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment