src/glcontext.c

changeset 115
e5f8c99b0987
parent 110
29f8d0d586f8
child 137
f8e6e0ae61a8
equal deleted inserted replaced
114:5b91bbab1ac0 115:e5f8c99b0987
41 source, id, type, severity, length, message); 41 source, id, type, severity, length, message);
42 } else { 42 } else {
43 asc_dprintf("OpenGL source = %d, id = %u, type = %d, severity= %d, message = %.*s", 43 asc_dprintf("OpenGL source = %d, id = %u, type = %d, severity= %d, message = %.*s",
44 source, id, type, severity, length, message); 44 source, id, type, severity, length, message);
45 } 45 }
46 }
47
48 static int asc_primitives_init(AscGLContext *context) {
49 asc_dprintf("Create primitives for the GL context of active window.");
50 asc_mesh_allocate_buffers(context->primitives, ASC_PRIMITIVE_COUNT);
51
52 asc_primitives_init_plane(&context->primitives[ASC_PRIMITIVE_PLANE_IDX]);
53 // TODO: more primitives
54
55 return asc_error_catch_all_gl();
56 }
57
58 static void asc_primitives_destroy(AscGLContext *context) {
59 asc_dprintf("Destroy primitives in GL context of active window.");
60 asc_mesh_free_buffers((AscMesh*)&context->primitives, sizeof(context->primitives) / sizeof(AscMesh));
61 } 46 }
62 47
63 static int asc_shader_initialize_predefined(AscGLContext *ctx) { 48 static int asc_shader_initialize_predefined(AscGLContext *ctx) {
64 int ret = 0; 49 int ret = 0;
65 ret |= asc_shader_sprite_init(&ctx->shader.sprite); 50 ret |= asc_shader_sprite_init(&ctx->shader.sprite);
143 128
144 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 129 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
145 glEnable(GL_DEBUG_OUTPUT); 130 glEnable(GL_DEBUG_OUTPUT);
146 glDebugMessageCallback(asc_gl_debug_callback, NULL); 131 glDebugMessageCallback(asc_gl_debug_callback, NULL);
147 132
148 if (asc_primitives_init(ctx)) {
149 asc_error("Creating primitive meshes failed");
150 SDL_GL_DeleteContext(ctx->glctx);
151 return false;
152 }
153
154 if (asc_shader_initialize_predefined(ctx)) { 133 if (asc_shader_initialize_predefined(ctx)) {
155 asc_error("Initializing predefined shaders failed"); 134 asc_error("Initializing predefined shaders failed");
156 SDL_GL_DeleteContext(ctx->glctx); 135 SDL_GL_DeleteContext(ctx->glctx);
157 return false; 136 return false;
158 } 137 }
178 SDL_GL_MakeCurrent(ctx->window, ctx->glctx); 157 SDL_GL_MakeCurrent(ctx->window, ctx->glctx);
179 158
180 cxListFree(ctx->cleanup_funcs); 159 cxListFree(ctx->cleanup_funcs);
181 asc_texture_destroy_predefined(ctx); 160 asc_texture_destroy_predefined(ctx);
182 asc_shader_destroy_predefined(ctx); 161 asc_shader_destroy_predefined(ctx);
183 asc_primitives_destroy(ctx);
184 162
185 // destroy the GL context and the window 163 // destroy the GL context and the window
186 SDL_GL_DeleteContext(ctx->glctx); 164 SDL_GL_DeleteContext(ctx->glctx);
187 ctx->glctx = NULL; 165 ctx->glctx = NULL;
188 } 166 }

mercurial