Mercurial > repos > blastem
comparison render_sdl.c @ 495:39cad98d2789
Allow OpenGL support to be disabled at compile time. Move generic utility functions out of config.c
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 28 Oct 2013 19:37:30 -0700 |
parents | c8e65962bfed |
children | 0820a71b80f3 |
comparison
equal
deleted
inserted
replaced
492:dffc07104b09 | 495:39cad98d2789 |
---|---|
95 } else { | 95 } else { |
96 return SDL_MapRGB(screen->format, r, g, b); | 96 return SDL_MapRGB(screen->format, r, g, b); |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 #ifndef DISABLE_OPENGL | |
100 GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], at_pos; | 101 GLuint textures[3], buffers[2], vshader, fshader, program, un_textures[2], at_pos; |
101 | 102 |
102 const GLfloat vertex_data[] = { | 103 const GLfloat vertex_data[] = { |
103 -1.0f, -1.0f, | 104 -1.0f, -1.0f, |
104 1.0f, -1.0f, | 105 1.0f, -1.0f, |
140 glDeleteShader(ret); | 141 glDeleteShader(ret); |
141 return 0; | 142 return 0; |
142 } | 143 } |
143 return ret; | 144 return ret; |
144 } | 145 } |
146 #endif | |
145 | 147 |
146 void render_alloc_surfaces(vdp_context * context) | 148 void render_alloc_surfaces(vdp_context * context) |
147 { | 149 { |
150 #ifndef DISABLE_OPENGL | |
148 if (render_gl) { | 151 if (render_gl) { |
149 context->oddbuf = context->framebuf = malloc(320 * 240 * 4 * 2); | 152 context->oddbuf = context->framebuf = malloc(320 * 240 * 4 * 2); |
150 memset(context->oddbuf, 0, 320 * 240 * 4 * 2); | 153 memset(context->oddbuf, 0, 320 * 240 * 4 * 2); |
151 context->evenbuf = ((char *)context->oddbuf) + 320 * 240 * 4; | 154 context->evenbuf = ((char *)context->oddbuf) + 320 * 240 * 4; |
152 glGenTextures(3, textures); | 155 glGenTextures(3, textures); |
183 } | 186 } |
184 un_textures[0] = glGetUniformLocation(program, "textures[0]"); | 187 un_textures[0] = glGetUniformLocation(program, "textures[0]"); |
185 un_textures[1] = glGetUniformLocation(program, "textures[1]"); | 188 un_textures[1] = glGetUniformLocation(program, "textures[1]"); |
186 at_pos = glGetAttribLocation(program, "pos"); | 189 at_pos = glGetAttribLocation(program, "pos"); |
187 } else { | 190 } else { |
191 #endif | |
188 context->oddbuf = context->framebuf = malloc(320 * 240 * screen->format->BytesPerPixel * 2); | 192 context->oddbuf = context->framebuf = malloc(320 * 240 * screen->format->BytesPerPixel * 2); |
189 context->evenbuf = ((char *)context->oddbuf) + 320 * 240 * screen->format->BytesPerPixel; | 193 context->evenbuf = ((char *)context->oddbuf) + 320 * 240 * screen->format->BytesPerPixel; |
190 } | 194 #ifndef DISABLE_OPENGL |
195 } | |
196 #endif | |
191 } | 197 } |
192 | 198 |
193 uint8_t render_depth() | 199 uint8_t render_depth() |
194 { | 200 { |
195 return screen->format->BytesPerPixel * 8; | 201 return screen->format->BytesPerPixel * 8; |
318 printf("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); | 324 printf("\tNum Axes: %d\n\tNum Buttons: %d\n\tNum Hats: %d\n", SDL_JoystickNumAxes(joy), SDL_JoystickNumButtons(joy), SDL_JoystickNumHats(joy)); |
319 } | 325 } |
320 } | 326 } |
321 SDL_JoystickEventState(SDL_ENABLE); | 327 SDL_JoystickEventState(SDL_ENABLE); |
322 } | 328 } |
323 | 329 #ifndef DISABLE_OPENGL |
324 void render_context_gl(vdp_context * context) | 330 void render_context_gl(vdp_context * context) |
325 { | 331 { |
326 glBindTexture(GL_TEXTURE_2D, textures[context->framebuf == context->oddbuf ? 0 : 1]); | 332 glBindTexture(GL_TEXTURE_2D, textures[context->framebuf == context->oddbuf ? 0 : 1]); |
327 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 320, 240, GL_BGRA, GL_UNSIGNED_BYTE, context->framebuf);; | 333 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 320, 240, GL_BGRA, GL_UNSIGNED_BYTE, context->framebuf);; |
328 | 334 |
351 if (context->regs[REG_MODE_4] & BIT_INTERLACE) | 357 if (context->regs[REG_MODE_4] & BIT_INTERLACE) |
352 { | 358 { |
353 context->framebuf = context->framebuf == context->oddbuf ? context->evenbuf : context->oddbuf; | 359 context->framebuf = context->framebuf == context->oddbuf ? context->evenbuf : context->oddbuf; |
354 } | 360 } |
355 } | 361 } |
362 #endif | |
356 | 363 |
357 uint32_t blankbuf[320*240]; | 364 uint32_t blankbuf[320*240]; |
358 | 365 |
359 void render_context(vdp_context * context) | 366 void render_context(vdp_context * context) |
360 { | 367 { |
361 uint16_t *buf_16; | 368 uint16_t *buf_16; |
362 uint32_t *buf_32; | 369 uint32_t *buf_32; |
363 uint8_t b,g,r; | 370 uint8_t b,g,r; |
364 last_frame = SDL_GetTicks(); | 371 last_frame = SDL_GetTicks(); |
372 #ifndef DISABLE_OPENGL | |
365 if (render_gl) | 373 if (render_gl) |
366 { | 374 { |
367 render_context_gl(context); | 375 render_context_gl(context); |
368 return; | 376 return; |
369 } | 377 } |
378 #endif | |
370 if (SDL_MUSTLOCK(screen)) { | 379 if (SDL_MUSTLOCK(screen)) { |
371 if (SDL_LockSurface(screen) < 0) { | 380 if (SDL_LockSurface(screen) < 0) { |
372 return; | 381 return; |
373 } | 382 } |
374 } | 383 } |