src/glcontext.c

changeset 90
aa8e7a38905c
parent 89
e1f682a8a145
equal deleted inserted replaced
89:e1f682a8a145 90:aa8e7a38905c
48 cx_strfree(&buf); 48 cx_strfree(&buf);
49 } 49 }
50 50
51 static int asc_primitives_init(AscGLContext *context) { 51 static int asc_primitives_init(AscGLContext *context) {
52 asc_dprintf("Create primitives for the GL context of active window."); 52 asc_dprintf("Create primitives for the GL context of active window.");
53 asc_mesh_allocate_buffers((AscMesh*)&context->primitives, sizeof(context->primitives) / sizeof(AscMesh)); 53 asc_mesh_allocate_buffers(context->primitives, ASC_PRIMITIVE_COUNT);
54 54
55 asc_primitives_init_plane(&context->primitives.plane); 55 asc_primitives_init_plane(&context->primitives[ASC_PRIMITIVE_PLANE_IDX]);
56 // TODO: more primitives 56 // TODO: more primitives
57 57
58 return asc_error_catch_all_gl(); 58 return asc_error_catch_all_gl();
59 } 59 }
60 60
73 static void asc_shader_destroy_predefined(AscGLContext *ctx) { 73 static void asc_shader_destroy_predefined(AscGLContext *ctx) {
74 asc_shader_program_destroy(&ctx->shader.sprite.program); 74 asc_shader_program_destroy(&ctx->shader.sprite.program);
75 } 75 }
76 76
77 static int asc_texture_initialize_predefined(AscGLContext *ctx) { 77 static int asc_texture_initialize_predefined(AscGLContext *ctx) {
78 asc_texture_init_rectangle(&ctx->textures.empty_1x1_rect, 1); 78 asc_texture_init_rectangle(ctx->textures_rect, ASC_TEXTURE_RECT_COUNT);
79 asc_texture_init_2d(&ctx->textures.empty_1x1_2d, 1); 79 asc_texture_init_2d(ctx->textures_2d, ASC_TEXTURE_2D_COUNT);
80 80
81 // Create a 1x1 surface with 32-bit RGBA format 81 // Create a 1x1 surface with 32-bit RGBA format
82 SDL_Surface* white1x1 = SDL_CreateRGBSurface( 82 SDL_Surface* white1x1 = SDL_CreateRGBSurface(
83 0, 1, 1, 32, 83 0, 1, 1, 32,
84 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF); 84 0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF);
89 return 1; 89 return 1;
90 } 90 }
91 SDL_FillRect(white1x1, NULL, 0xFFFFFFFF); 91 SDL_FillRect(white1x1, NULL, 0xFFFFFFFF);
92 92
93 // Initialize the empty textures with the white surface 93 // Initialize the empty textures with the white surface
94 asc_texture_from_surface(&ctx->textures.empty_1x1_2d, white1x1); 94 asc_texture_from_surface(&ctx->textures_rect[ASC_TEXTURE_RECT_EMPTY_1X1_IDX], white1x1);
95 asc_texture_from_surface(&ctx->textures.empty_1x1_rect, white1x1); 95 asc_texture_from_surface(&ctx->textures_2d[ASC_TEXTURE_2D_EMPTY_1X1_IDX], white1x1);
96 96
97 return asc_error_catch_all_gl(); 97 return asc_error_catch_all_gl();
98 } 98 }
99 99
100 static void asc_texture_destroy_predefined(AscGLContext *ctx) { 100 static void asc_texture_destroy_predefined(AscGLContext *ctx) {
101 asc_texture_destroy(&ctx->textures.empty_1x1_2d, 1); 101 asc_texture_destroy(ctx->textures_rect, ASC_TEXTURE_RECT_COUNT);
102 asc_texture_destroy(&ctx->textures.empty_1x1_rect, 1); 102 asc_texture_destroy(ctx->textures_2d, ASC_TEXTURE_2D_COUNT);
103 } 103 }
104 104
105 bool asc_gl_context_initialize( 105 bool asc_gl_context_initialize(
106 AscGLContext *ctx, 106 AscGLContext *ctx,
107 SDL_Window *window, 107 SDL_Window *window,

mercurial