Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Making the API simpler, removed the writepixels interface

  • Loading branch information
slouken committed Feb 3, 2011
1 parent d1ef75d commit d199e964cba12f50985d560e4c17b588b046e90a
@@ -526,26 +526,6 @@ extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
Uint32 format,
void *pixels, int pitch);

/**
* \brief Write pixels to the current rendering target.
*
* \param rect A pointer to the rectangle to write, or NULL for the entire
* render target.
* \param format The format of the pixel data, or 0 to use the format
* of the rendering target
* \param pixels A pointer to the pixel data to write.
* \param pitch The pitch of the pixels parameter.
*
* \return 0 on success, or -1 if pixel writing is not supported.
*
* \warning This is a very slow operation, and should not be used frequently.
*/
extern DECLSPEC int SDLCALL SDL_RenderWritePixels(SDL_Renderer * renderer,
const SDL_Rect * rect,
Uint32 format,
const void *pixels,
int pitch);

/**
* \brief Update the screen with rendering performed.
*/
@@ -1212,45 +1212,6 @@ SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
format, pixels, pitch);
}

int
SDL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, const void * pixels, int pitch)
{
SDL_Window *window;
SDL_Rect real_rect;

CHECK_RENDERER_MAGIC(renderer, -1);

if (!renderer->RenderWritePixels) {
SDL_Unsupported();
return -1;
}
window = renderer->window;

if (!format) {
format = SDL_GetWindowPixelFormat(window);
}

real_rect.x = 0;
real_rect.y = 0;
SDL_GetWindowSize(window, &real_rect.w, &real_rect.h);
if (rect) {
if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
return 0;
}
if (real_rect.y > rect->y) {
pixels = (const Uint8 *)pixels + pitch * (real_rect.y - rect->y);
}
if (real_rect.x > rect->x) {
int bpp = SDL_BYTESPERPIXEL(SDL_GetWindowPixelFormat(window));
pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x);
}
}

return renderer->RenderWritePixels(renderer, &real_rect,
format, pixels, pitch);
}

void
SDL_RenderPresent(SDL_Renderer * renderer)
{
@@ -89,8 +89,6 @@ struct SDL_Renderer
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch);
int (*RenderWritePixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, const void * pixels, int pitch);
void (*RenderPresent) (SDL_Renderer * renderer);
void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);

@@ -115,8 +115,6 @@ static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch);
static int D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, const void * pixels, int pitch);
static void D3D_RenderPresent(SDL_Renderer * renderer);
static void D3D_DestroyTexture(SDL_Renderer * renderer,
SDL_Texture * texture);
@@ -325,7 +323,6 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->RenderFillRects = D3D_RenderFillRects;
renderer->RenderCopy = D3D_RenderCopy;
renderer->RenderReadPixels = D3D_RenderReadPixels;
renderer->RenderWritePixels = D3D_RenderWritePixels;
renderer->RenderPresent = D3D_RenderPresent;
renderer->DestroyTexture = D3D_DestroyTexture;
renderer->DestroyRenderer = D3D_DestroyRenderer;
@@ -1021,15 +1018,6 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
return 0;
}

static int
D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, const void * pixels, int pitch)
{
/* Work in progress */
SDL_Unsupported();
return -1;
}

static void
D3D_RenderPresent(SDL_Renderer * renderer)
{
@@ -63,8 +63,6 @@ static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 pixel_format, void * pixels, int pitch);
static int GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 pixel_format, const void * pixels, int pitch);
static void GL_RenderPresent(SDL_Renderer * renderer);
static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static void GL_DestroyRenderer(SDL_Renderer * renderer);
@@ -207,7 +205,6 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->RenderFillRects = GL_RenderFillRects;
renderer->RenderCopy = GL_RenderCopy;
renderer->RenderReadPixels = GL_RenderReadPixels;
renderer->RenderWritePixels = GL_RenderWritePixels;
renderer->RenderPresent = GL_RenderPresent;
renderer->DestroyTexture = GL_DestroyTexture;
renderer->DestroyRenderer = GL_DestroyRenderer;
@@ -776,50 +773,6 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
return 0;
}

static int
GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 pixel_format, const void * pixels, int pitch)
{
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
SDL_Window *window = renderer->window;
GLint internalFormat;
GLenum format, type;
Uint8 *src, *dst, *tmp;
int w, h, length, rows;

GL_ActivateRenderer(renderer);

if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) {
/* FIXME: Do a temp copy to a format that is supported */
SDL_SetError("Unsupported pixel format");
return -1;
}

SDL_GetWindowSize(window, &w, &h);

data->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
data->glPixelStorei(GL_UNPACK_ROW_LENGTH,
(pitch / SDL_BYTESPERPIXEL(pixel_format)));

/* Flip the rows to be bottom-up */
length = rect->h * rect->w * pitch;
tmp = SDL_stack_alloc(Uint8, length);
src = (Uint8*)pixels + (rect->h-1)*pitch;
dst = (Uint8*)tmp;
rows = rect->h;
while (rows--) {
SDL_memcpy(dst, src, pitch);
dst += pitch;
src -= pitch;
}

data->glRasterPos2i(rect->x, (h-rect->y));
data->glDrawPixels(rect->w, rect->h, format, type, tmp);
SDL_stack_free(tmp);

return 0;
}

static void
GL_RenderPresent(SDL_Renderer * renderer)
{
@@ -53,8 +53,6 @@ static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, void * pixels, int pitch);
static int SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, const void * pixels, int pitch);
static void SW_RenderPresent(SDL_Renderer * renderer);
static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static void SW_DestroyRenderer(SDL_Renderer * renderer);
@@ -166,7 +164,6 @@ SW_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->RenderFillRects = SW_RenderFillRects;
renderer->RenderCopy = SW_RenderCopy;
renderer->RenderReadPixels = SW_RenderReadPixels;
renderer->RenderWritePixels = SW_RenderWritePixels;
renderer->RenderPresent = SW_RenderPresent;
renderer->DestroyRenderer = SW_DestroyRenderer;
renderer->info = SW_RenderDriver.info;
@@ -592,29 +589,6 @@ SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
return 0;
}

static int
SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
Uint32 format, const void * pixels, int pitch)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;

if (!SW_ActivateRenderer(renderer)) {
return -1;
}

if (data->renderer->LockTexture(data->renderer, data->texture, rect,
&data->surface.pixels,
&data->surface.pitch) < 0) {
return -1;
}

SDL_ConvertPixels(rect->w, rect->h, format, pixels, pitch,
data->format, data->surface.pixels, data->surface.pitch);

data->renderer->UnlockTexture(data->renderer, data->texture);
return 0;
}

static void
SW_RenderPresent(SDL_Renderer * renderer)
{

0 comments on commit d199e96

Please sign in to comment.