Mercurial > sdl-ios-xcode
comparison src/video/SDL_renderer_gl.c @ 2222:926294b2bb4e
Emphasized the separation between SDL_Surface and SDL_Texture
- SDL_Surface is a system memory representation of pixel data
- SDL_Texture is a video memory representation of pixel data
The concept of SDL_Surface with SDL_HWSURFACE is no longer used.
Separated SDL_Texture types by usage rather than memory type
- SDL_TEXTUREACCESS_STATIC is for rarely changed pixel data,
can be placed in video memory.
- SDL_TEXTUREACCESS_STREAMING is for frequently changing pixel
data, usually placed in system memory or AGP memory.
Optimized the SDL_compat usage of the OpenGL renderer by only
using one copy of the framebuffer instead of two.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 11 Aug 2007 20:54:31 +0000 |
parents | f4c65e3bfaed |
children | 9b7d29d2432b |
comparison
equal
deleted
inserted
replaced
2221:1d75c38e1e5c | 2222:926294b2bb4e |
---|---|
36 | 36 |
37 static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags); | 37 static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags); |
38 static int GL_ActivateRenderer(SDL_Renderer * renderer); | 38 static int GL_ActivateRenderer(SDL_Renderer * renderer); |
39 static int GL_DisplayModeChanged(SDL_Renderer * renderer); | 39 static int GL_DisplayModeChanged(SDL_Renderer * renderer); |
40 static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); | 40 static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
41 static int GL_QueryTexturePixels(SDL_Renderer * renderer, | |
42 SDL_Texture * texture, void **pixels, | |
43 int *pitch); | |
41 static int GL_SetTexturePalette(SDL_Renderer * renderer, | 44 static int GL_SetTexturePalette(SDL_Renderer * renderer, |
42 SDL_Texture * texture, | 45 SDL_Texture * texture, |
43 const SDL_Color * colors, int firstcolor, | 46 const SDL_Color * colors, int firstcolor, |
44 int ncolors); | 47 int ncolors); |
45 static int GL_GetTexturePalette(SDL_Renderer * renderer, | 48 static int GL_GetTexturePalette(SDL_Renderer * renderer, |
243 } | 246 } |
244 | 247 |
245 renderer->ActivateRenderer = GL_ActivateRenderer; | 248 renderer->ActivateRenderer = GL_ActivateRenderer; |
246 renderer->DisplayModeChanged = GL_DisplayModeChanged; | 249 renderer->DisplayModeChanged = GL_DisplayModeChanged; |
247 renderer->CreateTexture = GL_CreateTexture; | 250 renderer->CreateTexture = GL_CreateTexture; |
251 renderer->QueryTexturePixels = GL_QueryTexturePixels; | |
248 renderer->SetTexturePalette = GL_SetTexturePalette; | 252 renderer->SetTexturePalette = GL_SetTexturePalette; |
249 renderer->GetTexturePalette = GL_GetTexturePalette; | 253 renderer->GetTexturePalette = GL_GetTexturePalette; |
250 renderer->SetTextureColorMod = GL_SetTextureColorMod; | 254 renderer->SetTextureColorMod = GL_SetTextureColorMod; |
251 renderer->SetTextureAlphaMod = GL_SetTextureAlphaMod; | 255 renderer->SetTextureAlphaMod = GL_SetTextureAlphaMod; |
252 renderer->SetTextureBlendMode = GL_SetTextureBlendMode; | 256 renderer->SetTextureBlendMode = GL_SetTextureBlendMode; |
490 return -1; | 494 return -1; |
491 } | 495 } |
492 SDL_memset(data->palette, 0xFF, 3 * 256 * sizeof(Uint8)); | 496 SDL_memset(data->palette, 0xFF, 3 * 256 * sizeof(Uint8)); |
493 } | 497 } |
494 | 498 |
499 if (texture->access == SDL_TEXTUREACCESS_STREAMING) { | |
500 data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); | |
501 data->pixels = SDL_malloc(texture->h * data->pitch); | |
502 if (!data->pixels) { | |
503 SDL_OutOfMemory(); | |
504 SDL_free(data); | |
505 return -1; | |
506 } | |
507 } | |
508 | |
495 texture->driverdata = data; | 509 texture->driverdata = data; |
496 | 510 |
497 renderdata->glGetError(); | 511 renderdata->glGetError(); |
498 renderdata->glGenTextures(1, &data->texture); | 512 renderdata->glGenTextures(1, &data->texture); |
499 if (renderdata->GL_ARB_texture_rectangle_supported) { | 513 if (renderdata->GL_ARB_texture_rectangle_supported) { |
521 } | 535 } |
522 return 0; | 536 return 0; |
523 } | 537 } |
524 | 538 |
525 static int | 539 static int |
540 GL_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture, | |
541 void **pixels, int *pitch) | |
542 { | |
543 GL_TextureData *data = (GL_TextureData *) texture->driverdata; | |
544 | |
545 *pixels = data->pixels; | |
546 *pitch = data->pitch; | |
547 return 0; | |
548 } | |
549 | |
550 static int | |
526 GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, | 551 GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture, |
527 const SDL_Color * colors, int firstcolor, int ncolors) | 552 const SDL_Color * colors, int firstcolor, int ncolors) |
528 { | 553 { |
529 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; | 554 GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata; |
530 GL_TextureData *data = (GL_TextureData *) texture->driverdata; | 555 GL_TextureData *data = (GL_TextureData *) texture->driverdata; |
658 GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, | 683 GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, |
659 const SDL_Rect * rect, int markDirty, void **pixels, | 684 const SDL_Rect * rect, int markDirty, void **pixels, |
660 int *pitch) | 685 int *pitch) |
661 { | 686 { |
662 GL_TextureData *data = (GL_TextureData *) texture->driverdata; | 687 GL_TextureData *data = (GL_TextureData *) texture->driverdata; |
663 | |
664 if (!data->pixels) { | |
665 data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format); | |
666 data->pixels = SDL_malloc(texture->h * data->pitch); | |
667 if (!data->pixels) { | |
668 SDL_OutOfMemory(); | |
669 return -1; | |
670 } | |
671 } | |
672 | 688 |
673 if (markDirty) { | 689 if (markDirty) { |
674 SDL_AddDirtyRect(&data->dirty, rect); | 690 SDL_AddDirtyRect(&data->dirty, rect); |
675 } | 691 } |
676 | 692 |