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

The rendering functions take a context so it's clear what window they…

…'re drawing to. This also potentially opens to the door to multi-threaded rendering in the future.
  • Loading branch information
slouken committed Feb 2, 2011
1 parent 84388cf commit 1f52b2586ceb0eb4434347a0f9a369c43111e390
@@ -85,6 +85,12 @@ typedef enum
SDL_TEXTUREMODULATE_ALPHA = 0x00000002 /**< srcA = srcA * alpha */
} SDL_TextureModulate;

/**
* \brief A structure representing rendering state
*/
struct SDL_Renderer;
typedef struct SDL_Renderer SDL_Renderer;

/**
* \brief An efficient driver-specific representation of pixel data
*/
@@ -123,37 +129,29 @@ extern DECLSPEC int SDLCALL SDL_GetRenderDriverInfo(int index,
SDL_RendererInfo * info);

/**
* \brief Create and make active a 2D rendering context for a window.
* \brief Create a 2D rendering context for a window.
*
* \param window The window where rendering is displayed.
* \param index The index of the rendering driver to initialize, or -1 to
* initialize the first one supporting the requested flags.
* \param flags ::SDL_RendererFlags.
*
* \return 0 on success, -1 if there was an error creating the renderer.
* \return A valid rendering context or NULL if there was an error.
*
* \sa SDL_SelectRenderer()
* \sa SDL_GetRendererInfo()
* \sa SDL_DestroyRenderer()
*/
extern DECLSPEC int SDLCALL SDL_CreateRenderer(SDL_Window * window,
extern DECLSPEC SDL_Renderer * SDLCALL SDL_CreateRenderer(SDL_Window * window,
int index, Uint32 flags);

/**
* \brief Select the rendering context for a particular window.
*
* \return 0 on success, -1 if the selected window doesn't have a
* rendering context.
* \brief Get information about a rendering context.
*/
extern DECLSPEC int SDLCALL SDL_SelectRenderer(SDL_Window * window);
extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_Renderer * renderer,
SDL_RendererInfo * info);

/**
* \brief Get information about the current rendering context.
*/
extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_RendererInfo * info);

/**
* \brief Create a texture for the current rendering context.
* \brief Create a texture for a rendering context.
*
* \param format The format of the texture.
* \param access One of the enumerated values in ::SDL_TextureAccess.
@@ -167,7 +165,7 @@ extern DECLSPEC int SDLCALL SDL_GetRendererInfo(SDL_RendererInfo * info);
* \sa SDL_QueryTexture()
* \sa SDL_DestroyTexture()
*/
extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(Uint32 format,
extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format,
int access, int w,
int h);

@@ -186,10 +184,7 @@ extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTexture(Uint32 format,
* \sa SDL_QueryTexture()
* \sa SDL_DestroyTexture()
*/
extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(Uint32
format,
SDL_Surface
* surface);
extern DECLSPEC SDL_Texture * SDLCALL SDL_CreateTextureFromSurface(SDL_Renderer * renderer, Uint32 format, SDL_Surface * surface);

/**
* \brief Query the attributes of a texture
@@ -419,9 +414,10 @@ extern DECLSPEC void SDLCALL SDL_DirtyTexture(SDL_Texture * texture,
* \param a The alpha value used to draw on the rendering target, usually
* ::SDL_ALPHA_OPAQUE (255).
*
* \return 0 on success, or -1 if there is no rendering context current.
* \return 0 on success, or -1 on error
*/
extern DECLSPEC int SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b,
extern DECLSPEC int SDL_SetRenderDrawColor(SDL_Renderer * renderer,
Uint8 r, Uint8 g, Uint8 b,
Uint8 a);

/**
@@ -433,60 +429,65 @@ extern DECLSPEC int SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b,
* \param a A pointer to the alpha value used to draw on the rendering target,
* usually ::SDL_ALPHA_OPAQUE (255).
*
* \return 0 on success, or -1 if there is no rendering context current.
* \return 0 on success, or -1 on error
*/
extern DECLSPEC int SDL_GetRenderDrawColor(Uint8 * r, Uint8 * g, Uint8 * b,
extern DECLSPEC int SDL_GetRenderDrawColor(SDL_Renderer * renderer,
Uint8 * r, Uint8 * g, Uint8 * b,
Uint8 * a);

/**
* \brief Set the blend mode used for drawing operations (Fill and Line).
*
* \param blendMode ::SDL_BlendMode to use for blending.
*
* \return 0 on success, or -1 if there is no rendering context current.
* \return 0 on success, or -1 on error
*
* \note If the blend mode is not supported, the closest supported mode is
* chosen.
*
* \sa SDL_GetRenderDrawBlendMode()
*/
extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_BlendMode blendMode);
extern DECLSPEC int SDLCALL SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer,
SDL_BlendMode blendMode);

