mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-05-10 15:21:00 +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:
@@ -1761,10 +1761,10 @@ expression e2;
|
||||
@@
|
||||
(
|
||||
- SDL_RenderSetLogicalSize(renderer, 0, 0)
|
||||
+ SDL_SetRenderLogicalPresentation(renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_ScaleModeNearest)
|
||||
+ SDL_SetRenderLogicalPresentation(renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED)
|
||||
|
|
||||
- SDL_RenderSetLogicalSize(renderer, e1, e2)
|
||||
+ SDL_SetRenderLogicalPresentation(renderer, e1, e2, SDL_LOGICAL_PRESENTATION_LETTERBOX, SDL_ScaleModeLinear)
|
||||
+ SDL_SetRenderLogicalPresentation(renderer, e1, e2, SDL_LOGICAL_PRESENTATION_LETTERBOX)
|
||||
)
|
||||
@@
|
||||
@@
|
||||
|
||||
@@ -55,7 +55,7 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
SDL_FRect rect;
|
||||
|
||||
/* as you can see from this, rendering draws over whatever was drawn before it. */
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); /* black, full alpha */
|
||||
SDL_SetRenderDrawColor(renderer, 33, 33, 33, 255); /* dark gray, full alpha */
|
||||
SDL_RenderClear(renderer); /* start with a blank canvas. */
|
||||
|
||||
/* draw a filled rectangle in the middle of the canvas. */
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
static SDL_Window *window = NULL;
|
||||
static SDL_Renderer *renderer = NULL;
|
||||
static SDL_Texture *texture = NULL;
|
||||
static SDL_Texture *converted_texture = NULL;
|
||||
static int texture_width = 0;
|
||||
static int texture_height = 0;
|
||||
static SDL_Texture *converted_texture = NULL;
|
||||
static int converted_texture_width = 0;
|
||||
static int converted_texture_height = 0;
|
||||
|
||||
#define WINDOW_WIDTH 640
|
||||
#define WINDOW_HEIGHT 480
|
||||
@@ -68,12 +70,6 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
|
||||
SDL_DestroySurface(surface); /* done with this, the texture has a copy of the pixels now. */
|
||||
|
||||
converted_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
if (!texture) {
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't create conversion texture!", SDL_GetError(), NULL);
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
|
||||
return SDL_APP_CONTINUE; /* carry on with the program! */
|
||||
}
|
||||
|
||||
@@ -111,8 +107,13 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
center.y = texture_height / 2.0f;
|
||||
SDL_RenderTextureRotated(renderer, texture, NULL, &dst_rect, rotation, ¢er, SDL_FLIP_NONE);
|
||||
|
||||
/* this whole thing is _super_ expensive. Seriously, don't do this in real life. */
|
||||
/* this next whole thing is _super_ expensive. Seriously, don't do this in real life. */
|
||||
|
||||
/* Download the pixels of what has just been rendered. This has to wait for the GPU to finish rendering it and everything before it,
|
||||
and then make an expensive copy from the GPU to system RAM! */
|
||||
surface = SDL_RenderReadPixels(renderer, NULL);
|
||||
|
||||
/* This is also expensive, but easier: convert the pixels to a format we want. */
|
||||
if (surface && (surface->format != SDL_PIXELFORMAT_RGBA8888) && (surface->format != SDL_PIXELFORMAT_BGRA8888)) {
|
||||
SDL_Surface *converted = SDL_ConvertSurface(surface, SDL_PIXELFORMAT_RGBA8888);
|
||||
SDL_DestroySurface(surface);
|
||||
@@ -120,6 +121,18 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
}
|
||||
|
||||
if (surface) {
|
||||
/* Rebuild converted_texture if the dimensions have changed (window resized, etc). */
|
||||
if ((surface->w != converted_texture_width) || (surface->h != converted_texture_height)) {
|
||||
SDL_DestroyTexture(converted_texture);
|
||||
converted_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, surface->w, surface->h);
|
||||
if (!converted_texture) {
|
||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Couldn't (re)create conversion texture!", SDL_GetError(), NULL);
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
converted_texture_width = surface->w;
|
||||
converted_texture_height = surface->h;
|
||||
}
|
||||
|
||||
/* Turn each pixel into either black or white. This is a lousy technique but it works here.
|
||||
In real life, something like Floyd-Steinberg dithering might work
|
||||
better: https://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering*/
|
||||
@@ -130,9 +143,10 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
Uint8 *p = (Uint8 *) (&pixels[x]);
|
||||
const Uint32 average = (((Uint32) p[1]) + ((Uint32) p[2]) + ((Uint32) p[3])) / 3;
|
||||
if (average == 0) {
|
||||
p[0] = 0; // turn off alpha for pure black pixels.
|
||||
p[0] = p[3] = 0xFF; p[1] = p[2] = 0; /* make pure black pixels red. */
|
||||
} else {
|
||||
p[1] = p[2] = p[3] = (average > 50) ? 0xFF : 0x00; /* make everything else either black or white. */
|
||||
}
|
||||
p[1] = p[2] = p[3] = (average > 50) ? 0xFF : 0x00;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,8 +156,8 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
|
||||
/* draw the texture to the top-left of the screen. */
|
||||
dst_rect.x = dst_rect.y = 0.0f;
|
||||
dst_rect.w = ((float) WINDOW_WIDTH) / 2.0f;
|
||||
dst_rect.h = ((float) WINDOW_WIDTH) / 2.0f;
|
||||
dst_rect.w = ((float) WINDOW_WIDTH) / 4.0f;
|
||||
dst_rect.h = ((float) WINDOW_HEIGHT) / 4.0f;
|
||||
SDL_RenderTexture(renderer, converted_texture, NULL, &dst_rect);
|
||||
}
|
||||
|
||||
|
||||
@@ -1266,13 +1266,23 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_GetRenderTarget(SDL_Renderer *rend
|
||||
/**
|
||||
* Set a device independent resolution and presentation mode for rendering.
|
||||
*
|
||||
* This function sets the width and height of the logical rendering output. A
|
||||
* render target is created at the specified size and used for rendering and
|
||||
* then copied to the output during presentation.
|
||||
* This function sets the width and height of the logical rendering output.
|
||||
* The renderer will act as if the window is always the requested dimensions,
|
||||
* scaling to the actual window resolution as necessary.
|
||||
*
|
||||
* This can be useful for games that expect a fixed size, but would like to
|
||||
* scale the output to whatever is available, regardless of how a user resizes
|
||||
* a window, or if the display is high DPI.
|
||||
*
|
||||
* You can disable logical coordinates by setting the mode to
|
||||
* SDL_LOGICAL_PRESENTATION_DISABLED, and in that case you get the full pixel
|
||||
* resolution of the output window.
|
||||
* resolution of the output window; it is safe to toggle logical presentation
|
||||
* during the rendering of a frame: perhaps most of the rendering is done to
|
||||
* specific dimensions but to make fonts look sharp, the app turns off logical
|
||||
* presentation while drawing text.
|
||||
*
|
||||
* Letterboxing will only happen if logical presentation is enabled during
|
||||
* SDL_RenderPresent; be sure to reenable it first if you were using it.
|
||||
*
|
||||
* You can convert coordinates in an event into rendering coordinates using
|
||||
* SDL_ConvertEventToRenderCoordinates().
|
||||
@@ -1281,7 +1291,6 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_GetRenderTarget(SDL_Renderer *rend
|
||||
* \param w the width of the logical resolution.
|
||||
* \param h the height of the logical resolution.
|
||||
* \param mode the presentation mode used.
|
||||
* \param scale_mode the scale mode used.
|
||||
* \returns true on success or false on failure; call SDL_GetError() for more
|
||||
* information.
|
||||
*
|
||||
@@ -1291,7 +1300,7 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL SDL_GetRenderTarget(SDL_Renderer *rend
|
||||
* \sa SDL_GetRenderLogicalPresentation
|
||||
* \sa SDL_GetRenderLogicalPresentationRect
|
||||
*/
|
||||
extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode, SDL_ScaleMode scale_mode);
|
||||
extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *renderer, int w, int h, SDL_RendererLogicalPresentation mode);
|
||||
|
||||
/**
|
||||
* Get device independent resolution and presentation mode for rendering.
|
||||
@@ -1302,8 +1311,6 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *
|
||||
* \param renderer the rendering context.
|
||||
* \param w an int to be filled with the width.
|
||||
* \param h an int to be filled with the height.
|
||||
* \param mode a pointer filled in with the presentation mode.
|
||||
* \param scale_mode a pointer filled in with the scale mode.
|
||||
* \returns true on success or false on failure; call SDL_GetError() for more
|
||||
* information.
|
||||
*
|
||||
@@ -1311,7 +1318,7 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SetRenderLogicalPresentation(SDL_Renderer *
|
||||
*
|
||||
* \sa SDL_SetRenderLogicalPresentation
|
||||
*/
|
||||
extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode, SDL_ScaleMode *scale_mode);
|
||||
extern SDL_DECLSPEC bool SDLCALL SDL_GetRenderLogicalPresentation(SDL_Renderer *renderer, int *w, int *h, SDL_RendererLogicalPresentation *mode);
|
||||
|
||||
/**
|
||||
* Get the final presentation rectangle for rendering.
|
||||
|
||||
@@ -103,7 +103,6 @@ typedef struct
|
||||
int logical_h;
|
||||
bool auto_scale_content;
|
||||
SDL_RendererLogicalPresentation logical_presentation;
|
||||
SDL_ScaleMode logical_scale_mode;
|
||||
float scale;
|
||||
int depth;
|
||||
float refresh_rate;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -1089,7 +1089,6 @@ static int SDLCALL render_testLogicalSize(void *arg)
|
||||
int w, h;
|
||||
int set_w, set_h;
|
||||
SDL_RendererLogicalPresentation set_presentation_mode;
|
||||
SDL_ScaleMode set_scale_mode;
|
||||
SDL_FRect set_rect;
|
||||
const int factor = 2;
|
||||
|
||||
@@ -1108,16 +1107,13 @@ static int SDLCALL render_testLogicalSize(void *arg)
|
||||
|
||||
/* Set the logical size and do a fill operation */
|
||||
CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
|
||||
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor,
|
||||
SDL_LOGICAL_PRESENTATION_LETTERBOX,
|
||||
SDL_SCALEMODE_NEAREST))
|
||||
CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode, &set_scale_mode))
|
||||
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor, SDL_LOGICAL_PRESENTATION_LETTERBOX))
|
||||
CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode))
|
||||
SDLTest_AssertCheck(
|
||||
set_w == (w / factor) &&
|
||||
set_h == (h / factor) &&
|
||||
set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX &&
|
||||
set_scale_mode == SDL_SCALEMODE_NEAREST,
|
||||
"Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d, %d", set_w, set_h, set_presentation_mode, set_scale_mode);
|
||||
set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX,
|
||||
"Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode);
|
||||
CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
|
||||
SDLTest_AssertCheck(
|
||||
set_rect.x == 0.0f &&
|
||||
@@ -1131,16 +1127,13 @@ static int SDLCALL render_testLogicalSize(void *arg)
|
||||
rect.w = (float)viewport.w / factor;
|
||||
rect.h = (float)viewport.h / factor;
|
||||
CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
|
||||
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0,
|
||||
SDL_LOGICAL_PRESENTATION_DISABLED,
|
||||
SDL_SCALEMODE_NEAREST))
|
||||
CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode, &set_scale_mode))
|
||||
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED))
|
||||
CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode))
|
||||
SDLTest_AssertCheck(
|
||||
set_w == 0 &&
|
||||
set_h == 0 &&
|
||||
set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED &&
|
||||
set_scale_mode == SDL_SCALEMODE_NEAREST,
|
||||
"Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d, %d", set_w, set_h, set_presentation_mode, set_scale_mode);
|
||||
set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED,
|
||||
"Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode);
|
||||
CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
|
||||
SDLTest_AssertCheck(
|
||||
set_rect.x == 0.0f &&
|
||||
@@ -1157,20 +1150,16 @@ static int SDLCALL render_testLogicalSize(void *arg)
|
||||
|
||||
/* Set the logical size and viewport and do a fill operation */
|
||||
CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
|
||||
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor,
|
||||
SDL_LOGICAL_PRESENTATION_LETTERBOX,
|
||||
SDL_SCALEMODE_NEAREST))
|
||||
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor, SDL_LOGICAL_PRESENTATION_LETTERBOX))
|
||||
viewport.x = (TESTRENDER_SCREEN_W / 4) / factor;
|
||||
viewport.y = (TESTRENDER_SCREEN_H / 4) / factor;
|
||||
viewport.w = (TESTRENDER_SCREEN_W / 2) / factor;
|
||||
viewport.h = (TESTRENDER_SCREEN_H / 2) / factor;
|
||||
viewport.w = TESTRENDER_SCREEN_W / factor;
|
||||
viewport.h = TESTRENDER_SCREEN_H / factor;
|
||||
CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport))
|
||||
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
|
||||
CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
|
||||
CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL))
|
||||
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0,
|
||||
SDL_LOGICAL_PRESENTATION_DISABLED,
|
||||
SDL_SCALEMODE_NEAREST))
|
||||
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED))
|
||||
|
||||
/* Check to see if final image matches. */
|
||||
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
|
||||
@@ -1196,15 +1185,13 @@ static int SDLCALL render_testLogicalSize(void *arg)
|
||||
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer,
|
||||
w - 2 * (TESTRENDER_SCREEN_W / 4),
|
||||
h,
|
||||
SDL_LOGICAL_PRESENTATION_LETTERBOX,
|
||||
SDL_SCALEMODE_LINEAR))
|
||||
CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode, &set_scale_mode))
|
||||
SDL_LOGICAL_PRESENTATION_LETTERBOX))
|
||||
CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode))
|
||||
SDLTest_AssertCheck(
|
||||
set_w == w - 2 * (TESTRENDER_SCREEN_W / 4) &&
|
||||
set_h == h &&
|
||||
set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX &&
|
||||
set_scale_mode == SDL_SCALEMODE_LINEAR,
|
||||
"Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d, %d", set_w, set_h, set_presentation_mode, set_scale_mode);
|
||||
set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX,
|
||||
"Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode);
|
||||
CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
|
||||
SDLTest_AssertCheck(
|
||||
set_rect.x == 20.0f &&
|
||||
@@ -1214,16 +1201,13 @@ static int SDLCALL render_testLogicalSize(void *arg)
|
||||
"Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
|
||||
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
|
||||
CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
|
||||
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0,
|
||||
SDL_LOGICAL_PRESENTATION_DISABLED,
|
||||
SDL_SCALEMODE_NEAREST))
|
||||
CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode, &set_scale_mode))
|
||||
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED))
|
||||
CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode))
|
||||
SDLTest_AssertCheck(
|
||||
set_w == 0 &&
|
||||
set_h == 0 &&
|
||||
set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED &&
|
||||
set_scale_mode == SDL_SCALEMODE_NEAREST,
|
||||
"Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d, %d", set_w, set_h, set_presentation_mode, set_scale_mode);
|
||||
set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED,
|
||||
"Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode);
|
||||
CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
|
||||
SDLTest_AssertCheck(
|
||||
set_rect.x == 0.0f &&
|
||||
|
||||
@@ -2086,8 +2086,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* scale for platforms that don't give you the window size you asked for. */
|
||||
SDL_SetRenderLogicalPresentation(screen, (int)SCREEN_WIDTH, (int)SCREEN_HEIGHT,
|
||||
SDL_LOGICAL_PRESENTATION_LETTERBOX,
|
||||
SDL_SCALEMODE_LINEAR);
|
||||
SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
||||
|
||||
|
||||
title_area.w = GAMEPAD_WIDTH;
|
||||
|
||||
+1
-1
@@ -1109,7 +1109,7 @@ int main(int argc, char *argv[])
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
int icon_w = 0, icon_h = 0;
|
||||
|
||||
SDL_SetRenderLogicalPresentation(renderer, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_LOGICAL_PRESENTATION_LETTERBOX, SDL_SCALEMODE_LINEAR);
|
||||
SDL_SetRenderLogicalPresentation(renderer, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
||||
|
||||
ctx->window = window;
|
||||
ctx->renderer = renderer;
|
||||
|
||||
@@ -117,11 +117,13 @@ int main(int argc, char *argv[])
|
||||
goto quit;
|
||||
}
|
||||
|
||||
if (!SDL_CreateWindowAndRenderer("testspriteminimal", WINDOW_WIDTH, WINDOW_HEIGHT, 0, &window, &renderer)) {
|
||||
if (!SDL_CreateWindowAndRenderer("testspriteminimal", WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_RESIZABLE, &window, &renderer)) {
|
||||
return_code = 2;
|
||||
goto quit;
|
||||
}
|
||||
|
||||
SDL_SetRenderLogicalPresentation(renderer, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_LOGICAL_PRESENTATION_LETTERBOX);
|
||||
|
||||
sprite = CreateTexture(renderer, icon_bmp, icon_bmp_len, &sprite_w, &sprite_h);
|
||||
|
||||
if (!sprite) {
|
||||
|
||||
Reference in New Issue
Block a user