Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Making the API simpler, removed support for palettized video modes an…
Browse files Browse the repository at this point in the history
…d textures.
  • Loading branch information
slouken committed Feb 2, 2011
1 parent a806932 commit 04e9376
Show file tree
Hide file tree
Showing 23 changed files with 19 additions and 783 deletions.
32 changes: 0 additions & 32 deletions include/SDL_render.h
Expand Up @@ -219,38 +219,6 @@ extern DECLSPEC int SDLCALL SDL_QueryTexture(SDL_Texture * texture,
extern DECLSPEC int SDLCALL SDL_QueryTexturePixels(SDL_Texture * texture,
void **pixels, int *pitch);

/**
* \brief Set the color palette of an indexed texture.
*
* \param texture The texture to update.
* \param colors The array of RGB color data.
* \param firstcolor The first index to update.
* \param ncolors The number of palette entries to fill with the color data.
*
* \return 0 on success, or -1 if the texture is not valid or not an indexed
* texture.
*/
extern DECLSPEC int SDLCALL SDL_SetTexturePalette(SDL_Texture * texture,
const SDL_Color * colors,
int firstcolor,
int ncolors);

/**
* \brief Get the color palette from an indexed texture if it has one.
*
* \param texture The texture to update.
* \param colors The array to fill with RGB color data.
* \param firstcolor The first index to retrieve.
* \param ncolors The number of palette entries to retrieve.
*
* \return 0 on success, or -1 if the texture is not valid or not an indexed
* texture.
*/
extern DECLSPEC int SDLCALL SDL_GetTexturePalette(SDL_Texture * texture,
SDL_Color * colors,
int firstcolor,
int ncolors);

/**
* \brief Set an additional color value used in render copy operations.
*
Expand Down
19 changes: 0 additions & 19 deletions include/SDL_video.h
Expand Up @@ -355,25 +355,6 @@ extern DECLSPEC int SDLCALL SDL_SetWindowDisplayMode(SDL_Window * window,
extern DECLSPEC int SDLCALL SDL_GetWindowDisplayMode(SDL_Window * window,
SDL_DisplayMode * mode);

/**
* \brief Set the palette entries for indexed display modes.
*
* \return 0 on success, or -1 if the display mode isn't palettized or the
* colors couldn't be set.
*/
extern DECLSPEC int SDLCALL SDL_SetDisplayPalette(const SDL_Color * colors,
int firstcolor,
int ncolors);

/**
* \brief Gets the palette entries for indexed display modes.
*
* \return 0 on success, or -1 if the display mode isn't palettized
*/
extern DECLSPEC int SDLCALL SDL_GetDisplayPalette(SDL_Color * colors,
int firstcolor,
int ncolors);

/**
* \brief Set the gamma correction for each of the color channels on the
* currently selected display.
Expand Down
46 changes: 2 additions & 44 deletions src/SDL_compat.c
Expand Up @@ -320,27 +320,6 @@ SDL_CompatEventFilter(void *userdata, SDL_Event * event)
return 1;
}

static int
SDL_VideoPaletteChanged(void *userdata, SDL_Palette * palette)
{
if (userdata == SDL_ShadowSurface) {
/* If the shadow palette changed, make the changes visible */
if (!SDL_VideoSurface->format->palette) {
SDL_UpdateRect(SDL_ShadowSurface, 0, 0, 0, 0);
}
}
if (userdata == SDL_VideoSurface) {
/* The display may not have a palette, but always set texture palette */
SDL_SetDisplayPalette(palette->colors, 0, palette->ncolors);

if (SDL_SetTexturePalette
(SDL_VideoTexture, palette->colors, 0, palette->ncolors) < 0) {
return -1;
}
}
return 0;
}

static void
GetEnvironmentWindowPosition(int w, int h, int *x, int *y)
{
Expand Down Expand Up @@ -543,8 +522,6 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
SDL_ShadowSurface = NULL;
}
if (SDL_VideoSurface) {
SDL_DelPaletteWatch(SDL_VideoSurface->format->palette,
SDL_VideoPaletteChanged, NULL);
SDL_FreeSurface(SDL_VideoSurface);
SDL_VideoSurface = NULL;
}
Expand Down Expand Up @@ -694,18 +671,6 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
}
SDL_VideoSurface->flags |= surface_flags;

/* Set a default screen palette */
if (SDL_VideoSurface->format->palette) {
SDL_VideoSurface->flags |= SDL_HWPALETTE;
SDL_DitherColors(SDL_VideoSurface->format->palette->colors,
SDL_VideoSurface->format->BitsPerPixel);
SDL_AddPaletteWatch(SDL_VideoSurface->format->palette,
SDL_VideoPaletteChanged, SDL_VideoSurface);
SDL_SetPaletteColors(SDL_VideoSurface->format->palette,
SDL_VideoSurface->format->palette->colors, 0,
SDL_VideoSurface->format->palette->ncolors);
}

