WinRT: merged with SDL 2.0.1 codebase

This commit is contained in:
David Ludwig
2013-10-27 21:26:46 -04:00
343 changed files with 12735 additions and 7248 deletions

View File

@@ -22,6 +22,7 @@
/* The SDL 2D rendering system */
#include "SDL_assert.h"
#include "SDL_hints.h"
#include "SDL_log.h"
#include "SDL_render.h"
@@ -120,7 +121,12 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
/* Window was resized, reset viewport */
int w, h;
SDL_GetWindowSize(window, &w, &h);
if (renderer->GetOutputSize) {
renderer->GetOutputSize(renderer, &w, &h);
} else {
SDL_GetWindowSize(renderer->window, &w, &h);
}
if (renderer->target) {
renderer->viewport_backup.x = 0;
renderer->viewport_backup.y = 0;
@@ -338,11 +344,11 @@ SDL_GetRendererOutputSize(SDL_Renderer * renderer, int *w, int *h)
if (renderer->target) {
return SDL_QueryTexture(renderer->target, NULL, NULL, w, h);
} else if (renderer->GetOutputSize) {
return renderer->GetOutputSize(renderer, w, h);
} else if (renderer->window) {
SDL_GetWindowSize(renderer->window, w, h);
return 0;
} else if (renderer->GetOutputSize) {
return renderer->GetOutputSize(renderer, w, h);
} else {
/* This should never happen */
SDL_SetError("Renderer doesn't support querying output size");
@@ -407,6 +413,11 @@ SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int
SDL_SetError("Texture dimensions can't be 0");
return NULL;
}
if ((renderer->info.max_texture_width && w > renderer->info.max_texture_width) ||
(renderer->info.max_texture_height && h > renderer->info.max_texture_height)) {
SDL_SetError("Texture dimensions are limited to %dx%d", renderer->info.max_texture_width, renderer->info.max_texture_height);
return NULL;
}
texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
if (!texture) {
SDL_OutOfMemory();
@@ -802,6 +813,110 @@ SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
}
}
static int
SDL_UpdateTextureYUVPlanar(SDL_Texture * texture, const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
{
SDL_Texture *native = texture->native;
SDL_Rect full_rect;
if (SDL_SW_UpdateYUVTexturePlanar(texture->yuv, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch) < 0) {
return -1;
}
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = texture->w;
full_rect.h = texture->h;
rect = &full_rect;
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
/* We can lock the texture and copy to it */
void *native_pixels;
int native_pitch;
if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) {
return -1;
}
SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
rect->w, rect->h, native_pixels, native_pitch);
SDL_UnlockTexture(native);
} else {
/* Use a temporary buffer for updating */
void *temp_pixels;
int temp_pitch;
temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
temp_pixels = SDL_malloc(rect->h * temp_pitch);
if (!temp_pixels) {
return SDL_OutOfMemory();
}
SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format,
rect->w, rect->h, temp_pixels, temp_pitch);
SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch);
SDL_free(temp_pixels);
}
return 0;
}
int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
{
SDL_Renderer *renderer;
SDL_Rect full_rect;
CHECK_TEXTURE_MAGIC(texture, -1);
if (!Yplane) {
return SDL_InvalidParamError("Yplane");
}
if (!Ypitch) {
return SDL_InvalidParamError("Ypitch");
}
if (!Uplane) {
return SDL_InvalidParamError("Uplane");
}
if (!Upitch) {
return SDL_InvalidParamError("Upitch");
}
if (!Vplane) {
return SDL_InvalidParamError("Vplane");
}
if (!Vpitch) {
return SDL_InvalidParamError("Vpitch");
}
if (texture->format != SDL_PIXELFORMAT_YV12 &&
texture->format != SDL_PIXELFORMAT_IYUV) {
return SDL_SetError("Texture format must by YV12 or IYUV");
}
if (!rect) {
full_rect.x = 0;
full_rect.y = 0;
full_rect.w = texture->w;
full_rect.h = texture->h;
rect = &full_rect;
}
if (texture->yuv) {
return SDL_UpdateTextureYUVPlanar(texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
} else {
SDL_assert(!texture->native);
renderer = texture->renderer;
SDL_assert(renderer->UpdateTextureYUV);
if (renderer->UpdateTextureYUV) {
return renderer->UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
} else {
return SDL_Unsupported();
}
}
}
static int
SDL_LockTextureYUV(SDL_Texture * texture, const SDL_Rect * rect,
void **pixels, int *pitch)
@@ -1715,9 +1830,7 @@ SDL_DestroyTexture(SDL_Texture * texture)
if (texture->yuv) {
SDL_SW_DestroyYUVTexture(texture->yuv);
}
if (texture->pixels) {
SDL_free(texture->pixels);
}
SDL_free(texture->pixels);
renderer->DestroyTexture(renderer, texture);
SDL_free(texture);

View File

@@ -89,6 +89,11 @@ struct SDL_Renderer
int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
int pitch);
int (*UpdateTextureYUV) (SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch);
int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch);
void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);

View File

@@ -958,10 +958,10 @@ SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture * swdata, Uint32 target_format)
if (SDL_HasMMX() && (Rmask == 0xF800) &&
(Gmask == 0x07E0) && (Bmask == 0x001F)
&& (swdata->w & 15) == 0) {
/*printf("Using MMX 16-bit 565 dither\n");*/
/* printf("Using MMX 16-bit 565 dither\n"); */
swdata->Display1X = Color565DitherYV12MMX1X;
} else {
/*printf("Using C 16-bit dither\n");*/
/* printf("Using C 16-bit dither\n"); */
swdata->Display1X = Color16DitherYV12Mod1X;
}
#else
@@ -979,10 +979,10 @@ SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture * swdata, Uint32 target_format)
if (SDL_HasMMX() && (Rmask == 0x00FF0000) &&
(Gmask == 0x0000FF00) &&
(Bmask == 0x000000FF) && (swdata->w & 15) == 0) {
/*printf("Using MMX 32-bit dither\n");*/
/* printf("Using MMX 32-bit dither\n"); */
swdata->Display1X = ColorRGBDitherYV12MMX1X;
} else {
/*printf("Using C 32-bit dither\n");*/
/* printf("Using C 32-bit dither\n"); */
swdata->Display1X = Color32DitherYV12Mod1X;
}
#else
@@ -1012,10 +1012,8 @@ SDL_SW_SetupYUVDisplay(SDL_SW_YUVTexture * swdata, Uint32 target_format)
break;
}
if (swdata->display) {
SDL_FreeSurface(swdata->display);
swdata->display = NULL;
}
SDL_FreeSurface(swdata->display);
swdata->display = NULL;
return 0;
}
@@ -1186,6 +1184,61 @@ SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
return 0;
}
int
SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
{
const Uint8 *src;
Uint8 *dst;
int row;
size_t length;
/* Copy the Y plane */
src = Yplane;
dst = swdata->pixels + rect->y * swdata->w + rect->x;
length = rect->w;
for (row = 0; row < rect->h; ++row) {
SDL_memcpy(dst, src, length);
src += Ypitch;
dst += swdata->w;
}
/* Copy the U plane */
src = Uplane;
if (swdata->format == SDL_PIXELFORMAT_IYUV) {
dst = swdata->pixels + swdata->h * swdata->w;
} else {
dst = swdata->pixels + swdata->h * swdata->w +
(swdata->h * swdata->w) / 4;
}
dst += rect->y/2 * swdata->w/2 + rect->x/2;
length = rect->w / 2;
for (row = 0; row < rect->h/2; ++row) {
SDL_memcpy(dst, src, length);
src += Upitch;
dst += swdata->w/2;
}
/* Copy the V plane */
src = Vplane;
if (swdata->format == SDL_PIXELFORMAT_YV12) {
dst = swdata->pixels + swdata->h * swdata->w;
} else {
dst = swdata->pixels + swdata->h * swdata->w +
(swdata->h * swdata->w) / 4;
}
dst += rect->y/2 * swdata->w/2 + rect->x/2;
length = rect->w / 2;
for (row = 0; row < rect->h/2; ++row) {
SDL_memcpy(dst, src, length);
src += Vpitch;
dst += swdata->w/2;
}
return 0;
}
int
SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
void **pixels, int *pitch)
@@ -1335,21 +1388,11 @@ void
SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata)
{
if (swdata) {
if (swdata->pixels) {
SDL_free(swdata->pixels);
}
if (swdata->colortab) {
SDL_free(swdata->colortab);
}
if (swdata->rgb_2_pix) {
SDL_free(swdata->rgb_2_pix);
}
if (swdata->stretch) {
SDL_FreeSurface(swdata->stretch);
}
if (swdata->display) {
SDL_FreeSurface(swdata->display);
}
SDL_free(swdata->pixels);
SDL_free(swdata->colortab);
SDL_free(swdata->rgb_2_pix);
SDL_FreeSurface(swdata->stretch);
SDL_FreeSurface(swdata->display);
SDL_free(swdata);
}
}

View File

@@ -57,6 +57,10 @@ int SDL_SW_QueryYUVTexturePixels(SDL_SW_YUVTexture * swdata, void **pixels,
int *pitch);
int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
const void *pixels, int pitch);
int SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch);
int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
void **pixels, int *pitch);
void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture * swdata);

View File

