mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-04-19 11:25:27 +00:00
Updates SDL to 2.0.12
This commit is contained in:
parent
3108a08650
commit
a526029f2f
861 changed files with 25596 additions and 8904 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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
|
||||
|
|
@ -75,6 +75,10 @@
|
|||
SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_SRC_COLOR, SDL_BLENDOPERATION_ADD, \
|
||||
SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD)
|
||||
|
||||
#define SDL_BLENDMODE_MUL_FULL \
|
||||
SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_DST_COLOR, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, \
|
||||
SDL_BLENDFACTOR_DST_ALPHA, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD)
|
||||
|
||||
#if !SDL_RENDER_DISABLED
|
||||
static const SDL_RenderDriver *render_drivers[] = {
|
||||
#if SDL_VIDEO_RENDER_D3D
|
||||
|
|
@ -101,7 +105,9 @@ static const SDL_RenderDriver *render_drivers[] = {
|
|||
#if SDL_VIDEO_RENDER_PSP
|
||||
&PSP_RenderDriver,
|
||||
#endif
|
||||
#if SDL_VIDEO_RENDER_SW
|
||||
&SW_RenderDriver
|
||||
#endif
|
||||
};
|
||||
#endif /* !SDL_RENDER_DISABLED */
|
||||
|
||||
|
|
@ -202,8 +208,6 @@ DebugLogRenderCommands(const SDL_RenderCommand *cmd)
|
|||
static int
|
||||
FlushRenderCommands(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_AllocVertGap *prevgap = &renderer->vertex_data_gaps;
|
||||
SDL_AllocVertGap *gap = prevgap;
|
||||
int retval;
|
||||
|
||||
SDL_assert((renderer->render_commands == NULL) == (renderer->render_commands_tail == NULL));
|
||||
|
|
@ -217,14 +221,6 @@ FlushRenderCommands(SDL_Renderer *renderer)
|
|||
|
||||
retval = renderer->RunCommandQueue(renderer, renderer->render_commands, renderer->vertex_data, renderer->vertex_data_used);
|
||||
|
||||
while (gap) {
|
||||
prevgap = gap;
|
||||
gap = gap->next;
|
||||
}
|
||||
prevgap->next = renderer->vertex_data_gaps_pool;
|
||||
renderer->vertex_data_gaps_pool = renderer->vertex_data_gaps.next;
|
||||
renderer->vertex_data_gaps.next = NULL;
|
||||
|
||||
/* Move the whole render command queue to the unused pool so we can reuse them next time. */
|
||||
if (renderer->render_commands_tail != NULL) {
|
||||
renderer->render_commands_tail->next = renderer->render_commands_pool;
|
||||
|
|
@ -263,79 +259,23 @@ SDL_RenderFlush(SDL_Renderer * renderer)
|
|||
return FlushRenderCommands(renderer);
|
||||
}
|
||||
|
||||
static SDL_AllocVertGap *
|
||||
AllocateVertexGap(SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_AllocVertGap *retval = renderer->vertex_data_gaps_pool;
|
||||
if (retval) {
|
||||
renderer->vertex_data_gaps_pool = retval->next;
|
||||
retval->next = NULL;
|
||||
} else {
|
||||
retval = (SDL_AllocVertGap *) SDL_malloc(sizeof (SDL_AllocVertGap));
|
||||
if (!retval) {
|
||||
SDL_OutOfMemory();
|
||||
}
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const size_t alignment, size_t *offset)
|
||||
{
|
||||
const size_t needed = renderer->vertex_data_used + numbytes + alignment;
|
||||
size_t aligner, aligned;
|
||||
void *retval;
|
||||
size_t current_offset = renderer->vertex_data_used;
|
||||
|
||||
SDL_AllocVertGap *prevgap = &renderer->vertex_data_gaps;
|
||||
SDL_AllocVertGap *gap = prevgap->next;
|
||||
while (gap) {
|
||||
const size_t gapoffset = gap->offset;
|
||||
aligner = (alignment && ((gap->offset % alignment) != 0)) ? (alignment - (gap->offset % alignment)) : 0;
|
||||
aligned = gapoffset + aligner;
|
||||
size_t aligner = (alignment && ((current_offset & (alignment - 1)) != 0)) ? (alignment - (current_offset & (alignment - 1))) : 0;
|
||||
size_t aligned = current_offset + aligner;
|
||||
|
||||
/* Can we use this gap? */
|
||||
if ((aligner < gap->len) && ((gap->len - aligner) >= numbytes)) {
|
||||
/* we either finished this gap off, trimmed the left, trimmed the right, or split it into two gaps. */
|
||||
if (gap->len == numbytes) { /* finished it off, remove it */
|
||||
SDL_assert(aligned == gapoffset);
|
||||
prevgap->next = gap->next;
|
||||
gap->next = renderer->vertex_data_gaps_pool;
|
||||
renderer->vertex_data_gaps_pool = gap;
|
||||
} else if (aligned == gapoffset) { /* trimmed the left */
|
||||
gap->offset += numbytes;
|
||||
gap->len -= numbytes;
|
||||
} else if (((aligned - gapoffset) + numbytes) == gap->len) { /* trimmed the right */
|
||||
gap->len -= numbytes;
|
||||
} else { /* split into two gaps */
|
||||
SDL_AllocVertGap *newgap = AllocateVertexGap(renderer);
|
||||
if (!newgap) {
|
||||
return NULL;
|
||||
}
|
||||
newgap->offset = aligned + numbytes;
|
||||
newgap->len = gap->len - (aligner + numbytes);
|
||||
newgap->next = gap->next;
|
||||
// gap->offset doesn't change.
|
||||
gap->len = aligner;
|
||||
gap->next = newgap;
|
||||
}
|
||||
|
||||
if (offset) {
|
||||
*offset = aligned;
|
||||
}
|
||||
return ((Uint8 *) renderer->vertex_data) + aligned;
|
||||
}
|
||||
|
||||
/* Try the next gap */
|
||||
prevgap = gap;
|
||||
gap = gap->next;
|
||||
}
|
||||
|
||||
/* no gaps with enough space; get a new piece of the vertex buffer */
|
||||
while (needed > renderer->vertex_data_allocation) {
|
||||
if (renderer->vertex_data_allocation < needed) {
|
||||
const size_t current_allocation = renderer->vertex_data ? renderer->vertex_data_allocation : 1024;
|
||||
const size_t newsize = current_allocation * 2;
|
||||
void *ptr = SDL_realloc(renderer->vertex_data, newsize);
|
||||
size_t newsize = current_allocation * 2;
|
||||
void *ptr;
|
||||
while (newsize < needed) {
|
||||
newsize *= 2;
|
||||
}
|
||||
ptr = SDL_realloc(renderer->vertex_data, newsize);
|
||||
if (ptr == NULL) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
|
|
@ -344,27 +284,13 @@ SDL_AllocateRenderVertices(SDL_Renderer *renderer, const size_t numbytes, const
|
|||
renderer->vertex_data_allocation = newsize;
|
||||
}
|
||||
|
||||
aligner = (alignment && ((renderer->vertex_data_used % alignment) != 0)) ? (alignment - (renderer->vertex_data_used % alignment)) : 0;
|
||||
aligned = renderer->vertex_data_used + aligner;
|
||||
|
||||
retval = ((Uint8 *) renderer->vertex_data) + aligned;
|
||||
if (offset) {
|
||||
*offset = aligned;
|
||||
}
|
||||
|
||||
if (aligner) { /* made a new gap... */
|
||||
SDL_AllocVertGap *newgap = AllocateVertexGap(renderer);
|
||||
if (newgap) { /* just let it slide as lost space if malloc fails. */
|
||||
newgap->offset = renderer->vertex_data_used;
|
||||
newgap->len = aligner;
|
||||
newgap->next = NULL;
|
||||
prevgap->next = newgap;
|
||||
}
|
||||
}
|
||||
|
||||
renderer->vertex_data_used += aligner + numbytes;
|
||||
|
||||
return retval;
|
||||
return ((Uint8 *) renderer->vertex_data) + aligned;
|
||||
}
|
||||
|
||||
static SDL_RenderCommand *
|
||||
|
|
@ -490,14 +416,14 @@ QueueCmdClear(SDL_Renderer *renderer)
|
|||
static int
|
||||
PrepQueueCmdDraw(SDL_Renderer *renderer, const Uint8 r, const Uint8 g, const Uint8 b, const Uint8 a)
|
||||
{
|
||||
int retval = 0;
|
||||
if (retval == 0) {
|
||||
retval = QueueCmdSetDrawColor(renderer, r, g, b, a);
|
||||
}
|
||||
if (retval == 0) {
|
||||
int retval = QueueCmdSetDrawColor(renderer, r, g, b, a);
|
||||
|
||||
/* Set the viewport and clip rect directly before draws, so the backends
|
||||
* don't have to worry about that state not being valid at draw time. */
|
||||
if (retval == 0 && !renderer->viewport_queued) {
|
||||
retval = QueueCmdSetViewport(renderer);
|
||||
}
|
||||
if (retval == 0) {
|
||||
if (retval == 0 && !renderer->cliprect_queued) {
|
||||
retval = QueueCmdSetClipRect(renderer);
|
||||
}
|
||||
return retval;
|
||||
|
|
@ -769,9 +695,13 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event)
|
|||
SDL_FPoint scale;
|
||||
GetWindowViewportValues(renderer, &logical_w, &logical_h, &viewport, &scale);
|
||||
if (logical_w) {
|
||||
int w = 1;
|
||||
int h = 1;
|
||||
SDL_GetRendererOutputSize(renderer, &w, &h);
|
||||
int w, h;
|
||||
|
||||
if (renderer->GetOutputSize) {
|
||||
renderer->GetOutputSize(renderer, &w, &h);
|
||||
} else {
|
||||
SDL_GetWindowSize(renderer->window, &w, &h);
|
||||
}
|
||||
|
||||
event->tfinger.x *= (w - 1);
|
||||
event->tfinger.y *= (h - 1);
|
||||
|
|
@ -979,7 +909,7 @@ error:
|
|||
SDL_Renderer *
|
||||
SDL_CreateSoftwareRenderer(SDL_Surface * surface)
|
||||
{
|
||||
#if !SDL_RENDER_DISABLED
|
||||
#if !SDL_RENDER_DISABLED && SDL_VIDEO_RENDER_SW
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
renderer = SW_CreateRendererForSurface(surface);
|
||||
|
|
@ -1046,6 +976,7 @@ IsSupportedBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
|
|||
case SDL_BLENDMODE_BLEND:
|
||||
case SDL_BLENDMODE_ADD:
|
||||
case SDL_BLENDMODE_MOD:
|
||||
case SDL_BLENDMODE_MUL:
|
||||
return SDL_TRUE;
|
||||
|
||||
default:
|
||||
|
|
@ -1185,7 +1116,11 @@ SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int
|
|||
renderer->textures = texture;
|
||||
|
||||
if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
|
||||
#if SDL_HAVE_YUV
|
||||
texture->yuv = SDL_SW_CreateYUVTexture(format, w, h);
|
||||
#else
|
||||
SDL_SetError("SDL not built with YUV support");
|
||||
#endif
|
||||
if (!texture->yuv) {
|
||||
SDL_DestroyTexture(texture);
|
||||
return NULL;
|
||||
|
|
@ -1232,7 +1167,7 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface)
|
|||
if (fmt->palette) {
|
||||
for (i = 0; i < fmt->palette->ncolors; i++) {
|
||||
Uint8 alpha_value = fmt->palette->colors[i].a;
|
||||
if (alpha_value != 0 || alpha_value != SDL_ALPHA_OPAQUE) {
|
||||
if (alpha_value != 0 && alpha_value != SDL_ALPHA_OPAQUE) {
|
||||
needAlpha = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
|
|
@ -1464,6 +1399,34 @@ SDL_GetTextureBlendMode(SDL_Texture * texture, SDL_BlendMode *blendMode)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_SetTextureScaleMode(SDL_Texture * texture, SDL_ScaleMode scaleMode)
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
CHECK_TEXTURE_MAGIC(texture, -1);
|
||||
|
||||
renderer = texture->renderer;
|
||||
renderer->SetTextureScaleMode(renderer, texture, scaleMode);
|
||||
texture->scaleMode = scaleMode;
|
||||
if (texture->native) {
|
||||
return SDL_SetTextureScaleMode(texture->native, scaleMode);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
SDL_GetTextureScaleMode(SDL_Texture * texture, SDL_ScaleMode *scaleMode)
|
||||
{
|
||||
CHECK_TEXTURE_MAGIC(texture, -1);
|
||||
|
||||
if (scaleMode) {
|
||||
*scaleMode = texture->scaleMode;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
static int
|
||||
SDL_UpdateTextureYUV(SDL_Texture * texture, const SDL_Rect * rect,
|
||||
const void *pixels, int pitch)
|
||||
|
|
@ -1509,6 +1472,7 @@ SDL_UpdateTextureYUV(SDL_Texture * texture, const SDL_Rect * rect,
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* SDL_HAVE_YUV */
|
||||
|
||||
static int
|
||||
SDL_UpdateTextureNative(SDL_Texture * texture, const SDL_Rect * rect,
|
||||
|
|
@ -1576,8 +1540,10 @@ SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
|
|||
|
||||
if ((rect->w == 0) || (rect->h == 0)) {
|
||||
return 0; /* nothing to do. */
|
||||
#if SDL_HAVE_YUV
|
||||
} else if (texture->yuv) {
|
||||
return SDL_UpdateTextureYUV(texture, rect, pixels, pitch);
|
||||
#endif
|
||||
} else if (texture->native) {
|
||||
return SDL_UpdateTextureNative(texture, rect, pixels, pitch);
|
||||
} else {
|
||||
|
|
@ -1589,6 +1555,7 @@ SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
|
|||
}
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
static int
|
||||
SDL_UpdateTextureYUVPlanar(SDL_Texture * texture, const SDL_Rect * rect,
|
||||
const Uint8 *Yplane, int Ypitch,
|
||||
|
|
@ -1640,12 +1607,14 @@ SDL_UpdateTextureYUVPlanar(SDL_Texture * texture, const SDL_Rect * rect,
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
#endif /* SDL_HAVE_YUV */
|
||||
|
||||
int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect,
|
||||
const Uint8 *Yplane, int Ypitch,
|
||||
const Uint8 *Uplane, int Upitch,
|
||||
const Uint8 *Vplane, int Vpitch)
|
||||
{
|
||||
#if SDL_HAVE_YUV
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Rect full_rect;
|
||||
|
||||
|
|
@ -1702,14 +1671,19 @@ int SDL_UpdateYUVTexture(SDL_Texture * texture, const SDL_Rect * rect,
|
|||
return SDL_Unsupported();
|
||||
}
|
||||
}
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
static int
|
||||
SDL_LockTextureYUV(SDL_Texture * texture, const SDL_Rect * rect,
|
||||
void **pixels, int *pitch)
|
||||
{
|
||||
return SDL_SW_LockYUVTexture(texture->yuv, rect, pixels, pitch);
|
||||
}
|
||||
#endif /* SDL_HAVE_YUV */
|
||||
|
||||
static int
|
||||
SDL_LockTextureNative(SDL_Texture * texture, const SDL_Rect * rect,
|
||||
|
|
@ -1743,12 +1717,15 @@ SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect,
|
|||
rect = &full_rect;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texture->yuv) {
|
||||
if (FlushRenderCommandsIfTextureNeeded(texture) < 0) {
|
||||
return -1;
|
||||
}
|
||||
return SDL_LockTextureYUV(texture, rect, pixels, pitch);
|
||||
} else if (texture->native) {
|
||||
} else
|
||||
#endif
|
||||
if (texture->native) {
|
||||
/* Calls a real SDL_LockTexture/SDL_UnlockTexture on unlock, flushing then. */
|
||||
return SDL_LockTextureNative(texture, rect, pixels, pitch);
|
||||
} else {
|
||||
|
|
@ -1760,6 +1737,43 @@ SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect,
|
|||
}
|
||||
}
|
||||
|
||||
int
|
||||
SDL_LockTextureToSurface(SDL_Texture *texture, const SDL_Rect *rect,
|
||||
SDL_Surface **surface)
|
||||
{
|
||||
SDL_Rect real_rect;
|
||||
void *pixels = NULL;
|
||||
int pitch, ret;
|
||||
|
||||
if (texture == NULL || surface == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
real_rect.x = 0;
|
||||
real_rect.y = 0;
|
||||
real_rect.w = texture->w;
|
||||
real_rect.h = texture->h;
|
||||
|
||||
if (rect) {
|
||||
SDL_IntersectRect(rect, &real_rect, &real_rect);
|
||||
}
|
||||
|
||||
ret = SDL_LockTexture(texture, &real_rect, &pixels, &pitch);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
texture->locked_surface = SDL_CreateRGBSurfaceWithFormatFrom(pixels, real_rect.w, real_rect.h, 0, pitch, texture->format);
|
||||
if (texture->locked_surface == NULL) {
|
||||
SDL_UnlockTexture(texture);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*surface = texture->locked_surface;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
static void
|
||||
SDL_UnlockTextureYUV(SDL_Texture * texture)
|
||||
{
|
||||
|
|
@ -1780,6 +1794,7 @@ SDL_UnlockTextureYUV(SDL_Texture * texture)
|
|||
rect.w, rect.h, native_pixels, native_pitch);
|
||||
SDL_UnlockTexture(native);
|
||||
}
|
||||
#endif /* SDL_HAVE_YUV */
|
||||
|
||||
static void
|
||||
SDL_UnlockTextureNative(SDL_Texture * texture)
|
||||
|
|
@ -1810,14 +1825,20 @@ SDL_UnlockTexture(SDL_Texture * texture)
|
|||
if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
|
||||
return;
|
||||
}
|
||||
#if SDL_HAVE_YUV
|
||||
if (texture->yuv) {
|
||||
SDL_UnlockTextureYUV(texture);
|
||||
} else if (texture->native) {
|
||||
} else
|
||||
#endif
|
||||
if (texture->native) {
|
||||
SDL_UnlockTextureNative(texture);
|
||||
} else {
|
||||
SDL_Renderer *renderer = texture->renderer;
|
||||
renderer->UnlockTexture(renderer, texture);
|
||||
}
|
||||
|
||||
SDL_FreeSurface(texture->locked_surface);
|
||||
texture->locked_surface = NULL;
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
|
|
@ -3164,12 +3185,18 @@ SDL_DestroyTexture(SDL_Texture * texture)
|
|||
if (texture->native) {
|
||||
SDL_DestroyTexture(texture->native);
|
||||
}
|
||||
#if SDL_HAVE_YUV
|
||||
if (texture->yuv) {
|
||||
SDL_SW_DestroyYUVTexture(texture->yuv);
|
||||
}
|
||||
#endif
|
||||
SDL_free(texture->pixels);
|
||||
|
||||
renderer->DestroyTexture(renderer, texture);
|
||||
|
||||
SDL_FreeSurface(texture->locked_surface);
|
||||
texture->locked_surface = NULL;
|
||||
|
||||
SDL_free(texture);
|
||||
}
|
||||
|
||||
|
|
@ -3177,8 +3204,6 @@ void
|
|||
SDL_DestroyRenderer(SDL_Renderer * renderer)
|
||||
{
|
||||
SDL_RenderCommand *cmd;
|
||||
SDL_AllocVertGap *gap;
|
||||
SDL_AllocVertGap *nextgap;
|
||||
|
||||
CHECK_RENDERER_MAGIC(renderer, );
|
||||
|
||||
|
|
@ -3203,16 +3228,6 @@ SDL_DestroyRenderer(SDL_Renderer * renderer)
|
|||
|
||||
SDL_free(renderer->vertex_data);
|
||||
|
||||
for (gap = renderer->vertex_data_gaps.next; gap; gap = nextgap) {
|
||||
nextgap = gap->next;
|
||||
SDL_free(gap);
|
||||
}
|
||||
|
||||
for (gap = renderer->vertex_data_gaps_pool; gap; gap = nextgap) {
|
||||
nextgap = gap->next;
|
||||
SDL_free(gap);
|
||||
}
|
||||
|
||||
/* Free existing textures for this renderer */
|
||||
while (renderer->textures) {
|
||||
SDL_Texture *tex = renderer->textures; (void) tex;
|
||||
|
|
@ -3306,6 +3321,9 @@ SDL_GetShortBlendMode(SDL_BlendMode blendMode)
|
|||
if (blendMode == SDL_BLENDMODE_MOD_FULL) {
|
||||
return SDL_BLENDMODE_MOD;
|
||||
}
|
||||
if (blendMode == SDL_BLENDMODE_MUL_FULL) {
|
||||
return SDL_BLENDMODE_MUL;
|
||||
}
|
||||
return blendMode;
|
||||
}
|
||||
|
||||
|
|
@ -3324,6 +3342,9 @@ SDL_GetLongBlendMode(SDL_BlendMode blendMode)
|
|||
if (blendMode == SDL_BLENDMODE_MOD) {
|
||||
return SDL_BLENDMODE_MOD_FULL;
|
||||
}
|
||||
if (blendMode == SDL_BLENDMODE_MUL) {
|
||||
return SDL_BLENDMODE_MUL_FULL;
|
||||
}
|
||||
return blendMode;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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,13 +32,6 @@
|
|||
|
||||
typedef struct SDL_RenderDriver SDL_RenderDriver;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SDL_ScaleModeNearest,
|
||||
SDL_ScaleModeLinear,
|
||||
SDL_ScaleModeBest
|
||||
} SDL_ScaleMode;
|
||||
|
||||
/* Define the SDL texture structure */
|
||||
struct SDL_Texture
|
||||
{
|
||||
|
|
@ -60,6 +53,7 @@ struct SDL_Texture
|
|||
void *pixels;
|
||||
int pitch;
|
||||
SDL_Rect locked_rect;
|
||||
SDL_Surface *locked_surface; /**< Locked region exposed as a SDL surface */
|
||||
|
||||
Uint32 last_command_generation; /* last command queue generation this texture was in. */
|
||||
|
||||
|
|
@ -110,13 +104,6 @@ typedef struct SDL_RenderCommand
|
|||
struct SDL_RenderCommand *next;
|
||||
} SDL_RenderCommand;
|
||||
|
||||
typedef struct SDL_AllocVertGap
|
||||
{
|
||||
size_t offset;
|
||||
size_t len;
|
||||
struct SDL_AllocVertGap *next;
|
||||
} SDL_AllocVertGap;
|
||||
|
||||
|
||||
/* Define the SDL renderer structure */
|
||||
struct SDL_Renderer
|
||||
|
|
@ -152,6 +139,7 @@ struct SDL_Renderer
|
|||
int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * rect, void **pixels, int *pitch);
|
||||
void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
|
||||
void (*SetTextureScaleMode) (SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode);
|
||||
int (*SetRenderTarget) (SDL_Renderer * renderer, SDL_Texture * texture);
|
||||
int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||
Uint32 format, void * pixels, int pitch);
|
||||
|
|
@ -226,8 +214,6 @@ struct SDL_Renderer
|
|||
void *vertex_data;
|
||||
size_t vertex_data_used;
|
||||
size_t vertex_data_allocation;
|
||||
SDL_AllocVertGap vertex_data_gaps;
|
||||
SDL_AllocVertGap *vertex_data_gaps_pool;
|
||||
|
||||
void *driverdata;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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
|
||||
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
/* This is the software implementation of the YUV texture support */
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
|
||||
#include "SDL_assert.h"
|
||||
|
||||
#include "SDL_yuv_sw_c.h"
|
||||
|
|
@ -411,4 +413,6 @@ SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata)
|
|||
}
|
||||
}
|
||||
|
||||
#endif /* SDL_HAVE_YUV */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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
|
||||
|
|
@ -234,6 +234,10 @@ D3D_InitRenderState(D3D_RenderData *data)
|
|||
D3DMATRIX matrix;
|
||||
|
||||
IDirect3DDevice9 *device = data->device;
|
||||
IDirect3DDevice9_SetPixelShader(device, NULL);
|
||||
IDirect3DDevice9_SetTexture(device, 0, NULL);
|
||||
IDirect3DDevice9_SetTexture(device, 1, NULL);
|
||||
IDirect3DDevice9_SetTexture(device, 2, NULL);
|
||||
IDirect3DDevice9_SetFVF(device, D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
|
||||
IDirect3DDevice9_SetVertexShader(device, NULL);
|
||||
IDirect3DDevice9_SetRenderState(device, D3DRS_ZENABLE, D3DZB_FALSE);
|
||||
|
|
@ -708,8 +712,27 @@ D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
texturedata->texture.dirty = SDL_TRUE;
|
||||
if (data->drawstate.texture == texture) {
|
||||
data->drawstate.texture = NULL;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
D3D_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
|
||||
{
|
||||
D3D_TextureData *texturedata = (D3D_TextureData *)texture->driverdata;
|
||||
|
||||
if (!texturedata) {
|
||||
return;
|
||||
}
|
||||
|
||||
texturedata->scaleMode = (scaleMode == SDL_ScaleModeNearest) ? D3DTEXF_POINT : D3DTEXF_LINEAR;
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -1216,7 +1239,7 @@ D3D_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *verti
|
|||
|
||||
/* upload the new VBO data for this set of commands. */
|
||||
vbo = data->vertexBuffers[vboidx];
|
||||
if (!vbo || (data->vertexBufferSize[vboidx] < vertsize)) {
|
||||
if (data->vertexBufferSize[vboidx] < vertsize) {
|
||||
const DWORD usage = D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY;
|
||||
const DWORD fvf = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1;
|
||||
if (vbo) {
|
||||
|
|
@ -1440,20 +1463,17 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
|||
|
||||
result = IDirect3DSurface9_GetDesc(backBuffer, &desc);
|
||||
if (FAILED(result)) {
|
||||
IDirect3DSurface9_Release(backBuffer);
|
||||
return D3D_SetError("GetDesc()", result);
|
||||
}
|
||||
|
||||
result = IDirect3DDevice9_CreateOffscreenPlainSurface(data->device, desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &surface, NULL);
|
||||
if (FAILED(result)) {
|
||||
IDirect3DSurface9_Release(backBuffer);
|
||||
return D3D_SetError("CreateOffscreenPlainSurface()", result);
|
||||
}
|
||||
|
||||
result = IDirect3DDevice9_GetRenderTargetData(data->device, backBuffer, surface);
|
||||
if (FAILED(result)) {
|
||||
IDirect3DSurface9_Release(surface);
|
||||
IDirect3DSurface9_Release(backBuffer);
|
||||
return D3D_SetError("GetRenderTargetData()", result);
|
||||
}
|
||||
|
||||
|
|
@ -1465,7 +1485,6 @@ D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
|||
result = IDirect3DSurface9_LockRect(surface, &locked, &d3drect, D3DLOCK_READONLY);
|
||||
if (FAILED(result)) {
|
||||
IDirect3DSurface9_Release(surface);
|
||||
IDirect3DSurface9_Release(backBuffer);
|
||||
return D3D_SetError("LockRect()", result);
|
||||
}
|
||||
|
||||
|
|
@ -1513,6 +1532,13 @@ D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
|
||||
if (renderdata->drawstate.texture == texture) {
|
||||
renderdata->drawstate.texture = NULL;
|
||||
renderdata->drawstate.shader = NULL;
|
||||
IDirect3DDevice9_SetPixelShader(renderdata->device, NULL);
|
||||
IDirect3DDevice9_SetTexture(renderdata->device, 0, NULL);
|
||||
if (data->yuv) {
|
||||
IDirect3DDevice9_SetTexture(renderdata->device, 1, NULL);
|
||||
IDirect3DDevice9_SetTexture(renderdata->device, 2, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
|
|
@ -1604,6 +1630,7 @@ D3D_Reset(SDL_Renderer * renderer)
|
|||
IDirect3DVertexBuffer9_Release(data->vertexBuffers[i]);
|
||||
}
|
||||
data->vertexBuffers[i] = NULL;
|
||||
data->vertexBufferSize[i] = 0;
|
||||
}
|
||||
|
||||
result = IDirect3DDevice9_Reset(data->device, &data->pparams);
|
||||
|
|
@ -1688,6 +1715,7 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->UpdateTextureYUV = D3D_UpdateTextureYUV;
|
||||
renderer->LockTexture = D3D_LockTexture;
|
||||
renderer->UnlockTexture = D3D_UnlockTexture;
|
||||
renderer->SetTextureScaleMode = D3D_SetTextureScaleMode;
|
||||
renderer->SetRenderTarget = D3D_SetRenderTarget;
|
||||
renderer->QueueSetViewport = D3D_QueueSetViewport;
|
||||
renderer->QueueSetDrawColor = D3D_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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
|
||||
|
|
@ -636,7 +636,8 @@ D3D11_CreateDeviceResources(SDL_Renderer * renderer)
|
|||
/* Create blending states: */
|
||||
if (!D3D11_CreateBlendState(renderer, SDL_BLENDMODE_BLEND) ||
|
||||
!D3D11_CreateBlendState(renderer, SDL_BLENDMODE_ADD) ||
|
||||
!D3D11_CreateBlendState(renderer, SDL_BLENDMODE_MOD)) {
|
||||
!D3D11_CreateBlendState(renderer, SDL_BLENDMODE_MOD) ||
|
||||
!D3D11_CreateBlendState(renderer, SDL_BLENDMODE_MUL)) {
|
||||
/* D3D11_CreateBlendMode will set the SDL error, if it fails */
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -1523,6 +1524,18 @@ D3D11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
SAFE_RELEASE(textureData->stagingTexture);
|
||||
}
|
||||
|
||||
static void
|
||||
D3D11_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
|
||||
{
|
||||
D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata;
|
||||
|
||||
if (!textureData) {
|
||||
return;
|
||||
}
|
||||
|
||||
textureData->scaleMode = (scaleMode == SDL_ScaleModeNearest) ? D3D11_FILTER_MIN_MAG_MIP_POINT : D3D11_FILTER_MIN_MAG_MIP_LINEAR;
|
||||
}
|
||||
|
||||
static int
|
||||
D3D11_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{
|
||||
|
|
@ -1728,82 +1741,88 @@ D3D11_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
|
|||
float minx, miny, maxx, maxy;
|
||||
float minu, maxu, minv, maxv;
|
||||
|
||||
if (flip & SDL_FLIP_HORIZONTAL) {
|
||||
minu = (float) srcrect->x / texture->w;
|
||||
maxu = (float) (srcrect->x + srcrect->w) / texture->w;
|
||||
} else {
|
||||
minu = (float) (srcrect->x + srcrect->w) / texture->w;
|
||||
maxu = (float) srcrect->x / texture->w;
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flip & SDL_FLIP_VERTICAL) {
|
||||
minv = (float) srcrect->y / texture->h;
|
||||
maxv = (float) (srcrect->y + srcrect->h) / texture->h;
|
||||
} else {
|
||||
minv = (float) (srcrect->y + srcrect->h) / texture->h;
|
||||
maxv = (float) srcrect->y / texture->h;
|
||||
}
|
||||
cmd->data.draw.count = 1;
|
||||
|
||||
minx = -center->x;
|
||||
maxx = dstrect->w - center->x;
|
||||
miny = -center->y;
|
||||
maxy = dstrect->h - center->y;
|
||||
|
||||
cmd->data.draw.count = 1;
|
||||
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->tex.x = minu;
|
||||
verts->tex.y = minv;
|
||||
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->tex.x = minu;
|
||||
verts->tex.y = maxv;
|
||||
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->tex.x = maxu;
|
||||
verts->tex.y = minv;
|
||||
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->tex.x = maxu;
|
||||
verts->tex.y = maxv;
|
||||
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->tex.x = 0.0f;
|
||||
verts->tex.y = 0.0f;
|
||||
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;
|
||||
|
|
@ -1817,6 +1836,12 @@ D3D11_UpdateVertexBuffer(SDL_Renderer *renderer,
|
|||
D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata;
|
||||
HRESULT result = S_OK;
|
||||
const int vbidx = rendererData->currentVertexBuffer;
|
||||
const UINT stride = sizeof(VertexPositionColor);
|
||||
const UINT offset = 0;
|
||||
|
||||
if (dataSizeInBytes == 0) {
|
||||
return 0; /* nothing to do. */
|
||||
}
|
||||
|
||||
if (rendererData->vertexBuffers[vbidx] && rendererData->vertexBufferSizes[vbidx] >= dataSizeInBytes) {
|
||||
D3D11_MAPPED_SUBRESOURCE mappedResource;
|
||||
|
|
@ -1836,8 +1861,6 @@ D3D11_UpdateVertexBuffer(SDL_Renderer *renderer,
|
|||
} else {
|
||||
D3D11_BUFFER_DESC vertexBufferDesc;
|
||||
D3D11_SUBRESOURCE_DATA vertexBufferData;
|
||||
const UINT stride = sizeof(VertexPositionColor);
|
||||
const UINT offset = 0;
|
||||
|
||||
SAFE_RELEASE(rendererData->vertexBuffers[vbidx]);
|
||||
|
||||
|
|
@ -1862,15 +1885,17 @@ D3D11_UpdateVertexBuffer(SDL_Renderer *renderer,
|
|||
return -1;
|
||||
}
|
||||
|
||||
ID3D11DeviceContext_IASetVertexBuffers(rendererData->d3dContext,
|
||||
0,
|
||||
1,
|
||||
&rendererData->vertexBuffers[vbidx],
|
||||
&stride,
|
||||
&offset
|
||||
);
|
||||
rendererData->vertexBufferSizes[vbidx] = dataSizeInBytes;
|
||||
}
|
||||
|
||||
ID3D11DeviceContext_IASetVertexBuffers(rendererData->d3dContext,
|
||||
0,
|
||||
1,
|
||||
&rendererData->vertexBuffers[vbidx],
|
||||
&stride,
|
||||
&offset
|
||||
);
|
||||
|
||||
rendererData->currentVertexBuffer++;
|
||||
if (rendererData->currentVertexBuffer >= SDL_arraysize(rendererData->vertexBuffers)) {
|
||||
rendererData->currentVertexBuffer = 0;
|
||||
|
|
@ -2486,6 +2511,7 @@ D3D11_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->UpdateTextureYUV = D3D11_UpdateTextureYUV;
|
||||
renderer->LockTexture = D3D11_LockTexture;
|
||||
renderer->UnlockTexture = D3D11_UnlockTexture;
|
||||
renderer->SetTextureScaleMode = D3D11_SetTextureScaleMode;
|
||||
renderer->SetRenderTarget = D3D11_SetRenderTarget;
|
||||
renderer->QueueSetViewport = D3D11_QueueSetViewport;
|
||||
renderer->QueueSetDrawColor = D3D11_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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,20 +26,22 @@
|
|||
#include "SDL_log.h"
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_syswm.h"
|
||||
#include "SDL_metal.h"
|
||||
#include "../SDL_sysrender.h"
|
||||
|
||||
#ifdef __MACOSX__
|
||||
#include "../../video/cocoa/SDL_cocoametalview.h"
|
||||
#else
|
||||
#include "../../video/uikit/SDL_uikitmetalview.h"
|
||||
#endif
|
||||
#include <Availability.h>
|
||||
#import <Metal/Metal.h>
|
||||
#import <QuartzCore/CAMetalLayer.h>
|
||||
|
||||
#ifdef __MACOSX__
|
||||
#import <AppKit/NSView.h>
|
||||
#endif
|
||||
|
||||
/* Regenerate these with build-metal-shaders.sh */
|
||||
#ifdef __MACOSX__
|
||||
#include "SDL_shaders_metal_osx.h"
|
||||
#elif defined(__TVOS__)
|
||||
#include "SDL_shaders_metal_tvos.h"
|
||||
#else
|
||||
#include "SDL_shaders_metal_ios.h"
|
||||
#endif
|
||||
|
|
@ -47,20 +49,23 @@
|
|||
/* Apple Metal renderer implementation */
|
||||
|
||||
/* 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 */
|
||||
#ifdef __MACOSX__
|
||||
#define CONSTANT_ALIGN 256
|
||||
#define CONSTANT_ALIGN(x) (256)
|
||||
#else
|
||||
#define CONSTANT_ALIGN 4
|
||||
#define CONSTANT_ALIGN(x) (x < 4 ? 4 : x)
|
||||
#endif
|
||||
|
||||
#define ALIGN_CONSTANTS(size) ((size + CONSTANT_ALIGN - 1) & (~(CONSTANT_ALIGN - 1)))
|
||||
#define DEVICE_ALIGN(x) (x < 4 ? 4 : x)
|
||||
|
||||
#define ALIGN_CONSTANTS(align, size) ((size + CONSTANT_ALIGN(align) - 1) & (~(CONSTANT_ALIGN(align) - 1)))
|
||||
|
||||
static const size_t CONSTANTS_OFFSET_INVALID = 0xFFFFFFFF;
|
||||
static const size_t CONSTANTS_OFFSET_IDENTITY = 0;
|
||||
static const size_t CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM = ALIGN_CONSTANTS(CONSTANTS_OFFSET_IDENTITY + sizeof(float) * 16);
|
||||
static const size_t CONSTANTS_OFFSET_DECODE_JPEG = ALIGN_CONSTANTS(CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM + sizeof(float) * 16);
|
||||
static const size_t CONSTANTS_OFFSET_DECODE_BT601 = ALIGN_CONSTANTS(CONSTANTS_OFFSET_DECODE_JPEG + sizeof(float) * 4 * 4);
|
||||
static const size_t CONSTANTS_OFFSET_DECODE_BT709 = ALIGN_CONSTANTS(CONSTANTS_OFFSET_DECODE_BT601 + sizeof(float) * 4 * 4);
|
||||
static const size_t CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM = ALIGN_CONSTANTS(16, CONSTANTS_OFFSET_IDENTITY + sizeof(float) * 16);
|
||||
static const size_t CONSTANTS_OFFSET_DECODE_JPEG = ALIGN_CONSTANTS(16, CONSTANTS_OFFSET_HALF_PIXEL_TRANSFORM + sizeof(float) * 16);
|
||||
static const size_t CONSTANTS_OFFSET_DECODE_BT601 = ALIGN_CONSTANTS(16, CONSTANTS_OFFSET_DECODE_JPEG + sizeof(float) * 4 * 4);
|
||||
static const size_t CONSTANTS_OFFSET_DECODE_BT709 = ALIGN_CONSTANTS(16, CONSTANTS_OFFSET_DECODE_BT601 + sizeof(float) * 4 * 4);
|
||||
static const size_t CONSTANTS_LENGTH = CONSTANTS_OFFSET_DECODE_BT709 + sizeof(float) * 4 * 4;
|
||||
|
||||
typedef enum SDL_MetalVertexFunction
|
||||
|
|
@ -118,6 +123,7 @@ typedef struct METAL_ShaderPipelines
|
|||
@property (nonatomic, retain) id<MTLSamplerState> mtlsamplerlinear;
|
||||
@property (nonatomic, retain) id<MTLBuffer> mtlbufconstants;
|
||||
@property (nonatomic, retain) id<MTLBuffer> mtlbufquadindices;
|
||||
@property (nonatomic, assign) SDL_MetalView mtlview;
|
||||
@property (nonatomic, retain) CAMetalLayer *mtllayer;
|
||||
@property (nonatomic, retain) MTLRenderPassDescriptor *mtlpassdesc;
|
||||
@property (nonatomic, assign) METAL_ShaderPipelines *activepipelines;
|
||||
|
|
@ -167,6 +173,7 @@ typedef struct METAL_ShaderPipelines
|
|||
[_mtltexture release];
|
||||
[_mtltexture_uv release];
|
||||
[_mtlsampler release];
|
||||
[_lockedbuffer release];
|
||||
[super dealloc];
|
||||
}
|
||||
#endif
|
||||
|
|
@ -259,8 +266,36 @@ MakePipelineState(METAL_RenderData *data, METAL_PipelineCache *cache,
|
|||
mtlpipedesc.vertexFunction = mtlvertfn;
|
||||
mtlpipedesc.fragmentFunction = mtlfragfn;
|
||||
|
||||
MTLRenderPipelineColorAttachmentDescriptor *rtdesc = mtlpipedesc.colorAttachments[0];
|
||||
MTLVertexDescriptor *vertdesc = [MTLVertexDescriptor vertexDescriptor];
|
||||
|
||||
switch (cache->vertexFunction) {
|
||||
case SDL_METAL_VERTEX_SOLID:
|
||||
/* position (float2) */
|
||||
vertdesc.layouts[0].stride = sizeof(float) * 2;
|
||||
vertdesc.layouts[0].stepFunction = MTLVertexStepFunctionPerVertex;
|
||||
|
||||
vertdesc.attributes[0].format = MTLVertexFormatFloat2;
|
||||
vertdesc.attributes[0].offset = 0;
|
||||
vertdesc.attributes[0].bufferIndex = 0;
|
||||
break;
|
||||
case SDL_METAL_VERTEX_COPY:
|
||||
/* position (float2), texcoord (float2) */
|
||||
vertdesc.layouts[0].stride = sizeof(float) * 4;
|
||||
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].bufferIndex = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
mtlpipedesc.vertexDescriptor = vertdesc;
|
||||
|
||||
MTLRenderPipelineColorAttachmentDescriptor *rtdesc = mtlpipedesc.colorAttachments[0];
|
||||
rtdesc.pixelFormat = cache->renderTargetFormat;
|
||||
|
||||
if (blendmode != SDL_BLENDMODE_NONE) {
|
||||
|
|
@ -322,6 +357,7 @@ MakePipelineCache(METAL_RenderData *data, METAL_PipelineCache *cache, const char
|
|||
MakePipelineState(data, cache, @" (blend=blend)", SDL_BLENDMODE_BLEND);
|
||||
MakePipelineState(data, cache, @" (blend=add)", SDL_BLENDMODE_ADD);
|
||||
MakePipelineState(data, cache, @" (blend=mod)", SDL_BLENDMODE_MOD);
|
||||
MakePipelineState(data, cache, @" (blend=mul)", SDL_BLENDMODE_MUL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -406,7 +442,7 @@ ChoosePipelineState(METAL_RenderData *data, METAL_ShaderPipelines *pipelines, SD
|
|||
}
|
||||
|
||||
static void
|
||||
METAL_ActivateRenderCommandEncoder(SDL_Renderer * renderer, MTLLoadAction load, MTLClearColor *clear_color)
|
||||
METAL_ActivateRenderCommandEncoder(SDL_Renderer * renderer, MTLLoadAction load, MTLClearColor *clear_color, id<MTLBuffer> vertex_buffer)
|
||||
{
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
|
||||
|
|
@ -449,6 +485,13 @@ METAL_ActivateRenderCommandEncoder(SDL_Renderer * renderer, MTLLoadAction load,
|
|||
data.mtlcmdencoder.label = @"SDL metal renderer render target";
|
||||
}
|
||||
|
||||
/* Set up buffer bindings for positions, texcoords, and color once here,
|
||||
* the offsets are adjusted in the code that uses them. */
|
||||
if (vertex_buffer != nil) {
|
||||
[data.mtlcmdencoder setVertexBuffer:vertex_buffer offset:0 atIndex:0];
|
||||
[data.mtlcmdencoder setFragmentBuffer:vertex_buffer offset:0 atIndex:0];
|
||||
}
|
||||
|
||||
data.activepipelines = ChooseShaderPipelines(data, mtltexture.pixelFormat);
|
||||
|
||||
// make sure this has a definite place in the queue. This way it will
|
||||
|
|
@ -790,6 +833,7 @@ METAL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
|
||||
int buffersize = 0;
|
||||
id<MTLBuffer> lockedbuffer = nil;
|
||||
|
||||
if (rect->w <= 0 || rect->h <= 0) {
|
||||
return SDL_SetError("Invalid rectangle dimensions for LockTexture.");
|
||||
|
|
@ -803,13 +847,19 @@ METAL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
buffersize = (*pitch) * rect->h;
|
||||
}
|
||||
|
||||
texturedata.lockedrect = *rect;
|
||||
texturedata.lockedbuffer = [data.mtldevice newBufferWithLength:buffersize options:MTLResourceStorageModeShared];
|
||||
if (texturedata.lockedbuffer == nil) {
|
||||
lockedbuffer = [data.mtldevice newBufferWithLength:buffersize options:MTLResourceStorageModeShared];
|
||||
if (lockedbuffer == nil) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
*pixels = [texturedata.lockedbuffer contents];
|
||||
texturedata.lockedrect = *rect;
|
||||
texturedata.lockedbuffer = lockedbuffer;
|
||||
*pixels = [lockedbuffer contents];
|
||||
|
||||
/* METAL_TextureData.lockedbuffer retains. */
|
||||
#if !__has_feature(objc_arc)
|
||||
[lockedbuffer release];
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}}
|
||||
|
|
@ -893,14 +943,23 @@ METAL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
[data.mtlcmdbuffer commit];
|
||||
data.mtlcmdbuffer = nil;
|
||||
|
||||
#if !__has_feature(objc_arc)
|
||||
[texturedata.lockedbuffer release];
|
||||
#endif
|
||||
|
||||
texturedata.lockedbuffer = nil;
|
||||
texturedata.lockedbuffer = nil; /* Retained property, so it calls release. */
|
||||
texturedata.hasdata = YES;
|
||||
}}
|
||||
|
||||
static void
|
||||
METAL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
|
||||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata;
|
||||
|
||||
if (scaleMode == SDL_ScaleModeNearest) {
|
||||
texturedata.mtlsampler = data.mtlsamplernearest;
|
||||
} else {
|
||||
texturedata.mtlsampler = data.mtlsamplerlinear;
|
||||
}
|
||||
}}
|
||||
|
||||
static int
|
||||
METAL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{ @autoreleasepool {
|
||||
|
|
@ -937,7 +996,7 @@ METAL_QueueSetViewport(SDL_Renderer * renderer, SDL_RenderCommand *cmd)
|
|||
const int w = cmd->data.viewport.rect.w;
|
||||
const int h = cmd->data.viewport.rect.h;
|
||||
const size_t matrixlen = sizeof (projection);
|
||||
float *matrix = (float *) SDL_AllocateRenderVertices(renderer, matrixlen, CONSTANT_ALIGN, &cmd->data.viewport.first);
|
||||
float *matrix = (float *) SDL_AllocateRenderVertices(renderer, matrixlen, CONSTANT_ALIGN(16), &cmd->data.viewport.first);
|
||||
if (!matrix) {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -959,7 +1018,7 @@ static int
|
|||
METAL_QueueSetDrawColor(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
|
||||
{
|
||||
const size_t vertlen = sizeof (float) * 4;
|
||||
float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, CONSTANT_ALIGN, &cmd->data.color.first);
|
||||
float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(16), &cmd->data.color.first);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -974,7 +1033,7 @@ static int
|
|||
METAL_QueueDrawPoints(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FPoint * points, int count)
|
||||
{
|
||||
const size_t vertlen = (sizeof (float) * 2) * count;
|
||||
float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, 0, &cmd->data.draw.first);
|
||||
float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(8), &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -987,7 +1046,7 @@ static int
|
|||
METAL_QueueFillRects(SDL_Renderer * renderer, SDL_RenderCommand *cmd, const SDL_FRect * rects, int count)
|
||||
{
|
||||
const size_t vertlen = (sizeof (float) * 8) * count;
|
||||
float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, 0, &cmd->data.draw.first);
|
||||
float *verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(8), &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -1029,28 +1088,31 @@ METAL_QueueCopy(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture * t
|
|||
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, 0, &cmd->data.draw.first);
|
||||
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++) = dstrect->x;
|
||||
*(verts++) = dstrect->y;
|
||||
*(verts++) = dstrect->x + dstrect->w;
|
||||
*(verts++) = dstrect->y + dstrect->h;
|
||||
*(verts++) = dstrect->x + dstrect->w;
|
||||
*(verts++) = dstrect->y;
|
||||
|
||||
*(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);
|
||||
|
||||
|
|
@ -1071,7 +1133,7 @@ METAL_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
|
|||
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, &cmd->data.draw.count);
|
||||
verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, CONSTANT_ALIGN(16), &cmd->data.draw.count);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -1090,7 +1152,7 @@ METAL_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
|
|||
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, 0, &cmd->data.draw.first);
|
||||
verts = (float *) SDL_AllocateRenderVertices(renderer, vertlen, DEVICE_ALIGN(8), &cmd->data.draw.first);
|
||||
if (!verts) {
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -1111,23 +1173,24 @@ METAL_QueueCopyEx(SDL_Renderer * renderer, SDL_RenderCommand *cmd, SDL_Texture *
|
|||
minv = tmp;
|
||||
}
|
||||
|
||||
// vertices
|
||||
/* Interleaved positions and texture coordinates */
|
||||
*(verts++) = -center->x;
|
||||
*(verts++) = dstrect->h - center->y;
|
||||
*(verts++) = -center->x;
|
||||
*(verts++) = -center->y;
|
||||
*(verts++) = dstrect->w - center->x;
|
||||
*(verts++) = dstrect->h - center->y;
|
||||
*(verts++) = dstrect->w - center->x;
|
||||
*(verts++) = -center->y;
|
||||
|
||||
// texcoords
|
||||
*(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;
|
||||
|
||||
|
|
@ -1139,8 +1202,10 @@ typedef struct
|
|||
{
|
||||
#if __has_feature(objc_arc)
|
||||
__unsafe_unretained id<MTLRenderPipelineState> pipeline;
|
||||
__unsafe_unretained id<MTLBuffer> vertex_buffer;
|
||||
#else
|
||||
id<MTLRenderPipelineState> pipeline;
|
||||
id<MTLBuffer> vertex_buffer;
|
||||
#endif
|
||||
size_t constants_offset;
|
||||
SDL_Texture *texture;
|
||||
|
|
@ -1163,7 +1228,7 @@ 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);
|
||||
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, statecache->vertex_buffer);
|
||||
|
||||
if (statecache->viewport_dirty) {
|
||||
MTLViewport viewport;
|
||||
|
|
@ -1199,7 +1264,7 @@ SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Met
|
|||
}
|
||||
|
||||
if (statecache->color_dirty) {
|
||||
[data.mtlcmdencoder setFragmentBuffer:mtlbufvertex offset:statecache->color_offset atIndex:0];
|
||||
[data.mtlcmdencoder setFragmentBufferOffset:statecache->color_offset atIndex:0];
|
||||
statecache->color_dirty = SDL_FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -1216,7 +1281,7 @@ SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Met
|
|||
statecache->constants_offset = constants_offset;
|
||||
}
|
||||
|
||||
[data.mtlcmdencoder setVertexBuffer:mtlbufvertex offset:first atIndex:0]; // position
|
||||
[data.mtlcmdencoder setVertexBufferOffset:first atIndex:0]; /* position/texcoords */
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -1229,8 +1294,6 @@ SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const size_t
|
|||
|
||||
SetDrawState(renderer, cmd, texturedata.fragmentFunction, constants_offset, mtlbufvertex, statecache);
|
||||
|
||||
[data.mtlcmdencoder setVertexBuffer:mtlbufvertex offset:cmd->data.draw.first+(8*sizeof (float)) atIndex:1]; // texcoords
|
||||
|
||||
if (texture != statecache->texture) {
|
||||
METAL_TextureData *oldtexturedata = NULL;
|
||||
if (statecache->texture) {
|
||||
|
|
@ -1254,9 +1317,12 @@ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
|
|||
{ @autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
METAL_DrawStateCache statecache;
|
||||
SDL_zero(statecache);
|
||||
|
||||
id<MTLBuffer> mtlbufvertex = nil;
|
||||
|
||||
statecache.pipeline = nil;
|
||||
statecache.vertex_buffer = nil;
|
||||
statecache.constants_offset = CONSTANTS_OFFSET_INVALID;
|
||||
statecache.texture = NULL;
|
||||
statecache.color_dirty = SDL_TRUE;
|
||||
|
|
@ -1280,6 +1346,8 @@ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
|
|||
#endif
|
||||
mtlbufvertex.label = @"SDL vertex data";
|
||||
SDL_memcpy([mtlbufvertex contents], vertices, vertsize);
|
||||
|
||||
statecache.vertex_buffer = mtlbufvertex;
|
||||
}
|
||||
|
||||
// If there's a command buffer here unexpectedly (app requested one?). Commit it so we can start fresh.
|
||||
|
|
@ -1294,6 +1362,7 @@ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
|
|||
SDL_memcpy(&statecache.viewport, &cmd->data.viewport.rect, sizeof (statecache.viewport));
|
||||
statecache.projection_offset = cmd->data.viewport.first;
|
||||
statecache.viewport_dirty = SDL_TRUE;
|
||||
statecache.cliprect_dirty = SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -1338,7 +1407,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.
|
||||
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionClear, &color);
|
||||
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionClear, &color, mtlbufvertex);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -1355,17 +1424,21 @@ METAL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
|
|||
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);
|
||||
/* 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 (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];
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
@ -1397,7 +1470,7 @@ 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);
|
||||
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil);
|
||||
|
||||
[data.mtlcmdencoder endEncoding];
|
||||
id<MTLTexture> mtltexture = data.mtlpassdesc.colorAttachments[0].texture;
|
||||
|
|
@ -1475,6 +1548,8 @@ METAL_DestroyRenderer(SDL_Renderer * renderer)
|
|||
}
|
||||
|
||||
DestroyAllPipelines(data.allpipelines, data.pipelinescount);
|
||||
|
||||
SDL_Metal_DestroyView(data.mtlview);
|
||||
}
|
||||
|
||||
SDL_free(renderer);
|
||||
|
|
@ -1490,7 +1565,7 @@ METAL_GetMetalLayer(SDL_Renderer * renderer)
|
|||
static void *
|
||||
METAL_GetMetalCommandEncoder(SDL_Renderer * renderer)
|
||||
{ @autoreleasepool {
|
||||
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL);
|
||||
METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil);
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata;
|
||||
return (__bridge void*)data.mtlcmdencoder;
|
||||
}}
|
||||
|
|
@ -1501,6 +1576,8 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
SDL_Renderer *renderer = NULL;
|
||||
METAL_RenderData *data = NULL;
|
||||
id<MTLDevice> mtldevice = nil;
|
||||
SDL_MetalView view = NULL;
|
||||
CAMetalLayer *layer = nil;
|
||||
SDL_SysWMinfo syswm;
|
||||
|
||||
SDL_VERSION(&syswm.version);
|
||||
|
|
@ -1527,26 +1604,42 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
view = SDL_Metal_CreateView(window);
|
||||
|
||||
if (view == NULL) {
|
||||
#if !__has_feature(objc_arc)
|
||||
[mtldevice release];
|
||||
#endif
|
||||
SDL_free(renderer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// !!! FIXME: error checking on all of this.
|
||||
data = [[METAL_RenderData alloc] init];
|
||||
|
||||
if (data == nil) {
|
||||
#if !__has_feature(objc_arc)
|
||||
[mtldevice release];
|
||||
#endif
|
||||
SDL_Metal_DestroyView(view);
|
||||
SDL_free(renderer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
renderer->driverdata = (void*)CFBridgingRetain(data);
|
||||
renderer->window = window;
|
||||
|
||||
data.mtlview = view;
|
||||
|
||||
#ifdef __MACOSX__
|
||||
NSView *view = Cocoa_Mtl_AddMetalView(window);
|
||||
CAMetalLayer *layer = (CAMetalLayer *)[view layer];
|
||||
layer = (CAMetalLayer *)[(NSView *)view layer];
|
||||
#else
|
||||
layer = (CAMetalLayer *)[(__bridge UIView *)view layer];
|
||||
#endif
|
||||
|
||||
layer.device = mtldevice;
|
||||
|
||||
//layer.colorspace = nil;
|
||||
|
||||
#else
|
||||
UIView *view = UIKit_Mtl_AddMetalView(window);
|
||||
CAMetalLayer *layer = (CAMetalLayer *)[view layer];
|
||||
#endif
|
||||
|
||||
// Necessary for RenderReadPixels.
|
||||
/* Necessary for RenderReadPixels. */
|
||||
layer.framebufferOnly = NO;
|
||||
|
||||
data.mtldevice = layer.device;
|
||||
|
|
@ -1685,6 +1778,7 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->UpdateTextureYUV = METAL_UpdateTextureYUV;
|
||||
renderer->LockTexture = METAL_LockTexture;
|
||||
renderer->UnlockTexture = METAL_UnlockTexture;
|
||||
renderer->SetTextureScaleMode = METAL_SetTextureScaleMode;
|
||||
renderer->SetRenderTarget = METAL_SetRenderTarget;
|
||||
renderer->QueueSetViewport = METAL_QueueSetViewport;
|
||||
renderer->QueueSetDrawColor = METAL_QueueSetDrawColor;
|
||||
|
|
@ -1763,7 +1857,6 @@ METAL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
[mtlsamplerlinear release];
|
||||
[mtlbufconstants release];
|
||||
[mtlbufquadindices release];
|
||||
[view release];
|
||||
[data release];
|
||||
[mtldevice release];
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -3,48 +3,56 @@
|
|||
|
||||
using namespace metal;
|
||||
|
||||
struct SolidVertexInput
|
||||
{
|
||||
float2 position [[attribute(0)]];
|
||||
};
|
||||
|
||||
struct SolidVertexOutput
|
||||
{
|
||||
float4 position [[position]];
|
||||
float pointSize [[point_size]];
|
||||
};
|
||||
|
||||
vertex SolidVertexOutput SDL_Solid_vertex(const device float2 *position [[buffer(0)]],
|
||||
vertex SolidVertexOutput SDL_Solid_vertex(SolidVertexInput in [[stage_in]],
|
||||
constant float4x4 &projection [[buffer(2)]],
|
||||
constant float4x4 &transform [[buffer(3)]],
|
||||
uint vid [[vertex_id]])
|
||||
constant float4x4 &transform [[buffer(3)]])
|
||||
{
|
||||
SolidVertexOutput v;
|
||||
v.position = (projection * transform) * float4(position[vid], 0.0f, 1.0f);
|
||||
v.position = (projection * transform) * float4(in.position, 0.0f, 1.0f);
|
||||
v.pointSize = 1.0f;
|
||||
return v;
|
||||
}
|
||||
|
||||
fragment float4 SDL_Solid_fragment(constant float4 &col [[buffer(0)]])
|
||||
fragment float4 SDL_Solid_fragment(const device float4 &col [[buffer(0)]])
|
||||
{
|
||||
return col;
|
||||
}
|
||||
|
||||
struct CopyVertexInput
|
||||
{
|
||||
float2 position [[attribute(0)]];
|
||||
float2 texcoord [[attribute(1)]];
|
||||
};
|
||||
|
||||
struct CopyVertexOutput
|
||||
{
|
||||
float4 position [[position]];
|
||||
float2 texcoord;
|
||||
};
|
||||
|
||||
vertex CopyVertexOutput SDL_Copy_vertex(const device float2 *position [[buffer(0)]],
|
||||
const device float2 *texcoords [[buffer(1)]],
|
||||
vertex CopyVertexOutput SDL_Copy_vertex(CopyVertexInput in [[stage_in]],
|
||||
constant float4x4 &projection [[buffer(2)]],
|
||||
constant float4x4 &transform [[buffer(3)]],
|
||||
uint vid [[vertex_id]])
|
||||
constant float4x4 &transform [[buffer(3)]])
|
||||
{
|
||||
CopyVertexOutput v;
|
||||
v.position = (projection * transform) * float4(position[vid], 0.0f, 1.0f);
|
||||
v.texcoord = texcoords[vid];
|
||||
v.position = (projection * transform) * float4(in.position, 0.0f, 1.0f);
|
||||
v.texcoord = in.texcoord;
|
||||
return v;
|
||||
}
|
||||
|
||||
fragment float4 SDL_Copy_fragment(CopyVertexOutput vert [[stage_in]],
|
||||
constant float4 &col [[buffer(0)]],
|
||||
const device float4 &col [[buffer(0)]],
|
||||
texture2d<float> tex [[texture(0)]],
|
||||
sampler s [[sampler(0)]])
|
||||
{
|
||||
|
|
@ -60,7 +68,7 @@ struct YUVDecode
|
|||
};
|
||||
|
||||
fragment float4 SDL_YUV_fragment(CopyVertexOutput vert [[stage_in]],
|
||||
constant float4 &col [[buffer(0)]],
|
||||
const device float4 &col [[buffer(0)]],
|
||||
constant YUVDecode &decode [[buffer(1)]],
|
||||
texture2d<float> texY [[texture(0)]],
|
||||
texture2d_array<float> texUV [[texture(1)]],
|
||||
|
|
@ -77,7 +85,7 @@ fragment float4 SDL_YUV_fragment(CopyVertexOutput vert [[stage_in]],
|
|||
}
|
||||
|
||||
fragment float4 SDL_NV12_fragment(CopyVertexOutput vert [[stage_in]],
|
||||
constant float4 &col [[buffer(0)]],
|
||||
const device float4 &col [[buffer(0)]],
|
||||
constant YUVDecode &decode [[buffer(1)]],
|
||||
texture2d<float> texY [[texture(0)]],
|
||||
texture2d<float> texUV [[texture(1)]],
|
||||
|
|
@ -93,7 +101,7 @@ fragment float4 SDL_NV12_fragment(CopyVertexOutput vert [[stage_in]],
|
|||
}
|
||||
|
||||
fragment float4 SDL_NV21_fragment(CopyVertexOutput vert [[stage_in]],
|
||||
constant float4 &col [[buffer(0)]],
|
||||
const device float4 &col [[buffer(0)]],
|
||||
constant YUVDecode &decode [[buffer(1)]],
|
||||
texture2d<float> texY [[texture(0)]],
|
||||
texture2d<float> texUV [[texture(1)]],
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
1854
Engine/lib/sdl/src/render/metal/SDL_shaders_metal_tvos.h
Normal file
1854
Engine/lib/sdl/src/render/metal/SDL_shaders_metal_tvos.h
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -6,13 +6,17 @@ cd `dirname "$0"`
|
|||
|
||||
generate_shaders()
|
||||
{
|
||||
platform=$1
|
||||
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/usr/bin/metal -std=$platform-metal1.1 -Wall -O3 -o ./sdl.air ./SDL_shaders_metal.metal || exit $?
|
||||
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/usr/bin/metal-ar rc sdl.metalar sdl.air || exit $?
|
||||
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/usr/bin/metallib -o sdl.metallib sdl.metalar || exit $?
|
||||
xxd -i sdl.metallib | perl -w -p -e 's/\Aunsigned /const unsigned /;' >./SDL_shaders_metal_$platform.h
|
||||
fileplatform=$1
|
||||
compileplatform=$2
|
||||
sdkplatform=$3
|
||||
minversion=$4
|
||||
xcrun -sdk $sdkplatform metal -c -std=$compileplatform-metal1.1 -m$sdkplatform-version-min=$minversion -Wall -O3 -o ./sdl.air ./SDL_shaders_metal.metal || exit $?
|
||||
xcrun -sdk $sdkplatform metal-ar rc sdl.metalar sdl.air || exit $?
|
||||
xcrun -sdk $sdkplatform metallib -o sdl.metallib sdl.metalar || exit $?
|
||||
xxd -i sdl.metallib | perl -w -p -e 's/\Aunsigned /const unsigned /;' >./SDL_shaders_metal_$fileplatform.h
|
||||
rm -f sdl.air sdl.metalar sdl.metallib
|
||||
}
|
||||
|
||||
generate_shaders osx
|
||||
generate_shaders ios
|
||||
generate_shaders osx osx macosx 10.11
|
||||
generate_shaders ios ios iphoneos 8.0
|
||||
generate_shaders tvos ios appletvos 9.0
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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
|
||||
|
|
@ -180,7 +180,7 @@ GL_ClearErrors(SDL_Renderer *renderer)
|
|||
}
|
||||
} else if (data->glGetError != NULL) {
|
||||
while (data->glGetError() != GL_NO_ERROR) {
|
||||
continue;
|
||||
/* continue; */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -768,6 +768,43 @@ GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
GL_UpdateTexture(renderer, texture, rect, pixels, data->pitch);
|
||||
}
|
||||
|
||||
static void
|
||||
GL_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
|
||||
{
|
||||
GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
|
||||
const GLenum textype = renderdata->textype;
|
||||
GL_TextureData *data = (GL_TextureData *) texture->driverdata;
|
||||
GLenum glScaleMode = (scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR;
|
||||
|
||||
renderdata->glEnable(textype);
|
||||
renderdata->glBindTexture(textype, data->texture);
|
||||
renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
|
||||
renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
|
||||
renderdata->glDisable(textype);
|
||||
|
||||
if (texture->format == SDL_PIXELFORMAT_YV12 ||
|
||||
texture->format == SDL_PIXELFORMAT_IYUV) {
|
||||
renderdata->glEnable(textype);
|
||||
renderdata->glBindTexture(textype, data->utexture);
|
||||
renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
|
||||
renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
|
||||
|
||||
renderdata->glBindTexture(textype, data->vtexture);
|
||||
renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
|
||||
renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
|
||||
renderdata->glDisable(textype);
|
||||
}
|
||||
|
||||
if (texture->format == SDL_PIXELFORMAT_NV12 ||
|
||||
texture->format == SDL_PIXELFORMAT_NV21) {
|
||||
renderdata->glEnable(textype);
|
||||
renderdata->glBindTexture(textype, data->utexture);
|
||||
renderdata->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, glScaleMode);
|
||||
renderdata->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, glScaleMode);
|
||||
renderdata->glDisable(textype);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
GL_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{
|
||||
|
|
@ -1166,9 +1203,9 @@ GL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
data->drawstate.clear_color = color;
|
||||
}
|
||||
|
||||
if (data->drawstate.cliprect_enabled) {
|
||||
if (data->drawstate.cliprect_enabled || data->drawstate.cliprect_enabled_dirty) {
|
||||
data->glDisable(GL_SCISSOR_TEST);
|
||||
data->drawstate.cliprect_enabled_dirty = SDL_TRUE;
|
||||
data->drawstate.cliprect_enabled_dirty = data->drawstate.cliprect_enabled;
|
||||
}
|
||||
|
||||
data->glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
|
@ -1210,6 +1247,7 @@ GL_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vertic
|
|||
data->glVertex2f(verts[0], verts[1]);
|
||||
}
|
||||
data->glEnd();
|
||||
verts -= 2 * count;
|
||||
|
||||
/* The line is half open, so we need one more point to complete it.
|
||||
* http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html
|
||||
|
|
@ -1576,6 +1614,7 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->UpdateTextureYUV = GL_UpdateTextureYUV;
|
||||
renderer->LockTexture = GL_LockTexture;
|
||||
renderer->UnlockTexture = GL_UnlockTexture;
|
||||
renderer->SetTextureScaleMode = GL_SetTextureScaleMode;
|
||||
renderer->SetRenderTarget = GL_SetRenderTarget;
|
||||
renderer->QueueSetViewport = GL_QueueSetViewport;
|
||||
renderer->QueueSetDrawColor = GL_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#if SDL_VIDEO_RENDER_OGL_ES && !SDL_RENDER_DISABLED
|
||||
|
||||
#include "SDL_assert.h"
|
||||
#include "SDL_hints.h"
|
||||
#include "SDL_opengles.h"
|
||||
#include "../SDL_sysrender.h"
|
||||
|
|
@ -492,6 +493,18 @@ GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
GLES_UpdateTexture(renderer, texture, &rect, data->pixels, data->pitch);
|
||||
}
|
||||
|
||||
static void
|
||||
GLES_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
|
||||
{
|
||||
GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
|
||||
GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
|
||||
GLenum glScaleMode = (scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR;
|
||||
|
||||
renderdata->glBindTexture(data->type, data->texture);
|
||||
renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, glScaleMode);
|
||||
renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, glScaleMode);
|
||||
}
|
||||
|
||||
static int
|
||||
GLES_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{
|
||||
|
|
@ -866,9 +879,9 @@ GLES_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *vert
|
|||
data->drawstate.clear_color = color;
|
||||
}
|
||||
|
||||
if (data->drawstate.cliprect_enabled) {
|
||||
if (data->drawstate.cliprect_enabled || data->drawstate.cliprect_enabled_dirty) {
|
||||
data->glDisable(GL_SCISSOR_TEST);
|
||||
data->drawstate.cliprect_enabled_dirty = SDL_TRUE;
|
||||
data->drawstate.cliprect_enabled_dirty = data->drawstate.cliprect_enabled;
|
||||
}
|
||||
|
||||
data->glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
|
@ -1141,6 +1154,7 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->UpdateTexture = GLES_UpdateTexture;
|
||||
renderer->LockTexture = GLES_LockTexture;
|
||||
renderer->UnlockTexture = GLES_UnlockTexture;
|
||||
renderer->SetTextureScaleMode = GLES_SetTextureScaleMode;
|
||||
renderer->SetRenderTarget = GLES_SetRenderTarget;
|
||||
renderer->QueueSetViewport = GLES_QueueSetViewport;
|
||||
renderer->QueueSetDrawColor = GLES_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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
|
||||
|
|
@ -54,7 +54,7 @@ SDL_PROC(void, glPixelStorei, (GLenum, GLint))
|
|||
SDL_PROC(void, glReadPixels, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoid*))
|
||||
SDL_PROC(void, glScissor, (GLint, GLint, GLsizei, GLsizei))
|
||||
SDL_PROC(void, glShaderBinary, (GLsizei, const GLuint *, GLenum, const void *, GLsizei))
|
||||
#if __NACL__ || __ANDROID__
|
||||
#if __NACL__
|
||||
SDL_PROC(void, glShaderSource, (GLuint, GLsizei, const GLchar **, const GLint *))
|
||||
#else
|
||||
SDL_PROC(void, glShaderSource, (GLuint, GLsizei, const GLchar* const*, const GLint *))
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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
|
||||
|
|
@ -208,7 +208,7 @@ GL_ClearErrors(SDL_Renderer *renderer)
|
|||
return;
|
||||
}
|
||||
while (data->glGetError() != GL_NO_ERROR) {
|
||||
continue;
|
||||
/* continue; */
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1277,9 +1277,9 @@ GLES2_RunCommandQueue(SDL_Renderer * renderer, SDL_RenderCommand *cmd, void *ver
|
|||
data->drawstate.clear_color = color;
|
||||
}
|
||||
|
||||
if (data->drawstate.cliprect_enabled) {
|
||||
if (data->drawstate.cliprect_enabled || data->drawstate.cliprect_enabled_dirty) {
|
||||
data->glDisable(GL_SCISSOR_TEST);
|
||||
data->drawstate.cliprect_enabled_dirty = SDL_TRUE;
|
||||
data->drawstate.cliprect_enabled_dirty = data->drawstate.cliprect_enabled;
|
||||
}
|
||||
|
||||
data->glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
|
@ -1743,6 +1743,36 @@ GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
|||
GLES2_UpdateTexture(renderer, texture, &rect, tdata->pixel_data, tdata->pitch);
|
||||
}
|
||||
|
||||
static void
|
||||
GLES2_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
|
||||
{
|
||||
GLES2_RenderData *renderdata = (GLES2_RenderData *) renderer->driverdata;
|
||||
GLES2_TextureData *data = (GLES2_TextureData *) texture->driverdata;
|
||||
GLenum glScaleMode = (scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR;
|
||||
|
||||
if (data->yuv) {
|
||||
renderdata->glActiveTexture(GL_TEXTURE2);
|
||||
renderdata->glBindTexture(data->texture_type, data->texture_v);
|
||||
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, glScaleMode);
|
||||
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, glScaleMode);
|
||||
|
||||
renderdata->glActiveTexture(GL_TEXTURE1);
|
||||
renderdata->glBindTexture(data->texture_type, data->texture_u);
|
||||
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, glScaleMode);
|
||||
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, glScaleMode);
|
||||
} else if (data->nv12) {
|
||||
renderdata->glActiveTexture(GL_TEXTURE1);
|
||||
renderdata->glBindTexture(data->texture_type, data->texture_u);
|
||||
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, glScaleMode);
|
||||
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, glScaleMode);
|
||||
}
|
||||
|
||||
renderdata->glActiveTexture(GL_TEXTURE0);
|
||||
renderdata->glBindTexture(data->texture_type, data->texture);
|
||||
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MIN_FILTER, glScaleMode);
|
||||
renderdata->glTexParameteri(data->texture_type, GL_TEXTURE_MAG_FILTER, glScaleMode);
|
||||
}
|
||||
|
||||
static int
|
||||
GLES2_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{
|
||||
|
|
@ -1812,7 +1842,7 @@ GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
|||
int status;
|
||||
|
||||
temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
||||
buflen = (size_t) (rect->h * temp_pitch);
|
||||
buflen = rect->h * temp_pitch;
|
||||
if (buflen == 0) {
|
||||
return 0; /* nothing to do. */
|
||||
}
|
||||
|
|
@ -2064,6 +2094,7 @@ GLES2_CreateRenderer(SDL_Window *window, Uint32 flags)
|
|||
renderer->UpdateTextureYUV = GLES2_UpdateTextureYUV;
|
||||
renderer->LockTexture = GLES2_LockTexture;
|
||||
renderer->UnlockTexture = GLES2_UnlockTexture;
|
||||
renderer->SetTextureScaleMode = GLES2_SetTextureScaleMode;
|
||||
renderer->SetRenderTarget = GLES2_SetRenderTarget;
|
||||
renderer->QueueSetViewport = GLES2_QueueSetViewport;
|
||||
renderer->QueueSetDrawColor = GLES2_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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
|
||||
|
|
@ -428,6 +428,12 @@ PSP_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
PSP_UpdateTexture(renderer, texture, &rect, psp_texture->data, psp_texture->pitch);
|
||||
}
|
||||
|
||||
static void
|
||||
PSP_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
|
||||
{
|
||||
/* Nothing to do because TextureActivate takes care of it */
|
||||
}
|
||||
|
||||
static int
|
||||
PSP_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{
|
||||
|
|
@ -670,7 +676,12 @@ PSP_SetBlendMode(SDL_Renderer * renderer, int blendMode)
|
|||
case SDL_BLENDMODE_MOD:
|
||||
sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
|
||||
sceGuEnable(GU_BLEND);
|
||||
sceGuBlendFunc( GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0);
|
||||
sceGuBlendFunc(GU_ADD, GU_FIX, GU_SRC_COLOR, 0, 0);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
sceGuTexFunc(GU_TFX_MODULATE , GU_TCC_RGBA);
|
||||
sceGuEnable(GU_BLEND);
|
||||
sceGuBlendFunc(GU_ADD, GU_DST_COLOR, GU_ONE_MINUS_SRC_ALPHA, 0, 0);
|
||||
break;
|
||||
}
|
||||
data->currentBlendMode = blendMode;
|
||||
|
|
@ -938,6 +949,7 @@ PSP_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->UpdateTexture = PSP_UpdateTexture;
|
||||
renderer->LockTexture = PSP_LockTexture;
|
||||
renderer->UnlockTexture = PSP_UnlockTexture;
|
||||
renderer->SetTextureScaleMode = PSP_SetTextureScaleMode;
|
||||
renderer->SetRenderTarget = PSP_SetRenderTarget;
|
||||
renderer->QueueSetViewport = PSP_QueueSetViewport;
|
||||
renderer->QueueSetDrawColor = PSP_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
|
||||
#include "SDL_draw.h"
|
||||
#include "SDL_blendfillrect.h"
|
||||
|
|
@ -42,6 +42,9 @@ SDL_BlendFillRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB555);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
FILLRECT(Uint16, DRAW_SETPIXEL_MUL_RGB555);
|
||||
break;
|
||||
default:
|
||||
FILLRECT(Uint16, DRAW_SETPIXEL_RGB555);
|
||||
break;
|
||||
|
|
@ -65,6 +68,9 @@ SDL_BlendFillRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB565);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
FILLRECT(Uint16, DRAW_SETPIXEL_MUL_RGB565);
|
||||
break;
|
||||
default:
|
||||
FILLRECT(Uint16, DRAW_SETPIXEL_RGB565);
|
||||
break;
|
||||
|
|
@ -88,6 +94,9 @@ SDL_BlendFillRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB888);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
FILLRECT(Uint32, DRAW_SETPIXEL_MUL_RGB888);
|
||||
break;
|
||||
default:
|
||||
FILLRECT(Uint32, DRAW_SETPIXEL_RGB888);
|
||||
break;
|
||||
|
|
@ -111,6 +120,9 @@ SDL_BlendFillRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_ARGB8888);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
FILLRECT(Uint32, DRAW_SETPIXEL_MUL_ARGB8888);
|
||||
break;
|
||||
default:
|
||||
FILLRECT(Uint32, DRAW_SETPIXEL_ARGB8888);
|
||||
break;
|
||||
|
|
@ -137,6 +149,9 @@ SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
FILLRECT(Uint16, DRAW_SETPIXEL_MOD_RGB);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
FILLRECT(Uint16, DRAW_SETPIXEL_MUL_RGB);
|
||||
break;
|
||||
default:
|
||||
FILLRECT(Uint16, DRAW_SETPIXEL_RGB);
|
||||
break;
|
||||
|
|
@ -153,6 +168,9 @@ SDL_BlendFillRect_RGB(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGB);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
FILLRECT(Uint32, DRAW_SETPIXEL_MUL_RGB);
|
||||
break;
|
||||
default:
|
||||
FILLRECT(Uint32, DRAW_SETPIXEL_RGB);
|
||||
break;
|
||||
|
|
@ -182,6 +200,9 @@ SDL_BlendFillRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
FILLRECT(Uint32, DRAW_SETPIXEL_MOD_RGBA);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
FILLRECT(Uint32, DRAW_SETPIXEL_MUL_RGBA);
|
||||
break;
|
||||
default:
|
||||
FILLRECT(Uint32, DRAW_SETPIXEL_RGBA);
|
||||
break;
|
||||
|
|
@ -331,6 +352,6 @@ SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count,
|
|||
return status;
|
||||
}
|
||||
|
||||
#endif /* !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
|
||||
#include "SDL_draw.h"
|
||||
#include "SDL_blendline.h"
|
||||
|
|
@ -59,6 +59,9 @@ SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
HLINE(Uint16, DRAW_SETPIXEL_MUL_RGB, draw_end);
|
||||
break;
|
||||
default:
|
||||
HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
|
||||
break;
|
||||
|
|
@ -74,6 +77,9 @@ SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
VLINE(Uint16, DRAW_SETPIXEL_MUL_RGB, draw_end);
|
||||
break;
|
||||
default:
|
||||
VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
|
||||
break;
|
||||
|
|
@ -89,6 +95,9 @@ SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DLINE(Uint16, DRAW_SETPIXEL_MUL_RGB, draw_end);
|
||||
break;
|
||||
default:
|
||||
DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
|
||||
break;
|
||||
|
|
@ -110,6 +119,11 @@ SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
DRAW_SETPIXELXY2_MOD_RGB, DRAW_SETPIXELXY2_MOD_RGB,
|
||||
draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY2_MUL_RGB, DRAW_SETPIXELXY2_MUL_RGB,
|
||||
draw_end);
|
||||
break;
|
||||
default:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
|
||||
|
|
@ -150,6 +164,9 @@ SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
HLINE(Uint16, DRAW_SETPIXEL_MUL_RGB555, draw_end);
|
||||
break;
|
||||
default:
|
||||
HLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
|
||||
break;
|
||||
|
|
@ -165,6 +182,9 @@ SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
VLINE(Uint16, DRAW_SETPIXEL_MUL_RGB555, draw_end);
|
||||
break;
|
||||
default:
|
||||
VLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
|
||||
break;
|
||||
|
|
@ -180,6 +200,9 @@ SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DLINE(Uint16, DRAW_SETPIXEL_MUL_RGB555, draw_end);
|
||||
break;
|
||||
default:
|
||||
DLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
|
||||
break;
|
||||
|
|
@ -201,6 +224,11 @@ SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
DRAW_SETPIXELXY_MOD_RGB555, DRAW_SETPIXELXY_MOD_RGB555,
|
||||
draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY_MUL_RGB555, DRAW_SETPIXELXY_MUL_RGB555,
|
||||
draw_end);
|
||||
break;
|
||||
default:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
|
||||
|
|
@ -241,6 +269,9 @@ SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
HLINE(Uint16, DRAW_SETPIXEL_MUL_RGB565, draw_end);
|
||||
break;
|
||||
default:
|
||||
HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
|
||||
break;
|
||||
|
|
@ -256,6 +287,9 @@ SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
VLINE(Uint16, DRAW_SETPIXEL_MUL_RGB565, draw_end);
|
||||
break;
|
||||
default:
|
||||
VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
|
||||
break;
|
||||
|
|
@ -271,6 +305,9 @@ SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DLINE(Uint16, DRAW_SETPIXEL_MUL_RGB565, draw_end);
|
||||
break;
|
||||
default:
|
||||
DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
|
||||
break;
|
||||
|
|
@ -292,6 +329,11 @@ SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
DRAW_SETPIXELXY_MOD_RGB565, DRAW_SETPIXELXY_MOD_RGB565,
|
||||
draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY_MUL_RGB565, DRAW_SETPIXELXY_MUL_RGB565,
|
||||
draw_end);
|
||||
break;
|
||||
default:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
|
||||
|
|
@ -333,6 +375,9 @@ SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
HLINE(Uint32, DRAW_SETPIXEL_MUL_RGB, draw_end);
|
||||
break;
|
||||
default:
|
||||
HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
|
||||
break;
|
||||
|
|
@ -348,6 +393,9 @@ SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
VLINE(Uint32, DRAW_SETPIXEL_MUL_RGB, draw_end);
|
||||
break;
|
||||
default:
|
||||
VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
|
||||
break;
|
||||
|
|
@ -363,6 +411,9 @@ SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DLINE(Uint32, DRAW_SETPIXEL_MUL_RGB, draw_end);
|
||||
break;
|
||||
default:
|
||||
DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
|
||||
break;
|
||||
|
|
@ -384,6 +435,11 @@ SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
DRAW_SETPIXELXY4_MOD_RGB, DRAW_SETPIXELXY4_MOD_RGB,
|
||||
draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY4_MUL_RGB, DRAW_SETPIXELXY4_MUL_RGB,
|
||||
draw_end);
|
||||
break;
|
||||
default:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
|
||||
|
|
@ -425,6 +481,9 @@ SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
HLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
HLINE(Uint32, DRAW_SETPIXEL_MUL_RGBA, draw_end);
|
||||
break;
|
||||
default:
|
||||
HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
|
||||
break;
|
||||
|
|
@ -440,6 +499,9 @@ SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
VLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
VLINE(Uint32, DRAW_SETPIXEL_MUL_RGBA, draw_end);
|
||||
break;
|
||||
default:
|
||||
VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
|
||||
break;
|
||||
|
|
@ -455,6 +517,9 @@ SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DLINE(Uint32, DRAW_SETPIXEL_MUL_RGBA, draw_end);
|
||||
break;
|
||||
default:
|
||||
DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
|
||||
break;
|
||||
|
|
@ -476,6 +541,11 @@ SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
DRAW_SETPIXELXY4_MOD_RGBA, DRAW_SETPIXELXY4_MOD_RGBA,
|
||||
draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY4_MUL_RGBA, DRAW_SETPIXELXY4_MUL_RGBA,
|
||||
draw_end);
|
||||
break;
|
||||
default:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
|
||||
|
|
@ -516,6 +586,9 @@ SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
HLINE(Uint32, DRAW_SETPIXEL_MUL_RGB888, draw_end);
|
||||
break;
|
||||
default:
|
||||
HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
|
||||
break;
|
||||
|
|
@ -531,6 +604,9 @@ SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
VLINE(Uint32, DRAW_SETPIXEL_MUL_RGB888, draw_end);
|
||||
break;
|
||||
default:
|
||||
VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
|
||||
break;
|
||||
|
|
@ -546,6 +622,9 @@ SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DLINE(Uint32, DRAW_SETPIXEL_MUL_RGB888, draw_end);
|
||||
break;
|
||||
default:
|
||||
DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
|
||||
break;
|
||||
|
|
@ -567,6 +646,11 @@ SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
DRAW_SETPIXELXY_MOD_RGB888, DRAW_SETPIXELXY_MOD_RGB888,
|
||||
draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY_MUL_RGB888, DRAW_SETPIXELXY_MUL_RGB888,
|
||||
draw_end);
|
||||
break;
|
||||
default:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
|
||||
|
|
@ -607,6 +691,9 @@ SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
HLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
HLINE(Uint32, DRAW_SETPIXEL_MUL_ARGB8888, draw_end);
|
||||
break;
|
||||
default:
|
||||
HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
|
||||
break;
|
||||
|
|
@ -622,6 +709,9 @@ SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
VLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
VLINE(Uint32, DRAW_SETPIXEL_MUL_ARGB8888, draw_end);
|
||||
break;
|
||||
default:
|
||||
VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
|
||||
break;
|
||||
|
|
@ -637,6 +727,9 @@ SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DLINE(Uint32, DRAW_SETPIXEL_MUL_ARGB8888, draw_end);
|
||||
break;
|
||||
default:
|
||||
DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
|
||||
break;
|
||||
|
|
@ -658,6 +751,11 @@ SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
|
|||
DRAW_SETPIXELXY_MOD_ARGB8888, DRAW_SETPIXELXY_MOD_ARGB8888,
|
||||
draw_end);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY_MUL_ARGB8888, DRAW_SETPIXELXY_MUL_ARGB8888,
|
||||
draw_end);
|
||||
break;
|
||||
default:
|
||||
AALINE(x1, y1, x2, y2,
|
||||
DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
|
||||
|
|
@ -772,6 +870,6 @@ SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif /* !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
|
||||
#include "SDL_draw.h"
|
||||
#include "SDL_blendpoint.h"
|
||||
|
|
@ -42,6 +42,9 @@ SDL_BlendPoint_RGB555(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY_MOD_RGB555(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DRAW_SETPIXELXY_MUL_RGB555(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY_RGB555(x, y);
|
||||
break;
|
||||
|
|
@ -65,6 +68,9 @@ SDL_BlendPoint_RGB565(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY_MOD_RGB565(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DRAW_SETPIXELXY_MUL_RGB565(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY_RGB565(x, y);
|
||||
break;
|
||||
|
|
@ -88,6 +94,9 @@ SDL_BlendPoint_RGB888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode,
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY_MOD_RGB888(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DRAW_SETPIXELXY_MUL_RGB888(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY_RGB888(x, y);
|
||||
break;
|
||||
|
|
@ -111,6 +120,9 @@ SDL_BlendPoint_ARGB8888(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY_MOD_ARGB8888(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DRAW_SETPIXELXY_MUL_ARGB8888(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY_ARGB8888(x, y);
|
||||
break;
|
||||
|
|
@ -137,6 +149,9 @@ SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uin
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY2_MOD_RGB(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DRAW_SETPIXELXY2_MUL_RGB(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY2_RGB(x, y);
|
||||
break;
|
||||
|
|
@ -153,6 +168,9 @@ SDL_BlendPoint_RGB(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uin
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY4_MOD_RGB(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DRAW_SETPIXELXY4_MUL_RGB(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY4_RGB(x, y);
|
||||
break;
|
||||
|
|
@ -182,6 +200,9 @@ SDL_BlendPoint_RGBA(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Ui
|
|||
case SDL_BLENDMODE_MOD:
|
||||
DRAW_SETPIXELXY4_MOD_RGBA(x, y);
|
||||
break;
|
||||
case SDL_BLENDMODE_MUL:
|
||||
DRAW_SETPIXELXY4_MUL_RGBA(x, y);
|
||||
break;
|
||||
default:
|
||||
DRAW_SETPIXELXY4_RGBA(x, y);
|
||||
break;
|
||||
|
|
@ -336,6 +357,6 @@ SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
return status;
|
||||
}
|
||||
|
||||
#endif /* !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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
|
||||
|
|
@ -80,6 +80,17 @@ do { \
|
|||
setpixel; \
|
||||
} while (0)
|
||||
|
||||
#define DRAW_SETPIXEL_MUL(getpixel, setpixel) \
|
||||
do { \
|
||||
unsigned sr, sg, sb, sa; sa = 0xFF; \
|
||||
getpixel; \
|
||||
sr = DRAW_MUL(sr, r) + DRAW_MUL(inva, sr); if (sr > 0xff) sr = 0xff; \
|
||||
sg = DRAW_MUL(sg, g) + DRAW_MUL(inva, sg); if (sg > 0xff) sg = 0xff; \
|
||||
sb = DRAW_MUL(sb, b) + DRAW_MUL(inva, sb); if (sb > 0xff) sb = 0xff; \
|
||||
sa = DRAW_MUL(sa, a) + DRAW_MUL(inva, sa); if (sa > 0xff) sa = 0xff; \
|
||||
setpixel; \
|
||||
} while (0)
|
||||
|
||||
#define DRAW_SETPIXELXY(x, y, type, bpp, op) \
|
||||
do { \
|
||||
type *pixel = (type *)((Uint8 *)dst->pixels + (y) * dst->pitch \
|
||||
|
|
@ -106,6 +117,10 @@ do { \
|
|||
DRAW_SETPIXEL_MOD(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
|
||||
RGB555_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_MUL_RGB555 \
|
||||
DRAW_SETPIXEL_MUL(RGB_FROM_RGB555(*pixel, sr, sg, sb), \
|
||||
RGB555_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXELXY_RGB555(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB555)
|
||||
|
||||
|
|
@ -118,6 +133,9 @@ do { \
|
|||
#define DRAW_SETPIXELXY_MOD_RGB555(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB555)
|
||||
|
||||
#define DRAW_SETPIXELXY_MUL_RGB555(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MUL_RGB555)
|
||||
|
||||
/*
|
||||
* Define draw operators for RGB565
|
||||
*/
|
||||
|
|
@ -137,6 +155,10 @@ do { \
|
|||
DRAW_SETPIXEL_MOD(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
|
||||
RGB565_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_MUL_RGB565 \
|
||||
DRAW_SETPIXEL_MUL(RGB_FROM_RGB565(*pixel, sr, sg, sb), \
|
||||
RGB565_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXELXY_RGB565(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB565)
|
||||
|
||||
|
|
@ -149,6 +171,9 @@ do { \
|
|||
#define DRAW_SETPIXELXY_MOD_RGB565(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MOD_RGB565)
|
||||
|
||||
#define DRAW_SETPIXELXY_MUL_RGB565(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MUL_RGB565)
|
||||
|
||||
/*
|
||||
* Define draw operators for RGB888
|
||||
*/
|
||||
|
|
@ -168,6 +193,10 @@ do { \
|
|||
DRAW_SETPIXEL_MOD(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
|
||||
RGB888_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_MUL_RGB888 \
|
||||
DRAW_SETPIXEL_MUL(RGB_FROM_RGB888(*pixel, sr, sg, sb), \
|
||||
RGB888_FROM_RGB(*pixel, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXELXY_RGB888(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGB888)
|
||||
|
||||
|
|
@ -180,6 +209,9 @@ do { \
|
|||
#define DRAW_SETPIXELXY_MOD_RGB888(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB888)
|
||||
|
||||
#define DRAW_SETPIXELXY_MUL_RGB888(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_RGB888)
|
||||
|
||||
/*
|
||||
* Define draw operators for ARGB8888
|
||||
*/
|
||||
|
|
@ -199,6 +231,10 @@ do { \
|
|||
DRAW_SETPIXEL_MOD(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
|
||||
ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
|
||||
|
||||
#define DRAW_SETPIXEL_MUL_ARGB8888 \
|
||||
DRAW_SETPIXEL_MUL(RGBA_FROM_ARGB8888(*pixel, sr, sg, sb, sa), \
|
||||
ARGB8888_FROM_RGBA(*pixel, sr, sg, sb, sa))
|
||||
|
||||
#define DRAW_SETPIXELXY_ARGB8888(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_ARGB8888)
|
||||
|
||||
|
|
@ -211,6 +247,9 @@ do { \
|
|||
#define DRAW_SETPIXELXY_MOD_ARGB8888(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_ARGB8888)
|
||||
|
||||
#define DRAW_SETPIXELXY_MUL_ARGB8888(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_ARGB8888)
|
||||
|
||||
/*
|
||||
* Define draw operators for general RGB
|
||||
*/
|
||||
|
|
@ -230,6 +269,10 @@ do { \
|
|||
DRAW_SETPIXEL_MOD(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
|
||||
PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXEL_MUL_RGB \
|
||||
DRAW_SETPIXEL_MUL(RGB_FROM_PIXEL(*pixel, fmt, sr, sg, sb), \
|
||||
PIXEL_FROM_RGB(*pixel, fmt, sr, sg, sb))
|
||||
|
||||
#define DRAW_SETPIXELXY2_RGB(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_RGB)
|
||||
|
||||
|
|
@ -254,6 +297,12 @@ do { \
|
|||
#define DRAW_SETPIXELXY4_MOD_RGB(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGB)
|
||||
|
||||
#define DRAW_SETPIXELXY2_MUL_RGB(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint16, 2, DRAW_SETPIXEL_MUL_RGB)
|
||||
|
||||
#define DRAW_SETPIXELXY4_MUL_RGB(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_RGB)
|
||||
|
||||
|
||||
/*
|
||||
* Define draw operators for general RGBA
|
||||
|
|
@ -274,6 +323,10 @@ do { \
|
|||
DRAW_SETPIXEL_MOD(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
|
||||
PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
|
||||
|
||||
#define DRAW_SETPIXEL_MUL_RGBA \
|
||||
DRAW_SETPIXEL_MUL(RGBA_FROM_PIXEL(*pixel, fmt, sr, sg, sb, sa), \
|
||||
PIXEL_FROM_RGBA(*pixel, fmt, sr, sg, sb, sa))
|
||||
|
||||
#define DRAW_SETPIXELXY4_RGBA(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_RGBA)
|
||||
|
||||
|
|
@ -286,6 +339,9 @@ do { \
|
|||
#define DRAW_SETPIXELXY4_MOD_RGBA(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MOD_RGBA)
|
||||
|
||||
#define DRAW_SETPIXELXY4_MUL_RGBA(x, y) \
|
||||
DRAW_SETPIXELXY(x, y, Uint32, 4, DRAW_SETPIXEL_MUL_RGBA)
|
||||
|
||||
/*
|
||||
* Define line drawing macro
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
|
||||
#include "SDL_draw.h"
|
||||
#include "SDL_drawline.h"
|
||||
|
|
@ -204,6 +204,6 @@ SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif /* !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
|
||||
#include "SDL_draw.h"
|
||||
#include "SDL_drawpoint.h"
|
||||
|
|
@ -109,6 +109,6 @@ SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
|
|||
return 0;
|
||||
}
|
||||
|
||||
#endif /* !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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,7 +20,7 @@
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if !SDL_RENDER_DISABLED
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
|
||||
#include "../SDL_sysrender.h"
|
||||
#include "SDL_render_sw_c.h"
|
||||
|
|
@ -179,6 +179,11 @@ SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
{
|
||||
}
|
||||
|
||||
static void
|
||||
SW_SetTextureScaleMode(SDL_Renderer * renderer, SDL_Texture * texture, SDL_ScaleMode scaleMode)
|
||||
{
|
||||
}
|
||||
|
||||
static int
|
||||
SW_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
{
|
||||
|
|
@ -394,8 +399,8 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Surface *surface, SDL_Texture * tex
|
|||
blitRequired = SDL_TRUE;
|
||||
}
|
||||
|
||||
/* The color and alpha modulation has to be applied before the rotation when using the NONE and MOD blend modes. */
|
||||
if ((blendmode == SDL_BLENDMODE_NONE || blendmode == SDL_BLENDMODE_MOD) && (alphaMod & rMod & gMod & bMod) != 255) {
|
||||
/* The color and alpha modulation has to be applied before the rotation when using the NONE, MOD or MUL blend modes. */
|
||||
if ((blendmode == SDL_BLENDMODE_NONE || blendmode == SDL_BLENDMODE_MOD || blendmode == SDL_BLENDMODE_MUL) && (alphaMod & rMod & gMod & bMod) != 255) {
|
||||
applyModulation = SDL_TRUE;
|
||||
SDL_SetSurfaceAlphaMod(src_clone, alphaMod);
|
||||
SDL_SetSurfaceColorMod(src_clone, rMod, gMod, bMod);
|
||||
|
|
@ -568,7 +573,7 @@ PrepTextureForCopy(const SDL_RenderCommand *cmd)
|
|||
SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
|
||||
const SDL_bool colormod = ((r & g & b) != 0xFF);
|
||||
const SDL_bool alphamod = (a != 0xFF);
|
||||
const SDL_bool blending = ((blend == SDL_BLENDMODE_ADD) || (blend == SDL_BLENDMODE_MOD));
|
||||
const SDL_bool blending = ((blend == SDL_BLENDMODE_ADD) || (blend == SDL_BLENDMODE_MOD) || (blend == SDL_BLENDMODE_MUL));
|
||||
|
||||
if (colormod || alphamod || blending) {
|
||||
SDL_SetSurfaceRLE(surface, 0);
|
||||
|
|
@ -830,6 +835,7 @@ SW_CreateRendererForSurface(SDL_Surface * surface)
|
|||
renderer->UpdateTexture = SW_UpdateTexture;
|
||||
renderer->LockTexture = SW_LockTexture;
|
||||
renderer->UnlockTexture = SW_UnlockTexture;
|
||||
renderer->SetTextureScaleMode = SW_SetTextureScaleMode;
|
||||
renderer->SetRenderTarget = SW_SetRenderTarget;
|
||||
renderer->QueueSetViewport = SW_QueueSetViewport;
|
||||
renderer->QueueSetDrawColor = SW_QueueSetViewport; /* SetViewport and SetDrawColor are (currently) no-ops. */
|
||||
|
|
@ -883,6 +889,6 @@ SDL_RenderDriver SW_RenderDriver = {
|
|||
0}
|
||||
};
|
||||
|
||||
#endif /* !SDL_RENDER_DISABLED */
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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,6 +30,8 @@ Andreas Schiffler -- aschiffler at ferzkopp dot net
|
|||
*/
|
||||
#include "../../SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED
|
||||
|
||||
#if defined(__WIN32__)
|
||||
#include "../../core/windows/SDL_windows.h"
|
||||
#endif
|
||||
|
|
@ -474,8 +476,8 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery,
|
|||
SDL_FillRect(rz_dst, NULL, colorkey);
|
||||
} else if (blendmode == SDL_BLENDMODE_NONE) {
|
||||
blendmode = SDL_BLENDMODE_BLEND;
|
||||
} else if (blendmode == SDL_BLENDMODE_MOD) {
|
||||
/* Without a colorkey, the target texture has to be white for the MOD blend mode so
|
||||
} else if (blendmode == SDL_BLENDMODE_MOD || blendmode == SDL_BLENDMODE_MUL) {
|
||||
/* Without a colorkey, the target texture has to be white for the MOD and MUL blend mode so
|
||||
* that the pixels outside the rotated area don't affect the destination surface.
|
||||
*/
|
||||
colorkey = SDL_MapRGBA(rz_dst->format, 255, 255, 255, 0);
|
||||
|
|
@ -532,3 +534,5 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery,
|
|||
/* Return rotated surface */
|
||||
return rz_dst;
|
||||
}
|
||||
|
||||
#endif /* SDL_VIDEO_RENDER_SW && !SDL_RENDER_DISABLED */
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Simple DirectMedia Layer
|
||||
Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2020 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue