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.

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%402584
This commit is contained in:
Sam Lantinga 2007-08-11 20:54:31 +00:00
parent c1a200fa1d
commit 6b348f07c7
11 changed files with 203 additions and 291 deletions

View file

@ -38,6 +38,9 @@ static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags);
static int GL_ActivateRenderer(SDL_Renderer * renderer);
static int GL_DisplayModeChanged(SDL_Renderer * renderer);
static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int GL_QueryTexturePixels(SDL_Renderer * renderer,
SDL_Texture * texture, void **pixels,
int *pitch);
static int GL_SetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture,
const SDL_Color * colors, int firstcolor,
@ -245,6 +248,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->ActivateRenderer = GL_ActivateRenderer;
renderer->DisplayModeChanged = GL_DisplayModeChanged;
renderer->CreateTexture = GL_CreateTexture;
renderer->QueryTexturePixels = GL_QueryTexturePixels;
renderer->SetTexturePalette = GL_SetTexturePalette;
renderer->GetTexturePalette = GL_GetTexturePalette;
renderer->SetTextureColorMod = GL_SetTextureColorMod;
@ -492,6 +496,16 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
SDL_memset(data->palette, 0xFF, 3 * 256 * sizeof(Uint8));
}
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
data->pixels = SDL_malloc(texture->h * data->pitch);
if (!data->pixels) {
SDL_OutOfMemory();
SDL_free(data);
return -1;
}
}
texture->driverdata = data;
renderdata->glGetError();
@ -522,6 +536,17 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
return 0;
}
static int
GL_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
void **pixels, int *pitch)
{
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
*pixels = data->pixels;
*pitch = data->pitch;
return 0;
}
static int
GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Color * colors, int firstcolor, int ncolors)
@ -661,15 +686,6 @@ GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
{
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
if (!data->pixels) {
data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
data->pixels = SDL_malloc(texture->h * data->pitch);
if (!data->pixels) {
SDL_OutOfMemory();
return -1;
}
}
if (markDirty) {
SDL_AddDirtyRect(&data->dirty, rect);
}