mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-11 08:18:59 +08:00
render: Remove the logical presentation render target.
Now we render directly to the window, scaling as appropriate. This fixes some concerns the render target introduced, like the quality of the final scaled output, how to step outside of the logical size temporarily to draw some things sharply at the native resolution, and loss of sub-pixel precision. Fixes #8736.
This commit is contained in:
@@ -499,7 +499,7 @@ SDL_DYNAPI_PROC(bool,SDL_GetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode
|
||||
SDL_DYNAPI_PROC(bool,SDL_GetRenderDrawColor,(SDL_Renderer *a, Uint8 *b, Uint8 *c, Uint8 *d, Uint8 *e),(a,b,c,d,e),return)
|
||||
SDL_DYNAPI_PROC(bool,SDL_GetRenderDrawColorFloat,(SDL_Renderer *a, float *b, float *c, float *d, float *e),(a,b,c,d,e),return)
|
||||
SDL_DYNAPI_PROC(const char*,SDL_GetRenderDriver,(int a),(a),return)
|
||||
SDL_DYNAPI_PROC(bool,SDL_GetRenderLogicalPresentation,(SDL_Renderer *a, int *b, int *c, SDL_RendererLogicalPresentation *d, SDL_ScaleMode *e),(a,b,c,d,e),return)
|
||||
SDL_DYNAPI_PROC(bool,SDL_GetRenderLogicalPresentation,(SDL_Renderer *a, int *b, int *c, SDL_RendererLogicalPresentation *d),(a,b,c,d),return)
|
||||
SDL_DYNAPI_PROC(bool,SDL_GetRenderLogicalPresentationRect,(SDL_Renderer *a, SDL_FRect *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(void*,SDL_GetRenderMetalCommandEncoder,(SDL_Renderer *a),(a),return)
|
||||
SDL_DYNAPI_PROC(void*,SDL_GetRenderMetalLayer,(SDL_Renderer *a),(a),return)
|
||||
@@ -879,7 +879,7 @@ SDL_DYNAPI_PROC(bool,SDL_SetRenderColorScale,(SDL_Renderer *a, float b),(a,b),re
|
||||
SDL_DYNAPI_PROC(bool,SDL_SetRenderDrawBlendMode,(SDL_Renderer *a, SDL_BlendMode b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(bool,SDL_SetRenderDrawColor,(SDL_Renderer *a, Uint8 b, Uint8 c, Uint8 d, Uint8 e),(a,b,c,d,e),return)
|
||||
SDL_DYNAPI_PROC(bool,SDL_SetRenderDrawColorFloat,(SDL_Renderer *a, float b, float c, float d, float e),(a,b,c,d,e),return)
|
||||
SDL_DYNAPI_PROC(bool,SDL_SetRenderLogicalPresentation,(SDL_Renderer *a, int b, int c, SDL_RendererLogicalPresentation d, SDL_ScaleMode e),(a,b,c,d,e),return)
|
||||
SDL_DYNAPI_PROC(bool,SDL_SetRenderLogicalPresentation,(SDL_Renderer *a, int b, int c, SDL_RendererLogicalPresentation d),(a,b,c,d),return)
|
||||
SDL_DYNAPI_PROC(bool,SDL_SetRenderScale,(SDL_Renderer *a, float b, float c),(a,b,c),return)
|
||||
SDL_DYNAPI_PROC(bool,SDL_SetRenderTarget,(SDL_Renderer *a, SDL_Texture *b),(a,b),return)
|
||||
SDL_DYNAPI_PROC(bool,SDL_SetRenderVSync,(SDL_Renderer *a, int b),(a,b),return)
|
||||
|
||||
+194
-267
File diff suppressed because it is too large
Load Diff
@@ -63,7 +63,9 @@ typedef struct SDL_RenderViewState
|
||||
SDL_Rect pixel_clip_rect;
|
||||
bool clipping_enabled;
|
||||
SDL_FPoint scale;
|
||||
|
||||
SDL_FPoint logical_scale;
|
||||
SDL_FPoint logical_offset;
|
||||
SDL_FPoint current_scale; // this is just `scale * logical_scale`, precalculated, since we use it a lot.
|
||||
} SDL_RenderViewState;
|
||||
|
||||
// Define the SDL texture structure
|
||||
@@ -240,9 +242,8 @@ struct SDL_Renderer
|
||||
Uint64 last_present;
|
||||
|
||||
// Support for logical output coordinates
|
||||
SDL_Texture *logical_target;
|
||||
SDL_RendererLogicalPresentation logical_presentation_mode;
|
||||
SDL_ScaleMode logical_scale_mode;
|
||||
int logical_w, logical_h;
|
||||
SDL_FRect logical_src_rect;
|
||||
SDL_FRect logical_dst_rect;
|
||||
|
||||
|
||||
@@ -1465,7 +1465,6 @@ static SDL_Surface *GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *
|
||||
SDL_PixelFormat format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ARGB8888;
|
||||
GLint internalFormat;
|
||||
GLenum targetFormat, type;
|
||||
int w, h;
|
||||
SDL_Surface *surface;
|
||||
|
||||
GL_ActivateRenderer(renderer);
|
||||
@@ -1480,13 +1479,16 @@ static SDL_Surface *GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_GetCurrentRenderOutputSize(renderer, &w, &h);
|
||||
int y = rect->y;
|
||||
if (!renderer->target) {
|
||||
int w, h;
|
||||
SDL_GetRenderOutputSize(renderer, &w, &h);
|
||||
y = (h - y) - rect->h;
|
||||
}
|
||||
|
||||
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
data->glPixelStorei(GL_PACK_ROW_LENGTH, (surface->pitch / SDL_BYTESPERPIXEL(format)));
|
||||
|
||||
data->glReadPixels(rect->x, renderer->target ? rect->y : (h - rect->y) - rect->h,
|
||||
rect->w, rect->h, targetFormat, type, surface->pixels);
|
||||
data->glReadPixels(rect->x, y, rect->w, rect->h, targetFormat, type, surface->pixels);
|
||||
|
||||
if (!GL_CheckError("glReadPixels()", renderer)) {
|
||||
SDL_DestroySurface(surface);
|
||||
|
||||
@@ -1993,7 +1993,6 @@ static SDL_Surface *GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rec
|
||||
{
|
||||
GLES2_RenderData *data = (GLES2_RenderData *)renderer->internal;
|
||||
SDL_PixelFormat format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_RGBA32;
|
||||
int w, h;
|
||||
SDL_Surface *surface;
|
||||
|
||||
surface = SDL_CreateSurface(rect->w, rect->h, format);
|
||||
@@ -2001,10 +2000,14 @@ static SDL_Surface *GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rec
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_GetCurrentRenderOutputSize(renderer, &w, &h);
|
||||
int y = rect->y;
|
||||
if (!renderer->target) {
|
||||
int w, h;
|
||||
SDL_GetRenderOutputSize(renderer, &w, &h);
|
||||
y = (h - y) - rect->h;
|
||||
}
|
||||
|
||||
data->glReadPixels(rect->x, renderer->target ? rect->y : (h - rect->y) - rect->h,
|
||||
rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
|
||||
data->glReadPixels(rect->x, y, rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels);
|
||||
if (!GL_CheckError("glReadPixels()", renderer)) {
|
||||
SDL_DestroySurface(surface);
|
||||
return NULL;
|
||||
|
||||
@@ -1080,7 +1080,6 @@ void read_pixels(int x, int y, size_t width, size_t height, void *data)
|
||||
static SDL_Surface *VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect)
|
||||
{
|
||||
Uint32 format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888;
|
||||
int w, h;
|
||||
SDL_Surface *surface;
|
||||
|
||||
// TODO: read from texture rendertarget.
|
||||
@@ -1094,10 +1093,14 @@ static SDL_Surface *VITA_GXM_RenderReadPixels(SDL_Renderer *renderer, const SDL_
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_GetCurrentRenderOutputSize(renderer, &w, &h);
|
||||
int y = rect->y;
|
||||
if (!renderer->target) {
|
||||
int w, h;
|
||||
SDL_GetRenderOutputSize(renderer, &w, &h);
|
||||
y = (h - y) - rect->h;
|
||||
}
|
||||
|
||||
read_pixels(rect->x, renderer->target ? rect->y : (h - rect->y) - rect->h,
|
||||
rect->w, rect->h, surface->pixels);
|
||||
read_pixels(rect->x, y, rect->w, rect->h, surface->pixels);
|
||||
|
||||
// Flip the rows to be top-down if necessary
|
||||
|
||||
|
||||
@@ -482,21 +482,6 @@ static int SDLCALL SDLTest_CommonStateParseVideoArguments(void *data, char **arg
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "--logical-scale-quality") == 0) {
|
||||
++index;
|
||||
if (!argv[index]) {
|
||||
return -1;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "nearest") == 0) {
|
||||
state->logical_scale_mode = SDL_SCALEMODE_NEAREST;
|
||||
return 2;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "linear") == 0) {
|
||||
state->logical_scale_mode = SDL_SCALEMODE_LINEAR;
|
||||
return 2;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (SDL_strcasecmp(argv[index], "--scale") == 0) {
|
||||
++index;
|
||||
if (!argv[index]) {
|
||||
@@ -708,7 +693,6 @@ SDLTest_CommonState *SDLTest_CommonCreateState(char **argv, SDL_InitFlags flags)
|
||||
state->window_w = DEFAULT_WINDOW_WIDTH;
|
||||
state->window_h = DEFAULT_WINDOW_HEIGHT;
|
||||
state->logical_presentation = SDL_LOGICAL_PRESENTATION_DISABLED;
|
||||
state->logical_scale_mode = SDL_SCALEMODE_LINEAR;
|
||||
state->num_windows = 1;
|
||||
state->audio_freq = 22050;
|
||||
state->audio_format = SDL_AUDIO_S16;
|
||||
@@ -1082,21 +1066,6 @@ static void SDLTest_PrintLogicalPresentation(char *text, size_t maxlen, SDL_Rend
|
||||
}
|
||||
}
|
||||
|
||||
static void SDLTest_PrintScaleMode(char *text, size_t maxlen, SDL_ScaleMode scale_mode)
|
||||
{
|
||||
switch (scale_mode) {
|
||||
case SDL_SCALEMODE_NEAREST:
|
||||
SDL_snprintfcat(text, maxlen, "NEAREST");
|
||||
break;
|
||||
case SDL_SCALEMODE_LINEAR:
|
||||
SDL_snprintfcat(text, maxlen, "LINEAR");
|
||||
break;
|
||||
default:
|
||||
SDL_snprintfcat(text, maxlen, "0x%8.8x", scale_mode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void SDLTest_PrintRenderer(SDL_Renderer *renderer)
|
||||
{
|
||||
const char *name;
|
||||
@@ -1480,7 +1449,7 @@ bool SDLTest_CommonInit(SDLTest_CommonState *state)
|
||||
if (state->render_vsync) {
|
||||
SDL_SetRenderVSync(state->renderers[i], state->render_vsync);
|
||||
}
|
||||
if (!SDL_SetRenderLogicalPresentation(state->renderers[i], state->logical_w, state->logical_h, state->logical_presentation, state->logical_scale_mode)) {
|
||||
if (!SDL_SetRenderLogicalPresentation(state->renderers[i], state->logical_w, state->logical_h, state->logical_presentation)) {
|
||||
SDL_Log("Couldn't set logical presentation: %s\n", SDL_GetError());
|
||||
return false;
|
||||
}
|
||||
@@ -2587,7 +2556,6 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl
|
||||
SDL_DisplayID windowDisplayID = SDL_GetDisplayForWindow(window);
|
||||
const char *name;
|
||||
SDL_RendererLogicalPresentation logical_presentation;
|
||||
SDL_ScaleMode logical_scale_mode;
|
||||
|
||||
/* Video */
|
||||
|
||||
@@ -2638,12 +2606,9 @@ void SDLTest_CommonDrawWindowInfo(SDL_Renderer *renderer, SDL_Window *window, fl
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
SDL_GetRenderLogicalPresentation(renderer, &w, &h, &logical_presentation, &logical_scale_mode);
|
||||
SDL_GetRenderLogicalPresentation(renderer, &w, &h, &logical_presentation);
|
||||
(void)SDL_snprintf(text, sizeof(text), "SDL_GetRenderLogicalPresentation: %dx%d ", w, h);
|
||||
SDLTest_PrintLogicalPresentation(text, sizeof(text), logical_presentation);
|
||||
SDL_snprintfcat(text, sizeof(text), ", ");
|
||||
SDLTest_PrintScaleMode(text, sizeof(text), logical_scale_mode);
|
||||
SDLTest_DrawString(renderer, 0.0f, textY, text);
|
||||
textY += lineHeight;
|
||||
|
||||
/* Window */
|
||||
|
||||
Reference in New Issue
Block a user