/**
* \brief Get the blend mode used for drawing operations.
*
* \param blendMode A pointer filled in with the current blend mode.
*
* \return 0 on success, or -1 if there is no rendering context current.
* \return 0 on success, or -1 on error
*
* \sa SDL_SetRenderDrawBlendMode()
*/
extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_BlendMode *blendMode);
extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer,
SDL_BlendMode *blendMode);

/**
* \brief Clear the current rendering target with the drawing color
*/
extern DECLSPEC int SDLCALL SDL_RenderClear(void);
extern DECLSPEC int SDLCALL SDL_RenderClear(SDL_Renderer * renderer);

/**
* \brief Draw a point on the current rendering target.
*
* \param x The x coordinate of the point.
* \param y The y coordinate of the point.
*
* \return 0 on success, or -1 if there is no rendering context current.
* \return 0 on success, or -1 on error
*/
extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(int x, int y);
extern DECLSPEC int SDLCALL SDL_RenderDrawPoint(SDL_Renderer * renderer,
int x, int y);

/**
* \brief Draw multiple points on the current rendering target.
*
* \param points The points to draw
* \param count The number of points to draw
*
* \return 0 on success, or -1 if there is no rendering context current.
* \return 0 on success, or -1 on error
*/
extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(const SDL_Point * points,
extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(SDL_Renderer * renderer,
const SDL_Point * points,
int count);

/**
@@ -497,59 +498,67 @@ extern DECLSPEC int SDLCALL SDL_RenderDrawPoints(const SDL_Point * points,
* \param x2 The x coordinate of the end point.
* \param y2 The y coordinate of the end point.
*
* \return 0 on success, or -1 if there is no rendering context current.
* \return 0 on success, or -1 on error
*/
extern DECLSPEC int SDLCALL SDL_RenderDrawLine(int x1, int y1, int x2, int y2);
extern DECLSPEC int SDLCALL SDL_RenderDrawLine(SDL_Renderer * renderer,
int x1, int y1, int x2, int y2);

/**
* \brief Draw a series of connected lines on the current rendering target.
*
* \param points The points along the lines
* \param count The number of points, drawing count-1 lines
*
* \return 0 on success, or -1 if there is no rendering context current.
* \return 0 on success, or -1 on error
*/
extern DECLSPEC int SDLCALL SDL_RenderDrawLines(const SDL_Point * points,
extern DECLSPEC int SDLCALL SDL_RenderDrawLines(SDL_Renderer * renderer,
const SDL_Point * points,
int count);

/**
* \brief Draw a rectangle on the current rendering target.
*
* \param rect A pointer to the destination rectangle, or NULL to outline the entire rendering target.
*
* \return 0 on success, or -1 if there is no rendering context current.
* \return 0 on success, or -1 on error
*/
extern DECLSPEC int SDLCALL SDL_RenderDrawRect(const SDL_Rect * rect);
extern DECLSPEC int SDLCALL SDL_RenderDrawRect(SDL_Renderer * renderer,
const SDL_Rect * rect);

/**
* \brief Draw some number of rectangles on the current rendering target.
*
* \param rects A pointer to an array of destination rectangles.
* \param count The number of rectangles.
*
* \return 0 on success, or -1 if there is no rendering context current.
* \return 0 on success, or -1 on error
*/
extern DECLSPEC int SDLCALL SDL_RenderDrawRects(const SDL_Rect ** rects, int count);
extern DECLSPEC int SDLCALL SDL_RenderDrawRects(SDL_Renderer * renderer,
const SDL_Rect ** rects,
int count);

/**
* \brief Fill a rectangle on the current rendering target with the drawing color.
*
* \param rect A pointer to the destination rectangle, or NULL for the entire
* rendering target.
*
* \return 0 on success, or -1 if there is no rendering context current.
* \return 0 on success, or -1 on error
*/
extern DECLSPEC int SDLCALL SDL_RenderFillRect(const SDL_Rect * rect);
extern DECLSPEC int SDLCALL SDL_RenderFillRect(SDL_Renderer * renderer,
const SDL_Rect * rect);

/**
* \brief Fill some number of rectangles on the current rendering target with the drawing color.
*
* \param rects A pointer to an array of destination rectangles.
* \param count The number of rectangles.
*
* \return 0 on success, or -1 if there is no rendering context current.
* \return 0 on success, or -1 on error
*/
extern DECLSPEC int SDLCALL SDL_RenderFillRects(const SDL_Rect ** rect, int count);
extern DECLSPEC int SDLCALL SDL_RenderFillRects(SDL_Renderer * renderer,
const SDL_Rect ** rect,
int count);

/**
* \brief Copy a portion of the texture to the current rendering target.
@@ -560,10 +569,10 @@ extern DECLSPEC int SDLCALL SDL_RenderFillRects(const SDL_Rect ** rect, int coun
* \param dstrect A pointer to the destination rectangle, or NULL for the
* entire rendering target.
*
* \return 0 on success, or -1 if there is no rendering context current, or the
* driver doesn't support the requested operation.
* \return 0 on success, or -1 on error
*/
extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Texture * texture,
extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Renderer * renderer,
SDL_Texture * texture,
const SDL_Rect * srcrect,
const SDL_Rect * dstrect);

@@ -581,7 +590,8 @@ extern DECLSPEC int SDLCALL SDL_RenderCopy(SDL_Texture * texture,
*
* \warning This is a very slow operation, and should not be used frequently.
*/
extern DECLSPEC int SDLCALL SDL_RenderReadPixels(const SDL_Rect * rect,
extern DECLSPEC int SDLCALL SDL_RenderReadPixels(SDL_Renderer * renderer,
const SDL_Rect * rect,
Uint32 format,
void *pixels, int pitch);

@@ -599,15 +609,16 @@ extern DECLSPEC int SDLCALL SDL_RenderReadPixels(const SDL_Rect * rect,
*
* \warning This is a very slow operation, and should not be used frequently.
*/
extern DECLSPEC int SDLCALL SDL_RenderWritePixels(const SDL_Rect * rect,
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.
*/
extern DECLSPEC void SDLCALL SDL_RenderPresent(void);
extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);

/**
* \brief Destroy the specified texture.
@@ -623,7 +634,7 @@ extern DECLSPEC void SDLCALL SDL_DestroyTexture(SDL_Texture * texture);
*
* \sa SDL_CreateRenderer()
*/
extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Window * window);
extern DECLSPEC void SDLCALL SDL_DestroyRenderer(SDL_Renderer * renderer);


/* Ends C function definitions when using C++ */
@@ -31,7 +31,7 @@
#include "video/SDL_yuv_sw_c.h"

static SDL_Window *SDL_VideoWindow = NULL;
static SDL_RendererInfo SDL_VideoRendererInfo;
static SDL_Renderer *SDL_VideoRenderer = NULL;
static SDL_Texture *SDL_VideoTexture = NULL;
static SDL_Surface *SDL_VideoSurface = NULL;
static SDL_Surface *SDL_ShadowSurface = NULL;
@@ -467,7 +467,8 @@ SDL_ResizeVideoMode(int width, int height, int bpp, Uint32 flags)
/* Destroy the screen texture and recreate it */
SDL_QueryTexture(SDL_VideoTexture, &format, &access, &w, &h);
SDL_DestroyTexture(SDL_VideoTexture);
SDL_VideoTexture = SDL_CreateTexture(format, access, width, height);
SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, format,
access, width, height);
if (!SDL_VideoTexture) {
return -1;
}
@@ -667,20 +668,20 @@ SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags)
}