@@ -22,14 +22,14 @@
#if SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED
#include "../../core/windows/SDL_windows.h"
#include "SDL_hints.h"
#include "SDL_loadso.h"
#include "SDL_syswm.h"
#include "SDL_system.h"
#include "../SDL_sysrender.h"
#include <stdio.h>
#include "../../video/windows/SDL_windowsvideo.h"
#if SDL_VIDEO_RENDER_D3D
#define D3D_DEBUG_INFO
@@ -207,6 +207,11 @@ static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
int pitch);
static int D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch);
static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch);
static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
@@ -395,6 +400,73 @@ D3DFMTToPixelFormat(D3DFORMAT format)
}
}
static void
D3D_InitRenderState(D3D_RenderData *data)
{
D3DMATRIX matrix;
IDirect3DDevice9 *device = data->device;
IDirect3DDevice9_SetVertexShader(device, NULL);
IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
IDirect3DDevice9_SetRenderState(device, D3DRS_CULLMODE, D3DCULL_NONE);
IDirect3DDevice9_SetRenderState(device, D3DRS_LIGHTING, FALSE);
/* Enable color modulation by diffuse color */
IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLOROP,
D3DTOP_MODULATE);
IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG1,
D3DTA_TEXTURE);
IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_COLORARG2,
D3DTA_DIFFUSE);
/* Enable alpha modulation by diffuse alpha */
IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAOP,
D3DTOP_MODULATE);
IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG1,
D3DTA_TEXTURE);
IDirect3DDevice9_SetTextureStageState(device, 0, D3DTSS_ALPHAARG2,
D3DTA_DIFFUSE);
/* Enable separate alpha blend function, if possible */
if (data->enableSeparateAlphaBlend) {
IDirect3DDevice9_SetRenderState(device, D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
}
/* Disable second texture stage, since we're done */
IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_COLOROP,
D3DTOP_DISABLE);
IDirect3DDevice9_SetTextureStageState(device, 1, D3DTSS_ALPHAOP,
D3DTOP_DISABLE);
/* Set an identity world and view matrix */
matrix.m[0][0] = 1.0f;
matrix.m[0][1] = 0.0f;
matrix.m[0][2] = 0.0f;
matrix.m[0][3] = 0.0f;
matrix.m[1][0] = 0.0f;
matrix.m[1][1] = 1.0f;
matrix.m[1][2] = 0.0f;
matrix.m[1][3] = 0.0f;
matrix.m[2][0] = 0.0f;
matrix.m[2][1] = 0.0f;
matrix.m[2][2] = 1.0f;
matrix.m[2][3] = 0.0f;
matrix.m[3][0] = 0.0f;
matrix.m[3][1] = 0.0f;
matrix.m[3][2] = 0.0f;
matrix.m[3][3] = 1.0f;
IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &matrix);
IDirect3DDevice9_SetTransform(device, D3DTS_VIEW, &matrix);
/* Reset our current scale mode */
SDL_memset(data->scaleMode, 0xFF, sizeof(data->scaleMode));
/* Start the render with beginScene */
data->beginScene = SDL_TRUE;
}
static int
D3D_Reset(SDL_Renderer * renderer)
{
@@ -416,14 +488,9 @@ D3D_Reset(SDL_Renderer * renderer)
return D3D_SetError("Reset()", result);
}
}
IDirect3DDevice9_SetVertexShader(data->device, NULL);
IDirect3DDevice9_SetFVF(data->device,
D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
D3DCULL_NONE);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget);
SDL_memset(data->scaleMode, 0xFF, sizeof(data->scaleMode));
D3D_InitRenderState(data);
D3D_UpdateViewport(renderer);
return 0;
}
@@ -476,15 +543,17 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
D3D_RenderData *data;
SDL_SysWMinfo windowinfo;
HRESULT result;
const char *hint;
D3DPRESENT_PARAMETERS pparams;
IDirect3DSwapChain9 *chain;
D3DCAPS9 caps;
DWORD device_flags;
Uint32 window_flags;
int w, h;
SDL_DisplayMode fullscreen_mode;
D3DMATRIX matrix;
int d3dxVersion;
char d3dxDLLFile[50];
int displayIndex;
renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
if (!renderer) {
@@ -499,21 +568,7 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
return NULL;
}
data->d3dDLL = SDL_LoadObject("D3D9.DLL");
if (data->d3dDLL) {
IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
D3DCreate =
(IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(data->d3dDLL,
"Direct3DCreate9");
if (D3DCreate) {
data->d3d = D3DCreate(D3D_SDK_VERSION);
}
if (!data->d3d) {
SDL_UnloadObject(data->d3dDLL);
data->d3dDLL = NULL;
}
if( D3D_LoadDLL( &data->d3dDLL, &data->d3d ) ) {
for (d3dxVersion=50;d3dxVersion>0;d3dxVersion--) {
LPTSTR dllName;
SDL_snprintf(d3dxDLLFile, sizeof(d3dxDLLFile), "D3DX9_%02d.dll", d3dxVersion);
@@ -535,8 +590,6 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
}
}
if (!data->d3d || !data->matrixStack) {
SDL_free(renderer);
SDL_free(data);
@@ -547,6 +600,7 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->WindowEvent = D3D_WindowEvent;
renderer->CreateTexture = D3D_CreateTexture;
renderer->UpdateTexture = D3D_UpdateTexture;
renderer->UpdateTextureYUV = D3D_UpdateTextureYUV;
renderer->LockTexture = D3D_LockTexture;
renderer->UnlockTexture = D3D_UnlockTexture;
renderer->SetRenderTarget = D3D_SetRenderTarget;
@@ -606,26 +660,34 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
}
/* FIXME: Which adapter? */
data->adapter = D3DADAPTER_DEFAULT;
/* Get the adapter for the display that the window is on */
displayIndex = SDL_GetWindowDisplayIndex( window );
data->adapter = SDL_Direct3D9GetAdapterIndex( displayIndex );
IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps);
device_flags = D3DCREATE_FPU_PRESERVE;
if (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
device_flags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
} else {
device_flags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
}
hint = SDL_GetHint(SDL_HINT_RENDER_DIRECT3D_THREADSAFE);
if (hint && SDL_atoi(hint)) {
device_flags |= D3DCREATE_MULTITHREADED;
}
result = IDirect3D9_CreateDevice(data->d3d, data->adapter,
D3DDEVTYPE_HAL,
pparams.hDeviceWindow,
D3DCREATE_FPU_PRESERVE | ((caps.
DevCaps &
D3DDEVCAPS_HWTRANSFORMANDLIGHT) ?
D3DCREATE_HARDWARE_VERTEXPROCESSING :
D3DCREATE_SOFTWARE_VERTEXPROCESSING),
device_flags,
&pparams, &data->device);
if (FAILED(result)) {
D3D_DestroyRenderer(renderer);
D3D_SetError("CreateDevice()", result);
return NULL;
}
data->beginScene = SDL_TRUE;
SDL_memset(data->scaleMode, 0xFF, sizeof(data->scaleMode));
/* Get presentation parameters to fill info */
result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
@@ -658,61 +720,12 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
data->enableSeparateAlphaBlend = SDL_TRUE;
}
/* Set up parameters for rendering */
IDirect3DDevice9_SetVertexShader(data->device, NULL);
IDirect3DDevice9_SetFVF(data->device,
D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_ZENABLE, D3DZB_FALSE);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
D3DCULL_NONE);
IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
/* Enable color modulation by diffuse color */
IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLOROP,
D3DTOP_MODULATE);
IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG1,
D3DTA_TEXTURE);
IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG2,
D3DTA_DIFFUSE);
/* Enable alpha modulation by diffuse alpha */
IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAOP,
D3DTOP_MODULATE);
IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG1,
D3DTA_TEXTURE);
IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG2,
D3DTA_DIFFUSE);
/* Enable separate alpha blend function, if possible */
if (data->enableSeparateAlphaBlend) {
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SEPARATEALPHABLENDENABLE, TRUE);
}
/* Disable second texture stage, since we're done */
IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_COLOROP,
D3DTOP_DISABLE);
IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_ALPHAOP,
D3DTOP_DISABLE);
/* Store the default render target */
IDirect3DDevice9_GetRenderTarget(data->device, 0, &data->defaultRenderTarget );
data->currentRenderTarget = NULL;
/* Set an identity world and view matrix */
matrix.m[0][0] = 1.0f;
matrix.m[0][1] = 0.0f;
matrix.m[0][2] = 0.0f;
matrix.m[0][3] = 0.0f;
matrix.m[1][0] = 0.0f;
matrix.m[1][1] = 1.0f;
matrix.m[1][2] = 0.0f;
matrix.m[1][3] = 0.0f;
matrix.m[2][0] = 0.0f;
matrix.m[2][1] = 0.0f;
matrix.m[2][2] = 1.0f;
matrix.m[2][3] = 0.0f;
matrix.m[3][0] = 0.0f;
matrix.m[3][1] = 0.0f;
matrix.m[3][2] = 0.0f;
matrix.m[3][3] = 1.0f;
IDirect3DDevice9_SetTransform(data->device, D3DTS_WORLD, &matrix);
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, &matrix);
/* Set up parameters for rendering */
D3D_InitRenderState(data);
if (caps.MaxSimultaneousTextures >= 3)
{
@@ -864,7 +877,7 @@ GetScaleQuality(void)
if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) {
return D3DTEXF_POINT;
} else /*if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0)*/ {
} else /* if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) */ {
return D3DTEXF_LINEAR;
}
}
@@ -1013,6 +1026,36 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
return 0;
}
static int
D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
{
D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
SDL_bool full_texture = SDL_FALSE;
#ifdef USE_DYNAMIC_TEXTURE
if (texture->access == SDL_TEXTUREACCESS_STREAMING &&
rect->x == 0 && rect->y == 0 &&
rect->w == texture->w && rect->h == texture->h) {
full_texture = SDL_TRUE;
}
#endif
if (D3D_UpdateTextureInternal(data->texture, texture->format, full_texture, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
return -1;
}
if (D3D_UpdateTextureInternal(data->utexture, texture->format, full_texture, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch) < 0) {
return -1;
}
if (D3D_UpdateTextureInternal(data->vtexture, texture->format, full_texture, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch) < 0) {
return -1;
}
return 0;
}
static int
D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch)
@@ -1023,7 +1066,7 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
HRESULT result;
if (data->yuv) {
// It's more efficient to upload directly...
/* It's more efficient to upload directly... */
if (!data->pixels) {
data->pitch = texture->w;
data->pixels = (Uint8 *)SDL_malloc((texture->h * data->pitch * 3) / 2);
@@ -1173,6 +1216,7 @@ D3D_RenderClear(SDL_Renderer * renderer)
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
DWORD color;
HRESULT result;
int BackBufferWidth, BackBufferHeight;
if (D3D_ActivateRenderer(renderer) < 0) {
return -1;
@@ -1180,10 +1224,18 @@ D3D_RenderClear(SDL_Renderer * renderer)
color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
if (renderer->target) {
BackBufferWidth = renderer->target->w;
BackBufferHeight = renderer->target->h;
} else {
BackBufferWidth = data->pparams.BackBufferWidth;
BackBufferHeight = data->pparams.BackBufferHeight;
}
/* Don't reset the viewport if we don't have to! */
if (!renderer->viewport.x && !renderer->viewport.y &&
renderer->viewport.w == data->pparams.BackBufferWidth &&
renderer->viewport.h == data->pparams.BackBufferHeight) {
renderer->viewport.w == BackBufferWidth &&
renderer->viewport.h == BackBufferHeight) {
result = IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);
} else {
D3DVIEWPORT9 viewport;
@@ -1191,8 +1243,8 @@ D3D_RenderClear(SDL_Renderer * renderer)
/* Clear is defined to clear the entire render target */
viewport.X = 0;
viewport.Y = 0;
viewport.Width = data->pparams.BackBufferWidth;
viewport.Height = data->pparams.BackBufferHeight;
viewport.Width = BackBufferWidth;
viewport.Height = BackBufferHeight;
viewport.MinZ = 0.0f;
viewport.MaxZ = 1.0f;
IDirect3DDevice9_SetViewport(data->device, &viewport);
@@ -1803,9 +1855,7 @@ D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
if (data->vtexture) {
IDirect3DTexture9_Release(data->vtexture);
}
if (data->pixels) {
SDL_free(data->pixels);
}
SDL_free(data->pixels);
SDL_free(data);
texture->driverdata = NULL;
}
@@ -1825,7 +1875,9 @@ D3D_DestroyRenderer(SDL_Renderer * renderer)
IDirect3DSurface9_Release(data->currentRenderTarget);
data->currentRenderTarget = NULL;
}
if (data->ps_yuv) {
IDirect3DPixelShader9_Release(data->ps_yuv);
}
if (data->device) {
IDirect3DDevice9_Release(data->device);
}
@@ -1839,6 +1891,25 @@ D3D_DestroyRenderer(SDL_Renderer * renderer)
SDL_free(renderer);
}
IDirect3DDevice9 *
SDL_RenderGetD3D9Device(SDL_Renderer * renderer)
{
D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
IDirect3DDevice9 *device;
// Make sure that this is a D3D renderer
if (renderer->DestroyRenderer != D3D_DestroyRenderer) {
SDL_SetError("Renderer is not a D3D renderer");
return NULL;
}
device = data->device;
if (device) {
IDirect3DDevice9_AddRef( device );
}
return device;
}
#endif /* SDL_VIDEO_RENDER_D3D && !SDL_RENDER_DISABLED */
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -89,8 +89,8 @@ SDL_PROC_UNUSED(void, glDepthFunc, (GLenum func))
SDL_PROC_UNUSED(void, glDepthMask, (GLboolean flag))
SDL_PROC_UNUSED(void, glDepthRange, (GLclampd zNear, GLclampd zFar))
SDL_PROC(void, glDisable, (GLenum cap))
SDL_PROC_UNUSED(void, glDisableClientState, (GLenum array))
SDL_PROC_UNUSED(void, glDrawArrays, (GLenum mode, GLint first, GLsizei count))
SDL_PROC(void, glDisableClientState, (GLenum array))
SDL_PROC(void, glDrawArrays, (GLenum mode, GLint first, GLsizei count))
SDL_PROC_UNUSED(void, glDrawBuffer, (GLenum mode))
SDL_PROC_UNUSED(void, glDrawElements,
(GLenum mode, GLsizei count, GLenum type,
@@ -103,7 +103,7 @@ SDL_PROC_UNUSED(void, glEdgeFlagPointer,
(GLsizei stride, const GLvoid * pointer))
SDL_PROC_UNUSED(void, glEdgeFlagv, (const GLboolean * flag))
SDL_PROC(void, glEnable, (GLenum cap))
SDL_PROC_UNUSED(void, glEnableClientState, (GLenum array))
SDL_PROC(void, glEnableClientState, (GLenum array))
SDL_PROC(void, glEnd, (void))
SDL_PROC_UNUSED(void, glEndList, (void))
SDL_PROC_UNUSED(void, glEvalCoord1d, (GLdouble u))
@@ -448,7 +448,7 @@ SDL_PROC_UNUSED(void, glVertex4iv, (const GLint * v))
SDL_PROC_UNUSED(void, glVertex4s,
(GLshort x, GLshort y, GLshort z, GLshort w))
SDL_PROC_UNUSED(void, glVertex4sv, (const GLshort * v))
SDL_PROC_UNUSED(void, glVertexPointer,
SDL_PROC(void, glVertexPointer,
(GLint size, GLenum type, GLsizei stride,
const GLvoid * pointer))
SDL_PROC(void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height))

View File

@@ -47,10 +47,16 @@ static const float inv255f = 1.0f / 255.0f;
static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags);
static void GL_WindowEvent(SDL_Renderer * renderer,
const SDL_WindowEvent *event);
static int GL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h);
static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels,
int pitch);
static int GL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch);
static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, void **pixels, int *pitch);
static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
@@ -310,7 +316,7 @@ GL_ResetState(SDL_Renderer *renderer)
data->glDisable(GL_DEPTH_TEST);
data->glDisable(GL_CULL_FACE);
/* This ended up causing video discrepancies between OpenGL and Direct3D */
/*data->glEnable(GL_LINE_SMOOTH);*/
/* data->glEnable(GL_LINE_SMOOTH); */
data->glMatrixMode(GL_MODELVIEW);
data->glLoadIdentity();
@@ -399,8 +405,10 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
}
renderer->WindowEvent = GL_WindowEvent;
renderer->GetOutputSize = GL_GetOutputSize;
renderer->CreateTexture = GL_CreateTexture;
renderer->UpdateTexture = GL_UpdateTexture;
renderer->UpdateTextureYUV = GL_UpdateTextureYUV;
renderer->LockTexture = GL_LockTexture;
renderer->UnlockTexture = GL_UnlockTexture;
renderer->SetRenderTarget = GL_SetRenderTarget;
@@ -506,6 +514,10 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_IYUV;
}
#ifdef __MACOSX__
renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_UYVY;
#endif
if (SDL_GL_ExtensionSupported("GL_EXT_framebuffer_object")) {
data->GL_EXT_framebuffer_object_supported = SDL_TRUE;
data->glGenFramebuffersEXT = (PFNGLGENFRAMEBUFFERSEXTPROC)
@@ -539,6 +551,14 @@ GL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
}
}
static int
GL_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
{
SDL_GL_GetDrawableSize(renderer->window, w, h);
return 0;
}
SDL_FORCE_INLINE int
power_of_2(int input)
{
@@ -566,6 +586,13 @@ convert_format(GL_RenderData *renderdata, Uint32 pixel_format,
*format = GL_LUMINANCE;
*type = GL_UNSIGNED_BYTE;
break;
#ifdef __MACOSX__
case SDL_PIXELFORMAT_UYVY:
*internalFormat = GL_RGB8;
*format = GL_YCBCR_422_APPLE;
*type = GL_UNSIGNED_SHORT_8_8_APPLE;
break;
#endif
default:
return SDL_FALSE;
}
@@ -623,8 +650,6 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
}
}
texture->driverdata = data;
if (texture->access == SDL_TEXTUREACCESS_TARGET) {
data->fbo = GL_GetFBO(renderdata, texture->w, texture->h);
} else {
@@ -637,8 +662,10 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
SDL_free(data);
return -1;
}
texture->driverdata = data;
if ((renderdata->GL_ARB_texture_rectangle_supported)
/*&& texture->access != SDL_TEXTUREACCESS_TARGET*/){
/* && texture->access != SDL_TEXTUREACCESS_TARGET */){
data->type = GL_TEXTURE_RECTANGLE_ARB;
texture_w = texture->w;
texture_h = texture->h;
@@ -788,6 +815,43 @@ GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
data->format, data->formattype, pixels);
}
renderdata->glDisable(data->type);
return GL_CheckError("glTexSubImage2D()", renderer);
}
static int
GL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect,
const Uint8 *Yplane, int Ypitch,
const Uint8 *Uplane, int Upitch,
const Uint8 *Vplane, int Vpitch)
{
GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
GL_ActivateRenderer(renderer);
renderdata->glEnable(data->type);
renderdata->glBindTexture(data->type, data->texture);
renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Ypitch);
renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
rect->h, data->format, data->formattype,
Yplane);
renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Upitch);
renderdata->glBindTexture(data->type, data->utexture);
renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2,
rect->w/2, rect->h/2,
data->format, data->formattype, Uplane);
renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH, Vpitch);
renderdata->glBindTexture(data->type, data->vtexture);
renderdata->glTexSubImage2D(data->type, 0, rect->x/2, rect->y/2,
rect->w/2, rect->h/2,
data->format, data->formattype, Vplane);
renderdata->glDisable(data->type);
return GL_CheckError("glTexSubImage2D()", renderer);
}
@@ -984,15 +1048,17 @@ GL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_FPoint * points,
int count)
{
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
int i;
GL_SetDrawingState(renderer);
data->glBegin(GL_POINTS);
for (i = 0; i < count; ++i) {
data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
}
data->glEnd();
data->glTranslatef(0.5f, 0.5f, 0.0f);
data->glVertexPointer(2, GL_FLOAT, 0, points);
data->glEnableClientState(GL_VERTEX_ARRAY);
data->glDrawArrays(GL_POINTS, 0, count);
data->glDisableClientState(GL_VERTEX_ARRAY);
data->glTranslatef(-0.5f, -0.5f, 0.0f);
return 0;
}
@@ -1002,61 +1068,28 @@ GL_RenderDrawLines(SDL_Renderer * renderer, const SDL_FPoint * points,
int count)
{
GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
int i;
GL_SetDrawingState(renderer);
data->glTranslatef(0.5f, 0.5f, 0.0f);
data->glVertexPointer(2, GL_FLOAT, 0, points);
data->glEnableClientState(GL_VERTEX_ARRAY);
if (count > 2 &&
points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
data->glBegin(GL_LINE_LOOP);
/* GL_LINE_LOOP takes care of the final segment */
--count;
for (i = 0; i < count; ++i) {
data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
}
data->glEnd();
data->glDrawArrays(GL_LINE_LOOP, 0, count-1);
} else {
#if defined(__APPLE__) || defined(__WIN32__)
#else
int x1, y1, x2, y2;
#endif
data->glBegin(GL_LINE_STRIP);
for (i = 0; i < count; ++i) {
data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
}
data->glEnd();
/* The line is half open, so we need one more point to complete it.
* http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html
* If we have to, we can use vertical line and horizontal line textures
* for vertical and horizontal lines, and then create custom textures
* for diagonal lines and software render those. It's terrible, but at
* least it would be pixel perfect.
*/
data->glBegin(GL_POINTS);
#if defined(__APPLE__) || defined(__WIN32__)
/* Mac OS X and Windows seem to always leave the second point open */
data->glVertex2f(0.5f + points[count-1].x, 0.5f + points[count-1].y);
#else
/* Linux seems to leave the right-most or bottom-most point open */
x1 = points[0].x;
y1 = points[0].y;
x2 = points[count-1].x;
y2 = points[count-1].y;
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);
}
#endif
data->glEnd();
data->glDrawArrays(GL_LINE_STRIP, 0, count);
}
/* Make sure all the line endpoints are closed.
* http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html
* Which points need to be drawn varies by driver, so just draw all of them.
*/
data->glDrawArrays(GL_POINTS, 0, count);
data->glDisableClientState(GL_VERTEX_ARRAY);
data->glTranslatef(-0.5f, -0.5f, 0.0f);
return GL_CheckError("", renderer);
}
@@ -1267,7 +1300,9 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
format, type, temp_pixels);
GL_CheckError("", renderer);
if (GL_CheckError("glReadPixels()", renderer) < 0) {
return -1;
}
/* Flip the rows to be top-down */
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
@@ -1318,9 +1353,7 @@ GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
renderdata->glDeleteTextures(1, &data->utexture);
renderdata->glDeleteTextures(1, &data->vtexture);
}
if (data->pixels) {
SDL_free(data->pixels);
}
SDL_free(data->pixels);
SDL_free(data);
texture->driverdata = NULL;
}

