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

Commit

Permalink
Browse files Browse the repository at this point in the history
Date: Fri, 19 Dec 2008 20:17:35 +0100
From: Couriersud
Subject: Re: Aw: Experience using SDL1.3 in sdlmame/Proposal for api additions

> For consistency you'd probably want:
> SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a);
> SDL_SetRenderDrawBlendMode(SDL_BlendMode blendMode);
> SDL_RenderLine(int x1, int y1, int x2, int y2);
> SDL_RenderFill(SDL_Rect *rect);
>
> You probably also want to add API functions query the current state.
>

I have implemented the above api for the opengl, x11, directfb and
software renderers. I have also renamed *TEXTUREBLENDMODE* constants to
BLENDMODE*. The unix build compiles. The windows renderer still needs to
be updated, but I have no windows development machine at hand. Have a
look at the x11 renderer for a sample.

Vector games now run at 90% both on opengl and directfb in comparison to
sdlmame's own opengl renderer. The same applies to raster games.

The diff also includes

a) Changed XDrawRect to XFillRect in x11 renderer
b) A number of changes to fix blending and modulation issues in the
directfb renderer.
  • Loading branch information
slouken committed Dec 20, 2008
1 parent 229f329 commit f8c4ad8
Show file tree
Hide file tree
Showing 26 changed files with 731 additions and 258 deletions.
1 change: 1 addition & 0 deletions TODO
Expand Up @@ -5,6 +5,7 @@
- in progress, software support is done, Ryan is working on OpenGL shaders
* Implement desktop video mode change notification?
* Implement icon support (with translucency?)
* Add draw blend mode and line drawing support for software renderer and win32
* Verify mouse grab support
* Properly handle mouse grab with Vista DPI scaling
* Make sure the mouse is where it's supposed to be when un-grabbed
Expand Down
2 changes: 1 addition & 1 deletion XCodeiPhoneOS/Demos/src/accelerometer.c
Expand Up @@ -145,7 +145,7 @@ initializeTextures()
if (shipID == 0) {
fatalError("could not create ship texture");
}
SDL_SetTextureBlendMode(shipID, SDL_TEXTUREBLENDMODE_BLEND);
SDL_SetTextureBlendMode(shipID, SDL_BLENDMODE_BLEND);

/* set the width and height of the ship from the surface dimensions */
ship.rect.w = bmp_surface->w;
Expand Down
2 changes: 1 addition & 1 deletion XCodeiPhoneOS/Demos/src/happy.c
Expand Up @@ -127,7 +127,7 @@ initializeTexture()
if (texture_id == 0) {
fatalError("could not create texture");
}
SDL_SetTextureBlendMode(texture_id, SDL_TEXTUREBLENDMODE_BLEND);
SDL_SetTextureBlendMode(texture_id, SDL_BLENDMODE_BLEND);

/* free up allocated memory */
SDL_FreeSurface(bmp_surface_rgba);
Expand Down
2 changes: 1 addition & 1 deletion XCodeiPhoneOS/Demos/src/keyboard.c
Expand Up @@ -223,7 +223,7 @@ loadFont(void)
printf("texture creation failed: %s\n", SDL_GetError());
} else {
/* set blend mode for our texture */
SDL_SetTextureBlendMode(textureID, SDL_TEXTUREBLENDMODE_BLEND);
SDL_SetTextureBlendMode(textureID, SDL_BLENDMODE_BLEND);
}
SDL_FreeSurface(surface);
SDL_FreeSurface(converted);
Expand Down
2 changes: 1 addition & 1 deletion XCodeiPhoneOS/Demos/src/touch.c
Expand Up @@ -65,7 +65,7 @@ initializeTexture()
fatalError("could not create brush texture");
}
/* additive blending -- laying strokes on top of eachother makes them brighter */
SDL_SetTextureBlendMode(brushID, SDL_TEXTUREBLENDMODE_ADD);
SDL_SetTextureBlendMode(brushID, SDL_BLENDMODE_ADD);
/* set brush color (red) */
SDL_SetTextureColorMod(brushID, 255, 100, 100);
}
Expand Down
94 changes: 82 additions & 12 deletions include/SDL_video.h
Expand Up @@ -206,18 +206,18 @@ typedef enum
} SDL_TextureModulate;

/**
* \enum SDL_TextureBlendMode
* \enum SDL_BlendMode
*
* \brief The texture blend mode used in SDL_RenderCopy()
* \brief The blend mode used in SDL_RenderCopy() and drawing operations
*/
typedef enum
{
SDL_TEXTUREBLENDMODE_NONE = 0x00000000, /**< No blending */
SDL_TEXTUREBLENDMODE_MASK = 0x00000001, /**< dst = A ? src : dst (alpha is mask) */
SDL_TEXTUREBLENDMODE_BLEND = 0x00000002, /**< dst = (src * A) + (dst * (1-A)) */
SDL_TEXTUREBLENDMODE_ADD = 0x00000004, /**< dst = (src * A) + dst */
SDL_TEXTUREBLENDMODE_MOD = 0x00000008 /**< dst = src * dst */
} SDL_TextureBlendMode;
SDL_BLENDMODE_NONE = 0x00000000, /**< No blending */
SDL_BLENDMODE_MASK = 0x00000001, /**< dst = A ? src : dst (alpha is mask) */
SDL_BLENDMODE_BLEND = 0x00000002, /**< dst = (src * A) + (dst * (1-A)) */
SDL_BLENDMODE_ADD = 0x00000004, /**< dst = (src * A) + dst */
SDL_BLENDMODE_MOD = 0x00000008 /**< dst = src * dst */
} SDL_BlendMode;