/* Create a shadow surface if necessary */
if ((bpp != SDL_VideoSurface->format->BitsPerPixel)
&& !(flags & SDL_ANYFORMAT)) {
Expand All @@ -719,15 +684,8 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
/* 8-bit SDL_ShadowSurface surfaces report that they have exclusive palette */
if (SDL_ShadowSurface->format->palette) {
SDL_ShadowSurface->flags |= SDL_HWPALETTE;
if (SDL_VideoSurface->format->palette) {
SDL_SetSurfacePalette(SDL_ShadowSurface,
SDL_VideoSurface->format->palette);
} else {
SDL_DitherColors(SDL_ShadowSurface->format->palette->colors,
SDL_ShadowSurface->format->BitsPerPixel);
}
SDL_AddPaletteWatch(SDL_ShadowSurface->format->palette,
SDL_VideoPaletteChanged, SDL_ShadowSurface);
SDL_DitherColors(SDL_ShadowSurface->format->palette->colors,
SDL_ShadowSurface->format->BitsPerPixel);
}
}
SDL_PublicSurface =
Expand Down
119 changes: 1 addition & 118 deletions src/video/SDL_renderer_gl.c
Expand Up @@ -72,13 +72,6 @@ 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,
int ncolors);
static int GL_GetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture, SDL_Color * colors,
int firstcolor, int ncolors);
static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
int pitch);
Expand Down Expand Up @@ -111,11 +104,8 @@ SDL_RenderDriver GL_RenderDriver = {
{
"opengl",
(SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
15,
13,
{
SDL_PIXELFORMAT_INDEX1LSB,
SDL_PIXELFORMAT_INDEX1MSB,
SDL_PIXELFORMAT_INDEX8,
SDL_PIXELFORMAT_RGB332,
SDL_PIXELFORMAT_RGB444,
SDL_PIXELFORMAT_RGB555,
Expand Down Expand Up @@ -149,7 +139,6 @@ typedef struct
#include "SDL_glfuncs.h"
#undef SDL_PROC

PFNGLCOLORTABLEEXTPROC glColorTableEXT;
void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
const GLvoid * pointer);

Expand Down Expand Up @@ -278,8 +267,6 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->WindowEvent = GL_WindowEvent;
renderer->CreateTexture = GL_CreateTexture;
renderer->QueryTexturePixels = GL_QueryTexturePixels;
renderer->SetTexturePalette = GL_SetTexturePalette;
renderer->GetTexturePalette = GL_GetTexturePalette;
renderer->UpdateTexture = GL_UpdateTexture;
renderer->LockTexture = GL_LockTexture;
renderer->UnlockTexture = GL_UnlockTexture;
Expand Down Expand Up @@ -339,21 +326,6 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
|| SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
}
if (SDL_GL_ExtensionSupported("GL_EXT_paletted_texture")) {
data->GL_EXT_paletted_texture_supported = SDL_TRUE;
data->glColorTableEXT =
(PFNGLCOLORTABLEEXTPROC) SDL_GL_GetProcAddress("glColorTableEXT");
} else {
/* Don't advertise support for 8-bit indexed texture format */
Uint32 i, j;
SDL_RendererInfo *info = &renderer->info;
for (i = 0, j = 0; i < info->num_texture_formats; ++i) {
if (info->texture_formats[i] != SDL_PIXELFORMAT_INDEX8) {
info->texture_formats[j++] = info->texture_formats[i];
}
}
--info->num_texture_formats;
}
if (SDL_GL_ExtensionSupported("GL_APPLE_ycbcr_422")) {
data->GL_APPLE_ycbcr_422_supported = SDL_TRUE;
}
Expand Down Expand Up @@ -572,20 +544,6 @@ convert_format(GL_RenderData *renderdata, Uint32 pixel_format,
GLint* internalFormat, GLenum* format, GLenum* type)
{
switch (pixel_format) {
case SDL_PIXELFORMAT_INDEX1LSB:
case SDL_PIXELFORMAT_INDEX1MSB:
*internalFormat = GL_RGB;
*format = GL_COLOR_INDEX;
*type = GL_BITMAP;
break;
case SDL_PIXELFORMAT_INDEX8:
if (!renderdata->GL_EXT_paletted_texture_supported) {
return SDL_FALSE;
}
*internalFormat = GL_COLOR_INDEX8_EXT;
*format = GL_COLOR_INDEX;
*type = GL_UNSIGNED_BYTE;
break;
case SDL_PIXELFORMAT_RGB332:
*internalFormat = GL_R3_G3_B2;
*format = GL_RGB;
Expand Down Expand Up @@ -752,16 +710,6 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)

data->shader = shader;

if (texture->format == SDL_PIXELFORMAT_INDEX8) {
data->palette = (Uint8 *) SDL_malloc(3 * 256 * sizeof(Uint8));
if (!data->palette) {
SDL_OutOfMemory();
SDL_free(data);
return -1;
}
SDL_memset(data->palette, 0xFF, 3 * 256 * sizeof(Uint8));
}

if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
data->pitch = texture->w * bytes_per_pixel(texture->format);
data->pixels = SDL_malloc(texture->h * data->pitch);
Expand Down Expand Up @@ -871,65 +819,10 @@ GL_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
return 0;
}

static int
GL_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Color * colors, int firstcolor, int ncolors)
{
GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
Uint8 *palette;

GL_ActivateRenderer(renderer);

if (!data->palette) {
SDL_SetError("Texture doesn't have a palette");
return -1;
}
palette = data->palette + firstcolor * 3;
while (ncolors--) {
*palette++ = colors->r;
*palette++ = colors->g;
*palette++ = colors->b;
++colors;
}
renderdata->glEnable(data->type);
renderdata->glBindTexture(data->type, data->texture);
renderdata->glColorTableEXT(data->type, GL_RGB8, 256, GL_RGB,
GL_UNSIGNED_BYTE, data->palette);
return 0;
}

static int
GL_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
SDL_Color * colors, int firstcolor, int ncolors)
{
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
Uint8 *palette;

if (!data->palette) {
SDL_SetError("Texture doesn't have a palette");
return -1;
}
palette = data->palette + firstcolor * 3;
while (ncolors--) {
colors->r = *palette++;
colors->g = *palette++;
colors->b = *palette++;
colors->unused = SDL_ALPHA_OPAQUE;
++colors;
}
return 0;
}