View File

@@ -30,7 +30,7 @@
/* OpenGL shader implementation */
/*#define DEBUG_SHADERS*/
/* #define DEBUG_SHADERS */
typedef struct
{

View File

@@ -1,6 +1,6 @@
SDL_PROC(void, glBindTexture, (GLenum, GLuint))
SDL_PROC(void, glBlendFunc, (GLenum, GLenum))
SDL_PROC(void, glBlendFuncSeparateOES, (GLenum, GLenum, GLenum, GLenum))
SDL_PROC_OES(void, glBlendFuncSeparateOES, (GLenum, GLenum, GLenum, GLenum))
SDL_PROC(void, glClear, (GLbitfield))
SDL_PROC(void, glClearColor, (GLclampf, GLclampf, GLclampf, GLclampf))
SDL_PROC(void, glColor4f, (GLfloat, GLfloat, GLfloat, GLfloat))
@@ -8,11 +8,11 @@ SDL_PROC(void, glDeleteTextures, (GLsizei, const GLuint *))
SDL_PROC(void, glDisable, (GLenum))
SDL_PROC(void, glDisableClientState, (GLenum array))
SDL_PROC(void, glDrawArrays, (GLenum, GLint, GLsizei))
SDL_PROC(void, glDrawTexfOES, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat))
SDL_PROC_OES(void, glDrawTexfOES, (GLfloat, GLfloat, GLfloat, GLfloat, GLfloat))
SDL_PROC(void, glEnable, (GLenum))
SDL_PROC(void, glEnableClientState, (GLenum))
SDL_PROC(void, glFinish, (void))
SDL_PROC(void, glGenFramebuffersOES, (GLsizei, GLuint *))
SDL_PROC_OES(void, glGenFramebuffersOES, (GLsizei, GLuint *))
SDL_PROC(void, glGenTextures, (GLsizei, GLuint *))
SDL_PROC(GLenum, glGetError, (void))
SDL_PROC(void, glGetIntegerv, (GLenum, GLint *))
@@ -30,13 +30,13 @@ SDL_PROC(void, glTexParameteriv, (GLenum, GLenum, const GLint *))
SDL_PROC(void, glTexSubImage2D, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, const GLvoid *))
SDL_PROC(void, glVertexPointer, (GLint, GLenum, GLsizei, const GLvoid *))
SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei))
SDL_PROC(void, glBindFramebufferOES, (GLenum, GLuint))
SDL_PROC(void, glFramebufferTexture2DOES, (GLenum, GLenum, GLenum, GLuint, GLint))
SDL_PROC(GLenum, glCheckFramebufferStatusOES, (GLenum))
SDL_PROC_OES(void, glBindFramebufferOES, (GLenum, GLuint))
SDL_PROC_OES(void, glFramebufferTexture2DOES, (GLenum, GLenum, GLenum, GLuint, GLint))
SDL_PROC_OES(GLenum, glCheckFramebufferStatusOES, (GLenum))
SDL_PROC(void, glPushMatrix, (void))
SDL_PROC(void, glTranslatef, (GLfloat, GLfloat, GLfloat))
SDL_PROC(void, glRotatef, (GLfloat, GLfloat, GLfloat, GLfloat))
SDL_PROC(void, glPopMatrix, (void))
SDL_PROC(void, glDeleteFramebuffersOES, (GLsizei, const GLuint*))
SDL_PROC_OES(void, glDeleteFramebuffersOES, (GLsizei, const GLuint*))
/* vi: set ts=4 sw=4 expandtab: */

