| | |
| | | /* |
| | | Simple DirectMedia Layer |
| | | Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org> |
| | | Copyright (C) 1997-2018 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 |
| | |
| | | #define SDL_WINDOWRENDERDATA "_SDL_WindowRenderData" |
| | | |
| | | #define CHECK_RENDERER_MAGIC(renderer, retval) \ |
| | | SDL_assert(renderer && renderer->magic == &renderer_magic); \ |
| | | if (!renderer || renderer->magic != &renderer_magic) { \ |
| | | SDL_SetError("Invalid renderer"); \ |
| | | return retval; \ |
| | | } |
| | | |
| | | #define CHECK_TEXTURE_MAGIC(texture, retval) \ |
| | | SDL_assert(texture && texture->magic == &texture_magic); \ |
| | | if (!texture || texture->magic != &texture_magic) { \ |
| | | SDL_SetError("Invalid texture"); \ |
| | | return retval; \ |
| | | } |
| | | |
| | | /* Predefined blend modes */ |
| | | #define SDL_COMPOSE_BLENDMODE(srcColorFactor, dstColorFactor, colorOperation, \ |
| | | srcAlphaFactor, dstAlphaFactor, alphaOperation) \ |
| | | (SDL_BlendMode)(((Uint32)colorOperation << 0) | \ |
| | | ((Uint32)srcColorFactor << 4) | \ |
| | | ((Uint32)dstColorFactor << 8) | \ |
| | | ((Uint32)alphaOperation << 16) | \ |
| | | ((Uint32)srcAlphaFactor << 20) | \ |
| | | ((Uint32)dstAlphaFactor << 24)) |
| | | |
| | | #define SDL_BLENDMODE_NONE_FULL \ |
| | | SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ZERO, SDL_BLENDOPERATION_ADD, \ |
| | | SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ZERO, SDL_BLENDOPERATION_ADD) |
| | | |
| | | #define SDL_BLENDMODE_BLEND_FULL \ |
| | | SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD, \ |
| | | SDL_BLENDFACTOR_ONE, SDL_BLENDFACTOR_ONE_MINUS_SRC_ALPHA, SDL_BLENDOPERATION_ADD) |
| | | |
| | | #define SDL_BLENDMODE_ADD_FULL \ |
| | | SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD, \ |
| | | SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD) |
| | | |
| | | #define SDL_BLENDMODE_MOD_FULL \ |
| | | SDL_COMPOSE_BLENDMODE(SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_SRC_COLOR, SDL_BLENDOPERATION_ADD, \ |
| | | SDL_BLENDFACTOR_ZERO, SDL_BLENDFACTOR_ONE, SDL_BLENDOPERATION_ADD) |
| | | |
| | | #if !SDL_RENDER_DISABLED |
| | | static const SDL_RenderDriver *render_drivers[] = { |
| | |
| | | #endif |
| | | #if SDL_VIDEO_RENDER_DIRECTFB |
| | | &DirectFB_RenderDriver, |
| | | #endif |
| | | #if SDL_VIDEO_RENDER_METAL |
| | | &METAL_RenderDriver, |
| | | #endif |
| | | #if SDL_VIDEO_RENDER_PSP |
| | | &PSP_RenderDriver, |
| | |
| | | #endif |
| | | } |
| | | |
| | | static int |
| | | static int SDLCALL |
| | | SDL_RendererEventWatch(void *userdata, SDL_Event *event) |
| | | { |
| | | SDL_Renderer *renderer = (SDL_Renderer *)userdata; |
| | |
| | | } else if (event->type == SDL_MOUSEMOTION) { |
| | | SDL_Window *window = SDL_GetWindowFromID(event->motion.windowID); |
| | | if (renderer->logical_w && window == renderer->window) { |
| | | event->motion.x -= renderer->viewport.x; |
| | | event->motion.y -= renderer->viewport.y; |
| | | event->motion.x = (int)(event->motion.x / renderer->scale.x); |
| | | event->motion.y = (int)(event->motion.y / renderer->scale.y); |
| | | event->motion.x -= (int)(renderer->viewport.x * renderer->dpi_scale.x); |
| | | event->motion.y -= (int)(renderer->viewport.y * renderer->dpi_scale.y); |
| | | event->motion.x = (int)(event->motion.x / (renderer->scale.x * renderer->dpi_scale.x)); |
| | | event->motion.y = (int)(event->motion.y / (renderer->scale.y * renderer->dpi_scale.y)); |
| | | if (event->motion.xrel > 0) { |
| | | event->motion.xrel = SDL_max(1, (int)(event->motion.xrel / renderer->scale.x)); |
| | | event->motion.xrel = SDL_max(1, (int)(event->motion.xrel / (renderer->scale.x * renderer->dpi_scale.x))); |
| | | } else if (event->motion.xrel < 0) { |
| | | event->motion.xrel = SDL_min(-1, (int)(event->motion.xrel / renderer->scale.x)); |
| | | event->motion.xrel = SDL_min(-1, (int)(event->motion.xrel / (renderer->scale.x * renderer->dpi_scale.x))); |
| | | } |
| | | if (event->motion.yrel > 0) { |
| | | event->motion.yrel = SDL_max(1, (int)(event->motion.yrel / renderer->scale.y)); |
| | | event->motion.yrel = SDL_max(1, (int)(event->motion.yrel / (renderer->scale.y * renderer->dpi_scale.y))); |
| | | } else if (event->motion.yrel < 0) { |
| | | event->motion.yrel = SDL_min(-1, (int)(event->motion.yrel / renderer->scale.y)); |
| | | event->motion.yrel = SDL_min(-1, (int)(event->motion.yrel / (renderer->scale.y * renderer->dpi_scale.y))); |
| | | } |
| | | } |
| | | } else if (event->type == SDL_MOUSEBUTTONDOWN || |
| | | event->type == SDL_MOUSEBUTTONUP) { |
| | | SDL_Window *window = SDL_GetWindowFromID(event->button.windowID); |
| | | if (renderer->logical_w && window == renderer->window) { |
| | | event->button.x -= renderer->viewport.x; |
| | | event->button.y -= renderer->viewport.y; |
| | | event->button.x = (int)(event->button.x / renderer->scale.x); |
| | | event->button.y = (int)(event->button.y / renderer->scale.y); |
| | | event->button.x -= (int)(renderer->viewport.x * renderer->dpi_scale.x); |
| | | event->button.y -= (int)(renderer->viewport.y * renderer->dpi_scale.y); |
| | | event->button.x = (int)(event->button.x / (renderer->scale.x * renderer->dpi_scale.x)); |
| | | event->button.y = (int)(event->button.y / (renderer->scale.y * renderer->dpi_scale.y)); |
| | | } |
| | | } else if (event->type == SDL_FINGERDOWN || |
| | | event->type == SDL_FINGERUP || |
| | | event->type == SDL_FINGERMOTION) { |
| | | if (renderer->logical_w) { |
| | | int w = 1; |
| | | int h = 1; |
| | | SDL_GetRendererOutputSize(renderer, &w, &h); |
| | | |
| | | event->tfinger.x *= (w - 1); |
| | | event->tfinger.y *= (h - 1); |
| | | |
| | | event->tfinger.x -= (renderer->viewport.x * renderer->dpi_scale.x); |
| | | event->tfinger.y -= (renderer->viewport.y * renderer->dpi_scale.y); |
| | | event->tfinger.x = (event->tfinger.x / (renderer->scale.x * renderer->dpi_scale.x)); |
| | | event->tfinger.y = (event->tfinger.y / (renderer->scale.y * renderer->dpi_scale.y)); |
| | | |
| | | if (renderer->logical_w > 1) { |
| | | event->tfinger.x = event->tfinger.x / (renderer->logical_w - 1); |
| | | } else { |
| | | event->tfinger.x = 0.5f; |
| | | } |
| | | if (renderer->logical_h > 1) { |
| | | event->tfinger.y = event->tfinger.y / (renderer->logical_h - 1); |
| | | } else { |
| | | event->tfinger.y = 0.5f; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return 0; |
| | | } |
| | | |
| | |
| | | renderer->window = window; |
| | | renderer->scale.x = 1.0f; |
| | | renderer->scale.y = 1.0f; |
| | | renderer->dpi_scale.x = 1.0f; |
| | | renderer->dpi_scale.y = 1.0f; |
| | | |
| | | if (window && renderer->GetOutputSize) { |
| | | int window_w, window_h; |
| | | int output_w, output_h; |
| | | if (renderer->GetOutputSize(renderer, &output_w, &output_h) == 0) { |
| | | SDL_GetWindowSize(renderer->window, &window_w, &window_h); |
| | | renderer->dpi_scale.x = (float)window_w / output_w; |
| | | renderer->dpi_scale.y = (float)window_h / output_h; |
| | | } |
| | | } |
| | | |
| | | if (SDL_GetWindowFlags(window) & (SDL_WINDOW_HIDDEN|SDL_WINDOW_MINIMIZED)) { |
| | | renderer->hidden = SDL_TRUE; |
| | |
| | | } else { |
| | | SDL_assert(0 && "This should never happen"); |
| | | return SDL_SetError("Renderer doesn't support querying output size"); |
| | | } |
| | | } |
| | | |
| | | static SDL_bool |
| | | IsSupportedBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode) |
| | | { |
| | | switch (blendMode) |
| | | { |
| | | /* These are required to be supported by all renderers */ |
| | | case SDL_BLENDMODE_NONE: |
| | | case SDL_BLENDMODE_BLEND: |
| | | case SDL_BLENDMODE_ADD: |
| | | case SDL_BLENDMODE_MOD: |
| | | return SDL_TRUE; |
| | | |
| | | default: |
| | | return renderer->SupportsBlendMode && renderer->SupportsBlendMode(renderer, blendMode); |
| | | } |
| | | } |
| | | |
| | |
| | | CHECK_TEXTURE_MAGIC(texture, -1); |
| | | |
| | | renderer = texture->renderer; |
| | | if (!IsSupportedBlendMode(renderer, blendMode)) { |
| | | return SDL_Unsupported(); |
| | | } |
| | | texture->blendMode = blendMode; |
| | | if (texture->native) { |
| | | return SDL_SetTextureBlendMode(texture->native, blendMode); |
| | |
| | | |
| | | if (texture->access == SDL_TEXTUREACCESS_STREAMING) { |
| | | /* We can lock the texture and copy to it */ |
| | | void *native_pixels; |
| | | int native_pitch; |
| | | void *native_pixels = NULL; |
| | | int native_pitch = 0; |
| | | |
| | | if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { |
| | | return -1; |
| | |
| | | SDL_UnlockTexture(native); |
| | | } else { |
| | | /* Use a temporary buffer for updating */ |
| | | void *temp_pixels; |
| | | int temp_pitch; |
| | | |
| | | temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); |
| | | temp_pixels = SDL_malloc(rect->h * temp_pitch); |
| | | if (!temp_pixels) { |
| | | return SDL_OutOfMemory(); |
| | | const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); |
| | | const size_t alloclen = rect->h * temp_pitch; |
| | | if (alloclen > 0) { |
| | | void *temp_pixels = SDL_malloc(alloclen); |
| | | if (!temp_pixels) { |
| | | return SDL_OutOfMemory(); |
| | | } |
| | | SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, |
| | | rect->w, rect->h, temp_pixels, temp_pitch); |
| | | SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); |
| | | SDL_free(temp_pixels); |
| | | } |
| | | SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, |
| | | rect->w, rect->h, temp_pixels, temp_pitch); |
| | | SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); |
| | | SDL_free(temp_pixels); |
| | | } |
| | | return 0; |
| | | } |
| | |
| | | { |
| | | SDL_Texture *native = texture->native; |
| | | |
| | | if (!rect->w || !rect->h) { |
| | | return 0; /* nothing to do. */ |
| | | } |
| | | |
| | | if (texture->access == SDL_TEXTUREACCESS_STREAMING) { |
| | | /* We can lock the texture and copy to it */ |
| | | void *native_pixels; |
| | | int native_pitch; |
| | | void *native_pixels = NULL; |
| | | int native_pitch = 0; |
| | | |
| | | if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { |
| | | return -1; |
| | |
| | | SDL_UnlockTexture(native); |
| | | } else { |
| | | /* Use a temporary buffer for updating */ |
| | | void *temp_pixels; |
| | | int temp_pitch; |
| | | |
| | | temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); |
| | | temp_pixels = SDL_malloc(rect->h * temp_pitch); |
| | | if (!temp_pixels) { |
| | | return SDL_OutOfMemory(); |
| | | const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); |
| | | const size_t alloclen = rect->h * temp_pitch; |
| | | if (alloclen > 0) { |
| | | void *temp_pixels = SDL_malloc(alloclen); |
| | | if (!temp_pixels) { |
| | | return SDL_OutOfMemory(); |
| | | } |
| | | SDL_ConvertPixels(rect->w, rect->h, |
| | | texture->format, pixels, pitch, |
| | | native->format, temp_pixels, temp_pitch); |
| | | SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); |
| | | SDL_free(temp_pixels); |
| | | } |
| | | SDL_ConvertPixels(rect->w, rect->h, |
| | | texture->format, pixels, pitch, |
| | | native->format, temp_pixels, temp_pitch); |
| | | SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); |
| | | SDL_free(temp_pixels); |
| | | } |
| | | return 0; |
| | | } |
| | |
| | | full_rect.h = texture->h; |
| | | rect = &full_rect; |
| | | |
| | | if (!rect->w || !rect->h) { |
| | | return 0; /* nothing to do. */ |
| | | } |
| | | |
| | | if (texture->access == SDL_TEXTUREACCESS_STREAMING) { |
| | | /* We can lock the texture and copy to it */ |
| | | void *native_pixels; |
| | | int native_pitch; |
| | | void *native_pixels = NULL; |
| | | int native_pitch = 0; |
| | | |
| | | if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { |
| | | return -1; |
| | |
| | | SDL_UnlockTexture(native); |
| | | } else { |
| | | /* Use a temporary buffer for updating */ |
| | | void *temp_pixels; |
| | | int temp_pitch; |
| | | |
| | | temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); |
| | | temp_pixels = SDL_malloc(rect->h * temp_pitch); |
| | | if (!temp_pixels) { |
| | | return SDL_OutOfMemory(); |
| | | const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); |
| | | const size_t alloclen = rect->h * temp_pitch; |
| | | if (alloclen > 0) { |
| | | void *temp_pixels = SDL_malloc(alloclen); |
| | | if (!temp_pixels) { |
| | | return SDL_OutOfMemory(); |
| | | } |
| | | SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, |
| | | rect->w, rect->h, temp_pixels, temp_pitch); |
| | | SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); |
| | | SDL_free(temp_pixels); |
| | | } |
| | | SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, |
| | | rect->w, rect->h, temp_pixels, temp_pitch); |
| | | SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); |
| | | SDL_free(temp_pixels); |
| | | } |
| | | return 0; |
| | | } |
| | |
| | | full_rect.w = texture->w; |
| | | full_rect.h = texture->h; |
| | | rect = &full_rect; |
| | | } |
| | | |
| | | if (!rect->w || !rect->h) { |
| | | return 0; /* nothing to do. */ |
| | | } |
| | | |
| | | if (texture->yuv) { |
| | |
| | | float real_aspect; |
| | | float scale; |
| | | SDL_Rect viewport; |
| | | /* 0 is for letterbox, 1 is for overscan */ |
| | | int scale_policy = 0; |
| | | const char *hint; |
| | | |
| | | if (!renderer->logical_w || !renderer->logical_h) { |
| | | return 0; |
| | | } |
| | | if (SDL_GetRendererOutputSize(renderer, &w, &h) < 0) { |
| | | return -1; |
| | | } |
| | | |
| | | hint = SDL_GetHint(SDL_HINT_RENDER_LOGICAL_SIZE_MODE); |
| | | if (hint && (*hint == '1' || SDL_strcasecmp(hint, "overscan") == 0)) { |
| | | SDL_bool overscan_supported = SDL_TRUE; |
| | | /* Unfortunately, Direct3D 9 doesn't support negative viewport numbers |
| | | which the overscan implementation relies on. |
| | | */ |
| | | if (SDL_strcasecmp(SDL_GetCurrentVideoDriver(), "direct3d") == 0) { |
| | | overscan_supported = SDL_FALSE; |
| | | } |
| | | if (overscan_supported) { |
| | | scale_policy = 1; |
| | | } |
| | | } |
| | | |
| | | want_aspect = (float)renderer->logical_w / renderer->logical_h; |
| | |
| | | scale = (float)w / renderer->logical_w; |
| | | SDL_RenderSetViewport(renderer, NULL); |
| | | } else if (want_aspect > real_aspect) { |
| | | /* We want a wider aspect ratio than is available - letterbox it */ |
| | | scale = (float)w / renderer->logical_w; |
| | | viewport.x = 0; |
| | | viewport.w = w; |
| | | viewport.h = (int)SDL_ceil(renderer->logical_h * scale); |
| | | viewport.y = (h - viewport.h) / 2; |
| | | SDL_RenderSetViewport(renderer, &viewport); |
| | | if (scale_policy == 1) { |
| | | /* We want a wider aspect ratio than is available - |
| | | zoom so logical height matches the real height |
| | | and the width will grow off the screen |
| | | */ |
| | | scale = (float)h / renderer->logical_h; |
| | | viewport.y = 0; |
| | | viewport.h = h; |
| | | viewport.w = (int)SDL_ceil(renderer->logical_w * scale); |
| | | viewport.x = (w - viewport.w) / 2; |
| | | SDL_RenderSetViewport(renderer, &viewport); |
| | | } else { |
| | | /* We want a wider aspect ratio than is available - letterbox it */ |
| | | scale = (float)w / renderer->logical_w; |
| | | viewport.x = 0; |
| | | viewport.w = w; |
| | | viewport.h = (int)SDL_ceil(renderer->logical_h * scale); |
| | | viewport.y = (h - viewport.h) / 2; |
| | | SDL_RenderSetViewport(renderer, &viewport); |
| | | } |
| | | } else { |
| | | /* We want a narrower aspect ratio than is available - use side-bars */ |
| | | scale = (float)h / renderer->logical_h; |
| | | viewport.y = 0; |
| | | viewport.h = h; |
| | | viewport.w = (int)SDL_ceil(renderer->logical_w * scale); |
| | | viewport.x = (w - viewport.w) / 2; |
| | | SDL_RenderSetViewport(renderer, &viewport); |
| | | if (scale_policy == 1) { |
| | | /* We want a narrower aspect ratio than is available - |
| | | zoom so logical width matches the real width |
| | | and the height will grow off the screen |
| | | */ |
| | | scale = (float)w / renderer->logical_w; |
| | | viewport.x = 0; |
| | | viewport.w = w; |
| | | viewport.h = (int)SDL_ceil(renderer->logical_h * scale); |
| | | viewport.y = (h - viewport.h) / 2; |
| | | SDL_RenderSetViewport(renderer, &viewport); |
| | | } else { |
| | | /* We want a narrower aspect ratio than is available - use side-bars */ |
| | | scale = (float)h / renderer->logical_h; |
| | | viewport.y = 0; |
| | | viewport.h = h; |
| | | viewport.w = (int)SDL_ceil(renderer->logical_w * scale); |
| | | viewport.x = (w - viewport.w) / 2; |
| | | SDL_RenderSetViewport(renderer, &viewport); |
| | | } |
| | | } |
| | | |
| | | /* Set the new scale */ |
| | |
| | | { |
| | | CHECK_RENDERER_MAGIC(renderer, -1); |
| | | |
| | | if (!IsSupportedBlendMode(renderer, blendMode)) { |
| | | return SDL_Unsupported(); |
| | | } |
| | | renderer->blendMode = blendMode; |
| | | return 0; |
| | | } |
| | |
| | | |
| | | /* Free existing textures for this renderer */ |
| | | while (renderer->textures) { |
| | | SDL_Texture *tex = renderer->textures; (void) tex; |
| | | SDL_DestroyTexture(renderer->textures); |
| | | SDL_assert(tex != renderer->textures); /* satisfy static analysis. */ |
| | | } |
| | | |
| | | if (renderer->window) { |
| | |
| | | return SDL_Unsupported(); |
| | | } |
| | | |
| | | void * |
| | | SDL_RenderGetMetalLayer(SDL_Renderer * renderer) |
| | | { |
| | | CHECK_RENDERER_MAGIC(renderer, NULL); |
| | | |
| | | if (renderer->GetMetalLayer) { |
| | | return renderer->GetMetalLayer(renderer); |
| | | } |
| | | return NULL; |
| | | } |
| | | |
| | | void * |
| | | SDL_RenderGetMetalCommandEncoder(SDL_Renderer * renderer) |
| | | { |
| | | CHECK_RENDERER_MAGIC(renderer, NULL); |
| | | |
| | | if (renderer->GetMetalCommandEncoder) { |
| | | return renderer->GetMetalCommandEncoder(renderer); |
| | | } |
| | | return NULL; |
| | | } |
| | | |
| | | static SDL_BlendMode |
| | | SDL_GetShortBlendMode(SDL_BlendMode blendMode) |
| | | { |
| | | if (blendMode == SDL_BLENDMODE_NONE_FULL) { |
| | | return SDL_BLENDMODE_NONE; |
| | | } |
| | | if (blendMode == SDL_BLENDMODE_BLEND_FULL) { |
| | | return SDL_BLENDMODE_BLEND; |
| | | } |
| | | if (blendMode == SDL_BLENDMODE_ADD_FULL) { |
| | | return SDL_BLENDMODE_ADD; |
| | | } |
| | | if (blendMode == SDL_BLENDMODE_MOD_FULL) { |
| | | return SDL_BLENDMODE_MOD; |
| | | } |
| | | return blendMode; |
| | | } |
| | | |
| | | static SDL_BlendMode |
| | | SDL_GetLongBlendMode(SDL_BlendMode blendMode) |
| | | { |
| | | if (blendMode == SDL_BLENDMODE_NONE) { |
| | | return SDL_BLENDMODE_NONE_FULL; |
| | | } |
| | | if (blendMode == SDL_BLENDMODE_BLEND) { |
| | | return SDL_BLENDMODE_BLEND_FULL; |
| | | } |
| | | if (blendMode == SDL_BLENDMODE_ADD) { |
| | | return SDL_BLENDMODE_ADD_FULL; |
| | | } |
| | | if (blendMode == SDL_BLENDMODE_MOD) { |
| | | return SDL_BLENDMODE_MOD_FULL; |
| | | } |
| | | return blendMode; |
| | | } |
| | | |
| | | SDL_BlendMode |
| | | SDL_ComposeCustomBlendMode(SDL_BlendFactor srcColorFactor, SDL_BlendFactor dstColorFactor, |
| | | SDL_BlendOperation colorOperation, |
| | | SDL_BlendFactor srcAlphaFactor, SDL_BlendFactor dstAlphaFactor, |
| | | SDL_BlendOperation alphaOperation) |
| | | { |
| | | SDL_BlendMode blendMode = SDL_COMPOSE_BLENDMODE(srcColorFactor, dstColorFactor, colorOperation, |
| | | srcAlphaFactor, dstAlphaFactor, alphaOperation); |
| | | return SDL_GetShortBlendMode(blendMode); |
| | | } |
| | | |
| | | SDL_BlendFactor |
| | | SDL_GetBlendModeSrcColorFactor(SDL_BlendMode blendMode) |
| | | { |
| | | blendMode = SDL_GetLongBlendMode(blendMode); |
| | | return (SDL_BlendFactor)(((Uint32)blendMode >> 4) & 0xF); |
| | | } |
| | | |
| | | SDL_BlendFactor |
| | | SDL_GetBlendModeDstColorFactor(SDL_BlendMode blendMode) |
| | | { |
| | | blendMode = SDL_GetLongBlendMode(blendMode); |
| | | return (SDL_BlendFactor)(((Uint32)blendMode >> 8) & 0xF); |
| | | } |
| | | |
| | | SDL_BlendOperation |
| | | SDL_GetBlendModeColorOperation(SDL_BlendMode blendMode) |
| | | { |
| | | blendMode = SDL_GetLongBlendMode(blendMode); |
| | | return (SDL_BlendOperation)(((Uint32)blendMode >> 0) & 0xF); |
| | | } |
| | | |
| | | SDL_BlendFactor |
| | | SDL_GetBlendModeSrcAlphaFactor(SDL_BlendMode blendMode) |
| | | { |
| | | blendMode = SDL_GetLongBlendMode(blendMode); |
| | | return (SDL_BlendFactor)(((Uint32)blendMode >> 20) & 0xF); |
| | | } |
| | | |
| | | SDL_BlendFactor |
| | | SDL_GetBlendModeDstAlphaFactor(SDL_BlendMode blendMode) |
| | | { |
| | | blendMode = SDL_GetLongBlendMode(blendMode); |
| | | return (SDL_BlendFactor)(((Uint32)blendMode >> 24) & 0xF); |
| | | } |
| | | |
| | | SDL_BlendOperation |
| | | SDL_GetBlendModeAlphaOperation(SDL_BlendMode blendMode) |
| | | { |
| | | blendMode = SDL_GetLongBlendMode(blendMode); |
| | | return (SDL_BlendOperation)(((Uint32)blendMode >> 16) & 0xF); |
| | | } |
| | | |
| | | /* vi: set ts=4 sw=4 expandtab: */ |