/* Create a renderer for the window */
if (SDL_CreateRenderer(SDL_VideoWindow, -1, 0) < 0) {
SDL_VideoRenderer = SDL_CreateRenderer(SDL_VideoWindow, -1, 0);
if (!SDL_VideoRenderer) {
return NULL;
}
SDL_GetRendererInfo(&SDL_VideoRendererInfo);

/* Create a texture for the screen surface */
SDL_VideoTexture =
SDL_CreateTexture(desired_format, SDL_TEXTUREACCESS_STREAMING, width,
height);
SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, desired_format,
SDL_TEXTUREACCESS_STREAMING,
width, height);

if (!SDL_VideoTexture) {
SDL_VideoTexture =
SDL_CreateTexture(desktop_format,
SDL_TEXTUREACCESS_STREAMING, width, height);
SDL_VideoTexture = SDL_CreateTexture(SDL_VideoRenderer, desktop_format,
SDL_TEXTUREACCESS_STREAMING,
width, height);
}
if (!SDL_VideoTexture) {
return NULL;
@@ -890,8 +891,8 @@ SDL_UpdateRects(SDL_Surface * screen, int numrects, SDL_Rect * rects)
rect.y = 0;
rect.w = screen->w;
rect.h = screen->h;
SDL_RenderCopy(SDL_VideoTexture, &rect, &rect);
SDL_RenderPresent();
SDL_RenderCopy(SDL_VideoRenderer, SDL_VideoTexture, &rect, &rect);
SDL_RenderPresent(SDL_VideoRenderer);
}
}

@@ -1584,7 +1585,8 @@ SDL_CreateYUVOverlay(int w, int h, Uint32 format, SDL_Surface * display)
}

overlay->hwdata->texture =
SDL_CreateTexture(texture_format, SDL_TEXTUREACCESS_STREAMING, w, h);
SDL_CreateTexture(SDL_VideoRenderer, texture_format,
SDL_TEXTUREACCESS_STREAMING, w, h);
if (overlay->hwdata->texture) {
overlay->hwdata->sw = NULL;
} else {
@@ -1600,7 +1602,7 @@ SDL_CreateYUVOverlay(int w, int h, Uint32 format, SDL_Surface * display)
SDL_GetCurrentDisplayMode(&current_mode);
texture_format = current_mode.format;
overlay->hwdata->texture =
SDL_CreateTexture(texture_format,
SDL_CreateTexture(SDL_VideoRenderer, texture_format,
SDL_TEXTUREACCESS_STREAMING, w, h);
}
if (!overlay->hwdata->texture) {
@@ -1688,10 +1690,10 @@ SDL_DisplayYUVOverlay(SDL_Overlay * overlay, SDL_Rect * dstrect)
SDL_SetError("Passed a NULL overlay or dstrect");
return -1;
}
if (SDL_RenderCopy(overlay->hwdata->texture, NULL, dstrect) < 0) {
if (SDL_RenderCopy(SDL_VideoRenderer, overlay->hwdata->texture, NULL, dstrect) < 0) {
return -1;
}
SDL_RenderPresent();
SDL_RenderPresent(SDL_VideoRenderer);
return 0;
}

@@ -106,7 +106,6 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
}
window->w = data1;
window->h = data2;
SDL_OnWindowResized(window);
break;
case SDL_WINDOWEVENT_MINIMIZED:
if (window->flags & SDL_WINDOW_MINIMIZED) {

0 comments on commit 1f52b25

Please sign in to comment.