View File

@@ -96,7 +96,7 @@ SDL_RenderDriver GLES_RenderDriver = {
GLES_CreateRenderer,
{
"opengles",
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE),
(SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC ),
1,
{SDL_PIXELFORMAT_ABGR8888},
0,
@@ -113,8 +113,10 @@ typedef struct
} current;
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
#define SDL_PROC_OES SDL_PROC
#include "SDL_glesfuncs.h"
#undef SDL_PROC
#undef SDL_PROC_OES
SDL_bool GL_OES_framebuffer_object_supported;
GLES_FBOList *framebuffers;
GLuint window_framebuffer;
@@ -183,6 +185,7 @@ static int GLES_LoadFunctions(GLES_RenderData * data)
#ifdef __SDL_NOGETPROCADDR__
#define SDL_PROC(ret,func,params) data->func=func;
#define SDL_PROC_OES(ret,func,params) data->func=func;
#else
#define SDL_PROC(ret,func,params) \
do { \
@@ -191,10 +194,15 @@ static int GLES_LoadFunctions(GLES_RenderData * data)
return SDL_SetError("Couldn't load GLES function %s: %s\n", #func, SDL_GetError()); \
} \
} while ( 0 );
#define SDL_PROC_OES(ret,func,params) \
do { \
data->func = SDL_GL_GetProcAddress(#func); \
} while ( 0 );
#endif /* _SDL_NOGETPROCADDR_ */
#include "SDL_glesfuncs.h"
#undef SDL_PROC
#undef SDL_PROC_OES
return 0;
}
@@ -272,7 +280,7 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
GLint value;
Uint32 windowFlags;
SDL_GL_SetAttribute(SDL_GL_CONTEXT_EGL, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
@@ -367,7 +375,8 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
renderer->info.max_texture_height = value;
if (SDL_GL_ExtensionSupported("GL_OES_framebuffer_object")) {
/* Android does not report GL_OES_framebuffer_object but the functionality seems to be there anyway */
if (SDL_GL_ExtensionSupported("GL_OES_framebuffer_object") || data->glGenFramebuffersOES) {
data->GL_OES_framebuffer_object_supported = SDL_TRUE;
renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE;
@@ -405,7 +414,7 @@ GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
}
}
static __inline__ int
static SDL_INLINE int
power_of_2(int input)
{
int value = 1;
@@ -465,12 +474,17 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
}
}
texture->driverdata = data;
if (texture->access == SDL_TEXTUREACCESS_TARGET) {
data->fbo = GLES_GetFBO(renderer->driverdata, texture->w, texture->h);
if (!renderdata->GL_OES_framebuffer_object_supported) {
SDL_free(data);
return SDL_SetError("GL_OES_framebuffer_object not supported");
}
data->fbo = GLES_GetFBO(renderer->driverdata, texture->w, texture->h);
} else {
data->fbo = NULL;
data->fbo = NULL;
}
renderdata->glGetError();
renderdata->glEnable(GL_TEXTURE_2D);
@@ -503,8 +517,11 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
result = renderdata->glGetError();
if (result != GL_NO_ERROR) {
SDL_free(data);
return GLES_SetError("glTexImage2D()", result);
}
texture->driverdata = data;
return 0;
}
@@ -556,9 +573,7 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
data->format,
data->formattype,
src);
if (blob) {
SDL_free(blob);
}
SDL_free(blob);
if (renderdata->glGetError() != GL_NO_ERROR)
{
@@ -602,6 +617,10 @@ GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
GLenum status;
GLES_ActivateRenderer(renderer);
if (!data->GL_OES_framebuffer_object_supported) {
return SDL_SetError("Can't enable render target support in this renderer");
}
if (texture == NULL) {
data->glBindFramebufferOES(GL_FRAMEBUFFER_OES, data->window_framebuffer);
@@ -843,6 +862,8 @@ GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
GLfloat minx, miny, maxx, maxy;
GLfloat minu, maxu, minv, maxv;
GLfloat vertices[8];
GLfloat texCoords[8];
GLES_ActivateRenderer(renderer);
@@ -903,9 +924,6 @@ GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
maxv *= texturedata->texh;
GLfloat vertices[8];
GLfloat texCoords[8];
vertices[0] = minx;
vertices[1] = miny;
vertices[2] = maxx;
@@ -944,6 +962,9 @@ GLES_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
GLfloat minx, miny, maxx, maxy;
GLfloat minu, maxu, minv, maxv;
GLfloat centerx, centery;
GLfloat vertices[8];
GLfloat texCoords[8];
GLES_ActivateRenderer(renderer);
@@ -994,9 +1015,6 @@ GLES_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
maxv *= texturedata->texh;
GLfloat vertices[8];
GLfloat texCoords[8];
vertices[0] = minx;
vertices[1] = miny;
vertices[2] = maxx;
@@ -1096,9 +1114,7 @@ GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
if (data->texture) {
renderdata->glDeleteTextures(1, &data->texture);
}
if (data->pixels) {
SDL_free(data->pixels);
}
SDL_free(data->pixels);
SDL_free(data);
texture->driverdata = NULL;
}

File diff suppressed because it is too large Load Diff

View File

@@ -458,7 +458,7 @@ PSP_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
static int
PSP_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
{
// PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata;
/* PSP_RenderData *renderdata = (PSP_RenderData *) renderer->driverdata; */
PSP_TextureData* psp_texture = (PSP_TextureData*) SDL_calloc(1, sizeof(*psp_texture));;
if(!psp_texture)
@@ -528,7 +528,7 @@ static int
PSP_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
const SDL_Rect * rect, const void *pixels, int pitch)
{
// PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata;
/* PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; */
const Uint8 *src;
Uint8 *dst;
int row, length,dpitch;
@@ -895,8 +895,8 @@ PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
sceGuColor(0xFFFFFFFF);
}
// x += width * 0.5f;
// y += height * 0.5f;
/* x += width * 0.5f; */
/* y += height * 0.5f; */
x += centerx;
y += centery;
@@ -904,8 +904,8 @@ PSP_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
MathSincos(degToRad(angle), &s, &c);
// width *= 0.5f;
// height *= 0.5f;
/* width *= 0.5f; */
/* height *= 0.5f; */
width -= centerx;
height -= centery;
@@ -968,7 +968,7 @@ PSP_RenderPresent(SDL_Renderer * renderer)
sceGuFinish();
sceGuSync(0,0);
// if(data->vsync)
/* if(data->vsync) */
sceDisplayWaitVblankStart();
data->backbuffer = data->frontbuffer;
@@ -988,10 +988,7 @@ PSP_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
if(psp_texture == 0)
return;
if(psp_texture->data != 0)
{
SDL_free(psp_texture->data);
}
SDL_free(psp_texture->data);
SDL_free(psp_texture);
texture->driverdata = NULL;
}
@@ -1007,8 +1004,8 @@ PSP_DestroyRenderer(SDL_Renderer * renderer)
StartDrawing(renderer);
sceGuTerm();
// vfree(data->backbuffer);
// vfree(data->frontbuffer);
/* vfree(data->backbuffer); */
/* vfree(data->frontbuffer); */
data->initialized = SDL_FALSE;
data->displayListAvail = SDL_FALSE;

