-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
crude sketch of auto error checking - please help improve (#50)
* crude sketch of auto error checking * Cleanup and add new glp functions to export tags list * Add string output for glGetError returns * Make glpSetAutoCheckErrors() return the current setting And take no arguments to just return the current flag value.
- Loading branch information
1 parent
c9bb77f
commit 9257866
Showing
6 changed files
with
139 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
#define GL_NO_ERROR 0 | ||
#define GL_INVALID_ENUM 0x0500 | ||
#define GL_INVALID_VALUE 0x0501 | ||
#define GL_INVALID_OPERATION 0x0502 | ||
#define GL_STACK_OVERFLOW 0x0503 | ||
#define GL_STACK_UNDERFLOW 0x0504 | ||
#define GL_OUT_OF_MEMORY 0x0505 | ||
#define GL_INVALID_FRAMEBUFFER_OPERATION 0x0506 | ||
#define GL_CONTEXT_LOST 0x0507 | ||
*/ | ||
|
||
const char* const gl_error_symbol_strings[] = { | ||
"GL_NO_ERROR", | ||
"GL_INVALID_ENUM", | ||
"GL_INVALID_VALUE", | ||
"GL_INVALID_OPERATION", | ||
"GL_STACK_OVERFLOW", | ||
"GL_STACK_UNDERFLOW", | ||
"GL_OUT_OF_MEMORY", | ||
"GL_INVALID_FRAMEBUFFER_OPERATION", | ||
"GL_CONTEXT_LOST", | ||
}; | ||
|
||
int is_gl_error(int rval) { | ||
int err; | ||
err = rval & 0x0507 > 0 ? (rval & 0x07) + 1 : 0; | ||
return err; | ||
} | ||
|
||
const char* gl_error_string(int err) { | ||
return gl_error_symbol_strings[is_gl_error(err)]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#! /usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use OpenGL::Modern ':all'; | ||
use OpenGL::Modern::Helpers 'glGetVersion_p'; | ||
use Capture::Tiny 'capture'; | ||
|
||
SKIP: { | ||
plan skip_all => "glewContext did not succeed, skipping live tests" | ||
if glewCreateContext() != GLEW_OK; # returns GL_TRUE or GL_FALSE | ||
|
||
my $gI_status = ( done_glewInit() ) ? GLEW_OK() : glewInit(); # returns GLEW_OK or ??? | ||
plan skip_all => "glewInit did not succeed, skipping live tests" | ||
if $gI_status != GLEW_OK; | ||
|
||
glClear GL_COLOR; | ||
pass "didn't crash yet"; | ||
|
||
my ( $out, $err ) = capture { | ||
eval { $@ = undef; glpCheckErrors }; | ||
}; | ||
like $err, qr/OpenGL error: 1281/, "got expected errors"; | ||
like $@, qr/1 OpenGL errors encountered/, "can check for errors manually"; | ||
|
||
eval { $@ = undef; glpSetAutoCheckErrors 3 }; | ||
is $@, "Usage: glpSetAutoCheckErrors(1|0)\n", "glpSetAutoCheckErrors only accepts 2 values"; | ||
|
||
glpSetAutoCheckErrors 1; | ||
( $out, $err ) = capture { | ||
eval { $@ = undef; glClear GL_COLOR }; | ||
}; | ||
like $err, qr/OpenGL error: 1281/, "got expected errors"; | ||
like $@, qr/1 OpenGL errors encountered/, "errors cause crashes now"; | ||
|
||
glpSetAutoCheckErrors 0; | ||
glClear GL_COLOR; | ||
pass "crashes are gone again"; | ||
|
||
( $out, $err ) = capture { | ||
eval { $@ = undef; glpCheckErrors }; | ||
}; | ||
like $err, qr/OpenGL error: 1281/, "got expected errors"; | ||
like $@, qr/1 OpenGL errors encountered/, "but we can still check for errors manually"; | ||
|
||
done_testing; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters