2006-07-19 07:18:45 +00:00
|
|
|
/*
|
|
|
|
SDL - Simple DirectMedia Layer
|
2008-12-08 00:24:15 +00:00
|
|
|
Copyright (C) 1997-2009 Sam Lantinga
|
2006-07-19 07:18:45 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
Sam Lantinga
|
|
|
|
slouken@libsdl.org
|
|
|
|
*/
|
|
|
|
#include "SDL_config.h"
|
|
|
|
|
2006-07-28 08:43:17 +00:00
|
|
|
#if SDL_VIDEO_RENDER_OGL
|
2006-07-22 08:33:18 +00:00
|
|
|
|
|
|
|
#include "SDL_video.h"
|
|
|
|
#include "SDL_opengl.h"
|
|
|
|
#include "SDL_sysvideo.h"
|
|
|
|
#include "SDL_pixels_c.h"
|
|
|
|
#include "SDL_rect_c.h"
|
|
|
|
#include "SDL_yuv_sw_c.h"
|
2006-07-19 07:18:45 +00:00
|
|
|
|
2007-08-15 04:04:17 +00:00
|
|
|
#ifdef __MACOSX__
|
|
|
|
#include <OpenGL/OpenGL.h>
|
|
|
|
#endif
|
|
|
|
|
2008-11-22 06:59:22 +00:00
|
|
|
|
2006-07-19 07:18:45 +00:00
|
|
|
/* OpenGL renderer implementation */
|
|
|
|
|
2007-08-12 07:02:28 +00:00
|
|
|
/* Details on optimizing the texture path on Mac OS X:
|
|
|
|
http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/chapter_10_section_2.html
|
|
|
|
*/
|
|
|
|
|
2008-12-06 00:56:47 +00:00
|
|
|
/* !!! FIXME: this should go in a higher level than the GL renderer. */
|
|
|
|
static __inline__ int
|
|
|
|
bytes_per_pixel(const Uint32 format)
|
|
|
|
{
|
2008-12-06 17:41:01 +00:00
|
|
|
if (!SDL_ISPIXELFORMAT_FOURCC(format)) {
|
|
|
|
return SDL_BYTESPERPIXEL(format);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FOURCC format */
|
2008-12-06 00:56:47 +00:00
|
|
|
switch (format) {
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
case SDL_PIXELFORMAT_YV12:
|
|
|
|
case SDL_PIXELFORMAT_IYUV:
|
|
|
|
case SDL_PIXELFORMAT_YUY2:
|
|
|
|
case SDL_PIXELFORMAT_UYVY:
|
|
|
|
case SDL_PIXELFORMAT_YVYU:
|
|
|
|
return 2;
|
|
|
|
default:
|
|
|
|
return 1; /* shouldn't ever hit this. */
|
2008-12-06 00:56:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-08-28 03:17:39 +00:00
|
|
|
static const float inv255f = 1.0f / 255.0f;
|
|
|
|
|
2006-07-19 07:18:45 +00:00
|
|
|
static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags);
|
2006-07-22 19:51:48 +00:00
|
|
|
static int GL_ActivateRenderer(SDL_Renderer * renderer);
|
2006-08-06 04:39:13 +00:00
|
|
|
static int GL_DisplayModeChanged(SDL_Renderer * renderer);
|
2006-07-19 07:18:45 +00:00
|
|
|
static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
|
2007-08-11 20:54:31 +00:00
|
|
|
static int GL_QueryTexturePixels(SDL_Renderer * renderer,
|
|
|
|
SDL_Texture * texture, void **pixels,
|
|
|
|
int *pitch);
|
2006-07-19 07:18:45 +00:00
|
|
|
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);
|
2006-08-28 03:17:39 +00:00
|
|
|
static int GL_SetTextureColorMod(SDL_Renderer * renderer,
|
|
|
|
SDL_Texture * texture);
|
|
|
|
static int GL_SetTextureAlphaMod(SDL_Renderer * renderer,
|
|
|
|
SDL_Texture * texture);
|
|
|
|
static int GL_SetTextureBlendMode(SDL_Renderer * renderer,
|
|
|
|
SDL_Texture * texture);
|
|
|
|
static int GL_SetTextureScaleMode(SDL_Renderer * renderer,
|
|
|
|
SDL_Texture * texture);
|
2006-07-19 07:18:45 +00:00
|
|
|
static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|
|
|
const SDL_Rect * rect, const void *pixels,
|
|
|
|
int pitch);
|
|
|
|
static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
2006-08-28 03:17:39 +00:00
|
|
|
const SDL_Rect * rect, int markDirty, void **pixels,
|
|
|
|
int *pitch);
|
2006-07-19 07:18:45 +00:00
|
|
|
static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
|
|
|
|
static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|
|
|
int numrects, const SDL_Rect * rects);
|
2008-12-21 17:39:41 +00:00
|
|
|
static int GL_RenderPoint(SDL_Renderer * renderer, int x, int y);
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
static int GL_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
|
|
|
|
int y2);
|
|
|
|
static int GL_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
|
2006-07-19 07:18:45 +00:00
|
|
|
static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
2006-08-28 03:17:39 +00:00
|
|
|
const SDL_Rect * srcrect, const SDL_Rect * dstrect);
|
2009-11-15 04:58:03 +00:00
|
|
|
static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
2009-11-16 07:13:07 +00:00
|
|
|
Uint32 pixel_format, void * pixels, int pitch);
|
2009-11-15 04:58:03 +00:00
|
|
|
static int GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
2009-11-16 07:13:07 +00:00
|
|
|
Uint32 pixel_format, const void * pixels, int pitch);
|
2006-07-19 07:18:45 +00:00
|
|
|
static void GL_RenderPresent(SDL_Renderer * renderer);
|
|
|
|
static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
|
|
|
|
static void GL_DestroyRenderer(SDL_Renderer * renderer);
|
|
|
|
|
|
|
|
|
|
|
|
SDL_RenderDriver GL_RenderDriver = {
|
|
|
|
GL_CreateRenderer,
|
|
|
|
{
|
|
|
|
"opengl",
|
2006-08-06 23:34:59 +00:00
|
|
|
(SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTDISCARD |
|
|
|
|
SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
|
2006-08-28 03:17:39 +00:00
|
|
|
(SDL_TEXTUREMODULATE_NONE | SDL_TEXTUREMODULATE_COLOR |
|
|
|
|
SDL_TEXTUREMODULATE_ALPHA),
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
(SDL_BLENDMODE_NONE | SDL_BLENDMODE_MASK |
|
|
|
|
SDL_BLENDMODE_BLEND | SDL_BLENDMODE_ADD | SDL_BLENDMODE_MOD),
|
2006-08-05 17:09:42 +00:00
|
|
|
(SDL_TEXTURESCALEMODE_NONE | SDL_TEXTURESCALEMODE_FAST |
|
|
|
|
SDL_TEXTURESCALEMODE_SLOW),
|
2008-12-01 00:05:31 +00:00
|
|
|
15,
|
2006-07-19 07:18:45 +00:00
|
|
|
{
|
2006-08-05 17:09:42 +00:00
|
|
|
SDL_PIXELFORMAT_INDEX1LSB,
|
|
|
|
SDL_PIXELFORMAT_INDEX1MSB,
|
|
|
|
SDL_PIXELFORMAT_INDEX8,
|
|
|
|
SDL_PIXELFORMAT_RGB332,
|
|
|
|
SDL_PIXELFORMAT_RGB444,
|
|
|
|
SDL_PIXELFORMAT_RGB555,
|
|
|
|
SDL_PIXELFORMAT_ARGB4444,
|
|
|
|
SDL_PIXELFORMAT_ARGB1555,
|
|
|
|
SDL_PIXELFORMAT_RGB565,
|
|
|
|
SDL_PIXELFORMAT_RGB24,
|
|
|
|
SDL_PIXELFORMAT_BGR24,
|
|
|
|
SDL_PIXELFORMAT_RGB888,
|
|
|
|
SDL_PIXELFORMAT_BGR888,
|
|
|
|
SDL_PIXELFORMAT_ARGB8888,
|
|
|
|
SDL_PIXELFORMAT_ABGR8888,
|
2008-12-01 00:05:31 +00:00
|
|
|
SDL_PIXELFORMAT_ARGB2101010},
|
2006-07-19 07:18:45 +00:00
|
|
|
0,
|
|
|
|
0}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
SDL_GLContext context;
|
2008-12-05 07:00:58 +00:00
|
|
|
SDL_bool updateSize;
|
2006-07-22 21:58:17 +00:00
|
|
|
SDL_bool GL_ARB_texture_rectangle_supported;
|
2007-08-12 16:53:58 +00:00
|
|
|
SDL_bool GL_EXT_paletted_texture_supported;
|
2008-12-07 04:02:23 +00:00
|
|
|
SDL_bool GL_APPLE_ycbcr_422_supported;
|
|
|
|
SDL_bool GL_MESA_ycbcr_texture_supported;
|
2008-12-06 00:56:47 +00:00
|
|
|
SDL_bool GL_ARB_fragment_program_supported;
|
2006-07-22 23:04:41 +00:00
|
|
|
int blendMode;
|
|
|
|
int scaleMode;
|
|
|
|
|
|
|
|
/* OpenGL functions */
|
|
|
|
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
|
|
|
|
#include "SDL_glfuncs.h"
|
|
|
|
#undef SDL_PROC
|
2006-08-06 23:34:59 +00:00
|
|
|
|
|
|
|
PFNGLCOLORTABLEEXTPROC glColorTableEXT;
|
2007-08-12 16:53:58 +00:00
|
|
|
void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
|
|
|
|
const GLvoid * pointer);
|
2008-12-06 00:56:47 +00:00
|
|
|
|
|
|
|
PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
|
|
|
|
PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB;
|
|
|
|
PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB;
|
|
|
|
PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB;
|
|
|
|
PFNGLGENPROGRAMSARBPROC glGenProgramsARB;
|
|
|
|
PFNGLBINDPROGRAMARBPROC glBindProgramARB;
|
|
|
|
PFNGLPROGRAMSTRINGARBPROC glProgramStringARB;
|
|
|
|
|
|
|
|
/* (optional) fragment programs */
|
2009-11-21 05:29:31 +00:00
|
|
|
GLuint fragment_program_mask;
|
2008-12-06 00:56:47 +00:00
|
|
|
GLuint fragment_program_UYVY;
|
2006-07-19 07:18:45 +00:00
|
|
|
} GL_RenderData;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GLuint texture;
|
2008-12-06 00:56:47 +00:00
|
|
|
GLuint shader;
|
2006-07-22 08:33:18 +00:00
|
|
|
GLenum type;
|
2006-07-19 07:18:45 +00:00
|
|
|
GLfloat texw;
|
|
|
|
GLfloat texh;
|
2006-07-22 08:33:18 +00:00
|
|
|
GLenum format;
|
|
|
|
GLenum formattype;
|
2006-08-06 23:34:59 +00:00
|
|
|
Uint8 *palette;
|
2006-07-19 07:18:45 +00:00
|
|
|
void *pixels;
|
|
|
|
int pitch;
|
2006-07-22 08:33:18 +00:00
|
|
|
SDL_DirtyRectList dirty;
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
int HACK_RYAN_FIXME;
|
2006-07-19 07:18:45 +00:00
|
|
|
} GL_TextureData;
|
|
|
|
|
|
|
|
|
2006-07-22 21:02:57 +00:00
|
|
|
static void
|
|
|
|
GL_SetError(const char *prefix, GLenum result)
|
|
|
|
{
|
|
|
|
const char *error;
|
|
|
|
|
|
|
|
switch (result) {
|
|
|
|
case GL_NO_ERROR:
|
|
|
|
error = "GL_NO_ERROR";
|
|
|
|
break;
|
|
|
|
case GL_INVALID_ENUM:
|
|
|
|
error = "GL_INVALID_ENUM";
|
|
|
|
break;
|
|
|
|
case GL_INVALID_VALUE:
|
|
|
|
error = "GL_INVALID_VALUE";
|
|
|
|
break;
|
|
|
|
case GL_INVALID_OPERATION:
|
|
|
|
error = "GL_INVALID_OPERATION";
|
|
|
|
break;
|
|
|
|
case GL_STACK_OVERFLOW:
|
|
|
|
error = "GL_STACK_OVERFLOW";
|
|
|
|
break;
|
|
|
|
case GL_STACK_UNDERFLOW:
|
|
|
|
error = "GL_STACK_UNDERFLOW";
|
|
|
|
break;
|
|
|
|
case GL_OUT_OF_MEMORY:
|
|
|
|
error = "GL_OUT_OF_MEMORY";
|
|
|
|
break;
|
|
|
|
case GL_TABLE_TOO_LARGE:
|
|
|
|
error = "GL_TABLE_TOO_LARGE";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error = "UNKNOWN";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SDL_SetError("%s: %s", prefix, error);
|
|
|
|
}
|
|
|
|
|
2006-07-22 23:04:41 +00:00
|
|
|
static int
|
|
|
|
GL_LoadFunctions(GL_RenderData * data)
|
|
|
|
{
|
|
|
|
#if defined(__QNXNTO__) && (_NTO_VERSION < 630)
|
|
|
|
#define __SDL_NOGETPROCADDR__
|
|
|
|
#endif
|
|
|
|
#ifdef __SDL_NOGETPROCADDR__
|
|
|
|
#define SDL_PROC(ret,func,params) data->func=func;
|
|
|
|
#else
|
|
|
|
#define SDL_PROC(ret,func,params) \
|
|
|
|
do { \
|
|
|
|
data->func = SDL_GL_GetProcAddress(#func); \
|
|
|
|
if ( ! data->func ) { \
|
|
|
|
SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
|
|
|
|
return -1; \
|
|
|
|
} \
|
|
|
|
} while ( 0 );
|
|
|
|
#endif /* __SDL_NOGETPROCADDR__ */
|
|
|
|
|
|
|
|
#include "SDL_glfuncs.h"
|
|
|
|
#undef SDL_PROC
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-19 07:18:45 +00:00
|
|
|
void
|
|
|
|
GL_AddRenderDriver(_THIS)
|
|
|
|
{
|
2006-07-22 08:33:18 +00:00
|
|
|
if (_this->GL_CreateContext) {
|
2006-07-19 07:18:45 +00:00
|
|
|
SDL_AddRenderDriver(0, &GL_RenderDriver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Renderer *
|
|
|
|
GL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|
|
|
{
|
|
|
|
SDL_Renderer *renderer;
|
|
|
|
GL_RenderData *data;
|
2006-07-28 08:43:17 +00:00
|
|
|
GLint value;
|
2006-08-06 23:34:59 +00:00
|
|
|
int doublebuffer;
|
2006-07-19 07:18:45 +00:00
|
|
|
|
2006-08-06 23:34:59 +00:00
|
|
|
/* Render directly to the window, unless we're compositing */
|
|
|
|
#ifndef __MACOSX__
|
|
|
|
if (flags & SDL_RENDERER_SINGLEBUFFER) {
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
|
|
|
|
}
|
|
|
|
#endif
|
2006-07-19 07:18:45 +00:00
|
|
|
if (!(window->flags & SDL_WINDOW_OPENGL)) {
|
2006-07-23 00:19:12 +00:00
|
|
|
if (SDL_RecreateWindow(window, window->flags | SDL_WINDOW_OPENGL) < 0) {
|
2006-07-22 21:02:57 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2006-07-19 07:18:45 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 08:33:18 +00:00
|
|
|
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
|
2006-07-19 07:18:45 +00:00
|
|
|
if (!renderer) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-07-22 08:33:18 +00:00
|
|
|
data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
|
2006-07-19 07:18:45 +00:00
|
|
|
if (!data) {
|
|
|
|
GL_DestroyRenderer(renderer);
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-07-22 19:51:48 +00:00
|
|
|
renderer->ActivateRenderer = GL_ActivateRenderer;
|
2006-08-06 04:39:13 +00:00
|
|
|
renderer->DisplayModeChanged = GL_DisplayModeChanged;
|
2006-07-19 07:18:45 +00:00
|
|
|
renderer->CreateTexture = GL_CreateTexture;
|
2007-08-11 20:54:31 +00:00
|
|
|
renderer->QueryTexturePixels = GL_QueryTexturePixels;
|
2006-07-19 07:18:45 +00:00
|
|
|
renderer->SetTexturePalette = GL_SetTexturePalette;
|
|
|
|
renderer->GetTexturePalette = GL_GetTexturePalette;
|
2006-08-28 03:17:39 +00:00
|
|
|
renderer->SetTextureColorMod = GL_SetTextureColorMod;
|
|
|
|
renderer->SetTextureAlphaMod = GL_SetTextureAlphaMod;
|
|
|
|
renderer->SetTextureBlendMode = GL_SetTextureBlendMode;
|
|
|
|
renderer->SetTextureScaleMode = GL_SetTextureScaleMode;
|
2006-07-19 07:18:45 +00:00
|
|
|
renderer->UpdateTexture = GL_UpdateTexture;
|
|
|
|
renderer->LockTexture = GL_LockTexture;
|
|
|
|
renderer->UnlockTexture = GL_UnlockTexture;
|
|
|
|
renderer->DirtyTexture = GL_DirtyTexture;
|
2008-12-21 17:39:41 +00:00
|
|
|
renderer->RenderPoint = GL_RenderPoint;
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
renderer->RenderLine = GL_RenderLine;
|
2006-07-19 07:18:45 +00:00
|
|
|
renderer->RenderFill = GL_RenderFill;
|
|
|
|
renderer->RenderCopy = GL_RenderCopy;
|
2009-11-15 04:58:03 +00:00
|
|
|
renderer->RenderReadPixels = GL_RenderReadPixels;
|
|
|
|
renderer->RenderWritePixels = GL_RenderWritePixels;
|
2006-07-19 07:18:45 +00:00
|
|
|
renderer->RenderPresent = GL_RenderPresent;
|
|
|
|
renderer->DestroyTexture = GL_DestroyTexture;
|
|
|
|
renderer->DestroyRenderer = GL_DestroyRenderer;
|
|
|
|
renderer->info = GL_RenderDriver.info;
|
|
|
|
renderer->window = window->id;
|
|
|
|
renderer->driverdata = data;
|
|
|
|
|
|
|
|
renderer->info.flags =
|
2006-08-05 17:09:42 +00:00
|
|
|
(SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED);
|
2006-07-19 07:18:45 +00:00
|
|
|
|
2006-07-22 23:04:41 +00:00
|
|
|
if (GL_LoadFunctions(data) < 0) {
|
|
|
|
GL_DestroyRenderer(renderer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-07-19 07:18:45 +00:00
|
|
|
data->context = SDL_GL_CreateContext(window->id);
|
|
|
|
if (!data->context) {
|
|
|
|
GL_DestroyRenderer(renderer);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (SDL_GL_MakeCurrent(window->id, data->context) < 0) {
|
|
|
|
GL_DestroyRenderer(renderer);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-08-15 04:04:17 +00:00
|
|
|
#ifdef __MACOSX__
|
|
|
|
/* Enable multi-threaded rendering */
|
|
|
|
/* Disabled until Ryan finishes his VBO/PBO code...
|
2008-01-08 00:10:46 +00:00
|
|
|
CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine);
|
|
|
|
*/
|
2007-08-15 04:04:17 +00:00
|
|
|
#endif
|
|
|
|
|
2006-08-05 17:09:42 +00:00
|
|
|
if (flags & SDL_RENDERER_PRESENTVSYNC) {
|
2006-07-19 07:18:45 +00:00
|
|
|
SDL_GL_SetSwapInterval(1);
|
|
|
|
} else {
|
|
|
|
SDL_GL_SetSwapInterval(0);
|
|
|
|
}
|
|
|
|
if (SDL_GL_GetSwapInterval() > 0) {
|
2006-08-05 17:09:42 +00:00
|
|
|
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
2006-07-19 07:18:45 +00:00
|
|
|
}
|
|
|
|
|
2006-08-06 23:34:59 +00:00
|
|
|
if (SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &doublebuffer) == 0) {
|
|
|
|
if (!doublebuffer) {
|
|
|
|
renderer->info.flags |= SDL_RENDERER_SINGLEBUFFER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-28 08:43:17 +00:00
|
|
|
data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
|
|
|
|
renderer->info.max_texture_width = value;
|
|
|
|
data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
|
|
|
|
renderer->info.max_texture_height = value;
|
2006-07-22 08:33:18 +00:00
|
|
|
|
2006-07-22 21:58:17 +00:00
|
|
|
if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
|
|
|
|
|| SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
|
|
|
|
data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
|
|
|
|
}
|
2006-08-06 23:34:59 +00:00
|
|
|
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;
|
|
|
|
}
|
2008-12-07 04:02:23 +00:00
|
|
|
if (SDL_GL_ExtensionSupported("GL_APPLE_ycbcr_422")) {
|
|
|
|
data->GL_APPLE_ycbcr_422_supported = SDL_TRUE;
|
|
|
|
}
|
|
|
|
if (SDL_GL_ExtensionSupported("GL_MESA_ycbcr_texture")) {
|
|
|
|
data->GL_MESA_ycbcr_texture_supported = SDL_TRUE;
|
|
|
|
}
|
2007-08-12 16:53:58 +00:00
|
|
|
if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
|
|
|
|
data->glTextureRangeAPPLE =
|
|
|
|
(void (*)(GLenum, GLsizei, const GLvoid *))
|
|
|
|
SDL_GL_GetProcAddress("glTextureRangeAPPLE");
|
|
|
|
}
|
2006-07-22 08:33:18 +00:00
|
|
|
|
2008-12-06 00:56:47 +00:00
|
|
|
/* we might use fragment programs for YUV data, etc. */
|
|
|
|
if (SDL_GL_ExtensionSupported("GL_ARB_fragment_program")) {
|
|
|
|
/* !!! FIXME: this doesn't check for errors. */
|
|
|
|
/* !!! FIXME: this should really reuse the glfuncs.h stuff. */
|
|
|
|
data->glGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC)
|
|
|
|
SDL_GL_GetProcAddress("glGetProgramivARB");
|
|
|
|
data->glGetProgramStringARB = (PFNGLGETPROGRAMSTRINGARBPROC)
|
|
|
|
SDL_GL_GetProcAddress("glGetProgramStringARB");
|
|
|
|
data->glProgramLocalParameter4fvARB =
|
|
|
|
(PFNGLPROGRAMLOCALPARAMETER4FVARBPROC)
|
|
|
|
SDL_GL_GetProcAddress("glProgramLocalParameter4fvARB");
|
|
|
|
data->glDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC)
|
|
|
|
SDL_GL_GetProcAddress("glDeleteProgramsARB");
|
|
|
|
data->glGenProgramsARB = (PFNGLGENPROGRAMSARBPROC)
|
|
|
|
SDL_GL_GetProcAddress("glGenProgramsARB");
|
|
|
|
data->glBindProgramARB = (PFNGLBINDPROGRAMARBPROC)
|
|
|
|
SDL_GL_GetProcAddress("glBindProgramARB");
|
|
|
|
data->glProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC)
|
|
|
|
SDL_GL_GetProcAddress("glProgramStringARB");
|
|
|
|
data->GL_ARB_fragment_program_supported = SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
2006-07-19 07:18:45 +00:00
|
|
|
/* Set up parameters for rendering */
|
2006-07-22 23:04:41 +00:00
|
|
|
data->blendMode = -1;
|
|
|
|
data->scaleMode = -1;
|
|
|
|
data->glDisable(GL_DEPTH_TEST);
|
|
|
|
data->glDisable(GL_CULL_FACE);
|
2009-09-19 04:43:41 +00:00
|
|
|
/* This ended up causing video discrepancies between OpenGL and Direct3D */
|
|
|
|
/*data->glEnable(GL_LINE_SMOOTH);*/
|
2006-07-22 21:58:17 +00:00
|
|
|
if (data->GL_ARB_texture_rectangle_supported) {
|
2006-07-22 23:04:41 +00:00
|
|
|
data->glEnable(GL_TEXTURE_RECTANGLE_ARB);
|
2006-07-22 21:58:17 +00:00
|
|
|
} else {
|
2006-07-22 23:04:41 +00:00
|
|
|
data->glEnable(GL_TEXTURE_2D);
|
2006-07-22 21:58:17 +00:00
|
|
|
}
|
2008-12-05 07:00:58 +00:00
|
|
|
data->updateSize = SDL_TRUE;
|
2006-07-19 07:18:45 +00:00
|
|
|
|
|
|
|
return renderer;
|
|
|
|
}
|
|
|
|
|
2006-07-22 19:51:48 +00:00
|
|
|
static int
|
|
|
|
GL_ActivateRenderer(SDL_Renderer * renderer)
|
|
|
|
{
|
|
|
|
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
|
|
|
|
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
|
|
|
|
|
2006-08-06 04:39:13 +00:00
|
|
|
if (SDL_GL_MakeCurrent(window->id, data->context) < 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
2008-12-05 07:00:58 +00:00
|
|
|
if (data->updateSize) {
|
2008-12-06 05:23:35 +00:00
|
|
|
data->glMatrixMode(GL_PROJECTION);
|
|
|
|
data->glLoadIdentity();
|
|
|
|
data->glMatrixMode(GL_MODELVIEW);
|
|
|
|
data->glLoadIdentity();
|
|
|
|
data->glViewport(0, 0, window->w, window->h);
|
2009-09-28 15:32:58 +00:00
|
|
|
data->glOrtho(0.0, (GLdouble) window->w,
|
|
|
|
(GLdouble) window->h, 0.0, 0.0, 1.0);
|
2008-12-05 07:00:58 +00:00
|
|
|
data->updateSize = SDL_FALSE;
|
|
|
|
}
|
2006-08-06 04:39:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
GL_DisplayModeChanged(SDL_Renderer * renderer)
|
|
|
|
{
|
|
|
|
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
|
|
|
|
|
2008-12-06 05:23:35 +00:00
|
|
|
/* Rebind the context to the window area and update matrices */
|
|
|
|
data->updateSize = SDL_TRUE;
|
|
|
|
return GL_ActivateRenderer(renderer);
|
2006-07-22 19:51:48 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 19:03:31 +00:00
|
|
|
static __inline__ int
|
|
|
|
power_of_2(int input)
|
|
|
|
{
|
|
|
|
int value = 1;
|
|
|
|
|
|
|
|
while (value < input) {
|
|
|
|
value <<= 1;
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2008-12-06 00:56:47 +00:00
|
|
|
|
2008-12-08 00:24:15 +00:00
|
|
|
//#define DEBUG_PROGRAM_COMPILE 1
|
2008-12-06 00:56:47 +00:00
|
|
|
|
2009-11-21 05:29:31 +00:00
|
|
|
static void
|
|
|
|
set_shader_error(GL_RenderData * data, const char *prefix)
|
|
|
|
{
|
|
|
|
GLint pos = 0;
|
|
|
|
const GLubyte *errstr;
|
|
|
|
data->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
|
|
|
|
errstr = data->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
|
|
|
|
printf("%s: shader compile error at position %d: %s",
|
|
|
|
prefix, (int) pos, (const char *) errstr);
|
|
|
|
}
|
|
|
|
|
2008-12-06 00:56:47 +00:00
|
|
|
static GLuint
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
compile_shader(GL_RenderData * data, GLenum shader_type, const char *_code)
|
2008-12-06 00:56:47 +00:00
|
|
|
{
|
2008-12-07 07:06:34 +00:00
|
|
|
const int have_texture_rects = data->GL_ARB_texture_rectangle_supported;
|
|
|
|
const char *replacement = have_texture_rects ? "RECT" : "2D";
|
2008-12-25 05:11:29 +00:00
|
|
|
const size_t replacementlen = SDL_strlen(replacement);
|
2008-12-07 07:06:34 +00:00
|
|
|
const char *token = "%TEXTURETARGET%";
|
2008-12-25 05:11:29 +00:00
|
|
|
const size_t tokenlen = SDL_strlen(token);
|
2008-12-07 07:06:34 +00:00
|
|
|
char *code = NULL;
|
|
|
|
char *ptr = NULL;
|
|
|
|
GLuint program = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The TEX instruction needs a different target depending on what we use.
|
|
|
|
* To handle this, we use "%TEXTURETARGET%" and replace the string before
|
|
|
|
* compiling the shader.
|
|
|
|
*/
|
|
|
|
code = SDL_strdup(_code);
|
|
|
|
if (code == NULL)
|
|
|
|
return 0;
|
|
|
|
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
for (ptr = SDL_strstr(code, token); ptr; ptr = SDL_strstr(ptr + 1, token)) {
|
2008-12-25 05:11:29 +00:00
|
|
|
SDL_memcpy(ptr, replacement, replacementlen);
|
|
|
|
SDL_memmove(ptr + replacementlen, ptr + tokenlen,
|
|
|
|
SDL_strlen(ptr + tokenlen) + 1);
|
2008-12-07 07:06:34 +00:00
|
|
|
}
|
|
|
|
|
2008-12-06 00:56:47 +00:00
|
|
|
#if DEBUG_PROGRAM_COMPILE
|
2008-12-07 07:06:34 +00:00
|
|
|
printf("compiling shader:\n%s\n\n", code);
|
2008-12-06 00:56:47 +00:00
|
|
|
#endif
|
|
|
|
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
data->glGetError(); /* flush any existing error state. */
|
2008-12-06 00:56:47 +00:00
|
|
|
data->glGenProgramsARB(1, &program);
|
|
|
|
data->glBindProgramARB(shader_type, program);
|
|
|
|
data->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB,
|
2009-09-05 23:37:35 +00:00
|
|
|
(GLsizei)SDL_strlen(code), code);
|
2008-12-07 07:06:34 +00:00
|
|
|
|
|
|
|
SDL_free(code);
|
2008-12-06 00:56:47 +00:00
|
|
|
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
if (data->glGetError() == GL_INVALID_OPERATION) {
|
2008-12-06 00:56:47 +00:00
|
|
|
#if DEBUG_PROGRAM_COMPILE
|
|
|
|
GLint pos = 0;
|
|
|
|
const GLubyte *errstr;
|
|
|
|
data->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
|
|
|
|
errstr = data->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
|
|
|
|
printf("program compile error at position %d: %s\n\n",
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
(int) pos, (const char *) errstr);
|
2008-12-06 00:56:47 +00:00
|
|
|
#endif
|
|
|
|
data->glBindProgramARB(shader_type, 0);
|
|
|
|
data->glDeleteProgramsARB(1, &program);
|
|
|
|
return 0;
|
2008-12-07 07:16:40 +00:00
|
|
|
}
|
2008-12-06 00:56:47 +00:00
|
|
|
|
|
|
|
return program;
|
|
|
|
}
|
|
|
|
|
2008-12-07 07:16:40 +00:00
|
|
|
|
2009-11-21 05:29:31 +00:00
|
|
|
/*
|
|
|
|
* Fragment program that implements mask semantics
|
|
|
|
*/
|
|
|
|
static const char *fragment_program_mask_source_code = "!!ARBfp1.0\n"
|
|
|
|
"OUTPUT output = result.color;\n"
|
|
|
|
"TEMP value;\n"
|
|
|
|
"TEX value, fragment.texcoord[0], texture[0], %TEXTURETARGET%;\n"
|
|
|
|
"MUL value, fragment.color, value;\n"
|
|
|
|
"SGE value.a, value.a, 0.001;\n"
|
|
|
|
"MOV output, value;\n"
|
|
|
|
"END";
|
|
|
|
|
2008-12-07 07:16:40 +00:00
|
|
|
/*
|
|
|
|
* Fragment program that renders from UYVY textures.
|
|
|
|
* The UYVY to RGB equasion is:
|
|
|
|
* R = 1.164(Y-16) + 1.596(Cr-128)
|
|
|
|
* G = 1.164(Y-16) - 0.813(Cr-128) - 0.391(Cb-128)
|
|
|
|
* B = 1.164(Y-16) + 2.018(Cb-128)
|
|
|
|
* Byte layout is Cb, Y1, Cr, Y2, stored in the R, G, B, A channels.
|
|
|
|
* 4 bytes == 2 pixels: Y1/Cb/Cr, Y2/Cb/Cr
|
|
|
|
*
|
|
|
|
* !!! FIXME: this ignores blendmodes, etc.
|
|
|
|
* !!! FIXME: this could be more efficient...use a dot product for green, etc.
|
|
|
|
*/
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
static const char *fragment_program_UYVY_source_code = "!!ARBfp1.0\n"
|
2008-12-07 07:16:40 +00:00
|
|
|
/* outputs... */
|
2008-12-06 00:56:47 +00:00
|
|
|
"OUTPUT outcolor = result.color;\n"
|
2008-12-07 07:16:40 +00:00
|
|
|
/* scratch registers... */
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
"TEMP uyvy;\n" "TEMP luminance;\n" "TEMP work;\n"
|
2008-12-07 07:16:40 +00:00
|
|
|
/* Halve the coordinates to grab the correct 32 bits for the fragment. */
|
2008-12-06 00:56:47 +00:00
|
|
|
"MUL work, fragment.texcoord, { 0.5, 1.0, 1.0, 1.0 };\n"
|
2008-12-07 07:16:40 +00:00
|
|
|
/* Sample the YUV texture. Cb, Y1, Cr, Y2, are stored in x, y, z, w. */
|
2008-12-07 07:06:34 +00:00
|
|
|
"TEX uyvy, work, texture[0], %TEXTURETARGET%;\n"
|
2008-12-07 07:16:40 +00:00
|
|
|
/* Do subtractions (128/255, 16/255, 128/255, 16/255) */
|
2008-12-07 04:38:32 +00:00
|
|
|
"SUB uyvy, uyvy, { 0.501960784313726, 0.06274509803922, 0.501960784313726, 0.06274509803922 };\n"
|
2008-12-07 07:16:40 +00:00
|
|
|
/* Choose the luminance component by texcoord. */
|
|
|
|
/* !!! FIXME: laziness wins out for now... just average Y1 and Y2. */
|
2008-12-06 00:56:47 +00:00
|
|
|
"ADD luminance, uyvy.yyyy, uyvy.wwww;\n"
|
|
|
|
"MUL luminance, luminance, { 0.5, 0.5, 0.5, 0.5 };\n"
|
2008-12-07 07:16:40 +00:00
|
|
|
/* Multiply luminance by its magic value. */
|
2008-12-06 00:56:47 +00:00
|
|
|
"MUL luminance, luminance, { 1.164, 1.164, 1.164, 1.164 };\n"
|
2008-12-07 07:16:40 +00:00
|
|
|
/* uyvy.xyzw becomes Cr/Cr/Cb/Cb, with multiplications. */
|
2008-12-06 00:56:47 +00:00
|
|
|
"MUL uyvy, uyvy.zzxx, { 1.596, -0.813, 2.018, -0.391 };\n"
|
2008-12-07 07:16:40 +00:00
|
|
|
/* Add luminance to Cr and Cb, store to RGB channels. */
|
2008-12-06 00:56:47 +00:00
|
|
|
"ADD work.rgb, luminance, uyvy;\n"
|
2008-12-07 07:16:40 +00:00
|
|
|
/* Do final addition for Green channel. (!!! FIXME: this should be a DPH?) */
|
2008-12-06 00:56:47 +00:00
|
|
|
"ADD work.g, work.g, uyvy.w;\n"
|
2008-12-07 07:16:40 +00:00
|
|
|
/* Make sure alpha channel is fully opaque. (!!! FIXME: blend modes!) */
|
2008-12-06 00:56:47 +00:00
|
|
|
"MOV work.a, { 1.0 };\n"
|
2008-12-07 07:16:40 +00:00
|
|
|
/* Store out the final fragment color... */
|
2008-12-06 00:56:47 +00:00
|
|
|
"MOV outcolor, work;\n"
|
2008-12-07 07:16:40 +00:00
|
|
|
/* ...and we're done! */
|
2008-12-06 00:56:47 +00:00
|
|
|
"END\n";
|
|
|
|
|
2009-11-15 08:01:34 +00:00
|
|
|
static __inline__ SDL_bool
|
|
|
|
convert_format(GL_RenderData *renderdata, Uint32 pixel_format,
|
|
|
|
GLint* internalFormat, GLenum* format, GLenum* type)
|
2006-07-19 07:18:45 +00:00
|
|
|
{
|
2009-11-15 08:01:34 +00:00
|
|
|
switch (pixel_format) {
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_INDEX1LSB:
|
|
|
|
case SDL_PIXELFORMAT_INDEX1MSB:
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB;
|
|
|
|
*format = GL_COLOR_INDEX;
|
|
|
|
*type = GL_BITMAP;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_INDEX8:
|
2006-08-06 23:34:59 +00:00
|
|
|
if (!renderdata->GL_EXT_paletted_texture_supported) {
|
2009-11-15 08:01:34 +00:00
|
|
|
return SDL_FALSE;
|
2006-08-06 23:34:59 +00:00
|
|
|
}
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_COLOR_INDEX8_EXT;
|
|
|
|
*format = GL_COLOR_INDEX;
|
|
|
|
*type = GL_UNSIGNED_BYTE;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_RGB332:
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_R3_G3_B2;
|
|
|
|
*format = GL_RGB;
|
|
|
|
*type = GL_UNSIGNED_BYTE_3_3_2;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_RGB444:
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB4;
|
|
|
|
*format = GL_RGB;
|
|
|
|
*type = GL_UNSIGNED_SHORT_4_4_4_4;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_RGB555:
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB5;
|
|
|
|
*format = GL_RGB;
|
|
|
|
*type = GL_UNSIGNED_SHORT_5_5_5_1;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_ARGB4444:
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGBA4;
|
|
|
|
*format = GL_BGRA;
|
|
|
|
*type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_ARGB1555:
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB5_A1;
|
|
|
|
*format = GL_BGRA;
|
|
|
|
*type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_RGB565:
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB8;
|
|
|
|
*format = GL_RGB;
|
|
|
|
*type = GL_UNSIGNED_SHORT_5_6_5;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_RGB24:
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB8;
|
|
|
|
*format = GL_RGB;
|
|
|
|
*type = GL_UNSIGNED_BYTE;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_RGB888:
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB8;
|
|
|
|
*format = GL_BGRA;
|
|
|
|
*type = GL_UNSIGNED_BYTE;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_BGR24:
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB8;
|
|
|
|
*format = GL_BGR;
|
|
|
|
*type = GL_UNSIGNED_BYTE;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_BGR888:
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB8;
|
|
|
|
*format = GL_RGBA;
|
|
|
|
*type = GL_UNSIGNED_BYTE;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_ARGB8888:
|
2007-08-12 07:02:28 +00:00
|
|
|
#ifdef __MACOSX__
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGBA;
|
|
|
|
*format = GL_BGRA;
|
|
|
|
*type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
2007-08-12 07:02:28 +00:00
|
|
|
#else
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGBA8;
|
|
|
|
*format = GL_BGRA;
|
|
|
|
*type = GL_UNSIGNED_BYTE;
|
2007-08-12 07:02:28 +00:00
|
|
|
#endif
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_ABGR8888:
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGBA8;
|
|
|
|
*format = GL_RGBA;
|
|
|
|
*type = GL_UNSIGNED_BYTE;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_PIXELFORMAT_ARGB2101010:
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB10_A2;
|
|
|
|
*format = GL_BGRA;
|
|
|
|
*type = GL_UNSIGNED_INT_2_10_10_10_REV;
|
2006-07-22 08:33:18 +00:00
|
|
|
break;
|
2008-12-06 00:56:47 +00:00
|
|
|
case SDL_PIXELFORMAT_UYVY:
|
2008-12-07 04:02:23 +00:00
|
|
|
if (renderdata->GL_APPLE_ycbcr_422_supported) {
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB;
|
|
|
|
*format = GL_YCBCR_422_APPLE;
|
2008-12-07 04:02:23 +00:00
|
|
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
2009-11-15 08:01:34 +00:00
|
|
|
*type = GL_UNSIGNED_SHORT_8_8_APPLE;
|
2008-12-07 04:02:23 +00:00
|
|
|
#else
|
2009-11-15 08:01:34 +00:00
|
|
|
*type = GL_UNSIGNED_SHORT_8_8_REV_APPLE;
|
2008-12-07 04:02:23 +00:00
|
|
|
#endif
|
|
|
|
} else if (renderdata->GL_MESA_ycbcr_texture_supported) {
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB;
|
|
|
|
*format = GL_YCBCR_MESA;
|
2008-12-07 04:02:23 +00:00
|
|
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
2009-11-15 08:01:34 +00:00
|
|
|
*type = GL_UNSIGNED_SHORT_8_8_MESA;
|
2008-12-07 04:02:23 +00:00
|
|
|
#else
|
2009-11-15 08:01:34 +00:00
|
|
|
*type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
|
2008-12-07 04:02:23 +00:00
|
|
|
#endif
|
|
|
|
} else if (renderdata->GL_ARB_fragment_program_supported) {
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGBA;
|
|
|
|
*format = GL_RGBA;
|
|
|
|
*type = GL_UNSIGNED_BYTE;
|
2008-12-06 00:56:47 +00:00
|
|
|
} else {
|
2009-11-15 08:01:34 +00:00
|
|
|
return SDL_FALSE;
|
2008-12-06 00:56:47 +00:00
|
|
|
}
|
|
|
|
break;
|
2008-12-07 04:02:23 +00:00
|
|
|
case SDL_PIXELFORMAT_YUY2:
|
|
|
|
if (renderdata->GL_APPLE_ycbcr_422_supported) {
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB;
|
|
|
|
*format = GL_YCBCR_422_APPLE;
|
2008-12-07 04:02:23 +00:00
|
|
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
2009-11-15 08:01:34 +00:00
|
|
|
*type = GL_UNSIGNED_SHORT_8_8_REV_APPLE;
|
2008-12-07 04:02:23 +00:00
|
|
|
#else
|
2009-11-15 08:01:34 +00:00
|
|
|
*type = GL_UNSIGNED_SHORT_8_8_APPLE;
|
2008-12-07 04:02:23 +00:00
|
|
|
#endif
|
|
|
|
} else if (renderdata->GL_MESA_ycbcr_texture_supported) {
|
2009-11-15 08:01:34 +00:00
|
|
|
*internalFormat = GL_RGB;
|
|
|
|
*format = GL_YCBCR_MESA;
|
2008-12-07 04:02:23 +00:00
|
|
|
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
|
2009-11-15 08:01:34 +00:00
|
|
|
*type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
|
2008-12-07 04:02:23 +00:00
|
|
|
#else
|
2009-11-15 08:01:34 +00:00
|
|
|
*type = GL_UNSIGNED_SHORT_8_8_MESA;
|
2008-12-06 18:37:06 +00:00
|
|
|
#endif
|
2008-12-07 04:02:23 +00:00
|
|
|
} else {
|
2009-11-15 08:01:34 +00:00
|
|
|
return SDL_FALSE;
|
2008-12-07 04:02:23 +00:00
|
|
|
}
|
|
|
|
break;
|
2006-07-22 08:33:18 +00:00
|
|
|
default:
|
2009-11-15 08:01:34 +00:00
|
|
|
return SDL_FALSE;
|
|
|
|
}
|
|
|
|
return SDL_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|
|
|
{
|
|
|
|
GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
|
|
|
|
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
|
|
|
|
GL_TextureData *data;
|
|
|
|
GLint internalFormat;
|
|
|
|
GLenum format, type;
|
|
|
|
int texture_w, texture_h;
|
|
|
|
GLuint shader = 0;
|
|
|
|
GLenum result;
|
|
|
|
|
|
|
|
if (!convert_format(renderdata, texture->format, &internalFormat,
|
|
|
|
&format, &type)) {
|
2006-07-22 08:33:18 +00:00
|
|
|
SDL_SetError("Unsupported texture format");
|
|
|
|
return -1;
|
|
|
|
}
|
2009-11-15 08:01:34 +00:00
|
|
|
if (texture->format == SDL_PIXELFORMAT_UYVY &&
|
|
|
|
!renderdata->GL_APPLE_ycbcr_422_supported &&
|
|
|
|
!renderdata->GL_MESA_ycbcr_texture_supported &&
|
|
|
|
renderdata->GL_ARB_fragment_program_supported) {
|
|
|
|
if (renderdata->fragment_program_UYVY == 0) {
|
|
|
|
renderdata->fragment_program_UYVY =
|
|
|
|
compile_shader(renderdata, GL_FRAGMENT_PROGRAM_ARB,
|
|
|
|
fragment_program_UYVY_source_code);
|
|
|
|
if (renderdata->fragment_program_UYVY == 0) {
|
2009-11-21 05:29:31 +00:00
|
|
|
set_shader_error(renderdata, "UYVY");
|
2009-11-15 08:01:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
shader = renderdata->fragment_program_UYVY;
|
|
|
|
}
|
2006-07-19 07:18:45 +00:00
|
|
|
|
2006-07-22 08:33:18 +00:00
|
|
|
data = (GL_TextureData *) SDL_calloc(1, sizeof(*data));
|
2006-07-19 07:18:45 +00:00
|
|
|
if (!data) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-12-06 00:56:47 +00:00
|
|
|
data->shader = shader;
|
|
|
|
|
2006-08-06 23:34:59 +00:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2007-08-11 20:54:31 +00:00
|
|
|
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
|
2008-12-06 00:56:47 +00:00
|
|
|
data->pitch = texture->w * bytes_per_pixel(texture->format);
|
2007-08-11 20:54:31 +00:00
|
|
|
data->pixels = SDL_malloc(texture->h * data->pitch);
|
|
|
|
if (!data->pixels) {
|
|
|
|
SDL_OutOfMemory();
|
|
|
|
SDL_free(data);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-19 07:18:45 +00:00
|
|
|
texture->driverdata = data;
|
|
|
|
|
2006-07-22 23:04:41 +00:00
|
|
|
renderdata->glGetError();
|
|
|
|
renderdata->glGenTextures(1, &data->texture);
|
2006-07-22 21:58:17 +00:00
|
|
|
if (renderdata->GL_ARB_texture_rectangle_supported) {
|
|
|
|
data->type = GL_TEXTURE_RECTANGLE_ARB;
|
|
|
|
texture_w = texture->w;
|
|
|
|
texture_h = texture->h;
|
2008-12-06 00:56:47 +00:00
|
|
|
data->texw = (GLfloat) texture_w;
|
|
|
|
data->texh = (GLfloat) texture_h;
|
2006-07-22 21:58:17 +00:00
|
|
|
} else {
|
|
|
|
data->type = GL_TEXTURE_2D;
|
|
|
|
texture_w = power_of_2(texture->w);
|
|
|
|
texture_h = power_of_2(texture->h);
|
2008-12-06 00:56:47 +00:00
|
|
|
data->texw = (GLfloat) (texture->w) / texture_w;
|
2006-07-22 21:58:17 +00:00
|
|
|
data->texh = (GLfloat) texture->h / texture_h;
|
|
|
|
}
|
2008-12-06 00:56:47 +00:00
|
|
|
|
2008-12-06 17:41:01 +00:00
|
|
|
/* YUV formats use RGBA but are really two bytes per pixel */
|
|
|
|
if (internalFormat == GL_RGBA && bytes_per_pixel(texture->format) < 4) {
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
data->HACK_RYAN_FIXME = 2;
|
2008-12-06 18:22:28 +00:00
|
|
|
} else {
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
data->HACK_RYAN_FIXME = 1;
|
2008-12-06 17:41:01 +00:00
|
|
|
}
|
2008-12-06 18:22:28 +00:00
|
|
|
texture_w /= data->HACK_RYAN_FIXME;
|
2008-12-06 17:41:01 +00:00
|
|
|
|
2006-07-22 08:33:18 +00:00
|
|
|
data->format = format;
|
|
|
|
data->formattype = type;
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
renderdata->glEnable(data->type);
|
2006-07-22 23:04:41 +00:00
|
|
|
renderdata->glBindTexture(data->type, data->texture);
|
2007-08-12 07:02:28 +00:00
|
|
|
renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
|
|
|
|
GL_NEAREST);
|
|
|
|
renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
|
|
|
|
GL_NEAREST);
|
|
|
|
renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
|
|
|
|
GL_CLAMP_TO_EDGE);
|
|
|
|
renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
|
|
|
|
GL_CLAMP_TO_EDGE);
|
2008-12-06 17:43:10 +00:00
|
|
|
#ifdef __MACOSX__
|
2007-08-12 07:02:28 +00:00
|
|
|
#ifndef GL_TEXTURE_STORAGE_HINT_APPLE
|
|
|
|
#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC
|
|
|
|
#endif
|
|
|
|
#ifndef STORAGE_CACHED_APPLE
|
|
|
|
#define STORAGE_CACHED_APPLE 0x85BE
|
|
|
|
#endif
|
|
|
|
#ifndef STORAGE_SHARED_APPLE
|
|
|
|
#define STORAGE_SHARED_APPLE 0x85BF
|
|
|
|
#endif
|
|
|
|
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
|
|
|
|
renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
|
|
|
|
GL_STORAGE_SHARED_APPLE);
|
|
|
|
} else {
|
|
|
|
renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
|
|
|
|
GL_STORAGE_CACHED_APPLE);
|
|
|
|
}
|
2008-11-29 21:48:14 +00:00
|
|
|
/* This causes a crash in testoverlay for some reason. Apple bug? */
|
|
|
|
#if 0
|
2008-01-08 00:10:46 +00:00
|
|
|
if (texture->access == SDL_TEXTUREACCESS_STREAMING
|
|
|
|
&& texture->format == SDL_PIXELFORMAT_ARGB8888) {
|
2007-08-13 02:38:59 +00:00
|
|
|
/*
|
2008-01-08 00:10:46 +00:00
|
|
|
if (renderdata->glTextureRangeAPPLE) {
|
|
|
|
renderdata->glTextureRangeAPPLE(data->type,
|
|
|
|
texture->h * data->pitch,
|
|
|
|
data->pixels);
|
|
|
|
}
|
|
|
|
*/
|
2007-08-12 07:02:28 +00:00
|
|
|
renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
|
|
|
|
renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
|
|
|
|
texture_h, 0, format, type, data->pixels);
|
|
|
|
} else
|
2008-11-29 21:48:14 +00:00
|
|
|
#endif
|
2007-08-12 07:02:28 +00:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
|
|
|
|
texture_h, 0, format, type, NULL);
|
|
|
|
}
|
2009-01-14 06:53:03 +00:00
|
|
|
renderdata->glDisable(data->type);
|
2006-07-22 23:04:41 +00:00
|
|
|
result = renderdata->glGetError();
|
2006-07-22 21:02:57 +00:00
|
|
|
if (result != GL_NO_ERROR) {
|
|
|
|
GL_SetError("glTexImage2D()", result);
|
|
|
|
return -1;
|
|
|
|
}
|
2006-07-19 07:18:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-11 20:54:31 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2006-07-19 07:18:45 +00:00
|
|
|
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;
|
2006-08-06 23:34:59 +00:00
|
|
|
Uint8 *palette;
|
2006-07-19 07:18:45 +00:00
|
|
|
|
2006-08-06 23:34:59 +00:00
|
|
|
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;
|
|
|
|
}
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
renderdata->glEnable(data->type);
|
2006-08-06 23:34:59 +00:00
|
|
|
renderdata->glBindTexture(data->type, data->texture);
|
|
|
|
renderdata->glColorTableEXT(data->type, GL_RGB8, 256, GL_RGB,
|
|
|
|
GL_UNSIGNED_BYTE, data->palette);
|
2006-07-19 07:18:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
GL_GetTexturePalette(SDL_Renderer * renderer, SDL_Texture * texture,
|
|
|
|
SDL_Color * colors, int firstcolor, int ncolors)
|
|
|
|
{
|
2006-08-06 23:34:59 +00:00
|
|
|
GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
|
2006-07-19 07:18:45 +00:00
|
|
|
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
|
2006-08-06 23:34:59 +00:00
|
|
|
Uint8 *palette;
|
2006-07-19 07:18:45 +00:00
|
|
|
|
2006-08-06 23:34:59 +00:00
|
|
|
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;
|
|
|
|
}
|
2006-07-19 07:18:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-22 21:02:57 +00:00
|
|
|
static void
|
2006-07-22 23:04:41 +00:00
|
|
|
SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture,
|
|
|
|
int pitch)
|
2006-07-22 21:02:57 +00:00
|
|
|
{
|
2006-08-05 17:09:42 +00:00
|
|
|
if (texture->format == SDL_PIXELFORMAT_INDEX1LSB) {
|
2006-07-22 23:04:41 +00:00
|
|
|
renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 1);
|
2006-08-05 17:09:42 +00:00
|
|
|
} else if (texture->format == SDL_PIXELFORMAT_INDEX1MSB) {
|
2006-07-22 23:04:41 +00:00
|
|
|
renderdata->glPixelStorei(GL_UNPACK_LSB_FIRST, 0);
|
2006-07-22 21:02:57 +00:00
|
|
|
}
|
2006-07-22 23:04:41 +00:00
|
|
|
renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
2008-11-29 15:32:14 +00:00
|
|
|
renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
(pitch / bytes_per_pixel(texture->format)) /
|
2009-01-10 21:50:26 +00:00
|
|
|
((GL_TextureData *) texture->driverdata)->
|
|
|
|
HACK_RYAN_FIXME);
|
2006-07-22 21:02:57 +00:00
|
|
|
}
|
|
|
|
|
2006-08-28 03:17:39 +00:00
|
|
|
static int
|
|
|
|
GL_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
|
|
|
|
{
|
2006-08-28 03:27:59 +00:00
|
|
|
return 0;
|
2006-08-28 03:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
GL_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
|
|
|
|
{
|
2006-08-28 03:27:59 +00:00
|
|
|
return 0;
|
2006-08-28 03:17:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
GL_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
|
|
|
|
{
|
|
|
|
switch (texture->blendMode) {
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
case SDL_BLENDMODE_NONE:
|
|
|
|
case SDL_BLENDMODE_MASK:
|
|
|
|
case SDL_BLENDMODE_BLEND:
|
|
|
|
case SDL_BLENDMODE_ADD:
|
|
|
|
case SDL_BLENDMODE_MOD:
|
2006-08-28 03:17:39 +00:00
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
SDL_Unsupported();
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
texture->blendMode = SDL_BLENDMODE_NONE;
|
2006-08-28 03:17:39 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
GL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture)
|
|
|
|
{
|
|
|
|
switch (texture->scaleMode) {
|
|
|
|
case SDL_TEXTURESCALEMODE_NONE:
|
|
|
|
case SDL_TEXTURESCALEMODE_FAST:
|
|
|
|
case SDL_TEXTURESCALEMODE_SLOW:
|
|
|
|
return 0;
|
|
|
|
case SDL_TEXTURESCALEMODE_BEST:
|
|
|
|
SDL_Unsupported();
|
|
|
|
texture->scaleMode = SDL_TEXTURESCALEMODE_SLOW;
|
|
|
|
return -1;
|
|
|
|
default:
|
|
|
|
SDL_Unsupported();
|
|
|
|
texture->scaleMode = SDL_TEXTURESCALEMODE_NONE;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-19 07:18:45 +00:00
|
|
|
static int
|
|
|
|
GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|
|
|
const SDL_Rect * rect, const void *pixels, int pitch)
|
|
|
|
{
|
2006-07-22 23:04:41 +00:00
|
|
|
GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
|
2006-07-19 07:18:45 +00:00
|
|
|
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
|
2006-07-22 21:02:57 +00:00
|
|
|
GLenum result;
|
2006-07-19 07:18:45 +00:00
|
|
|
|
2006-07-22 23:04:41 +00:00
|
|
|
renderdata->glGetError();
|
|
|
|
SetupTextureUpdate(renderdata, texture, pitch);
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
renderdata->glEnable(data->type);
|
2006-07-22 23:04:41 +00:00
|
|
|
renderdata->glBindTexture(data->type, data->texture);
|
|
|
|
renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
|
|
|
|
rect->h, data->format, data->formattype,
|
|
|
|
pixels);
|
2009-01-14 06:53:03 +00:00
|
|
|
renderdata->glDisable(data->type);
|
2006-07-22 23:04:41 +00:00
|
|
|
result = renderdata->glGetError();
|
2006-07-22 21:02:57 +00:00
|
|
|
if (result != GL_NO_ERROR) {
|
|
|
|
GL_SetError("glTexSubImage2D()", result);
|
|
|
|
return -1;
|
|
|
|
}
|
2006-07-19 07:18:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|
|
|
const SDL_Rect * rect, int markDirty, void **pixels,
|
|
|
|
int *pitch)
|
|
|
|
{
|
|
|
|
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
|
|
|
|
|
2006-07-22 08:33:18 +00:00
|
|
|
if (markDirty) {
|
|
|
|
SDL_AddDirtyRect(&data->dirty, rect);
|
2006-07-19 07:18:45 +00:00
|
|
|
}
|
2006-07-22 08:33:18 +00:00
|
|
|
|
|
|
|
*pixels =
|
|
|
|
(void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
|
2008-12-06 00:56:47 +00:00
|
|
|
rect->x * bytes_per_pixel(texture->format));
|
2006-07-22 08:33:18 +00:00
|
|
|
*pitch = data->pitch;
|
2006-07-19 07:18:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
|
|
|
|
const SDL_Rect * rects)
|
|
|
|
{
|
|
|
|
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < numrects; ++i) {
|
2006-07-22 08:33:18 +00:00
|
|
|
SDL_AddDirtyRect(&data->dirty, &rects[i]);
|
2006-07-19 07:18:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-31 07:56:56 +00:00
|
|
|
static void
|
2009-11-19 08:02:00 +00:00
|
|
|
GL_SetBlendMode(GL_RenderData * data, int blendMode, int isprimitive)
|
2008-12-31 07:56:56 +00:00
|
|
|
{
|
|
|
|
if (blendMode != data->blendMode) {
|
|
|
|
switch (blendMode) {
|
|
|
|
case SDL_BLENDMODE_NONE:
|
|
|
|
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
data->glDisable(GL_BLEND);
|
|
|
|
break;
|
|
|
|
case SDL_BLENDMODE_MASK:
|
2009-11-19 08:02:00 +00:00
|
|
|
if (isprimitive) {
|
|
|
|
/* The same as SDL_BLENDMODE_NONE */
|
|
|
|
blendMode = SDL_BLENDMODE_NONE;
|
|
|
|
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
data->glDisable(GL_BLEND);
|
|
|
|
} else {
|
|
|
|
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
|
|
|
data->glEnable(GL_BLEND);
|
|
|
|
data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
}
|
2009-11-19 05:33:41 +00:00
|
|
|
break;
|
2008-12-31 07:56:56 +00:00
|
|
|
case SDL_BLENDMODE_BLEND:
|
|
|
|
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
data->glEnable(GL_BLEND);
|
|
|
|
data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
break;
|
|
|
|
case SDL_BLENDMODE_ADD:
|
|
|
|
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
data->glEnable(GL_BLEND);
|
|
|
|
data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
|
|
|
break;
|
|
|
|
case SDL_BLENDMODE_MOD:
|
|
|
|
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
data->glEnable(GL_BLEND);
|
|
|
|
data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
data->blendMode = blendMode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
static int
|
2008-12-30 04:22:24 +00:00
|
|
|
GL_RenderPoint(SDL_Renderer * renderer, int x, int y)
|
2006-07-19 07:18:45 +00:00
|
|
|
{
|
|
|
|
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
|
2008-12-30 04:22:24 +00:00
|
|
|
|
2009-11-19 08:02:00 +00:00
|
|
|
GL_SetBlendMode(data, renderer->blendMode, 1);
|
2006-07-19 07:18:45 +00:00
|
|
|
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
data->glColor4f((GLfloat) renderer->r * inv255f,
|
|
|
|
(GLfloat) renderer->g * inv255f,
|
|
|
|
(GLfloat) renderer->b * inv255f,
|
|
|
|
(GLfloat) renderer->a * inv255f);
|
2008-12-30 04:22:24 +00:00
|
|
|
|
|
|
|
data->glBegin(GL_POINTS);
|
2009-11-19 04:33:35 +00:00
|
|
|
data->glVertex2f(0.5f + x, 0.5f + y);
|
2008-12-30 04:22:24 +00:00
|
|
|
data->glEnd();
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-21 17:39:41 +00:00
|
|
|
static int
|
2008-12-30 04:22:24 +00:00
|
|
|
GL_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
|
2008-12-21 17:39:41 +00:00
|
|
|
{
|
|
|
|
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
|
|
|
|
|
2009-11-19 08:02:00 +00:00
|
|
|
GL_SetBlendMode(data, renderer->blendMode, 1);
|
2008-12-21 17:39:41 +00:00
|
|
|
|
|
|
|
data->glColor4f((GLfloat) renderer->r * inv255f,
|
|
|
|
(GLfloat) renderer->g * inv255f,
|
|
|
|
(GLfloat) renderer->b * inv255f,
|
|
|
|
(GLfloat) renderer->a * inv255f);
|
|
|
|
|
2008-12-30 04:22:24 +00:00
|
|
|
data->glBegin(GL_LINES);
|
2009-11-19 04:33:35 +00:00
|
|
|
data->glVertex2f(0.5f + x1, 0.5f + y1);
|
|
|
|
data->glVertex2f(0.5f + x2, 0.5f + y2);
|
2008-12-21 17:39:41 +00:00
|
|
|
data->glEnd();
|
|
|
|
|
2009-11-21 06:19:34 +00:00
|
|
|
/* For some reason the rightmost or lowest endpoint is skipped */
|
2009-11-19 04:59:19 +00:00
|
|
|
data->glBegin(GL_POINTS);
|
2009-11-21 06:19:34 +00:00
|
|
|
if (x1 > x2) {
|
|
|
|
data->glVertex2f(0.5f + x1, 0.5f + y1);
|
|
|
|
} else if (x2 > x1) {
|
|
|
|
data->glVertex2f(0.5f + x2, 0.5f + y2);
|
|
|
|
} else if (y1 > y2) {
|
|
|
|
data->glVertex2f(0.5f + x1, 0.5f + y1);
|
|
|
|
} else if (y2 > y1) {
|
|
|
|
data->glVertex2f(0.5f + x2, 0.5f + y2);
|
|
|
|
}
|
2009-11-19 04:59:19 +00:00
|
|
|
data->glEnd();
|
|
|
|
|
2008-12-21 17:39:41 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
static int
|
2008-12-30 04:22:24 +00:00
|
|
|
GL_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
{
|
|
|
|
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
|
|
|
|
|
2009-11-19 08:02:00 +00:00
|
|
|
GL_SetBlendMode(data, renderer->blendMode, 1);
|
2008-12-31 07:56:56 +00:00
|
|
|
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
data->glColor4f((GLfloat) renderer->r * inv255f,
|
|
|
|
(GLfloat) renderer->g * inv255f,
|
|
|
|
(GLfloat) renderer->b * inv255f,
|
|
|
|
(GLfloat) renderer->a * inv255f);
|
2008-12-31 07:56:56 +00:00
|
|
|
|
2008-12-30 04:22:24 +00:00
|
|
|
data->glRecti(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
|
2008-12-21 17:39:41 +00:00
|
|
|
|
2006-07-19 07:18:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
2006-08-28 03:17:39 +00:00
|
|
|
const SDL_Rect * srcrect, const SDL_Rect * dstrect)
|
2006-07-19 07:18:45 +00:00
|
|
|
{
|
|
|
|
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
|
|
|
|
GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
|
2009-11-21 05:29:31 +00:00
|
|
|
GLuint shader = 0;
|
2006-07-19 07:18:45 +00:00
|
|
|
int minx, miny, maxx, maxy;
|
|
|
|
GLfloat minu, maxu, minv, maxv;
|
|
|
|
|
2007-09-10 12:20:02 +00:00
|
|
|
if (texturedata->dirty.list) {
|
2006-07-22 08:33:18 +00:00
|
|
|
SDL_DirtyRect *dirty;
|
|
|
|
void *pixels;
|
2008-12-06 00:56:47 +00:00
|
|
|
int bpp = bytes_per_pixel(texture->format);
|
2006-07-22 08:33:18 +00:00
|
|
|
int pitch = texturedata->pitch;
|
|
|
|
|
2006-07-22 23:04:41 +00:00
|
|
|
SetupTextureUpdate(data, texture, pitch);
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
data->glEnable(texturedata->type);
|
2006-07-22 23:04:41 +00:00
|
|
|
data->glBindTexture(texturedata->type, texturedata->texture);
|
2006-07-22 08:33:18 +00:00
|
|
|
for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
|
|
|
|
SDL_Rect *rect = &dirty->rect;
|
|
|
|
pixels =
|
|
|
|
(void *) ((Uint8 *) texturedata->pixels + rect->y * pitch +
|
|
|
|
rect->x * bpp);
|
2006-07-22 23:04:41 +00:00
|
|
|
data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
rect->w / texturedata->HACK_RYAN_FIXME,
|
|
|
|
rect->h, texturedata->format,
|
2006-07-22 23:04:41 +00:00
|
|
|
texturedata->formattype, pixels);
|
2006-07-22 08:33:18 +00:00
|
|
|
}
|
|
|
|
SDL_ClearDirtyRects(&texturedata->dirty);
|
|
|
|
}
|
|
|
|
|
2006-07-19 07:18:45 +00:00
|
|
|
minx = dstrect->x;
|
|
|
|
miny = dstrect->y;
|
|
|
|
maxx = dstrect->x + dstrect->w;
|
|
|
|
maxy = dstrect->y + dstrect->h;
|
|
|
|
|
|
|
|
minu = (GLfloat) srcrect->x / texture->w;
|
2006-07-22 08:33:18 +00:00
|
|
|
minu *= texturedata->texw;
|
2006-07-19 07:18:45 +00:00
|
|
|
maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
|
2006-07-22 08:33:18 +00:00
|
|
|
maxu *= texturedata->texw;
|
2006-07-19 07:18:45 +00:00
|
|
|
minv = (GLfloat) srcrect->y / texture->h;
|
2006-07-22 08:33:18 +00:00
|
|
|
minv *= texturedata->texh;
|
2006-07-19 07:18:45 +00:00
|
|
|
maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
|
2006-07-22 08:33:18 +00:00
|
|
|
maxv *= texturedata->texh;
|
2006-07-19 07:18:45 +00:00
|
|
|
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
data->glEnable(texturedata->type);
|
2006-07-22 23:04:41 +00:00
|
|
|
data->glBindTexture(texturedata->type, texturedata->texture);
|
|
|
|
|
2006-08-28 03:17:39 +00:00
|
|
|
if (texture->modMode) {
|
|
|
|
data->glColor4f((GLfloat) texture->r * inv255f,
|
|
|
|
(GLfloat) texture->g * inv255f,
|
|
|
|
(GLfloat) texture->b * inv255f,
|
|
|
|
(GLfloat) texture->a * inv255f);
|
|
|
|
} else {
|
|
|
|
data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
|
|
|
}
|
|
|
|
|
2009-11-19 08:02:00 +00:00
|
|
|
GL_SetBlendMode(data, texture->blendMode, 0);
|
2006-07-19 07:18:45 +00:00
|
|
|
|
2009-11-21 05:29:31 +00:00
|
|
|
/* Set up the shader for the copy, we have a special one for MASK */
|
|
|
|
shader = texturedata->shader;
|
|
|
|
if (texture->blendMode == SDL_BLENDMODE_MASK && !shader) {
|
|
|
|
if (data->fragment_program_mask == 0) {
|
|
|
|
data->fragment_program_mask =
|
|
|
|
compile_shader(data, GL_FRAGMENT_PROGRAM_ARB,
|
|
|
|
fragment_program_mask_source_code);
|
|
|
|
if (data->fragment_program_mask == 0) {
|
|
|
|
/* That's okay, we'll just miss some of the blend semantics */
|
|
|
|
data->fragment_program_mask = ~0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data->fragment_program_mask != ~0) {
|
|
|
|
shader = data->fragment_program_mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-28 03:17:39 +00:00
|
|
|
if (texture->scaleMode != data->scaleMode) {
|
|
|
|
switch (texture->scaleMode) {
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_TEXTURESCALEMODE_NONE:
|
|
|
|
case SDL_TEXTURESCALEMODE_FAST:
|
2006-07-22 23:04:41 +00:00
|
|
|
data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
|
|
|
|
GL_NEAREST);
|
|
|
|
data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
|
|
|
|
GL_NEAREST);
|
|
|
|
break;
|
2006-08-05 17:09:42 +00:00
|
|
|
case SDL_TEXTURESCALEMODE_SLOW:
|
|
|
|
case SDL_TEXTURESCALEMODE_BEST:
|
2006-07-22 23:04:41 +00:00
|
|
|
data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
|
|
|
|
GL_LINEAR);
|
|
|
|
data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
|
|
|
|
GL_LINEAR);
|
|
|
|
break;
|
|
|
|
}
|
2006-08-28 03:17:39 +00:00
|
|
|
data->scaleMode = texture->scaleMode;
|
2006-07-19 07:18:45 +00:00
|
|
|
}
|
|
|
|
|
2009-11-21 05:29:31 +00:00
|
|
|
if (shader) {
|
2008-12-06 00:56:47 +00:00
|
|
|
data->glEnable(GL_FRAGMENT_PROGRAM_ARB);
|
2009-11-21 05:29:31 +00:00
|
|
|
data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, shader);
|
2008-12-06 00:56:47 +00:00
|
|
|
}
|
|
|
|
|
2006-07-22 23:04:41 +00:00
|
|
|
data->glBegin(GL_TRIANGLE_STRIP);
|
|
|
|
data->glTexCoord2f(minu, minv);
|
2009-11-21 06:34:43 +00:00
|
|
|
data->glVertex2f((GLfloat) minx, (GLfloat) miny);
|
2006-07-22 23:04:41 +00:00
|
|
|
data->glTexCoord2f(maxu, minv);
|
2009-11-21 06:34:43 +00:00
|
|
|
data->glVertex2f((GLfloat) maxx, (GLfloat) miny);
|
2006-07-22 23:04:41 +00:00
|
|
|
data->glTexCoord2f(minu, maxv);
|
2009-11-21 06:34:43 +00:00
|
|
|
data->glVertex2f((GLfloat) minx, (GLfloat) maxy);
|
2006-07-22 23:04:41 +00:00
|
|
|
data->glTexCoord2f(maxu, maxv);
|
2009-11-21 06:34:43 +00:00
|
|
|
data->glVertex2f((GLfloat) maxx, (GLfloat) maxy);
|
2006-07-22 23:04:41 +00:00
|
|
|
data->glEnd();
|
2006-07-19 07:18:45 +00:00
|
|
|
|
2009-11-21 05:29:31 +00:00
|
|
|
if (shader) {
|
2008-12-06 00:56:47 +00:00
|
|
|
data->glDisable(GL_FRAGMENT_PROGRAM_ARB);
|
|
|
|
}
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
|
|
|
|
data->glDisable(texturedata->type);
|
|
|
|
|
2006-07-19 07:18:45 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-15 04:58:03 +00:00
|
|
|
static int
|
|
|
|
GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
2009-11-16 07:13:07 +00:00
|
|
|
Uint32 pixel_format, void * pixels, int pitch)
|
2009-11-15 04:58:03 +00:00
|
|
|
{
|
2009-11-15 08:01:34 +00:00
|
|
|
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
|
2009-11-18 08:07:37 +00:00
|
|
|
SDL_Window *window = SDL_GetWindowFromID(renderer->window);
|
2009-11-15 08:01:34 +00:00
|
|
|
GLint internalFormat;
|
|
|
|
GLenum format, type;
|
2009-11-16 07:13:07 +00:00
|
|
|
Uint8 *src, *dst, *tmp;
|
|
|
|
int length, rows;
|
2009-11-15 08:01:34 +00:00
|
|
|
|
|
|
|
if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) {
|
2009-11-16 07:13:07 +00:00
|
|
|
/* FIXME: Do a temp copy to a format that is supported */
|
2009-11-15 08:01:34 +00:00
|
|
|
SDL_SetError("Unsupported pixel format");
|
|
|
|
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);
|
|
|
|
}
|
2009-11-18 07:35:00 +00:00
|
|
|
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
|
|
|
data->glPixelStorei(GL_PACK_ROW_LENGTH,
|
|
|
|
(pitch / bytes_per_pixel(pixel_format)));
|
2009-11-15 08:01:34 +00:00
|
|
|
|
2009-11-18 08:07:37 +00:00
|
|
|
data->glReadPixels(rect->x, (window->h-rect->y)-rect->h, rect->w, rect->h,
|
2009-11-16 07:13:07 +00:00
|
|
|
format, type, pixels);
|
|
|
|
|
|
|
|
/* Flip the rows to be top-down */
|
|
|
|
length = rect->w * bytes_per_pixel(pixel_format);
|
|
|
|
src = (Uint8*)pixels + (rect->h-1)*pitch;
|
|
|
|
dst = (Uint8*)pixels;
|
|
|
|
tmp = SDL_stack_alloc(Uint8, length);
|
|
|
|
rows = rect->h / 2;
|
|
|
|
while (rows--) {
|
|
|
|
SDL_memcpy(tmp, dst, length);
|
|
|
|
SDL_memcpy(dst, src, length);
|
|
|
|
SDL_memcpy(src, tmp, length);
|
2009-11-18 08:07:37 +00:00
|
|
|
dst += pitch;
|
|
|
|
src -= pitch;
|
2009-11-16 07:13:07 +00:00
|
|
|
}
|
|
|
|
SDL_stack_free(tmp);
|
2009-11-17 06:50:29 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-11-15 04:58:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
2009-11-16 07:13:07 +00:00
|
|
|
Uint32 pixel_format, const void * pixels, int pitch)
|
2009-11-15 04:58:03 +00:00
|
|
|
{
|
2009-11-16 07:13:07 +00:00
|
|
|
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
|
|
|
|
GLint internalFormat;
|
|
|
|
GLenum format, type;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: We need to copy the data and flip it */
|
|
|
|
|
|
|
|
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)));
|
|
|
|
|
2009-11-18 07:35:00 +00:00
|
|
|
data->glRasterPos2i(rect->x, rect->y);
|
|
|
|
data->glDrawPixels(rect->w, rect->h, format, type, pixels);
|
2009-11-17 06:50:29 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-11-15 04:58:03 +00:00
|
|
|
}
|
|
|
|
|
2006-07-19 07:18:45 +00:00
|
|
|
static void
|
|
|
|
GL_RenderPresent(SDL_Renderer * renderer)
|
|
|
|
{
|
|
|
|
SDL_GL_SwapWindow(renderer->window);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|
|
|
{
|
2006-07-22 23:04:41 +00:00
|
|
|
GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
|
2006-07-19 07:18:45 +00:00
|
|
|
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
|
|
|
|
|
|
|
|
if (!data) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (data->texture) {
|
2006-07-22 23:04:41 +00:00
|
|
|
renderdata->glDeleteTextures(1, &data->texture);
|
2006-07-22 08:33:18 +00:00
|
|
|
}
|
2006-08-06 23:34:59 +00:00
|
|
|
if (data->palette) {
|
|
|
|
SDL_free(data->palette);
|
|
|
|
}
|
2006-07-22 08:33:18 +00:00
|
|
|
if (data->pixels) {
|
|
|
|
SDL_free(data->pixels);
|
2006-07-19 07:18:45 +00:00
|
|
|
}
|
2006-07-22 08:33:18 +00:00
|
|
|
SDL_FreeDirtyRects(&data->dirty);
|
2006-07-19 07:18:45 +00:00
|
|
|
SDL_free(data);
|
|
|
|
texture->driverdata = NULL;
|
|
|
|
}
|
|
|
|
|
2006-08-07 05:24:13 +00:00
|
|
|
static void
|
2006-07-19 07:18:45 +00:00
|
|
|
GL_DestroyRenderer(SDL_Renderer * renderer)
|
|
|
|
{
|
|
|
|
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
|
|
|
|
|
|
|
|
if (data) {
|
2006-07-22 08:33:18 +00:00
|
|
|
if (data->context) {
|
2008-12-06 00:56:47 +00:00
|
|
|
if (data->GL_ARB_fragment_program_supported) {
|
|
|
|
data->glDisable(GL_FRAGMENT_PROGRAM_ARB);
|
|
|
|
data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0);
|
2009-11-21 05:29:31 +00:00
|
|
|
if (data->fragment_program_mask &&
|
|
|
|
data->fragment_program_mask != ~0) {
|
|
|
|
data->glDeleteProgramsARB(1,
|
|
|
|
&data->fragment_program_mask);
|
|
|
|
}
|
|
|
|
if (data->fragment_program_UYVY &&
|
|
|
|
data->fragment_program_UYVY != ~0) {
|
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.
--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403346
2008-12-20 12:00:00 +00:00
|
|
|
data->glDeleteProgramsARB(1,
|
|
|
|
&data->fragment_program_UYVY);
|
2008-12-06 00:56:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-14 18:17:49 +00:00
|
|
|
/* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
|
2006-07-22 08:33:18 +00:00
|
|
|
SDL_GL_DeleteContext(data->context);
|
2006-07-19 07:18:45 +00:00
|
|
|
}
|
|
|
|
SDL_free(data);
|
|
|
|
}
|
|
|
|
SDL_free(renderer);
|
|
|
|
}
|
|
|
|
|
2006-07-28 08:43:17 +00:00
|
|
|
#endif /* SDL_VIDEO_RENDER_OGL */
|
2006-07-19 07:18:45 +00:00
|
|
|
|
|
|
|
/* vi: set ts=4 sw=4 expandtab: */
|