/**
* \enum SDL_TextureScaleMode
Expand Down Expand Up @@ -1141,9 +1141,80 @@ extern DECLSPEC void SDLCALL SDL_DirtyTexture(SDL_TextureID textureID,
const SDL_Rect * rects);

/**
* \fn void SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a, const SDL_Rect *rect)
* \fn void SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
*
* \brief Fill the current rendering target with the specified color.
* \brief Set the color used for drawing operations (Fill and Line).
*
* \param r The red value used to draw on the rendering target
* \param g The green value used to draw on the rendering target
* \param b The blue value used to draw on the rendering target
* \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
*/
extern DECLSPEC int SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b,
Uint8 a);

/**
* \fn void SDL_GetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a)
*
* \brief Get the color used for drawing operations (Fill and Line).
*
* \param r A pointer to the red value used to draw on the rendering target
* \param g A pointer to the green value used to draw on the rendering target
* \param b A pointer to the blue value used to draw on the rendering target
* \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
*/
extern DECLSPEC int SDL_GetRenderDrawColor(Uint8 * r, Uint8 * g, Uint8 * b,
Uint8 * a);

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

/**
* \fn int SDL_GetRenderDrawBlendMode(int *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
*
* \sa SDL_SetRenderDrawBlendMode()
*/
extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(int *blendMode);

/**
* \fn void SDL_RenderLine(int x1, int y1, int x2, int y2)
*
* \brief Draw a line on the current rendering target.
*
* \param x1 The x coordinate of the start point
* \param y1 The y coordinate of the start point
* \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
*/

extern DECLSPEC int SDLCALL SDL_RenderLine(int x1, int y1, int x2, int y2);

/**
* \fn void SDL_RenderFill(const SDL_Rect *rect)
*
* \brief Fill the current rendering target with the drawing color.
*
* \param r The red value used to fill the rendering target
* \param g The green value used to fill the rendering target
Expand All @@ -1153,8 +1224,7 @@ extern DECLSPEC void SDLCALL SDL_DirtyTexture(SDL_TextureID textureID,
*
* \return 0 on success, or -1 if there is no rendering context current
*/
extern DECLSPEC int SDLCALL SDL_RenderFill(Uint8 r, Uint8 g, Uint8 b, Uint8 a,
const SDL_Rect * rect);
extern DECLSPEC int SDLCALL SDL_RenderFill(const SDL_Rect * rect);

/**
* \fn int SDL_RenderCopy(SDL_TextureID textureID, const SDL_Rect *srcrect, const SDL_Rect *dstrect)
Expand Down
4 changes: 2 additions & 2 deletions src/SDL_compat.c
Expand Up @@ -696,10 +696,10 @@ SDL_SetAlpha(SDL_Surface * surface, Uint32 flag, Uint8 value)
value = 0xFF;
}
SDL_SetSurfaceAlphaMod(surface, value);
SDL_SetSurfaceBlendMode(surface, SDL_TEXTUREBLENDMODE_BLEND);
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND);
} else {
SDL_SetSurfaceAlphaMod(surface, 0xFF);
SDL_SetSurfaceBlendMode(surface, SDL_TEXTUREBLENDMODE_NONE);
SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_NONE);
}
SDL_SetSurfaceRLE(surface, (flag & SDL_RLEACCEL));

Expand Down
6 changes: 3 additions & 3 deletions src/video/SDL_glfuncs.h
Expand Up @@ -206,7 +206,7 @@ SDL_PROC_UNUSED(void, glLighti, (GLenum light, GLenum pname, GLint param))
SDL_PROC_UNUSED(void, glLightiv,
(GLenum light, GLenum pname, const GLint * params))
SDL_PROC_UNUSED(void, glLineStipple, (GLint factor, GLushort pattern))
SDL_PROC_UNUSED(void, glLineWidth, (GLfloat width))
SDL_PROC(void, glLineWidth, (GLfloat width))
SDL_PROC_UNUSED(void, glListBase, (GLuint base))
SDL_PROC(void, glLoadIdentity, (void))
SDL_PROC_UNUSED(void, glLoadMatrixd, (const GLdouble * m))
Expand Down Expand Up @@ -272,7 +272,7 @@ SDL_PROC(void, glPixelStorei, (GLenum pname, GLint param))
SDL_PROC_UNUSED(void, glPixelTransferf, (GLenum pname, GLfloat param))
SDL_PROC_UNUSED(void, glPixelTransferi, (GLenum pname, GLint param))
SDL_PROC_UNUSED(void, glPixelZoom, (GLfloat xfactor, GLfloat yfactor))
SDL_PROC_UNUSED(void, glPointSize, (GLfloat size))
SDL_PROC(void, glPointSize, (GLfloat size))
SDL_PROC_UNUSED(void, glPolygonMode, (GLenum face, GLenum mode))
SDL_PROC_UNUSED(void, glPolygonOffset, (GLfloat factor, GLfloat units))
SDL_PROC_UNUSED(void, glPolygonStipple, (const GLubyte * mask))
Expand Down Expand Up @@ -324,7 +324,7 @@ SDL_PROC_UNUSED(void, glRectdv, (const GLdouble * v1, const GLdouble * v2))
SDL_PROC_UNUSED(void, glRectf,
(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2))
SDL_PROC_UNUSED(void, glRectfv, (const GLfloat * v1, const GLfloat * v2))
SDL_PROC_UNUSED(void, glRecti, (GLint x1, GLint y1, GLint x2, GLint y2))
SDL_PROC(void, glRecti, (GLint x1, GLint y1, GLint x2, GLint y2))
SDL_PROC_UNUSED(void, glRectiv, (const GLint * v1, const GLint * v2))
SDL_PROC_UNUSED(void, glRects,
(GLshort x1, GLshort y1, GLshort x2, GLshort y2))
Expand Down

0 comments on commit f8c4ad8

Please sign in to comment.