mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-13 23:54:35 +00:00
update sdl to https://github.com/libsdl-org/SDL 22March 2022
This commit is contained in:
parent
ee4253c982
commit
2614274639
1225 changed files with 148950 additions and 51674 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -43,7 +43,7 @@ struct SDL_Texture
|
|||
int modMode; /**< The texture modulation mode */
|
||||
SDL_BlendMode blendMode; /**< The texture blend mode */
|
||||
SDL_ScaleMode scaleMode; /**< The texture scale mode */
|
||||
Uint8 r, g, b, a; /**< Texture modulation values */
|
||||
SDL_Color color; /**< Texture modulation values */
|
||||
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
|
|
@ -58,6 +58,7 @@ struct SDL_Texture
|
|||
Uint32 last_command_generation; /* last command queue generation this texture was in. */
|
||||
|
||||
void *driverdata; /**< Driver specific texture representation */
|
||||
void *userdata;
|
||||
|
||||
SDL_Texture *prev;
|
||||
SDL_Texture *next;
|
||||
|
|
@ -74,7 +75,8 @@ typedef enum
|
|||
SDL_RENDERCMD_DRAW_LINES,
|
||||
SDL_RENDERCMD_FILL_RECTS,
|
||||
SDL_RENDERCMD_COPY,
|
||||
SDL_RENDERCMD_COPY_EX
|
||||
SDL_RENDERCMD_COPY_EX,
|
||||
SDL_RENDERCMD_GEOMETRY
|
||||
} SDL_RenderCommandType;
|
||||
|
||||
typedef struct SDL_RenderCommand
|
||||
|
|
@ -105,6 +107,21 @@ typedef struct SDL_RenderCommand
|
|||
} SDL_RenderCommand;
|
||||
|
||||
|
||||
typedef struct SDL_VertexSolid
|
||||
{
|
||||
SDL_FPoint position;
|
||||
SDL_Color color;
|
||||
} SDL_VertexSolid;
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SDL_RENDERLINEMETHOD_POINTS,
|
||||
SDL_RENDERLINEMETHOD_LINES,
|
||||
SDL_RENDERLINEMETHOD_GEOMETRY,
|
||||
} SDL_RenderLineMethod;
|
||||
|
||||
|
||||
/* Define the SDL renderer structure */
|
||||
struct SDL_Renderer
|
||||
{
|
||||
|
|
@ -126,16 +143,27 @@ struct SDL_Renderer
|
|||
const SDL_Rect * srcrect, const SDL_FRect * dstrect);
|
||||
int (*QueueCopyEx) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
|
||||
const SDL_Rect * srcquad, const SDL_FRect * dstrect,
|
||||
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip);
|
||||
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip, float scale_x, float scale_y);
|
||||
int (*QueueGeometry) (SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
|
||||
int num_vertices, const void *indices, int num_indices, int size_indices,
|
||||
float scale_x, float scale_y);
|
||||
|
||||
int (*RunCommandQueue) (SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize);
|
||||
int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect, const void *pixels,
|
||||
int pitch);
|
||||
#if SDL_HAVE_YUV
|
||||
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 (*UpdateTextureNV) (SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect,
|
||||
const Uint8 *Yplane, int Ypitch,
|
||||
const Uint8 *UVplane, int UVpitch);
|
||||
#endif
|
||||
int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect, void **pixels, int *pitch);
|
||||
void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
|
||||
|
|
@ -148,6 +176,8 @@ struct SDL_Renderer
|
|||
|
||||
void (*DestroyRenderer) (SDL_Renderer * renderer);
|
||||
|
||||
int (*SetVSync) (SDL_Renderer * renderer, int vsync);
|
||||
|
||||
int (*GL_BindTexture) (SDL_Renderer * renderer, SDL_Texture *texture, float *texw, float *texh);
|
||||
int (*GL_UnbindTexture) (SDL_Renderer * renderer, SDL_Texture *texture);
|
||||
|
||||
|
|
@ -171,12 +201,12 @@ struct SDL_Renderer
|
|||
SDL_bool integer_scale;
|
||||
|
||||
/* The drawable area within the window */
|
||||
SDL_Rect viewport;
|
||||
SDL_Rect viewport_backup;
|
||||
SDL_FRect viewport;
|
||||
SDL_FRect viewport_backup;
|
||||
|
||||
/* The clip rectangle within the window */
|
||||
SDL_Rect clip_rect;
|
||||
SDL_Rect clip_rect_backup;
|
||||
SDL_FRect clip_rect;
|
||||
SDL_FRect clip_rect_backup;
|
||||
|
||||
/* Wether or not the clipping rectangle is used. */
|
||||
SDL_bool clipping_enabled;
|
||||
|
|
@ -192,6 +222,9 @@ struct SDL_Renderer
|
|||
/* Whether or not to scale relative mouse motion */
|
||||
SDL_bool relative_scaling;
|
||||
|
||||
/* The method of drawing lines */
|
||||
SDL_RenderLineMethod line_method;
|
||||
|
||||
/* Remainder from scaled relative motion */
|
||||
float xrel;
|
||||
float yrel;
|
||||
|
|
@ -201,7 +234,7 @@ struct SDL_Renderer
|
|||
SDL_Texture *target;
|
||||
SDL_mutex *target_mutex;
|
||||
|
||||
Uint8 r, g, b, a; /**< Color for drawing operations values */
|
||||
SDL_Color color; /**< Color for drawing operations values */
|
||||
SDL_BlendMode blendMode; /**< The drawing blend mode */
|
||||
|
||||
SDL_bool always_batch;
|
||||
|
|
@ -211,8 +244,8 @@ struct SDL_Renderer
|
|||
SDL_RenderCommand *render_commands_pool;
|
||||
Uint32 render_command_generation;
|
||||
Uint32 last_queued_color;
|
||||
SDL_Rect last_queued_viewport;
|
||||
SDL_Rect last_queued_cliprect;
|
||||
SDL_FRect last_queued_viewport;
|
||||
SDL_FRect last_queued_cliprect;
|
||||
SDL_bool last_queued_cliprect_enabled;
|
||||
SDL_bool color_queued;
|
||||
SDL_bool viewport_queued;
|
||||
|
|
@ -244,6 +277,7 @@ extern SDL_RenderDriver DirectFB_RenderDriver;
|
|||
extern SDL_RenderDriver METAL_RenderDriver;
|
||||
extern SDL_RenderDriver PSP_RenderDriver;
|
||||
extern SDL_RenderDriver SW_RenderDriver;
|
||||
extern SDL_RenderDriver VITA_GXM_RenderDriver;
|
||||
|
||||
/* Blend mode functions */
|
||||
extern SDL_BlendFactor SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode);
|
||||
|
|
@ -258,6 +292,9 @@ extern SDL_BlendOperation SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode
|
|||
the next call, because it might be in an array that gets realloc()'d. */
|
||||
extern void *SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset);
|
||||
|
||||
extern int SDL_PrivateLowerBlitScaled(SDL_Surface * src, SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect, SDL_ScaleMode scaleMode);
|
||||
extern int SDL_PrivateUpperBlitScaled(SDL_Surface * src, const SDL_Rect * srcrect, SDL_Surface * dst, SDL_Rect * dstrect, SDL_ScaleMode scaleMode);
|
||||
|
||||
#endif /* SDL_sysrender_h_ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
|
||||
#include "SDL_yuv_sw_c.h"
|
||||
#include "SDL_cpuinfo.h"
|
||||
|
||||
|
||||
SDL_SW_YUVTexture *
|
||||
|
|
@ -84,7 +85,7 @@ SDL_SW_CreateYUVTexture(Uint32 format, int w, int h)
|
|||
SDL_assert(0 && "We should never get here (caught above)");
|
||||
break;
|
||||
}
|
||||
swdata->pixels = (Uint8 *) SDL_malloc(dst_size);
|
||||
swdata->pixels = (Uint8 *) SDL_SIMDAlloc(dst_size);
|
||||
if (!swdata->pixels) {
|
||||
SDL_SW_DestroyYUVTexture(swdata);
|
||||
SDL_OutOfMemory();
|
||||
|
|
@ -299,6 +300,40 @@ SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int SDL_SW_UpdateNVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
|
||||
const Uint8 *Yplane, int Ypitch,
|
||||
const Uint8 *UVplane, int UVpitch)
|
||||
{
|
||||
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 UV or VU plane */
|
||||
src = UVplane;
|
||||
dst = swdata->pixels + swdata->h * swdata->w;
|
||||
dst += rect->y * ((swdata->w + 1)/2) + rect->x;
|
||||
length = (rect->w + 1) / 2;
|
||||
length *= 2;
|
||||
for (row = 0; row < (rect->h + 1)/2; ++row) {
|
||||
SDL_memcpy(dst, src, length);
|
||||
src += UVpitch;
|
||||
dst += 2 * ((swdata->w + 1)/2);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
|
||||
void **pixels, int *pitch)
|
||||
|
|
@ -405,7 +440,7 @@ void
|
|||
SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata)
|
||||
{
|
||||
if (swdata) {
|
||||
SDL_free(swdata->pixels);
|
||||
SDL_SIMDFree(swdata->pixels);
|
||||
SDL_FreeSurface(swdata->stretch);
|
||||
SDL_FreeSurface(swdata->display);
|
||||
SDL_free(swdata);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -55,6 +55,9 @@ int SDL_SW_UpdateYUVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * r
|
|||
const Uint8 *Yplane, int Ypitch,
|
||||
const Uint8 *Uplane, int Upitch,
|
||||
const Uint8 *Vplane, int Vpitch);
|
||||
int SDL_SW_UpdateNVTexturePlanar(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
|
||||
const Uint8 *Yplane, int Ypitch,
|
||||
const Uint8 *UVplane, int UVpitch);
|
||||
int SDL_SW_LockYUVTexture(SDL_SW_YUVTexture * swdata, const SDL_Rect * rect,
|
||||
void **pixels, int *pitch);
|
||||
void SDL_SW_UnlockYUVTexture(SDL_SW_YUVTexture * swdata);
|
||||
|
|
@ -63,11 +66,6 @@ int SDL_SW_CopyYUVToRGB(SDL_SW_YUVTexture * swdata, const SDL_Rect * srcrect,
|
|||
int pitch);
|
||||
void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata);
|
||||
|
||||
/* FIXME: This breaks on various versions of GCC and should be rewritten using intrinsics */
|
||||
#if 0 /* (__GNUC__ > 2) && defined(__i386__) && __OPTIMIZE__ && SDL_ASSEMBLY_ROUTINES && !defined(__clang__) */
|
||||
#define USE_MMX_ASSEMBLY 1
|
||||
#endif
|
||||
|
||||
#endif /* SDL_yuv_sw_c_h_ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -51,7 +51,6 @@ typedef struct
|
|||
SDL_bool cliprect_enabled_dirty;
|
||||
SDL_Rect cliprect;
|
||||
SDL_bool cliprect_dirty;
|
||||
SDL_bool is_copy_ex;
|
||||
LPDIRECT3DPIXELSHADER9 shader;
|
||||
} D3D_DrawStateCache;
|
||||
|
||||
|
|
@ -72,7 +71,9 @@ typedef struct
|
|||
IDirect3DSurface9 *defaultRenderTarget;
|
||||
IDirect3DSurface9 *currentRenderTarget;
|
||||
void* d3dxDLL;
|
||||
#if SDL_HAVE_YUV
|
||||
LPDIRECT3DPIXELSHADER9 shaders[NUM_SHADERS];
|
||||
#endif
|
||||
LPDIRECT3DVERTEXBUFFER9 vertexBuffers[8];
|
||||
size_t vertexBufferSize[8];
|
||||
int currentVertexBuffer;
|
||||
|
|
@ -96,6 +97,7 @@ typedef struct
|
|||
D3D_TextureRep texture;
|
||||
D3DTEXTUREFILTERTYPE scaleMode;
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
/* YV12 texture support */
|
||||
SDL_bool yuv;
|
||||
D3D_TextureRep utexture;
|
||||
|
|
@ -103,6 +105,7 @@ typedef struct
|
|||
Uint8 *pixels;
|
||||
int pitch;
|
||||
SDL_Rect locked_rect;
|
||||
#endif
|
||||
} D3D_TextureData;
|
||||
|
||||
typedef struct
|
||||
|
|
@ -535,7 +538,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
if (D3D_CreateTextureRep(data->device, &texturedata->texture, usage, texture->format, PixelFormatToD3DFMT(texture->format), texture->w, texture->h) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texture->format == SDL_PIXELFORMAT_YV12 ||
|
||||
texture->format == SDL_PIXELFORMAT_IYUV) {
|
||||
texturedata->yuv = SDL_TRUE;
|
||||
|
|
@ -548,6 +551,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -564,7 +568,7 @@ D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
if (D3D_RecreateTextureRep(data->device, &texturedata->texture) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata->yuv) {
|
||||
if (D3D_RecreateTextureRep(data->device, &texturedata->utexture) < 0) {
|
||||
return -1;
|
||||
|
|
@ -574,6 +578,7 @@ D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -585,14 +590,13 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
|
||||
|
||||
if (!texturedata) {
|
||||
SDL_SetError("Texture is not currently available");
|
||||
return -1;
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
if (D3D_UpdateTextureRep(data->device, &texturedata->texture, rect->x, rect->y, rect->w, rect->h, pixels, pitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata->yuv) {
|
||||
/* Skip to the correct offset into the next texture */
|
||||
pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
|
||||
|
|
@ -607,9 +611,11 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
static int
|
||||
D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect,
|
||||
|
|
@ -621,8 +627,7 @@ D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
|
||||
|
||||
if (!texturedata) {
|
||||
SDL_SetError("Texture is not currently available");
|
||||
return -1;
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
if (D3D_UpdateTextureRep(data->device, &texturedata->texture, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
|
||||
|
|
@ -636,6 +641,7 @@ D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
|
|
@ -646,10 +652,9 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
IDirect3DDevice9 *device = data->device;
|
||||
|
||||
if (!texturedata) {
|
||||
SDL_SetError("Texture is not currently available");
|
||||
return -1;
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
texturedata->locked_rect = *rect;
|
||||
|
||||
if (texturedata->yuv) {
|
||||
|
|
@ -665,7 +670,9 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
(void *) ((Uint8 *) texturedata->pixels + rect->y * texturedata->pitch +
|
||||
rect->x * SDL_BYTESPERPIXEL(texture->format));
|
||||
*pitch = texturedata->pitch;
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
RECT d3drect;
|
||||
D3DLOCKED_RECT locked;
|
||||
HRESULT result;
|
||||
|
|
@ -698,14 +705,17 @@ D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
if (!texturedata) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata->yuv) {
|
||||
const SDL_Rect *rect = &texturedata->locked_rect;
|
||||
void *pixels =
|
||||
(void *) ((Uint8 *) texturedata->pixels + rect->y * texturedata->pitch +
|
||||
rect->x * SDL_BYTESPERPIXEL(texture->format));
|
||||
D3D_UpdateTexture(renderer, texture, rect, pixels, texturedata->pitch);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
IDirect3DTexture9_UnlockRect(texturedata->texture.staging, 0);
|
||||
texturedata->texture.dirty = SDL_TRUE;
|
||||
if (data->drawstate.texture == texture) {
|
||||
|
|
@ -713,10 +723,6 @@ D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
data->drawstate.shader = NULL;
|
||||
IDirect3DDevice9_SetPixelShader(data->device, NULL);
|
||||
IDirect3DDevice9_SetTexture(data->device, 0, NULL);
|
||||
if (texturedata->yuv) {
|
||||
IDirect3DDevice9_SetTexture(data->device, 1, NULL);
|
||||
IDirect3DDevice9_SetTexture(data->device, 2, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -755,8 +761,7 @@ D3D_SetRenderTargetInternal(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
|
||||
texturedata = (D3D_TextureData *)texture->driverdata;
|
||||
if (!texturedata) {
|
||||
SDL_SetError("Texture is not currently available");
|
||||
return -1;
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
/* Make sure the render target is updated if it was locked and written to */
|
||||
|
|
@ -831,190 +836,55 @@ D3D_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_F
|
|||
}
|
||||
|
||||
static int
|
||||
D3D_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
|
||||
D3D_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
|
||||
int num_vertices, const void *indices, int num_indices, int size_indices,
|
||||
float scale_x, float scale_y)
|
||||
{
|
||||
const DWORD color = D3DCOLOR_ARGB(cmd->data.draw.a, cmd->data.draw.r, cmd->data.draw.g, cmd->data.draw.b);
|
||||
const size_t vertslen = count * sizeof (Vertex) * 4;
|
||||
Vertex *verts = (Vertex *) SDL_AllocateRenderVertices(renderer, vertslen, 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
int count = indices ? num_indices : num_vertices;
|
||||
Vertex *verts = (Vertex *) SDL_AllocateRenderVertices(renderer, count * sizeof (Vertex), 0, &cmd->data.draw.first);
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_memset(verts, '\0', vertslen);
|
||||
cmd->data.draw.count = count;
|
||||
size_indices = indices ? size_indices : 0;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
const SDL_FRect *rect = &rects[i];
|
||||
const float minx = rect->x;
|
||||
const float maxx = rect->x + rect->w;
|
||||
const float miny = rect->y;
|
||||
const float maxy = rect->y + rect->h;
|
||||
int j;
|
||||
float *xy_;
|
||||
SDL_Color col_;
|
||||
if (size_indices == 4) {
|
||||
j = ((const Uint32 *)indices)[i];
|
||||
} else if (size_indices == 2) {
|
||||
j = ((const Uint16 *)indices)[i];
|
||||
} else if (size_indices == 1) {
|
||||
j = ((const Uint8 *)indices)[i];
|
||||
} else {
|
||||
j = i;
|
||||
}
|
||||
|
||||
verts->x = minx;
|
||||
verts->y = miny;
|
||||
verts->color = color;
|
||||
verts++;
|
||||
xy_ = (float *)((char*)xy + j * xy_stride);
|
||||
col_ = *(SDL_Color *)((char*)color + j * color_stride);
|
||||
|
||||
verts->x = maxx;
|
||||
verts->y = miny;
|
||||
verts->color = color;
|
||||
verts++;
|
||||
verts->x = xy_[0] * scale_x - 0.5f;
|
||||
verts->y = xy_[1] * scale_y - 0.5f;
|
||||
verts->z = 0.0f;
|
||||
verts->color = D3DCOLOR_ARGB(col_.a, col_.r, col_.g, col_.b);
|
||||
|
||||
verts->x = maxx;
|
||||
verts->y = maxy;
|
||||
verts->color = color;
|
||||
verts++;
|
||||
if (texture) {
|
||||
float *uv_ = (float *)((char*)uv + j * uv_stride);
|
||||
verts->u = uv_[0];
|
||||
verts->v = uv_[1];
|
||||
} else {
|
||||
verts->u = 0.0f;
|
||||
verts->v = 0.0f;
|
||||
}
|
||||
|
||||
verts->x = minx;
|
||||
verts->y = maxy;
|
||||
verts->color = color;
|
||||
verts++;
|
||||
verts += 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
D3D_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
|
||||
const SDL_Rect * srcrect, const SDL_FRect * dstrect)
|
||||
{
|
||||
const DWORD color = D3DCOLOR_ARGB(cmd->data.draw.a, cmd->data.draw.r, cmd->data.draw.g, cmd->data.draw.b);
|
||||
float minx, miny, maxx, maxy;
|
||||
float minu, maxu, minv, maxv;
|
||||
const size_t vertslen = sizeof (Vertex) * 4;
|
||||
Vertex *verts = (Vertex *) SDL_AllocateRenderVertices(renderer, vertslen, 0, &cmd->data.draw.first);
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = 1;
|
||||
|
||||
minx = dstrect->x - 0.5f;
|
||||
miny = dstrect->y - 0.5f;
|
||||
maxx = dstrect->x + dstrect->w - 0.5f;
|
||||
maxy = dstrect->y + dstrect->h - 0.5f;
|
||||
|
||||
minu = (float) srcrect->x / texture->w;
|
||||
maxu = (float) (srcrect->x + srcrect->w) / texture->w;
|
||||
minv = (float) srcrect->y / texture->h;
|
||||
maxv = (float) (srcrect->y + srcrect->h) / texture->h;
|
||||
|
||||
verts->x = minx;
|
||||
verts->y = miny;
|
||||
verts->z = 0.0f;
|
||||
verts->color = color;
|
||||
verts->u = minu;
|
||||
verts->v = minv;
|
||||
verts++;
|
||||
|
||||
verts->x = maxx;
|
||||
verts->y = miny;
|
||||
verts->z = 0.0f;
|
||||
verts->color = color;
|
||||
verts->u = maxu;
|
||||
verts->v = minv;
|
||||
verts++;
|
||||
|
||||
verts->x = maxx;
|
||||
verts->y = maxy;
|
||||
verts->z = 0.0f;
|
||||
verts->color = color;
|
||||
verts->u = maxu;
|
||||
verts->v = maxv;
|
||||
verts++;
|
||||
|
||||
verts->x = minx;
|
||||
verts->y = maxy;
|
||||
verts->z = 0.0f;
|
||||
verts->color = color;
|
||||
verts->u = minu;
|
||||
verts->v = maxv;
|
||||
verts++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
D3D_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
|
||||
const SDL_Rect * srcquad, const SDL_FRect * dstrect,
|
||||
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
|
||||
{
|
||||
const DWORD color = D3DCOLOR_ARGB(cmd->data.draw.a, cmd->data.draw.r, cmd->data.draw.g, cmd->data.draw.b);
|
||||
float minx, miny, maxx, maxy;
|
||||
float minu, maxu, minv, maxv;
|
||||
const size_t vertslen = sizeof (Vertex) * 5;
|
||||
Vertex *verts = (Vertex *) SDL_AllocateRenderVertices(renderer, vertslen, 0, &cmd->data.draw.first);
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = 1;
|
||||
|
||||
minx = -center->x;
|
||||
maxx = dstrect->w - center->x;
|
||||
miny = -center->y;
|
||||
maxy = dstrect->h - center->y;
|
||||
|
||||
if (flip & SDL_FLIP_HORIZONTAL) {
|
||||
minu = (float) (srcquad->x + srcquad->w) / texture->w;
|
||||
maxu = (float) srcquad->x / texture->w;
|
||||
} else {
|
||||
minu = (float) srcquad->x / texture->w;
|
||||
maxu = (float) (srcquad->x + srcquad->w) / texture->w;
|
||||
}
|
||||
|
||||
if (flip & SDL_FLIP_VERTICAL) {
|
||||
minv = (float) (srcquad->y + srcquad->h) / texture->h;
|
||||
maxv = (float) srcquad->y / texture->h;
|
||||
} else {
|
||||
minv = (float) srcquad->y / texture->h;
|
||||
maxv = (float) (srcquad->y + srcquad->h) / texture->h;
|
||||
}
|
||||
|
||||
verts->x = minx;
|
||||
verts->y = miny;
|
||||
verts->z = 0.0f;
|
||||
verts->color = color;
|
||||
verts->u = minu;
|
||||
verts->v = minv;
|
||||
verts++;
|
||||
|
||||
verts->x = maxx;
|
||||
verts->y = miny;
|
||||
verts->z = 0.0f;
|
||||
verts->color = color;
|
||||
verts->u = maxu;
|
||||
verts->v = minv;
|
||||
verts++;
|
||||
|
||||
verts->x = maxx;
|
||||
verts->y = maxy;
|
||||
verts->z = 0.0f;
|
||||
verts->color = color;
|
||||
verts->u = maxu;
|
||||
verts->v = maxv;
|
||||
verts++;
|
||||
|
||||
verts->x = minx;
|
||||
verts->y = maxy;
|
||||
verts->z = 0.0f;
|
||||
verts->color = color;
|
||||
verts->u = minu;
|
||||
verts->v = maxv;
|
||||
verts++;
|
||||
|
||||
verts->x = dstrect->x + center->x - 0.5f; /* X translation */
|
||||
verts->y = dstrect->y + center->y - 0.5f; /* Y translation */
|
||||
verts->z = (float)(M_PI * (float) angle / 180.0f); /* rotation */
|
||||
verts->color = 0;
|
||||
verts->u = 0.0f;
|
||||
verts->v = 0.0f;
|
||||
verts++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1076,8 +946,7 @@ SetupTextureState(D3D_RenderData *data, SDL_Texture * texture, LPDIRECT3DPIXELSH
|
|||
SDL_assert(*shader == NULL);
|
||||
|
||||
if (!texturedata) {
|
||||
SDL_SetError("Texture is not currently available");
|
||||
return -1;
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
UpdateTextureScaleMode(data, texturedata, 0);
|
||||
|
|
@ -1085,7 +954,7 @@ SetupTextureState(D3D_RenderData *data, SDL_Texture * texture, LPDIRECT3DPIXELSH
|
|||
if (BindTextureRep(data->device, &texturedata->texture, 0) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata->yuv) {
|
||||
switch (SDL_GetYUVConversionModeForResolution(texture->w, texture->h)) {
|
||||
case SDL_YUV_CONVERSION_JPEG:
|
||||
|
|
@ -1111,30 +980,33 @@ SetupTextureState(D3D_RenderData *data, SDL_Texture * texture, LPDIRECT3DPIXELSH
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
|
||||
{
|
||||
const SDL_bool was_copy_ex = data->drawstate.is_copy_ex;
|
||||
const SDL_bool is_copy_ex = (cmd->command == SDL_RENDERCMD_COPY_EX);
|
||||
SDL_Texture *texture = cmd->data.draw.texture;
|
||||
const SDL_BlendMode blend = cmd->data.draw.blend;
|
||||
|
||||
if (texture != data->drawstate.texture) {
|
||||
#if SDL_HAVE_YUV
|
||||
D3D_TextureData *oldtexturedata = data->drawstate.texture ? (D3D_TextureData *) data->drawstate.texture->driverdata : NULL;
|
||||
D3D_TextureData *newtexturedata = texture ? (D3D_TextureData *) texture->driverdata : NULL;
|
||||
#endif
|
||||
LPDIRECT3DPIXELSHADER9 shader = NULL;
|
||||
|
||||
/* disable any enabled textures we aren't going to use, let SetupTextureState() do the rest. */
|
||||
if (texture == NULL) {
|
||||
IDirect3DDevice9_SetTexture(data->device, 0, NULL);
|
||||
}
|
||||
#if SDL_HAVE_YUV
|
||||
if ((!newtexturedata || !newtexturedata->yuv) && (oldtexturedata && oldtexturedata->yuv)) {
|
||||
IDirect3DDevice9_SetTexture(data->device, 1, NULL);
|
||||
IDirect3DDevice9_SetTexture(data->device, 2, NULL);
|
||||
}
|
||||
#endif
|
||||
if (texture && SetupTextureState(data, texture, &shader) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -1151,10 +1023,12 @@ SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
|
|||
} else if (texture) {
|
||||
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
|
||||
UpdateDirtyTexture(data->device, &texturedata->texture);
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata->yuv) {
|
||||
UpdateDirtyTexture(data->device, &texturedata->utexture);
|
||||
UpdateDirtyTexture(data->device, &texturedata->vtexture);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (blend != data->drawstate.blend) {
|
||||
|
|
@ -1177,14 +1051,6 @@ SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
|
|||
data->drawstate.blend = blend;
|
||||
}
|
||||
|
||||
if (is_copy_ex != was_copy_ex) {
|
||||
if (!is_copy_ex) { /* SDL_RENDERCMD_COPY_EX will set this, we only want to reset it here if necessary. */
|
||||
const Float4X4 d3dmatrix = MatrixIdentity();
|
||||
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*) &d3dmatrix);
|
||||
}
|
||||
data->drawstate.is_copy_ex = is_copy_ex;
|
||||
}
|
||||
|
||||
if (data->drawstate.viewport_dirty) {
|
||||
const SDL_Rect *viewport = &data->drawstate.viewport;
|
||||
const D3DVIEWPORT9 d3dviewport = { viewport->x, viewport->y, viewport->w, viewport->h, 0.0f, 1.0f };
|
||||
|
|
@ -1229,52 +1095,53 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
|
|||
const int vboidx = data->currentVertexBuffer;
|
||||
IDirect3DVertexBuffer9 *vbo = NULL;
|
||||
const SDL_bool istarget = renderer->target != NULL;
|
||||
size_t i;
|
||||
|
||||
if (D3D_ActivateRenderer(renderer) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* upload the new VBO data for this set of commands. */
|
||||
vbo = data->vertexBuffers[vboidx];
|
||||
if (data->vertexBufferSize[vboidx] < vertsize) {
|
||||
const DWORD usage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY;
|
||||
const DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;
|
||||
if (vertices) {
|
||||
/* upload the new VBO data for this set of commands. */
|
||||
vbo = data->vertexBuffers[vboidx];
|
||||
if (data->vertexBufferSize[vboidx] < vertsize) {
|
||||
const DWORD usage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY;
|
||||
const DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;
|
||||
if (vbo) {
|
||||
IDirect3DVertexBuffer9_Release(vbo);
|
||||
}
|
||||
|
||||
if (FAILED(IDirect3DDevice9_CreateVertexBuffer(data->device, (UINT) vertsize, usage, fvf, D3DPOOL_DEFAULT, &vbo, NULL))) {
|
||||
vbo = NULL;
|
||||
}
|
||||
data->vertexBuffers[vboidx] = vbo;
|
||||
data->vertexBufferSize[vboidx] = vbo ? vertsize : 0;
|
||||
}
|
||||
|
||||
if (vbo) {
|
||||
IDirect3DVertexBuffer9_Release(vbo);
|
||||
}
|
||||
|
||||
if (FAILED(IDirect3DDevice9_CreateVertexBuffer(data->device, (UINT) vertsize, usage, fvf, D3DPOOL_DEFAULT, &vbo, NULL))) {
|
||||
vbo = NULL;
|
||||
}
|
||||
data->vertexBuffers[vboidx] = vbo;
|
||||
data->vertexBufferSize[vboidx] = vbo ? vertsize : 0;
|
||||
}
|
||||
|
||||
if (vbo) {
|
||||
void *ptr;
|
||||
if (FAILED(IDirect3DVertexBuffer9_Lock(vbo, 0, (UINT) vertsize, &ptr, D3DLOCK_DISCARD))) {
|
||||
vbo = NULL; /* oh well, we'll do immediate mode drawing. :( */
|
||||
} else {
|
||||
SDL_memcpy(ptr, vertices, vertsize);
|
||||
if (FAILED(IDirect3DVertexBuffer9_Unlock(vbo))) {
|
||||
void *ptr;
|
||||
if (FAILED(IDirect3DVertexBuffer9_Lock(vbo, 0, (UINT) vertsize, &ptr, D3DLOCK_DISCARD))) {
|
||||
vbo = NULL; /* oh well, we'll do immediate mode drawing. :( */
|
||||
} else {
|
||||
SDL_memcpy(ptr, vertices, vertsize);
|
||||
if (FAILED(IDirect3DVertexBuffer9_Unlock(vbo))) {
|
||||
vbo = NULL; /* oh well, we'll do immediate mode drawing. :( */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* cycle through a few VBOs so D3D has some time with the data before we replace it. */
|
||||
if (vbo) {
|
||||
data->currentVertexBuffer++;
|
||||
if (data->currentVertexBuffer >= SDL_arraysize(data->vertexBuffers)) {
|
||||
data->currentVertexBuffer = 0;
|
||||
/* cycle through a few VBOs so D3D has some time with the data before we replace it. */
|
||||
if (vbo) {
|
||||
data->currentVertexBuffer++;
|
||||
if (data->currentVertexBuffer >= SDL_arraysize(data->vertexBuffers)) {
|
||||
data->currentVertexBuffer = 0;
|
||||
}
|
||||
} else if (!data->reportedVboProblem) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "SDL failed to get a vertex buffer for this Direct3D 9 rendering batch!");
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Dropping back to a slower method.");
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "This might be a brief hiccup, but if performance is bad, this is probably why.");
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "This error will not be logged again for this renderer.");
|
||||
data->reportedVboProblem = SDL_TRUE;
|
||||
}
|
||||
} else if (!data->reportedVboProblem) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "SDL failed to get a vertex buffer for this Direct3D 9 rendering batch!");
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "Dropping back to a slower method.");
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "This might be a brief hiccup, but if performance is bad, this is probably why.");
|
||||
SDL_LogError(SDL_LOG_CATEGORY_RENDER, "This error will not be logged again for this renderer.");
|
||||
data->reportedVboProblem = SDL_TRUE;
|
||||
}
|
||||
|
||||
IDirect3DDevice9_SetStreamSource(data->device, 0, vbo, 0, sizeof (Vertex));
|
||||
|
|
@ -1316,20 +1183,21 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
|
|||
const SDL_Rect *viewport = &data->drawstate.viewport;
|
||||
const int backw = istarget ? renderer->target->w : data->pparams.BackBufferWidth;
|
||||
const int backh = istarget ? renderer->target->h : data->pparams.BackBufferHeight;
|
||||
const SDL_bool viewport_equal = ((viewport->x == 0) && (viewport->y == 0) && (viewport->w == backw) && (viewport->h == backh)) ? SDL_TRUE : SDL_FALSE;
|
||||
|
||||
if (data->drawstate.cliprect_enabled) {
|
||||
if (data->drawstate.cliprect_enabled || data->drawstate.cliprect_enabled_dirty) {
|
||||
IDirect3DDevice9_SetRenderState(data->device, D3DRS_SCISSORTESTENABLE, FALSE);
|
||||
data->drawstate.cliprect_enabled_dirty = SDL_TRUE;
|
||||
data->drawstate.cliprect_enabled_dirty = data->drawstate.cliprect_enabled;
|
||||
}
|
||||
|
||||
/* Don't reset the viewport if we don't have to! */
|
||||
if (!viewport->x && !viewport->y && (viewport->w == backw) && (viewport->h == backh)) {
|
||||
if (!data->drawstate.viewport_dirty && viewport_equal) {
|
||||
IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);
|
||||
} else {
|
||||
/* Clear is defined to clear the entire render target */
|
||||
const D3DVIEWPORT9 wholeviewport = { 0, 0, backw, backh, 0.0f, 1.0f };
|
||||
IDirect3DDevice9_SetViewport(data->device, &wholeviewport);
|
||||
data->drawstate.viewport_dirty = SDL_TRUE;
|
||||
data->drawstate.viewport_dirty = SDL_TRUE; /* we still need to (re)set orthographic projection, so always mark it dirty. */
|
||||
IDirect3DDevice9_Clear(data->device, 0, NULL, D3DCLEAR_TARGET, color, 0.0f, 0);
|
||||
}
|
||||
|
||||
|
|
@ -1374,58 +1242,24 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
|
|||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_FILL_RECTS: {
|
||||
case SDL_RENDERCMD_FILL_RECTS: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_COPY: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_COPY_EX: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_GEOMETRY: {
|
||||
const size_t count = cmd->data.draw.count;
|
||||
const size_t first = cmd->data.draw.first;
|
||||
SetDrawState(data, cmd);
|
||||
if (vbo) {
|
||||
size_t offset = 0;
|
||||
for (i = 0; i < count; ++i, offset += 4) {
|
||||
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLEFAN, (UINT) ((first / sizeof (Vertex)) + offset), 2);
|
||||
}
|
||||
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLELIST, (UINT) (first / sizeof (Vertex)), (UINT) count / 3);
|
||||
} else {
|
||||
const Vertex *verts = (Vertex *) (((Uint8 *) vertices) + first);
|
||||
for (i = 0; i < count; ++i, verts += 4) {
|
||||
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, verts, sizeof (Vertex));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_COPY: {
|
||||
const size_t count = cmd->data.draw.count;
|
||||
const size_t first = cmd->data.draw.first;
|
||||
SetDrawState(data, cmd);
|
||||
if (vbo) {
|
||||
size_t offset = 0;
|
||||
for (i = 0; i < count; ++i, offset += 4) {
|
||||
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLEFAN, (UINT) ((first / sizeof (Vertex)) + offset), 2);
|
||||
}
|
||||
} else {
|
||||
const Vertex *verts = (Vertex *) (((Uint8 *) vertices) + first);
|
||||
for (i = 0; i < count; ++i, verts += 4) {
|
||||
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, verts, sizeof (Vertex));
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_COPY_EX: {
|
||||
const size_t first = cmd->data.draw.first;
|
||||
const Vertex *verts = (Vertex *) (((Uint8 *) vertices) + first);
|
||||
const Vertex *transvert = verts + 4;
|
||||
const float translatex = transvert->x;
|
||||
const float translatey = transvert->y;
|
||||
const float rotation = transvert->z;
|
||||
const Float4X4 d3dmatrix = MatrixMultiply(MatrixRotationZ(rotation), MatrixTranslation(translatex, translatey, 0));
|
||||
SetDrawState(data, cmd);
|
||||
|
||||
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&d3dmatrix);
|
||||
|
||||
if (vbo) {
|
||||
IDirect3DDevice9_DrawPrimitive(data->device, D3DPT_TRIANGLEFAN, (UINT) (first / sizeof (Vertex)), 2);
|
||||
} else {
|
||||
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, verts, sizeof (Vertex));
|
||||
const Vertex* verts = (Vertex*)(((Uint8*)vertices) + first);
|
||||
IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLELIST, (UINT) count / 3, verts, sizeof(Vertex));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -1452,6 +1286,7 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
|||
RECT d3drect;
|
||||
D3DLOCKED_RECT locked;
|
||||
HRESULT result;
|
||||
int status;
|
||||
|
||||
if (data->currentRenderTarget) {
|
||||
backBuffer = data->currentRenderTarget;
|
||||
|
|
@ -1486,7 +1321,7 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
|||
return D3D_SetError("LockRect()", result);
|
||||
}
|
||||
|
||||
SDL_ConvertPixels(rect->w, rect->h,
|
||||
status = SDL_ConvertPixels(rect->w, rect->h,
|
||||
D3DFMTToPixelFormat(desc.Format), locked.pBits, locked.Pitch,
|
||||
format, pixels, pitch);
|
||||
|
||||
|
|
@ -1494,7 +1329,7 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
|||
|
||||
IDirect3DSurface9_Release(surface);
|
||||
|
||||
return 0;
|
||||
return status;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -1533,10 +1368,12 @@ D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
renderdata->drawstate.shader = NULL;
|
||||
IDirect3DDevice9_SetPixelShader(renderdata->device, NULL);
|
||||
IDirect3DDevice9_SetTexture(renderdata->device, 0, NULL);
|
||||
#if SDL_HAVE_YUV
|
||||
if (data->yuv) {
|
||||
IDirect3DDevice9_SetTexture(renderdata->device, 1, NULL);
|
||||
IDirect3DDevice9_SetTexture(renderdata->device, 2, NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
|
|
@ -1544,9 +1381,11 @@ D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
}
|
||||
|
||||
D3D_DestroyTextureRep(&data->texture);
|
||||
#if SDL_HAVE_YUV
|
||||
D3D_DestroyTextureRep(&data->utexture);
|
||||
D3D_DestroyTextureRep(&data->vtexture);
|
||||
SDL_free(data->pixels);
|
||||
#endif
|
||||
SDL_free(data);
|
||||
texture->driverdata = NULL;
|
||||
}
|
||||
|
|
@ -1568,12 +1407,14 @@ D3D_DestroyRenderer(SDL_Renderer * renderer)
|
|||
IDirect3DSurface9_Release(data->currentRenderTarget);
|
||||
data->currentRenderTarget = NULL;
|
||||
}
|
||||
#if SDL_HAVE_YUV
|
||||
for (i = 0; i < SDL_arraysize(data->shaders); ++i) {
|
||||
if (data->shaders[i]) {
|
||||
IDirect3DPixelShader9_Release(data->shaders[i]);
|
||||
data->shaders[i] = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* Release all vertex buffers */
|
||||
for (i = 0; i < SDL_arraysize(data->vertexBuffers); ++i) {
|
||||
if (data->vertexBuffers[i]) {
|
||||
|
|
@ -1603,6 +1444,12 @@ D3D_Reset(SDL_Renderer * renderer)
|
|||
SDL_Texture *texture;
|
||||
int i;
|
||||
|
||||
/* Cancel any scene that we've started */
|
||||
if (!data->beginScene) {
|
||||
IDirect3DDevice9_EndScene(data->device);
|
||||
data->beginScene = SDL_TRUE;
|
||||
}
|
||||
|
||||
/* Release the default render target before reset */
|
||||
if (data->defaultRenderTarget) {
|
||||
IDirect3DSurface9_Release(data->defaultRenderTarget);
|
||||
|
|
@ -1657,7 +1504,6 @@ D3D_Reset(SDL_Renderer * renderer)
|
|||
data->drawstate.texture = NULL;
|
||||
data->drawstate.shader = NULL;
|
||||
data->drawstate.blend = SDL_BLENDMODE_INVALID;
|
||||
data->drawstate.is_copy_ex = SDL_FALSE;
|
||||
IDirect3DDevice9_SetTransform(data->device, D3DTS_VIEW, (D3DMATRIX*)&d3dmatrix);
|
||||
|
||||
/* Let the application know that render targets were reset */
|
||||
|
|
@ -1670,6 +1516,24 @@ D3D_Reset(SDL_Renderer * renderer)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
D3D_SetVSync(SDL_Renderer * renderer, const int vsync)
|
||||
{
|
||||
D3D_RenderData *data = renderer->driverdata;
|
||||
if (vsync) {
|
||||
data->pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
|
||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
} else {
|
||||
data->pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||
renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
if (D3D_Reset(renderer) < 0) {
|
||||
/* D3D_Reset will call SDL_SetError() */
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_Renderer *
|
||||
D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
{
|
||||
|
|
@ -1710,7 +1574,9 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->SupportsBlendMode = D3D_SupportsBlendMode;
|
||||
renderer->CreateTexture = D3D_CreateTexture;
|
||||
renderer->UpdateTexture = D3D_UpdateTexture;
|
||||
#if SDL_HAVE_YUV
|
||||
renderer->UpdateTextureYUV = D3D_UpdateTextureYUV;
|
||||
#endif
|
||||
renderer->LockTexture = D3D_LockTexture;
|
||||
renderer->UnlockTexture = D3D_UnlockTexture;
|
||||
renderer->SetTextureScaleMode = D3D_SetTextureScaleMode;
|
||||
|
|
@ -1719,14 +1585,13 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->QueueSetDrawColor = D3D_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
renderer->QueueDrawPoints = D3D_QueueDrawPoints;
|
||||
renderer->QueueDrawLines = D3D_QueueDrawPoints; /* lines and points queue vertices the same way. */
|
||||
renderer->QueueFillRects = D3D_QueueFillRects;
|
||||
renderer->QueueCopy = D3D_QueueCopy;
|
||||
renderer->QueueCopyEx = D3D_QueueCopyEx;
|
||||
renderer->QueueGeometry = D3D_QueueGeometry;
|
||||
renderer->RunCommandQueue = D3D_RunCommandQueue;
|
||||
renderer->RenderReadPixels = D3D_RenderReadPixels;
|
||||
renderer->RenderPresent = D3D_RenderPresent;
|
||||
renderer->DestroyTexture = D3D_DestroyTexture;
|
||||
renderer->DestroyRenderer = D3D_DestroyRenderer;
|
||||
renderer->SetVSync = D3D_SetVSync;
|
||||
renderer->info = D3D_RenderDriver.info;
|
||||
renderer->info.flags = (SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
|
||||
renderer->driverdata = data;
|
||||
|
|
@ -1811,9 +1676,6 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
IDirect3DDevice9_GetDeviceCaps(data->device, &caps);
|
||||
renderer->info.max_texture_width = caps.MaxTextureWidth;
|
||||
renderer->info.max_texture_height = caps.MaxTextureHeight;
|
||||
if (caps.NumSimultaneousRTs >= 2) {
|
||||
renderer->info.flags |= SDL_RENDERER_TARGETTEXTURE;
|
||||
}
|
||||
|
||||
if (caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND) {
|
||||
data->enableSeparateAlphaBlend = SDL_TRUE;
|
||||
|
|
@ -1825,7 +1687,7 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
|
||||
/* Set up parameters for rendering */
|
||||
D3D_InitRenderState(data);
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (caps.MaxSimultaneousTextures >= 3) {
|
||||
int i;
|
||||
for (i = 0; i < SDL_arraysize(data->shaders); ++i) {
|
||||
|
|
@ -1839,7 +1701,7 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_IYUV;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
data->drawstate.blend = SDL_BLENDMODE_INVALID;
|
||||
|
||||
return renderer;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -20,6 +20,9 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#include "SDL_render.h"
|
||||
#include "SDL_system.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
|
||||
|
||||
#define COBJMACROS
|
||||
|
|
@ -51,13 +54,17 @@ extern ISwapChainBackgroundPanelNative * WINRT_GlobalSwapChainBackgroundPanelNat
|
|||
#endif /* __WINRT__ */
|
||||
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
#define SDL_COMPOSE_ERROR(str) __FUNCTION__ ", " str
|
||||
#else
|
||||
#define SDL_COMPOSE_ERROR(str) SDL_STRINGIFY_ARG(__FUNCTION__) ", " str
|
||||
#endif
|
||||
|
||||
#define SAFE_RELEASE(X) if ((X)) { IUnknown_Release(SDL_static_cast(IUnknown*, X)); X = NULL; }
|
||||
|
||||
|
||||
/* !!! FIXME: vertex buffer bandwidth could be significantly lower; move color to a uniform, only use UV coords
|
||||
!!! FIXME: when textures are needed, and don't ever pass Z, since it's always zero. */
|
||||
/* !!! FIXME: vertex buffer bandwidth could be lower; only use UV coords when
|
||||
!!! FIXME: textures are needed. */
|
||||
|
||||
/* Vertex shader, common values */
|
||||
typedef struct
|
||||
|
|
@ -69,9 +76,9 @@ typedef struct
|
|||
/* Per-vertex data */
|
||||
typedef struct
|
||||
{
|
||||
Float3 pos;
|
||||
Float2 pos;
|
||||
Float2 tex;
|
||||
Float4 color;
|
||||
SDL_Color color;
|
||||
} VertexPositionColor;
|
||||
|
||||
/* Per-texture data */
|
||||
|
|
@ -84,7 +91,7 @@ typedef struct
|
|||
int lockedTexturePositionX;
|
||||
int lockedTexturePositionY;
|
||||
D3D11_FILTER scaleMode;
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
/* YV12 texture support */
|
||||
SDL_bool yuv;
|
||||
ID3D11Texture2D *mainTextureU;
|
||||
|
|
@ -100,6 +107,7 @@ typedef struct
|
|||
Uint8 *pixels;
|
||||
int pitch;
|
||||
SDL_Rect locked_rect;
|
||||
#endif
|
||||
} D3D11_TextureData;
|
||||
|
||||
/* Blend mode data */
|
||||
|
|
@ -176,11 +184,13 @@ typedef struct
|
|||
|
||||
static const GUID SDL_IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } };
|
||||
static const GUID SDL_IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } };
|
||||
#if defined(__WINRT__) && NTDDI_VERSION > NTDDI_WIN8
|
||||
static const GUID SDL_IID_IDXGIDevice3 = { 0x6007896c, 0x3244, 0x4afd, { 0xbf, 0x18, 0xa6, 0xd3, 0xbe, 0xda, 0x50, 0x23 } };
|
||||
#endif
|
||||
static const GUID SDL_IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } };
|
||||
static const GUID SDL_IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } };
|
||||
static const GUID SDL_IID_ID3D11DeviceContext1 = { 0xbb2c6faa, 0xb5fb, 0x4082, { 0x8e, 0x6b, 0x38, 0x8b, 0x8c, 0xfa, 0x90, 0xe1 } };
|
||||
static const GUID SDL_IID_ID3D11Debug = { 0x79cf2233, 0x7536, 0x4948, { 0x9d, 0x36, 0x1e, 0x46, 0x92, 0xdc, 0x57, 0x60 } };
|
||||
/*static const GUID SDL_IID_ID3D11Debug = { 0x79cf2233, 0x7536, 0x4948, { 0x9d, 0x36, 0x1e, 0x46, 0x92, 0xdc, 0x57, 0x60 } };*/
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
|
|
@ -478,6 +488,11 @@ D3D11_CreateDeviceResources(SDL_Renderer * renderer)
|
|||
creationFlags |= D3D11_CREATE_DEVICE_DEBUG;
|
||||
}
|
||||
|
||||
/* Create a single-threaded device unless the app requests otherwise. */
|
||||
if (!SDL_GetHintBoolean(SDL_HINT_RENDER_DIRECT3D_THREADSAFE, SDL_FALSE)) {
|
||||
creationFlags |= D3D11_CREATE_DEVICE_SINGLETHREADED;
|
||||
}
|
||||
|
||||
/* Create the Direct3D 11 API device object and a corresponding context. */
|
||||
result = D3D11CreateDeviceFunc(
|
||||
data->dxgiAdapter,
|
||||
|
|
@ -691,7 +706,10 @@ D3D11_GetRotationForCurrentRenderTarget(SDL_Renderer * renderer)
|
|||
static int
|
||||
D3D11_GetViewportAlignedD3DRect(SDL_Renderer * renderer, const SDL_Rect * sdlRect, D3D11_RECT * outRect, BOOL includeViewportOffset)
|
||||
{
|
||||
D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
|
||||
const int rotation = D3D11_GetRotationForCurrentRenderTarget(renderer);
|
||||
const SDL_Rect *viewport = &data->currentViewport;
|
||||
|
||||
switch (rotation) {
|
||||
case DXGI_MODE_ROTATION_IDENTITY:
|
||||
outRect->left = sdlRect->x;
|
||||
|
|
@ -699,27 +717,27 @@ D3D11_GetViewportAlignedD3DRect(SDL_Renderer * renderer, const SDL_Rect * sdlRec
|
|||
outRect->top = sdlRect->y;
|
||||
outRect->bottom = sdlRect->y + sdlRect->h;
|
||||
if (includeViewportOffset) {
|
||||
outRect->left += renderer->viewport.x;
|
||||
outRect->right += renderer->viewport.x;
|
||||
outRect->top += renderer->viewport.y;
|
||||
outRect->bottom += renderer->viewport.y;
|
||||
outRect->left += viewport->x;
|
||||
outRect->right += viewport->x;
|
||||
outRect->top += viewport->y;
|
||||
outRect->bottom += viewport->y;
|
||||
}
|
||||
break;
|
||||
case DXGI_MODE_ROTATION_ROTATE270:
|
||||
outRect->left = sdlRect->y;
|
||||
outRect->right = sdlRect->y + sdlRect->h;
|
||||
outRect->top = renderer->viewport.w - sdlRect->x - sdlRect->w;
|
||||
outRect->bottom = renderer->viewport.w - sdlRect->x;
|
||||
outRect->top = viewport->w - sdlRect->x - sdlRect->w;
|
||||
outRect->bottom = viewport->w - sdlRect->x;
|
||||
break;
|
||||
case DXGI_MODE_ROTATION_ROTATE180:
|
||||
outRect->left = renderer->viewport.w - sdlRect->x - sdlRect->w;
|
||||
outRect->right = renderer->viewport.w - sdlRect->x;
|
||||
outRect->top = renderer->viewport.h - sdlRect->y - sdlRect->h;
|
||||
outRect->bottom = renderer->viewport.h - sdlRect->y;
|
||||
outRect->left = viewport->w - sdlRect->x - sdlRect->w;
|
||||
outRect->right = viewport->w - sdlRect->x;
|
||||
outRect->top = viewport->h - sdlRect->y - sdlRect->h;
|
||||
outRect->bottom = viewport->h - sdlRect->y;
|
||||
break;
|
||||
case DXGI_MODE_ROTATION_ROTATE90:
|
||||
outRect->left = renderer->viewport.h - sdlRect->y - sdlRect->h;
|
||||
outRect->right = renderer->viewport.h - sdlRect->y;
|
||||
outRect->left = viewport->h - sdlRect->y - sdlRect->h;
|
||||
outRect->right = viewport->h - sdlRect->y;
|
||||
outRect->top = sdlRect->x;
|
||||
outRect->bottom = sdlRect->x + sdlRect->h;
|
||||
break;
|
||||
|
|
@ -761,7 +779,11 @@ D3D11_CreateSwapChain(SDL_Renderer * renderer, int w, int h)
|
|||
if (usingXAML) {
|
||||
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
|
||||
} else {
|
||||
swapChainDesc.Scaling = DXGI_SCALING_NONE;
|
||||
if (WIN_IsWindows8OrGreater()) {
|
||||
swapChainDesc.Scaling = DXGI_SCALING_NONE;
|
||||
} else {
|
||||
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
|
||||
}
|
||||
}
|
||||
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; /* All Windows Store apps must use this SwapEffect. */
|
||||
#endif
|
||||
|
|
@ -944,11 +966,13 @@ D3D11_CreateWindowSizeDependentResources(SDL_Renderer * renderer)
|
|||
*
|
||||
* TODO, WinRT: reexamine the docs for IDXGISwapChain1::SetRotation, see if might be available, usable, and prudent-to-call on WinPhone 8.1
|
||||
*/
|
||||
if (data->swapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) {
|
||||
result = IDXGISwapChain1_SetRotation(data->swapChain, data->rotation);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain1::SetRotation"), result);
|
||||
goto done;
|
||||
if (WIN_IsWindows8OrGreater()) {
|
||||
if (data->swapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) {
|
||||
result = IDXGISwapChain1_SetRotation(data->swapChain, data->rotation);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain1::SetRotation"), result);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1091,10 +1115,9 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
);
|
||||
if (FAILED(result)) {
|
||||
D3D11_DestroyTexture(renderer, texture);
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texture->format == SDL_PIXELFORMAT_YV12 ||
|
||||
texture->format == SDL_PIXELFORMAT_IYUV) {
|
||||
textureData->yuv = SDL_TRUE;
|
||||
|
|
@ -1109,8 +1132,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
);
|
||||
if (FAILED(result)) {
|
||||
D3D11_DestroyTexture(renderer, texture);
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
|
||||
}
|
||||
|
||||
result = ID3D11Device_CreateTexture2D(rendererData->d3dDevice,
|
||||
|
|
@ -1120,8 +1142,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
);
|
||||
if (FAILED(result)) {
|
||||
D3D11_DestroyTexture(renderer, texture);
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1142,11 +1163,10 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
);
|
||||
if (FAILED(result)) {
|
||||
D3D11_DestroyTexture(renderer, texture);
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D"), result);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_HAVE_YUV */
|
||||
resourceViewDesc.Format = textureDesc.Format;
|
||||
resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
|
||||
resourceViewDesc.Texture2D.MostDetailedMip = 0;
|
||||
|
|
@ -1158,10 +1178,9 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
);
|
||||
if (FAILED(result)) {
|
||||
D3D11_DestroyTexture(renderer, texture);
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (textureData->yuv) {
|
||||
result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
|
||||
(ID3D11Resource *)textureData->mainTextureU,
|
||||
|
|
@ -1170,8 +1189,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
);
|
||||
if (FAILED(result)) {
|
||||
D3D11_DestroyTexture(renderer, texture);
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
|
||||
}
|
||||
result = ID3D11Device_CreateShaderResourceView(rendererData->d3dDevice,
|
||||
(ID3D11Resource *)textureData->mainTextureV,
|
||||
|
|
@ -1180,8 +1198,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
);
|
||||
if (FAILED(result)) {
|
||||
D3D11_DestroyTexture(renderer, texture);
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1197,8 +1214,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
);
|
||||
if (FAILED(result)) {
|
||||
D3D11_DestroyTexture(renderer, texture);
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateShaderResourceView"), result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1214,11 +1230,10 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
&textureData->mainTextureRenderTargetView);
|
||||
if (FAILED(result)) {
|
||||
D3D11_DestroyTexture(renderer, texture);
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateRenderTargetView"), result);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateRenderTargetView"), result);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_HAVE_YUV */
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -1236,11 +1251,15 @@ D3D11_DestroyTexture(SDL_Renderer * renderer,
|
|||
SAFE_RELEASE(data->mainTextureResourceView);
|
||||
SAFE_RELEASE(data->mainTextureRenderTargetView);
|
||||
SAFE_RELEASE(data->stagingTexture);
|
||||
#if SDL_HAVE_YUV
|
||||
SAFE_RELEASE(data->mainTextureU);
|
||||
SAFE_RELEASE(data->mainTextureResourceViewU);
|
||||
SAFE_RELEASE(data->mainTextureV);
|
||||
SAFE_RELEASE(data->mainTextureResourceViewV);
|
||||
SAFE_RELEASE(data->mainTextureNV);
|
||||
SAFE_RELEASE(data->mainTextureResourceViewNV);
|
||||
SDL_free(data->pixels);
|
||||
#endif
|
||||
SDL_free(data);
|
||||
texture->driverdata = NULL;
|
||||
}
|
||||
|
|
@ -1270,8 +1289,7 @@ D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *tex
|
|||
NULL,
|
||||
&stagingTexture);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result);
|
||||
}
|
||||
|
||||
/* Get a write-only pointer to data in the staging texture: */
|
||||
|
|
@ -1283,9 +1301,8 @@ D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Texture2D *tex
|
|||
&textureMemory
|
||||
);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result);
|
||||
SAFE_RELEASE(stagingTexture);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result);
|
||||
}
|
||||
|
||||
src = (const Uint8 *)pixels;
|
||||
|
|
@ -1337,14 +1354,13 @@ D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata;
|
||||
|
||||
if (!textureData) {
|
||||
SDL_SetError("Texture is not currently available");
|
||||
return -1;
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, srcPixels, srcPitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (textureData->yuv) {
|
||||
/* Skip to the correct offset into the next texture */
|
||||
srcPixels = (const void*)((const Uint8*)srcPixels + rect->h * srcPitch);
|
||||
|
|
@ -1368,9 +1384,11 @@ D3D11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif /* SDL_HAVE_YUV */
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
static int
|
||||
D3D11_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect,
|
||||
|
|
@ -1382,8 +1400,7 @@ D3D11_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata;
|
||||
|
||||
if (!textureData) {
|
||||
SDL_SetError("Texture is not currently available");
|
||||
return -1;
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
|
||||
|
|
@ -1398,6 +1415,30 @@ D3D11_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
D3D11_UpdateTextureNV(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect,
|
||||
const Uint8 *Yplane, int Ypitch,
|
||||
const Uint8 *UVplane, int UVpitch)
|
||||
{
|
||||
D3D11_RenderData *rendererData = (D3D11_RenderData *)renderer->driverdata;
|
||||
D3D11_TextureData *textureData = (D3D11_TextureData *)texture->driverdata;
|
||||
|
||||
if (!textureData) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTexture, SDL_BYTESPERPIXEL(texture->format), rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (D3D11_UpdateTextureInternal(rendererData, textureData->mainTextureNV, 2, rect->x / 2, rect->y / 2, ((rect->w + 1) / 2), (rect->h + 1) / 2, UVplane, UVpitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int
|
||||
D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect, void **pixels, int *pitch)
|
||||
|
|
@ -1409,10 +1450,9 @@ D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
D3D11_MAPPED_SUBRESOURCE textureMemory;
|
||||
|
||||
if (!textureData) {
|
||||
SDL_SetError("Texture is not currently available");
|
||||
return -1;
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (textureData->yuv || textureData->nv12) {
|
||||
/* It's more efficient to upload directly... */
|
||||
if (!textureData->pixels) {
|
||||
|
|
@ -1429,7 +1469,7 @@ D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
*pitch = textureData->pitch;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
if (textureData->stagingTexture) {
|
||||
return SDL_SetError("texture is already locked");
|
||||
}
|
||||
|
|
@ -1454,8 +1494,7 @@ D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
NULL,
|
||||
&textureData->stagingTexture);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateTexture2D [create staging texture]"), result);
|
||||
}
|
||||
|
||||
/* Get a write-only pointer to data in the staging texture: */
|
||||
|
|
@ -1467,9 +1506,8 @@ D3D11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
&textureMemory
|
||||
);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result);
|
||||
SAFE_RELEASE(textureData->stagingTexture);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [map staging texture]"), result);
|
||||
}
|
||||
|
||||
/* Make note of where the staging texture will be written to
|
||||
|
|
@ -1495,7 +1533,7 @@ D3D11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
if (!textureData) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (textureData->yuv || textureData->nv12) {
|
||||
const SDL_Rect *rect = &textureData->locked_rect;
|
||||
void *pixels =
|
||||
|
|
@ -1504,7 +1542,7 @@ D3D11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
D3D11_UpdateTexture(renderer, texture, rect, pixels, textureData->pitch);
|
||||
return;
|
||||
}
|
||||
|
||||
#endif
|
||||
/* Commit the pixel buffer's changes back to the staging texture: */
|
||||
ID3D11DeviceContext_Unmap(rendererData->d3dContext,
|
||||
(ID3D11Resource *)textureData->stagingTexture,
|
||||
|
|
@ -1568,11 +1606,12 @@ static int
|
|||
D3D11_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
|
||||
{
|
||||
VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, count * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
|
||||
const float r = (float)(cmd->data.draw.r / 255.0f);
|
||||
const float g = (float)(cmd->data.draw.g / 255.0f);
|
||||
const float b = (float)(cmd->data.draw.b / 255.0f);
|
||||
const float a = (float)(cmd->data.draw.a / 255.0f);
|
||||
int i;
|
||||
SDL_Color color;
|
||||
color.r = cmd->data.draw.r;
|
||||
color.g = cmd->data.draw.g;
|
||||
color.b = cmd->data.draw.b;
|
||||
color.a = cmd->data.draw.a;
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
|
|
@ -1583,13 +1622,9 @@ D3D11_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL
|
|||
for (i = 0; i < count; i++) {
|
||||
verts->pos.x = points[i].x + 0.5f;
|
||||
verts->pos.y = points[i].y + 0.5f;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->tex.x = 0.0f;
|
||||
verts->tex.y = 0.0f;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts->color = color;
|
||||
verts++;
|
||||
}
|
||||
|
||||
|
|
@ -1597,238 +1632,55 @@ D3D11_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL
|
|||
}
|
||||
|
||||
static int
|
||||
D3D11_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
|
||||
D3D11_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
|
||||
int num_vertices, const void *indices, int num_indices, int size_indices,
|
||||
float scale_x, float scale_y)
|
||||
{
|
||||
VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, count * 4 * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
|
||||
const float r = (float)(cmd->data.draw.r / 255.0f);
|
||||
const float g = (float)(cmd->data.draw.g / 255.0f);
|
||||
const float b = (float)(cmd->data.draw.b / 255.0f);
|
||||
const float a = (float)(cmd->data.draw.a / 255.0f);
|
||||
int i;
|
||||
int count = indices ? num_indices : num_vertices;
|
||||
VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, count * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = count;
|
||||
size_indices = indices ? size_indices : 0;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
verts->pos.x = rects[i].x;
|
||||
verts->pos.y = rects[i].y;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->tex.x = 0.0f;
|
||||
verts->tex.y = 0.0f;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts++;
|
||||
int j;
|
||||
float *xy_;
|
||||
if (size_indices == 4) {
|
||||
j = ((const Uint32 *)indices)[i];
|
||||
} else if (size_indices == 2) {
|
||||
j = ((const Uint16 *)indices)[i];
|
||||
} else if (size_indices == 1) {
|
||||
j = ((const Uint8 *)indices)[i];
|
||||
} else {
|
||||
j = i;
|
||||
}
|
||||
|
||||
verts->pos.x = rects[i].x;
|
||||
verts->pos.y = rects[i].y + rects[i].h;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->tex.x = 0.0f;
|
||||
verts->tex.y = 0.0f;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts++;
|
||||
xy_ = (float *)((char*)xy + j * xy_stride);
|
||||
|
||||
verts->pos.x = rects[i].x + rects[i].w;
|
||||
verts->pos.y = rects[i].y;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->tex.x = 0.0f;
|
||||
verts->tex.y = 0.0f;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts++;
|
||||
verts->pos.x = xy_[0] * scale_x;
|
||||
verts->pos.y = xy_[1] * scale_y;
|
||||
verts->color = *(SDL_Color*)((char*)color + j * color_stride);
|
||||
|
||||
verts->pos.x = rects[i].x + rects[i].w;
|
||||
verts->pos.y = rects[i].y + rects[i].h;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->tex.x = 0.0f;
|
||||
verts->tex.y = 0.0f;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts++;
|
||||
if (texture) {
|
||||
float *uv_ = (float *)((char*)uv + j * uv_stride);
|
||||
verts->tex.x = uv_[0];
|
||||
verts->tex.y = uv_[1];
|
||||
} else {
|
||||
verts->tex.x = 0.0f;
|
||||
verts->tex.y = 0.0f;
|
||||
}
|
||||
|
||||
verts += 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
D3D11_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
|
||||
const SDL_Rect * srcrect, const SDL_FRect * dstrect)
|
||||
{
|
||||
VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, 4 * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
|
||||
const float r = (float)(cmd->data.draw.r / 255.0f);
|
||||
const float g = (float)(cmd->data.draw.g / 255.0f);
|
||||
const float b = (float)(cmd->data.draw.b / 255.0f);
|
||||
const float a = (float)(cmd->data.draw.a / 255.0f);
|
||||
const float minu = (float) srcrect->x / texture->w;
|
||||
const float maxu = (float) (srcrect->x + srcrect->w) / texture->w;
|
||||
const float minv = (float) srcrect->y / texture->h;
|
||||
const float maxv = (float) (srcrect->y + srcrect->h) / texture->h;
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = 1;
|
||||
|
||||
verts->pos.x = dstrect->x;
|
||||
verts->pos.y = dstrect->y;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->tex.x = minu;
|
||||
verts->tex.y = minv;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts++;
|
||||
|
||||
verts->pos.x = dstrect->x;
|
||||
verts->pos.y = dstrect->y + dstrect->h;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->tex.x = minu;
|
||||
verts->tex.y = maxv;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts++;
|
||||
|
||||
verts->pos.x = dstrect->x + dstrect->w;
|
||||
verts->pos.y = dstrect->y;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->tex.x = maxu;
|
||||
verts->tex.y = minv;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts++;
|
||||
|
||||
verts->pos.x = dstrect->x + dstrect->w;
|
||||
verts->pos.y = dstrect->y + dstrect->h;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->tex.x = maxu;
|
||||
verts->tex.y = maxv;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
D3D11_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
|
||||
const SDL_Rect * srcrect, const SDL_FRect * dstrect,
|
||||
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
|
||||
{
|
||||
VertexPositionColor *verts = (VertexPositionColor *) SDL_AllocateRenderVertices(renderer, 5 * sizeof (VertexPositionColor), 0, &cmd->data.draw.first);
|
||||
const float r = (float)(cmd->data.draw.r / 255.0f);
|
||||
const float g = (float)(cmd->data.draw.g / 255.0f);
|
||||
const float b = (float)(cmd->data.draw.b / 255.0f);
|
||||
const float a = (float)(cmd->data.draw.a / 255.0f);
|
||||
float minx, miny, maxx, maxy;
|
||||
float minu, maxu, minv, maxv;
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = 1;
|
||||
|
||||
minx = -center->x;
|
||||
maxx = dstrect->w - center->x;
|
||||
miny = -center->y;
|
||||
maxy = dstrect->h - center->y;
|
||||
|
||||
if (flip & SDL_FLIP_HORIZONTAL) {
|
||||
minu = (float) (srcrect->x + srcrect->w) / texture->w;
|
||||
maxu = (float) srcrect->x / texture->w;
|
||||
} else {
|
||||
minu = (float) srcrect->x / texture->w;
|
||||
maxu = (float) (srcrect->x + srcrect->w) / texture->w;
|
||||
}
|
||||
|
||||
if (flip & SDL_FLIP_VERTICAL) {
|
||||
minv = (float) (srcrect->y + srcrect->h) / texture->h;
|
||||
maxv = (float) srcrect->y / texture->h;
|
||||
} else {
|
||||
minv = (float) srcrect->y / texture->h;
|
||||
maxv = (float) (srcrect->y + srcrect->h) / texture->h;
|
||||
}
|
||||
|
||||
|
||||
|
||||
verts->pos.x = minx;
|
||||
verts->pos.y = miny;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts->tex.x = minu;
|
||||
verts->tex.y = minv;
|
||||
verts++;
|
||||
|
||||
verts->pos.x = minx;
|
||||
verts->pos.y = maxy;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts->tex.x = minu;
|
||||
verts->tex.y = maxv;
|
||||
verts++;
|
||||
|
||||
verts->pos.x = maxx;
|
||||
verts->pos.y = miny;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts->tex.x = maxu;
|
||||
verts->tex.y = minv;
|
||||
verts++;
|
||||
|
||||
verts->pos.x = maxx;
|
||||
verts->pos.y = maxy;
|
||||
verts->pos.z = 0.0f;
|
||||
verts->color.x = r;
|
||||
verts->color.y = g;
|
||||
verts->color.z = b;
|
||||
verts->color.w = a;
|
||||
verts->tex.x = maxu;
|
||||
verts->tex.y = maxv;
|
||||
verts++;
|
||||
|
||||
verts->pos.x = dstrect->x + center->x; /* X translation */
|
||||
verts->pos.y = dstrect->y + center->y; /* Y translation */
|
||||
verts->pos.z = (float)(M_PI * (float) angle / 180.0f); /* rotation */
|
||||
verts->color.x = 0;
|
||||
verts->color.y = 0;
|
||||
verts->color.z = 0;
|
||||
verts->color.w = 0;
|
||||
verts->tex.x = 0.0f;
|
||||
verts->tex.y = 0.0f;
|
||||
verts++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
D3D11_UpdateVertexBuffer(SDL_Renderer *renderer,
|
||||
const void * vertexData, size_t dataSizeInBytes)
|
||||
|
|
@ -1853,8 +1705,7 @@ D3D11_UpdateVertexBuffer(SDL_Renderer *renderer,
|
|||
&mappedResource
|
||||
);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [vertex buffer]"), result);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11DeviceContext1::Map [vertex buffer]"), result);
|
||||
}
|
||||
SDL_memcpy(mappedResource.pData, vertexData, dataSizeInBytes);
|
||||
ID3D11DeviceContext_Unmap(rendererData->d3dContext, (ID3D11Resource *)rendererData->vertexBuffers[vbidx], 0);
|
||||
|
|
@ -1881,8 +1732,7 @@ D3D11_UpdateVertexBuffer(SDL_Renderer *renderer,
|
|||
&rendererData->vertexBuffers[vbidx]
|
||||
);
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBuffer [vertex buffer]"), result);
|
||||
return -1;
|
||||
return WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("ID3D11Device1::CreateBuffer [vertex buffer]"), result);
|
||||
}
|
||||
|
||||
rendererData->vertexBufferSizes[vbidx] = dataSizeInBytes;
|
||||
|
|
@ -2135,7 +1985,7 @@ D3D11_SetCopyState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, const
|
|||
default:
|
||||
return SDL_SetError("Unknown scale mode: %d\n", textureData->scaleMode);
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (textureData->yuv) {
|
||||
ID3D11ShaderResourceView *shaderResources[] = {
|
||||
textureData->mainTextureResourceView,
|
||||
|
|
@ -2186,7 +2036,7 @@ D3D11_SetCopyState(SDL_Renderer * renderer, const SDL_RenderCommand *cmd, const
|
|||
SDL_arraysize(shaderResources), shaderResources, textureSampler, matrix);
|
||||
|
||||
}
|
||||
|
||||
#endif /* SDL_HAVE_YUV */
|
||||
return D3D11_SetDrawState(renderer, cmd, rendererData->pixelShaders[SHADER_RGB],
|
||||
1, &textureData->mainTextureResourceView, textureSampler, matrix);
|
||||
}
|
||||
|
|
@ -2204,7 +2054,6 @@ D3D11_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
|
|||
{
|
||||
D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
|
||||
const int viewportRotation = D3D11_GetRotationForCurrentRenderTarget(renderer);
|
||||
size_t i;
|
||||
|
||||
if (rendererData->currentViewportRotation != viewportRotation) {
|
||||
rendererData->currentViewportRotation = viewportRotation;
|
||||
|
|
@ -2276,37 +2125,28 @@ D3D11_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
|
|||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_FILL_RECTS: {
|
||||
case SDL_RENDERCMD_FILL_RECTS: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_COPY: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_COPY_EX: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_GEOMETRY: {
|
||||
SDL_Texture *texture = cmd->data.draw.texture;
|
||||
const size_t count = cmd->data.draw.count;
|
||||
const size_t first = cmd->data.draw.first;
|
||||
const size_t start = first / sizeof (VertexPositionColor);
|
||||
size_t offset = 0;
|
||||
D3D11_SetDrawState(renderer, cmd, rendererData->pixelShaders[SHADER_SOLID], 0, NULL, NULL, NULL);
|
||||
for (i = 0; i < count; i++, offset += 4) {
|
||||
D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, start + offset, 4);
|
||||
|
||||
if (texture) {
|
||||
D3D11_SetCopyState(renderer, cmd, NULL);
|
||||
} else {
|
||||
D3D11_SetDrawState(renderer, cmd, rendererData->pixelShaders[SHADER_SOLID], 0, NULL, NULL, NULL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_COPY: {
|
||||
const size_t first = cmd->data.draw.first;
|
||||
const size_t start = first / sizeof (VertexPositionColor);
|
||||
D3D11_SetCopyState(renderer, cmd, NULL);
|
||||
D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, start, 4);
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_COPY_EX: {
|
||||
const size_t first = cmd->data.draw.first;
|
||||
const size_t start = first / sizeof (VertexPositionColor);
|
||||
const VertexPositionColor *verts = (VertexPositionColor *) (((Uint8 *) vertices) + first);
|
||||
const VertexPositionColor *transvert = verts + 4;
|
||||
const float translatex = transvert->pos.x;
|
||||
const float translatey = transvert->pos.y;
|
||||
const float rotation = transvert->pos.z;
|
||||
const Float4X4 matrix = MatrixMultiply(MatrixRotationZ(rotation), MatrixTranslation(translatex, translatey, 0));
|
||||
D3D11_SetCopyState(renderer, cmd, &matrix);
|
||||
D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, start, 4);
|
||||
D3D11_DrawPrimitives(renderer, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST, start, count);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -2399,30 +2239,20 @@ D3D11_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
|||
/* Copy the data into the desired buffer, converting pixels to the
|
||||
* desired format at the same time:
|
||||
*/
|
||||
if (SDL_ConvertPixels(
|
||||
status = SDL_ConvertPixels(
|
||||
rect->w, rect->h,
|
||||
D3D11_DXGIFormatToSDLPixelFormat(stagingTextureDesc.Format),
|
||||
textureMemory.pData,
|
||||
textureMemory.RowPitch,
|
||||
format,
|
||||
pixels,
|
||||
pitch) != 0) {
|
||||
/* When SDL_ConvertPixels fails, it'll have already set the format.
|
||||
* Get the error message, and attach some extra data to it.
|
||||
*/
|
||||
char errorMessage[1024];
|
||||
SDL_snprintf(errorMessage, sizeof(errorMessage), "%s, Convert Pixels failed: %s", __FUNCTION__, SDL_GetError());
|
||||
SDL_SetError("%s", errorMessage);
|
||||
goto done;
|
||||
}
|
||||
pitch);
|
||||
|
||||
/* Unmap the texture: */
|
||||
ID3D11DeviceContext_Unmap(data->d3dContext,
|
||||
(ID3D11Resource *)stagingTexture,
|
||||
0);
|
||||
|
||||
status = 0;
|
||||
|
||||
done:
|
||||
SAFE_RELEASE(backBuffer);
|
||||
SAFE_RELEASE(stagingTexture);
|
||||
|
|
@ -2486,6 +2316,21 @@ D3D11_RenderPresent(SDL_Renderer * renderer)
|
|||
}
|
||||
}
|
||||
|
||||
#if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
|
||||
/* no-op. */
|
||||
#else
|
||||
static int
|
||||
D3D11_SetVSync(SDL_Renderer * renderer, const int vsync)
|
||||
{
|
||||
if (vsync) {
|
||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
} else {
|
||||
renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_Renderer *
|
||||
D3D11_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
{
|
||||
|
|
@ -2500,6 +2345,7 @@ D3D11_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
|
||||
data = (D3D11_RenderData *) SDL_calloc(1, sizeof(*data));
|
||||
if (!data) {
|
||||
SDL_free(renderer);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -2510,7 +2356,10 @@ D3D11_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->SupportsBlendMode = D3D11_SupportsBlendMode;
|
||||
renderer->CreateTexture = D3D11_CreateTexture;
|
||||
renderer->UpdateTexture = D3D11_UpdateTexture;
|
||||
#if SDL_HAVE_YUV
|
||||
renderer->UpdateTextureYUV = D3D11_UpdateTextureYUV;
|
||||
renderer->UpdateTextureNV = D3D11_UpdateTextureNV;
|
||||
#endif
|
||||
renderer->LockTexture = D3D11_LockTexture;
|
||||
renderer->UnlockTexture = D3D11_UnlockTexture;
|
||||
renderer->SetTextureScaleMode = D3D11_SetTextureScaleMode;
|
||||
|
|
@ -2519,9 +2368,7 @@ D3D11_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->QueueSetDrawColor = D3D11_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
renderer->QueueDrawPoints = D3D11_QueueDrawPoints;
|
||||
renderer->QueueDrawLines = D3D11_QueueDrawPoints; /* lines and points queue vertices the same way. */
|
||||
renderer->QueueFillRects = D3D11_QueueFillRects;
|
||||
renderer->QueueCopy = D3D11_QueueCopy;
|
||||
renderer->QueueCopyEx = D3D11_QueueCopyEx;
|
||||
renderer->QueueGeometry = D3D11_QueueGeometry;
|
||||
renderer->RunCommandQueue = D3D11_RunCommandQueue;
|
||||
renderer->RenderReadPixels = D3D11_RenderReadPixels;
|
||||
renderer->RenderPresent = D3D11_RenderPresent;
|
||||
|
|
@ -2548,6 +2395,7 @@ D3D11_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
if ((flags & SDL_RENDERER_PRESENTVSYNC)) {
|
||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
renderer->SetVSync = D3D11_SetVSync;
|
||||
#endif
|
||||
|
||||
/* HACK: make sure the SDL_Renderer references the SDL_Window data now, in
|
||||
|
|
@ -2593,4 +2441,30 @@ SDL_RenderDriver D3D11_RenderDriver = {
|
|||
|
||||
#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
|
||||
|
||||
#ifdef __WIN32__
|
||||
/* This function needs to always exist on Windows, for the Dynamic API. */
|
||||
ID3D11Device *
|
||||
SDL_RenderGetD3D11Device(SDL_Renderer * renderer)
|
||||
{
|
||||
ID3D11Device *device = NULL;
|
||||
|
||||
#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
|
||||
D3D11_RenderData *data = (D3D11_RenderData *) renderer->driverdata;
|
||||
|
||||
/* Make sure that this is a D3D renderer */
|
||||
if (renderer->DestroyRenderer != D3D11_DestroyRenderer) {
|
||||
SDL_SetError("Renderer is not a D3D11 renderer");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
device = (ID3D11Device *)data->d3dDevice;
|
||||
if (device) {
|
||||
ID3D11Device_AddRef(device);
|
||||
}
|
||||
#endif /* SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED */
|
||||
|
||||
return device;
|
||||
}
|
||||
#endif /* __WIN32__ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -1886,9 +1886,10 @@ static struct
|
|||
{
|
||||
const void *shader_data;
|
||||
SIZE_T shader_size;
|
||||
} D3D11_shaders[] = {
|
||||
} D3D11_shaders[NUM_SHADERS] = {
|
||||
{ D3D11_PixelShader_Colors, sizeof(D3D11_PixelShader_Colors) },
|
||||
{ D3D11_PixelShader_Textures, sizeof(D3D11_PixelShader_Textures) },
|
||||
#if SDL_HAVE_YUV
|
||||
{ D3D11_PixelShader_YUV_JPEG, sizeof(D3D11_PixelShader_YUV_JPEG) },
|
||||
{ D3D11_PixelShader_YUV_BT601, sizeof(D3D11_PixelShader_YUV_BT601) },
|
||||
{ D3D11_PixelShader_YUV_BT709, sizeof(D3D11_PixelShader_YUV_BT709) },
|
||||
|
|
@ -1898,6 +1899,7 @@ static struct
|
|||
{ D3D11_PixelShader_NV21_JPEG, sizeof(D3D11_PixelShader_NV21_JPEG) },
|
||||
{ D3D11_PixelShader_NV21_BT601, sizeof(D3D11_PixelShader_NV21_BT601) },
|
||||
{ D3D11_PixelShader_NV21_BT709, sizeof(D3D11_PixelShader_NV21_BT709) },
|
||||
#endif
|
||||
};
|
||||
|
||||
int D3D11_CreateVertexShader(ID3D11Device1 *d3dDevice, ID3D11VertexShader **vertexShader, ID3D11InputLayout **inputLayout)
|
||||
|
|
@ -1905,9 +1907,9 @@ int D3D11_CreateVertexShader(ID3D11Device1 *d3dDevice, ID3D11VertexShader **vert
|
|||
/* Declare how the input layout for SDL's vertex shader will be setup: */
|
||||
const D3D11_INPUT_ELEMENT_DESC vertexDesc[] =
|
||||
{
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "POSITION", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 8, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
{ "COLOR", 0, DXGI_FORMAT_R8G8B8A8_UNORM, 0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0 },
|
||||
};
|
||||
HRESULT result;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -25,6 +25,7 @@
|
|||
typedef enum {
|
||||
SHADER_SOLID,
|
||||
SHADER_RGB,
|
||||
#if SDL_HAVE_YUV
|
||||
SHADER_YUV_JPEG,
|
||||
SHADER_YUV_BT601,
|
||||
SHADER_YUV_BT709,
|
||||
|
|
@ -34,6 +35,7 @@ typedef enum {
|
|||
SHADER_NV21_JPEG,
|
||||
SHADER_NV21_BT601,
|
||||
SHADER_NV21_BT709,
|
||||
#endif
|
||||
NUM_SHADERS
|
||||
} D3D11_Shader;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -32,6 +32,7 @@
|
|||
#import <QuartzCore/CAMetalLayer.h>
|
||||
|
||||
#ifdef __MACOSX__
|
||||
#import <AppKit/NSWindow.h>
|
||||
#import <AppKit/NSView.h>
|
||||
#endif
|
||||
|
||||
|
|
@ -59,7 +60,7 @@ extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
|
|||
|
||||
/* macOS requires constants in a buffer to have a 256 byte alignment. */
|
||||
/* Use native type alignments from https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf */
|
||||
#if defined(__MACOSX__) || TARGET_OS_SIMULATOR
|
||||
#if defined(__MACOSX__) || TARGET_OS_SIMULATOR || TARGET_OS_MACCATALYST
|
||||
#define CONSTANT_ALIGN(x) (256)
|
||||
#else
|
||||
#define CONSTANT_ALIGN(x) (x < 4 ? 4 : x)
|
||||
|
|
@ -166,11 +167,12 @@ typedef struct METAL_ShaderPipelines
|
|||
@property (nonatomic, retain) id<MTLTexture> mtltexture_uv;
|
||||
@property (nonatomic, retain) id<MTLSamplerState> mtlsampler;
|
||||
@property (nonatomic, assign) SDL_MetalFragmentFunction fragmentFunction;
|
||||
#if SDL_HAVE_YUV
|
||||
@property (nonatomic, assign) BOOL yuv;
|
||||
@property (nonatomic, assign) BOOL nv12;
|
||||
@property (nonatomic, assign) size_t conversionBufferOffset;
|
||||
#endif
|
||||
@property (nonatomic, assign) BOOL hasdata;
|
||||
|
||||
@property (nonatomic, retain) id<MTLBuffer> lockedbuffer;
|
||||
@property (nonatomic, assign) SDL_Rect lockedrect;
|
||||
@end
|
||||
|
|
@ -279,26 +281,35 @@ MakePipelineState(METAL_RenderData *data, METAL_PipelineCache *cache,
|
|||
|
||||
switch (cache->vertexFunction) {
|
||||
case SDL_METAL_VERTEX_SOLID:
|
||||
/* position (float2) */
|
||||
vertdesc.layouts[0].stride = sizeof(float) * 2;
|
||||
/* position (float2), color (uchar4normalized) */
|
||||
vertdesc.layouts[0].stride = sizeof(float) * 2 + sizeof (int);
|
||||
vertdesc.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex;
|
||||
|
||||
vertdesc.attributes[0].format = MTLVertexFormatFloat2;
|
||||
vertdesc.attributes[0].offset = 0;
|
||||
vertdesc.attributes[0].bufferIndex = 0;
|
||||
|
||||
vertdesc.attributes[1].format = MTLVertexFormatUChar4Normalized;
|
||||
vertdesc.attributes[1].offset = sizeof (float) * 2;
|
||||
vertdesc.attributes[1].bufferIndex = 0;
|
||||
|
||||
break;
|
||||
case SDL_METAL_VERTEX_COPY:
|
||||
/* position (float2), texcoord (float2) */
|
||||
vertdesc.layouts[0].stride = sizeof(float) * 4;
|
||||
/* position (float2), color (uchar4normalized), texcoord (float2) */
|
||||
vertdesc.layouts[0].stride = sizeof(float) * 2 + sizeof (int) + sizeof (float) * 2;
|
||||
vertdesc.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex;
|
||||
|
||||
vertdesc.attributes[0].format = MTLVertexFormatFloat2;
|
||||
vertdesc.attributes[0].offset = 0;
|
||||
vertdesc.attributes[0].bufferIndex = 0;
|
||||
|
||||
vertdesc.attributes[1].format = MTLVertexFormatFloat2;
|
||||
vertdesc.attributes[1].offset = sizeof(float) * 2;
|
||||
vertdesc.attributes[1].format = MTLVertexFormatUChar4Normalized;
|
||||
vertdesc.attributes[1].offset = sizeof (float) * 2;
|
||||
vertdesc.attributes[1].bufferIndex = 0;
|
||||
|
||||
vertdesc.attributes[2].format = MTLVertexFormatFloat2;
|
||||
vertdesc.attributes[2].offset = sizeof(float) * 2 + sizeof (int);
|
||||
vertdesc.attributes[2].bufferIndex = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -450,7 +461,7 @@ ChoosePipelineState(METAL_RenderData *data, METAL_ShaderPipelines *pipelines, SD
|
|||
return MakePipelineState(data, cache, [NSString stringWithFormat:@" (blend=custom 0x%x)", blendmode], blendmode);
|
||||
}
|
||||
|
||||
static void
|
||||
static SDL_bool
|
||||
METAL_ActivateRenderCommandEncoder(SDL_Renderer * renderer, MTLLoadAction load, MTLClearColor *clear_color, id<MTLBuffer> vertex_buffer)
|
||||
{
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
|
|
@ -472,10 +483,16 @@ METAL_ActivateRenderCommandEncoder(SDL_Renderer * renderer, MTLLoadAction load,
|
|||
load = MTLLoadActionDontCare;
|
||||
}
|
||||
}
|
||||
mtltexture = data.mtlbackbuffer.texture;
|
||||
if (data.mtlbackbuffer != nil) {
|
||||
mtltexture = data.mtlbackbuffer.texture;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_assert(mtltexture);
|
||||
/* mtltexture can be nil here if macOS refused to give us a drawable,
|
||||
which apparently can happen for minimized windows, etc. */
|
||||
if (mtltexture == nil) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (load == MTLLoadActionClear) {
|
||||
SDL_assert(clear_color != NULL);
|
||||
|
|
@ -508,6 +525,8 @@ METAL_ActivateRenderCommandEncoder(SDL_Renderer * renderer, MTLLoadAction load,
|
|||
// or whatever. This means we can _always_ batch rendering commands!
|
||||
[data.mtlcmdbuffer enqueue];
|
||||
}
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -587,14 +606,14 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
mtltexdesc.usage = MTLTextureUsageShaderRead;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
id<MTLTexture> mtltexture = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
|
||||
if (mtltexture == nil) {
|
||||
return SDL_SetError("Texture allocation failed");
|
||||
}
|
||||
|
||||
id<MTLTexture> mtltexture_uv = nil;
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
BOOL yuv = (texture->format == SDL_PIXELFORMAT_IYUV) || (texture->format == SDL_PIXELFORMAT_YV12);
|
||||
BOOL nv12 = (texture->format == SDL_PIXELFORMAT_NV12) || (texture->format == SDL_PIXELFORMAT_NV21);
|
||||
|
||||
|
|
@ -619,7 +638,7 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
return SDL_SetError("Texture allocation failed");
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_HAVE_YUV */
|
||||
METAL_TextureData *texturedata = [[METAL_TextureData alloc] init];
|
||||
if (texture->scaleMode == SDL_ScaleModeNearest) {
|
||||
texturedata.mtlsampler = data.mtlsamplernearest;
|
||||
|
|
@ -628,7 +647,7 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
}
|
||||
texturedata.mtltexture = mtltexture;
|
||||
texturedata.mtltexture_uv = mtltexture_uv;
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
texturedata.yuv = yuv;
|
||||
texturedata.nv12 = nv12;
|
||||
|
||||
|
|
@ -638,10 +657,12 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
texturedata.fragmentFunction = SDL_METAL_FRAGMENT_NV12;
|
||||
} else if (texture->format == SDL_PIXELFORMAT_NV21) {
|
||||
texturedata.fragmentFunction = SDL_METAL_FRAGMENT_NV21;
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
texturedata.fragmentFunction = SDL_METAL_FRAGMENT_COPY;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (yuv || nv12) {
|
||||
size_t offset = 0;
|
||||
SDL_YUV_CONVERSION_MODE mode = SDL_GetYUVConversionModeForResolution(texture->w, texture->h);
|
||||
|
|
@ -653,7 +674,7 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
}
|
||||
texturedata.conversionBufferOffset = offset;
|
||||
}
|
||||
|
||||
#endif
|
||||
texture->driverdata = (void*)CFBridgingRetain(texturedata);
|
||||
|
||||
#if !__has_feature(objc_arc)
|
||||
|
|
@ -767,7 +788,7 @@ METAL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture, *rect, 0, pixels, pitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata.yuv) {
|
||||
int Uslice = texture->format == SDL_PIXELFORMAT_YV12 ? 1 : 0;
|
||||
int Vslice = texture->format == SDL_PIXELFORMAT_YV12 ? 0 : 1;
|
||||
|
|
@ -797,12 +818,13 @@ METAL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
texturedata.hasdata = YES;
|
||||
|
||||
return 0;
|
||||
}}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
static int
|
||||
METAL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect,
|
||||
|
|
@ -835,6 +857,34 @@ METAL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
return 0;
|
||||
}}
|
||||
|
||||
static int
|
||||
METAL_UpdateTextureNV(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect,
|
||||
const Uint8 *Yplane, int Ypitch,
|
||||
const Uint8 *UVplane, int UVpitch)
|
||||
{ @autoreleasepool {
|
||||
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
|
||||
SDL_Rect UVrect = {rect->x / 2, rect->y / 2, (rect->w + 1) / 2, (rect->h + 1) / 2};
|
||||
|
||||
/* Bail out if we're supposed to update an empty rectangle */
|
||||
if (rect->w <= 0 || rect->h <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture, *rect, 0, Yplane, Ypitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture_uv, UVrect, 0, UVplane, UVpitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
texturedata.hasdata = YES;
|
||||
|
||||
return 0;
|
||||
}}
|
||||
#endif
|
||||
|
||||
static int
|
||||
METAL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect, void **pixels, int *pitch)
|
||||
|
|
@ -849,10 +899,12 @@ METAL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
}
|
||||
|
||||
*pitch = SDL_BYTESPERPIXEL(texture->format) * rect->w;
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata.yuv || texturedata.nv12) {
|
||||
buffersize = ((*pitch) * rect->h) + (2 * (*pitch + 1) / 2) * ((rect->h + 1) / 2);
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
buffersize = (*pitch) * rect->h;
|
||||
}
|
||||
|
||||
|
|
@ -906,7 +958,7 @@ METAL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
destinationSlice:0
|
||||
destinationLevel:0
|
||||
destinationOrigin:MTLOriginMake(rect.x, rect.y, 0)];
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata.yuv) {
|
||||
int Uslice = texture->format == SDL_PIXELFORMAT_YV12 ? 1 : 0;
|
||||
int Vslice = texture->format == SDL_PIXELFORMAT_YV12 ? 0 : 1;
|
||||
|
|
@ -946,7 +998,7 @@ METAL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
destinationLevel:0
|
||||
destinationOrigin:MTLOriginMake(UVrect.x, UVrect.y, 0)];
|
||||
}
|
||||
|
||||
#endif
|
||||
[blitcmd endEncoding];
|
||||
|
||||
[data.mtlcmdbuffer commit];
|
||||
|
|
@ -991,13 +1043,6 @@ METAL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
}}
|
||||
|
||||
|
||||
// normalize a value from 0.0f to len into 0.0f to 1.0f.
|
||||
static inline float
|
||||
normtex(const float _val, const float len)
|
||||
{
|
||||
return _val / len;
|
||||
}
|
||||
|
||||
static int
|
||||
METAL_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd)
|
||||
{
|
||||
|
|
@ -1031,38 +1076,66 @@ METAL_QueueSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
|
|||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
* FIXME: not needed anymore, some cleanup to do
|
||||
*
|
||||
*(verts++) = ((float)cmd->data.color.r) / 255.0f;
|
||||
*(verts++) = ((float)cmd->data.color.g) / 255.0f;
|
||||
*(verts++) = ((float)cmd->data.color.b) / 255.0f;
|
||||
*(verts++) = ((float)cmd->data.color.a) / 255.0f;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
METAL_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
|
||||
{
|
||||
const size_t vertlen = (sizeof (float) * 2) * count;
|
||||
const SDL_Color color = {
|
||||
cmd->data.draw.r,
|
||||
cmd->data.draw.g,
|
||||
cmd->data.draw.b,
|
||||
cmd->data.draw.a
|
||||
};
|
||||
|
||||
const size_t vertlen = (2 * sizeof (float) + sizeof (SDL_Color)) * count;
|
||||
float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(8), &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
cmd->data.draw.count = count;
|
||||
SDL_memcpy(verts, points, vertlen);
|
||||
|
||||
for (int i = 0; i < count; i++, points++) {
|
||||
*(verts++) = points->x;
|
||||
*(verts++) = points->y;
|
||||
*((SDL_Color *)verts++) = color;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
METAL_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
|
||||
{
|
||||
const SDL_Color color = {
|
||||
cmd->data.draw.r,
|
||||
cmd->data.draw.g,
|
||||
cmd->data.draw.b,
|
||||
cmd->data.draw.a
|
||||
};
|
||||
|
||||
SDL_assert(count >= 2); /* should have been checked at the higher level. */
|
||||
|
||||
const size_t vertlen = (sizeof (float) * 2) * count;
|
||||
const size_t vertlen = (2 * sizeof (float) + sizeof (SDL_Color)) * count;
|
||||
float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(8), &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
cmd->data.draw.count = count;
|
||||
SDL_memcpy(verts, points, vertlen);
|
||||
|
||||
for (int i = 0; i < count; i++, points++) {
|
||||
*(verts++) = points->x;
|
||||
*(verts++) = points->y;
|
||||
*((SDL_Color *)verts++) = color;
|
||||
}
|
||||
|
||||
/* If the line segment is completely horizontal or vertical,
|
||||
make it one pixel longer, to satisfy the diamond-exit rule.
|
||||
|
|
@ -1072,8 +1145,8 @@ METAL_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_
|
|||
that are missing a pixel that frames something and not arbitrary
|
||||
angles. Maybe !!! FIXME for later, though. */
|
||||
|
||||
points += count - 2; /* update the last line. */
|
||||
verts += (count * 2) - 2;
|
||||
points -= 2; /* update the last line. */
|
||||
verts -= 2 + 1;
|
||||
|
||||
const float xstart = points[0].x;
|
||||
const float ystart = points[0].y;
|
||||
|
|
@ -1090,161 +1163,50 @@ METAL_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_
|
|||
}
|
||||
|
||||
static int
|
||||
METAL_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
|
||||
METAL_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
|
||||
int num_vertices, const void *indices, int num_indices, int size_indices,
|
||||
float scale_x, float scale_y)
|
||||
{
|
||||
const size_t vertlen = (sizeof (float) * 8) * count;
|
||||
int count = indices ? num_indices : num_vertices;
|
||||
const size_t vertlen = (2 * sizeof (float) + sizeof (int) + (texture ? 2 : 0) * sizeof (float)) * count;
|
||||
float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(8), &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = count;
|
||||
size_indices = indices ? size_indices : 0;
|
||||
|
||||
/* Quads in the following vertex order (matches the quad index buffer):
|
||||
* 1---3
|
||||
* | \ |
|
||||
* 0---2
|
||||
*/
|
||||
for (int i = 0; i < count; i++, rects++) {
|
||||
if ((rects->w <= 0.0f) || (rects->h <= 0.0f)) {
|
||||
cmd->data.draw.count--;
|
||||
for (int i = 0; i < count; i++) {
|
||||
int j;
|
||||
if (size_indices == 4) {
|
||||
j = ((const Uint32 *)indices)[i];
|
||||
} else if (size_indices == 2) {
|
||||
j = ((const Uint16 *)indices)[i];
|
||||
} else if (size_indices == 1) {
|
||||
j = ((const Uint8 *)indices)[i];
|
||||
} else {
|
||||
*(verts++) = rects->x;
|
||||
*(verts++) = rects->y + rects->h;
|
||||
*(verts++) = rects->x;
|
||||
*(verts++) = rects->y;
|
||||
*(verts++) = rects->x + rects->w;
|
||||
*(verts++) = rects->y + rects->h;
|
||||
*(verts++) = rects->x + rects->w;
|
||||
*(verts++) = rects->y;
|
||||
j = i;
|
||||
}
|
||||
|
||||
float *xy_ = (float *)((char*)xy + j * xy_stride);
|
||||
|
||||
*(verts++) = xy_[0] * scale_x;
|
||||
*(verts++) = xy_[1] * scale_y;
|
||||
|
||||
*((SDL_Color *)verts++) = *(SDL_Color *)((char*)color + j * color_stride);
|
||||
|
||||
if (texture) {
|
||||
float *uv_ = (float *)((char*)uv + j * uv_stride);
|
||||
*(verts++) = uv_[0];
|
||||
*(verts++) = uv_[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (cmd->data.draw.count == 0) {
|
||||
cmd->command = SDL_RENDERCMD_NO_OP; // nothing to do, just skip this one later.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
METAL_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
|
||||
const SDL_Rect * srcrect, const SDL_FRect * dstrect)
|
||||
{
|
||||
const float texw = (float) texture->w;
|
||||
const float texh = (float) texture->h;
|
||||
// !!! FIXME: use an index buffer
|
||||
const size_t vertlen = (sizeof (float) * 16);
|
||||
float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(8), &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = 1;
|
||||
|
||||
/* Interleaved positions and texture coordinates */
|
||||
*(verts++) = dstrect->x;
|
||||
*(verts++) = dstrect->y + dstrect->h;
|
||||
*(verts++) = normtex(srcrect->x, texw);
|
||||
*(verts++) = normtex(srcrect->y + srcrect->h, texh);
|
||||
|
||||
*(verts++) = dstrect->x;
|
||||
*(verts++) = dstrect->y;
|
||||
*(verts++) = normtex(srcrect->x, texw);
|
||||
*(verts++) = normtex(srcrect->y, texh);
|
||||
|
||||
*(verts++) = dstrect->x + dstrect->w;
|
||||
*(verts++) = dstrect->y + dstrect->h;
|
||||
*(verts++) = normtex(srcrect->x + srcrect->w, texw);
|
||||
*(verts++) = normtex(srcrect->y + srcrect->h, texh);
|
||||
|
||||
*(verts++) = dstrect->x + dstrect->w;
|
||||
*(verts++) = dstrect->y;
|
||||
*(verts++) = normtex(srcrect->x + srcrect->w, texw);
|
||||
*(verts++) = normtex(srcrect->y, texh);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
METAL_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
|
||||
const SDL_Rect * srcquad, const SDL_FRect * dstrect,
|
||||
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
|
||||
{
|
||||
const float texw = (float) texture->w;
|
||||
const float texh = (float) texture->h;
|
||||
const float rads = (float)(M_PI * (float) angle / 180.0f);
|
||||
const float c = cosf(rads), s = sinf(rads);
|
||||
float minu, maxu, minv, maxv;
|
||||
const size_t vertlen = (sizeof (float) * 32);
|
||||
float *verts;
|
||||
|
||||
// cheat and store this offset in (count) because it needs to be aligned in ways other fields don't and we aren't using count otherwise.
|
||||
verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, CONSTANT_ALIGN(16), &cmd->data.draw.count);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// transform matrix
|
||||
SDL_memset(verts, '\0', sizeof (*verts) * 16);
|
||||
verts[10] = verts[15] = 1.0f;
|
||||
// rotation
|
||||
verts[0] = c;
|
||||
verts[1] = s;
|
||||
verts[4] = -s;
|
||||
verts[5] = c;
|
||||
|
||||
// translation
|
||||
verts[12] = dstrect->x + center->x;
|
||||
verts[13] = dstrect->y + center->y;
|
||||
|
||||
// rest of the vertices don't need the aggressive alignment. Pack them in.
|
||||
verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(8), &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
minu = normtex(srcquad->x, texw);
|
||||
maxu = normtex(srcquad->x + srcquad->w, texw);
|
||||
minv = normtex(srcquad->y, texh);
|
||||
maxv = normtex(srcquad->y + srcquad->h, texh);
|
||||
|
||||
if (flip & SDL_FLIP_HORIZONTAL) {
|
||||
float tmp = maxu;
|
||||
maxu = minu;
|
||||
minu = tmp;
|
||||
}
|
||||
if (flip & SDL_FLIP_VERTICAL) {
|
||||
float tmp = maxv;
|
||||
maxv = minv;
|
||||
minv = tmp;
|
||||
}
|
||||
|
||||
/* Interleaved positions and texture coordinates */
|
||||
*(verts++) = -center->x;
|
||||
*(verts++) = dstrect->h - center->y;
|
||||
*(verts++) = minu;
|
||||
*(verts++) = maxv;
|
||||
|
||||
*(verts++) = -center->x;
|
||||
*(verts++) = -center->y;
|
||||
*(verts++) = minu;
|
||||
*(verts++) = minv;
|
||||
|
||||
*(verts++) = dstrect->w - center->x;
|
||||
*(verts++) = dstrect->h - center->y;
|
||||
*(verts++) = maxu;
|
||||
*(verts++) = maxv;
|
||||
|
||||
*(verts++) = dstrect->w - center->x;
|
||||
*(verts++) = -center->y;
|
||||
*(verts++) = maxu;
|
||||
*(verts++) = minv;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
#if __has_feature(objc_arc)
|
||||
|
|
@ -1266,7 +1228,7 @@ typedef struct
|
|||
size_t color_offset;
|
||||
} METAL_DrawStateCache;
|
||||
|
||||
static void
|
||||
static SDL_bool
|
||||
SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_MetalFragmentFunction shader,
|
||||
const size_t constants_offset, id<MTLBuffer> mtlbufvertex, METAL_DrawStateCache *statecache)
|
||||
{
|
||||
|
|
@ -1275,7 +1237,9 @@ SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Met
|
|||
size_t first = cmd->data.draw.first;
|
||||
id<MTLRenderPipelineState> newpipeline;
|
||||
|
||||
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, statecache->vertex_buffer);
|
||||
if (!METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, statecache->vertex_buffer)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (statecache->viewport_dirty) {
|
||||
MTLViewport viewport;
|
||||
|
|
@ -1291,22 +1255,29 @@ SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Met
|
|||
}
|
||||
|
||||
if (statecache->cliprect_dirty) {
|
||||
MTLScissorRect mtlrect;
|
||||
SDL_Rect output;
|
||||
SDL_Rect clip;
|
||||
if (statecache->cliprect_enabled) {
|
||||
const SDL_Rect *rect = &statecache->cliprect;
|
||||
mtlrect.x = statecache->viewport.x + rect->x;
|
||||
mtlrect.y = statecache->viewport.y + rect->y;
|
||||
mtlrect.width = rect->w;
|
||||
mtlrect.height = rect->h;
|
||||
clip = statecache->cliprect;
|
||||
clip.x += statecache->viewport.x;
|
||||
clip.y += statecache->viewport.y;
|
||||
} else {
|
||||
mtlrect.x = statecache->viewport.x;
|
||||
mtlrect.y = statecache->viewport.y;
|
||||
mtlrect.width = statecache->viewport.w;
|
||||
mtlrect.height = statecache->viewport.h;
|
||||
clip = statecache->viewport;
|
||||
}
|
||||
if (mtlrect.width > 0 && mtlrect.height > 0) {
|
||||
|
||||
/* Set Scissor Rect Validation: w/h must be <= render pass */
|
||||
SDL_zero(output);
|
||||
METAL_GetOutputSize(renderer, &output.w, &output.h);
|
||||
|
||||
if (SDL_IntersectRect(&output, &clip, &clip)) {
|
||||
MTLScissorRect mtlrect;
|
||||
mtlrect.x = clip.x;
|
||||
mtlrect.y = clip.y;
|
||||
mtlrect.width = clip.w;
|
||||
mtlrect.height = clip.h;
|
||||
[data.mtlcmdencoder setScissorRect:mtlrect];
|
||||
}
|
||||
|
||||
statecache->cliprect_dirty = SDL_FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -1329,9 +1300,10 @@ SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Met
|
|||
}
|
||||
|
||||
[data.mtlcmdencoder setVertexBufferOffset:first atIndex:0]; /* position/texcoords */
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
static SDL_bool
|
||||
SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const size_t constants_offset,
|
||||
id<MTLBuffer> mtlbufvertex, METAL_DrawStateCache *statecache)
|
||||
{
|
||||
|
|
@ -1339,7 +1311,9 @@ SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const size_t
|
|||
SDL_Texture *texture = cmd->data.draw.texture;
|
||||
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
|
||||
|
||||
SetDrawState(renderer, cmd, texturedata.fragmentFunction, constants_offset, mtlbufvertex, statecache);
|
||||
if (!SetDrawState(renderer, cmd, texturedata.fragmentFunction, constants_offset, mtlbufvertex, statecache)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (texture != statecache->texture) {
|
||||
METAL_TextureData *oldtexturedata = NULL;
|
||||
|
|
@ -1351,12 +1325,15 @@ SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const size_t
|
|||
}
|
||||
|
||||
[data.mtlcmdencoder setFragmentTexture:texturedata.mtltexture atIndex:0];
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata.yuv || texturedata.nv12) {
|
||||
[data.mtlcmdencoder setFragmentTexture:texturedata.mtltexture_uv atIndex:1];
|
||||
[data.mtlcmdencoder setFragmentBuffer:data.mtlbufconstants offset:texturedata.conversionBufferOffset atIndex:1];
|
||||
}
|
||||
#endif
|
||||
statecache->texture = texture;
|
||||
}
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -1454,6 +1431,7 @@ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
|
|||
MTLClearColor color = MTLClearColorMake(r / 255.0f, g / 255.0f, b / 255.0f, a / 255.0f);
|
||||
|
||||
// get new command encoder, set up with an initial clear operation.
|
||||
// (this might fail, and future draw operations will notice.)
|
||||
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionClear, &color, mtlbufvertex);
|
||||
break;
|
||||
}
|
||||
|
|
@ -1462,44 +1440,34 @@ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
|
|||
case SDL_RENDERCMD_DRAW_LINES: {
|
||||
const size_t count = cmd->data.draw.count;
|
||||
const MTLPrimitiveType primtype = (cmd->command == SDL_RENDERCMD_DRAW_POINTS) ? MTLPrimitiveTypePoint : MTLPrimitiveTypeLineStrip;
|
||||
SetDrawState(renderer, cmd, SDL_METAL_FRAGMENT_SOLID, CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM, mtlbufvertex, &statecache);
|
||||
[data.mtlcmdencoder drawPrimitives:primtype vertexStart:0 vertexCount:count];
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_FILL_RECTS: {
|
||||
const size_t count = cmd->data.draw.count;
|
||||
const size_t maxcount = UINT16_MAX / 4;
|
||||
SetDrawState(renderer, cmd, SDL_METAL_FRAGMENT_SOLID, CONSTANTS_OFFSET_IDENTITY, mtlbufvertex, &statecache);
|
||||
if (count == 1) {
|
||||
[data.mtlcmdencoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
|
||||
} else {
|
||||
/* Our index buffer has 16 bit indices, so we can only draw
|
||||
* 65k vertices (16k rects) at a time. */
|
||||
for (size_t i = 0; i < count; i += maxcount) {
|
||||
/* Set the vertex buffer offset for our current positions.
|
||||
* The vertex buffer itself was bound in SetDrawState. */
|
||||
[data.mtlcmdencoder setVertexBufferOffset:cmd->data.draw.first + i*sizeof(float)*8 atIndex:0];
|
||||
[data.mtlcmdencoder drawIndexedPrimitives:MTLPrimitiveTypeTriangle
|
||||
indexCount:SDL_min(maxcount, count - i) * 6
|
||||
indexType:MTLIndexTypeUInt16
|
||||
indexBuffer:data.mtlbufquadindices
|
||||
indexBufferOffset:0];
|
||||
}
|
||||
if (SetDrawState(renderer, cmd, SDL_METAL_FRAGMENT_SOLID, CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM, mtlbufvertex, &statecache)) {
|
||||
[data.mtlcmdencoder drawPrimitives:primtype vertexStart:0 vertexCount:count];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_COPY: {
|
||||
SetCopyState(renderer, cmd, CONSTANTS_OFFSET_IDENTITY, mtlbufvertex, &statecache);
|
||||
[data.mtlcmdencoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
|
||||
case SDL_RENDERCMD_FILL_RECTS: /* unused */
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_COPY_EX: {
|
||||
SetCopyState(renderer, cmd, CONSTANTS_OFFSET_INVALID, mtlbufvertex, &statecache);
|
||||
[data.mtlcmdencoder setVertexBuffer:mtlbufvertex offset:cmd->data.draw.count atIndex:3]; // transform
|
||||
[data.mtlcmdencoder drawPrimitives:MTLPrimitiveTypeTriangleStrip vertexStart:0 vertexCount:4];
|
||||
case SDL_RENDERCMD_COPY: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_COPY_EX: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_GEOMETRY: {
|
||||
const size_t count = cmd->data.draw.count;
|
||||
SDL_Texture *texture = cmd->data.draw.texture;
|
||||
|
||||
if (texture) {
|
||||
if (SetCopyState(renderer, cmd, CONSTANTS_OFFSET_IDENTITY, mtlbufvertex, &statecache)) {
|
||||
[data.mtlcmdencoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:count];
|
||||
}
|
||||
} else {
|
||||
if (SetDrawState(renderer, cmd, SDL_METAL_FRAGMENT_SOLID, CONSTANTS_OFFSET_IDENTITY, mtlbufvertex, &statecache)) {
|
||||
[data.mtlcmdencoder drawPrimitives:MTLPrimitiveTypeTriangle vertexStart:0 vertexCount:count];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -1517,7 +1485,9 @@ METAL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
|||
Uint32 pixel_format, void * pixels, int pitch)
|
||||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil);
|
||||
if (!METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil)) {
|
||||
return SDL_SetError("Failed to activate render command encoder (is your window in the background?");
|
||||
}
|
||||
|
||||
[data.mtlcmdencoder endEncoding];
|
||||
id<MTLTexture> mtltexture = data.mtlpassdesc.colorAttachments[0].texture;
|
||||
|
|
@ -1562,20 +1532,28 @@ static void
|
|||
METAL_RenderPresent(SDL_Renderer * renderer)
|
||||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
SDL_bool ready = SDL_TRUE;
|
||||
|
||||
// If we don't have a command buffer, we can't present, so activate to get one.
|
||||
if (data.mtlcmdencoder == nil) {
|
||||
// We haven't even gotten a backbuffer yet? Clear it to black. Otherwise, load the existing data.
|
||||
if (data.mtlbackbuffer == nil) {
|
||||
MTLClearColor color = MTLClearColorMake(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionClear, &color, nil);
|
||||
ready = METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionClear, &color, nil);
|
||||
} else {
|
||||
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil);
|
||||
ready = METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil);
|
||||
}
|
||||
}
|
||||
|
||||
[data.mtlcmdencoder endEncoding];
|
||||
[data.mtlcmdbuffer presentDrawable:data.mtlbackbuffer];
|
||||
|
||||
// If we don't have a drawable to present, don't try to present it.
|
||||
// But we'll still try to commit the command buffer in case it was already enqueued.
|
||||
if (ready) {
|
||||
SDL_assert(data.mtlbackbuffer != nil);
|
||||
[data.mtlcmdbuffer presentDrawable:data.mtlbackbuffer];
|
||||
}
|
||||
|
||||
[data.mtlcmdbuffer commit];
|
||||
|
||||
data.mtlcmdencoder = nil;
|
||||
|
|
@ -1602,7 +1580,11 @@ METAL_DestroyRenderer(SDL_Renderer * renderer)
|
|||
|
||||
DestroyAllPipelines(data.allpipelines, data.pipelinescount);
|
||||
|
||||
SDL_Metal_DestroyView(data.mtlview);
|
||||
/* Release the metal view instead of destroying it,
|
||||
in case we want to use it later (recreating the renderer)
|
||||
*/
|
||||
/* SDL_Metal_DestroyView(data.mtlview); */
|
||||
CFBridgingRelease(data.mtlview);
|
||||
}
|
||||
|
||||
SDL_free(renderer);
|
||||
|
|
@ -1618,11 +1600,61 @@ METAL_GetMetalLayer(SDL_Renderer * renderer)
|
|||
static void *
|
||||
METAL_GetMetalCommandEncoder(SDL_Renderer * renderer)
|
||||
{ @autoreleasepool {
|
||||
// note that data.mtlcmdencoder can be nil if METAL_ActivateRenderCommandEncoder fails.
|
||||
// Before SDL 2.0.18, it might have returned a non-nil encoding that might not have been
|
||||
// usable for presentation. Check your return values!
|
||||
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil);
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
return (__bridge void*)data.mtlcmdencoder;
|
||||
}}
|
||||
|
||||
static int
|
||||
METAL_SetVSync(SDL_Renderer * renderer, const int vsync)
|
||||
{
|
||||
#if (defined(__MACOSX__) && defined(MAC_OS_X_VERSION_10_13)) || TARGET_OS_MACCATALYST
|
||||
if (@available(macOS 10.13, *)) {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
if (vsync) {
|
||||
data.mtllayer.displaySyncEnabled = YES;
|
||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
} else {
|
||||
data.mtllayer.displaySyncEnabled = NO;
|
||||
renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return SDL_SetError("This Apple OS does not support displaySyncEnabled!");
|
||||
}
|
||||
|
||||
static SDL_MetalView GetWindowView(SDL_Window *window)
|
||||
{
|
||||
SDL_SysWMinfo info;
|
||||
|
||||
SDL_VERSION(&info.version);
|
||||
if (SDL_GetWindowWMInfo(window, &info)) {
|
||||
#ifdef __MACOSX__
|
||||
if (info.subsystem == SDL_SYSWM_COCOA) {
|
||||
NSView *view = info.info.cocoa.window.contentView;
|
||||
if (view.subviews.count > 0) {
|
||||
view = view.subviews[0];
|
||||
if (view.tag == SDL_METALVIEW_TAG) {
|
||||
return (SDL_MetalView)CFBridgingRetain(view);
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (info.subsystem == SDL_SYSWM_UIKIT) {
|
||||
UIView *view = info.info.uikit.window.rootViewController.view;
|
||||
if (view.tag == SDL_METALVIEW_TAG) {
|
||||
return (SDL_MetalView)CFBridgingRetain(view);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
static SDL_Renderer *
|
||||
METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
{ @autoreleasepool {
|
||||
|
|
@ -1673,7 +1705,10 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
view = SDL_Metal_CreateView(window);
|
||||
view = GetWindowView(window);
|
||||
if (view == nil) {
|
||||
view = SDL_Metal_CreateView(window);
|
||||
}
|
||||
|
||||
if (view == NULL) {
|
||||
#if !__has_feature(objc_arc)
|
||||
|
|
@ -1693,7 +1728,11 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
#if !__has_feature(objc_arc)
|
||||
[mtldevice release];
|
||||
#endif
|
||||
SDL_Metal_DestroyView(view);
|
||||
/* Release the metal view instead of destroying it,
|
||||
in case we want to use it later (recreating the renderer)
|
||||
*/
|
||||
/* SDL_Metal_DestroyView(view); */
|
||||
CFBridgingRelease(view);
|
||||
SDL_free(renderer);
|
||||
if (changed_window) {
|
||||
SDL_RecreateWindow(window, window_flags);
|
||||
|
|
@ -1850,7 +1889,10 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->SupportsBlendMode = METAL_SupportsBlendMode;
|
||||
renderer->CreateTexture = METAL_CreateTexture;
|
||||
renderer->UpdateTexture = METAL_UpdateTexture;
|
||||
#if SDL_HAVE_YUV
|
||||
renderer->UpdateTextureYUV = METAL_UpdateTextureYUV;
|
||||
renderer->UpdateTextureNV = METAL_UpdateTextureNV;
|
||||
#endif
|
||||
renderer->LockTexture = METAL_LockTexture;
|
||||
renderer->UnlockTexture = METAL_UnlockTexture;
|
||||
renderer->SetTextureScaleMode = METAL_SetTextureScaleMode;
|
||||
|
|
@ -1859,14 +1901,13 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->QueueSetDrawColor = METAL_QueueSetDrawColor;
|
||||
renderer->QueueDrawPoints = METAL_QueueDrawPoints;
|
||||
renderer->QueueDrawLines = METAL_QueueDrawLines;
|
||||
renderer->QueueFillRects = METAL_QueueFillRects;
|
||||
renderer->QueueCopy = METAL_QueueCopy;
|
||||
renderer->QueueCopyEx = METAL_QueueCopyEx;
|
||||
renderer->QueueGeometry = METAL_QueueGeometry;
|
||||
renderer->RunCommandQueue = METAL_RunCommandQueue;
|
||||
renderer->RenderReadPixels = METAL_RenderReadPixels;
|
||||
renderer->RenderPresent = METAL_RenderPresent;
|
||||
renderer->DestroyTexture = METAL_DestroyTexture;
|
||||
renderer->DestroyRenderer = METAL_DestroyRenderer;
|
||||
renderer->SetVSync = METAL_SetVSync;
|
||||
renderer->GetMetalLayer = METAL_GetMetalLayer;
|
||||
renderer->GetMetalCommandEncoder = METAL_GetMetalCommandEncoder;
|
||||
|
||||
|
|
@ -1875,7 +1916,7 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
|
||||
renderer->always_batch = SDL_TRUE;
|
||||
|
||||
#if defined(__MACOSX__) && defined(MAC_OS_X_VERSION_10_13)
|
||||
#if (defined(__MACOSX__) && defined(MAC_OS_X_VERSION_10_13)) || TARGET_OS_MACCATALYST
|
||||
if (@available(macOS 10.13, *)) {
|
||||
data.mtllayer.displaySyncEnabled = (flags & SDL_RENDERER_PRESENTVSYNC) != 0;
|
||||
if (data.mtllayer.displaySyncEnabled) {
|
||||
|
|
@ -1889,7 +1930,7 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
|
||||
/* https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf */
|
||||
int maxtexsize = 4096;
|
||||
#if defined(__MACOSX__)
|
||||
#if defined(__MACOSX__) || TARGET_OS_MACCATALYST
|
||||
maxtexsize = 16384;
|
||||
#elif defined(__TVOS__)
|
||||
maxtexsize = 8192;
|
||||
|
|
|
|||
|
|
@ -6,11 +6,13 @@ using namespace metal;
|
|||
struct SolidVertexInput
|
||||
{
|
||||
float2 position [[attribute(0)]];
|
||||
float4 color [[attribute(1)]];
|
||||
};
|
||||
|
||||
struct SolidVertexOutput
|
||||
{
|
||||
float4 position [[position]];
|
||||
float4 color;
|
||||
float pointSize [[point_size]];
|
||||
};
|
||||
|
||||
|
|
@ -20,24 +22,27 @@ vertex SolidVertexOutput SDL_Solid_vertex(SolidVertexInput in [[stage_in]],
|
|||
{
|
||||
SolidVertexOutput v;
|
||||
v.position = (projection * transform) * float4(in.position, 0.0f, 1.0f);
|
||||
v.color = in.color;
|
||||
v.pointSize = 1.0f;
|
||||
return v;
|
||||
}
|
||||
|
||||
fragment float4 SDL_Solid_fragment(const device float4 &col [[buffer(0)]])
|
||||
fragment float4 SDL_Solid_fragment(SolidVertexInput in [[stage_in]])
|
||||
{
|
||||
return col;
|
||||
return in.color;
|
||||
}
|
||||
|
||||
struct CopyVertexInput
|
||||
{
|
||||
float2 position [[attribute(0)]];
|
||||
float2 texcoord [[attribute(1)]];
|
||||
float4 color [[attribute(1)]];
|
||||
float2 texcoord [[attribute(2)]];
|
||||
};
|
||||
|
||||
struct CopyVertexOutput
|
||||
{
|
||||
float4 position [[position]];
|
||||
float4 color;
|
||||
float2 texcoord;
|
||||
};
|
||||
|
||||
|
|
@ -47,16 +52,16 @@ vertex CopyVertexOutput SDL_Copy_vertex(CopyVertexInput in [[stage_in]],
|
|||
{
|
||||
CopyVertexOutput v;
|
||||
v.position = (projection * transform) * float4(in.position, 0.0f, 1.0f);
|
||||
v.color = in.color;
|
||||
v.texcoord = in.texcoord;
|
||||
return v;
|
||||
}
|
||||
|
||||
fragment float4 SDL_Copy_fragment(CopyVertexOutput vert [[stage_in]],
|
||||
const device float4 &col [[buffer(0)]],
|
||||
texture2d<float> tex [[texture(0)]],
|
||||
sampler s [[sampler(0)]])
|
||||
{
|
||||
return tex.sample(s, vert.texcoord) * col;
|
||||
return tex.sample(s, vert.texcoord) * vert.color;
|
||||
}
|
||||
|
||||
struct YUVDecode
|
||||
|
|
@ -68,7 +73,6 @@ struct YUVDecode
|
|||
};
|
||||
|
||||
fragment float4 SDL_YUV_fragment(CopyVertexOutput vert [[stage_in]],
|
||||
const device float4 &col [[buffer(0)]],
|
||||
constant YUVDecode &decode [[buffer(1)]],
|
||||
texture2d<float> texY [[texture(0)]],
|
||||
texture2d_array<float> texUV [[texture(1)]],
|
||||
|
|
@ -81,11 +85,10 @@ fragment float4 SDL_YUV_fragment(CopyVertexOutput vert [[stage_in]],
|
|||
|
||||
yuv += decode.offset;
|
||||
|
||||
return col * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0);
|
||||
return vert.color * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0);
|
||||
}
|
||||
|
||||
fragment float4 SDL_NV12_fragment(CopyVertexOutput vert [[stage_in]],
|
||||
const device float4 &col [[buffer(0)]],
|
||||
constant YUVDecode &decode [[buffer(1)]],
|
||||
texture2d<float> texY [[texture(0)]],
|
||||
texture2d<float> texUV [[texture(1)]],
|
||||
|
|
@ -97,11 +100,10 @@ fragment float4 SDL_NV12_fragment(CopyVertexOutput vert [[stage_in]],
|
|||
|
||||
yuv += decode.offset;
|
||||
|
||||
return col * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0);
|
||||
return vert.color * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0);
|
||||
}
|
||||
|
||||
fragment float4 SDL_NV21_fragment(CopyVertexOutput vert [[stage_in]],
|
||||
const device float4 &col [[buffer(0)]],
|
||||
constant YUVDecode &decode [[buffer(1)]],
|
||||
texture2d<float> texY [[texture(0)]],
|
||||
texture2d<float> texUV [[texture(1)]],
|
||||
|
|
@ -113,5 +115,6 @@ fragment float4 SDL_NV21_fragment(CopyVertexOutput vert [[stage_in]],
|
|||
|
||||
yuv += decode.offset;
|
||||
|
||||
return col * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0);
|
||||
return vert.color * float4(dot(yuv, decode.Rcoeff), dot(yuv, decode.Gcoeff), dot(yuv, decode.Bcoeff), 1.0);
|
||||
}
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -73,7 +73,7 @@ SDL_PROC_UNUSED(void, glColor4i, (GLint, GLint, GLint, GLint))
|
|||
SDL_PROC_UNUSED(void, glColor4iv, (const GLint *))
|
||||
SDL_PROC_UNUSED(void, glColor4s, (GLshort, GLshort, GLshort, GLshort))
|
||||
SDL_PROC_UNUSED(void, glColor4sv, (const GLshort *))
|
||||
SDL_PROC_UNUSED(void, glColor4ub,
|
||||
SDL_PROC(void, glColor4ub,
|
||||
(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha))
|
||||
SDL_PROC_UNUSED(void, glColor4ubv, (const GLubyte * v))
|
||||
SDL_PROC_UNUSED(void, glColor4ui,
|
||||
|
|
@ -86,7 +86,7 @@ SDL_PROC_UNUSED(void, glColorMask,
|
|||
(GLboolean red, GLboolean green, GLboolean blue,
|
||||
GLboolean alpha))
|
||||
SDL_PROC_UNUSED(void, glColorMaterial, (GLenum face, GLenum mode))
|
||||
SDL_PROC_UNUSED(void, glColorPointer,
|
||||
SDL_PROC(void, glColorPointer,
|
||||
(GLint size, GLenum type, GLsizei stride,
|
||||
const GLvoid * pointer))
|
||||
SDL_PROC_UNUSED(void, glCopyPixels,
|
||||
|
|
@ -111,8 +111,8 @@ SDL_PROC(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,
|
||||
|
|
@ -125,7 +125,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))
|
||||
|
|
@ -159,7 +159,7 @@ SDL_PROC_UNUSED(void, glGetBooleanv, (GLenum pname, GLboolean * params))
|
|||
SDL_PROC_UNUSED(void, glGetClipPlane, (GLenum plane, GLdouble * equation))
|
||||
SDL_PROC_UNUSED(void, glGetDoublev, (GLenum pname, GLdouble * params))
|
||||
SDL_PROC(GLenum, glGetError, (void))
|
||||
SDL_PROC_UNUSED(void, glGetFloatv, (GLenum pname, GLfloat * params))
|
||||
SDL_PROC(void, glGetFloatv, (GLenum pname, GLfloat * params))
|
||||
SDL_PROC(void, glGetIntegerv, (GLenum pname, GLint * params))
|
||||
SDL_PROC_UNUSED(void, glGetLightfv,
|
||||
(GLenum light, GLenum pname, GLfloat * params))
|
||||
|
|
@ -302,14 +302,14 @@ SDL_PROC_UNUSED(void, glPolygonOffset, (GLfloat factor, GLfloat units))
|
|||
SDL_PROC_UNUSED(void, glPolygonStipple, (const GLubyte * mask))
|
||||
SDL_PROC_UNUSED(void, glPopAttrib, (void))
|
||||
SDL_PROC_UNUSED(void, glPopClientAttrib, (void))
|
||||
SDL_PROC(void, glPopMatrix, (void))
|
||||
SDL_PROC_UNUSED(void, glPopMatrix, (void))
|
||||
SDL_PROC_UNUSED(void, glPopName, (void))
|
||||
SDL_PROC_UNUSED(void, glPrioritizeTextures,
|
||||
(GLsizei n, const GLuint * textures,
|
||||
const GLclampf * priorities))
|
||||
SDL_PROC_UNUSED(void, glPushAttrib, (GLbitfield mask))
|
||||
SDL_PROC_UNUSED(void, glPushClientAttrib, (GLbitfield mask))
|
||||
SDL_PROC(void, glPushMatrix, (void))
|
||||
SDL_PROC_UNUSED(void, glPushMatrix, (void))
|
||||
SDL_PROC_UNUSED(void, glPushName, (GLuint name))
|
||||
SDL_PROC_UNUSED(void, glRasterPos2d, (GLdouble x, GLdouble y))
|
||||
SDL_PROC_UNUSED(void, glRasterPos2dv, (const GLdouble * v))
|
||||
|
|
@ -354,7 +354,7 @@ SDL_PROC_UNUSED(void, glRects,
|
|||
(GLshort x1, GLshort y1, GLshort x2, GLshort y2))
|
||||
SDL_PROC_UNUSED(void, glRectsv, (const GLshort * v1, const GLshort * v2))
|
||||
SDL_PROC_UNUSED(GLint, glRenderMode, (GLenum mode))
|
||||
SDL_PROC(void, glRotated,
|
||||
SDL_PROC_UNUSED(void, glRotated,
|
||||
(GLdouble angle, GLdouble x, GLdouble y, GLdouble z))
|
||||
SDL_PROC(void, glRotatef,
|
||||
(GLfloat angle, GLfloat x, GLfloat y, GLfloat z))
|
||||
|
|
@ -401,7 +401,7 @@ SDL_PROC_UNUSED(void, glTexCoord4iv, (const GLint * v))
|
|||
SDL_PROC_UNUSED(void, glTexCoord4s,
|
||||
(GLshort s, GLshort t, GLshort r, GLshort q))
|
||||
SDL_PROC_UNUSED(void, glTexCoord4sv, (const GLshort * v))
|
||||
SDL_PROC_UNUSED(void, glTexCoordPointer,
|
||||
SDL_PROC(void, glTexCoordPointer,
|
||||
(GLint size, GLenum type, GLsizei stride,
|
||||
const GLvoid * pointer))
|
||||
SDL_PROC(void, glTexEnvf, (GLenum target, GLenum pname, GLfloat param))
|
||||
|
|
@ -442,7 +442,7 @@ SDL_PROC(void, glTexSubImage2D,
|
|||
GLsizei width, GLsizei height, GLenum format, GLenum type,
|
||||
const GLvoid * pixels))
|
||||
SDL_PROC_UNUSED(void, glTranslated, (GLdouble x, GLdouble y, GLdouble z))
|
||||
SDL_PROC(void, glTranslatef, (GLfloat x, GLfloat y, GLfloat z))
|
||||
SDL_PROC_UNUSED(void, glTranslatef, (GLfloat x, GLfloat y, GLfloat z))
|
||||
SDL_PROC_UNUSED(void, glVertex2d, (GLdouble x, GLdouble y))
|
||||
SDL_PROC_UNUSED(void, glVertex2dv, (const GLdouble * v))
|
||||
SDL_PROC(void, glVertex2f, (GLfloat x, GLfloat y))
|
||||
|
|
@ -470,7 +470,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))
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -149,7 +149,7 @@ struct GL_ShaderContext
|
|||
"uniform sampler2D tex1; // U/V \n" \
|
||||
"\n" \
|
||||
|
||||
#define NV12_SHADER_BODY \
|
||||
#define NV12_RA_SHADER_BODY \
|
||||
"\n" \
|
||||
"void main()\n" \
|
||||
"{\n" \
|
||||
|
|
@ -174,6 +174,31 @@ struct GL_ShaderContext
|
|||
" gl_FragColor = vec4(rgb, 1.0) * v_color;\n" \
|
||||
"}" \
|
||||
|
||||
#define NV12_RG_SHADER_BODY \
|
||||
"\n" \
|
||||
"void main()\n" \
|
||||
"{\n" \
|
||||
" vec2 tcoord;\n" \
|
||||
" vec3 yuv, rgb;\n" \
|
||||
"\n" \
|
||||
" // Get the Y value \n" \
|
||||
" tcoord = v_texCoord;\n" \
|
||||
" yuv.x = texture2D(tex0, tcoord).r;\n" \
|
||||
"\n" \
|
||||
" // Get the U and V values \n" \
|
||||
" tcoord *= UVCoordScale;\n" \
|
||||
" yuv.yz = texture2D(tex1, tcoord).rg;\n" \
|
||||
"\n" \
|
||||
" // Do the color transform \n" \
|
||||
" yuv += offset;\n" \
|
||||
" rgb.r = dot(yuv, Rcoeff);\n" \
|
||||
" rgb.g = dot(yuv, Gcoeff);\n" \
|
||||
" rgb.b = dot(yuv, Bcoeff);\n" \
|
||||
"\n" \
|
||||
" // That was easy. :) \n" \
|
||||
" gl_FragColor = vec4(rgb, 1.0) * v_color;\n" \
|
||||
"}" \
|
||||
|
||||
#define NV21_SHADER_PROLOGUE \
|
||||
"varying vec4 v_color;\n" \
|
||||
"varying vec2 v_texCoord;\n" \
|
||||
|
|
@ -259,7 +284,7 @@ static const char *shader_source[NUM_SHADERS][2] =
|
|||
" gl_FragColor = texture2D(tex0, v_texCoord) * v_color;\n"
|
||||
"}"
|
||||
},
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
/* SHADER_YUV_JPEG */
|
||||
{
|
||||
/* vertex shader */
|
||||
|
|
@ -294,25 +319,43 @@ static const char *shader_source[NUM_SHADERS][2] =
|
|||
/* fragment shader */
|
||||
NV12_SHADER_PROLOGUE
|
||||
JPEG_SHADER_CONSTANTS
|
||||
NV12_SHADER_BODY
|
||||
NV12_RA_SHADER_BODY
|
||||
},
|
||||
/* SHADER_NV12_BT601 */
|
||||
/* SHADER_NV12_RA_BT601 */
|
||||
{
|
||||
/* vertex shader */
|
||||
TEXTURE_VERTEX_SHADER,
|
||||
/* fragment shader */
|
||||
NV12_SHADER_PROLOGUE
|
||||
BT601_SHADER_CONSTANTS
|
||||
NV12_SHADER_BODY
|
||||
NV12_RA_SHADER_BODY
|
||||
},
|
||||
/* SHADER_NV12_BT709 */
|
||||
/* SHADER_NV12_RG_BT601 */
|
||||
{
|
||||
/* vertex shader */
|
||||
TEXTURE_VERTEX_SHADER,
|
||||
/* fragment shader */
|
||||
NV12_SHADER_PROLOGUE
|
||||
BT601_SHADER_CONSTANTS
|
||||
NV12_RG_SHADER_BODY
|
||||
},
|
||||
/* SHADER_NV12_RA_BT709 */
|
||||
{
|
||||
/* vertex shader */
|
||||
TEXTURE_VERTEX_SHADER,
|
||||
/* fragment shader */
|
||||
NV12_SHADER_PROLOGUE
|
||||
BT709_SHADER_CONSTANTS
|
||||
NV12_SHADER_BODY
|
||||
NV12_RA_SHADER_BODY
|
||||
},
|
||||
/* SHADER_NV12_RG_BT709 */
|
||||
{
|
||||
/* vertex shader */
|
||||
TEXTURE_VERTEX_SHADER,
|
||||
/* fragment shader */
|
||||
NV12_SHADER_PROLOGUE
|
||||
BT709_SHADER_CONSTANTS
|
||||
NV12_RG_SHADER_BODY
|
||||
},
|
||||
/* SHADER_NV21_JPEG */
|
||||
{
|
||||
|
|
@ -341,6 +384,7 @@ static const char *shader_source[NUM_SHADERS][2] =
|
|||
BT709_SHADER_CONSTANTS
|
||||
NV21_SHADER_BODY
|
||||
},
|
||||
#endif /* SDL_HAVE_YUV */
|
||||
};
|
||||
|
||||
static SDL_bool
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -32,15 +32,19 @@ typedef enum {
|
|||
SHADER_SOLID,
|
||||
SHADER_RGB,
|
||||
SHADER_RGBA,
|
||||
#if SDL_HAVE_YUV
|
||||
SHADER_YUV_JPEG,
|
||||
SHADER_YUV_BT601,
|
||||
SHADER_YUV_BT709,
|
||||
SHADER_NV12_JPEG,
|
||||
SHADER_NV12_BT601,
|
||||
SHADER_NV12_BT709,
|
||||
SHADER_NV12_RA_BT601,
|
||||
SHADER_NV12_RG_BT601,
|
||||
SHADER_NV12_RA_BT709,
|
||||
SHADER_NV12_RG_BT709,
|
||||
SHADER_NV21_JPEG,
|
||||
SHADER_NV21_BT601,
|
||||
SHADER_NV21_BT709,
|
||||
#endif
|
||||
NUM_SHADERS
|
||||
} GL_Shader;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -27,6 +27,7 @@ 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))
|
||||
SDL_PROC(void, glColorPointer, (GLint, GLenum, GLsizei, const GLvoid *))
|
||||
SDL_PROC(void, glDeleteTextures, (GLsizei, const GLuint *))
|
||||
SDL_PROC(void, glDisable, (GLenum))
|
||||
SDL_PROC(void, glDisableClientState, (GLenum array))
|
||||
|
|
@ -56,10 +57,6 @@ SDL_PROC(void, glViewport, (GLint, GLint, GLsizei, GLsizei))
|
|||
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_OES(void, glDeleteFramebuffersOES, (GLsizei, const GLuint*))
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -564,194 +564,98 @@ static int
|
|||
GLES_QueueDrawLines(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
|
||||
{
|
||||
int i;
|
||||
GLfloat prevx, prevy;
|
||||
const size_t vertlen = (sizeof (GLfloat) * 2) * count;
|
||||
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, vertlen, 0, &cmd->data.draw.first);
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
cmd->data.draw.count = count;
|
||||
|
||||
/* Offset to hit the center of the pixel. */
|
||||
for (i = 0; i < count; i++) {
|
||||
*(verts++) = 0.5f + points[i].x;
|
||||
*(verts++) = 0.5f + points[i].y;
|
||||
/* 0.5f offset to hit the center of the pixel. */
|
||||
prevx = 0.5f + points->x;
|
||||
prevy = 0.5f + points->y;
|
||||
*(verts++) = prevx;
|
||||
*(verts++) = prevy;
|
||||
|
||||
/* bump the end of each line segment out a quarter of a pixel, to provoke
|
||||
the diamond-exit rule. Without this, you won't just drop the last
|
||||
pixel of the last line segment, but you might also drop pixels at the
|
||||
edge of any given line segment along the way too. */
|
||||
for (i = 1; i < count; i++) {
|
||||
const GLfloat xstart = prevx;
|
||||
const GLfloat ystart = prevy;
|
||||
const GLfloat xend = points[i].x + 0.5f; /* 0.5f to hit pixel center. */
|
||||
const GLfloat yend = points[i].y + 0.5f;
|
||||
/* bump a little in the direction we are moving in. */
|
||||
const GLfloat deltax = xend - xstart;
|
||||
const GLfloat deltay = yend - ystart;
|
||||
const GLfloat angle = SDL_atan2f(deltay, deltax);
|
||||
prevx = xend + (SDL_cosf(angle) * 0.25f);
|
||||
prevy = yend + (SDL_sinf(angle) * 0.25f);
|
||||
*(verts++) = prevx;
|
||||
*(verts++) = prevy;
|
||||
}
|
||||
|
||||
/* Make the last line segment one pixel longer, to satisfy the
|
||||
diamond-exit rule. */
|
||||
verts -= 4;
|
||||
{
|
||||
const GLfloat xstart = verts[0];
|
||||
const GLfloat ystart = verts[1];
|
||||
const GLfloat xend = verts[2];
|
||||
const GLfloat yend = verts[3];
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ystart == yend) { /* horizontal line */
|
||||
verts[2] += (xend > xstart) ? 1.0f : -1.0f;
|
||||
} else if (xstart == xend) { /* vertical line */
|
||||
verts[3] += (yend > ystart) ? 1.0f : -1.0f;
|
||||
} else { /* bump a pixel in the direction we are moving in. */
|
||||
const GLfloat deltax = xend - xstart;
|
||||
const GLfloat deltay = yend - ystart;
|
||||
const GLfloat angle = SDL_atan2f(deltay, deltax);
|
||||
verts[2] += SDL_cosf(angle);
|
||||
verts[3] += SDL_sinf(angle);
|
||||
static int
|
||||
GLES_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
|
||||
int num_vertices, const void *indices, int num_indices, int size_indices,
|
||||
float scale_x, float scale_y)
|
||||
{
|
||||
GLES_TextureData *texturedata = NULL;
|
||||
int i;
|
||||
int count = indices ? num_indices : num_vertices;
|
||||
GLfloat *verts;
|
||||
int sz = 2 + 4 + (texture ? 2 : 0);
|
||||
|
||||
verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * sz * sizeof (GLfloat), 0, &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (texture) {
|
||||
texturedata = (GLES_TextureData *) texture->driverdata;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = count;
|
||||
size_indices = indices ? size_indices : 0;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
int j;
|
||||
float *xy_;
|
||||
SDL_Color col_;
|
||||
if (size_indices == 4) {
|
||||
j = ((const Uint32 *)indices)[i];
|
||||
} else if (size_indices == 2) {
|
||||
j = ((const Uint16 *)indices)[i];
|
||||
} else if (size_indices == 1) {
|
||||
j = ((const Uint8 *)indices)[i];
|
||||
} else {
|
||||
j = i;
|
||||
}
|
||||
|
||||
xy_ = (float *)((char*)xy + j * xy_stride);
|
||||
col_ = *(SDL_Color *)((char*)color + j * color_stride);
|
||||
|
||||
*(verts++) = xy_[0] * scale_x;
|
||||
*(verts++) = xy_[1] * scale_y;
|
||||
|
||||
*(verts++) = col_.r * inv255f;
|
||||
*(verts++) = col_.g * inv255f;
|
||||
*(verts++) = col_.b * inv255f;
|
||||
*(verts++) = col_.a * inv255f;
|
||||
|
||||
if (texture) {
|
||||
float *uv_ = (float *)((char*)uv + j * uv_stride);
|
||||
*(verts++) = uv_[0] * texturedata->texw;
|
||||
*(verts++) = uv_[1] * texturedata->texh;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
GLES_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
|
||||
{
|
||||
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, count * 8 * sizeof (GLfloat), 0, &cmd->data.draw.first);
|
||||
int i;
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = count;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
const SDL_FRect *rect = &rects[i];
|
||||
const GLfloat minx = rect->x;
|
||||
const GLfloat maxx = rect->x + rect->w;
|
||||
const GLfloat miny = rect->y;
|
||||
const GLfloat maxy = rect->y + rect->h;
|
||||
*(verts++) = minx;
|
||||
*(verts++) = miny;
|
||||
*(verts++) = maxx;
|
||||
*(verts++) = miny;
|
||||
*(verts++) = minx;
|
||||
*(verts++) = maxy;
|
||||
*(verts++) = maxx;
|
||||
*(verts++) = maxy;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
GLES_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
|
||||
const SDL_Rect * srcrect, const SDL_FRect * dstrect)
|
||||
{
|
||||
GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
|
||||
GLfloat minx, miny, maxx, maxy;
|
||||
GLfloat minu, maxu, minv, maxv;
|
||||
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, 16 * sizeof (GLfloat), 0, &cmd->data.draw.first);
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = 1;
|
||||
|
||||
minx = dstrect->x;
|
||||
miny = dstrect->y;
|
||||
maxx = dstrect->x + dstrect->w;
|
||||
maxy = dstrect->y + dstrect->h;
|
||||
|
||||
minu = (GLfloat) srcrect->x / texture->w;
|
||||
minu *= texturedata->texw;
|
||||
maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
|
||||
maxu *= texturedata->texw;
|
||||
minv = (GLfloat) srcrect->y / texture->h;
|
||||
minv *= texturedata->texh;
|
||||
maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
|
||||
maxv *= texturedata->texh;
|
||||
|
||||
*(verts++) = minx;
|
||||
*(verts++) = miny;
|
||||
*(verts++) = maxx;
|
||||
*(verts++) = miny;
|
||||
*(verts++) = minx;
|
||||
*(verts++) = maxy;
|
||||
*(verts++) = maxx;
|
||||
*(verts++) = maxy;
|
||||
|
||||
*(verts++) = minu;
|
||||
*(verts++) = minv;
|
||||
*(verts++) = maxu;
|
||||
*(verts++) = minv;
|
||||
*(verts++) = minu;
|
||||
*(verts++) = maxv;
|
||||
*(verts++) = maxu;
|
||||
*(verts++) = maxv;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
GLES_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
|
||||
const SDL_Rect * srcquad, const SDL_FRect * dstrect,
|
||||
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
|
||||
{
|
||||
GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
|
||||
GLfloat minx, miny, maxx, maxy;
|
||||
GLfloat centerx, centery;
|
||||
GLfloat minu, maxu, minv, maxv;
|
||||
GLfloat *verts = (GLfloat *) SDL_AllocateRenderVertices(renderer, 19 * sizeof (GLfloat), 0, &cmd->data.draw.first);
|
||||
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
centerx = center->x;
|
||||
centery = center->y;
|
||||
|
||||
if (flip & SDL_FLIP_HORIZONTAL) {
|
||||
minx = dstrect->w - centerx;
|
||||
maxx = -centerx;
|
||||
}
|
||||
else {
|
||||
minx = -centerx;
|
||||
maxx = dstrect->w - centerx;
|
||||
}
|
||||
|
||||
if (flip & SDL_FLIP_VERTICAL) {
|
||||
miny = dstrect->h - centery;
|
||||
maxy = -centery;
|
||||
}
|
||||
else {
|
||||
miny = -centery;
|
||||
maxy = dstrect->h - centery;
|
||||
}
|
||||
|
||||
minu = (GLfloat) srcquad->x / texture->w;
|
||||
minu *= texturedata->texw;
|
||||
maxu = (GLfloat) (srcquad->x + srcquad->w) / texture->w;
|
||||
maxu *= texturedata->texw;
|
||||
minv = (GLfloat) srcquad->y / texture->h;
|
||||
minv *= texturedata->texh;
|
||||
maxv = (GLfloat) (srcquad->y + srcquad->h) / texture->h;
|
||||
maxv *= texturedata->texh;
|
||||
|
||||
cmd->data.draw.count = 1;
|
||||
|
||||
*(verts++) = minx;
|
||||
*(verts++) = miny;
|
||||
*(verts++) = maxx;
|
||||
*(verts++) = miny;
|
||||
*(verts++) = minx;
|
||||
*(verts++) = maxy;
|
||||
*(verts++) = maxx;
|
||||
*(verts++) = maxy;
|
||||
|
||||
*(verts++) = minu;
|
||||
*(verts++) = minv;
|
||||
*(verts++) = maxu;
|
||||
*(verts++) = minv;
|
||||
*(verts++) = minu;
|
||||
*(verts++) = maxv;
|
||||
*(verts++) = maxu;
|
||||
*(verts++) = maxv;
|
||||
|
||||
*(verts++) = (GLfloat) dstrect->x + centerx;
|
||||
*(verts++) = (GLfloat) dstrect->y + centery;
|
||||
*(verts++) = (GLfloat) angle;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -763,7 +667,7 @@ SetDrawState(GLES_RenderData *data, const SDL_RenderCommand *cmd)
|
|||
const Uint8 g = cmd->data.draw.g;
|
||||
const Uint8 b = cmd->data.draw.b;
|
||||
const Uint8 a = cmd->data.draw.a;
|
||||
const Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b);
|
||||
const Uint32 color = (((Uint32)a << 24) | (r << 16) | (g << 8) | b);
|
||||
|
||||
if (color != data->drawstate.color) {
|
||||
const GLfloat fr = ((GLfloat) r) * inv255f;
|
||||
|
|
@ -865,7 +769,6 @@ static int
|
|||
GLES_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertices, size_t vertsize)
|
||||
{
|
||||
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
|
||||
size_t i;
|
||||
|
||||
if (GLES_ActivateRenderer(renderer) < 0) {
|
||||
return -1;
|
||||
|
|
@ -874,7 +777,15 @@ GLES_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vert
|
|||
data->drawstate.target = renderer->target;
|
||||
|
||||
if (!renderer->target) {
|
||||
SDL_GL_GetDrawableSize(renderer->window, &data->drawstate.drawablew, &data->drawstate.drawableh);
|
||||
int w, h;
|
||||
SDL_GL_GetDrawableSize(renderer->window, &w, &h);
|
||||
if ((w != data->drawstate.drawablew) || (h != data->drawstate.drawableh)) {
|
||||
data->drawstate.viewport_dirty = SDL_TRUE; // if the window dimensions changed, invalidate the current viewport, etc.
|
||||
data->drawstate.cliprect_dirty = SDL_TRUE;
|
||||
data->drawstate.drawablew = w;
|
||||
data->drawstate.drawableh = h;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while (cmd) {
|
||||
|
|
@ -910,7 +821,7 @@ GLES_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vert
|
|||
const Uint8 g = cmd->data.color.g;
|
||||
const Uint8 b = cmd->data.color.b;
|
||||
const Uint8 a = cmd->data.color.a;
|
||||
const Uint32 color = ((a << 24) | (r << 16) | (g << 8) | b);
|
||||
const Uint32 color = (((Uint32)a << 24) | (r << 16) | (g << 8) | b);
|
||||
if (color != data->drawstate.clear_color) {
|
||||
const GLfloat fr = ((GLfloat) r) * inv255f;
|
||||
const GLfloat fg = ((GLfloat) g) * inv255f;
|
||||
|
|
@ -949,42 +860,38 @@ GLES_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vert
|
|||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_FILL_RECTS: {
|
||||
case SDL_RENDERCMD_FILL_RECTS: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_COPY: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_COPY_EX: /* unused */
|
||||
break;
|
||||
|
||||
case SDL_RENDERCMD_GEOMETRY: {
|
||||
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
SDL_Texture *texture = cmd->data.draw.texture;
|
||||
const size_t count = cmd->data.draw.count;
|
||||
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
GLsizei offset = 0;
|
||||
SetDrawState(data, cmd);
|
||||
data->glVertexPointer(2, GL_FLOAT, 0, verts);
|
||||
for (i = 0; i < count; ++i, offset += 4) {
|
||||
data->glDrawArrays(GL_TRIANGLE_STRIP, offset, 4);
|
||||
int stride = (2 + 4 + (texture ? 2 : 0)) * sizeof (float);
|
||||
|
||||
if (texture) {
|
||||
SetCopyState(data, cmd);
|
||||
} else {
|
||||
SetDrawState(data, cmd);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_COPY: {
|
||||
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
SetCopyState(data, cmd);
|
||||
data->glVertexPointer(2, GL_FLOAT, 0, verts);
|
||||
data->glTexCoordPointer(2, GL_FLOAT, 0, verts + 8);
|
||||
data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
break;
|
||||
}
|
||||
data->glEnableClientState(GL_COLOR_ARRAY);
|
||||
|
||||
case SDL_RENDERCMD_COPY_EX: {
|
||||
const GLfloat *verts = (GLfloat *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
const GLfloat translatex = verts[16];
|
||||
const GLfloat translatey = verts[17];
|
||||
const GLfloat angle = verts[18];
|
||||
SetCopyState(data, cmd);
|
||||
data->glVertexPointer(2, GL_FLOAT, 0, verts);
|
||||
data->glTexCoordPointer(2, GL_FLOAT, 0, verts + 8);
|
||||
data->glVertexPointer(2, GL_FLOAT, stride, verts);
|
||||
data->glColorPointer(4, GL_FLOAT, stride, verts + 2);
|
||||
if (texture) {
|
||||
data->glTexCoordPointer(2, GL_FLOAT, stride, verts + 2 + 4);
|
||||
}
|
||||
|
||||
/* Translate to flip, rotate, translate to position */
|
||||
data->glPushMatrix();
|
||||
data->glTranslatef(translatex, translatey, 0.0f);
|
||||
data->glRotatef(angle, 0.0, 0.0, 1.0);
|
||||
data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
data->glPopMatrix();
|
||||
data->glDrawArrays(GL_TRIANGLES, 0, (GLsizei) count);
|
||||
|
||||
data->glDisableClientState(GL_COLOR_ARRAY);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -1141,6 +1048,27 @@ static int GLES_UnbindTexture (SDL_Renderer * renderer, SDL_Texture *texture)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
GLES_SetVSync(SDL_Renderer * renderer, const int vsync)
|
||||
{
|
||||
int retval;
|
||||
if (vsync) {
|
||||
retval = SDL_GL_SetSwapInterval(1);
|
||||
} else {
|
||||
retval = SDL_GL_SetSwapInterval(0);
|
||||
}
|
||||
if (retval != 0) {
|
||||
return retval;
|
||||
}
|
||||
if (SDL_GL_GetSwapInterval() > 0) {
|
||||
renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
|
||||
} else {
|
||||
renderer->info.flags &= ~SDL_RENDERER_PRESENTVSYNC;
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
static SDL_Renderer *
|
||||
GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
{
|
||||
|
|
@ -1195,14 +1123,13 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->QueueSetDrawColor = GLES_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
renderer->QueueDrawPoints = GLES_QueueDrawPoints;
|
||||
renderer->QueueDrawLines = GLES_QueueDrawLines;
|
||||
renderer->QueueFillRects = GLES_QueueFillRects;
|
||||
renderer->QueueCopy = GLES_QueueCopy;
|
||||
renderer->QueueCopyEx = GLES_QueueCopyEx;
|
||||
renderer->QueueGeometry = GLES_QueueGeometry;
|
||||
renderer->RunCommandQueue = GLES_RunCommandQueue;
|
||||
renderer->RenderReadPixels = GLES_RenderReadPixels;
|
||||
renderer->RenderPresent = GLES_RenderPresent;
|
||||
renderer->DestroyTexture = GLES_DestroyTexture;
|
||||
renderer->DestroyRenderer = GLES_DestroyRenderer;
|
||||
renderer->SetVSync = GLES_SetVSync;
|
||||
renderer->GL_BindTexture = GLES_BindTexture;
|
||||
renderer->GL_UnbindTexture = GLES_UnbindTexture;
|
||||
renderer->info = GLES_RenderDriver.info;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -41,7 +41,6 @@ SDL_PROC(void, glEnableVertexAttribArray, (GLuint))
|
|||
SDL_PROC(void, glFinish, (void))
|
||||
SDL_PROC(void, glGenFramebuffers, (GLsizei, GLuint *))
|
||||
SDL_PROC(void, glGenTextures, (GLsizei, GLuint *))
|
||||
SDL_PROC(void, glGetBooleanv, (GLenum, GLboolean *))
|
||||
SDL_PROC(const GLubyte *, glGetString, (GLenum))
|
||||
SDL_PROC(GLenum, glGetError, (void))
|
||||
SDL_PROC(void, glGetIntegerv, (GLenum, GLint *))
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -30,60 +30,51 @@
|
|||
/*************************************************************************************************
|
||||
* Vertex/fragment shader source *
|
||||
*************************************************************************************************/
|
||||
/* Notes on a_angle:
|
||||
* It is a vector containing sin and cos for rotation matrix
|
||||
* To get correct rotation for most cases when a_angle is disabled cos
|
||||
value is decremented by 1.0 to get proper output with 0.0 which is
|
||||
default value
|
||||
*/
|
||||
static const Uint8 GLES2_VertexSrc_Default_[] = " \
|
||||
static const Uint8 GLES2_Vertex_Default[] = " \
|
||||
uniform mat4 u_projection; \
|
||||
attribute vec2 a_position; \
|
||||
attribute vec4 a_color; \
|
||||
attribute vec2 a_texCoord; \
|
||||
attribute vec2 a_angle; \
|
||||
attribute vec2 a_center; \
|
||||
varying vec2 v_texCoord; \
|
||||
varying vec4 v_color; \
|
||||
\
|
||||
void main() \
|
||||
{ \
|
||||
float s = a_angle[0]; \
|
||||
float c = a_angle[1] + 1.0; \
|
||||
mat2 rotationMatrix = mat2(c, -s, s, c); \
|
||||
vec2 position = rotationMatrix * (a_position - a_center) + a_center; \
|
||||
v_texCoord = a_texCoord; \
|
||||
gl_Position = u_projection * vec4(position, 0.0, 1.0);\
|
||||
gl_Position = u_projection * vec4(a_position, 0.0, 1.0);\
|
||||
gl_PointSize = 1.0; \
|
||||
v_color = a_color; \
|
||||
} \
|
||||
";
|
||||
|
||||
static const Uint8 GLES2_FragmentSrc_SolidSrc_[] = " \
|
||||
static const Uint8 GLES2_Fragment_Solid[] = " \
|
||||
precision mediump float; \
|
||||
uniform vec4 u_color; \
|
||||
varying vec4 v_color; \
|
||||
\
|
||||
void main() \
|
||||
{ \
|
||||
gl_FragColor = u_color; \
|
||||
gl_FragColor = v_color; \
|
||||
} \
|
||||
";
|
||||
|
||||
static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \
|
||||
static const Uint8 GLES2_Fragment_TextureABGR[] = " \
|
||||
precision mediump float; \
|
||||
uniform sampler2D u_texture; \
|
||||
uniform vec4 u_color; \
|
||||
varying vec4 v_color; \
|
||||
varying vec2 v_texCoord; \
|
||||
\
|
||||
void main() \
|
||||
{ \
|
||||
gl_FragColor = texture2D(u_texture, v_texCoord); \
|
||||
gl_FragColor *= u_color; \
|
||||
gl_FragColor *= v_color; \
|
||||
} \
|
||||
";
|
||||
|
||||
/* ARGB to ABGR conversion */
|
||||
static const Uint8 GLES2_FragmentSrc_TextureARGBSrc_[] = " \
|
||||
static const Uint8 GLES2_Fragment_TextureARGB[] = " \
|
||||
precision mediump float; \
|
||||
uniform sampler2D u_texture; \
|
||||
uniform vec4 u_color; \
|
||||
varying vec4 v_color; \
|
||||
varying vec2 v_texCoord; \
|
||||
\
|
||||
void main() \
|
||||
|
|
@ -92,15 +83,15 @@ static const Uint8 GLES2_FragmentSrc_TextureARGBSrc_[] = " \
|
|||
gl_FragColor = abgr; \
|
||||
gl_FragColor.r = abgr.b; \
|
||||
gl_FragColor.b = abgr.r; \
|
||||
gl_FragColor *= u_color; \
|
||||
gl_FragColor *= v_color; \
|
||||
} \
|
||||
";
|
||||
|
||||
/* RGB to ABGR conversion */
|
||||
static const Uint8 GLES2_FragmentSrc_TextureRGBSrc_[] = " \
|
||||
static const Uint8 GLES2_Fragment_TextureRGB[] = " \
|
||||
precision mediump float; \
|
||||
uniform sampler2D u_texture; \
|
||||
uniform vec4 u_color; \
|
||||
varying vec4 v_color; \
|
||||
varying vec2 v_texCoord; \
|
||||
\
|
||||
void main() \
|
||||
|
|
@ -110,15 +101,15 @@ static const Uint8 GLES2_FragmentSrc_TextureRGBSrc_[] = " \
|
|||
gl_FragColor.r = abgr.b; \
|
||||
gl_FragColor.b = abgr.r; \
|
||||
gl_FragColor.a = 1.0; \
|
||||
gl_FragColor *= u_color; \
|
||||
gl_FragColor *= v_color; \
|
||||
} \
|
||||
";
|
||||
|
||||
/* BGR to ABGR conversion */
|
||||
static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
|
||||
static const Uint8 GLES2_Fragment_TextureBGR[] = " \
|
||||
precision mediump float; \
|
||||
uniform sampler2D u_texture; \
|
||||
uniform vec4 u_color; \
|
||||
varying vec4 v_color; \
|
||||
varying vec2 v_texCoord; \
|
||||
\
|
||||
void main() \
|
||||
|
|
@ -126,10 +117,12 @@ static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
|
|||
vec4 abgr = texture2D(u_texture, v_texCoord); \
|
||||
gl_FragColor = abgr; \
|
||||
gl_FragColor.a = 1.0; \
|
||||
gl_FragColor *= u_color; \
|
||||
gl_FragColor *= v_color; \
|
||||
} \
|
||||
";
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
|
||||
#define JPEG_SHADER_CONSTANTS \
|
||||
"// YUV offset \n" \
|
||||
"const vec3 offset = vec3(0, -0.501960814, -0.501960814);\n" \
|
||||
|
|
@ -163,7 +156,7 @@ static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
|
|||
"uniform sampler2D u_texture;\n" \
|
||||
"uniform sampler2D u_texture_u;\n" \
|
||||
"uniform sampler2D u_texture_v;\n" \
|
||||
"uniform vec4 u_color;\n" \
|
||||
"varying vec4 v_color;\n" \
|
||||
"varying vec2 v_texCoord;\n" \
|
||||
"\n" \
|
||||
|
||||
|
|
@ -185,10 +178,10 @@ static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
|
|||
"\n" \
|
||||
" // That was easy. :) \n" \
|
||||
" gl_FragColor = vec4(rgb, 1);\n" \
|
||||
" gl_FragColor *= u_color;\n" \
|
||||
" gl_FragColor *= v_color;\n" \
|
||||
"}" \
|
||||
|
||||
#define NV12_SHADER_BODY \
|
||||
#define NV12_RA_SHADER_BODY \
|
||||
"\n" \
|
||||
"void main()\n" \
|
||||
"{\n" \
|
||||
|
|
@ -205,7 +198,27 @@ static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
|
|||
"\n" \
|
||||
" // That was easy. :) \n" \
|
||||
" gl_FragColor = vec4(rgb, 1);\n" \
|
||||
" gl_FragColor *= u_color;\n" \
|
||||
" gl_FragColor *= v_color;\n" \
|
||||
"}" \
|
||||
|
||||
#define NV12_RG_SHADER_BODY \
|
||||
"\n" \
|
||||
"void main()\n" \
|
||||
"{\n" \
|
||||
" mediump vec3 yuv;\n" \
|
||||
" lowp vec3 rgb;\n" \
|
||||
"\n" \
|
||||
" // Get the YUV values \n" \
|
||||
" yuv.x = texture2D(u_texture, v_texCoord).r;\n" \
|
||||
" yuv.yz = texture2D(u_texture_u, v_texCoord).rg;\n" \
|
||||
"\n" \
|
||||
" // Do the color transform \n" \
|
||||
" yuv += offset;\n" \
|
||||
" rgb = matrix * yuv;\n" \
|
||||
"\n" \
|
||||
" // That was easy. :) \n" \
|
||||
" gl_FragColor = vec4(rgb, 1);\n" \
|
||||
" gl_FragColor *= v_color;\n" \
|
||||
"}" \
|
||||
|
||||
#define NV21_SHADER_BODY \
|
||||
|
|
@ -225,344 +238,132 @@ static const Uint8 GLES2_FragmentSrc_TextureBGRSrc_[] = " \
|
|||
"\n" \
|
||||
" // That was easy. :) \n" \
|
||||
" gl_FragColor = vec4(rgb, 1);\n" \
|
||||
" gl_FragColor *= u_color;\n" \
|
||||
" gl_FragColor *= v_color;\n" \
|
||||
"}" \
|
||||
|
||||
/* YUV to ABGR conversion */
|
||||
static const Uint8 GLES2_FragmentSrc_TextureYUVJPEGSrc_[] = \
|
||||
static const Uint8 GLES2_Fragment_TextureYUVJPEG[] = \
|
||||
YUV_SHADER_PROLOGUE \
|
||||
JPEG_SHADER_CONSTANTS \
|
||||
YUV_SHADER_BODY \
|
||||
;
|
||||
static const Uint8 GLES2_FragmentSrc_TextureYUVBT601Src_[] = \
|
||||
static const Uint8 GLES2_Fragment_TextureYUVBT601[] = \
|
||||
YUV_SHADER_PROLOGUE \
|
||||
BT601_SHADER_CONSTANTS \
|
||||
YUV_SHADER_BODY \
|
||||
;
|
||||
static const Uint8 GLES2_FragmentSrc_TextureYUVBT709Src_[] = \
|
||||
static const Uint8 GLES2_Fragment_TextureYUVBT709[] = \
|
||||
YUV_SHADER_PROLOGUE \
|
||||
BT709_SHADER_CONSTANTS \
|
||||
YUV_SHADER_BODY \
|
||||
;
|
||||
|
||||
/* NV12 to ABGR conversion */
|
||||
static const Uint8 GLES2_FragmentSrc_TextureNV12JPEGSrc_[] = \
|
||||
static const Uint8 GLES2_Fragment_TextureNV12JPEG[] = \
|
||||
YUV_SHADER_PROLOGUE \
|
||||
JPEG_SHADER_CONSTANTS \
|
||||
NV12_SHADER_BODY \
|
||||
NV12_RA_SHADER_BODY \
|
||||
;
|
||||
static const Uint8 GLES2_FragmentSrc_TextureNV12BT601Src_[] = \
|
||||
static const Uint8 GLES2_Fragment_TextureNV12BT601_RA[] = \
|
||||
YUV_SHADER_PROLOGUE \
|
||||
BT601_SHADER_CONSTANTS \
|
||||
NV12_SHADER_BODY \
|
||||
NV12_RA_SHADER_BODY \
|
||||
;
|
||||
static const Uint8 GLES2_FragmentSrc_TextureNV12BT709Src_[] = \
|
||||
static const Uint8 GLES2_Fragment_TextureNV12BT601_RG[] = \
|
||||
YUV_SHADER_PROLOGUE \
|
||||
BT601_SHADER_CONSTANTS \
|
||||
NV12_RG_SHADER_BODY \
|
||||
;
|
||||
static const Uint8 GLES2_Fragment_TextureNV12BT709_RA[] = \
|
||||
YUV_SHADER_PROLOGUE \
|
||||
BT709_SHADER_CONSTANTS \
|
||||
NV12_SHADER_BODY \
|
||||
NV12_RA_SHADER_BODY \
|
||||
;
|
||||
static const Uint8 GLES2_Fragment_TextureNV12BT709_RG[] = \
|
||||
YUV_SHADER_PROLOGUE \
|
||||
BT709_SHADER_CONSTANTS \
|
||||
NV12_RG_SHADER_BODY \
|
||||
;
|
||||
|
||||
/* NV21 to ABGR conversion */
|
||||
static const Uint8 GLES2_FragmentSrc_TextureNV21JPEGSrc_[] = \
|
||||
static const Uint8 GLES2_Fragment_TextureNV21JPEG[] = \
|
||||
YUV_SHADER_PROLOGUE \
|
||||
JPEG_SHADER_CONSTANTS \
|
||||
NV21_SHADER_BODY \
|
||||
;
|
||||
static const Uint8 GLES2_FragmentSrc_TextureNV21BT601Src_[] = \
|
||||
static const Uint8 GLES2_Fragment_TextureNV21BT601[] = \
|
||||
YUV_SHADER_PROLOGUE \
|
||||
BT601_SHADER_CONSTANTS \
|
||||
NV21_SHADER_BODY \
|
||||
;
|
||||
static const Uint8 GLES2_FragmentSrc_TextureNV21BT709Src_[] = \
|
||||
static const Uint8 GLES2_Fragment_TextureNV21BT709[] = \
|
||||
YUV_SHADER_PROLOGUE \
|
||||
BT709_SHADER_CONSTANTS \
|
||||
NV21_SHADER_BODY \
|
||||
;
|
||||
#endif
|
||||
|
||||
/* Custom Android video format texture */
|
||||
static const Uint8 GLES2_FragmentSrc_TextureExternalOESSrc_[] = " \
|
||||
static const Uint8 GLES2_Fragment_TextureExternalOES[] = " \
|
||||
#extension GL_OES_EGL_image_external : require\n\
|
||||
precision mediump float; \
|
||||
uniform samplerExternalOES u_texture; \
|
||||
uniform vec4 u_color; \
|
||||
varying vec4 v_color; \
|
||||
varying vec2 v_texCoord; \
|
||||
\
|
||||
void main() \
|
||||
{ \
|
||||
gl_FragColor = texture2D(u_texture, v_texCoord); \
|
||||
gl_FragColor *= u_color; \
|
||||
gl_FragColor *= v_color; \
|
||||
} \
|
||||
";
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_VertexSrc_Default = {
|
||||
GL_VERTEX_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_VertexSrc_Default_),
|
||||
GLES2_VertexSrc_Default_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_SolidSrc = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_SolidSrc_),
|
||||
GLES2_FragmentSrc_SolidSrc_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureABGRSrc = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureABGRSrc_),
|
||||
GLES2_FragmentSrc_TextureABGRSrc_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureARGBSrc = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureARGBSrc_),
|
||||
GLES2_FragmentSrc_TextureARGBSrc_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureRGBSrc = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureRGBSrc_),
|
||||
GLES2_FragmentSrc_TextureRGBSrc_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureBGRSrc = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureBGRSrc_),
|
||||
GLES2_FragmentSrc_TextureBGRSrc_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureYUVJPEGSrc = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureYUVJPEGSrc_),
|
||||
GLES2_FragmentSrc_TextureYUVJPEGSrc_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureYUVBT601Src = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureYUVBT601Src_),
|
||||
GLES2_FragmentSrc_TextureYUVBT601Src_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureYUVBT709Src = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureYUVBT709Src_),
|
||||
GLES2_FragmentSrc_TextureYUVBT709Src_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV12JPEGSrc = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureNV12JPEGSrc_),
|
||||
GLES2_FragmentSrc_TextureNV12JPEGSrc_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV12BT601Src = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureNV12BT601Src_),
|
||||
GLES2_FragmentSrc_TextureNV12BT601Src_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV21BT709Src = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureNV21BT709Src_),
|
||||
GLES2_FragmentSrc_TextureNV21BT709Src_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV21JPEGSrc = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureNV21JPEGSrc_),
|
||||
GLES2_FragmentSrc_TextureNV21JPEGSrc_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV21BT601Src = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureNV21BT601Src_),
|
||||
GLES2_FragmentSrc_TextureNV21BT601Src_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureNV12BT709Src = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureNV12BT709Src_),
|
||||
GLES2_FragmentSrc_TextureNV12BT709Src_
|
||||
};
|
||||
|
||||
static const GLES2_ShaderInstance GLES2_FragmentSrc_TextureExternalOESSrc = {
|
||||
GL_FRAGMENT_SHADER,
|
||||
GLES2_SOURCE_SHADER,
|
||||
sizeof(GLES2_FragmentSrc_TextureExternalOESSrc_),
|
||||
GLES2_FragmentSrc_TextureExternalOESSrc_
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************************************
|
||||
* Vertex/fragment shader definitions *
|
||||
*************************************************************************************************/
|
||||
|
||||
static GLES2_Shader GLES2_VertexShader_Default = {
|
||||
1,
|
||||
{
|
||||
&GLES2_VertexSrc_Default
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_SolidSrc = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_SolidSrc
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureABGRSrc = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureABGRSrc
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureARGBSrc = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureARGBSrc
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureRGBSrc = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureRGBSrc
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureBGRSrc = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureBGRSrc
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureYUVJPEGSrc = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureYUVJPEGSrc
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureYUVBT601Src = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureYUVBT601Src
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureYUVBT709Src = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureYUVBT709Src
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureNV12JPEGSrc = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureNV12JPEGSrc
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureNV12BT601Src = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureNV12BT601Src
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureNV12BT709Src = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureNV12BT709Src
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureNV21JPEGSrc = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureNV21JPEGSrc
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureNV21BT601Src = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureNV21BT601Src
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureNV21BT709Src = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureNV21BT709Src
|
||||
}
|
||||
};
|
||||
|
||||
static GLES2_Shader GLES2_FragmentShader_TextureExternalOESSrc = {
|
||||
1,
|
||||
{
|
||||
&GLES2_FragmentSrc_TextureExternalOESSrc
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************************************************
|
||||
* Shader selector *
|
||||
*************************************************************************************************/
|
||||
|
||||
const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type)
|
||||
const Uint8 *GLES2_GetShader(GLES2_ShaderType type)
|
||||
{
|
||||
switch (type) {
|
||||
case GLES2_SHADER_VERTEX_DEFAULT:
|
||||
return &GLES2_VertexShader_Default;
|
||||
case GLES2_SHADER_FRAGMENT_SOLID_SRC:
|
||||
return &GLES2_FragmentShader_SolidSrc;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC:
|
||||
return &GLES2_FragmentShader_TextureABGRSrc;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC:
|
||||
return &GLES2_FragmentShader_TextureARGBSrc;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC:
|
||||
return &GLES2_FragmentShader_TextureRGBSrc;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC:
|
||||
return &GLES2_FragmentShader_TextureBGRSrc;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_YUV_JPEG_SRC:
|
||||
return &GLES2_FragmentShader_TextureYUVJPEGSrc;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT601_SRC:
|
||||
return &GLES2_FragmentShader_TextureYUVBT601Src;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT709_SRC:
|
||||
return &GLES2_FragmentShader_TextureYUVBT709Src;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV12_JPEG_SRC:
|
||||
return &GLES2_FragmentShader_TextureNV12JPEGSrc;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV12_BT601_SRC:
|
||||
return &GLES2_FragmentShader_TextureNV12BT601Src;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV12_BT709_SRC:
|
||||
return &GLES2_FragmentShader_TextureNV12BT709Src;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV21_JPEG_SRC:
|
||||
return &GLES2_FragmentShader_TextureNV21JPEGSrc;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT601_SRC:
|
||||
return &GLES2_FragmentShader_TextureNV21BT601Src;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT709_SRC:
|
||||
return &GLES2_FragmentShader_TextureNV21BT709Src;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_EXTERNAL_OES_SRC:
|
||||
return &GLES2_FragmentShader_TextureExternalOESSrc;
|
||||
return GLES2_Vertex_Default;
|
||||
case GLES2_SHADER_FRAGMENT_SOLID:
|
||||
return GLES2_Fragment_Solid;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_ABGR:
|
||||
return GLES2_Fragment_TextureABGR;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_ARGB:
|
||||
return GLES2_Fragment_TextureARGB;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_RGB:
|
||||
return GLES2_Fragment_TextureRGB;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_BGR:
|
||||
return GLES2_Fragment_TextureBGR;
|
||||
#if SDL_HAVE_YUV
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_YUV_JPEG:
|
||||
return GLES2_Fragment_TextureYUVJPEG;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT601:
|
||||
return GLES2_Fragment_TextureYUVBT601;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT709:
|
||||
return GLES2_Fragment_TextureYUVBT709;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV12_JPEG:
|
||||
return GLES2_Fragment_TextureNV12JPEG;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV12_RA_BT601:
|
||||
return GLES2_Fragment_TextureNV12BT601_RA;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV12_RG_BT601:
|
||||
return GLES2_Fragment_TextureNV12BT601_RG;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV12_RA_BT709:
|
||||
return GLES2_Fragment_TextureNV12BT709_RA;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV12_RG_BT709:
|
||||
return GLES2_Fragment_TextureNV12BT709_RG;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV21_JPEG:
|
||||
return GLES2_Fragment_TextureNV21JPEG;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT601:
|
||||
return GLES2_Fragment_TextureNV21BT601;
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT709:
|
||||
return GLES2_Fragment_TextureNV21BT709;
|
||||
#endif
|
||||
case GLES2_SHADER_FRAGMENT_TEXTURE_EXTERNAL_OES:
|
||||
return GLES2_Fragment_TextureExternalOES;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -25,43 +25,33 @@
|
|||
|
||||
#if SDL_VIDEO_RENDER_OGL_ES2
|
||||
|
||||
typedef struct GLES2_ShaderInstance
|
||||
{
|
||||
GLenum type;
|
||||
GLenum format;
|
||||
int length;
|
||||
const void *data;
|
||||
} GLES2_ShaderInstance;
|
||||
|
||||
typedef struct GLES2_Shader
|
||||
{
|
||||
int instance_count;
|
||||
const GLES2_ShaderInstance *instances[4];
|
||||
} GLES2_Shader;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GLES2_SHADER_VERTEX_DEFAULT,
|
||||
GLES2_SHADER_FRAGMENT_SOLID_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_ABGR_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_ARGB_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_BGR_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_RGB_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_YUV_JPEG_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT601_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT709_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV12_JPEG_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV12_BT601_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV12_BT709_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV21_JPEG_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT601_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT709_SRC,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_EXTERNAL_OES_SRC
|
||||
GLES2_SHADER_VERTEX_DEFAULT = 0,
|
||||
GLES2_SHADER_FRAGMENT_SOLID,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_ABGR,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_ARGB,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_BGR,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_RGB,
|
||||
#if SDL_HAVE_YUV
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_YUV_JPEG,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT601,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_YUV_BT709,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV12_JPEG,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV12_RA_BT601,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV12_RG_BT601,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV12_RA_BT709,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV12_RG_BT709,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV21_JPEG,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT601,
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_NV21_BT709,
|
||||
#endif
|
||||
GLES2_SHADER_FRAGMENT_TEXTURE_EXTERNAL_OES,
|
||||
GLES2_SHADER_COUNT
|
||||
} GLES2_ShaderType;
|
||||
|
||||
#define GLES2_SOURCE_SHADER (GLenum)-1
|
||||
|
||||
const GLES2_Shader *GLES2_GetShader(GLES2_ShaderType type);
|
||||
const Uint8 *GLES2_GetShader(GLES2_ShaderType type);
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_OGL_ES2 */
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -220,7 +220,7 @@ SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
SDL_Rect clipped;
|
||||
|
||||
if (!dst) {
|
||||
return SDL_SetError("Passed NULL destination surface");
|
||||
return SDL_InvalidParamError("SDL_BlendFillRect(): dst");
|
||||
}
|
||||
|
||||
/* This function doesn't work on surfaces < 8 bpp */
|
||||
|
|
@ -291,7 +291,7 @@ SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
|
|||
int status = 0;
|
||||
|
||||
if (!dst) {
|
||||
return SDL_SetError("Passed NULL destination surface");
|
||||
return SDL_InvalidParamError("SDL_BlendFillRects(): dst");
|
||||
}
|
||||
|
||||
/* This function doesn't work on surfaces < 8 bpp */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -809,7 +809,7 @@ SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
BlendLineFunc func;
|
||||
|
||||
if (!dst) {
|
||||
return SDL_SetError("SDL_BlendLine(): Passed NULL destination surface");
|
||||
return SDL_InvalidParamError("SDL_BlendLine(): dst");
|
||||
}
|
||||
|
||||
func = SDL_CalculateBlendLineFunc(dst->format);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -218,7 +218,7 @@ SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r
|
|||
Uint8 g, Uint8 b, Uint8 a)
|
||||
{
|
||||
if (!dst) {
|
||||
return SDL_SetError("Passed NULL destination surface");
|
||||
return SDL_InvalidParamError("SDL_BlendPoint(): dst");
|
||||
}
|
||||
|
||||
/* This function doesn't work on surfaces < 8 bpp */
|
||||
|
|
@ -287,7 +287,7 @@ SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
int status = 0;
|
||||
|
||||
if (!dst) {
|
||||
return SDL_SetError("Passed NULL destination surface");
|
||||
return SDL_InvalidParamError("SDL_BlendPoints(): dst");
|
||||
}
|
||||
|
||||
/* This function doesn't work on surfaces < 8 bpp */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -618,10 +618,10 @@ do { \
|
|||
while (height--) { \
|
||||
{ int n = (width+3)/4; \
|
||||
switch (width & 3) { \
|
||||
case 0: do { op; pixel++; /* fallthrough */ \
|
||||
case 3: op; pixel++; /* fallthrough */ \
|
||||
case 2: op; pixel++; /* fallthrough */ \
|
||||
case 1: op; pixel++; /* fallthrough */ \
|
||||
case 0: do { op; pixel++; SDL_FALLTHROUGH; \
|
||||
case 3: op; pixel++; SDL_FALLTHROUGH; \
|
||||
case 2: op; pixel++; SDL_FALLTHROUGH; \
|
||||
case 1: op; pixel++; \
|
||||
} while ( --n > 0 ); \
|
||||
} \
|
||||
} \
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -144,7 +144,7 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
|
|||
DrawLineFunc func;
|
||||
|
||||
if (!dst) {
|
||||
return SDL_SetError("SDL_DrawLine(): Passed NULL destination surface");
|
||||
return SDL_InvalidParamError("SDL_DrawLine(): dst");
|
||||
}
|
||||
|
||||
func = SDL_CalculateDrawLineFunc(dst->format);
|
||||
|
|
@ -173,7 +173,7 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
DrawLineFunc func;
|
||||
|
||||
if (!dst) {
|
||||
return SDL_SetError("SDL_DrawLines(): Passed NULL destination surface");
|
||||
return SDL_InvalidParamError("SDL_DrawLines(): dst");
|
||||
}
|
||||
|
||||
func = SDL_CalculateDrawLineFunc(dst->format);
|
||||
|
|
@ -193,8 +193,8 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
continue;
|
||||
}
|
||||
|
||||
/* Draw the end if it was clipped */
|
||||
draw_end = (x2 != points[i].x || y2 != points[i].y);
|
||||
/* Draw the end if the whole line is a single point or it was clipped */
|
||||
draw_end = ((x1 == x2) && (y1 == y2)) || (x2 != points[i].x || y2 != points[i].y);
|
||||
|
||||
func(dst, x1, y1, x2, y2, color, draw_end);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -30,7 +30,7 @@ int
|
|||
SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
|
||||
{
|
||||
if (!dst) {
|
||||
return SDL_SetError("Passed NULL destination surface");
|
||||
return SDL_InvalidParamError("SDL_DrawPoint(): dst");
|
||||
}
|
||||
|
||||
/* This function doesn't work on surfaces < 8 bpp */
|
||||
|
|
@ -71,7 +71,7 @@ SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
int x, y;
|
||||
|
||||
if (!dst) {
|
||||
return SDL_SetError("Passed NULL destination surface");
|
||||
return SDL_InvalidParamError("SDL_DrawPoints(): dst");
|
||||
}
|
||||
|
||||
/* This function doesn't work on surfaces < 8 bpp */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -33,6 +33,7 @@
|
|||
#include "SDL_drawline.h"
|
||||
#include "SDL_drawpoint.h"
|
||||
#include "SDL_rotate.h"
|
||||
#include "SDL_triangle.h"
|
||||
|
||||
/* SDL surface based renderer implementation */
|
||||
|
||||
|
|
@ -98,8 +99,7 @@ SW_GetOutputSize(SDL_Renderer * renderer, int *w, int *h)
|
|||
return 0;
|
||||
}
|
||||
|
||||
SDL_SetError("Software renderer doesn't have an output surface");
|
||||
return -1;
|
||||
return SDL_SetError("Software renderer doesn't have an output surface");
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -116,9 +116,8 @@ SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
texture->driverdata =
|
||||
SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
|
||||
Bmask, Amask);
|
||||
SDL_SetSurfaceColorMod(texture->driverdata, texture->r, texture->g,
|
||||
texture->b);
|
||||
SDL_SetSurfaceAlphaMod(texture->driverdata, texture->a);
|
||||
SDL_SetSurfaceColorMod(texture->driverdata, texture->color.r, texture->color.g, texture->color.b);
|
||||
SDL_SetSurfaceAlphaMod(texture->driverdata, texture->color.a);
|
||||
SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode);
|
||||
|
||||
/* Only RLE encode textures without an alpha channel since the RLE coder
|
||||
|
|
@ -214,18 +213,9 @@ SW_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FP
|
|||
|
||||
cmd->data.draw.count = count;
|
||||
|
||||
if (renderer->viewport.x || renderer->viewport.y) {
|
||||
const int x = renderer->viewport.x;
|
||||
const int y = renderer->viewport.y;
|
||||
for (i = 0; i < count; i++, verts++, points++) {
|
||||
verts->x = (int)(x + points->x);
|
||||
verts->y = (int)(y + points->y);
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < count; i++, verts++, points++) {
|
||||
verts->x = (int)points->x;
|
||||
verts->y = (int)points->y;
|
||||
}
|
||||
for (i = 0; i < count; i++, verts++, points++) {
|
||||
verts->x = (int)points->x;
|
||||
verts->y = (int)points->y;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -243,23 +233,11 @@ SW_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRe
|
|||
|
||||
cmd->data.draw.count = count;
|
||||
|
||||
if (renderer->viewport.x || renderer->viewport.y) {
|
||||
const int x = renderer->viewport.x;
|
||||
const int y = renderer->viewport.y;
|
||||
|
||||
for (i = 0; i < count; i++, verts++, rects++) {
|
||||
verts->x = (int)(x + rects->x);
|
||||
verts->y = (int)(y + rects->y);
|
||||
verts->w = SDL_max((int)rects->w, 1);
|
||||
verts->h = SDL_max((int)rects->h, 1);
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < count; i++, verts++, rects++) {
|
||||
verts->x = (int)rects->x;
|
||||
verts->y = (int)rects->y;
|
||||
verts->w = SDL_max((int)rects->w, 1);
|
||||
verts->h = SDL_max((int)rects->h, 1);
|
||||
}
|
||||
for (i = 0; i < count; i++, verts++, rects++) {
|
||||
verts->x = (int)rects->x;
|
||||
verts->y = (int)rects->y;
|
||||
verts->w = SDL_max((int)rects->w, 1);
|
||||
verts->h = SDL_max((int)rects->h, 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
@ -280,13 +258,8 @@ SW_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * text
|
|||
SDL_memcpy(verts, srcrect, sizeof (SDL_Rect));
|
||||
verts++;
|
||||
|
||||
if (renderer->viewport.x || renderer->viewport.y) {
|
||||
verts->x = (int)(renderer->viewport.x + dstrect->x);
|
||||
verts->y = (int)(renderer->viewport.y + dstrect->y);
|
||||
} else {
|
||||
verts->x = (int)dstrect->x;
|
||||
verts->y = (int)dstrect->y;
|
||||
}
|
||||
verts->x = (int)dstrect->x;
|
||||
verts->y = (int)dstrect->y;
|
||||
verts->w = (int)dstrect->w;
|
||||
verts->h = (int)dstrect->h;
|
||||
|
||||
|
|
@ -300,12 +273,14 @@ typedef struct CopyExData
|
|||
double angle;
|
||||
SDL_FPoint center;
|
||||
SDL_RendererFlip flip;
|
||||
float scale_x;
|
||||
float scale_y;
|
||||
} CopyExData;
|
||||
|
||||
static int
|
||||
SW_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * texture,
|
||||
const SDL_Rect * srcrect, const SDL_FRect * dstrect,
|
||||
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip)
|
||||
const double angle, const SDL_FPoint *center, const SDL_RendererFlip flip, float scale_x, float scale_y)
|
||||
{
|
||||
CopyExData *verts = (CopyExData *) SDL_AllocateRenderVertices(renderer, sizeof (CopyExData), 0, &cmd->data.draw.first);
|
||||
|
||||
|
|
@ -317,33 +292,48 @@ SW_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * te
|
|||
|
||||
SDL_memcpy(&verts->srcrect, srcrect, sizeof (SDL_Rect));
|
||||
|
||||
if (renderer->viewport.x || renderer->viewport.y) {
|
||||
verts->dstrect.x = (int)(renderer->viewport.x + dstrect->x);
|
||||
verts->dstrect.y = (int)(renderer->viewport.y + dstrect->y);
|
||||
} else {
|
||||
verts->dstrect.x = (int)dstrect->x;
|
||||
verts->dstrect.y = (int)dstrect->y;
|
||||
}
|
||||
verts->dstrect.x = (int)dstrect->x;
|
||||
verts->dstrect.y = (int)dstrect->y;
|
||||
verts->dstrect.w = (int)dstrect->w;
|
||||
verts->dstrect.h = (int)dstrect->h;
|
||||
verts->angle = angle;
|
||||
SDL_memcpy(&verts->center, center, sizeof (SDL_FPoint));
|
||||
verts->flip = flip;
|
||||
verts->scale_x = scale_x;
|
||||
verts->scale_y = scale_y;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
Blit_to_Screen(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *surface, SDL_Rect *dstrect,
|
||||
float scale_x, float scale_y, SDL_ScaleMode scaleMode)
|
||||
{
|
||||
int retval;
|
||||
/* Renderer scaling, if needed */
|
||||
if (scale_x != 1.0f || scale_y != 1.0f) {
|
||||
SDL_Rect r;
|
||||
r.x = (int)((float) dstrect->x * scale_x);
|
||||
r.y = (int)((float) dstrect->y * scale_y);
|
||||
r.w = (int)((float) dstrect->w * scale_x);
|
||||
r.h = (int)((float) dstrect->h * scale_y);
|
||||
retval = SDL_PrivateUpperBlitScaled(src, srcrect, surface, &r, scaleMode);
|
||||
} else {
|
||||
retval = SDL_BlitSurface(src, srcrect, surface, dstrect);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
static int
|
||||
SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * texture,
|
||||
const SDL_Rect * srcrect, const SDL_Rect * final_rect,
|
||||
const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip)
|
||||
const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip, float scale_x, float scale_y)
|
||||
{
|
||||
SDL_Surface *src = (SDL_Surface *) texture->driverdata;
|
||||
SDL_Rect tmp_rect;
|
||||
SDL_Surface *src_clone, *src_rotated, *src_scaled;
|
||||
SDL_Surface *mask = NULL, *mask_rotated = NULL;
|
||||
int retval = 0, dstwidth, dstheight, abscenterx, abscentery;
|
||||
double cangle, sangle, px, py, p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y;
|
||||
int retval = 0;
|
||||
SDL_BlendMode blendmode;
|
||||
Uint8 alphaMod, rMod, gMod, bMod;
|
||||
int applyModulation = SDL_FALSE;
|
||||
|
|
@ -434,7 +424,7 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
|
|||
retval = -1;
|
||||
} else {
|
||||
SDL_SetSurfaceBlendMode(src_clone, SDL_BLENDMODE_NONE);
|
||||
retval = SDL_BlitScaled(src_clone, srcrect, src_scaled, &scale_rect);
|
||||
retval = SDL_PrivateUpperBlitScaled(src_clone, srcrect, src_scaled, &scale_rect, texture->scaleMode);
|
||||
SDL_FreeSurface(src_clone);
|
||||
src_clone = src_scaled;
|
||||
src_scaled = NULL;
|
||||
|
|
@ -445,53 +435,32 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
|
|||
SDL_SetSurfaceBlendMode(src_clone, blendmode);
|
||||
|
||||
if (!retval) {
|
||||
SDLgfx_rotozoomSurfaceSizeTrig(tmp_rect.w, tmp_rect.h, angle, &dstwidth, &dstheight, &cangle, &sangle);
|
||||
src_rotated = SDLgfx_rotateSurface(src_clone, angle, dstwidth/2, dstheight/2, (texture->scaleMode == SDL_ScaleModeNearest) ? 0 : 1, flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL, dstwidth, dstheight, cangle, sangle);
|
||||
SDL_Rect rect_dest;
|
||||
double cangle, sangle;
|
||||
|
||||
SDLgfx_rotozoomSurfaceSizeTrig(tmp_rect.w, tmp_rect.h, angle, center,
|
||||
&rect_dest, &cangle, &sangle);
|
||||
src_rotated = SDLgfx_rotateSurface(src_clone, angle,
|
||||
(texture->scaleMode == SDL_ScaleModeNearest) ? 0 : 1, flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL,
|
||||
&rect_dest, cangle, sangle, center);
|
||||
if (src_rotated == NULL) {
|
||||
retval = -1;
|
||||
}
|
||||
if (!retval && mask != NULL) {
|
||||
/* The mask needed for the NONE blend mode gets rotated with the same parameters. */
|
||||
mask_rotated = SDLgfx_rotateSurface(mask, angle, dstwidth/2, dstheight/2, SDL_FALSE, 0, 0, dstwidth, dstheight, cangle, sangle);
|
||||
mask_rotated = SDLgfx_rotateSurface(mask, angle,
|
||||
SDL_FALSE, 0, 0,
|
||||
&rect_dest, cangle, sangle, center);
|
||||
if (mask_rotated == NULL) {
|
||||
retval = -1;
|
||||
}
|
||||
}
|
||||
if (!retval) {
|
||||
/* 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;
|
||||
abscentery = final_rect->y + (int)center->y;
|
||||
/* Compensate the angle inversion to match the behaviour of the other backends */
|
||||
sangle = -sangle;
|
||||
|
||||
/* Top Left */
|
||||
px = final_rect->x - abscenterx;
|
||||
py = final_rect->y - abscentery;
|
||||
p1x = px * cangle - py * sangle + abscenterx;
|
||||
p1y = px * sangle + py * cangle + abscentery;
|
||||
|
||||
/* Top Right */
|
||||
px = final_rect->x + final_rect->w - abscenterx;
|
||||
py = final_rect->y - abscentery;
|
||||
p2x = px * cangle - py * sangle + abscenterx;
|
||||
p2y = px * sangle + py * cangle + abscentery;
|
||||
|
||||
/* Bottom Left */
|
||||
px = final_rect->x - abscenterx;
|
||||
py = final_rect->y + final_rect->h - abscentery;
|
||||
p3x = px * cangle - py * sangle + abscenterx;
|
||||
p3y = px * sangle + py * cangle + abscentery;
|
||||
|
||||
/* Bottom Right */
|
||||
px = final_rect->x + final_rect->w - abscenterx;
|
||||
py = final_rect->y + final_rect->h - abscentery;
|
||||
p4x = px * cangle - py * sangle + abscenterx;
|
||||
p4y = px * sangle + py * cangle + abscentery;
|
||||
|
||||
tmp_rect.x = (int)MIN(MIN(p1x, p2x), MIN(p3x, p4x));
|
||||
tmp_rect.y = (int)MIN(MIN(p1y, p2y), MIN(p3y, p4y));
|
||||
tmp_rect.w = dstwidth;
|
||||
tmp_rect.h = dstheight;
|
||||
tmp_rect.x = final_rect->x + rect_dest.x;
|
||||
tmp_rect.y = final_rect->y + rect_dest.y;
|
||||
tmp_rect.w = rect_dest.w;
|
||||
tmp_rect.h = rect_dest.h;
|
||||
|
||||
/* The NONE blend mode needs some special care with non-opaque surfaces.
|
||||
* Other blend modes or opaque surfaces can be blitted directly.
|
||||
|
|
@ -502,7 +471,8 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
|
|||
SDL_SetSurfaceAlphaMod(src_rotated, alphaMod);
|
||||
SDL_SetSurfaceColorMod(src_rotated, rMod, gMod, bMod);
|
||||
}
|
||||
retval = SDL_BlitSurface(src_rotated, NULL, surface, &tmp_rect);
|
||||
/* Renderer scaling, if needed */
|
||||
retval = Blit_to_Screen(src_rotated, NULL, surface, &tmp_rect, scale_x, scale_y, texture->scaleMode);
|
||||
} else {
|
||||
/* The NONE blend mode requires three steps to get the pixels onto the destination surface.
|
||||
* First, the area where the rotated pixels will be blitted to get set to zero.
|
||||
|
|
@ -511,7 +481,8 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
|
|||
*/
|
||||
SDL_Rect mask_rect = tmp_rect;
|
||||
SDL_SetSurfaceBlendMode(mask_rotated, SDL_BLENDMODE_NONE);
|
||||
retval = SDL_BlitSurface(mask_rotated, NULL, surface, &mask_rect);
|
||||
/* Renderer scaling, if needed */
|
||||
retval = Blit_to_Screen(mask_rotated, NULL, surface, &mask_rect, scale_x, scale_y, texture->scaleMode);
|
||||
if (!retval) {
|
||||
/* The next step copies the alpha value. This is done with the BLEND blend mode and
|
||||
* by modulating the source colors with 0. Since the destination is all zeros, this
|
||||
|
|
@ -519,7 +490,8 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
|
|||
*/
|
||||
SDL_SetSurfaceColorMod(src_rotated, 0, 0, 0);
|
||||
mask_rect = tmp_rect;
|
||||
retval = SDL_BlitSurface(src_rotated, NULL, surface, &mask_rect);
|
||||
/* Renderer scaling, if needed */
|
||||
retval = Blit_to_Screen(src_rotated, NULL, surface, &mask_rect, scale_x, scale_y, texture->scaleMode);
|
||||
if (!retval) {
|
||||
/* The last step gets the color values in place. The ADD blend mode simply adds them to
|
||||
* the destination (where the color values are all zero). However, because the ADD blend
|
||||
|
|
@ -535,7 +507,8 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
|
|||
retval = -1;
|
||||
} else {
|
||||
SDL_SetSurfaceBlendMode(src_rotated_rgb, SDL_BLENDMODE_ADD);
|
||||
retval = SDL_BlitSurface(src_rotated_rgb, NULL, surface, &tmp_rect);
|
||||
/* Renderer scaling, if needed */
|
||||
retval = Blit_to_Screen(src_rotated_rgb, NULL, surface, &tmp_rect, scale_x, scale_y, texture->scaleMode);
|
||||
SDL_FreeSurface(src_rotated_rgb);
|
||||
}
|
||||
}
|
||||
|
|
@ -560,6 +533,104 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
|
|||
return retval;
|
||||
}
|
||||
|
||||
|
||||
typedef struct GeometryFillData
|
||||
{
|
||||
SDL_Point dst;
|
||||
SDL_Color color;
|
||||
} GeometryFillData;
|
||||
|
||||
typedef struct GeometryCopyData
|
||||
{
|
||||
SDL_Point src;
|
||||
SDL_Point dst;
|
||||
SDL_Color color;
|
||||
} GeometryCopyData;
|
||||
|
||||
static int
|
||||
SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_Texture *texture,
|
||||
const float *xy, int xy_stride, const SDL_Color *color, int color_stride, const float *uv, int uv_stride,
|
||||
int num_vertices, const void *indices, int num_indices, int size_indices,
|
||||
float scale_x, float scale_y)
|
||||
{
|
||||
int i;
|
||||
int count = indices ? num_indices : num_vertices;
|
||||
void *verts;
|
||||
int sz = texture ? sizeof (GeometryCopyData) : sizeof (GeometryFillData);
|
||||
|
||||
verts = (void *) SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
cmd->data.draw.count = count;
|
||||
size_indices = indices ? size_indices : 0;
|
||||
|
||||
if (texture) {
|
||||
GeometryCopyData *ptr = (GeometryCopyData *) verts;
|
||||
for (i = 0; i < count; i++) {
|
||||
int j;
|
||||
float *xy_;
|
||||
SDL_Color col_;
|
||||
float *uv_;
|
||||
if (size_indices == 4) {
|
||||
j = ((const Uint32 *)indices)[i];
|
||||
} else if (size_indices == 2) {
|
||||
j = ((const Uint16 *)indices)[i];
|
||||
} else if (size_indices == 1) {
|
||||
j = ((const Uint8 *)indices)[i];
|
||||
} else {
|
||||
j = i;
|
||||
}
|
||||
|
||||
xy_ = (float *)((char*)xy + j * xy_stride);
|
||||
col_ = *(SDL_Color *)((char*)color + j * color_stride);
|
||||
|
||||
uv_ = (float *)((char*)uv + j * uv_stride);
|
||||
|
||||
ptr->src.x = (int)(uv_[0] * texture->w);
|
||||
ptr->src.y = (int)(uv_[1] * texture->h);
|
||||
|
||||
ptr->dst.x = (int)(xy_[0] * scale_x);
|
||||
ptr->dst.y = (int)(xy_[1] * scale_y);
|
||||
trianglepoint_2_fixedpoint(&ptr->dst);
|
||||
|
||||
ptr->color = col_;
|
||||
|
||||
ptr++;
|
||||
}
|
||||
} else {
|
||||
GeometryFillData *ptr = (GeometryFillData *) verts;
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
int j;
|
||||
float *xy_;
|
||||
SDL_Color col_;
|
||||
if (size_indices == 4) {
|
||||
j = ((const Uint32 *)indices)[i];
|
||||
} else if (size_indices == 2) {
|
||||
j = ((const Uint16 *)indices)[i];
|
||||
} else if (size_indices == 1) {
|
||||
j = ((const Uint8 *)indices)[i];
|
||||
} else {
|
||||
j = i;
|
||||
}
|
||||
|
||||
xy_ = (float *)((char*)xy + j * xy_stride);
|
||||
col_ = *(SDL_Color *)((char*)color + j * color_stride);
|
||||
|
||||
ptr->dst.x = (int)(xy_[0] * scale_x);
|
||||
ptr->dst.y = (int)(xy_[1] * scale_y);
|
||||
trianglepoint_2_fixedpoint(&ptr->dst);
|
||||
|
||||
ptr->color = col_;
|
||||
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
PrepTextureForCopy(const SDL_RenderCommand *cmd)
|
||||
{
|
||||
|
|
@ -634,7 +705,7 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
}
|
||||
|
||||
case SDL_RENDERCMD_SETCLIPRECT: {
|
||||
drawstate.cliprect = cmd->data.cliprect.enabled ? &cmd->data.cliprect.rect : NULL;
|
||||
drawstate.cliprect = cmd->data.cliprect.enabled ? &cmd->data.cliprect.rect : NULL;
|
||||
drawstate.surface_cliprect_dirty = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
|
|
@ -657,9 +728,19 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
const Uint8 b = cmd->data.draw.b;
|
||||
const Uint8 a = cmd->data.draw.a;
|
||||
const int count = (int) cmd->data.draw.count;
|
||||
const SDL_Point *verts = (SDL_Point *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
SDL_Point *verts = (SDL_Point *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
const SDL_BlendMode blend = cmd->data.draw.blend;
|
||||
SetDrawState(surface, &drawstate);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
verts[i].x += drawstate.viewport->x;
|
||||
verts[i].y += drawstate.viewport->y;
|
||||
}
|
||||
}
|
||||
|
||||
if (blend == SDL_BLENDMODE_NONE) {
|
||||
SDL_DrawPoints(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a));
|
||||
} else {
|
||||
|
|
@ -674,9 +755,19 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
const Uint8 b = cmd->data.draw.b;
|
||||
const Uint8 a = cmd->data.draw.a;
|
||||
const int count = (int) cmd->data.draw.count;
|
||||
const SDL_Point *verts = (SDL_Point *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
SDL_Point *verts = (SDL_Point *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
const SDL_BlendMode blend = cmd->data.draw.blend;
|
||||
SetDrawState(surface, &drawstate);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
verts[i].x += drawstate.viewport->x;
|
||||
verts[i].y += drawstate.viewport->y;
|
||||
}
|
||||
}
|
||||
|
||||
if (blend == SDL_BLENDMODE_NONE) {
|
||||
SDL_DrawLines(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a));
|
||||
} else {
|
||||
|
|
@ -691,9 +782,19 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
const Uint8 b = cmd->data.draw.b;
|
||||
const Uint8 a = cmd->data.draw.a;
|
||||
const int count = (int) cmd->data.draw.count;
|
||||
const SDL_Rect *verts = (SDL_Rect *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
SDL_Rect *verts = (SDL_Rect *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
const SDL_BlendMode blend = cmd->data.draw.blend;
|
||||
SetDrawState(surface, &drawstate);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
int i;
|
||||
for (i = 0; i < count; i++) {
|
||||
verts[i].x += drawstate.viewport->x;
|
||||
verts[i].y += drawstate.viewport->y;
|
||||
}
|
||||
}
|
||||
|
||||
if (blend == SDL_BLENDMODE_NONE) {
|
||||
SDL_FillRects(surface, verts, count, SDL_MapRGBA(surface->format, r, g, b, a));
|
||||
} else {
|
||||
|
|
@ -713,6 +814,12 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
|
||||
PrepTextureForCopy(cmd);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
dstrect->x += drawstate.viewport->x;
|
||||
dstrect->y += drawstate.viewport->y;
|
||||
}
|
||||
|
||||
if ( srcrect->w == dstrect->w && srcrect->h == dstrect->h ) {
|
||||
SDL_BlitSurface(src, srcrect, surface, dstrect);
|
||||
} else {
|
||||
|
|
@ -720,17 +827,118 @@ SW_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
* to avoid potentially frequent RLE encoding/decoding.
|
||||
*/
|
||||
SDL_SetSurfaceRLE(surface, 0);
|
||||
SDL_BlitScaled(src, srcrect, surface, dstrect);
|
||||
|
||||
/* Prevent to do scaling + clipping on viewport boundaries as it may lose proportion */
|
||||
if (dstrect->x < 0 || dstrect->y < 0 || dstrect->x + dstrect->w > surface->w || dstrect->y + dstrect->h > surface->h) {
|
||||
SDL_Surface *tmp = SDL_CreateRGBSurfaceWithFormat(0, dstrect->w, dstrect->h, 0, src->format->format);
|
||||
/* Scale to an intermediate surface, then blit */
|
||||
if (tmp) {
|
||||
SDL_Rect r;
|
||||
SDL_BlendMode blendmode;
|
||||
Uint8 alphaMod, rMod, gMod, bMod;
|
||||
|
||||
SDL_GetSurfaceBlendMode(src, &blendmode);
|
||||
SDL_GetSurfaceAlphaMod(src, &alphaMod);
|
||||
SDL_GetSurfaceColorMod(src, &rMod, &gMod, &bMod);
|
||||
|
||||
r.x = 0;
|
||||
r.y = 0;
|
||||
r.w = dstrect->w;
|
||||
r.h = dstrect->h;
|
||||
|
||||
SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_NONE);
|
||||
SDL_SetSurfaceColorMod(src, 255, 255, 255);
|
||||
SDL_SetSurfaceAlphaMod(src, 255);
|
||||
|
||||
SDL_PrivateUpperBlitScaled(src, srcrect, tmp, &r, texture->scaleMode);
|
||||
|
||||
SDL_SetSurfaceColorMod(tmp, rMod, gMod, bMod);
|
||||
SDL_SetSurfaceAlphaMod(tmp, alphaMod);
|
||||
SDL_SetSurfaceBlendMode(tmp, blendmode);
|
||||
|
||||
SDL_BlitSurface(tmp, NULL, surface, dstrect);
|
||||
SDL_FreeSurface(tmp);
|
||||
/* No need to set back r/g/b/a/blendmode to 'src' since it's done in PrepTextureForCopy() */
|
||||
}
|
||||
} else{
|
||||
SDL_PrivateUpperBlitScaled(src, srcrect, surface, dstrect, texture->scaleMode);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_COPY_EX: {
|
||||
const CopyExData *copydata = (CopyExData *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
CopyExData *copydata = (CopyExData *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
SetDrawState(surface, &drawstate);
|
||||
PrepTextureForCopy(cmd);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
copydata->dstrect.x += drawstate.viewport->x;
|
||||
copydata->dstrect.y += drawstate.viewport->y;
|
||||
}
|
||||
|
||||
SW_RenderCopyEx(renderer, surface, cmd->data.draw.texture, ©data->srcrect,
|
||||
©data->dstrect, copydata->angle, ©data->center, copydata->flip);
|
||||
©data->dstrect, copydata->angle, ©data->center, copydata->flip,
|
||||
copydata->scale_x, copydata->scale_y);
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_RENDERCMD_GEOMETRY: {
|
||||
int i;
|
||||
SDL_Rect *verts = (SDL_Rect *) (((Uint8 *) vertices) + cmd->data.draw.first);
|
||||
const int count = (int) cmd->data.draw.count;
|
||||
SDL_Texture *texture = cmd->data.draw.texture;
|
||||
const SDL_BlendMode blend = cmd->data.draw.blend;
|
||||
|
||||
SetDrawState(surface, &drawstate);
|
||||
|
||||
if (texture) {
|
||||
SDL_Surface *src = (SDL_Surface *) texture->driverdata;
|
||||
|
||||
GeometryCopyData *ptr = (GeometryCopyData *) verts;
|
||||
|
||||
PrepTextureForCopy(cmd);
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
SDL_Point vp;
|
||||
vp.x = drawstate.viewport->x;
|
||||
vp.y = drawstate.viewport->y;
|
||||
trianglepoint_2_fixedpoint(&vp);
|
||||
for (i = 0; i < count; i++) {
|
||||
ptr[i].dst.x += vp.x;
|
||||
ptr[i].dst.y += vp.y;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i += 3, ptr += 3) {
|
||||
SDL_SW_BlitTriangle(
|
||||
src,
|
||||
&(ptr[0].src), &(ptr[1].src), &(ptr[2].src),
|
||||
surface,
|
||||
&(ptr[0].dst), &(ptr[1].dst), &(ptr[2].dst),
|
||||
ptr[0].color, ptr[1].color, ptr[2].color);
|
||||
}
|
||||
} else {
|
||||
GeometryFillData *ptr = (GeometryFillData *) verts;
|
||||
|
||||
/* Apply viewport */
|
||||
if (drawstate.viewport->x || drawstate.viewport->y) {
|
||||
SDL_Point vp;
|
||||
vp.x = drawstate.viewport->x;
|
||||
vp.y = drawstate.viewport->y;
|
||||
trianglepoint_2_fixedpoint(&vp);
|
||||
for (i = 0; i < count; i++) {
|
||||
ptr[i].dst.x += vp.x;
|
||||
ptr[i].dst.y += vp.y;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < count; i += 3, ptr += 3) {
|
||||
SDL_SW_FillTriangle(surface, &(ptr[0].dst), &(ptr[1].dst), &(ptr[2].dst), blend, ptr[0].color, ptr[1].color, ptr[2].color);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -809,7 +1017,7 @@ SW_CreateRendererForSurface(SDL_Surface * surface)
|
|||
SW_RenderData *data;
|
||||
|
||||
if (!surface) {
|
||||
SDL_SetError("Can't create renderer for NULL surface");
|
||||
SDL_InvalidParamError("surface");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
@ -843,6 +1051,7 @@ SW_CreateRendererForSurface(SDL_Surface * surface)
|
|||
renderer->QueueFillRects = SW_QueueFillRects;
|
||||
renderer->QueueCopy = SW_QueueCopy;
|
||||
renderer->QueueCopyEx = SW_QueueCopyEx;
|
||||
renderer->QueueGeometry = SW_QueueGeometry;
|
||||
renderer->RunCommandQueue = SW_RunCommandQueue;
|
||||
renderer->RenderReadPixels = SW_RenderReadPixels;
|
||||
renderer->RenderPresent = SW_RenderPresent;
|
||||
|
|
@ -859,9 +1068,29 @@ SW_CreateRendererForSurface(SDL_Surface * surface)
|
|||
static SDL_Renderer *
|
||||
SW_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
{
|
||||
const char *hint;
|
||||
SDL_Surface *surface;
|
||||
SDL_bool no_hint_set;
|
||||
|
||||
/* Set the vsync hint based on our flags, if it's not already set */
|
||||
hint = SDL_GetHint(SDL_HINT_RENDER_VSYNC);
|
||||
if (!hint || !*hint) {
|
||||
no_hint_set = SDL_TRUE;
|
||||
} else {
|
||||
no_hint_set = SDL_FALSE;
|
||||
}
|
||||
|
||||
if (no_hint_set) {
|
||||
SDL_SetHint(SDL_HINT_RENDER_VSYNC, (flags & SDL_RENDERER_PRESENTVSYNC) ? "1" : "0");
|
||||
}
|
||||
|
||||
surface = SDL_GetWindowSurface(window);
|
||||
|
||||
/* Reset the vsync hint if we set it above */
|
||||
if (no_hint_set) {
|
||||
SDL_SetHint(SDL_HINT_RENDER_VSYNC, "");
|
||||
}
|
||||
|
||||
if (!surface) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -872,7 +1101,7 @@ SDL_RenderDriver SW_RenderDriver = {
|
|||
SW_CreateRenderer,
|
||||
{
|
||||
"software",
|
||||
SDL_RENDERER_SOFTWARE | SDL_RENDERER_TARGETTEXTURE,
|
||||
SDL_RENDERER_SOFTWARE | SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_TARGETTEXTURE,
|
||||
8,
|
||||
{
|
||||
SDL_PIXELFORMAT_ARGB8888,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ to a situation where the program can segfault.
|
|||
\brief Returns colorkey info for a surface
|
||||
*/
|
||||
static Uint32
|
||||
_colorkey(SDL_Surface *src)
|
||||
get_colorkey(SDL_Surface *src)
|
||||
{
|
||||
Uint32 key = 0;
|
||||
if (SDL_HasColorKey(src)) {
|
||||
|
|
@ -91,6 +91,18 @@ _colorkey(SDL_Surface *src)
|
|||
return key;
|
||||
}
|
||||
|
||||
/* rotate (sx, sy) by (angle, center) into (dx, dy) */
|
||||
static void
|
||||
rotate(double sx, double sy, double sinangle, double cosangle, const SDL_FPoint *center, double *dx, double *dy) {
|
||||
sx -= center->x;
|
||||
sy -= center->y;
|
||||
|
||||
*dx = cosangle * sx - sinangle * sy;
|
||||
*dy = sinangle * sx + cosangle * sy;
|
||||
|
||||
*dx += center->x;
|
||||
*dy += center->y;
|
||||
}
|
||||
|
||||
/* !
|
||||
\brief Internal target surface sizing function for rotations with trig result return.
|
||||
|
|
@ -105,49 +117,61 @@ _colorkey(SDL_Surface *src)
|
|||
|
||||
*/
|
||||
void
|
||||
SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle,
|
||||
int *dstwidth, int *dstheight,
|
||||
double *cangle, double *sangle)
|
||||
SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FPoint *center,
|
||||
SDL_Rect *rect_dest, double *cangle, double *sangle)
|
||||
{
|
||||
/* The trig code below gets the wrong size (due to FP inaccuracy?) when angle is a multiple of 90 degrees */
|
||||
int angle90 = (int)(angle/90);
|
||||
if(angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */
|
||||
angle90 %= 4;
|
||||
if(angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
if(angle90 & 1) {
|
||||
*dstwidth = height;
|
||||
*dstheight = width;
|
||||
*cangle = 0;
|
||||
*sangle = angle90 == 1 ? -1 : 1; /* reversed because our rotations are clockwise */
|
||||
} else {
|
||||
*dstwidth = width;
|
||||
*dstheight = height;
|
||||
*cangle = angle90 == 0 ? 1 : -1;
|
||||
*sangle = 0;
|
||||
}
|
||||
} else {
|
||||
double x, y, cx, cy, sx, sy;
|
||||
double radangle;
|
||||
int dstwidthhalf, dstheighthalf;
|
||||
/*
|
||||
* Determine destination width and height by rotating a centered source box
|
||||
*/
|
||||
radangle = angle * (M_PI / -180.0); /* reverse the angle because our rotations are clockwise */
|
||||
*sangle = SDL_sin(radangle);
|
||||
*cangle = SDL_cos(radangle);
|
||||
x = (double)(width / 2);
|
||||
y = (double)(height / 2);
|
||||
cx = *cangle * x;
|
||||
cy = *cangle * y;
|
||||
sx = *sangle * x;
|
||||
sy = *sangle * y;
|
||||
int minx, maxx, miny, maxy;
|
||||
double radangle;
|
||||
double x0, x1, x2, x3;
|
||||
double y0, y1, y2, y3;
|
||||
double sinangle;
|
||||
double cosangle;
|
||||
|
||||
dstwidthhalf = MAX((int)
|
||||
SDL_ceil(MAX(MAX(MAX(SDL_fabs(cx + sy), SDL_fabs(cx - sy)), SDL_fabs(-cx + sy)), SDL_fabs(-cx - sy))), 1);
|
||||
dstheighthalf = MAX((int)
|
||||
SDL_ceil(MAX(MAX(MAX(SDL_fabs(sx + cy), SDL_fabs(sx - cy)), SDL_fabs(-sx + cy)), SDL_fabs(-sx - cy))), 1);
|
||||
*dstwidth = 2 * dstwidthhalf;
|
||||
*dstheight = 2 * dstheighthalf;
|
||||
radangle = angle * (M_PI / 180.0);
|
||||
sinangle = SDL_sin(radangle);
|
||||
cosangle = SDL_cos(radangle);
|
||||
|
||||
/*
|
||||
* Determine destination width and height by rotating a source box, at pixel center
|
||||
*/
|
||||
rotate(0.5, 0.5, sinangle, cosangle, center, &x0, &y0);
|
||||
rotate(width - 0.5, 0.5, sinangle, cosangle, center, &x1, &y1);
|
||||
rotate(0.5, height - 0.5, sinangle, cosangle, center, &x2, &y2);
|
||||
rotate(width - 0.5, height - 0.5, sinangle, cosangle, center, &x3, &y3);
|
||||
|
||||
minx = (int)SDL_floor( SDL_min( SDL_min(x0, x1), SDL_min(x2, x3) ) );
|
||||
maxx = (int)SDL_ceil( SDL_max( SDL_max(x0, x1), SDL_max(x2, x3) ) );
|
||||
|
||||
miny = (int)SDL_floor( SDL_min( SDL_min(y0, y1), SDL_min(y2, y3) ) );
|
||||
maxy = (int)SDL_ceil( SDL_max( SDL_max(y0, y1), SDL_max(y2, y3) ) );
|
||||
|
||||
rect_dest->w = maxx - minx;
|
||||
rect_dest->h = maxy - miny;
|
||||
rect_dest->x = minx;
|
||||
rect_dest->y = miny;
|
||||
|
||||
/* reverse the angle because our rotations are clockwise */
|
||||
*sangle = -sinangle;
|
||||
*cangle = cosangle;
|
||||
|
||||
{
|
||||
/* The trig code below gets the wrong size (due to FP inaccuracy?) when angle is a multiple of 90 degrees */
|
||||
int angle90 = (int)(angle/90);
|
||||
if(angle90 == angle/90) { /* if the angle is a multiple of 90 degrees */
|
||||
angle90 %= 4;
|
||||
if(angle90 < 0) angle90 += 4; /* 0:0 deg, 1:90 deg, 2:180 deg, 3:270 deg */
|
||||
if(angle90 & 1) {
|
||||
rect_dest->w = height;
|
||||
rect_dest->h = width;
|
||||
*cangle = 0;
|
||||
*sangle = angle90 == 1 ? -1 : 1; /* reversed because our rotations are clockwise */
|
||||
} else {
|
||||
rect_dest->w = width;
|
||||
rect_dest->h = height;
|
||||
*cangle = angle90 == 0 ? 1 : -1;
|
||||
*sangle = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -184,7 +208,7 @@ computeSourceIncrements90(SDL_Surface * src, int bpp, int angle, int flipx, int
|
|||
if (signy < 0) sp += (src->h-1)*src->pitch; \
|
||||
\
|
||||
for (dy = 0; dy < dst->h; sp += sincy, dp += dincy, dy++) { \
|
||||
if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use memcpy */ \
|
||||
if (sincx == sizeof(pixelType)) { /* if advancing src and dest equally, use SDL_memcpy */ \
|
||||
SDL_memcpy(dp, sp, dst->w*sizeof(pixelType)); \
|
||||
sp += dst->w*sizeof(pixelType); \
|
||||
dp += dst->w*sizeof(pixelType); \
|
||||
|
|
@ -220,48 +244,56 @@ Assumes dst surface was allocated with the correct dimensions.
|
|||
|
||||
\param src Source surface.
|
||||
\param dst Destination surface.
|
||||
\param cx Horizontal center coordinate.
|
||||
\param cy Vertical center coordinate.
|
||||
\param isin Integer version of sine of angle.
|
||||
\param icos Integer version of cosine of angle.
|
||||
\param flipx Flag indicating horizontal mirroring should be applied.
|
||||
\param flipy Flag indicating vertical mirroring should be applied.
|
||||
\param smooth Flag indicating anti-aliasing should be used.
|
||||
\param dst_rect destination coordinates
|
||||
\param center true center.
|
||||
*/
|
||||
static void
|
||||
_transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth)
|
||||
transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int isin, int icos,
|
||||
int flipx, int flipy, int smooth,
|
||||
const SDL_Rect *rect_dest,
|
||||
const SDL_FPoint *center)
|
||||
{
|
||||
int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh;
|
||||
int sw, sh;
|
||||
int cx, cy;
|
||||
tColorRGBA c00, c01, c10, c11, cswap;
|
||||
tColorRGBA *pc, *sp;
|
||||
int gap;
|
||||
const int fp_half = (1<<15);
|
||||
|
||||
/*
|
||||
* Variable setup
|
||||
*/
|
||||
xd = ((src->w - dst->w) << 15);
|
||||
yd = ((src->h - dst->h) << 15);
|
||||
ax = (cx << 16) - (icos * cx);
|
||||
ay = (cy << 16) - (isin * cx);
|
||||
sw = src->w - 1;
|
||||
sh = src->h - 1;
|
||||
pc = (tColorRGBA*) dst->pixels;
|
||||
gap = dst->pitch - dst->w * 4;
|
||||
cx = (int)(center->x * 65536.0);
|
||||
cy = (int)(center->y * 65536.0);
|
||||
|
||||
/*
|
||||
* Switch between interpolating and non-interpolating code
|
||||
*/
|
||||
if (smooth) {
|
||||
int y;
|
||||
for (y = 0; y < dst->h; y++) {
|
||||
dy = cy - y;
|
||||
sdx = (ax + (isin * dy)) + xd;
|
||||
sdy = (ay - (icos * dy)) + yd;
|
||||
int x;
|
||||
double src_x = (rect_dest->x + 0 + 0.5 - center->x);
|
||||
double src_y = (rect_dest->y + y + 0.5 - center->y);
|
||||
int sdx = (int)((icos * src_x - isin * src_y) + cx - fp_half);
|
||||
int sdy = (int)((isin * src_x + icos * src_y) + cy - fp_half);
|
||||
for (x = 0; x < dst->w; x++) {
|
||||
dx = (sdx >> 16);
|
||||
dy = (sdy >> 16);
|
||||
int dx = (sdx >> 16);
|
||||
int dy = (sdy >> 16);
|
||||
if (flipx) dx = sw - dx;
|
||||
if (flipy) dy = sh - dy;
|
||||
if ((dx > -1) && (dy > -1) && (dx < (src->w-1)) && (dy < (src->h-1))) {
|
||||
int ex, ey;
|
||||
int t1, t2;
|
||||
sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy) + dx;
|
||||
c00 = *sp;
|
||||
sp += 1;
|
||||
|
|
@ -303,13 +335,16 @@ _transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int
|
|||
pc = (tColorRGBA *) ((Uint8 *) pc + gap);
|
||||
}
|
||||
} else {
|
||||
int y;
|
||||
for (y = 0; y < dst->h; y++) {
|
||||
dy = cy - y;
|
||||
sdx = (ax + (isin * dy)) + xd;
|
||||
sdy = (ay - (icos * dy)) + yd;
|
||||
int x;
|
||||
double src_x = (rect_dest->x + 0 + 0.5 - center->x);
|
||||
double src_y = (rect_dest->y + y + 0.5 - center->y);
|
||||
int sdx = (int)((icos * src_x - isin * src_y) + cx - fp_half);
|
||||
int sdy = (int)((isin * src_x + icos * src_y) + cy - fp_half);
|
||||
for (x = 0; x < dst->w; x++) {
|
||||
dx = (sdx >> 16);
|
||||
dy = (sdy >> 16);
|
||||
int dx = (sdx >> 16);
|
||||
int dy = (sdy >> 16);
|
||||
if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
|
||||
if(flipx) dx = sw - dx;
|
||||
if(flipy) dy = sh - dy;
|
||||
|
|
@ -335,46 +370,54 @@ Assumes dst surface was allocated with the correct dimensions.
|
|||
|
||||
\param src Source surface.
|
||||
\param dst Destination surface.
|
||||
\param cx Horizontal center coordinate.
|
||||
\param cy Vertical center coordinate.
|
||||
\param isin Integer version of sine of angle.
|
||||
\param icos Integer version of cosine of angle.
|
||||
\param flipx Flag indicating horizontal mirroring should be applied.
|
||||
\param flipy Flag indicating vertical mirroring should be applied.
|
||||
\param dst_rect destination coordinates
|
||||
\param center true center.
|
||||
*/
|
||||
static void
|
||||
transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy)
|
||||
transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int isin, int icos, int flipx, int flipy,
|
||||
const SDL_Rect *rect_dest,
|
||||
const SDL_FPoint *center)
|
||||
{
|
||||
int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay;
|
||||
int sw, sh;
|
||||
int cx, cy;
|
||||
tColorY *pc;
|
||||
int gap;
|
||||
const int fp_half = (1<<15);
|
||||
int y;
|
||||
|
||||
/*
|
||||
* Variable setup
|
||||
*/
|
||||
xd = ((src->w - dst->w) << 15);
|
||||
yd = ((src->h - dst->h) << 15);
|
||||
ax = (cx << 16) - (icos * cx);
|
||||
ay = (cy << 16) - (isin * cx);
|
||||
sw = src->w - 1;
|
||||
sh = src->h - 1;
|
||||
pc = (tColorY*) dst->pixels;
|
||||
gap = dst->pitch - dst->w;
|
||||
cx = (int)(center->x * 65536.0);
|
||||
cy = (int)(center->y * 65536.0);
|
||||
|
||||
/*
|
||||
* Clear surface to colorkey
|
||||
*/
|
||||
SDL_memset(pc, (int)(_colorkey(src) & 0xff), dst->pitch * dst->h);
|
||||
SDL_memset(pc, (int)(get_colorkey(src) & 0xff), dst->pitch * dst->h);
|
||||
/*
|
||||
* Iterate through destination surface
|
||||
*/
|
||||
for (y = 0; y < dst->h; y++) {
|
||||
dy = cy - y;
|
||||
sdx = (ax + (isin * dy)) + xd;
|
||||
sdy = (ay - (icos * dy)) + yd;
|
||||
int x;
|
||||
double src_x = (rect_dest->x + 0 + 0.5 - center->x);
|
||||
double src_y = (rect_dest->y + y + 0.5 - center->y);
|
||||
int sdx = (int)((icos * src_x - isin * src_y) + cx - fp_half);
|
||||
int sdy = (int)((isin * src_x + icos * src_y) + cy - fp_half);
|
||||
for (x = 0; x < dst->w; x++) {
|
||||
dx = (sdx >> 16);
|
||||
dy = (sdy >> 16);
|
||||
int dx = (sdx >> 16);
|
||||
int dy = (sdy >> 16);
|
||||
if ((unsigned)dx < (unsigned)src->w && (unsigned)dy < (unsigned)src->h) {
|
||||
if (flipx) dx = (src->w-1)-dx;
|
||||
if (flipy) dy = (src->h-1)-dy;
|
||||
if (flipx) dx = sw - dx;
|
||||
if (flipy) dy = sh- dy;
|
||||
*pc = *((tColorY *)src->pixels + src->pitch * dy + dx);
|
||||
}
|
||||
sdx += icos;
|
||||
|
|
@ -390,7 +433,7 @@ transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin
|
|||
\brief Rotates and zooms a surface with different horizontal and vertival scaling factors and optional anti-aliasing.
|
||||
|
||||
Rotates a 32-bit or 8-bit 'src' surface to newly created 'dst' surface.
|
||||
'angle' is the rotation in degrees, 'centerx' and 'centery' the rotation center. If 'smooth' is set
|
||||
'angle' is the rotation in degrees, 'center' the rotation center. If 'smooth' is set
|
||||
then the destination 32-bit surface is anti-aliased. 8-bit surfaces must have a colorkey. 32-bit
|
||||
surfaces must have a 8888 layout with red, green, blue and alpha masks (any ordering goes).
|
||||
The blend mode of the 'src' surface has some effects on generation of the 'dst' surface: The NONE
|
||||
|
|
@ -400,21 +443,21 @@ When using the NONE and MOD modes, color and alpha modulation must be applied be
|
|||
|
||||
\param src The surface to rotozoom.
|
||||
\param angle The angle to rotate in degrees.
|
||||
\param centerx The horizontal coordinate of the center of rotation
|
||||
\param zoomy The vertical coordinate of the center of rotation
|
||||
\param smooth Antialiasing flag; set to SMOOTHING_ON to enable.
|
||||
\param flipx Set to 1 to flip the image horizontally
|
||||
\param flipy Set to 1 to flip the image vertically
|
||||
\param dstwidth The destination surface width
|
||||
\param dstheight The destination surface height
|
||||
\param rect_dest The destination rect bounding box
|
||||
\param cangle The angle cosine
|
||||
\param sangle The angle sine
|
||||
\param center The true coordinate of the center of rotation
|
||||
\return The new rotated surface.
|
||||
|
||||
*/
|
||||
|
||||
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)
|
||||
SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int flipy,
|
||||
const SDL_Rect *rect_dest, double cangle, double sangle, const SDL_FPoint *center)
|
||||
{
|
||||
SDL_Surface *rz_dst;
|
||||
int is8bit, angle90;
|
||||
|
|
@ -433,13 +476,12 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery,
|
|||
colorKeyAvailable = SDL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/* This function requires a 32-bit surface or 8-bit surface with a colorkey */
|
||||
is8bit = src->format->BitsPerPixel == 8 && colorKeyAvailable;
|
||||
if (!(is8bit || (src->format->BitsPerPixel == 32 && src->format->Amask)))
|
||||
return NULL;
|
||||
|
||||
/* Calculate target factors from sin/cos and zoom */
|
||||
/* Calculate target factors from sine/cosine and zoom */
|
||||
sangleinv = sangle*65536.0;
|
||||
cangleinv = cangle*65536.0;
|
||||
|
||||
|
|
@ -447,16 +489,18 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery,
|
|||
rz_dst = NULL;
|
||||
if (is8bit) {
|
||||
/* Target surface is 8 bit */
|
||||
rz_dst = SDL_CreateRGBSurface(0, dstwidth, dstheight + GUARD_ROWS, 8, 0, 0, 0, 0);
|
||||
rz_dst = SDL_CreateRGBSurfaceWithFormat(0, rect_dest->w, rect_dest->h + GUARD_ROWS, 8, src->format->format);
|
||||
if (rz_dst != NULL) {
|
||||
for (i = 0; i < src->format->palette->ncolors; i++) {
|
||||
rz_dst->format->palette->colors[i] = src->format->palette->colors[i];
|
||||
if (src->format->palette) {
|
||||
for (i = 0; i < src->format->palette->ncolors; i++) {
|
||||
rz_dst->format->palette->colors[i] = src->format->palette->colors[i];
|
||||
}
|
||||
rz_dst->format->palette->ncolors = src->format->palette->ncolors;
|
||||
}
|
||||
rz_dst->format->palette->ncolors = src->format->palette->ncolors;
|
||||
}
|
||||
} else {
|
||||
/* Target surface is 32 bit with source RGBA ordering */
|
||||
rz_dst = SDL_CreateRGBSurface(0, dstwidth, dstheight + GUARD_ROWS, 32,
|
||||
rz_dst = SDL_CreateRGBSurface(0, rect_dest->w, rect_dest->h + GUARD_ROWS, 32,
|
||||
src->format->Rmask, src->format->Gmask,
|
||||
src->format->Bmask, src->format->Amask);
|
||||
}
|
||||
|
|
@ -466,7 +510,7 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery,
|
|||
return NULL;
|
||||
|
||||
/* Adjust for guard rows */
|
||||
rz_dst->h = dstheight;
|
||||
rz_dst->h = rect_dest->h;
|
||||
|
||||
SDL_GetSurfaceBlendMode(src, &blendmode);
|
||||
|
||||
|
|
@ -497,7 +541,7 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery,
|
|||
}
|
||||
|
||||
/* check if the rotation is a multiple of 90 degrees so we can take a fast path and also somewhat reduce
|
||||
* the off-by-one problem in _transformSurfaceRGBA that expresses itself when the rotation is near
|
||||
* the off-by-one problem in transformSurfaceRGBA that expresses itself when the rotation is near
|
||||
* multiples of 90 degrees.
|
||||
*/
|
||||
angle90 = (int)(angle/90);
|
||||
|
|
@ -513,16 +557,16 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery,
|
|||
if(angle90 >= 0) {
|
||||
transformSurfaceY90(src, rz_dst, angle90, flipx, flipy);
|
||||
} else {
|
||||
transformSurfaceY(src, rz_dst, centerx, centery, (int)sangleinv, (int)cangleinv,
|
||||
flipx, flipy);
|
||||
transformSurfaceY(src, rz_dst, (int)sangleinv, (int)cangleinv,
|
||||
flipx, flipy, rect_dest, center);
|
||||
}
|
||||
} else {
|
||||
/* Call the 32-bit transformation routine to do the rotation */
|
||||
if (angle90 >= 0) {
|
||||
transformSurfaceRGBA90(src, rz_dst, angle90, flipx, flipy);
|
||||
} else {
|
||||
_transformSurfaceRGBA(src, rz_dst, centerx, centery, (int)sangleinv, (int)cangleinv,
|
||||
flipx, flipy, smooth);
|
||||
transformSurfaceRGBA(src, rz_dst, (int)sangleinv, (int)cangleinv,
|
||||
flipx, flipy, smooth, rect_dest, center);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
|
@ -26,7 +26,9 @@
|
|||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
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);
|
||||
extern SDL_Surface *SDLgfx_rotateSurface(SDL_Surface * src, double angle, int smooth, int flipx, int flipy,
|
||||
const SDL_Rect *rect_dest, double cangle, double sangle, const SDL_FPoint *center);
|
||||
extern void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FPoint *center,
|
||||
SDL_Rect *rect_dest, double *cangle, double *sangle);
|
||||
|
||||
#endif /* SDL_rotate_h_ */
|
||||
|
|
|
|||
888
Engine/lib/sdl/src/render/software/SDL_triangle.c
Normal file
888
Engine/lib/sdl/src/render/software/SDL_triangle.c
Normal file
|
|
@ -0,0 +1,888 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
|
||||
#include "SDL_surface.h"
|
||||
#include "SDL_triangle.h"
|
||||
|
||||
#include "../../video/SDL_blit.h"
|
||||
|
||||
/* fixed points bits precision
|
||||
* Set to 1, so that it can start rendering wth middle of a pixel precision.
|
||||
* It doesn't need to be increased.
|
||||
* But, if increased too much, it overflows (srcx, srcy) coordinates used for filling with texture.
|
||||
* (which could be turned to int64).
|
||||
*/
|
||||
#define FP_BITS 1
|
||||
|
||||
|
||||
#define COLOR_EQ(c1, c2) ((c1).r == (c2).r && (c1).g == (c2).g && (c1).b == (c2).b && (c1).a == (c2).a)
|
||||
|
||||
static void SDL_BlitTriangle_Slow(SDL_BlitInfo * info,
|
||||
SDL_Point s2_x_area, SDL_Rect dstrect, int area, int bias_w0, int bias_w1, int bias_w2,
|
||||
int d2d1_y, int d1d2_x, int d0d2_y, int d2d0_x, int d1d0_y, int d0d1_x,
|
||||
int s2s0_x, int s2s1_x, int s2s0_y, int s2s1_y, int w0_row, int w1_row, int w2_row,
|
||||
SDL_Color c0, SDL_Color c1, SDL_Color c2, int is_uniform);
|
||||
|
||||
#if 0
|
||||
int SDL_BlitTriangle(SDL_Surface *src, const SDL_Point srcpoints[3], SDL_Surface *dst, const SDL_Point dstpoints[3])
|
||||
{
|
||||
int i;
|
||||
SDL_Point points[6];
|
||||
|
||||
if (src == NULL || dst == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
if (srcpoints[i].x < 0 || srcpoints[i].y < 0 || srcpoints[i].x >= src->w || srcpoints[i].y >= src->h) {
|
||||
return SDL_SetError("Values of 'srcpoints' out of bounds");
|
||||
}
|
||||
}
|
||||
|
||||
points[0] = srcpoints[0];
|
||||
points[1] = dstpoints[0];
|
||||
points[2] = srcpoints[1];
|
||||
points[3] = dstpoints[1];
|
||||
points[4] = srcpoints[2];
|
||||
points[5] = dstpoints[2];
|
||||
for (i = 0; i < 3; i++) {
|
||||
trianglepoint_2_fixedpoint(&points[2 * i + 1]);
|
||||
}
|
||||
return SDL_SW_BlitTriangle(src, dst, points);
|
||||
}
|
||||
|
||||
int SDL_FillTriangle(SDL_Surface *dst, const SDL_Point points[3], Uint32 color)
|
||||
{
|
||||
int i;
|
||||
SDL_Point points_tmp[3];
|
||||
if (dst == NULL) {
|
||||
return -1;
|
||||
}
|
||||
for (i = 0; i < 3; i++) {
|
||||
points_tmp[i] = points[i];
|
||||
trianglepoint_2_fixedpoint(&points_tmp[i]);
|
||||
}
|
||||
return SDL_SW_FillTriangle(dst, points_tmp, SDL_BLENDMODE_NONE, color);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* cross product AB x AC */
|
||||
static int cross_product(const SDL_Point *a, const SDL_Point *b, int c_x, int c_y)
|
||||
{
|
||||
return (b->x - a->x) * (c_y - a->y) - (b->y - a->y) * (c_x - a->x);
|
||||
}
|
||||
|
||||
/* check for top left rules */
|
||||
static int is_top_left(const SDL_Point *a, const SDL_Point *b, int is_clockwise)
|
||||
{
|
||||
if (is_clockwise) {
|
||||
if (a->y == b->y && a->x < b->x) {
|
||||
return 1;
|
||||
}
|
||||
if (b->y < a->y) {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (a->y == b->y && b->x < a->x) {
|
||||
return 1;
|
||||
}
|
||||
if (a->y < b->y) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void trianglepoint_2_fixedpoint(SDL_Point *a) {
|
||||
a->x <<= FP_BITS;
|
||||
a->y <<= FP_BITS;
|
||||
}
|
||||
|
||||
/* bounding rect of three points (in fixed point) */
|
||||
static void bounding_rect_fixedpoint(const SDL_Point *a, const SDL_Point *b, const SDL_Point *c, SDL_Rect *r)
|
||||
{
|
||||
int min_x = SDL_min(a->x, SDL_min(b->x, c->x));
|
||||
int max_x = SDL_max(a->x, SDL_max(b->x, c->x));
|
||||
int min_y = SDL_min(a->y, SDL_min(b->y, c->y));
|
||||
int max_y = SDL_max(a->y, SDL_max(b->y, c->y));
|
||||
/* points are in fixed point, shift back */
|
||||
r->x = min_x >> FP_BITS;
|
||||
r->y = min_y >> FP_BITS;
|
||||
r->w = (max_x - min_x) >> FP_BITS;
|
||||
r->h = (max_y - min_y) >> FP_BITS;
|
||||
}
|
||||
|
||||
/* bounding rect of three points */
|
||||
static void bounding_rect(const SDL_Point *a, const SDL_Point *b, const SDL_Point *c, SDL_Rect *r)
|
||||
{
|
||||
int min_x = SDL_min(a->x, SDL_min(b->x, c->x));
|
||||
int max_x = SDL_max(a->x, SDL_max(b->x, c->x));
|
||||
int min_y = SDL_min(a->y, SDL_min(b->y, c->y));
|
||||
int max_y = SDL_max(a->y, SDL_max(b->y, c->y));
|
||||
r->x = min_x;
|
||||
r->y = min_y;
|
||||
r->w = (max_x - min_x);
|
||||
r->h = (max_y - min_y);
|
||||
}
|
||||
|
||||
|
||||
/* Triangle rendering, using Barycentric coordinates (w0, w1, w2)
|
||||
*
|
||||
* The cross product isn't computed from scratch at each iteration,
|
||||
* but optimized using constant step increments
|
||||
*
|
||||
*/
|
||||
|
||||
#define TRIANGLE_BEGIN_LOOP \
|
||||
{ \
|
||||
int x, y; \
|
||||
for (y = 0; y < dstrect.h; y++) { \
|
||||
/* y start */ \
|
||||
int w0 = w0_row; \
|
||||
int w1 = w1_row; \
|
||||
int w2 = w2_row; \
|
||||
for (x = 0; x < dstrect.w; x++) { \
|
||||
/* In triangle */ \
|
||||
if (w0 + bias_w0 >= 0 && w1 + bias_w1 >= 0 && w2 + bias_w2 >= 0) { \
|
||||
Uint8 *dptr = (Uint8 *) dst_ptr + x * dstbpp; \
|
||||
|
||||
|
||||
/* Use 64 bits precision to prevent overflow when interpolating color / texture with wide triangles */
|
||||
#define TRIANGLE_GET_TEXTCOORD \
|
||||
int srcx = (int)(((Sint64)w0 * s2s0_x + (Sint64)w1 * s2s1_x + s2_x_area.x) / area); \
|
||||
int srcy = (int)(((Sint64)w0 * s2s0_y + (Sint64)w1 * s2s1_y + s2_x_area.y) / area); \
|
||||
|
||||
#define TRIANGLE_GET_MAPPED_COLOR \
|
||||
int r = (int)(((Sint64)w0 * c0.r + (Sint64)w1 * c1.r + (Sint64)w2 * c2.r) / area); \
|
||||
int g = (int)(((Sint64)w0 * c0.g + (Sint64)w1 * c1.g + (Sint64)w2 * c2.g) / area); \
|
||||
int b = (int)(((Sint64)w0 * c0.b + (Sint64)w1 * c1.b + (Sint64)w2 * c2.b) / area); \
|
||||
int a = (int)(((Sint64)w0 * c0.a + (Sint64)w1 * c1.a + (Sint64)w2 * c2.a) / area); \
|
||||
int color = SDL_MapRGBA(format, r, g, b, a); \
|
||||
|
||||
#define TRIANGLE_GET_COLOR \
|
||||
int r = (int)(((Sint64)w0 * c0.r + (Sint64)w1 * c1.r + (Sint64)w2 * c2.r) / area); \
|
||||
int g = (int)(((Sint64)w0 * c0.g + (Sint64)w1 * c1.g + (Sint64)w2 * c2.g) / area); \
|
||||
int b = (int)(((Sint64)w0 * c0.b + (Sint64)w1 * c1.b + (Sint64)w2 * c2.b) / area); \
|
||||
int a = (int)(((Sint64)w0 * c0.a + (Sint64)w1 * c1.a + (Sint64)w2 * c2.a) / area); \
|
||||
|
||||
|
||||
#define TRIANGLE_END_LOOP \
|
||||
} \
|
||||
/* x += 1 */ \
|
||||
w0 += d2d1_y; \
|
||||
w1 += d0d2_y; \
|
||||
w2 += d1d0_y; \
|
||||
} \
|
||||
/* y += 1 */ \
|
||||
w0_row += d1d2_x; \
|
||||
w1_row += d2d0_x; \
|
||||
w2_row += d0d1_x; \
|
||||
dst_ptr += dst_pitch; \
|
||||
} \
|
||||
} \
|
||||
|
||||
int SDL_SW_FillTriangle(SDL_Surface *dst, SDL_Point *d0, SDL_Point *d1, SDL_Point *d2, SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2)
|
||||
{
|
||||
int ret = 0;
|
||||
int dst_locked = 0;
|
||||
|
||||
SDL_Rect dstrect;
|
||||
|
||||
int dstbpp;
|
||||
Uint8 *dst_ptr;
|
||||
int dst_pitch;
|
||||
|
||||
int area, is_clockwise;
|
||||
|
||||
int d2d1_y, d1d2_x, d0d2_y, d2d0_x, d1d0_y, d0d1_x;
|
||||
int w0_row, w1_row, w2_row;
|
||||
int bias_w0, bias_w1, bias_w2;
|
||||
|
||||
int is_uniform;
|
||||
|
||||
SDL_Surface *tmp = NULL;
|
||||
|
||||
if (dst == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
area = cross_product(d0, d1, d2->x, d2->y);
|
||||
|
||||
is_uniform = COLOR_EQ(c0, c1) && COLOR_EQ(c1, c2);
|
||||
|
||||
/* Flat triangle */
|
||||
if (area == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Lock the destination, if needed */
|
||||
if (SDL_MUSTLOCK(dst)) {
|
||||
if (SDL_LockSurface(dst) < 0) {
|
||||
ret = -1;
|
||||
goto end;
|
||||
} else {
|
||||
dst_locked = 1;
|
||||
}
|
||||
}
|
||||
|
||||
bounding_rect_fixedpoint(d0, d1, d2, &dstrect);
|
||||
|
||||
{
|
||||
/* Clip triangle rect with surface rect */
|
||||
SDL_Rect rect;
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
rect.w = dst->w;
|
||||
rect.h = dst->h;
|
||||
SDL_IntersectRect(&dstrect, &rect, &dstrect);
|
||||
}
|
||||
|
||||
{
|
||||
/* Clip triangle with surface clip rect */
|
||||
SDL_Rect rect;
|
||||
SDL_GetClipRect(dst, &rect);
|
||||
SDL_IntersectRect(&dstrect, &rect, &dstrect);
|
||||
}
|
||||
|
||||
|
||||
if (blend != SDL_BLENDMODE_NONE) {
|
||||
int format = dst->format->format;
|
||||
|
||||
/* need an alpha format */
|
||||
if (! dst->format->Amask) {
|
||||
format = SDL_PIXELFORMAT_ARGB8888;
|
||||
}
|
||||
|
||||
/* Use an intermediate surface */
|
||||
tmp = SDL_CreateRGBSurfaceWithFormat(0, dstrect.w, dstrect.h, 0, format);
|
||||
if (tmp == NULL) {
|
||||
ret = -1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (blend == SDL_BLENDMODE_MOD) {
|
||||
Uint32 c = SDL_MapRGBA(tmp->format, 255, 255, 255, 255);
|
||||
SDL_FillRect(tmp, NULL, c);
|
||||
}
|
||||
|
||||
SDL_SetSurfaceBlendMode(tmp, blend);
|
||||
|
||||
dstbpp = tmp->format->BytesPerPixel;
|
||||
dst_ptr = tmp->pixels;
|
||||
dst_pitch = tmp->pitch;
|
||||
|
||||
} else {
|
||||
/* Write directly to destination surface */
|
||||
dstbpp = dst->format->BytesPerPixel;
|
||||
dst_ptr = (Uint8 *)dst->pixels + dstrect.x * dstbpp + dstrect.y * dst->pitch;
|
||||
dst_pitch = dst->pitch;
|
||||
}
|
||||
|
||||
is_clockwise = area > 0;
|
||||
area = SDL_abs(area);
|
||||
|
||||
d2d1_y = (d1->y - d2->y) << FP_BITS;
|
||||
d0d2_y = (d2->y - d0->y) << FP_BITS;
|
||||
d1d0_y = (d0->y - d1->y) << FP_BITS;
|
||||
d1d2_x = (d2->x - d1->x) << FP_BITS;
|
||||
d2d0_x = (d0->x - d2->x) << FP_BITS;
|
||||
d0d1_x = (d1->x - d0->x) << FP_BITS;
|
||||
|
||||
/* Starting point for rendering, at the middle of a pixel */
|
||||
{
|
||||
SDL_Point p;
|
||||
p.x = dstrect.x;
|
||||
p.y = dstrect.y;
|
||||
trianglepoint_2_fixedpoint(&p);
|
||||
p.x += (1 << FP_BITS) / 2;
|
||||
p.y += (1 << FP_BITS) / 2;
|
||||
w0_row = cross_product(d1, d2, p.x, p.y);
|
||||
w1_row = cross_product(d2, d0, p.x, p.y);
|
||||
w2_row = cross_product(d0, d1, p.x, p.y);
|
||||
}
|
||||
|
||||
/* Handle anti-clockwise triangles */
|
||||
if (! is_clockwise) {
|
||||
d2d1_y *= -1;
|
||||
d0d2_y *= -1;
|
||||
d1d0_y *= -1;
|
||||
d1d2_x *= -1;
|
||||
d2d0_x *= -1;
|
||||
d0d1_x *= -1;
|
||||
w0_row *= -1;
|
||||
w1_row *= -1;
|
||||
w2_row *= -1;
|
||||
}
|
||||
|
||||
/* Add a bias to respect top-left rasterization rule */
|
||||
bias_w0 = (is_top_left(d1, d2, is_clockwise) ? 0 : -1);
|
||||
bias_w1 = (is_top_left(d2, d0, is_clockwise) ? 0 : -1);
|
||||
bias_w2 = (is_top_left(d0, d1, is_clockwise) ? 0 : -1);
|
||||
|
||||
if (is_uniform) {
|
||||
Uint32 color;
|
||||
if (tmp) {
|
||||
if (dst->format->Amask) {
|
||||
color = SDL_MapRGBA(tmp->format, c0.r, c0.g, c0.b, c0.a);
|
||||
} else {
|
||||
//color = SDL_MapRGB(tmp->format, c0.r, c0.g, c0.b);
|
||||
color = SDL_MapRGBA(tmp->format, c0.r, c0.g, c0.b, c0.a);
|
||||
}
|
||||
} else {
|
||||
color = SDL_MapRGBA(dst->format, c0.r, c0.g, c0.b, c0.a);
|
||||
}
|
||||
|
||||
if (dstbpp == 4) {
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
*(Uint32 *)dptr = color;
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
} else if (dstbpp == 3) {
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
Uint8 *s = (Uint8*)&color;
|
||||
dptr[0] = s[0];
|
||||
dptr[1] = s[1];
|
||||
dptr[2] = s[2];
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
} else if (dstbpp == 2) {
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
*(Uint16 *)dptr = color;
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
} else if (dstbpp == 1) {
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
*dptr = color;
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
}
|
||||
} else {
|
||||
SDL_PixelFormat *format = dst->format;
|
||||
if (tmp) {
|
||||
format = tmp->format;
|
||||
}
|
||||
if (dstbpp == 4) {
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_MAPPED_COLOR
|
||||
*(Uint32 *)dptr = color;
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
} else if (dstbpp == 3) {
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_MAPPED_COLOR
|
||||
Uint8 *s = (Uint8*)&color;
|
||||
dptr[0] = s[0];
|
||||
dptr[1] = s[1];
|
||||
dptr[2] = s[2];
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
} else if (dstbpp == 2) {
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_MAPPED_COLOR
|
||||
*(Uint16 *)dptr = color;
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
} else if (dstbpp == 1) {
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_MAPPED_COLOR
|
||||
*dptr = color;
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
}
|
||||
}
|
||||
|
||||
if (tmp) {
|
||||
SDL_BlitSurface(tmp, NULL, dst, &dstrect);
|
||||
SDL_FreeSurface(tmp);
|
||||
}
|
||||
|
||||
end:
|
||||
if (dst_locked) {
|
||||
SDL_UnlockSurface(dst);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int SDL_SW_BlitTriangle(
|
||||
SDL_Surface *src,
|
||||
SDL_Point *s0, SDL_Point *s1, SDL_Point *s2,
|
||||
SDL_Surface *dst,
|
||||
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
|
||||
SDL_Color c0, SDL_Color c1, SDL_Color c2)
|
||||
{
|
||||
int ret = 0;
|
||||
int src_locked = 0;
|
||||
int dst_locked = 0;
|
||||
|
||||
SDL_BlendMode blend;
|
||||
|
||||
SDL_Rect dstrect;
|
||||
|
||||
SDL_Point s2_x_area;
|
||||
|
||||
int dstbpp;
|
||||
Uint8 *dst_ptr;
|
||||
int dst_pitch;
|
||||
|
||||
int *src_ptr;
|
||||
int src_pitch;
|
||||
|
||||
int area, is_clockwise;
|
||||
|
||||
int d2d1_y, d1d2_x, d0d2_y, d2d0_x, d1d0_y, d0d1_x;
|
||||
int s2s0_x, s2s1_x, s2s0_y, s2s1_y;
|
||||
|
||||
int w0_row, w1_row, w2_row;
|
||||
int bias_w0, bias_w1, bias_w2;
|
||||
|
||||
int is_uniform;
|
||||
|
||||
int has_modulation;
|
||||
|
||||
if (src == NULL || dst == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
area = cross_product(d0, d1, d2->x, d2->y);
|
||||
|
||||
/* Flat triangle */
|
||||
if (area == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Lock the destination, if needed */
|
||||
if (SDL_MUSTLOCK(dst)) {
|
||||
if (SDL_LockSurface(dst) < 0) {
|
||||
ret = -1;
|
||||
goto end;
|
||||
} else {
|
||||
dst_locked = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Lock the source, if needed */
|
||||
if (SDL_MUSTLOCK(src)) {
|
||||
if (SDL_LockSurface(src) < 0) {
|
||||
ret = -1;
|
||||
goto end;
|
||||
} else {
|
||||
src_locked = 1;
|
||||
}
|
||||
}
|
||||
|
||||
is_uniform = COLOR_EQ(c0, c1) && COLOR_EQ(c1, c2);
|
||||
|
||||
bounding_rect_fixedpoint(d0, d1, d2, &dstrect);
|
||||
|
||||
SDL_GetSurfaceBlendMode(src, &blend);
|
||||
|
||||
/* TRIANGLE_GET_TEXTCOORD interpolates up to the max values included, so reduce by 1 */
|
||||
{
|
||||
SDL_Rect srcrect;
|
||||
int maxx, maxy;
|
||||
bounding_rect(s0, s1, s2, &srcrect);
|
||||
maxx = srcrect.x + srcrect.w;
|
||||
maxy = srcrect.y + srcrect.h;
|
||||
if (srcrect.w > 0) {
|
||||
if (s0->x == maxx) s0->x--;
|
||||
if (s1->x == maxx) s1->x--;
|
||||
if (s2->x == maxx) s2->x--;
|
||||
}
|
||||
if (srcrect.h > 0) {
|
||||
if (s0->y == maxy) s0->y--;
|
||||
if (s1->y == maxy) s1->y--;
|
||||
if (s2->y == maxy) s2->y--;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_uniform) {
|
||||
// SDL_GetSurfaceColorMod(src, &r, &g, &b);
|
||||
has_modulation = c0.r != 255 || c0.g != 255 || c0.b != 255 || c0.a != 255;;
|
||||
} else {
|
||||
has_modulation = SDL_TRUE;
|
||||
}
|
||||
|
||||
{
|
||||
/* Clip triangle rect with surface rect */
|
||||
SDL_Rect rect;
|
||||
rect.x = 0;
|
||||
rect.y = 0;
|
||||
rect.w = dst->w;
|
||||
rect.h = dst->h;
|
||||
|
||||
SDL_IntersectRect(&dstrect, &rect, &dstrect);
|
||||
}
|
||||
|
||||
{
|
||||
/* Clip triangle with surface clip rect */
|
||||
SDL_Rect rect;
|
||||
SDL_GetClipRect(dst, &rect);
|
||||
SDL_IntersectRect(&dstrect, &rect, &dstrect);
|
||||
}
|
||||
|
||||
/* Set destination pointer */
|
||||
dstbpp = dst->format->BytesPerPixel;
|
||||
dst_ptr = (Uint8 *)dst->pixels + dstrect.x * dstbpp + dstrect.y * dst->pitch;
|
||||
dst_pitch = dst->pitch;
|
||||
|
||||
/* Set source pointer */
|
||||
src_ptr = src->pixels;
|
||||
src_pitch = src->pitch;
|
||||
|
||||
is_clockwise = area > 0;
|
||||
area = SDL_abs(area);
|
||||
|
||||
d2d1_y = (d1->y - d2->y) << FP_BITS;
|
||||
d0d2_y = (d2->y - d0->y) << FP_BITS;
|
||||
d1d0_y = (d0->y - d1->y) << FP_BITS;
|
||||
|
||||
|
||||
d1d2_x = (d2->x - d1->x) << FP_BITS;
|
||||
d2d0_x = (d0->x - d2->x) << FP_BITS;
|
||||
d0d1_x = (d1->x - d0->x) << FP_BITS;
|
||||
|
||||
s2s0_x = s0->x - s2->x;
|
||||
s2s1_x = s1->x - s2->x;
|
||||
s2s0_y = s0->y - s2->y;
|
||||
s2s1_y = s1->y - s2->y;
|
||||
|
||||
/* Starting point for rendering, at the middle of a pixel */
|
||||
{
|
||||
SDL_Point p;
|
||||
p.x = dstrect.x;
|
||||
p.y = dstrect.y;
|
||||
trianglepoint_2_fixedpoint(&p);
|
||||
p.x += (1 << FP_BITS) / 2;
|
||||
p.y += (1 << FP_BITS) / 2;
|
||||
w0_row = cross_product(d1, d2, p.x, p.y);
|
||||
w1_row = cross_product(d2, d0, p.x, p.y);
|
||||
w2_row = cross_product(d0, d1, p.x, p.y);
|
||||
}
|
||||
|
||||
/* Handle anti-clockwise triangles */
|
||||
if (! is_clockwise) {
|
||||
d2d1_y *= -1;
|
||||
d0d2_y *= -1;
|
||||
d1d0_y *= -1;
|
||||
d1d2_x *= -1;
|
||||
d2d0_x *= -1;
|
||||
d0d1_x *= -1;
|
||||
w0_row *= -1;
|
||||
w1_row *= -1;
|
||||
w2_row *= -1;
|
||||
}
|
||||
|
||||
/* Add a bias to respect top-left rasterization rule */
|
||||
bias_w0 = (is_top_left(d1, d2, is_clockwise) ? 0 : -1);
|
||||
bias_w1 = (is_top_left(d2, d0, is_clockwise) ? 0 : -1);
|
||||
bias_w2 = (is_top_left(d0, d1, is_clockwise) ? 0 : -1);
|
||||
|
||||
/* precompute constant 's2->x * area' used in TRIANGLE_GET_TEXTCOORD */
|
||||
s2_x_area.x = s2->x * area;
|
||||
s2_x_area.y = s2->y * area;
|
||||
|
||||
if (blend != SDL_BLENDMODE_NONE || src->format->format != dst->format->format || has_modulation || ! is_uniform) {
|
||||
/* Use SDL_BlitTriangle_Slow */
|
||||
|
||||
SDL_BlitInfo *info = &src->map->info;
|
||||
SDL_BlitInfo tmp_info;
|
||||
|
||||
SDL_zero(tmp_info);
|
||||
|
||||
tmp_info.src_fmt = src->format;
|
||||
tmp_info.dst_fmt = dst->format;
|
||||
tmp_info.flags = info->flags;
|
||||
/*
|
||||
tmp_info.r = info->r;
|
||||
tmp_info.g = info->g;
|
||||
tmp_info.b = info->b;
|
||||
tmp_info.a = info->a;
|
||||
*/
|
||||
tmp_info.r = c0.r;
|
||||
tmp_info.g = c0.g;
|
||||
tmp_info.b = c0.b;
|
||||
tmp_info.a = c0.a;
|
||||
|
||||
|
||||
tmp_info.flags &= ~(SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA);
|
||||
|
||||
if (c0.r != 255 || c1.r != 255 || c2.r != 255 ||
|
||||
c0.g != 255 || c1.g != 255 || c2.g != 255 ||
|
||||
c0.b != 255 || c1.b != 255 || c2.b != 255) {
|
||||
tmp_info.flags |= SDL_COPY_MODULATE_COLOR;
|
||||
}
|
||||
|
||||
if (c0.a != 255 || c1.a != 255 || c2.a != 255) {
|
||||
tmp_info.flags |= SDL_COPY_MODULATE_ALPHA;
|
||||
}
|
||||
|
||||
tmp_info.colorkey = info->colorkey;
|
||||
|
||||
/* src */
|
||||
tmp_info.src = (Uint8 *) src_ptr;
|
||||
tmp_info.src_pitch = src_pitch;
|
||||
|
||||
/* dst */
|
||||
tmp_info.dst = (Uint8 *) dst_ptr;
|
||||
tmp_info.dst_pitch = dst_pitch;
|
||||
|
||||
SDL_BlitTriangle_Slow(&tmp_info, s2_x_area, dstrect, area, bias_w0, bias_w1, bias_w2,
|
||||
d2d1_y, d1d2_x, d0d2_y, d2d0_x, d1d0_y, d0d1_x,
|
||||
s2s0_x, s2s1_x, s2s0_y, s2s1_y, w0_row, w1_row, w2_row,
|
||||
c0, c1, c2, is_uniform);
|
||||
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (dstbpp == 4) {
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_TEXTCOORD
|
||||
Uint32 *sptr = (Uint32 *)((Uint8 *) src_ptr + srcy * src_pitch);
|
||||
*(Uint32 *)dptr = sptr[srcx];
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
} else if (dstbpp == 3) {
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_TEXTCOORD
|
||||
Uint8 *sptr = (Uint8 *)((Uint8 *) src_ptr + srcy * src_pitch);
|
||||
dptr[0] = sptr[3 * srcx];
|
||||
dptr[1] = sptr[3 * srcx + 1];
|
||||
dptr[2] = sptr[3 * srcx + 2];
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
} else if (dstbpp == 2) {
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_TEXTCOORD
|
||||
Uint16 *sptr = (Uint16 *)((Uint8 *) src_ptr + srcy * src_pitch);
|
||||
*(Uint16 *)dptr = sptr[srcx];
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
} else if (dstbpp == 1) {
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_TEXTCOORD
|
||||
Uint8 *sptr = (Uint8 *)((Uint8 *) src_ptr + srcy * src_pitch);
|
||||
*dptr = sptr[srcx];
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
}
|
||||
|
||||
end:
|
||||
if (dst_locked) {
|
||||
SDL_UnlockSurface(dst);
|
||||
}
|
||||
if (src_locked) {
|
||||
SDL_UnlockSurface(src);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
#define FORMAT_ALPHA 0
|
||||
#define FORMAT_NO_ALPHA -1
|
||||
#define FORMAT_2101010 1
|
||||
#define FORMAT_HAS_ALPHA(format) format == 0
|
||||
#define FORMAT_HAS_NO_ALPHA(format) format < 0
|
||||
static int SDL_INLINE detect_format(SDL_PixelFormat *pf) {
|
||||
if (pf->format == SDL_PIXELFORMAT_ARGB2101010) {
|
||||
return FORMAT_2101010;
|
||||
} else if (pf->Amask) {
|
||||
return FORMAT_ALPHA;
|
||||
} else {
|
||||
return FORMAT_NO_ALPHA;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
|
||||
SDL_Point s2_x_area, SDL_Rect dstrect, int area, int bias_w0, int bias_w1, int bias_w2,
|
||||
int d2d1_y, int d1d2_x, int d0d2_y, int d2d0_x, int d1d0_y, int d0d1_x,
|
||||
int s2s0_x, int s2s1_x, int s2s0_y, int s2s1_y, int w0_row, int w1_row, int w2_row,
|
||||
SDL_Color c0, SDL_Color c1, SDL_Color c2, int is_uniform)
|
||||
{
|
||||
const int flags = info->flags;
|
||||
Uint32 modulateR = info->r;
|
||||
Uint32 modulateG = info->g;
|
||||
Uint32 modulateB = info->b;
|
||||
Uint32 modulateA = info->a;
|
||||
Uint32 srcpixel;
|
||||
Uint32 srcR, srcG, srcB, srcA;
|
||||
Uint32 dstpixel;
|
||||
Uint32 dstR, dstG, dstB, dstA;
|
||||
SDL_PixelFormat *src_fmt = info->src_fmt;
|
||||
SDL_PixelFormat *dst_fmt = info->dst_fmt;
|
||||
int srcbpp = src_fmt->BytesPerPixel;
|
||||
int dstbpp = dst_fmt->BytesPerPixel;
|
||||
int srcfmt_val;
|
||||
int dstfmt_val;
|
||||
Uint32 rgbmask = ~src_fmt->Amask;
|
||||
Uint32 ckey = info->colorkey & rgbmask;
|
||||
|
||||
Uint8 *dst_ptr = info->dst;
|
||||
int dst_pitch = info->dst_pitch;;
|
||||
|
||||
srcfmt_val = detect_format(src_fmt);
|
||||
dstfmt_val = detect_format(dst_fmt);
|
||||
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
Uint8 *src;
|
||||
Uint8 *dst = dptr;
|
||||
TRIANGLE_GET_TEXTCOORD
|
||||
src = (info->src + (srcy * info->src_pitch) + (srcx * srcbpp));
|
||||
if (FORMAT_HAS_ALPHA(srcfmt_val)) {
|
||||
DISEMBLE_RGBA(src, srcbpp, src_fmt, srcpixel, srcR, srcG, srcB, srcA);
|
||||
} else if (FORMAT_HAS_NO_ALPHA(srcfmt_val)) {
|
||||
DISEMBLE_RGB(src, srcbpp, src_fmt, srcpixel, srcR, srcG, srcB);
|
||||
srcA = 0xFF;
|
||||
} else {
|
||||
/* SDL_PIXELFORMAT_ARGB2101010 */
|
||||
srcpixel = *((Uint32 *)(src));
|
||||
RGBA_FROM_ARGB2101010(srcpixel, srcR, srcG, srcB, srcA);
|
||||
}
|
||||
if (flags & SDL_COPY_COLORKEY) {
|
||||
/* srcpixel isn't set for 24 bpp */
|
||||
if (srcbpp == 3) {
|
||||
srcpixel = (srcR << src_fmt->Rshift) |
|
||||
(srcG << src_fmt->Gshift) | (srcB << src_fmt->Bshift);
|
||||
}
|
||||
if ((srcpixel & rgbmask) == ckey) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (FORMAT_HAS_ALPHA(dstfmt_val)) {
|
||||
DISEMBLE_RGBA(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB, dstA);
|
||||
} else if (FORMAT_HAS_NO_ALPHA(dstfmt_val)) {
|
||||
DISEMBLE_RGB(dst, dstbpp, dst_fmt, dstpixel, dstR, dstG, dstB);
|
||||
dstA = 0xFF;
|
||||
} else {
|
||||
/* SDL_PIXELFORMAT_ARGB2101010 */
|
||||
dstpixel = *((Uint32 *)(dst));
|
||||
RGBA_FROM_ARGB2101010(dstpixel, dstR, dstG, dstB, dstA);
|
||||
}
|
||||
|
||||
if (! is_uniform) {
|
||||
TRIANGLE_GET_COLOR
|
||||
modulateR = r;
|
||||
modulateG = g;
|
||||
modulateB = b;
|
||||
modulateA = a;
|
||||
}
|
||||
|
||||
if (flags & SDL_COPY_MODULATE_COLOR) {
|
||||
srcR = (srcR * modulateR) / 255;
|
||||
srcG = (srcG * modulateG) / 255;
|
||||
srcB = (srcB * modulateB) / 255;
|
||||
}
|
||||
if (flags & SDL_COPY_MODULATE_ALPHA) {
|
||||
srcA = (srcA * modulateA) / 255;
|
||||
}
|
||||
if (flags & (SDL_COPY_BLEND | SDL_COPY_ADD)) {
|
||||
/* This goes away if we ever use premultiplied alpha */
|
||||
if (srcA < 255) {
|
||||
srcR = (srcR * srcA) / 255;
|
||||
srcG = (srcG * srcA) / 255;
|
||||
srcB = (srcB * srcA) / 255;
|
||||
}
|
||||
}
|
||||
switch (flags & (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_MUL)) {
|
||||
case 0:
|
||||
dstR = srcR;
|
||||
dstG = srcG;
|
||||
dstB = srcB;
|
||||
dstA = srcA;
|
||||
break;
|
||||
case SDL_COPY_BLEND:
|
||||
dstR = srcR + ((255 - srcA) * dstR) / 255;
|
||||
dstG = srcG + ((255 - srcA) * dstG) / 255;
|
||||
dstB = srcB + ((255 - srcA) * dstB) / 255;
|
||||
dstA = srcA + ((255 - srcA) * dstA) / 255;
|
||||
break;
|
||||
case SDL_COPY_ADD:
|
||||
dstR = srcR + dstR;
|
||||
if (dstR > 255)
|
||||
dstR = 255;
|
||||
dstG = srcG + dstG;
|
||||
if (dstG > 255)
|
||||
dstG = 255;
|
||||
dstB = srcB + dstB;
|
||||
if (dstB > 255)
|
||||
dstB = 255;
|
||||
break;
|
||||
case SDL_COPY_MOD:
|
||||
dstR = (srcR * dstR) / 255;
|
||||
dstG = (srcG * dstG) / 255;
|
||||
dstB = (srcB * dstB) / 255;
|
||||
break;
|
||||
case SDL_COPY_MUL:
|
||||
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255;
|
||||
if (dstR > 255)
|
||||
dstR = 255;
|
||||
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255;
|
||||
if (dstG > 255)
|
||||
dstG = 255;
|
||||
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255;
|
||||
if (dstB > 255)
|
||||
dstB = 255;
|
||||
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255;
|
||||
if (dstA > 255)
|
||||
dstA = 255;
|
||||
break;
|
||||
}
|
||||
if (FORMAT_HAS_ALPHA(dstfmt_val)) {
|
||||
ASSEMBLE_RGBA(dst, dstbpp, dst_fmt, dstR, dstG, dstB, dstA);
|
||||
} else if (FORMAT_HAS_NO_ALPHA(dstfmt_val)) {
|
||||
ASSEMBLE_RGB(dst, dstbpp, dst_fmt, dstR, dstG, dstB);
|
||||
} else {
|
||||
/* SDL_PIXELFORMAT_ARGB2101010 */
|
||||
Uint32 pixel;
|
||||
ARGB2101010_FROM_RGBA(pixel, dstR, dstG, dstB, dstA);
|
||||
*(Uint32 *)dst = pixel;
|
||||
}
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
42
Engine/lib/sdl/src/render/software/SDL_triangle.h
Normal file
42
Engine/lib/sdl/src/render/software/SDL_triangle.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SDL_triangle_h_
|
||||
#define SDL_triangle_h_
|
||||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
extern int SDL_SW_FillTriangle(SDL_Surface *dst,
|
||||
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
|
||||
SDL_BlendMode blend, SDL_Color c0, SDL_Color c1, SDL_Color c2);
|
||||
|
||||
extern int SDL_SW_BlitTriangle(
|
||||
SDL_Surface *src,
|
||||
SDL_Point *s0, SDL_Point *s1, SDL_Point *s2,
|
||||
SDL_Surface *dst,
|
||||
SDL_Point *d0, SDL_Point *d1, SDL_Point *d2,
|
||||
SDL_Color c0, SDL_Color c1, SDL_Color c2);
|
||||
|
||||
extern void trianglepoint_2_fixedpoint(SDL_Point *a);
|
||||
|
||||
#endif /* SDL_triangle_h_ */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
1042
Engine/lib/sdl/src/render/vitagxm/SDL_render_vita_gxm.c
Normal file
1042
Engine/lib/sdl/src/render/vitagxm/SDL_render_vita_gxm.c
Normal file
File diff suppressed because it is too large
Load diff
117
Engine/lib/sdl/src/render/vitagxm/SDL_render_vita_gxm_memory.c
Normal file
117
Engine/lib/sdl/src/render/vitagxm/SDL_render_vita_gxm_memory.c
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_VITA_GXM
|
||||
|
||||
#include "SDL_render_vita_gxm_memory.h"
|
||||
|
||||
void *
|
||||
mem_gpu_alloc(SceKernelMemBlockType type, unsigned int size, unsigned int alignment, unsigned int attribs, SceUID *uid)
|
||||
{
|
||||
void *mem;
|
||||
|
||||
if (type == SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW) {
|
||||
size = ALIGN(size, 256*1024);
|
||||
} else {
|
||||
size = ALIGN(size, 4*1024);
|
||||
}
|
||||
|
||||
*uid = sceKernelAllocMemBlock("gpu_mem", type, size, NULL);
|
||||
|
||||
if (*uid < 0)
|
||||
return NULL;
|
||||
|
||||
if (sceKernelGetMemBlockBase(*uid, &mem) < 0)
|
||||
return NULL;
|
||||
|
||||
if (sceGxmMapMemory(mem, size, attribs) < 0)
|
||||
return NULL;
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
void
|
||||
mem_gpu_free(SceUID uid)
|
||||
{
|
||||
void *mem = NULL;
|
||||
if (sceKernelGetMemBlockBase(uid, &mem) < 0)
|
||||
return;
|
||||
sceGxmUnmapMemory(mem);
|
||||
sceKernelFreeMemBlock(uid);
|
||||
}
|
||||
|
||||
void *
|
||||
mem_vertex_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset)
|
||||
{
|
||||
void *mem = NULL;
|
||||
|
||||
size = ALIGN(size, 4096);
|
||||
*uid = sceKernelAllocMemBlock("vertex_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL);
|
||||
|
||||
if (sceKernelGetMemBlockBase(*uid, &mem) < 0)
|
||||
return NULL;
|
||||
if (sceGxmMapVertexUsseMemory(mem, size, usse_offset) < 0)
|
||||
return NULL;
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
void
|
||||
mem_vertex_usse_free(SceUID uid)
|
||||
{
|
||||
void *mem = NULL;
|
||||
if (sceKernelGetMemBlockBase(uid, &mem) < 0)
|
||||
return;
|
||||
sceGxmUnmapVertexUsseMemory(mem);
|
||||
sceKernelFreeMemBlock(uid);
|
||||
}
|
||||
|
||||
void *
|
||||
mem_fragment_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset)
|
||||
{
|
||||
void *mem = NULL;
|
||||
|
||||
size = ALIGN(size, 4096);
|
||||
*uid = sceKernelAllocMemBlock("fragment_usse", SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, size, NULL);
|
||||
|
||||
if (sceKernelGetMemBlockBase(*uid, &mem) < 0)
|
||||
return NULL;
|
||||
if (sceGxmMapFragmentUsseMemory(mem, size, usse_offset) < 0)
|
||||
return NULL;
|
||||
|
||||
return mem;
|
||||
}
|
||||
|
||||
void
|
||||
mem_fragment_usse_free(SceUID uid)
|
||||
{
|
||||
void *mem = NULL;
|
||||
if (sceKernelGetMemBlockBase(uid, &mem) < 0)
|
||||
return;
|
||||
sceGxmUnmapFragmentUsseMemory(mem);
|
||||
sceKernelFreeMemBlock(uid);
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_VITA_GXM */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SDL_RENDER_VITA_GXM_MEMORY_H
|
||||
#define SDL_RENDER_VITA_GXM_MEMORY_H
|
||||
|
||||
#include <psp2/gxm.h>
|
||||
#include <psp2/types.h>
|
||||
#include <psp2/kernel/sysmem.h>
|
||||
|
||||
#define ALIGN(x, a) (((x) + ((a) - 1)) & ~((a) - 1))
|
||||
|
||||
void *mem_gpu_alloc(SceKernelMemBlockType type, unsigned int size, unsigned int alignment, unsigned int attribs, SceUID *uid);
|
||||
void mem_gpu_free(SceUID uid);
|
||||
void *mem_vertex_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset);
|
||||
void mem_vertex_usse_free(SceUID uid);
|
||||
void *mem_fragment_usse_alloc(unsigned int size, SceUID *uid, unsigned int *usse_offset);
|
||||
void mem_fragment_usse_free(SceUID uid);
|
||||
|
||||
#endif /* SDL_RENDER_VITA_GXM_MEMORY_H */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
280
Engine/lib/sdl/src/render/vitagxm/SDL_render_vita_gxm_shaders.h
Normal file
280
Engine/lib/sdl/src/render/vitagxm/SDL_render_vita_gxm_shaders.h
Normal file
|
|
@ -0,0 +1,280 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SDL_RENDER_VITA_GXM_SHADERS_H
|
||||
#define SDL_RENDER_VITA_GXM_SHADERS_H
|
||||
|
||||
#include <psp2/gxm.h>
|
||||
|
||||
#define gxm_shader_clear_f_size 232
|
||||
static const unsigned char gxm_shader_clear_f[gxm_shader_clear_f_size] = {
|
||||
0x47, 0x58, 0x50, 0x00, 0x01, 0x05, 0x50, 0x03,
|
||||
0xe8, 0x00, 0x00, 0x00, 0xa2, 0x55, 0x22, 0x3e,
|
||||
0xc6, 0x7e, 0x77, 0xf1, 0x01, 0x00, 0x18, 0x00,
|
||||
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0xa4, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
|
||||
0x02, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x68, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x5c, 0x00, 0x00, 0x00, 0xc0, 0x3d, 0x03, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04,
|
||||
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x07, 0x44, 0xfa, 0x02, 0x80, 0x19, 0xf0,
|
||||
0x7e, 0x0d, 0x80, 0x40, 0x0e, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0x01, 0xe4, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x75, 0x43, 0x6c, 0x65,
|
||||
0x61, 0x72, 0x43, 0x6f, 0x6c, 0x6f, 0x72, 0x00,
|
||||
};
|
||||
|
||||
#define gxm_shader_clear_v_size 252
|
||||
static const unsigned char gxm_shader_clear_v[gxm_shader_clear_v_size] = {
|
||||
0x47, 0x58, 0x50, 0x00, 0x01, 0x05, 0x50, 0x03,
|
||||
0xfa, 0x00, 0x00, 0x00, 0xdc, 0x25, 0x34, 0x74,
|
||||
0x53, 0x4a, 0x7a, 0x5b, 0x04, 0x00, 0x19, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0xb8, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x74, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x78, 0x00, 0x00, 0x00, 0xc0, 0x3d, 0x03, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x54, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x4c, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x04,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x44, 0xfa,
|
||||
0x01, 0x00, 0x04, 0x90, 0x85, 0x11, 0xa5, 0x08,
|
||||
0x01, 0x80, 0x56, 0x90, 0x81, 0x11, 0x83, 0x08,
|
||||
0x00, 0x00, 0x20, 0xa0, 0x00, 0x50, 0x27, 0xfb,
|
||||
0x10, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x61, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
#define gxm_shader_color_f_size 212
|
||||
static const unsigned char gxm_shader_color_f[gxm_shader_color_f_size] = {
|
||||
0x47, 0x58, 0x50, 0x00, 0x01, 0x05, 0x50, 0x03,
|
||||
0xd4, 0x00, 0x00, 0x00, 0x9c, 0xd6, 0x9b, 0xf7,
|
||||
0x78, 0x00, 0x5d, 0x31, 0x01, 0x10, 0x18, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0xac, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00,
|
||||
0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x78, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x6c, 0x00, 0x00, 0x00, 0xc0, 0x3d, 0x03, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x50, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04,
|
||||
0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x0f, 0xa0, 0xd0, 0x0e, 0x00, 0x00, 0x00, 0x00,
|
||||
0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x07, 0x44, 0xfa, 0x02, 0x80, 0x19, 0xa0,
|
||||
0x7e, 0x0d, 0x80, 0x40,
|
||||
};
|
||||
|
||||
#define gxm_shader_color_v_size 368
|
||||
static const unsigned char gxm_shader_color_v[gxm_shader_color_v_size] = {
|
||||
0x47, 0x58, 0x50, 0x00, 0x01, 0x05, 0x50, 0x03,
|
||||
0x6d, 0x01, 0x00, 0x00, 0x09, 0xce, 0x4e, 0xc2,
|
||||
0xe1, 0xcd, 0x24, 0xbc, 0x00, 0x00, 0x19, 0x00,
|
||||
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
0x00, 0x01, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
|
||||
0x08, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x09, 0x00, 0x00, 0x00,
|
||||
0x98, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
0x74, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0xb8, 0x00, 0x00, 0x00, 0xc0, 0x3d, 0x03, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xac, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x8c, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xf3, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x19, 0x00, 0x09,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x06, 0x43, 0x00, 0x61,
|
||||
0x86, 0x81, 0xa2, 0x00, 0x07, 0x53, 0x40, 0x61,
|
||||
0x86, 0x81, 0xa2, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x40, 0x01, 0x04, 0xf8, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x44, 0xfa,
|
||||
0x80, 0x00, 0x08, 0x83, 0x21, 0x1d, 0x80, 0x38,
|
||||
0x00, 0x00, 0xf0, 0x83, 0x20, 0x0d, 0x80, 0x38,
|
||||
0x0a, 0x84, 0xb9, 0xff, 0xbc, 0x0d, 0xc0, 0x40,
|
||||
0x02, 0x11, 0x45, 0xcf, 0x80, 0x8f, 0xb1, 0x18,
|
||||
0x00, 0x11, 0x01, 0xc0, 0x81, 0x81, 0xb1, 0x18,
|
||||
0x01, 0xd1, 0x42, 0xc0, 0x81, 0x81, 0xb1, 0x18,
|
||||
0x40, 0x00, 0x10, 0x41, 0x09, 0x05, 0x82, 0x38,
|
||||
0x00, 0x00, 0x20, 0xa0, 0x00, 0x50, 0x27, 0xfb,
|
||||
0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||
0x30, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x2a, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x21, 0x00, 0x00, 0x00, 0x01, 0xe4, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x61, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x00, 0x61, 0x43, 0x6f, 0x6c, 0x6f, 0x72,
|
||||
0x00, 0x77, 0x76, 0x70, 0x00, 0x00, 0x00, 0x00,
|
||||
};
|
||||
|
||||
#define gxm_shader_texture_f_size 288
|
||||
static const unsigned char gxm_shader_texture_f[gxm_shader_texture_f_size] = {
|
||||
0x47, 0x58, 0x50, 0x00, 0x01, 0x05, 0x50, 0x03,
|
||||
0x20, 0x01, 0x00, 0x00, 0xeb, 0x4f, 0xb5, 0xba,
|
||||
0x60, 0xb2, 0xd0, 0x8d, 0x05, 0x18, 0x18, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0xc4, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
|
||||
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x05, 0x00, 0x00, 0x00,
|
||||
0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x78, 0x00, 0x00, 0x00, 0x74, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x84, 0x00, 0x00, 0x00, 0xc0, 0x3d, 0x03, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x58, 0x00, 0x00, 0x00,
|
||||
0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04,
|
||||
0x01, 0x00, 0x01, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x00, 0xa9, 0xd0, 0x0e, 0x00, 0x00, 0x00, 0x00,
|
||||
0xf0, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x07, 0x44, 0xfa, 0x00, 0x00, 0x00, 0x00,
|
||||
0x40, 0x09, 0x00, 0xf8, 0x02, 0x80, 0x99, 0xaf,
|
||||
0xbc, 0x0d, 0xc0, 0x40, 0x06, 0x82, 0xb9, 0xaf,
|
||||
0xbc, 0x0d, 0x80, 0x40, 0x7c, 0x0f, 0x04, 0x00,
|
||||
0x86, 0x47, 0xa4, 0x10, 0x30, 0x00, 0x00, 0x00,
|
||||
0x02, 0x04, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x74, 0x65, 0x78, 0x00,
|
||||
};
|
||||
|
||||
#define gxm_shader_texture_v_size 400
|
||||
static const unsigned char gxm_shader_texture_v[gxm_shader_texture_v_size] = {
|
||||
0x47, 0x58, 0x50, 0x00, 0x01, 0x05, 0x50, 0x03,
|
||||
0x8f, 0x01, 0x00, 0x00, 0x60, 0x1e, 0x69, 0x97,
|
||||
0x82, 0x7e, 0x0c, 0xac, 0x00, 0x00, 0x19, 0x00,
|
||||
0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x08, 0x01, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00,
|
||||
0x0c, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x0a, 0x00, 0x00, 0x00,
|
||||
0x98, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
0x74, 0x00, 0x00, 0x00, 0x88, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
|
||||
0xc0, 0x00, 0x00, 0x00, 0xc0, 0x3d, 0x03, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xb4, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xa4, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x9c, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x94, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x33, 0x0f, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x00, 0x0a,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x06, 0x43, 0x00, 0x61,
|
||||
0x86, 0x81, 0xa2, 0x00, 0x07, 0x53, 0x40, 0x61,
|
||||
0x86, 0x81, 0xa2, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x40, 0x01, 0x04, 0xf8, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x44, 0xfa,
|
||||
0x01, 0x0e, 0x01, 0x01, 0x02, 0x00, 0x10, 0xfa,
|
||||
0x80, 0x00, 0x08, 0x83, 0x21, 0x25, 0x80, 0x38,
|
||||
0x01, 0x01, 0x01, 0x01, 0x00, 0x00, 0x14, 0xfa,
|
||||
0x00, 0x00, 0xf0, 0x83, 0x20, 0x0d, 0x80, 0x38,
|
||||
0x0a, 0x84, 0xb9, 0xff, 0xbc, 0x0d, 0xc0, 0x40,
|
||||
0x02, 0x11, 0x45, 0xcf, 0x80, 0x8f, 0xb1, 0x18,
|
||||
0x00, 0x11, 0x01, 0xc0, 0x81, 0x81, 0xb1, 0x18,
|
||||
0x01, 0xd1, 0x42, 0xc0, 0x81, 0x81, 0xb1, 0x18,
|
||||
0x00, 0x00, 0x20, 0xa0, 0x00, 0x50, 0x27, 0xfb,
|
||||
0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||
0x40, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x3a, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x34, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
|
||||
0x2b, 0x00, 0x00, 0x00, 0x01, 0xe4, 0x00, 0x00,
|
||||
0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x61, 0x50, 0x6f, 0x73, 0x69, 0x74, 0x69, 0x6f,
|
||||
0x6e, 0x00, 0x61, 0x54, 0x65, 0x78, 0x63, 0x6f,
|
||||
0x6f, 0x72, 0x64, 0x00, 0x61, 0x43, 0x6f, 0x6c,
|
||||
0x6f, 0x72, 0x00, 0x77, 0x76, 0x70, 0x00, 0x00,
|
||||
};
|
||||
|
||||
static const SceGxmProgram *const clearVertexProgramGxp = (const SceGxmProgram *)gxm_shader_clear_v;
|
||||
static const SceGxmProgram *const clearFragmentProgramGxp = (const SceGxmProgram *)gxm_shader_clear_f;
|
||||
static const SceGxmProgram *const colorVertexProgramGxp = (const SceGxmProgram *)gxm_shader_color_v;
|
||||
static const SceGxmProgram *const colorFragmentProgramGxp = (const SceGxmProgram *)gxm_shader_color_f;
|
||||
static const SceGxmProgram *const textureVertexProgramGxp = (const SceGxmProgram *)gxm_shader_texture_v;
|
||||
static const SceGxmProgram *const textureFragmentProgramGxp = (const SceGxmProgram *)gxm_shader_texture_f;
|
||||
|
||||
#endif // SDL_RENDER_VITA_GXM_SHADERS_H
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
1239
Engine/lib/sdl/src/render/vitagxm/SDL_render_vita_gxm_tools.c
Normal file
1239
Engine/lib/sdl/src/render/vitagxm/SDL_render_vita_gxm_tools.c
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SDL_RENDER_VITA_GXM_TOOLS_H
|
||||
#define SDL_RENDER_VITA_GXM_TOOLS_H
|
||||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#include "SDL_hints.h"
|
||||
#include "../SDL_sysrender.h"
|
||||
|
||||
#include <psp2/kernel/processmgr.h>
|
||||
#include <psp2/appmgr.h>
|
||||
#include <psp2/display.h>
|
||||
#include <psp2/gxm.h>
|
||||
#include <psp2/types.h>
|
||||
#include <psp2/kernel/sysmem.h>
|
||||
|
||||
#include "SDL_render_vita_gxm_types.h"
|
||||
|
||||
void
|
||||
init_orthographic_matrix(float *m, float left, float right, float bottom, float top, float near, float far);
|
||||
|
||||
void *pool_malloc(VITA_GXM_RenderData *data, unsigned int size);
|
||||
void *pool_memalign(VITA_GXM_RenderData *data, unsigned int size, unsigned int alignment);
|
||||
|
||||
void set_clip_rectangle(VITA_GXM_RenderData *data, int x_min, int y_min, int x_max, int y_max);
|
||||
void unset_clip_rectangle(VITA_GXM_RenderData *data);
|
||||
|
||||
int gxm_init(SDL_Renderer *renderer);
|
||||
void gxm_finish(SDL_Renderer *renderer);
|
||||
|
||||
gxm_texture *create_gxm_texture(VITA_GXM_RenderData *data, unsigned int w, unsigned int h, SceGxmTextureFormat format, unsigned int isRenderTarget);
|
||||
void free_gxm_texture(gxm_texture *texture);
|
||||
|
||||
void gxm_texture_set_filters(gxm_texture *texture, SceGxmTextureFilter min_filter, SceGxmTextureFilter mag_filter);
|
||||
SceGxmTextureFormat gxm_texture_get_format(const gxm_texture *texture);
|
||||
|
||||
unsigned int gxm_texture_get_width(const gxm_texture *texture);
|
||||
unsigned int gxm_texture_get_height(const gxm_texture *texture);
|
||||
unsigned int gxm_texture_get_stride(const gxm_texture *texture);
|
||||
void *gxm_texture_get_datap(const gxm_texture *texture);
|
||||
|
||||
void gxm_minimal_init_for_common_dialog(void);
|
||||
void gxm_minimal_term_for_common_dialog(void);
|
||||
void gxm_init_for_common_dialog(void);
|
||||
void gxm_swap_for_common_dialog(void);
|
||||
void gxm_term_for_common_dialog(void);
|
||||
|
||||
#endif /* SDL_RENDER_VITA_GXM_TOOLS_H */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
201
Engine/lib/sdl/src/render/vitagxm/SDL_render_vita_gxm_types.h
Normal file
201
Engine/lib/sdl/src/render/vitagxm/SDL_render_vita_gxm_types.h
Normal file
|
|
@ -0,0 +1,201 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef SDL_RENDER_VITA_GXM_TYPES_H
|
||||
#define SDL_RENDER_VITA_GXM_TYPES_H
|
||||
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#include "SDL_hints.h"
|
||||
#include "../SDL_sysrender.h"
|
||||
|
||||
#include <psp2/kernel/processmgr.h>
|
||||
#include <psp2/appmgr.h>
|
||||
#include <psp2/display.h>
|
||||
#include <psp2/gxm.h>
|
||||
#include <psp2/types.h>
|
||||
#include <psp2/kernel/sysmem.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define VITA_GXM_SCREEN_WIDTH 960
|
||||
#define VITA_GXM_SCREEN_HEIGHT 544
|
||||
#define VITA_GXM_SCREEN_STRIDE 960
|
||||
|
||||
#define VITA_GXM_COLOR_FORMAT SCE_GXM_COLOR_FORMAT_A8B8G8R8
|
||||
#define VITA_GXM_PIXEL_FORMAT SCE_DISPLAY_PIXELFORMAT_A8B8G8R8
|
||||
|
||||
#define VITA_GXM_BUFFERS 3
|
||||
#define VITA_GXM_PENDING_SWAPS 2
|
||||
#define VITA_GXM_POOL_SIZE 2 * 1024 * 1024
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *address;
|
||||
Uint8 wait_vblank;
|
||||
} VITA_GXM_DisplayData;
|
||||
|
||||
typedef struct clear_vertex {
|
||||
float x;
|
||||
float y;
|
||||
} clear_vertex;
|
||||
|
||||
typedef struct color_vertex {
|
||||
float x;
|
||||
float y;
|
||||
SDL_Color color;
|
||||
} color_vertex;
|
||||
|
||||
typedef struct texture_vertex {
|
||||
float x;
|
||||
float y;
|
||||
float u;
|
||||
float v;
|
||||
SDL_Color color;
|
||||
} texture_vertex;
|
||||
|
||||
typedef struct gxm_texture {
|
||||
SceGxmTexture gxm_tex;
|
||||
SceUID data_UID;
|
||||
SceGxmRenderTarget *gxm_rendertarget;
|
||||
SceGxmColorSurface gxm_colorsurface;
|
||||
SceGxmDepthStencilSurface gxm_depthstencil;
|
||||
SceUID depth_UID;
|
||||
} gxm_texture;
|
||||
|
||||
typedef struct fragment_programs {
|
||||
SceGxmFragmentProgram *color;
|
||||
SceGxmFragmentProgram *texture;
|
||||
} fragment_programs;
|
||||
|
||||
typedef struct blend_fragment_programs {
|
||||
fragment_programs blend_mode_none;
|
||||
fragment_programs blend_mode_blend;
|
||||
fragment_programs blend_mode_add;
|
||||
fragment_programs blend_mode_mod;
|
||||
fragment_programs blend_mode_mul;
|
||||
} blend_fragment_programs;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SDL_Rect viewport;
|
||||
SDL_bool viewport_dirty;
|
||||
SDL_Texture *texture;
|
||||
SDL_Texture *target;
|
||||
SDL_Color color;
|
||||
SceGxmFragmentProgram *fragment_program;
|
||||
SceGxmVertexProgram *vertex_program;
|
||||
int last_command;
|
||||
|
||||
SDL_bool cliprect_enabled_dirty;
|
||||
SDL_bool cliprect_enabled;
|
||||
SDL_bool cliprect_dirty;
|
||||
SDL_Rect cliprect;
|
||||
SDL_bool texturing;
|
||||
SDL_Color clear_color;
|
||||
int drawablew;
|
||||
int drawableh;
|
||||
} gxm_drawstate_cache;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SDL_bool initialized;
|
||||
SDL_bool drawing;
|
||||
|
||||
unsigned int psm;
|
||||
unsigned int bpp;
|
||||
|
||||
int currentBlendMode;
|
||||
|
||||
VITA_GXM_DisplayData displayData;
|
||||
|
||||
SceUID vdmRingBufferUid;
|
||||
SceUID vertexRingBufferUid;
|
||||
SceUID fragmentRingBufferUid;
|
||||
SceUID fragmentUsseRingBufferUid;
|
||||
SceGxmContextParams contextParams;
|
||||
SceGxmContext *gxm_context;
|
||||
SceGxmRenderTarget *renderTarget;
|
||||
SceUID displayBufferUid[VITA_GXM_BUFFERS];
|
||||
void *displayBufferData[VITA_GXM_BUFFERS];
|
||||
SceGxmColorSurface displaySurface[VITA_GXM_BUFFERS];
|
||||
SceGxmSyncObject *displayBufferSync[VITA_GXM_BUFFERS];
|
||||
|
||||
SceUID depthBufferUid;
|
||||
SceUID stencilBufferUid;
|
||||
SceGxmDepthStencilSurface depthSurface;
|
||||
void *depthBufferData;
|
||||
void *stencilBufferData;
|
||||
|
||||
unsigned int backBufferIndex;
|
||||
unsigned int frontBufferIndex;
|
||||
|
||||
void* pool_addr[2];
|
||||
SceUID poolUid[2];
|
||||
unsigned int pool_index;
|
||||
unsigned int current_pool;
|
||||
|
||||
float ortho_matrix[4*4];
|
||||
|
||||
SceGxmVertexProgram *colorVertexProgram;
|
||||
SceGxmFragmentProgram *colorFragmentProgram;
|
||||
SceGxmVertexProgram *textureVertexProgram;
|
||||
SceGxmFragmentProgram *textureFragmentProgram;
|
||||
SceGxmProgramParameter *clearClearColorParam;
|
||||
SceGxmProgramParameter *colorWvpParam;
|
||||
SceGxmProgramParameter *textureWvpParam;
|
||||
|
||||
SceGxmShaderPatcher *shaderPatcher;
|
||||
SceGxmVertexProgram *clearVertexProgram;
|
||||
SceGxmFragmentProgram *clearFragmentProgram;
|
||||
|
||||
SceGxmShaderPatcherId clearVertexProgramId;
|
||||
SceGxmShaderPatcherId clearFragmentProgramId;
|
||||
SceGxmShaderPatcherId colorVertexProgramId;
|
||||
SceGxmShaderPatcherId colorFragmentProgramId;
|
||||
SceGxmShaderPatcherId textureVertexProgramId;
|
||||
SceGxmShaderPatcherId textureFragmentProgramId;
|
||||
|
||||
SceUID patcherBufferUid;
|
||||
SceUID patcherVertexUsseUid;
|
||||
SceUID patcherFragmentUsseUid;
|
||||
|
||||
SceUID clearVerticesUid;
|
||||
SceUID linearIndicesUid;
|
||||
clear_vertex *clearVertices;
|
||||
uint16_t *linearIndices;
|
||||
|
||||
blend_fragment_programs blendFragmentPrograms;
|
||||
|
||||
gxm_drawstate_cache drawstate;
|
||||
} VITA_GXM_RenderData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gxm_texture *tex;
|
||||
unsigned int pitch;
|
||||
unsigned int w;
|
||||
unsigned int h;
|
||||
} VITA_GXM_TextureData;
|
||||
|
||||
#endif /* SDL_RENDER_VITA_GXM_TYPES_H */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
4
Engine/lib/sdl/src/render/vitagxm/shader_src/clear_f.cg
Normal file
4
Engine/lib/sdl/src/render/vitagxm/shader_src/clear_f.cg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
float4 main( uniform float4 uClearColor) : COLOR
|
||||
{
|
||||
return uClearColor;
|
||||
}
|
||||
4
Engine/lib/sdl/src/render/vitagxm/shader_src/clear_v.cg
Normal file
4
Engine/lib/sdl/src/render/vitagxm/shader_src/clear_v.cg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
float4 main(float2 aPosition) : POSITION
|
||||
{
|
||||
return float4(aPosition, 1.f, 1.f);
|
||||
}
|
||||
4
Engine/lib/sdl/src/render/vitagxm/shader_src/color_f.cg
Normal file
4
Engine/lib/sdl/src/render/vitagxm/shader_src/color_f.cg
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
float4 main(float4 vColor : COLOR)
|
||||
{
|
||||
return vColor;
|
||||
}
|
||||
13
Engine/lib/sdl/src/render/vitagxm/shader_src/color_v.cg
Normal file
13
Engine/lib/sdl/src/render/vitagxm/shader_src/color_v.cg
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
void main(
|
||||
float2 aPosition,
|
||||
float4 aColor,
|
||||
uniform float4x4 wvp,
|
||||
out float4 vPosition : POSITION,
|
||||
out float4 vColor : COLOR,
|
||||
out float pSize : PSIZE
|
||||
)
|
||||
{
|
||||
vPosition = mul(float4(aPosition, 1.f, 0.5f), wvp);
|
||||
vColor = aColor;
|
||||
pSize = 1.f;
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
float4 main(float2 vTexcoord : TEXCOORD0, float4 vColor : COLOR, uniform sampler2D tex)
|
||||
{
|
||||
return tex2D(tex, vTexcoord) * vColor;
|
||||
}
|
||||
14
Engine/lib/sdl/src/render/vitagxm/shader_src/texture_v.cg
Normal file
14
Engine/lib/sdl/src/render/vitagxm/shader_src/texture_v.cg
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
void main(
|
||||
float2 aPosition,
|
||||
float2 aTexcoord,
|
||||
float4 aColor,
|
||||
uniform float4x4 wvp,
|
||||
out float4 vPosition : POSITION,
|
||||
out float4 vColor : COLOR,
|
||||
out float2 vTexcoord : TEXCOORD0
|
||||
)
|
||||
{
|
||||
vPosition = mul(float4(aPosition, 1.f, 0.5f), wvp);
|
||||
vTexcoord = aTexcoord;
|
||||
vColor = aColor;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue