Compare commits

...

8 Commits

Author SHA1 Message Date
Ozkan Sezer
cc9937201e x11: fix a typo after PR/13855 and kill lots of trailing whitespace 2025-09-03 04:37:56 +03:00
Sam Lantinga
ef19c72015 Set the texture scale and address mode when creating a texture
Fixes https://github.com/libsdl-org/sdl2-compat/issues/506
2025-09-02 18:05:31 -07:00
eafton
d14cbd7b50 Introduce X11 toolkit and make message dialogs use it (#13855) 2025-09-02 13:22:48 -07:00
Ryan C. Gordon
af74b1fe84 wikiheaders: Generate a current list of supported environment variables.
Fixes #13827.
2025-09-02 15:49:52 -04:00
Ozkan Sezer
83bb0f9105 cmake: simd detection clean-up for Apple multi-arch configs. 2025-09-02 22:34:10 +03:00
Anonymous Maarten
c0fb71f2a9 cmake: fix SDL_UNINSTALL post-configuration report 2025-09-02 21:29:50 +02:00
Anonymous Maarten
e15e2808f2 cmake: use 'TargetConditionals.h' on Apple for SIMD tests 2025-09-02 21:29:50 +02:00
Anonymous Maarten
1e7d3b51de cmake: use APPLE in dep_option
expands to <nothing> on e.g. Windows, which will be interpreted as true by cmake_dependent_option.
2025-09-02 21:29:50 +02:00
12 changed files with 2474 additions and 1219 deletions

View File

@@ -31,3 +31,11 @@ quickreftitle = SDL3 API Quick Reference
quickrefurl = https://libsdl.org/
quickrefdesc = The latest version of this document can be found at https://wiki.libsdl.org/SDL3/QuickReference
quickrefmacroregex = \A(SDL_PLATFORM_.*|SDL_.*_INTRINSICS|SDL_Atomic...Ref|SDL_assert.*?|SDL_COMPILE_TIME_ASSERT|SDL_arraysize|SDL_Swap[BL]E\d\d|SDL_[a-z]+_cast)\Z
envvarenabled = 1
envvartitle = SDL3 Environment Variables
envvardesc = SDL3 can be controlled by the user, externally, with environment variables. They are all operate exactly like the [hints you can get and set programmatically](CategoryHints), but named without the `_HINT` part (so `"SDL_HINT_A"` would be environment variable `"SDL_A"`).\n\nThis list matches the latest in SDL3's revision control.
envvarsymregex = \ASDL_HINT_(.*)\Z
envvarsymreplace = SDL_$1

View File

@@ -80,6 +80,12 @@ include("${SDL3_SOURCE_DIR}/cmake/PreseedNokiaNGageCache.cmake")
SDL_DetectCompiler()
SDL_DetectTargetCPUArchitectures(SDL_CPUS)
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
list(LENGTH CMAKE_OSX_ARCHITECTURES _num_arches)
if(_num_arches GREATER 1)
set(APPLE_MULTIARCH TRUE)
endif()
endif()
# Increment this if there is an incompatible change - but if that happens,
# we should rename the library from SDL3 to SDL4, at which point this would
@@ -354,7 +360,7 @@ dep_option(SDL_WASAPI "Use the Windows WASAPI audio driver" ON "WIN
dep_option(SDL_RENDER_D3D "Enable the Direct3D 9 render driver" ON "SDL_RENDER;SDL_DIRECTX" OFF)
dep_option(SDL_RENDER_D3D11 "Enable the Direct3D 11 render driver" ON "SDL_RENDER;SDL_DIRECTX" OFF)
dep_option(SDL_RENDER_D3D12 "Enable the Direct3D 12 render driver" ON "SDL_RENDER;SDL_DIRECTX" OFF)
dep_option(SDL_RENDER_METAL "Enable the Metal render driver" ON "SDL_RENDER;${APPLE}" OFF)
dep_option(SDL_RENDER_METAL "Enable the Metal render driver" ON "SDL_RENDER;APPLE" OFF)
dep_option(SDL_RENDER_GPU "Enable the SDL_GPU render driver" ON "SDL_RENDER;SDL_GPU" OFF)
dep_option(SDL_VIVANTE "Use Vivante EGL video driver" ON "${UNIX_SYS};SDL_CPU_ARM32" OFF)
dep_option(SDL_VULKAN "Enable Vulkan support" ON "SDL_VIDEO;ANDROID OR APPLE OR LINUX OR FREEBSD OR WINDOWS" OFF)
@@ -683,7 +689,7 @@ if(SDL_ASSEMBLY)
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -mmmx")
endif()
check_c_source_compiles("
check_x86_source_compiles([==[
#include <mmintrin.h>
void ints_add(int *dest, int *a, int *b, unsigned size) {
for (; size >= 2; size -= 2, dest += 2, a += 2, b += 2) {
@@ -693,7 +699,7 @@ if(SDL_ASSEMBLY)
int main(int argc, char *argv[]) {
ints_add((int*)0, (int*)0, (int*)0, 0);
return 0;
}" COMPILER_SUPPORTS_MMX)
}]==] COMPILER_SUPPORTS_MMX)
cmake_pop_check_state()
if(COMPILER_SUPPORTS_MMX)
set(HAVE_MMX TRUE)
@@ -704,7 +710,7 @@ if(SDL_ASSEMBLY)
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -msse")
endif()
check_c_source_compiles("
check_x86_source_compiles([==[
#include <xmmintrin.h>
void floats_add(float *dest, float *a, float *b, unsigned size) {
for (; size >= 4; size -= 4, dest += 4, a += 4, b += 4) {
@@ -714,7 +720,7 @@ if(SDL_ASSEMBLY)
int main(int argc, char **argv) {
floats_add((float*)0, (float*)0, (float*)0, 0);
return 0;
}" COMPILER_SUPPORTS_SSE)
}]==] COMPILER_SUPPORTS_SSE)
cmake_pop_check_state()
if(COMPILER_SUPPORTS_SSE)
set(HAVE_SSE TRUE)
@@ -725,7 +731,7 @@ if(SDL_ASSEMBLY)
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -msse2")
endif()
check_c_source_compiles("
check_x86_source_compiles([==[
#include <emmintrin.h>
void doubles_add(double *dest, double *a, double *b, unsigned size) {
for (; size >= 4; size -= 4, dest += 4, a += 4, b += 4) {
@@ -735,7 +741,7 @@ if(SDL_ASSEMBLY)
int main(int argc, char **argv) {
doubles_add((double*)0, (double*)0, (double*)0, 0);
return 0;
}" COMPILER_SUPPORTS_SSE2)
}]==] COMPILER_SUPPORTS_SSE2)
cmake_pop_check_state()
if(COMPILER_SUPPORTS_SSE2)
set(HAVE_SSE2 TRUE)
@@ -746,7 +752,7 @@ if(SDL_ASSEMBLY)
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -msse3")
endif()
check_c_source_compiles("
check_x86_source_compiles([==[
#include <pmmintrin.h>
void ints_add(int *dest, int *a, int *b, unsigned size) {
for (; size >= 4; size -= 4, dest += 4, a += 4, b += 4) {
@@ -756,7 +762,7 @@ if(SDL_ASSEMBLY)
int main(int argc, char **argv) {
ints_add((int*)0, (int*)0, (int*)0, 0);
return 0;
}" COMPILER_SUPPORTS_SSE3)
}]==] COMPILER_SUPPORTS_SSE3)
cmake_pop_check_state()
if(COMPILER_SUPPORTS_SSE3)
set(HAVE_SSE3 TRUE)
@@ -767,7 +773,7 @@ if(SDL_ASSEMBLY)
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -msse4.1")
endif()
check_c_source_compiles("
check_x86_source_compiles([==[
#include <smmintrin.h>
void ints_mul(int *dest, int *a, int *b, unsigned size) {
for (; size >= 4; size -= 4, dest += 4, a += 4, b += 4) {
@@ -777,7 +783,7 @@ if(SDL_ASSEMBLY)
int main(int argc, char **argv) {
ints_mul((int*)0, (int*)0, (int*)0, 0);
return 0;
}" COMPILER_SUPPORTS_SSE4_1)
}]==] COMPILER_SUPPORTS_SSE4_1)
cmake_pop_check_state()
if(COMPILER_SUPPORTS_SSE4_1)
set(HAVE_SSE4_1 TRUE)
@@ -788,14 +794,14 @@ if(SDL_ASSEMBLY)
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -msse4.2")
endif()
check_c_source_compiles("
check_x86_source_compiles([==[
#include <nmmintrin.h>
__m128i bitmask;
char data[16];
int main(int argc, char **argv) {
bitmask = _mm_cmpgt_epi64(_mm_set1_epi64x(0), _mm_loadu_si128((void*)data));
return 0;
}" COMPILER_SUPPORTS_SSE4_2)
}]==] COMPILER_SUPPORTS_SSE4_2)
cmake_pop_check_state()
if(COMPILER_SUPPORTS_SSE4_2)
set(HAVE_SSE4_2 TRUE)
@@ -806,7 +812,7 @@ if(SDL_ASSEMBLY)
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -mavx")
endif()
check_c_source_compiles("
check_x86_source_compiles([==[
#include <immintrin.h>
void floats_add(float *dest, float *a, float *b, unsigned size) {
for (; size >= 8; size -= 8, dest += 8, a += 8, b += 8) {
@@ -816,7 +822,7 @@ if(SDL_ASSEMBLY)
int main(int argc, char **argv) {
floats_add((float*)0, (float*)0, (float*)0, 0);
return 0;
}" COMPILER_SUPPORTS_AVX)
}]==] COMPILER_SUPPORTS_AVX)
cmake_pop_check_state()
if(COMPILER_SUPPORTS_AVX)
set(HAVE_AVX TRUE)
@@ -827,7 +833,7 @@ if(SDL_ASSEMBLY)
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -mavx2")
endif()
check_c_source_compiles("
check_x86_source_compiles([==[
#include <immintrin.h>
void ints_add(int *dest, int *a, int *b, unsigned size) {
for (; size >= 8; size -= 8, dest += 8, a += 8, b += 8) {
@@ -837,7 +843,7 @@ if(SDL_ASSEMBLY)
int main(int argc, char **argv) {
ints_add((int*)0, (int*)0, (int*)0, 0);
return 0;
}" COMPILER_SUPPORTS_AVX2)
}]==] COMPILER_SUPPORTS_AVX2)
cmake_pop_check_state()
if(COMPILER_SUPPORTS_AVX2)
set(HAVE_AVX2 TRUE)
@@ -848,7 +854,7 @@ if(SDL_ASSEMBLY)
if(USE_GCC OR USE_CLANG OR USE_INTELCC)
string(APPEND CMAKE_REQUIRED_FLAGS " -mavx512f")
endif()
check_c_source_compiles("
check_x86_source_compiles([==[
#include <immintrin.h>
void floats_add(float *dest, float *a, float *b, unsigned size) {
for (; size >= 16; size -= 16, dest += 16, a += 16, b += 16) {
@@ -858,7 +864,7 @@ if(SDL_ASSEMBLY)
int main(int argc, char **argv) {
floats_add((float*)0, (float*)0, (float*)0, 0);
return 0;
}" COMPILER_SUPPORTS_AVX512F)
}]==] COMPILER_SUPPORTS_AVX512F)
cmake_pop_check_state()
if(COMPILER_SUPPORTS_AVX512F)
set(HAVE_AVX512F TRUE)
@@ -866,18 +872,17 @@ if(SDL_ASSEMBLY)
endif()
if(SDL_ARMNEON)
check_c_source_compiles("
#include <arm_neon.h>
void floats_add(float *dest, float *a, float *b, unsigned size) {
for (; size >= 4; size -= 4, dest += 4, a += 4, b += 4) {
vst1q_f32(dest, vaddq_f32(vld1q_f32(a), vld1q_f32(b)));
}
check_arm_source_compiles([==[
#include <arm_neon.h>
void floats_add(float *dest, float *a, float *b, unsigned size) {
for (; size >= 4; size -= 4, dest += 4, a += 4, b += 4) {
vst1q_f32(dest, vaddq_f32(vld1q_f32(a), vld1q_f32(b)));
}
int main(int argc, char *argv[]) {
floats_add((float*)0, (float*)0, (float*)0, 0);
return 0;
}" COMPILER_SUPPORTS_ARMNEON)
}
int main(int argc, char *argv[]) {
floats_add((float*)0, (float*)0, (float*)0, 0);
return 0;
}]==] COMPILER_SUPPORTS_ARMNEON)
if(COMPILER_SUPPORTS_ARMNEON)
set(HAVE_ARMNEON TRUE)
endif()
@@ -4265,6 +4270,7 @@ endif()
##### Uninstall target #####
if(SDL_UNINSTALL)
set(HAVE_UNINSTALL ON)
if(NOT TARGET uninstall)
configure_file(cmake/cmake_uninstall.cmake.in cmake_uninstall.cmake IMMEDIATE @ONLY)

View File

@@ -58,6 +58,11 @@ my $quickreftitle = undef;
my $quickrefurl = undef;
my $quickrefdesc = undef;
my $quickrefmacroregex = undef;
my $envvarenabled = 0;
my $envvartitle = 'Environment Variables';
my $envvardesc = undef;
my $envvarsymregex = undef;
my $envvarsymreplace = undef;
my $changeformat = undef;
my $manpath = undef;
my $gitrev = undef;
@@ -137,6 +142,11 @@ if (defined $optionsfname) {
$quickrefurl = $val, next if $key eq 'quickrefurl';
$quickrefdesc = $val, next if $key eq 'quickrefdesc';
$quickrefmacroregex = $val, next if $key eq 'quickrefmacroregex';
$envvarenabled = int($val), next if $key eq 'envvarenabled';
$envvartitle = $val, next if $key eq 'envvartitle';
$envvardesc = $val, next if $key eq 'envvardesc';
$envvarsymregex = $val, next if $key eq 'envvarsymregex';
$envvarsymreplace = $val, next if $key eq 'envvarsymreplace';
}
}
close(OPTIONS);
@@ -1034,6 +1044,55 @@ sub generate_quickref {
}
sub generate_envvar_wiki_page {
my $briefsref = shift;
my $path = shift;
return if not $envvarenabled or not defined $envvarsymregex or not defined $envvarsymreplace;
my $replace = "\"$envvarsymreplace\"";
my $tmppath = "$path.tmp";
open(my $fh, '>', $tmppath) or die("Can't open '$tmppath': $!\n");
print $fh "<!-- DO NOT EDIT THIS PAGE ON THE WIKI. IT WILL BE OVERWRITTEN BY WIKIHEADERS AND CHANGES WILL BE LOST! -->\n\n";
print $fh "# $envvartitle\n\n";
if (defined $envvardesc) {
my $desc = "$envvardesc";
$desc =~ s/\\n/\n/g; # replace "\n" strings with actual newlines.
print $fh "$desc\n\n";
}
print $fh "## Environment Variable List\n\n";
foreach (sort keys %headersyms) {
my $sym = $_;
next if $headersymstype{$sym} != 2; # not a #define? skip it.
my $hint = "$_";
next if not $hint =~ s/$envvarsymregex/$replace/ee;
my $brief = $$briefsref{$sym};
if (not defined $brief) {
$brief = '';
} else {
$brief = "$brief";
chomp($brief);
my $thiswikitype = defined $wikitypes{$sym} ? $wikitypes{$sym} : 'md'; # default to MarkDown for new stuff.
$brief = ": " . dewikify($thiswikitype, $brief);
}
print $fh "- [$hint]($sym)$brief\n";
}
print $fh "\n";
close($fh);
rename($tmppath, $path) or die("Can't rename '$tmppath' to '$path': $!\n");
}
my $incpath = "$srcpath";
$incpath .= "/$incsubdir" if $incsubdir ne '';
@@ -2733,6 +2792,11 @@ __EOF__
generate_quickref(\%briefs, "$wikipath/QuickReference.md", 0);
generate_quickref(\%briefs, "$wikipath/QuickReferenceNoUnicode.md", 1);
}
if ($envvarenabled and defined $envvarsymregex and defined $envvarsymreplace) {
generate_envvar_wiki_page(\%briefs, "$wikipath/EnvironmentVariables.md");
}
} elsif ($copy_direction == -2) { # --copy-to-manpages
# This only takes from the wiki data, since it has sections we omit from the headers, like code examples.

View File

@@ -160,3 +160,63 @@ function(SDL_AddCommonCompilerFlags TARGET)
endif()
endif()
endfunction()
function(check_x86_source_compiles BODY VAR)
if(ARGN)
message(FATAL_ERROR "Unknown arguments: ${ARGN}")
endif()
if(APPLE_MULTIARCH AND (SDL_CPU_X86 OR SDL_CPU_X64))
set(test_conditional 1)
else()
set(test_conditional 0)
endif()
check_c_source_compiles("
#if ${test_conditional}
# if defined(__i386__) || defined(__x86_64__)
# define test_enabled 1
# else
# define test_enabled 0 /* feign success in Apple multi-arch configs */
# endif
#else /* test normally */
# define test_enabled 1
#endif
#if test_enabled
${BODY}
#else
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
return 0;
}
#endif" ${VAR})
endfunction()
function(check_arm_source_compiles BODY VAR)
if(ARGN)
message(FATAL_ERROR "Unknown arguments: ${ARGN}")
endif()
if(APPLE_MULTIARCH AND (SDL_CPU_ARM32 OR SDL_CPU_ARM64))
set(test_conditional 1)
else()
set(test_conditional 0)
endif()
check_c_source_compiles("
#if ${test_conditional}
# if defined(__arm__) || defined(__aarch64__)
# define test_enabled 1
# else
# define test_enabled 0 /* feign success in Apple multi-arch configs */
# endif
#else /* test normally */
# define test_enabled 1
#endif
#if test_enabled
${BODY}
#else
int main(int argc, char *argv[]) {
(void)argc;
(void)argv;
return 0;
}
#endif" ${VAR})
endfunction()

View File

@@ -442,6 +442,43 @@ static bool convert_format(Uint32 pixel_format, GLint *internalFormat, GLenum *f
return true;
}
static bool SetTextureScaleMode(GL_RenderData *data, GLenum textype, SDL_ScaleMode scaleMode)
{
switch (scaleMode) {
case SDL_SCALEMODE_NEAREST:
data->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
data->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
break;
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
case SDL_SCALEMODE_LINEAR:
data->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
data->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
break;
default:
return SDL_SetError("Unknown texture scale mode: %d", scaleMode);
}
return true;
}
static GLint TranslateAddressMode(SDL_TextureAddressMode addressMode)
{
switch (addressMode) {
case SDL_TEXTURE_ADDRESS_CLAMP:
return GL_CLAMP_TO_EDGE;
case SDL_TEXTURE_ADDRESS_WRAP:
return GL_REPEAT;
default:
SDL_assert(!"Unknown texture address mode");
return GL_CLAMP_TO_EDGE;
}
}
static void SetTextureAddressMode(GL_RenderData *data, GLenum textype, SDL_TextureAddressMode addressModeU, SDL_TextureAddressMode addressModeV)
{
data->glTexParameteri(textype, GL_TEXTURE_WRAP_S, TranslateAddressMode(addressModeU));
data->glTexParameteri(textype, GL_TEXTURE_WRAP_T, TranslateAddressMode(addressModeV));
}
static bool GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_PropertiesID create_props)
{
GL_RenderData *renderdata = (GL_RenderData *)renderer->internal;
@@ -538,11 +575,13 @@ static bool GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P
data->format = format;
data->formattype = type;
data->texture_scale_mode = SDL_SCALEMODE_INVALID;
data->texture_address_mode_u = SDL_TEXTURE_ADDRESS_INVALID;
data->texture_address_mode_v = SDL_TEXTURE_ADDRESS_INVALID;
data->texture_scale_mode = texture->scaleMode;
data->texture_address_mode_u = SDL_TEXTURE_ADDRESS_CLAMP;
data->texture_address_mode_v = SDL_TEXTURE_ADDRESS_CLAMP;
renderdata->glEnable(textype);
renderdata->glBindTexture(textype, data->texture);
SetTextureScaleMode(renderdata, textype, data->texture_scale_mode);
SetTextureAddressMode(renderdata, textype, data->texture_address_mode_u, data->texture_address_mode_v);
#ifdef SDL_PLATFORM_MACOS
#ifndef GL_TEXTURE_STORAGE_HINT_APPLE
#define GL_TEXTURE_STORAGE_HINT_APPLE 0x85BC
@@ -574,10 +613,11 @@ static bool GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P
renderdata->glTexImage2D(textype, 0, internalFormat, texture_w,
texture_h, 0, format, type, NULL);
}
renderdata->glDisable(textype);
if (!GL_CheckError("glTexImage2D()", renderer)) {
return false;
}
SetTextureScaleMode(renderdata, textype, data->texture_scale_mode);
SetTextureAddressMode(renderdata, textype, data->texture_address_mode_u, data->texture_address_mode_v);
#ifdef SDL_HAVE_YUV
if (texture->format == SDL_PIXELFORMAT_YV12 ||
@@ -600,11 +640,15 @@ static bool GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P
renderdata->glBindTexture(textype, data->utexture);
renderdata->glTexImage2D(textype, 0, internalFormat, (texture_w + 1) / 2,
(texture_h + 1) / 2, 0, format, type, NULL);
SetTextureScaleMode(renderdata, textype, data->texture_scale_mode);
SetTextureAddressMode(renderdata, textype, data->texture_address_mode_u, data->texture_address_mode_v);
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_U_NUMBER, data->utexture);
renderdata->glBindTexture(textype, data->vtexture);
renderdata->glTexImage2D(textype, 0, internalFormat, (texture_w + 1) / 2,
(texture_h + 1) / 2, 0, format, type, NULL);
SetTextureScaleMode(renderdata, textype, data->texture_scale_mode);
SetTextureAddressMode(renderdata, textype, data->texture_address_mode_u, data->texture_address_mode_v);
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_V_NUMBER, data->vtexture);
}
@@ -621,6 +665,8 @@ static bool GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P
renderdata->glBindTexture(textype, data->utexture);
renderdata->glTexImage2D(textype, 0, GL_LUMINANCE_ALPHA, (texture_w + 1) / 2,
(texture_h + 1) / 2, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, NULL);
SetTextureScaleMode(renderdata, textype, data->texture_scale_mode);
SetTextureAddressMode(renderdata, textype, data->texture_address_mode_u, data->texture_address_mode_v);
SDL_SetNumberProperty(props, SDL_PROP_TEXTURE_OPENGL_TEXTURE_UV_NUMBER, data->utexture);
}
#endif
@@ -660,6 +706,8 @@ static bool GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SDL_P
}
#endif // SDL_HAVE_YUV
renderdata->glDisable(textype);
return GL_CheckError("", renderer);
}
@@ -1083,43 +1131,6 @@ static bool SetDrawState(GL_RenderData *data, const SDL_RenderCommand *cmd, cons
return true;
}
static bool SetTextureScaleMode(GL_RenderData *data, GLenum textype, SDL_ScaleMode scaleMode)
{
switch (scaleMode) {
case SDL_SCALEMODE_NEAREST:
data->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
data->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
break;
case SDL_SCALEMODE_PIXELART: // Uses linear sampling
case SDL_SCALEMODE_LINEAR:
data->glTexParameteri(textype, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
data->glTexParameteri(textype, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
break;
default:
return SDL_SetError("Unknown texture scale mode: %d", scaleMode);
}
return true;
}
static GLint TranslateAddressMode(SDL_TextureAddressMode addressMode)
{
switch (addressMode) {
case SDL_TEXTURE_ADDRESS_CLAMP:
return GL_CLAMP_TO_EDGE;
case SDL_TEXTURE_ADDRESS_WRAP:
return GL_REPEAT;
default:
SDL_assert(!"Unknown texture address mode");
return GL_CLAMP_TO_EDGE;
}
}
static void SetTextureAddressMode(GL_RenderData *data, GLenum textype, SDL_TextureAddressMode addressModeU, SDL_TextureAddressMode addressModeV)
{
data->glTexParameteri(textype, GL_TEXTURE_WRAP_S, TranslateAddressMode(addressModeU));
data->glTexParameteri(textype, GL_TEXTURE_WRAP_T, TranslateAddressMode(addressModeV));
}
static bool SetCopyState(GL_RenderData *data, const SDL_RenderCommand *cmd)
{
SDL_Texture *texture = cmd->data.draw.texture;

View File

@@ -1658,9 +1658,9 @@ static bool GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
data->texture_u = 0;
data->texture_v = 0;
#endif
data->texture_scale_mode = SDL_SCALEMODE_INVALID;
data->texture_address_mode_u = SDL_TEXTURE_ADDRESS_INVALID;
data->texture_address_mode_v = SDL_TEXTURE_ADDRESS_INVALID;
data->texture_scale_mode = texture->scaleMode;
data->texture_address_mode_u = SDL_TEXTURE_ADDRESS_CLAMP;
data->texture_address_mode_v = SDL_TEXTURE_ADDRESS_CLAMP;
// Allocate a blob for image renderdata
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
@@ -1707,6 +1707,13 @@ static bool GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
renderdata->glActiveTexture(GL_TEXTURE2);
renderdata->glBindTexture(data->texture_type, data->texture_v);
renderdata->glTexImage2D(data->texture_type, 0, format, (texture->w + 1) / 2, (texture->h + 1) / 2, 0, format, type, NULL);
if (!GL_CheckError("glTexImage2D()", renderer)) {
SDL_free(data->pixel_data);
SDL_free(data);
return false;
}
SetTextureScaleMode(renderdata, data->texture_type, data->texture_scale_mode);
SetTextureAddressMode(renderdata, data->texture_type, data->texture_address_mode_u, data->texture_address_mode_v);
SDL_SetNumberProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_V_NUMBER, data->texture_v);
data->texture_u = (GLuint)SDL_GetNumberProperty(create_props, SDL_PROP_TEXTURE_CREATE_OPENGLES2_TEXTURE_U_NUMBER, 0);
@@ -1728,6 +1735,8 @@ static bool GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
SDL_free(data);
return false;
}
SetTextureScaleMode(renderdata, data->texture_type, data->texture_scale_mode);
SetTextureAddressMode(renderdata, data->texture_type, data->texture_address_mode_u, data->texture_address_mode_v);
SDL_SetNumberProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_U_NUMBER, data->texture_u);
if (!SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace, texture->w, texture->h, 8)) {
@@ -1755,6 +1764,8 @@ static bool GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
SDL_free(data);
return false;
}
SetTextureScaleMode(renderdata, data->texture_type, data->texture_scale_mode);
SetTextureAddressMode(renderdata, data->texture_type, data->texture_address_mode_u, data->texture_address_mode_v);
SDL_SetNumberProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_UV_NUMBER, data->texture_u);
if (!SDL_GetYCbCRtoRGBConversionMatrix(texture->colorspace, texture->w, texture->h, 8)) {
@@ -1785,6 +1796,8 @@ static bool GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture, SD
return false;
}
}
SetTextureScaleMode(renderdata, data->texture_type, data->texture_scale_mode);
SetTextureAddressMode(renderdata, data->texture_type, data->texture_address_mode_u, data->texture_address_mode_v);
SDL_SetNumberProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_NUMBER, data->texture);
SDL_SetNumberProperty(SDL_GetTextureProperties(texture), SDL_PROP_TEXTURE_OPENGLES2_TEXTURE_TARGET_NUMBER, data->texture_type);

File diff suppressed because it is too large Load Diff

View File

@@ -26,10 +26,6 @@
#include "SDL_x11video.h"
#include "SDL_x11settings.h"
#define SDL_XSETTINGS_GDK_WINDOW_SCALING_FACTOR "Gdk/WindowScalingFactor"
#define SDL_XSETTINGS_GDK_UNSCALED_DPI "Gdk/UnscaledDPI"
#define SDL_XSETTINGS_XFT_DPI "Xft/DPI"
static void UpdateContentScale(SDL_VideoDevice *_this)
{
if (_this) {
@@ -45,7 +41,7 @@ static void X11_XsettingsNotify(const char *name, XSettingsAction action, XSetti
SDL_VideoDevice *_this = data;
if (SDL_strcmp(name, SDL_XSETTINGS_GDK_WINDOW_SCALING_FACTOR) == 0 ||
SDL_strcmp(name, SDL_XSETTINGS_GDK_UNSCALED_DPI) == 0 ||
SDL_strcmp(name, SDL_XSETTINGS_GDK_UNSCALED_DPI) == 0 ||
SDL_strcmp(name, SDL_XSETTINGS_XFT_DPI) == 0) {
UpdateContentScale(_this);
}

View File

@@ -27,6 +27,10 @@
#include <X11/Xlib.h>
#include "xsettings-client.h"
#define SDL_XSETTINGS_GDK_WINDOW_SCALING_FACTOR "Gdk/WindowScalingFactor"
#define SDL_XSETTINGS_GDK_UNSCALED_DPI "Gdk/UnscaledDPI"
#define SDL_XSETTINGS_XFT_DPI "Xft/DPI"
typedef struct X11_SettingsData {
XSettingsClient *xsettings;
} SDLX11_SettingsData;

View File

@@ -42,6 +42,7 @@ SDL_X11_SYM(int,XConvertSelection,(Display* a,Atom b,Atom c,Atom d,Window e,Time
SDL_X11_SYM(Pixmap,XCreateBitmapFromData,(Display *dpy,Drawable d,_Xconst char *data,unsigned int width,unsigned int height))
SDL_X11_SYM(Colormap,XCreateColormap,(Display* a,Window b,Visual* c,int d))
SDL_X11_SYM(Cursor,XCreatePixmapCursor,(Display* a,Pixmap b,Pixmap c,XColor* d,XColor* e,unsigned int f,unsigned int g))
SDL_X11_SYM(Cursor,XCreatePixmap,(Display* a,Drawable b,unsigned int d,unsigned int e,unsigned int f))
SDL_X11_SYM(Cursor,XCreateFontCursor,(Display* a,unsigned int b))
SDL_X11_SYM(XFontSet,XCreateFontSet,(Display* a, _Xconst char* b, char*** c, int* d, char** e))
SDL_X11_SYM(GC,XCreateGC,(Display* a,Drawable b,unsigned long c,XGCValues* d))
@@ -68,6 +69,7 @@ SDL_X11_SYM(int,XFreeGC,(Display* a,GC b))
SDL_X11_SYM(int,XFreeFont,(Display* a, XFontStruct* b))
SDL_X11_SYM(int,XFreeModifiermap,(XModifierKeymap* a))
SDL_X11_SYM(int,XFreePixmap,(Display* a,Pixmap b))
SDL_X11_SYM(int,XFreeColormap,(Display* a,Colormap b))
SDL_X11_SYM(void,XFreeStringList,(char** a))
SDL_X11_SYM(char*,XGetAtomName,(Display *a,Atom b))
SDL_X11_SYM(int,XGetInputFocus,(Display *a,Window *b,int *c))
@@ -102,6 +104,8 @@ SDL_X11_SYM(Display*,XOpenDisplay,(_Xconst char* a))
SDL_X11_SYM(Status,XInitThreads,(void))
SDL_X11_SYM(int,XPeekEvent,(Display* a,XEvent* b))
SDL_X11_SYM(int,XPending,(Display* a))
SDL_X11_SYM(XImage*,XGetImage,(Display* a,Drawable b,int c, int d,unsigned int e,unsigned int f,unsigned long g,int h))
SDL_X11_SYM(void,XDestroyImage,(XImage *a))
SDL_X11_SYM(int,XPutImage,(Display* a,Drawable b,GC c,XImage* d,int e,int f,int g,int h,unsigned int i,unsigned int j))
SDL_X11_SYM(int,XQueryKeymap,(Display* a,char b[32]))
SDL_X11_SYM(Bool,XQueryPointer,(Display* a,Window b,Window* c,Window* d,int* e,int* f,int* g,int* h,unsigned int* i))

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,225 @@
/*
Simple DirectMedia Layer
Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "SDL_internal.h"
#ifndef SDL_x11toolkit_h_
#define SDL_x11toolkit_h_
#include "../../SDL_list.h"
#include "SDL_x11video.h"
#include "SDL_x11dyn.h"
#include "SDL_x11settings.h"
#include "SDL_x11toolkit.h"
#include "xsettings-client.h"
#ifdef SDL_VIDEO_DRIVER_X11
/* Various predefined paddings */
#define SDL_TOOLKIT_X11_ELEMENT_PADDING 4
#define SDL_TOOLKIT_X11_ELEMENT_PADDING_2 12
#define SDL_TOOLKIT_X11_ELEMENT_PADDING_3 8
#define SDL_TOOLKIT_X11_ELEMENT_PADDING_4 16
#define SDL_TOOLKIT_X11_ELEMENT_PADDING_5 3
typedef enum SDL_ToolkitChildModeX11
{
SDL_TOOLKIT_WINDOW_MODE_X11_DIALOG,
SDL_TOOLKIT_WINDOW_MODE_X11_CHILD, /* For embedding into a normal SDL_Window */
SDL_TOOLKIT_WINDOW_MODE_X11_MENU,
SDL_TOOLKIT_WINDOW_MODE_X11_TOOLTIP
} SDL_ToolkitWindowModeX11;
typedef struct SDL_ToolkitWindowX11
{
/* Locale */
char *origlocale;
/* Mode */
SDL_ToolkitWindowModeX11 mode;
/* Display */
Display *display;
int screen;
bool display_close;
/* Parent */
SDL_Window *parent;
struct SDL_ToolkitWindowX11 *tk_parent;
/* Window */
Window window;
Drawable drawable;
/* Visuals and drawing */
Visual *visual;
XVisualInfo vi;
Colormap cmap;
GC ctx;
int depth;
bool pixmap;
/* X11 extensions */
#ifdef SDL_VIDEO_DRIVER_X11_XDBE
XdbeBackBuffer buf;
bool xdbe; // Whether Xdbe is present or not
#endif
#ifdef SDL_VIDEO_DRIVER_X11_XRANDR
bool xrandr; // Whether Xrandr is present or not
#endif
bool utf8;
/* Atoms */
Atom wm_protocols;
Atom wm_delete_message;
/* Window and pixmap sizes */
int window_width; // Window width.
int window_height; // Window height.
int pixmap_width;
int pixmap_height;
int window_x;
int window_y;
/* XSettings and scaling */
XSettingsClient *xsettings;
bool xsettings_first_time;
int iscale;
float scale;
/* Font */
XFontSet font_set; // for UTF-8 systems
XFontStruct *font_struct; // Latin1 (ASCII) fallback.
/* Control colors */
const SDL_MessageBoxColor *color_hints;
XColor xcolor[SDL_MESSAGEBOX_COLOR_COUNT];
XColor xcolor_bevel_l1;
XColor xcolor_bevel_l2;
XColor xcolor_bevel_d;
XColor xcolor_pressed;
XColor xcolor_disabled_text;
/* Control list */
bool has_focus;
struct SDL_ToolkitControlX11 *focused_control;
struct SDL_ToolkitControlX11 *fiddled_control;
struct SDL_ToolkitControlX11 **controls;
size_t controls_sz;
struct SDL_ToolkitControlX11 **dyn_controls;
size_t dyn_controls_sz;
/* User callbacks */
void *cb_data;
void (*cb_on_scale_change)(struct SDL_ToolkitWindowX11 *, void *);
/* Popup windows */
SDL_ListNode *popup_windows;
/* Event loop */
XEvent *e;
struct SDL_ToolkitControlX11 *previous_control;
struct SDL_ToolkitControlX11 *key_control_esc;
struct SDL_ToolkitControlX11 *key_control_enter;
KeySym last_key_pressed;
int ev_i;
float ev_scale;
float ev_iscale;
bool draw;
bool close;
long event_mask;
} SDL_ToolkitWindowX11;
typedef enum SDL_ToolkitControlStateX11
{
SDL_TOOLKIT_CONTROL_STATE_X11_NORMAL,
SDL_TOOLKIT_CONTROL_STATE_X11_HOVER,
SDL_TOOLKIT_CONTROL_STATE_X11_PRESSED, /* Key/Button Up */
SDL_TOOLKIT_CONTROL_STATE_X11_PRESSED_HELD, /* Key/Button Down */
SDL_TOOLKIT_CONTROL_STATE_X11_DISABLED
} SDL_ToolkitControlStateX11;
typedef struct SDL_ToolkitControlX11
{
SDL_ToolkitWindowX11 *window;
SDL_ToolkitControlStateX11 state;
SDL_Rect rect;
bool selected;
bool dynamic;
bool is_default_enter;
bool is_default_esc;
/* User data */
void *data;
/* Virtual functions */
void (*func_draw)(struct SDL_ToolkitControlX11 *);
void (*func_calc_size)(struct SDL_ToolkitControlX11 *);
void (*func_on_scale_change)(struct SDL_ToolkitControlX11 *);
void (*func_on_state_change)(struct SDL_ToolkitControlX11 *);
void (*func_free)(struct SDL_ToolkitControlX11 *);
} SDL_ToolkitControlX11;
typedef struct SDL_ToolkitMenuItemX11
{
const char *utf8;
bool checkbox;
bool checked;
bool disabled;
void *cb_data;
void (*cb)(struct SDL_ToolkitMenuItemX11 *, void *);
SDL_ListNode *sub_menu;
/* Internal use */
SDL_Rect utf8_rect;
SDL_Rect hover_rect;
SDL_Rect check_rect;
SDL_ToolkitControlStateX11 state;
int arrow_x;
int arrow_y;
bool reverse_arrows;
} SDL_ToolkitMenuItemX11;
/* WINDOW FUNCTIONS */
extern SDL_ToolkitWindowX11 *X11Toolkit_CreateWindowStruct(SDL_Window *parent, SDL_ToolkitWindowX11 *tkparent, SDL_ToolkitWindowModeX11 mode, const SDL_MessageBoxColor *colorhints);
extern bool X11Toolkit_CreateWindowRes(SDL_ToolkitWindowX11 *data, int w, int h, int cx, int cy, char *title);
extern void X11Toolkit_DoWindowEventLoop(SDL_ToolkitWindowX11 *data);
extern void X11Toolkit_ResizeWindow(SDL_ToolkitWindowX11 *data, int w, int h);
extern void X11Toolkit_DestroyWindow(SDL_ToolkitWindowX11 *data);
extern void X11Toolkit_SignalWindowClose(SDL_ToolkitWindowX11 *data);
/* GENERIC CONTROL FUNCTIONS */
extern bool X11Toolkit_NotifyControlOfSizeChange(SDL_ToolkitControlX11 *control);
/* ICON CONTROL FUNCTIONS */
extern SDL_ToolkitControlX11 *X11Toolkit_CreateIconControl(SDL_ToolkitWindowX11 *window, SDL_MessageBoxFlags flags);
extern int X11Toolkit_GetIconControlCharY(SDL_ToolkitControlX11 *control);
/* LABEL CONTROL FUNCTIONS */
extern SDL_ToolkitControlX11 *X11Toolkit_CreateLabelControl(SDL_ToolkitWindowX11 *window, char *utf8);
/* BUTTON CONTROL FUNCTIONS */
extern SDL_ToolkitControlX11 *X11Toolkit_CreateButtonControl(SDL_ToolkitWindowX11 *window, const SDL_MessageBoxButtonData *data);
extern void X11Toolkit_RegisterCallbackForButtonControl(SDL_ToolkitControlX11 *control, void *data, void (*cb)(struct SDL_ToolkitControlX11 *, void *));
extern const SDL_MessageBoxButtonData *X11Toolkit_GetButtonControlData(SDL_ToolkitControlX11 *control);
#endif // SDL_VIDEO_DRIVER_X11
#endif // SDL_x11toolkit_h_