src/glcontext.c

changeset 92
78ce93fb46e5
parent 90
aa8e7a38905c
child 93
52611a99e574
equal deleted inserted replaced
91:8433c87c0f51 92:78ce93fb46e5
35 static void asc_gl_debug_callback( 35 static void asc_gl_debug_callback(
36 GLenum source, GLenum type, GLuint id, GLenum severity, 36 GLenum source, GLenum type, GLuint id, GLenum severity,
37 GLsizei length, const GLchar* message, 37 GLsizei length, const GLchar* message,
38 const void* userParam 38 const void* userParam
39 ) { 39 ) {
40 cxmutstr buf = cx_asprintf( 40 if (type == GL_DEBUG_TYPE_ERROR) {
41 "source = %d, id = %u, type = %d, severity= %d, message = %.*s", 41 asc_error("OpenGL source = %d, id = %u, type = %d, severity= %d, message = %.*s",
42 source, id, type, severity, length, message); 42 source, id, type, severity, length, message);
43 if (type == GL_DEBUG_TYPE_ERROR) {
44 asc_error(buf.ptr);
45 } else { 43 } else {
46 asc_dprintf("GL debug: %.*s", (int)buf.length, buf.ptr); 44 asc_dprintf("OpenGL source = %d, id = %u, type = %d, severity= %d, message = %.*s",
45 source, id, type, severity, length, message);
47 } 46 }
48 cx_strfree(&buf);
49 } 47 }
50 48
51 static int asc_primitives_init(AscGLContext *context) { 49 static int asc_primitives_init(AscGLContext *context) {
52 asc_dprintf("Create primitives for the GL context of active window."); 50 asc_dprintf("Create primitives for the GL context of active window.");
53 asc_mesh_allocate_buffers(context->primitives, ASC_PRIMITIVE_COUNT); 51 asc_mesh_allocate_buffers(context->primitives, ASC_PRIMITIVE_COUNT);
81 // Create a 1x1 surface with 32-bit RGBA format 79 // Create a 1x1 surface with 32-bit RGBA format
82 SDL_Surface* white1x1 = SDL_CreateRGBSurface( 80 SDL_Surface* white1x1 = SDL_CreateRGBSurface(
83 0, 1, 1, 32, 81 0, 1, 1, 32,
84 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); 82 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
85 if (white1x1 == NULL) { 83 if (white1x1 == NULL) {
86 // TODO: merge error messages once asc_error allows formatting 84 asc_error("Failed to create surface: %s", SDL_GetError());
87 asc_error("Failed to create surface");
88 asc_error(SDL_GetError());
89 return 1; 85 return 1;
90 } 86 }
91 SDL_FillRect(white1x1, NULL, 0xFFFFFFFF); 87 SDL_FillRect(white1x1, NULL, 0xFFFFFFFF);
92 88
93 // Initialize the empty textures with the white surface 89 // Initialize the empty textures with the white surface
142 return false; 138 return false;
143 } 139 }
144 140
145 return true; 141 return true;
146 } else { 142 } else {
147 asc_error(glewGetErrorString(err)); 143 asc_error("glewInit failed: %s", glewGetErrorString(err));
148 SDL_GL_DeleteContext(ctx->glctx); 144 SDL_GL_DeleteContext(ctx->glctx);
149 return false; 145 return false;
150 } 146 }
151 } 147 }
152 148

mercurial