View File

@@ -609,8 +609,8 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture,
retval = SDL_BlitScaled(src, srcrect, surface_scaled, &tmp_rect);
if (!retval) {
_rotozoomSurfaceSizeTrig(tmp_rect.w, tmp_rect.h, -angle, &dstwidth, &dstheight, &cangle, &sangle);
surface_rotated = _rotateSurface(surface_scaled, -angle, dstwidth/2, dstheight/2, GetScaleQuality(), flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL, dstwidth, dstheight, cangle, sangle);
SDLgfx_rotozoomSurfaceSizeTrig(tmp_rect.w, tmp_rect.h, -angle, &dstwidth, &dstheight, &cangle, &sangle);
surface_rotated = SDLgfx_rotateSurface(surface_scaled, -angle, dstwidth/2, dstheight/2, GetScaleQuality(), flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL, dstwidth, dstheight, cangle, sangle);
if(surface_rotated) {
/* Find out where the new origin is by rotating the four final_rect points around the center and then taking the extremes */
abscenterx = final_rect.x + (int)center->x;
@@ -718,9 +718,7 @@ SW_DestroyRenderer(SDL_Renderer * renderer)
{
SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
if (data) {
SDL_free(data);
}
SDL_free(data);
SDL_free(renderer);
}

View File

@@ -30,8 +30,8 @@ Andreas Schiffler -- aschiffler at ferzkopp dot net
*/
#include "SDL_config.h"
#ifdef WIN32
#include <windows.h>
#if defined(__WIN32__)
#include "../../core/windows/SDL_windows.h"
#endif
#include <stdlib.h>
@@ -42,7 +42,7 @@ Andreas Schiffler -- aschiffler at ferzkopp dot net
/* ---- Internally used structures */
/*!
/* !
\brief A 32 bit RGBA pixel.
*/
typedef struct tColorRGBA {
@@ -52,19 +52,19 @@ typedef struct tColorRGBA {
Uint8 a;
} tColorRGBA;
/*!
/* !
\brief A 8bit Y/palette pixel.
*/
typedef struct tColorY {
Uint8 y;
} tColorY;
/*!
/* !
\brief Returns maximum of two numbers a and b.
*/
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
/*!
/* !
\brief Number of guard rows added to destination surfaces.
This is a simple but effective workaround for observed issues.
@@ -76,15 +76,16 @@ to a situation where the program can segfault.
*/
#define GUARD_ROWS (2)
/*!
/* !
\brief Lower limit of absolute zoom factor or rotation degrees.
*/
#define VALUE_LIMIT 0.001
/*!
/* !
\brief Returns colorkey info for a surface
*/
Uint32 _colorkey(SDL_Surface *src)
static Uint32
_colorkey(SDL_Surface *src)
{
Uint32 key = 0;
SDL_GetColorKey(src, &key);
@@ -92,7 +93,7 @@ Uint32 _colorkey(SDL_Surface *src)
}
/*!
/* !
\brief Internal target surface sizing function for rotations with trig result return.
\param width The source surface width.
@@ -104,9 +105,10 @@ Uint32 _colorkey(SDL_Surface *src)
\param sangle The cosine of the angle
*/
void _rotozoomSurfaceSizeTrig(int width, int height, double angle,
int *dstwidth, int *dstheight,
double *cangle, double *sangle)
void
SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle,
int *dstwidth, int *dstheight,
double *cangle, double *sangle)
{
double x, y, cx, cy, sx, sy;
double radangle;
@@ -134,7 +136,7 @@ void _rotozoomSurfaceSizeTrig(int width, int height, double angle,
}
/*!
/* !
\brief Internal 32 bit rotozoomer with optional anti-aliasing.
Rotates and zooms 32 bit RGBA/ABGR 'src' surface to 'dst' surface based on the control
@@ -153,7 +155,8 @@ Assumes dst surface was allocated with the correct dimensions.
\param flipy Flag indicating vertical mirroring should be applied.
\param smooth Flag indicating anti-aliasing should be used.
*/
void _transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth)
static void
_transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth)
{
int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh;
tColorRGBA c00, c01, c10, c11, cswap;
@@ -252,7 +255,7 @@ void _transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy,
}
}
/*!
/* !
\brief Rotates and zooms 8 bit palette/Y 'src' surface to 'dst' surface without smoothing.
@@ -270,7 +273,8 @@ Assumes dst surface was allocated with the correct dimensions.
\param flipx Flag indicating horizontal mirroring should be applied.
\param flipy Flag indicating vertical mirroring should be applied.
*/
void transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy)
static void
transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy)
{
int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay;
tColorY *pc, *sp;
@@ -315,9 +319,7 @@ void transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int
}
/*!
/* !
\brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing.
Rotates a 32bit or 8bit 'src' surface to newly created 'dst' surface.
@@ -340,7 +342,8 @@ or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly.
*/
SDL_Surface *_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle)
SDL_Surface *
SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle)
{
SDL_Surface *rz_src;
SDL_Surface *rz_dst;
@@ -357,7 +360,7 @@ SDL_Surface *_rotateSurface(SDL_Surface * src, double angle, int centerx, int ce
if (src == NULL)
return (NULL);
if (src->flags & SDL_TRUE/*SDL_SRCCOLORKEY*/)
if (src->flags & SDL_TRUE/* SDL_SRCCOLORKEY */)
{
colorkey = _colorkey(src);
SDL_GetRGB(colorkey, src->format, &r, &g, &b);
@@ -391,14 +394,14 @@ SDL_Surface *_rotateSurface(SDL_Surface * src, double angle, int centerx, int ce
SDL_BlitSurface(src, NULL, rz_src, NULL);
if(colorKeyAvailable)
SDL_SetColorKey(src, SDL_TRUE /*SDL_SRCCOLORKEY*/, colorkey);
SDL_SetColorKey(src, SDL_TRUE /* SDL_SRCCOLORKEY */, colorkey);
src_converted = 1;
is32bit = 1;
}
/* Determine target size */
/*_rotozoomSurfaceSizeTrig(rz_src->w, rz_src->h, angle, &dstwidth, &dstheight, &cangle, &sangle); */
/* _rotozoomSurfaceSizeTrig(rz_src->w, rz_src->h, angle, &dstwidth, &dstheight, &cangle, &sangle); */
/*
* Calculate target factors from sin/cos and zoom
@@ -459,8 +462,8 @@ SDL_Surface *_rotateSurface(SDL_Surface * src, double angle, int centerx, int ce
/*
* Turn on source-alpha support
*/
/*SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255);*/
SDL_SetColorKey(rz_dst, /*SDL_SRCCOLORKEY*/ SDL_TRUE | SDL_RLEACCEL, _colorkey(rz_src));
/* SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); */
SDL_SetColorKey(rz_dst, /* SDL_SRCCOLORKEY */ SDL_TRUE | SDL_RLEACCEL, _colorkey(rz_src));
} else {
/*
* Copy palette and colorkey info
@@ -475,7 +478,7 @@ SDL_Surface *_rotateSurface(SDL_Surface * src, double angle, int centerx, int ce
transformSurfaceY(rz_src, rz_dst, centerx, centery,
(int) (sangleinv), (int) (cangleinv),
flipx, flipy);
SDL_SetColorKey(rz_dst, /*SDL_SRCCOLORKEY*/ SDL_TRUE | SDL_RLEACCEL, _colorkey(rz_src));
SDL_SetColorKey(rz_dst, /* SDL_SRCCOLORKEY */ SDL_TRUE | SDL_RLEACCEL, _colorkey(rz_src));
}
/*
* Unlock source surface
@@ -496,4 +499,3 @@ SDL_Surface *_rotateSurface(SDL_Surface * src, double angle, int centerx, int ce
*/
return (rz_dst);
}

View File

@@ -2,6 +2,6 @@
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
extern SDL_Surface *_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle);
extern void _rotozoomSurfaceSizeTrig(int width, int height, double angle, int *dstwidth, int *dstheight, double *cangle, double *sangle);
extern SDL_Surface *SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle);
extern void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, int *dstwidth, int *dstheight, double *cangle, double *sangle);