static void
SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture,
int pitch)
{
if (texture->format == SDL_PIXELFORMAT_INDEX1LSB) {
renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
} else if (texture->format == SDL_PIXELFORMAT_INDEX1MSB) {
renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 0);
}
renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
(pitch / bytes_per_pixel(texture->format)) /
Expand Down Expand Up @@ -1265,11 +1158,6 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
return -1;
}

if (pixel_format == SDL_PIXELFORMAT_INDEX1LSB) {
data->glPixelStorei(GL_PACK_LSB_FIRST, 1);
} else if (pixel_format == SDL_PIXELFORMAT_INDEX1MSB) {
data->glPixelStorei(GL_PACK_LSB_FIRST, 0);
}
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
data->glPixelStorei(GL_PACK_ROW_LENGTH,
(pitch / bytes_per_pixel(pixel_format)));
Expand Down Expand Up @@ -1314,11 +1202,6 @@ GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
return -1;
}

if (pixel_format == SDL_PIXELFORMAT_INDEX1LSB) {
data->glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
} else if (pixel_format == SDL_PIXELFORMAT_INDEX1MSB) {
data->glPixelStorei(GL_UNPACK_LSB_FIRST, 0);
}
data->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
data->glPixelStorei(GL_UNPACK_ROW_LENGTH,
(pitch / bytes_per_pixel(pixel_format)));
Expand Down
25 changes: 0 additions & 25 deletions src/video/SDL_renderer_gles.c
Expand Up @@ -60,13 +60,6 @@ static int GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int GLES_QueryTexturePixels(SDL_Renderer * renderer,
SDL_Texture * texture, void **pixels,
int *pitch);
static int GLES_SetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture,
const SDL_Color * colors, int firstcolor,
int ncolors);
static int GLES_GetTexturePalette(SDL_Renderer * renderer,
SDL_Texture * texture, SDL_Color * colors,
int firstcolor, int ncolors);
static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
int pitch);
Expand Down Expand Up @@ -219,8 +212,6 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->WindowEvent = GLES_WindowEvent;
renderer->CreateTexture = GLES_CreateTexture;
renderer->QueryTexturePixels = GLES_QueryTexturePixels;
renderer->SetTexturePalette = GLES_SetTexturePalette;
renderer->GetTexturePalette = GLES_GetTexturePalette;
renderer->UpdateTexture = GLES_UpdateTexture;
renderer->LockTexture = GLES_LockTexture;
renderer->UnlockTexture = GLES_UnlockTexture;
Expand Down Expand Up @@ -467,22 +458,6 @@ GLES_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
return 0;
}

static int
GLES_SetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Color * colors, int firstcolor, int ncolors)
{
SDL_SetError("OpenGL ES does not support paletted textures");
return -1;
}

static int
GLES_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
SDL_Color * colors, int firstcolor, int ncolors)
{
SDL_SetError("OpenGL ES does not support paletted textures");
return -1;
}

static void
SetupTextureUpdate(GLES_RenderData * renderdata, SDL_Texture * texture,
int pitch)
Expand Down

0 comments on commit 04e9376

Please sign in to comment.