mirror of
https://github.com/encounter/SDL.git
synced 2025-12-16 16:37:09 +00:00
Merge remote-tracking branch 'upstream/2.0.22' into switch-sdl2-2.0.14-dev
# Conflicts: # .gitignore # CMakeLists.txt # configure # configure.ac # include/SDL_config.h.cmake # include/SDL_config.h.in # sdl2-config.cmake.in # src/dynapi/SDL_dynapi.h # src/joystick/SDL_gamecontrollerdb.h # src/joystick/SDL_sysjoystick.h # src/video/SDL_video.c # src/video/khronos/EGL/eglplatform.h
This commit is contained in:
@@ -1,21 +1,56 @@
|
||||
cmake_minimum_required(VERSION 2.8.11)
|
||||
cmake_minimum_required(VERSION 3.0.0)
|
||||
project(SDL2 C)
|
||||
|
||||
# Global settings for all of the test targets
|
||||
# FIXME: is this wrong?
|
||||
remove_definitions(-DUSING_GENERATED_CONFIG_H)
|
||||
link_libraries(SDL2_test SDL2-static)
|
||||
|
||||
# FIXME: Parent directory CMakeLists.txt only sets these for mingw/cygwin,
|
||||
# but we need them for VS as well.
|
||||
if(PSP)
|
||||
link_libraries(
|
||||
SDL2main
|
||||
SDL2_test
|
||||
SDL2-static
|
||||
GL
|
||||
pspvram
|
||||
pspvfpu
|
||||
pspdisplay
|
||||
pspgu
|
||||
pspge
|
||||
pspaudio
|
||||
pspctrl
|
||||
psphprm
|
||||
psppower
|
||||
)
|
||||
else()
|
||||
link_libraries(SDL2_test SDL2-static)
|
||||
endif()
|
||||
|
||||
if(WINDOWS)
|
||||
# mingw32 must come before SDL2main to link successfully
|
||||
if(MINGW OR CYGWIN)
|
||||
link_libraries(mingw32)
|
||||
endif()
|
||||
|
||||
# FIXME: Parent directory CMakeLists.txt only sets these for mingw/cygwin,
|
||||
# but we need them for VS as well.
|
||||
link_libraries(SDL2main)
|
||||
add_definitions(-Dmain=SDL_main)
|
||||
endif()
|
||||
|
||||
# CMake incorrectly detects opengl32.lib being present on MSVC ARM64
|
||||
if(NOT MSVC OR NOT CMAKE_GENERATOR_PLATFORM STREQUAL "ARM64")
|
||||
find_package(OpenGL)
|
||||
endif()
|
||||
|
||||
if (OPENGL_FOUND)
|
||||
add_definitions(-DHAVE_OPENGL)
|
||||
endif()
|
||||
|
||||
add_executable(checkkeys checkkeys.c)
|
||||
add_executable(checkkeysthreads checkkeysthreads.c)
|
||||
add_executable(loopwave loopwave.c)
|
||||
add_executable(loopwavequeue loopwavequeue.c)
|
||||
add_executable(testsurround testsurround.c)
|
||||
add_executable(testresample testresample.c)
|
||||
add_executable(testaudioinfo testaudioinfo.c)
|
||||
|
||||
@@ -35,6 +70,7 @@ add_executable(testdropfile testdropfile.c)
|
||||
add_executable(testerror testerror.c)
|
||||
add_executable(testfile testfile.c)
|
||||
add_executable(testgamecontroller testgamecontroller.c)
|
||||
add_executable(testgeometry testgeometry.c)
|
||||
add_executable(testgesture testgesture.c)
|
||||
add_executable(testgl2 testgl2.c)
|
||||
add_executable(testgles testgles.c)
|
||||
@@ -49,6 +85,7 @@ add_executable(testjoystick testjoystick.c)
|
||||
add_executable(testkeys testkeys.c)
|
||||
add_executable(testloadso testloadso.c)
|
||||
add_executable(testlock testlock.c)
|
||||
add_executable(testmouse testmouse.c)
|
||||
|
||||
if(APPLE)
|
||||
add_executable(testnative testnative.c
|
||||
@@ -88,43 +125,151 @@ add_executable(controllermap controllermap.c)
|
||||
add_executable(testvulkan testvulkan.c)
|
||||
add_executable(testoffscreen testoffscreen.c)
|
||||
|
||||
# HACK: Dummy target to cause the resource files to be copied to the build directory.
|
||||
# Need to make it an executable so we can use the TARGET_FILE_DIR generator expression.
|
||||
# This is needed so they get copied to the correct Debug/Release subdirectory in Xcode.
|
||||
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/resources_dummy.c "int main(int argc, const char **argv){ return 1; }\n")
|
||||
add_executable(SDL2_test_resoureces ${CMAKE_CURRENT_BINARY_DIR}/resources_dummy.c)
|
||||
|
||||
file(GLOB RESOURCE_FILES *.bmp *.wav moose.dat utf8.txt)
|
||||
foreach(RESOURCE_FILE ${RESOURCE_FILES})
|
||||
add_custom_command(TARGET SDL2_test_resoureces POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:SDL2_test_resoureces>)
|
||||
endforeach(RESOURCE_FILE)
|
||||
if(OPENGL_FOUND)
|
||||
add_dependencies(testshader OpenGL::GL)
|
||||
add_dependencies(testgl2 OpenGL::GL)
|
||||
target_link_libraries(testshader OpenGL::GL)
|
||||
target_link_libraries(testgl2 OpenGL::GL)
|
||||
endif()
|
||||
|
||||
file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt)
|
||||
file(COPY ${RESOURCE_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
if(PSP)
|
||||
set(NEEDS_RESOURCES
|
||||
testscale
|
||||
testrendercopyex
|
||||
controllermap
|
||||
testyuv
|
||||
testgamecontroller
|
||||
testshape
|
||||
testshader
|
||||
testspriteminimal
|
||||
testautomation
|
||||
testrendertarget
|
||||
testsprite2
|
||||
loopwave
|
||||
loopwavequeue
|
||||
testresample
|
||||
testaudiohotplug
|
||||
testmultiaudio
|
||||
testiconv
|
||||
testoverlay2
|
||||
teststreaming
|
||||
testviewport
|
||||
)
|
||||
else()
|
||||
set(NEEDS_RESOURCES
|
||||
testscale
|
||||
testrendercopyex
|
||||
controllermap
|
||||
testyuv
|
||||
testgamecontroller
|
||||
testshape
|
||||
testshader
|
||||
testspriteminimal
|
||||
testautomation
|
||||
testcustomcursor
|
||||
testrendertarget
|
||||
testsprite2
|
||||
loopwave
|
||||
loopwavequeue
|
||||
testresample
|
||||
testaudiohotplug
|
||||
testmultiaudio
|
||||
testime
|
||||
testnative
|
||||
testiconv
|
||||
testoverlay2
|
||||
teststreaming
|
||||
testviewport
|
||||
)
|
||||
endif()
|
||||
|
||||
# TODO: Might be easier to make all targets depend on the resources...?
|
||||
if(PSP)
|
||||
# Build EBOOT files if building for PSP
|
||||
set(BUILD_EBOOT
|
||||
${NEEDS_RESOURCES}
|
||||
testbounds
|
||||
testgl2
|
||||
testsem
|
||||
testdisplayinfo
|
||||
teststreaming
|
||||
testgeometry
|
||||
testfile
|
||||
testdraw2
|
||||
testviewport
|
||||
testhittesting
|
||||
testoverlay2
|
||||
testver
|
||||
testdrawchessboard
|
||||
testsurround
|
||||
testintersections
|
||||
testmessage
|
||||
testaudiocapture
|
||||
testerror
|
||||
testatomic
|
||||
testjoystick
|
||||
testiconv
|
||||
testfilesystem
|
||||
testplatform
|
||||
testthread
|
||||
testqsort
|
||||
testaudioinfo
|
||||
testlock
|
||||
testtimer
|
||||
testpower
|
||||
testwm2
|
||||
torturethread
|
||||
)
|
||||
foreach(APP IN LISTS BUILD_EBOOT)
|
||||
create_pbp_file(
|
||||
TARGET ${APP}
|
||||
TITLE SDL-${APP}
|
||||
ICON_PATH NULL
|
||||
BACKGROUND_PATH NULL
|
||||
PREVIEW_PATH NULL
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${APP} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory
|
||||
$<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${APP} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E rename
|
||||
$<TARGET_FILE_DIR:${ARG_TARGET}>/EBOOT.PBP
|
||||
$<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/EBOOT.PBP
|
||||
)
|
||||
if(${BUILD_PRX})
|
||||
add_custom_command(
|
||||
TARGET ${APP} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E copy
|
||||
$<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}
|
||||
$<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}
|
||||
)
|
||||
add_custom_command(
|
||||
TARGET ${APP} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E rename
|
||||
$<TARGET_FILE_DIR:${ARG_TARGET}>/${APP}.prx
|
||||
$<TARGET_FILE_DIR:${ARG_TARGET}>/sdl-${APP}/${APP}.prx
|
||||
)
|
||||
endif()
|
||||
add_custom_command(
|
||||
TARGET ${APP} POST_BUILD
|
||||
COMMAND ${CMAKE_COMMAND} -E remove
|
||||
$<TARGET_FILE_DIR:${ARG_TARGET}>/PARAM.SFO
|
||||
)
|
||||
endforeach()
|
||||
endif()
|
||||
|
||||
set(NEEDS_RESOURCES
|
||||
testscale
|
||||
testrendercopyex
|
||||
controllermap
|
||||
testyuv
|
||||
testgamecontroller
|
||||
testshape
|
||||
testshader
|
||||
testnative
|
||||
testspriteminimal
|
||||
testautomation
|
||||
testcustomcursor
|
||||
testrendertarget
|
||||
testsprite2
|
||||
loopwave
|
||||
loopwavequeue
|
||||
testresample
|
||||
testaudiohotplug
|
||||
testmultiaudio
|
||||
)
|
||||
foreach(APP IN LISTS NEEDS_RESOURCES)
|
||||
add_dependencies(${APP} SDL2_test_resoureces)
|
||||
foreach(RESOURCE_FILE ${RESOURCE_FILES})
|
||||
if(PSP)
|
||||
add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>/sdl-${APP})
|
||||
else()
|
||||
add_custom_command(TARGET ${APP} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${RESOURCE_FILE} $<TARGET_FILE_DIR:${APP}>)
|
||||
endif()
|
||||
endforeach(RESOURCE_FILE)
|
||||
if(APPLE)
|
||||
# Make sure resource files get installed into macOS/iOS .app bundles.
|
||||
target_sources(${APP} PRIVATE "${RESOURCE_FILES}")
|
||||
|
||||
@@ -9,6 +9,7 @@ LIBS = @LIBS@
|
||||
|
||||
TARGETS = \
|
||||
checkkeys$(EXE) \
|
||||
checkkeysthreads$(EXE) \
|
||||
controllermap$(EXE) \
|
||||
loopwave$(EXE) \
|
||||
loopwavequeue$(EXE) \
|
||||
@@ -28,6 +29,7 @@ TARGETS = \
|
||||
testfile$(EXE) \
|
||||
testfilesystem$(EXE) \
|
||||
testgamecontroller$(EXE) \
|
||||
testgeometry$(EXE) \
|
||||
testgesture$(EXE) \
|
||||
testhaptic$(EXE) \
|
||||
testhittesting$(EXE) \
|
||||
@@ -41,6 +43,7 @@ TARGETS = \
|
||||
testlocale$(EXE) \
|
||||
testlock$(EXE) \
|
||||
testmessage$(EXE) \
|
||||
testmouse$(EXE) \
|
||||
testmultiaudio$(EXE) \
|
||||
testnative$(EXE) \
|
||||
testoverlay2$(EXE) \
|
||||
@@ -59,6 +62,7 @@ TARGETS = \
|
||||
testsprite2$(EXE) \
|
||||
testspriteminimal$(EXE) \
|
||||
teststreaming$(EXE) \
|
||||
testsurround$(EXE) \
|
||||
testthread$(EXE) \
|
||||
testtimer$(EXE) \
|
||||
testurl$(EXE) \
|
||||
@@ -69,7 +73,7 @@ TARGETS = \
|
||||
testyuv$(EXE) \
|
||||
torturethread$(EXE) \
|
||||
|
||||
|
||||
|
||||
@OPENGL_TARGETS@ += testgl2$(EXE) testshader$(EXE)
|
||||
@OPENGLES1_TARGETS@ += testgles$(EXE)
|
||||
@OPENGLES2_TARGETS@ += testgles2$(EXE)
|
||||
@@ -83,12 +87,18 @@ Makefile: $(srcdir)/Makefile.in
|
||||
checkkeys$(EXE): $(srcdir)/checkkeys.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
checkkeysthreads$(EXE): $(srcdir)/checkkeysthreads.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
loopwave$(EXE): $(srcdir)/loopwave.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
loopwavequeue$(EXE): $(srcdir)/loopwavequeue.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testsurround$(EXE): $(srcdir)/testsurround.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testresample$(EXE): $(srcdir)/testresample.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
@@ -157,7 +167,10 @@ testfile$(EXE): $(srcdir)/testfile.c
|
||||
|
||||
testgamecontroller$(EXE): $(srcdir)/testgamecontroller.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
|
||||
testgeometry$(EXE): $(srcdir)/testgeometry.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
testgesture$(EXE): $(srcdir)/testgesture.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
@@ -170,6 +183,9 @@ testgles$(EXE): $(srcdir)/testgles.c
|
||||
testgles2$(EXE): $(srcdir)/testgles2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
testgles2_sdf$(EXE): $(srcdir)/testgles2_sdf.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @MATHLIB@
|
||||
|
||||
testhaptic$(EXE): $(srcdir)/testhaptic.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
@@ -219,14 +235,22 @@ testnative$(EXE): $(srcdir)/testnative.c \
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS) @XLIB@
|
||||
endif
|
||||
|
||||
ifeq (@ISOS2@,true)
|
||||
testnative$(EXE): $(srcdir)/testnative.c \
|
||||
$(srcdir)/testnativeos2.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
endif
|
||||
|
||||
#there's probably a better way of doing this
|
||||
ifeq (@ISMACOSX@,false)
|
||||
ifeq (@ISWINDOWS@,false)
|
||||
ifeq (@ISUNIX@,false)
|
||||
ifeq (@ISOS2@,false)
|
||||
testnative$(EXE): ;
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
testoverlay2$(EXE): $(srcdir)/testoverlay2.c $(srcdir)/testyuv_cvt.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
@@ -315,6 +339,8 @@ testvulkan$(EXE): $(srcdir)/testvulkan.c
|
||||
testlocale$(EXE): $(srcdir)/testlocale.c
|
||||
$(CC) -o $@ $? $(CFLAGS) $(LIBS)
|
||||
|
||||
testmouse$(EXE): $(srcdir)/testmouse.c
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LIBS)
|
||||
|
||||
|
||||
clean:
|
||||
@@ -325,26 +351,26 @@ distclean: clean
|
||||
rm -f config.status config.cache config.log
|
||||
rm -rf $(srcdir)/autom4te*
|
||||
|
||||
DATA = \
|
||||
axis.bmp \
|
||||
button.bmp \
|
||||
controllermap.bmp \
|
||||
controllermap_back.bmp \
|
||||
icon.bmp \
|
||||
moose.dat \
|
||||
sample.bmp \
|
||||
sample.wav \
|
||||
testgles2_sdf_img_normal.bmp \
|
||||
testgles2_sdf_img_sdf.bmp \
|
||||
testyuv.bmp \
|
||||
unifont-13.0.06.hex \
|
||||
utf8.txt \
|
||||
$(NULL)
|
||||
|
||||
ifneq ($(srcdir), .)
|
||||
%.bmp: $(srcdir)/%.bmp
|
||||
cp $< $@
|
||||
|
||||
%.wav: $(srcdir)/%.wav
|
||||
cp $< $@
|
||||
|
||||
%.dat: $(srcdir)/%.dat
|
||||
$(DATA) : %: $(srcdir)/% Makefile
|
||||
cp $< $@
|
||||
endif
|
||||
|
||||
copydatafiles: copybmpfiles copywavfiles copydatfiles
|
||||
copydatafiles: $(DATA)
|
||||
.PHONY : copydatafiles
|
||||
|
||||
copybmpfiles: $(foreach bmp,$(wildcard $(srcdir)/*.bmp),$(notdir $(bmp)))
|
||||
.PHONY : copybmpfiles
|
||||
|
||||
copywavfiles: $(foreach wav,$(wildcard $(srcdir)/*.wav),$(notdir $(wav)))
|
||||
.PHONY : copywavfiles
|
||||
|
||||
copydatfiles: $(foreach dat,$(wildcard $(srcdir)/*.dat),$(notdir $(dat)))
|
||||
.PHONY : copydatfiles
|
||||
|
||||
|
||||
@@ -1,8 +1,20 @@
|
||||
BINPATH = .
|
||||
# Open Watcom makefile to build SDL2 tests for OS/2
|
||||
# wmake -f Makefile.os2
|
||||
|
||||
INCPATH = -I"$(%WATCOM)/h/os2" -I"$(%WATCOM)/h" -I"../include"
|
||||
|
||||
CFLAGS = $(INCPATH) -bt=os2 -d0 -q -bm -5s -fp5 -fpi87 -sg -oteanbmier -ei
|
||||
CFLAGS+= -wx -wcd=303
|
||||
|
||||
LIBPATH = ..
|
||||
LIBS = SDL2.lib SDL2test.lib
|
||||
|
||||
#CFLAGS+= -DHAVE_SDL_TTF
|
||||
#TTFLIBS = SDL2ttf.lib
|
||||
|
||||
TARGETS = testatomic.exe testdisplayinfo.exe testbounds.exe testdraw2.exe &
|
||||
testdrawchessboard.exe testdropfile.exe testerror.exe testfile.exe &
|
||||
testfilesystem.exe testgamecontroller.exe testgesture.exe &
|
||||
testfilesystem.exe testgamecontroller.exe testgeometry.exe testgesture.exe &
|
||||
testhittesting.exe testhotplug.exe testiconv.exe testime.exe testlocale.exe &
|
||||
testintersections.exe testjoystick.exe testkeys.exe testloadso.exe &
|
||||
testlock.exe testmessage.exe testoverlay2.exe testplatform.exe &
|
||||
@@ -11,21 +23,13 @@ TARGETS = testatomic.exe testdisplayinfo.exe testbounds.exe testdraw2.exe &
|
||||
testshader.exe testshape.exe testsprite2.exe testspriteminimal.exe &
|
||||
teststreaming.exe testthread.exe testtimer.exe testver.exe &
|
||||
testviewport.exe testwm2.exe torturethread.exe checkkeys.exe &
|
||||
checkkeysthreads.exe testmouse.exe &
|
||||
controllermap.exe testhaptic.exe testqsort.exe testresample.exe &
|
||||
testaudioinfo.exe testaudiocapture.exe loopwave.exe loopwavequeue.exe &
|
||||
testyuv.exe testgl2.exe testvulkan.exe testnative.exe testautomation.exe
|
||||
|
||||
# SDL2test.lib sources (../src/test)
|
||||
|
||||
CSRCS = SDL_test_assert.c SDL_test_common.c SDL_test_compare.c &
|
||||
SDL_test_crc32.c SDL_test_font.c SDL_test_fuzzer.c SDL_test_harness.c &
|
||||
SDL_test_imageBlit.c SDL_test_imageBlitBlend.c SDL_test_imageFace.c &
|
||||
SDL_test_imagePrimitives.c SDL_test_imagePrimitivesBlend.c &
|
||||
SDL_test_log.c SDL_test_md5.c SDL_test_random.c SDL_test_memory.c
|
||||
TESTLIB = SDL2test.lib
|
||||
testsurround.exe testyuv.exe testgl2.exe testvulkan.exe testnative.exe &
|
||||
testautomation.exe
|
||||
|
||||
# testautomation sources
|
||||
|
||||
TASRCS = testautomation.c testautomation_audio.c testautomation_clipboard.c &
|
||||
testautomation_events.c testautomation_hints.c &
|
||||
testautomation_keyboard.c testautomation_main.c &
|
||||
@@ -42,23 +46,9 @@ TAOBJS = $(TASRCS:.c=.obj)
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
INCPATH = -I$(%WATCOM)/h/os2 -I$(%WATCOM)/h -I../include
|
||||
|
||||
CFLAGS = $(INCPATH) -bt=os2 -d0 -q -bm -5s -fp5 -fpi87 -sg -oteanbmier -ei
|
||||
|
||||
LIBPATH = ..
|
||||
LIBS = SDL2.lib $(TESTLIB)
|
||||
|
||||
#CFLAGS+= -DHAVE_SDL_TTF
|
||||
#LIBS_TTF = SDL2ttf.lib
|
||||
|
||||
.c: ../src/test
|
||||
|
||||
$(TESTLIB): $(COBJS)
|
||||
wlib -q -b -n -c $@ $(COBJS)
|
||||
|
||||
.obj.exe:
|
||||
@%make $(TESTLIB)
|
||||
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
|
||||
|
||||
.c.obj:
|
||||
@@ -66,30 +56,22 @@ $(TESTLIB): $(COBJS)
|
||||
|
||||
# specials
|
||||
testautomation.exe: $(TAOBJS)
|
||||
@%make $(TESTLIB)
|
||||
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
|
||||
|
||||
testnative.exe: testnative.obj testnativeos2.obj
|
||||
@%make $(TESTLIB)
|
||||
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
|
||||
|
||||
testoverlay2.exe: testoverlay2.obj testyuv_cvt.obj
|
||||
@%make $(TESTLIB)
|
||||
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
|
||||
|
||||
testyuv.exe: testyuv.obj testyuv_cvt.obj
|
||||
@%make $(TESTLIB)
|
||||
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS)} op q op el file {$<} name $@
|
||||
|
||||
testime.exe: testime.obj
|
||||
@%make $(TESTLIB)
|
||||
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS) $(LIBS_TTF)} op q op el file {$<} name $@
|
||||
wlink SYS os2v2 libpath $(LIBPATH) lib {$(LIBS) $(TTFLIBS)} op q op el file {$<} name $@
|
||||
|
||||
clean: .SYMBOLIC
|
||||
@echo * Clean tests in $(BINPATH)
|
||||
@if exist *.obj rm *.obj
|
||||
@if exist *.err rm *.err
|
||||
|
||||
distclean: .SYMBOLIC clean
|
||||
@if exist *.exe rm *.exe
|
||||
@if exist $(TESTLIB) rm $(TESTLIB)
|
||||
|
||||
@@ -4,6 +4,7 @@ These are test programs for the SDL library:
|
||||
checkkeys Watch the key events to check the keyboard
|
||||
loopwave Audio test -- loop playing a WAV file
|
||||
loopwavequeue Audio test -- loop playing a WAV file with SDL_QueueAudio
|
||||
testsurround Audio test -- play test tone on each audio channel
|
||||
testaudioinfo Lists audio device capabilities
|
||||
testerror Tests multi-threaded error handling
|
||||
testfile Tests RWops layer
|
||||
@@ -14,6 +15,7 @@ These are test programs for the SDL library:
|
||||
testloadso Tests the loadable library layer
|
||||
testlocale Test Locale API
|
||||
testlock Hacked up test of multi-threading and locking
|
||||
testmouse Tests mouse coordinates
|
||||
testmultiaudio Tests using several audio devices
|
||||
testoverlay2 Tests the overlay flickering/scaling during playback.
|
||||
testplatform Tests types, endianness and cpu capabilities
|
||||
|
||||
@@ -5,13 +5,13 @@
|
||||
# stolen from Manish Singh
|
||||
# Shamelessly stolen from Owen Taylor
|
||||
|
||||
# serial 1
|
||||
# serial 2
|
||||
|
||||
dnl AM_PATH_SDL2([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
|
||||
dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
|
||||
dnl
|
||||
AC_DEFUN([AM_PATH_SDL2],
|
||||
[dnl
|
||||
[dnl
|
||||
dnl Get the cflags and libraries from the sdl2-config script
|
||||
dnl
|
||||
AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)],
|
||||
@@ -80,41 +80,19 @@ dnl Now check if the installed SDL is sufficiently new. (Also sanity
|
||||
dnl checks the results of sdl2-config to some extent
|
||||
dnl
|
||||
rm -f conf.sdltest
|
||||
AC_TRY_RUN([
|
||||
AC_RUN_IFELSE([AC_LANG_SOURCE([[
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "SDL.h"
|
||||
|
||||
char*
|
||||
my_strdup (char *str)
|
||||
{
|
||||
char *new_str;
|
||||
|
||||
if (str)
|
||||
{
|
||||
new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
|
||||
strcpy (new_str, str);
|
||||
}
|
||||
else
|
||||
new_str = NULL;
|
||||
|
||||
return new_str;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int major, minor, micro;
|
||||
char *tmp_version;
|
||||
FILE *fp = fopen("conf.sdltest", "w");
|
||||
|
||||
/* This hangs on some systems (?)
|
||||
system ("touch conf.sdltest");
|
||||
*/
|
||||
{ FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
|
||||
if (fp) fclose(fp);
|
||||
|
||||
/* HP/UX 9 (%@#!) writes to sscanf strings */
|
||||
tmp_version = my_strdup("$min_sdl_version");
|
||||
if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) {
|
||||
if (sscanf("$min_sdl_version", "%d.%d.%d", &major, &minor, µ) != 3) {
|
||||
printf("%s, bad version string\n", "$min_sdl_version");
|
||||
exit(1);
|
||||
}
|
||||
@@ -137,7 +115,7 @@ int main (int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
|
||||
]])], [], [no_sdl=yes], [echo $ac_n "cross compiling; assumed OK... $ac_c"])
|
||||
CFLAGS="$ac_save_CFLAGS"
|
||||
CXXFLAGS="$ac_save_CXXFLAGS"
|
||||
LIBS="$ac_save_LIBS"
|
||||
@@ -165,7 +143,7 @@ int main (int argc, char *argv[])
|
||||
CFLAGS="$CFLAGS $SDL_CFLAGS"
|
||||
CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
|
||||
LIBS="$LIBS $SDL_LIBS"
|
||||
AC_TRY_LINK([
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include <stdio.h>
|
||||
#include "SDL.h"
|
||||
|
||||
@@ -173,7 +151,7 @@ int main(int argc, char *argv[])
|
||||
{ return 0; }
|
||||
#undef main
|
||||
#define main K_and_R_C_main
|
||||
], [ return 0; ],
|
||||
]], [[ return 0; ]])],
|
||||
[ echo "*** The test program compiled, but did not run. This usually means"
|
||||
echo "*** that the run-time linker is not finding SDL or finding the wrong"
|
||||
echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
|
||||
@@ -228,7 +206,7 @@ int main(int argc, char *argv[])
|
||||
# ----------------------------------
|
||||
AC_DEFUN([PKG_PROG_PKG_CONFIG],
|
||||
[m4_pattern_forbid([^_?PKG_[A-Z_]+$])
|
||||
m4_pattern_allow([^PKG_CONFIG(_PATH)?$])
|
||||
m4_pattern_allow([^PKG_CONFIG(_PATH|_LIBDIR)?$])
|
||||
AC_ARG_VAR([PKG_CONFIG], [path to pkg-config utility])
|
||||
AC_ARG_VAR([PKG_CONFIG_PATH], [directories to add to pkg-config's search path])
|
||||
AC_ARG_VAR([PKG_CONFIG_LIBDIR], [path overriding pkg-config's built-in search path])
|
||||
@@ -309,7 +287,7 @@ AC_ARG_VAR([$1][_CFLAGS], [C compiler flags for $1, overriding pkg-config])dnl
|
||||
AC_ARG_VAR([$1][_LIBS], [linker flags for $1, overriding pkg-config])dnl
|
||||
|
||||
pkg_failed=no
|
||||
AC_MSG_CHECKING([for $1])
|
||||
AC_MSG_CHECKING([for $2])
|
||||
|
||||
_PKG_CONFIG([$1][_CFLAGS], [cflags], [$2])
|
||||
_PKG_CONFIG([$1][_LIBS], [libs], [$2])
|
||||
@@ -337,7 +315,7 @@ $$1_PKG_ERRORS
|
||||
Consider adjusting the PKG_CONFIG_PATH environment variable if you
|
||||
installed software in a non-standard prefix.
|
||||
|
||||
_PKG_TEXT])dnl
|
||||
_PKG_TEXT])[]dnl
|
||||
])
|
||||
elif test $pkg_failed = untried; then
|
||||
AC_MSG_RESULT([no])
|
||||
@@ -348,7 +326,7 @@ path to pkg-config.
|
||||
|
||||
_PKG_TEXT
|
||||
|
||||
To get pkg-config, see <http://pkg-config.freedesktop.org/>.])dnl
|
||||
To get pkg-config, see <http://pkg-config.freedesktop.org/>.])[]dnl
|
||||
])
|
||||
else
|
||||
$1[]_CFLAGS=$pkg_cv_[]$1[]_CFLAGS
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Regenerate configuration files
|
||||
|
||||
cp acinclude.m4 aclocal.m4
|
||||
found=false
|
||||
for autoconf in autoconf autoconf259 autoconf-2.59
|
||||
do if which $autoconf >/dev/null 2>&1; then $autoconf && found=true; break; fi
|
||||
done
|
||||
if test x$found = xfalse; then
|
||||
echo "Couldn't find autoconf, aborting"
|
||||
exit 1
|
||||
|
||||
if test "$AUTOCONF"x = x; then
|
||||
AUTOCONF=autoconf
|
||||
fi
|
||||
|
||||
$AUTOCONF || exit 1
|
||||
rm aclocal.m4
|
||||
rm -rf autom4te.cache
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -86,6 +86,8 @@ print_modifiers(char **text, size_t *maxlen)
|
||||
print_string(text, maxlen, " CAPS");
|
||||
if (mod & KMOD_MODE)
|
||||
print_string(text, maxlen, " MODE");
|
||||
if (mod & KMOD_SCROLL)
|
||||
print_string(text, maxlen, " SCROLL");
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -135,9 +137,10 @@ PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
|
||||
}
|
||||
|
||||
static void
|
||||
PrintText(char *eventtype, char *text)
|
||||
PrintText(const char *eventtype, const char *text)
|
||||
{
|
||||
char *spot, expanded[1024];
|
||||
const char *spot;
|
||||
char expanded[1024];
|
||||
|
||||
expanded[0] = '\0';
|
||||
for ( spot = text; *spot; ++spot )
|
||||
@@ -199,6 +202,7 @@ int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
@@ -219,6 +223,12 @@ main(int argc, char *argv[])
|
||||
quit(2);
|
||||
}
|
||||
|
||||
/* On wayland, no window will actually show until something has
|
||||
actually been displayed.
|
||||
*/
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
#if __IPHONEOS__
|
||||
/* Creating the context creates the view, which we need to show keyboard */
|
||||
SDL_GL_CreateContext(window);
|
||||
|
||||
285
test/checkkeysthreads.c
Normal file
285
test/checkkeysthreads.c
Normal file
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
Copyright (C) 1997-2022 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.
|
||||
*/
|
||||
|
||||
/* Simple program: Loop, watching keystrokes
|
||||
Note that you need to call SDL_PollEvent() or SDL_WaitEvent() to
|
||||
pump the event loop and catch keystrokes.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
int done;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDL_Quit();
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
static void
|
||||
print_string(char **text, size_t *maxlen, const char *fmt, ...)
|
||||
{
|
||||
int len;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
len = SDL_vsnprintf(*text, *maxlen, fmt, ap);
|
||||
if (len > 0) {
|
||||
*text += len;
|
||||
if ( ((size_t) len) < *maxlen ) {
|
||||
*maxlen -= (size_t) len;
|
||||
} else {
|
||||
*maxlen = 0;
|
||||
}
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
static void
|
||||
print_modifiers(char **text, size_t *maxlen)
|
||||
{
|
||||
int mod;
|
||||
print_string(text, maxlen, " modifiers:");
|
||||
mod = SDL_GetModState();
|
||||
if (!mod) {
|
||||
print_string(text, maxlen, " (none)");
|
||||
return;
|
||||
}
|
||||
if (mod & KMOD_LSHIFT)
|
||||
print_string(text, maxlen, " LSHIFT");
|
||||
if (mod & KMOD_RSHIFT)
|
||||
print_string(text, maxlen, " RSHIFT");
|
||||
if (mod & KMOD_LCTRL)
|
||||
print_string(text, maxlen, " LCTRL");
|
||||
if (mod & KMOD_RCTRL)
|
||||
print_string(text, maxlen, " RCTRL");
|
||||
if (mod & KMOD_LALT)
|
||||
print_string(text, maxlen, " LALT");
|
||||
if (mod & KMOD_RALT)
|
||||
print_string(text, maxlen, " RALT");
|
||||
if (mod & KMOD_LGUI)
|
||||
print_string(text, maxlen, " LGUI");
|
||||
if (mod & KMOD_RGUI)
|
||||
print_string(text, maxlen, " RGUI");
|
||||
if (mod & KMOD_NUM)
|
||||
print_string(text, maxlen, " NUM");
|
||||
if (mod & KMOD_CAPS)
|
||||
print_string(text, maxlen, " CAPS");
|
||||
if (mod & KMOD_MODE)
|
||||
print_string(text, maxlen, " MODE");
|
||||
if (mod & KMOD_SCROLL)
|
||||
print_string(text, maxlen, " SCROLL");
|
||||
}
|
||||
|
||||
static void
|
||||
PrintModifierState()
|
||||
{
|
||||
char message[512];
|
||||
char *spot;
|
||||
size_t left;
|
||||
|
||||
spot = message;
|
||||
left = sizeof(message);
|
||||
|
||||
print_modifiers(&spot, &left);
|
||||
SDL_Log("Initial state:%s\n", message);
|
||||
}
|
||||
|
||||
static void
|
||||
PrintKey(SDL_Keysym * sym, SDL_bool pressed, SDL_bool repeat)
|
||||
{
|
||||
char message[512];
|
||||
char *spot;
|
||||
size_t left;
|
||||
|
||||
spot = message;
|
||||
left = sizeof(message);
|
||||
|
||||
/* Print the keycode, name and state */
|
||||
if (sym->sym) {
|
||||
print_string(&spot, &left,
|
||||
"Key %s: scancode %d = %s, keycode 0x%08X = %s ",
|
||||
pressed ? "pressed " : "released",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
sym->sym, SDL_GetKeyName(sym->sym));
|
||||
} else {
|
||||
print_string(&spot, &left,
|
||||
"Unknown Key (scancode %d = %s) %s ",
|
||||
sym->scancode,
|
||||
SDL_GetScancodeName(sym->scancode),
|
||||
pressed ? "pressed " : "released");
|
||||
}
|
||||
print_modifiers(&spot, &left);
|
||||
if (repeat) {
|
||||
print_string(&spot, &left, " (repeat)");
|
||||
}
|
||||
SDL_Log("%s\n", message);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
static void
|
||||
PrintText(const char *eventtype, const char *text)
|
||||
{
|
||||
const char *spot;
|
||||
char expanded[1024];
|
||||
|
||||
expanded[0] = '\0';
|
||||
for ( spot = text; *spot; ++spot )
|
||||
{
|
||||
size_t length = SDL_strlen(expanded);
|
||||
SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", (unsigned char)*spot);
|
||||
}
|
||||
SDL_Log("%s Text (%s): \"%s%s\"\n", eventtype, expanded, *text == '"' ? "\\" : "", text);
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
/* Check for events */
|
||||
/*SDL_WaitEvent(&event); emscripten does not like waiting*/
|
||||
|
||||
fprintf(stderr, "starting loop\n"); fflush(stderr);
|
||||
// while (SDL_PollEvent(&event)) {
|
||||
while (!done && SDL_WaitEvent(&event)) {
|
||||
fprintf(stderr, "got event type: %d\n", event.type); fflush(stderr);
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
PrintKey(&event.key.keysym, (event.key.state == SDL_PRESSED) ? SDL_TRUE : SDL_FALSE, (event.key.repeat) ? SDL_TRUE : SDL_FALSE);
|
||||
break;
|
||||
case SDL_TEXTEDITING:
|
||||
PrintText("EDIT", event.text.text);
|
||||
break;
|
||||
case SDL_TEXTINPUT:
|
||||
PrintText("INPUT", event.text.text);
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Left button quits the app, other buttons toggles text input */
|
||||
fprintf(stderr, "mouse button down button: %d (LEFT=%d)\n", event.button.button, SDL_BUTTON_LEFT); fflush(stderr);
|
||||
if (event.button.button == SDL_BUTTON_LEFT) {
|
||||
done = 1;
|
||||
} else {
|
||||
if (SDL_IsTextInputActive()) {
|
||||
SDL_Log("Stopping text input\n");
|
||||
SDL_StopTextInput();
|
||||
} else {
|
||||
SDL_Log("Starting text input\n");
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
done = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
fprintf(stderr, "waiting new event\n"); fflush(stderr);
|
||||
}
|
||||
fprintf(stderr, "exiting event loop\n"); fflush(stderr);
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (done) {
|
||||
emscripten_cancel_main_loop();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Very simple thread - counts 0 to 9 delaying 50ms between increments */
|
||||
static int SDLCALL ping_thread(void *ptr)
|
||||
{
|
||||
int cnt;
|
||||
SDL_Event sdlevent;
|
||||
SDL_memset(&sdlevent, 0 , sizeof(SDL_Event));
|
||||
for (cnt = 0; cnt < 10; ++cnt) {
|
||||
fprintf(stderr, "sending event (%d/%d) from thread.\n", cnt + 1, 10); fflush(stderr);
|
||||
sdlevent.type = SDL_KEYDOWN;
|
||||
sdlevent.key.keysym.sym = SDLK_1;
|
||||
SDL_PushEvent(&sdlevent);
|
||||
SDL_Delay(1000 + rand() % 1000);
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Thread *thread;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize SDL */
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Set 640x480 video mode */
|
||||
window = SDL_CreateWindow("CheckKeys Test",
|
||||
SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||
640, 480, 0);
|
||||
if (!window) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create 640x480 window: %s\n",
|
||||
SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
|
||||
/* On wayland, no window will actually show until something has
|
||||
actually been displayed.
|
||||
*/
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
#if __IPHONEOS__
|
||||
/* Creating the context creates the view, which we need to show keyboard */
|
||||
SDL_GL_CreateContext(window);
|
||||
#endif
|
||||
|
||||
SDL_StartTextInput();
|
||||
|
||||
/* Print initial modifier state */
|
||||
SDL_PumpEvents();
|
||||
PrintModifierState();
|
||||
|
||||
/* Watch keystrokes */
|
||||
done = 0;
|
||||
|
||||
thread = SDL_CreateThread(ping_thread, "PingThread", (void *)NULL);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_WaitThread(thread, NULL);
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
282
test/configure
vendored
282
test/configure
vendored
@@ -581,9 +581,11 @@ PACKAGE_STRING=
|
||||
PACKAGE_BUGREPORT=
|
||||
PACKAGE_URL=
|
||||
|
||||
ac_unique_file="README"
|
||||
ac_unique_file="loopwave.c"
|
||||
ac_subst_vars='LTLIBOBJS
|
||||
LIBOBJS
|
||||
LIBUNWIND_LIBS
|
||||
LIBUNWIND_CFLAGS
|
||||
SDL_TTF_LIB
|
||||
XLIB
|
||||
GLES2LIB
|
||||
@@ -600,6 +602,7 @@ SDL_CFLAGS
|
||||
PKG_CONFIG_LIBDIR
|
||||
PKG_CONFIG_PATH
|
||||
PKG_CONFIG
|
||||
ISOS2
|
||||
ISUNIX
|
||||
ISWINDOWS
|
||||
ISMACOSX
|
||||
@@ -682,7 +685,9 @@ PKG_CONFIG_LIBDIR
|
||||
SDL_CFLAGS
|
||||
SDL_LIBS
|
||||
XMKMF
|
||||
CPP'
|
||||
CPP
|
||||
LIBUNWIND_CFLAGS
|
||||
LIBUNWIND_LIBS'
|
||||
|
||||
|
||||
# Initialize some variables set by options.
|
||||
@@ -1335,6 +1340,10 @@ Some influential environment variables:
|
||||
SDL_LIBS linker flags for SDL, overriding pkg-config
|
||||
XMKMF Path to xmkmf, Makefile generator for X Window System
|
||||
CPP C preprocessor
|
||||
LIBUNWIND_CFLAGS
|
||||
C compiler flags for LIBUNWIND, overriding pkg-config
|
||||
LIBUNWIND_LIBS
|
||||
linker flags for LIBUNWIND, overriding pkg-config
|
||||
|
||||
Use these variables to override the choices made by `configure' or to help
|
||||
it to find libraries and programs with nonstandard names/locations.
|
||||
@@ -1454,48 +1463,6 @@ fi
|
||||
|
||||
} # ac_fn_c_try_compile
|
||||
|
||||
# ac_fn_c_try_run LINENO
|
||||
# ----------------------
|
||||
# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
|
||||
# that executables *can* be run.
|
||||
ac_fn_c_try_run ()
|
||||
{
|
||||
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
|
||||
if { { ac_try="$ac_link"
|
||||
case "(($ac_try" in
|
||||
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||
*) ac_try_echo=$ac_try;;
|
||||
esac
|
||||
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
|
||||
$as_echo "$ac_try_echo"; } >&5
|
||||
(eval "$ac_link") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
|
||||
{ { case "(($ac_try" in
|
||||
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||
*) ac_try_echo=$ac_try;;
|
||||
esac
|
||||
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
|
||||
$as_echo "$ac_try_echo"; } >&5
|
||||
(eval "$ac_try") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; }; }; then :
|
||||
ac_retval=0
|
||||
else
|
||||
$as_echo "$as_me: program exited with status $ac_status" >&5
|
||||
$as_echo "$as_me: failed program was:" >&5
|
||||
sed 's/^/| /' conftest.$ac_ext >&5
|
||||
|
||||
ac_retval=$ac_status
|
||||
fi
|
||||
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
|
||||
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
|
||||
as_fn_set_status $ac_retval
|
||||
|
||||
} # ac_fn_c_try_run
|
||||
|
||||
# ac_fn_c_try_link LINENO
|
||||
# -----------------------
|
||||
# Try to link conftest.$ac_ext, and return whether this succeeded.
|
||||
@@ -1542,6 +1509,48 @@ fi
|
||||
|
||||
} # ac_fn_c_try_link
|
||||
|
||||
# ac_fn_c_try_run LINENO
|
||||
# ----------------------
|
||||
# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
|
||||
# that executables *can* be run.
|
||||
ac_fn_c_try_run ()
|
||||
{
|
||||
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
|
||||
if { { ac_try="$ac_link"
|
||||
case "(($ac_try" in
|
||||
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||
*) ac_try_echo=$ac_try;;
|
||||
esac
|
||||
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
|
||||
$as_echo "$ac_try_echo"; } >&5
|
||||
(eval "$ac_link") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
|
||||
{ { case "(($ac_try" in
|
||||
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
|
||||
*) ac_try_echo=$ac_try;;
|
||||
esac
|
||||
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
|
||||
$as_echo "$ac_try_echo"; } >&5
|
||||
(eval "$ac_try") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; }; }; then :
|
||||
ac_retval=0
|
||||
else
|
||||
$as_echo "$as_me: program exited with status $ac_status" >&5
|
||||
$as_echo "$as_me: failed program was:" >&5
|
||||
sed 's/^/| /' conftest.$ac_ext >&5
|
||||
|
||||
ac_retval=$ac_status
|
||||
fi
|
||||
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
|
||||
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
|
||||
as_fn_set_status $ac_retval
|
||||
|
||||
} # ac_fn_c_try_run
|
||||
|
||||
# ac_fn_c_try_cpp LINENO
|
||||
# ----------------------
|
||||
# Try to preprocess conftest.$ac_ext, and return whether this succeeded.
|
||||
@@ -1933,7 +1942,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
|
||||
|
||||
|
||||
ac_aux_dir=
|
||||
for ac_dir in $srcdir/../build-scripts; do
|
||||
for ac_dir in ../build-scripts "$srcdir"/../build-scripts; do
|
||||
if test -f "$ac_dir/install-sh"; then
|
||||
ac_aux_dir=$ac_dir
|
||||
ac_install_sh="$ac_aux_dir/install-sh -c"
|
||||
@@ -1949,7 +1958,7 @@ for ac_dir in $srcdir/../build-scripts; do
|
||||
fi
|
||||
done
|
||||
if test -z "$ac_aux_dir"; then
|
||||
as_fn_error $? "cannot find install-sh, install.sh, or shtool in $srcdir/../build-scripts" "$LINENO" 5
|
||||
as_fn_error $? "cannot find install-sh, install.sh, or shtool in ../build-scripts \"$srcdir\"/../build-scripts" "$LINENO" 5
|
||||
fi
|
||||
|
||||
# These three variables are undocumented and unsupported,
|
||||
@@ -2909,9 +2918,10 @@ fi
|
||||
ISUNIX="false"
|
||||
ISWINDOWS="false"
|
||||
ISMACOSX="false"
|
||||
ISOS2="false"
|
||||
|
||||
case "$host" in
|
||||
*-*-cygwin* | *-*-mingw32*)
|
||||
*-*-cygwin* | *-*-mingw*)
|
||||
ISWINDOWS="true"
|
||||
EXE=".exe"
|
||||
MATHLIB=""
|
||||
@@ -2922,7 +2932,7 @@ case "$host" in
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lGL"
|
||||
;;
|
||||
*-*-darwin* )
|
||||
*-*-darwin*)
|
||||
ISMACOSX="true"
|
||||
EXE=""
|
||||
MATHLIB=""
|
||||
@@ -2994,21 +3004,68 @@ fi
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lGLES_CM"
|
||||
;;
|
||||
*-*-emscripten* )
|
||||
*-*-emscripten*)
|
||||
EXE=".bc"
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS=""
|
||||
;;
|
||||
*-*-riscos* )
|
||||
*-*-riscos*)
|
||||
EXE=",e1f"
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS=""
|
||||
;;
|
||||
*-*-os2*)
|
||||
ISOS2="true"
|
||||
EXE=".exe"
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS=""
|
||||
;;
|
||||
*)
|
||||
ISUNIX="true"
|
||||
EXE=""
|
||||
MATHLIB="-lm"
|
||||
SYS_GL_LIBS="-lGL"
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for glBegin in -lOpenGL" >&5
|
||||
$as_echo_n "checking for glBegin in -lOpenGL... " >&6; }
|
||||
if ${ac_cv_lib_OpenGL_glBegin+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
ac_check_lib_save_LIBS=$LIBS
|
||||
LIBS="-lOpenGL $LIBS"
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
/* Override any GCC internal prototype to avoid an error.
|
||||
Use char because int might match the return type of a GCC
|
||||
builtin and then its argument prototype would still apply. */
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
char glBegin ();
|
||||
int
|
||||
main ()
|
||||
{
|
||||
return glBegin ();
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
ac_cv_lib_OpenGL_glBegin=yes
|
||||
else
|
||||
ac_cv_lib_OpenGL_glBegin=no
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS=$ac_check_lib_save_LIBS
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_OpenGL_glBegin" >&5
|
||||
$as_echo "$ac_cv_lib_OpenGL_glBegin" >&6; }
|
||||
if test "x$ac_cv_lib_OpenGL_glBegin" = xyes; then :
|
||||
SYS_GL_LIBS="-lOpenGL"
|
||||
else
|
||||
SYS_GL_LIBS="-lGL"
|
||||
fi
|
||||
|
||||
;;
|
||||
esac
|
||||
|
||||
@@ -3017,7 +3074,8 @@ esac
|
||||
|
||||
|
||||
|
||||
SDL_VERSION=2.0.0
|
||||
|
||||
SDL_VERSION=2.0.18
|
||||
|
||||
|
||||
|
||||
@@ -3166,8 +3224,8 @@ fi
|
||||
if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
|
||||
|
||||
pkg_failed=no
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SDL" >&5
|
||||
$as_echo_n "checking for SDL... " >&6; }
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for sdl2 >= $min_sdl_version" >&5
|
||||
$as_echo_n "checking for sdl2 >= $min_sdl_version... " >&6; }
|
||||
|
||||
if test -n "$SDL_CFLAGS"; then
|
||||
pkg_cv_SDL_CFLAGS="$SDL_CFLAGS"
|
||||
@@ -3331,38 +3389,16 @@ else
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "SDL.h"
|
||||
|
||||
char*
|
||||
my_strdup (char *str)
|
||||
{
|
||||
char *new_str;
|
||||
|
||||
if (str)
|
||||
{
|
||||
new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
|
||||
strcpy (new_str, str);
|
||||
}
|
||||
else
|
||||
new_str = NULL;
|
||||
|
||||
return new_str;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
int major, minor, micro;
|
||||
char *tmp_version;
|
||||
FILE *fp = fopen("conf.sdltest", "w");
|
||||
|
||||
/* This hangs on some systems (?)
|
||||
system ("touch conf.sdltest");
|
||||
*/
|
||||
{ FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
|
||||
if (fp) fclose(fp);
|
||||
|
||||
/* HP/UX 9 (%@#!) writes to sscanf strings */
|
||||
tmp_version = my_strdup("$min_sdl_version");
|
||||
if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, µ) != 3) {
|
||||
if (sscanf("$min_sdl_version", "%d.%d.%d", &major, &minor, µ) != 3) {
|
||||
printf("%s, bad version string\n", "$min_sdl_version");
|
||||
exit(1);
|
||||
}
|
||||
@@ -3874,15 +3910,12 @@ int
|
||||
main ()
|
||||
{
|
||||
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
|
||||
have_opengl=yes
|
||||
|
||||
have_opengl=yes
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_opengl" >&5
|
||||
@@ -3903,15 +3936,12 @@ int
|
||||
main ()
|
||||
{
|
||||
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
|
||||
have_opengles=yes
|
||||
|
||||
have_opengles=yes
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_opengles" >&5
|
||||
@@ -3932,15 +3962,12 @@ int
|
||||
main ()
|
||||
{
|
||||
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_compile "$LINENO"; then :
|
||||
|
||||
have_opengles2=yes
|
||||
|
||||
have_opengles2=yes
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_opengles2" >&5
|
||||
@@ -4022,6 +4049,79 @@ if test x$have_SDL_ttf = xyes; then
|
||||
fi
|
||||
|
||||
|
||||
|
||||
pkg_failed=no
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libunwind" >&5
|
||||
$as_echo_n "checking for libunwind... " >&6; }
|
||||
|
||||
if test -n "$LIBUNWIND_CFLAGS"; then
|
||||
pkg_cv_LIBUNWIND_CFLAGS="$LIBUNWIND_CFLAGS"
|
||||
elif test -n "$PKG_CONFIG"; then
|
||||
if test -n "$PKG_CONFIG" && \
|
||||
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libunwind\""; } >&5
|
||||
($PKG_CONFIG --exists --print-errors "libunwind") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; }; then
|
||||
pkg_cv_LIBUNWIND_CFLAGS=`$PKG_CONFIG --cflags "libunwind" 2>/dev/null`
|
||||
else
|
||||
pkg_failed=yes
|
||||
fi
|
||||
else
|
||||
pkg_failed=untried
|
||||
fi
|
||||
if test -n "$LIBUNWIND_LIBS"; then
|
||||
pkg_cv_LIBUNWIND_LIBS="$LIBUNWIND_LIBS"
|
||||
elif test -n "$PKG_CONFIG"; then
|
||||
if test -n "$PKG_CONFIG" && \
|
||||
{ { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libunwind\""; } >&5
|
||||
($PKG_CONFIG --exists --print-errors "libunwind") 2>&5
|
||||
ac_status=$?
|
||||
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
|
||||
test $ac_status = 0; }; then
|
||||
pkg_cv_LIBUNWIND_LIBS=`$PKG_CONFIG --libs "libunwind" 2>/dev/null`
|
||||
else
|
||||
pkg_failed=yes
|
||||
fi
|
||||
else
|
||||
pkg_failed=untried
|
||||
fi
|
||||
|
||||
|
||||
|
||||
if test $pkg_failed = yes; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
|
||||
if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
|
||||
_pkg_short_errors_supported=yes
|
||||
else
|
||||
_pkg_short_errors_supported=no
|
||||
fi
|
||||
if test $_pkg_short_errors_supported = yes; then
|
||||
LIBUNWIND_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors "libunwind" 2>&1`
|
||||
else
|
||||
LIBUNWIND_PKG_ERRORS=`$PKG_CONFIG --print-errors "libunwind" 2>&1`
|
||||
fi
|
||||
# Put the nasty error message in config.log where it belongs
|
||||
echo "$LIBUNWIND_PKG_ERRORS" >&5
|
||||
|
||||
have_libunwind=no
|
||||
elif test $pkg_failed = untried; then
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
||||
$as_echo "no" >&6; }
|
||||
have_libunwind=no
|
||||
else
|
||||
LIBUNWIND_CFLAGS=$pkg_cv_LIBUNWIND_CFLAGS
|
||||
LIBUNWIND_LIBS=$pkg_cv_LIBUNWIND_LIBS
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
||||
$as_echo "yes" >&6; }
|
||||
have_libunwind=yes
|
||||
fi
|
||||
if test x$have_libunwind = xyes ; then
|
||||
LIBS="$LIBS $LIBUNWIND_LIBS"
|
||||
fi
|
||||
|
||||
ac_config_files="$ac_config_files Makefile"
|
||||
|
||||
cat >confcache <<\_ACEOF
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
dnl Process this file with autoconf to produce a configure script.
|
||||
AC_INIT
|
||||
AC_CONFIG_SRCDIR([README])
|
||||
AC_CONFIG_SRCDIR([loopwave.c])
|
||||
|
||||
dnl Detect the canonical build and host environments
|
||||
AC_CONFIG_AUX_DIRS($srcdir/../build-scripts)
|
||||
AC_CONFIG_AUX_DIR([../build-scripts])
|
||||
AC_CANONICAL_HOST
|
||||
|
||||
dnl Check for tools
|
||||
@@ -18,10 +18,11 @@ dnl (Haiku, for example, sets none of these.)
|
||||
ISUNIX="false"
|
||||
ISWINDOWS="false"
|
||||
ISMACOSX="false"
|
||||
ISOS2="false"
|
||||
|
||||
dnl Figure out which math library to use
|
||||
case "$host" in
|
||||
*-*-cygwin* | *-*-mingw32*)
|
||||
*-*-cygwin* | *-*-mingw*)
|
||||
ISWINDOWS="true"
|
||||
EXE=".exe"
|
||||
MATHLIB=""
|
||||
@@ -32,7 +33,7 @@ case "$host" in
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lGL"
|
||||
;;
|
||||
*-*-darwin* )
|
||||
*-*-darwin*)
|
||||
ISMACOSX="true"
|
||||
EXE=""
|
||||
MATHLIB=""
|
||||
@@ -64,23 +65,31 @@ case "$host" in
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS="-lGLES_CM"
|
||||
;;
|
||||
*-*-emscripten* )
|
||||
*-*-emscripten*)
|
||||
dnl This should really be .js, but we need to specify extra flags when compiling to js
|
||||
EXE=".bc"
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS=""
|
||||
;;
|
||||
*-*-riscos* )
|
||||
*-*-riscos*)
|
||||
EXE=",e1f"
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS=""
|
||||
;;
|
||||
*-*-os2*)
|
||||
ISOS2="true"
|
||||
EXE=".exe"
|
||||
MATHLIB=""
|
||||
SYS_GL_LIBS=""
|
||||
;;
|
||||
*)
|
||||
dnl Oh well, call it Unix...
|
||||
ISUNIX="true"
|
||||
EXE=""
|
||||
MATHLIB="-lm"
|
||||
SYS_GL_LIBS="-lGL"
|
||||
dnl Use the new libOpenGL if present.
|
||||
AC_CHECK_LIB(OpenGL, glBegin,
|
||||
[SYS_GL_LIBS="-lOpenGL"],[SYS_GL_LIBS="-lGL"])
|
||||
;;
|
||||
esac
|
||||
AC_SUBST(EXE)
|
||||
@@ -88,9 +97,10 @@ AC_SUBST(MATHLIB)
|
||||
AC_SUBST(ISMACOSX)
|
||||
AC_SUBST(ISWINDOWS)
|
||||
AC_SUBST(ISUNIX)
|
||||
AC_SUBST(ISOS2)
|
||||
|
||||
dnl Check for SDL
|
||||
SDL_VERSION=2.0.0
|
||||
SDL_VERSION=2.0.18
|
||||
AM_PATH_SDL2($SDL_VERSION,
|
||||
:,
|
||||
AC_MSG_ERROR([*** SDL version $SDL_VERSION not found!])
|
||||
@@ -122,43 +132,34 @@ fi
|
||||
dnl Check for OpenGL
|
||||
AC_MSG_CHECKING(for OpenGL support)
|
||||
have_opengl=no
|
||||
AC_TRY_COMPILE([
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include "SDL_opengl.h"
|
||||
#ifndef SDL_VIDEO_OPENGL
|
||||
#error SDL_VIDEO_OPENGL
|
||||
#endif
|
||||
],[
|
||||
],[
|
||||
have_opengl=yes
|
||||
])
|
||||
]],[])], [have_opengl=yes],[])
|
||||
AC_MSG_RESULT($have_opengl)
|
||||
|
||||
dnl Check for OpenGL ES
|
||||
AC_MSG_CHECKING(for OpenGL ES support)
|
||||
have_opengles=no
|
||||
AC_TRY_COMPILE([
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include "SDL_opengles.h"
|
||||
#ifndef SDL_VIDEO_OPENGL_ES
|
||||
#error SDL_VIDEO_OPENGL_ES
|
||||
#endif
|
||||
],[
|
||||
],[
|
||||
have_opengles=yes
|
||||
])
|
||||
]],[])] ,[have_opengles=yes],[])
|
||||
AC_MSG_RESULT($have_opengles)
|
||||
|
||||
dnl Check for OpenGL ES2
|
||||
AC_MSG_CHECKING(for OpenGL ES2 support)
|
||||
have_opengles2=no
|
||||
AC_TRY_COMPILE([
|
||||
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
|
||||
#include "SDL_opengles2.h"
|
||||
#ifndef SDL_VIDEO_OPENGL_ES2
|
||||
#error SDL_VIDEO_OPENGL_ES2
|
||||
#endif
|
||||
],[
|
||||
],[
|
||||
have_opengles2=yes
|
||||
])
|
||||
]],[])], [have_opengles2=yes],[])
|
||||
AC_MSG_RESULT($have_opengles2)
|
||||
|
||||
GLLIB=""
|
||||
@@ -199,6 +200,16 @@ if test x$have_SDL_ttf = xyes; then
|
||||
fi
|
||||
AC_SUBST(SDL_TTF_LIB)
|
||||
|
||||
dnl Really, SDL2_test should be linking against libunwind (if it found
|
||||
dnl libunwind.h when configured), but SDL2_test is a static library, so
|
||||
dnl there's no way for it to link against it. We could make SDL2 depend on
|
||||
dnl it, but we don't want all SDL2 build to suddenly gain an extra dependency,
|
||||
dnl so just assume that if it's here now, SDL2_test was probably built with it.
|
||||
PKG_CHECK_MODULES(LIBUNWIND, libunwind, have_libunwind=yes, have_libunwind=no)
|
||||
if test x$have_libunwind = xyes ; then
|
||||
LIBS="$LIBS $LIBUNWIND_LIBS"
|
||||
fi
|
||||
|
||||
dnl Finally create all the generated files
|
||||
AC_CONFIG_FILES([Makefile])
|
||||
AC_OUTPUT
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -53,7 +53,7 @@ static struct
|
||||
double angle;
|
||||
int marker;
|
||||
|
||||
} s_arrBindingDisplay[BINDING_COUNT] = {
|
||||
} s_arrBindingDisplay[] = {
|
||||
{ 387, 167, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_A */
|
||||
{ 431, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_B */
|
||||
{ 342, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_X */
|
||||
@@ -86,8 +86,9 @@ static struct
|
||||
{ 91, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT */
|
||||
{ 375, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERRIGHT */
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(s_arrBindingDisplay, SDL_arraysize(s_arrBindingDisplay) == BINDING_COUNT);
|
||||
|
||||
static int s_arrBindingOrder[BINDING_COUNT] = {
|
||||
static int s_arrBindingOrder[] = {
|
||||
SDL_CONTROLLER_BUTTON_A,
|
||||
SDL_CONTROLLER_BUTTON_B,
|
||||
SDL_CONTROLLER_BUTTON_Y,
|
||||
@@ -118,7 +119,9 @@ static int s_arrBindingOrder[BINDING_COUNT] = {
|
||||
SDL_CONTROLLER_BUTTON_PADDLE2,
|
||||
SDL_CONTROLLER_BUTTON_PADDLE3,
|
||||
SDL_CONTROLLER_BUTTON_PADDLE4,
|
||||
SDL_CONTROLLER_BUTTON_TOUCHPAD,
|
||||
};
|
||||
SDL_COMPILE_TIME_ASSERT(s_arrBindingOrder, SDL_arraysize(s_arrBindingOrder) == BINDING_COUNT);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -162,7 +165,9 @@ static Uint32 s_unPendingAdvanceTime;
|
||||
static SDL_bool s_bBindingComplete;
|
||||
|
||||
static SDL_Window *window;
|
||||
static SDL_Renderer *screen;
|
||||
static SDL_bool done = SDL_FALSE;
|
||||
static SDL_bool bind_touchpad = SDL_FALSE;
|
||||
|
||||
SDL_Texture *
|
||||
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
||||
@@ -224,6 +229,19 @@ SetCurrentBinding(int iBinding)
|
||||
return;
|
||||
}
|
||||
|
||||
if (s_arrBindingOrder[iBinding] == -1)
|
||||
{
|
||||
SetCurrentBinding(iBinding + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (s_arrBindingOrder[iBinding] == SDL_CONTROLLER_BUTTON_TOUCHPAD &&
|
||||
!bind_touchpad)
|
||||
{
|
||||
SetCurrentBinding(iBinding + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
s_iCurrentBinding = iBinding;
|
||||
|
||||
pBinding = &s_arrBindings[s_arrBindingOrder[s_iCurrentBinding]];
|
||||
@@ -366,7 +384,6 @@ BMergeAxisBindings(int iIndex)
|
||||
static void
|
||||
WatchJoystick(SDL_Joystick * joystick)
|
||||
{
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_Texture *background_front, *background_back, *button, *axis, *marker;
|
||||
const char *name = NULL;
|
||||
SDL_Event event;
|
||||
@@ -375,12 +392,6 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
Uint32 alpha_ticks = 0;
|
||||
SDL_JoystickID nJoystickID;
|
||||
|
||||
screen = SDL_CreateRenderer(window, -1, 0);
|
||||
if (screen == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
return;
|
||||
}
|
||||
|
||||
background_front = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
|
||||
background_back = LoadTexture(screen, "controllermap_back.bmp", SDL_FALSE);
|
||||
button = LoadTexture(screen, "button.bmp", SDL_TRUE);
|
||||
@@ -412,10 +423,10 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
s_nNumAxes = SDL_JoystickNumAxes(joystick);
|
||||
s_arrAxisState = (AxisState *)SDL_calloc(s_nNumAxes, sizeof(*s_arrAxisState));
|
||||
|
||||
/* Skip any spurious events at start */
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
continue;
|
||||
}
|
||||
/* Skip any spurious events at start */
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Loop, getting joystick events! */
|
||||
while (!done && !s_bBindingComplete) {
|
||||
@@ -559,7 +570,7 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
if ((event.key.keysym.sym != SDLK_ESCAPE)) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
SDL_FALLTHROUGH;
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
@@ -728,6 +739,10 @@ main(int argc, char *argv[])
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (argv[1] && SDL_strcmp(argv[1], "--bind-touchpad") == 0) {
|
||||
bind_touchpad = SDL_TRUE;
|
||||
}
|
||||
|
||||
/* Create a window to display joystick axis position */
|
||||
window = SDL_CreateWindow("Game Controller Map", SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
||||
@@ -737,7 +752,13 @@ main(int argc, char *argv[])
|
||||
return 2;
|
||||
}
|
||||
|
||||
while (SDL_NumJoysticks() == 0) {
|
||||
screen = SDL_CreateRenderer(window, -1, 0);
|
||||
if (screen == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
return 2;
|
||||
}
|
||||
|
||||
while (!done && SDL_NumJoysticks() == 0) {
|
||||
SDL_Event event;
|
||||
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
@@ -746,7 +767,7 @@ main(int argc, char *argv[])
|
||||
if ((event.key.keysym.sym != SDLK_ESCAPE)) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
SDL_FALLTHROUGH;
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
@@ -754,6 +775,7 @@ main(int argc, char *argv[])
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDL_RenderPresent(screen);
|
||||
}
|
||||
|
||||
/* Print information about the joysticks */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -19,13 +19,13 @@
|
||||
*/
|
||||
|
||||
static
|
||||
char *
|
||||
tf(SDL_bool tf)
|
||||
const char *
|
||||
tf(SDL_bool _tf)
|
||||
{
|
||||
static char *t = "TRUE";
|
||||
static char *f = "FALSE";
|
||||
static const char *t = "TRUE";
|
||||
static const char *f = "FALSE";
|
||||
|
||||
if (tf)
|
||||
if (_tf)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
@@ -353,7 +353,7 @@ static SDL_bool EnqueueEvent_LockFree(SDL_EventQueue *queue, const SDL_Event *ev
|
||||
}
|
||||
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
SDL_AtomicDecRef(&queue->rwcount);
|
||||
(void) SDL_AtomicDecRef(&queue->rwcount);
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
@@ -400,7 +400,7 @@ static SDL_bool DequeueEvent_LockFree(SDL_EventQueue *queue, SDL_Event *event)
|
||||
}
|
||||
|
||||
#ifdef TEST_SPINLOCK_FIFO
|
||||
SDL_AtomicDecRef(&queue->rwcount);
|
||||
(void) SDL_AtomicDecRef(&queue->rwcount);
|
||||
#endif
|
||||
return status;
|
||||
}
|
||||
@@ -473,8 +473,6 @@ static SDL_bool DequeueEvent_Mutex(SDL_EventQueue *queue, SDL_Event *event)
|
||||
|
||||
static SDL_sem *writersDone;
|
||||
static SDL_sem *readersDone;
|
||||
static SDL_atomic_t writersRunning;
|
||||
static SDL_atomic_t readersRunning;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@@ -525,7 +523,6 @@ static int SDLCALL FIFO_Writer(void* _data)
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_AtomicAdd(&writersRunning, -1);
|
||||
SDL_SemPost(writersDone);
|
||||
return 0;
|
||||
}
|
||||
@@ -563,7 +560,6 @@ static int SDLCALL FIFO_Reader(void* _data)
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_AtomicAdd(&readersRunning, -1);
|
||||
SDL_SemPost(readersDone);
|
||||
return 0;
|
||||
}
|
||||
@@ -581,7 +577,7 @@ static int SDLCALL FIFO_Watcher(void* _data)
|
||||
SDL_Delay(0);
|
||||
}
|
||||
/* Do queue manipulation here... */
|
||||
SDL_AtomicDecRef(&queue->watcher);
|
||||
(void) SDL_AtomicDecRef(&queue->watcher);
|
||||
SDL_AtomicUnlock(&queue->lock);
|
||||
|
||||
/* Wait a bit... */
|
||||
@@ -627,7 +623,6 @@ static void RunFIFOTest(SDL_bool lock_free)
|
||||
/* Start the readers first */
|
||||
SDL_Log("Starting %d readers\n", NUM_READERS);
|
||||
SDL_zeroa(readerData);
|
||||
SDL_AtomicSet(&readersRunning, NUM_READERS);
|
||||
for (i = 0; i < NUM_READERS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "FIFOReader%d", i);
|
||||
@@ -639,7 +634,6 @@ static void RunFIFOTest(SDL_bool lock_free)
|
||||
/* Start up the writers */
|
||||
SDL_Log("Starting %d writers\n", NUM_WRITERS);
|
||||
SDL_zeroa(writerData);
|
||||
SDL_AtomicSet(&writersRunning, NUM_WRITERS);
|
||||
for (i = 0; i < NUM_WRITERS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "FIFOWriter%d", i);
|
||||
@@ -650,7 +644,7 @@ static void RunFIFOTest(SDL_bool lock_free)
|
||||
}
|
||||
|
||||
/* Wait for the writers */
|
||||
while (SDL_AtomicGet(&writersRunning) > 0) {
|
||||
for (i = 0; i < NUM_WRITERS; ++i) {
|
||||
SDL_SemWait(writersDone);
|
||||
}
|
||||
|
||||
@@ -658,7 +652,7 @@ static void RunFIFOTest(SDL_bool lock_free)
|
||||
SDL_AtomicSet(&queue.active, 0);
|
||||
|
||||
/* Wait for the readers */
|
||||
while (SDL_AtomicGet(&readersRunning) > 0) {
|
||||
for (i = 0; i < NUM_READERS; ++i) {
|
||||
SDL_SemWait(readersDone);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
|
||||
@@ -498,7 +498,7 @@ const int _numAudioFormats = 18;
|
||||
SDL_AudioFormat _audioFormats[] = { AUDIO_S8, AUDIO_U8, AUDIO_S16LSB, AUDIO_S16MSB, AUDIO_S16SYS, AUDIO_S16, AUDIO_U16LSB,
|
||||
AUDIO_U16MSB, AUDIO_U16SYS, AUDIO_U16, AUDIO_S32LSB, AUDIO_S32MSB, AUDIO_S32SYS, AUDIO_S32,
|
||||
AUDIO_F32LSB, AUDIO_F32MSB, AUDIO_F32SYS, AUDIO_F32 };
|
||||
char *_audioFormatsVerbose[] = { "AUDIO_S8", "AUDIO_U8", "AUDIO_S16LSB", "AUDIO_S16MSB", "AUDIO_S16SYS", "AUDIO_S16", "AUDIO_U16LSB",
|
||||
const char *_audioFormatsVerbose[] = { "AUDIO_S8", "AUDIO_U8", "AUDIO_S16LSB", "AUDIO_S16MSB", "AUDIO_S16SYS", "AUDIO_S16", "AUDIO_U16LSB",
|
||||
"AUDIO_U16MSB", "AUDIO_U16SYS", "AUDIO_U16", "AUDIO_S32LSB", "AUDIO_S32MSB", "AUDIO_S32SYS", "AUDIO_S32",
|
||||
"AUDIO_F32LSB", "AUDIO_F32MSB", "AUDIO_F32SYS", "AUDIO_F32" };
|
||||
const int _numAudioChannels = 4;
|
||||
@@ -697,7 +697,7 @@ int audio_openCloseAndGetAudioStatus()
|
||||
SDL_AudioStatus result;
|
||||
int i;
|
||||
int count;
|
||||
char *device;
|
||||
const char *device;
|
||||
SDL_AudioDeviceID id;
|
||||
SDL_AudioSpec desired, obtained;
|
||||
|
||||
@@ -707,7 +707,7 @@ int audio_openCloseAndGetAudioStatus()
|
||||
if (count > 0) {
|
||||
for (i = 0; i < count; i++) {
|
||||
/* Get device name */
|
||||
device = (char *)SDL_GetAudioDeviceName(i, 0);
|
||||
device = SDL_GetAudioDeviceName(i, 0);
|
||||
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
|
||||
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
|
||||
if (device == NULL) return TEST_ABORTED;
|
||||
@@ -721,7 +721,7 @@ int audio_openCloseAndGetAudioStatus()
|
||||
desired.userdata=NULL;
|
||||
|
||||
/* Open device */
|
||||
id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
|
||||
id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
|
||||
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
|
||||
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
|
||||
if (id > 1) {
|
||||
@@ -755,7 +755,7 @@ int audio_lockUnlockOpenAudioDevice()
|
||||
{
|
||||
int i;
|
||||
int count;
|
||||
char *device;
|
||||
const char *device;
|
||||
SDL_AudioDeviceID id;
|
||||
SDL_AudioSpec desired, obtained;
|
||||
|
||||
@@ -765,7 +765,7 @@ int audio_lockUnlockOpenAudioDevice()
|
||||
if (count > 0) {
|
||||
for (i = 0; i < count; i++) {
|
||||
/* Get device name */
|
||||
device = (char *)SDL_GetAudioDeviceName(i, 0);
|
||||
device = SDL_GetAudioDeviceName(i, 0);
|
||||
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
|
||||
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
|
||||
if (device == NULL) return TEST_ABORTED;
|
||||
@@ -779,7 +779,7 @@ int audio_lockUnlockOpenAudioDevice()
|
||||
desired.userdata=NULL;
|
||||
|
||||
/* Open device */
|
||||
id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
|
||||
id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
|
||||
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
|
||||
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >=2, got: %i", id);
|
||||
if (id > 1) {
|
||||
@@ -917,7 +917,7 @@ int audio_openCloseAudioDeviceConnected()
|
||||
int result = -1;
|
||||
int i;
|
||||
int count;
|
||||
char *device;
|
||||
const char *device;
|
||||
SDL_AudioDeviceID id;
|
||||
SDL_AudioSpec desired, obtained;
|
||||
|
||||
@@ -927,7 +927,7 @@ int audio_openCloseAudioDeviceConnected()
|
||||
if (count > 0) {
|
||||
for (i = 0; i < count; i++) {
|
||||
/* Get device name */
|
||||
device = (char *)SDL_GetAudioDeviceName(i, 0);
|
||||
device = SDL_GetAudioDeviceName(i, 0);
|
||||
SDLTest_AssertPass("SDL_GetAudioDeviceName(%i,0)", i);
|
||||
SDLTest_AssertCheck(device != NULL, "Validate device name is not NULL; got: %s", (device != NULL) ? device : "NULL");
|
||||
if (device == NULL) return TEST_ABORTED;
|
||||
@@ -941,7 +941,7 @@ int audio_openCloseAudioDeviceConnected()
|
||||
desired.userdata=NULL;
|
||||
|
||||
/* Open device */
|
||||
id = SDL_OpenAudioDevice((const char *)device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
|
||||
id = SDL_OpenAudioDevice(device, 0, &desired, &obtained, SDL_AUDIO_ALLOW_ANY_CHANGE);
|
||||
SDLTest_AssertPass("SDL_OpenAudioDevice('%s',...)", device);
|
||||
SDLTest_AssertCheck(id > 1, "Validate device ID; expected: >1, got: %i", id);
|
||||
if (id > 1) {
|
||||
|
||||
@@ -16,13 +16,12 @@
|
||||
* \brief Check call to SDL_HasClipboardText
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
|
||||
* http://wiki.libsdl.org/SDL_HasClipboardText
|
||||
*/
|
||||
int
|
||||
clipboard_testHasClipboardText(void *arg)
|
||||
{
|
||||
SDL_bool result;
|
||||
result = SDL_HasClipboardText();
|
||||
SDL_HasClipboardText();
|
||||
SDLTest_AssertPass("Call to SDL_HasClipboardText succeeded");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
@@ -32,7 +31,7 @@ clipboard_testHasClipboardText(void *arg)
|
||||
* \brief Check call to SDL_GetClipboardText
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText
|
||||
* http://wiki.libsdl.org/SDL_GetClipboardText
|
||||
*/
|
||||
int
|
||||
clipboard_testGetClipboardText(void *arg)
|
||||
@@ -49,7 +48,7 @@ clipboard_testGetClipboardText(void *arg)
|
||||
/**
|
||||
* \brief Check call to SDL_SetClipboardText
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetClipboardText
|
||||
* http://wiki.libsdl.org/SDL_SetClipboardText
|
||||
*/
|
||||
int
|
||||
clipboard_testSetClipboardText(void *arg)
|
||||
@@ -78,9 +77,9 @@ clipboard_testSetClipboardText(void *arg)
|
||||
/**
|
||||
* \brief End-to-end test of SDL_xyzClipboardText functions
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasClipboardText
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetClipboardText
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetClipboardText
|
||||
* http://wiki.libsdl.org/SDL_HasClipboardText
|
||||
* http://wiki.libsdl.org/SDL_GetClipboardText
|
||||
* http://wiki.libsdl.org/SDL_SetClipboardText
|
||||
*/
|
||||
int
|
||||
clipboard_testClipboardTextFunctions(void *arg)
|
||||
|
||||
@@ -42,8 +42,8 @@ int SDLCALL _events_sampleNullEventFilter(void *userdata, SDL_Event *event)
|
||||
/**
|
||||
* @brief Test pumping and peeking events.
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_PumpEvents
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_PollEvent
|
||||
* @sa http://wiki.libsdl.org/SDL_PumpEvents
|
||||
* @sa http://wiki.libsdl.org/SDL_PollEvent
|
||||
*/
|
||||
int
|
||||
events_pushPumpAndPollUserevent(void *arg)
|
||||
@@ -76,8 +76,8 @@ events_pushPumpAndPollUserevent(void *arg)
|
||||
/**
|
||||
* @brief Adds and deletes an event watch function with NULL userdata
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
|
||||
* @sa http://wiki.libsdl.org/SDL_AddEventWatch
|
||||
* @sa http://wiki.libsdl.org/SDL_DelEventWatch
|
||||
*
|
||||
*/
|
||||
int
|
||||
@@ -126,8 +126,8 @@ events_addDelEventWatch(void *arg)
|
||||
/**
|
||||
* @brief Adds and deletes an event watch function with userdata
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_AddEventWatch
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_DelEventWatch
|
||||
* @sa http://wiki.libsdl.org/SDL_AddEventWatch
|
||||
* @sa http://wiki.libsdl.org/SDL_DelEventWatch
|
||||
*
|
||||
*/
|
||||
int
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
|
||||
|
||||
const int _numHintsEnum = 25;
|
||||
char* _HintsEnum[] =
|
||||
const char* _HintsEnum[] =
|
||||
{
|
||||
SDL_HINT_ACCELEROMETER_AS_JOYSTICK,
|
||||
SDL_HINT_FRAMEBUFFER_ACCELERATION,
|
||||
@@ -37,33 +37,33 @@ char* _HintsEnum[] =
|
||||
SDL_HINT_VIDEO_X11_XVIDMODE,
|
||||
SDL_HINT_XINPUT_ENABLED,
|
||||
};
|
||||
char* _HintsVerbose[] =
|
||||
const char* _HintsVerbose[] =
|
||||
{
|
||||
"SDL_HINT_ACCELEROMETER_AS_JOYSTICK",
|
||||
"SDL_HINT_FRAMEBUFFER_ACCELERATION",
|
||||
"SDL_HINT_GAMECONTROLLERCONFIG",
|
||||
"SDL_HINT_GRAB_KEYBOARD",
|
||||
"SDL_HINT_IDLE_TIMER_DISABLED",
|
||||
"SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS",
|
||||
"SDL_HINT_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK",
|
||||
"SDL_HINT_MOUSE_RELATIVE_MODE_WARP",
|
||||
"SDL_HINT_ORIENTATIONS",
|
||||
"SDL_HINT_RENDER_DIRECT3D_THREADSAFE",
|
||||
"SDL_HINT_RENDER_DRIVER",
|
||||
"SDL_HINT_RENDER_OPENGL_SHADERS",
|
||||
"SDL_HINT_RENDER_SCALE_QUALITY",
|
||||
"SDL_HINT_RENDER_VSYNC",
|
||||
"SDL_HINT_TIMER_RESOLUTION",
|
||||
"SDL_HINT_VIDEO_ALLOW_SCREENSAVER",
|
||||
"SDL_HINT_VIDEO_HIGHDPI_DISABLED",
|
||||
"SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES",
|
||||
"SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
|
||||
"SDL_HINT_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
|
||||
"SDL_HINT_VIDEO_WIN_D3DCOMPILER",
|
||||
"SDL_HINT_VIDEO_X11_XINERAMA",
|
||||
"SDL_HINT_VIDEO_X11_XRANDR",
|
||||
"SDL_HINT_VIDEO_X11_XVIDMODE",
|
||||
"SDL_HINT_XINPUT_ENABLED"
|
||||
"SDL_ACCELEROMETER_AS_JOYSTICK",
|
||||
"SDL_FRAMEBUFFER_ACCELERATION",
|
||||
"SDL_GAMECONTROLLERCONFIG",
|
||||
"SDL_GRAB_KEYBOARD",
|
||||
"SDL_IDLE_TIMER_DISABLED",
|
||||
"SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS",
|
||||
"SDL_MAC_CTRL_CLICK_EMULATE_RIGHT_CLICK",
|
||||
"SDL_MOUSE_RELATIVE_MODE_WARP",
|
||||
"SDL_ORIENTATIONS",
|
||||
"SDL_RENDER_DIRECT3D_THREADSAFE",
|
||||
"SDL_RENDER_DRIVER",
|
||||
"SDL_RENDER_OPENGL_SHADERS",
|
||||
"SDL_RENDER_SCALE_QUALITY",
|
||||
"SDL_RENDER_VSYNC",
|
||||
"SDL_TIMER_RESOLUTION",
|
||||
"SDL_VIDEO_ALLOW_SCREENSAVER",
|
||||
"SDL_VIDEO_HIGHDPI_DISABLED",
|
||||
"SDL_VIDEO_MAC_FULLSCREEN_SPACES",
|
||||
"SDL_VIDEO_MINIMIZE_ON_FOCUS_LOSS",
|
||||
"SDL_VIDEO_WINDOW_SHARE_PIXEL_FORMAT",
|
||||
"SDL_VIDEO_WIN_D3DCOMPILER",
|
||||
"SDL_VIDEO_X11_XINERAMA",
|
||||
"SDL_VIDEO_X11_XRANDR",
|
||||
"SDL_VIDEO_X11_XVIDMODE",
|
||||
"SDL_XINPUT_ENABLED"
|
||||
};
|
||||
|
||||
|
||||
@@ -75,14 +75,14 @@ char* _HintsVerbose[] =
|
||||
int
|
||||
hints_getHint(void *arg)
|
||||
{
|
||||
char *result1;
|
||||
char *result2;
|
||||
const char *result1;
|
||||
const char *result2;
|
||||
int i;
|
||||
|
||||
|
||||
for (i=0; i<_numHintsEnum; i++) {
|
||||
result1 = (char *)SDL_GetHint((char*)_HintsEnum[i]);
|
||||
result1 = SDL_GetHint(_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using define definition", (char*)_HintsEnum[i]);
|
||||
result2 = (char *)SDL_GetHint((char *)_HintsVerbose[i]);
|
||||
result2 = SDL_GetHint(_HintsVerbose[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
|
||||
SDLTest_AssertCheck(
|
||||
(result1 == NULL && result2 == NULL) || (SDL_strcmp(result1, result2) == 0),
|
||||
@@ -90,7 +90,7 @@ hints_getHint(void *arg)
|
||||
(result1 == NULL) ? "null" : result1,
|
||||
(result2 == NULL) ? "null" : result2);
|
||||
}
|
||||
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
@@ -100,48 +100,52 @@ hints_getHint(void *arg)
|
||||
int
|
||||
hints_setHint(void *arg)
|
||||
{
|
||||
char *originalValue;
|
||||
char *value;
|
||||
char *testValue;
|
||||
const char *originalValue;
|
||||
const char *value;
|
||||
const char *testValue;
|
||||
SDL_bool result;
|
||||
int i, j;
|
||||
|
||||
/* Create random values to set */
|
||||
/* Create random values to set */
|
||||
value = SDLTest_RandomAsciiStringOfSize(10);
|
||||
|
||||
|
||||
for (i=0; i<_numHintsEnum; i++) {
|
||||
/* Capture current value */
|
||||
originalValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s)", (char*)_HintsEnum[i]);
|
||||
|
||||
originalValue = SDL_GetHint(_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s)", _HintsEnum[i]);
|
||||
|
||||
/* Copy the original value, since it will be freed when we set it again */
|
||||
originalValue = originalValue ? SDL_strdup(originalValue) : NULL;
|
||||
|
||||
/* Set value (twice) */
|
||||
for (j=1; j<=2; j++) {
|
||||
result = SDL_SetHint((char*)_HintsEnum[i], value);
|
||||
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", (char*)_HintsEnum[i], value, j);
|
||||
result = SDL_SetHint(_HintsEnum[i], value);
|
||||
SDLTest_AssertPass("Call to SDL_SetHint(%s, %s) (iteration %i)", _HintsEnum[i], value, j);
|
||||
SDLTest_AssertCheck(
|
||||
result == SDL_TRUE || result == SDL_FALSE,
|
||||
"Verify valid result was returned, got: %i",
|
||||
(int)result);
|
||||
testValue = (char *)SDL_GetHint((char*)_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", (char*)_HintsVerbose[i]);
|
||||
testValue = SDL_GetHint(_HintsEnum[i]);
|
||||
SDLTest_AssertPass("Call to SDL_GetHint(%s) - using string definition", _HintsVerbose[i]);
|
||||
SDLTest_AssertCheck(
|
||||
(SDL_strcmp(value, testValue) == 0),
|
||||
"Verify returned value equals set value; got: testValue='%s' value='%s",
|
||||
(testValue == NULL) ? "null" : testValue,
|
||||
value);
|
||||
}
|
||||
|
||||
|
||||
/* Reset original value */
|
||||
result = SDL_SetHint((char*)_HintsEnum[i], originalValue);
|
||||
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", (char*)_HintsEnum[i]);
|
||||
result = SDL_SetHint(_HintsEnum[i], originalValue);
|
||||
SDLTest_AssertPass("Call to SDL_SetHint(%s, originalValue)", _HintsEnum[i]);
|
||||
SDLTest_AssertCheck(
|
||||
result == SDL_TRUE || result == SDL_FALSE,
|
||||
"Verify valid result was returned, got: %i",
|
||||
(int)result);
|
||||
SDL_free((void *)originalValue);
|
||||
}
|
||||
|
||||
SDL_free(value);
|
||||
|
||||
|
||||
SDL_free((void *)value);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
/**
|
||||
* @brief Check call to SDL_GetKeyboardState with and without numkeys reference.
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardState
|
||||
* @sa http://wiki.libsdl.org/SDL_GetKeyboardState
|
||||
*/
|
||||
int
|
||||
keyboard_getKeyboardState(void *arg)
|
||||
@@ -42,15 +42,13 @@ keyboard_getKeyboardState(void *arg)
|
||||
/**
|
||||
* @brief Check call to SDL_GetKeyboardFocus
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyboardFocus
|
||||
* @sa http://wiki.libsdl.org/SDL_GetKeyboardFocus
|
||||
*/
|
||||
int
|
||||
keyboard_getKeyboardFocus(void *arg)
|
||||
{
|
||||
SDL_Window* window;
|
||||
|
||||
/* Call, but ignore return value */
|
||||
window = SDL_GetKeyboardFocus();
|
||||
SDL_GetKeyboardFocus();
|
||||
SDLTest_AssertPass("Call to SDL_GetKeyboardFocus()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
@@ -59,7 +57,7 @@ keyboard_getKeyboardFocus(void *arg)
|
||||
/**
|
||||
* @brief Check call to SDL_GetKeyFromName for known, unknown and invalid name.
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromName
|
||||
* @sa http://wiki.libsdl.org/SDL_GetKeyFromName
|
||||
*/
|
||||
int
|
||||
keyboard_getKeyFromName(void *arg)
|
||||
@@ -126,7 +124,7 @@ _checkInvalidScancodeError()
|
||||
/**
|
||||
* @brief Check call to SDL_GetKeyFromScancode
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyFromScancode
|
||||
* @sa http://wiki.libsdl.org/SDL_GetKeyFromScancode
|
||||
*/
|
||||
int
|
||||
keyboard_getKeyFromScancode(void *arg)
|
||||
@@ -165,13 +163,13 @@ keyboard_getKeyFromScancode(void *arg)
|
||||
/**
|
||||
* @brief Check call to SDL_GetKeyName
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName
|
||||
* @sa http://wiki.libsdl.org/SDL_GetKeyName
|
||||
*/
|
||||
int
|
||||
keyboard_getKeyName(void *arg)
|
||||
{
|
||||
char *result;
|
||||
char *expected;
|
||||
const char *result;
|
||||
const char *expected;
|
||||
|
||||
/* Case where key has a 1 character name */
|
||||
expected = "3";
|
||||
@@ -221,14 +219,14 @@ keyboard_getKeyName(void *arg)
|
||||
/**
|
||||
* @brief SDL_GetScancodeName negative cases
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeName
|
||||
* @sa http://wiki.libsdl.org/SDL_GetScancodeName
|
||||
*/
|
||||
int
|
||||
keyboard_getScancodeNameNegative(void *arg)
|
||||
{
|
||||
SDL_Scancode scancode;
|
||||
char *result;
|
||||
char *expected = "";
|
||||
const char *result;
|
||||
const char *expected = "";
|
||||
|
||||
/* Clear error message */
|
||||
SDL_ClearError();
|
||||
@@ -248,14 +246,14 @@ keyboard_getScancodeNameNegative(void *arg)
|
||||
/**
|
||||
* @brief SDL_GetKeyName negative cases
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetKeyName
|
||||
* @sa http://wiki.libsdl.org/SDL_GetKeyName
|
||||
*/
|
||||
int
|
||||
keyboard_getKeyNameNegative(void *arg)
|
||||
{
|
||||
SDL_Keycode keycode;
|
||||
char *result;
|
||||
char *expected = "";
|
||||
const char *result;
|
||||
const char *expected = "";
|
||||
|
||||
/* Unknown keycode */
|
||||
keycode = SDLK_UNKNOWN;
|
||||
@@ -285,8 +283,8 @@ keyboard_getKeyNameNegative(void *arg)
|
||||
/**
|
||||
* @brief Check call to SDL_GetModState and SDL_SetModState
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetModState
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetModState
|
||||
* @sa http://wiki.libsdl.org/SDL_GetModState
|
||||
* @sa http://wiki.libsdl.org/SDL_SetModState
|
||||
*/
|
||||
int
|
||||
keyboard_getSetModState(void *arg)
|
||||
@@ -307,7 +305,7 @@ keyboard_getSetModState(void *arg)
|
||||
KMOD_NUM |
|
||||
KMOD_CAPS |
|
||||
KMOD_MODE |
|
||||
KMOD_RESERVED;
|
||||
KMOD_SCROLL;
|
||||
|
||||
/* Get state, cache for later reset */
|
||||
result = SDL_GetModState();
|
||||
@@ -346,8 +344,8 @@ keyboard_getSetModState(void *arg)
|
||||
/**
|
||||
* @brief Check call to SDL_StartTextInput and SDL_StopTextInput
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_StartTextInput
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_StopTextInput
|
||||
* @sa http://wiki.libsdl.org/SDL_StartTextInput
|
||||
* @sa http://wiki.libsdl.org/SDL_StopTextInput
|
||||
*/
|
||||
int
|
||||
keyboard_startStopTextInput(void *arg)
|
||||
@@ -393,7 +391,7 @@ void _testSetTextInputRect(SDL_Rect refRect)
|
||||
/**
|
||||
* @brief Check call to SDL_SetTextInputRect
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
|
||||
* @sa http://wiki.libsdl.org/SDL_SetTextInputRect
|
||||
*/
|
||||
int
|
||||
keyboard_setTextInputRect(void *arg)
|
||||
@@ -473,7 +471,7 @@ keyboard_setTextInputRect(void *arg)
|
||||
/**
|
||||
* @brief Check call to SDL_SetTextInputRect with invalid data
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetTextInputRect
|
||||
* @sa http://wiki.libsdl.org/SDL_SetTextInputRect
|
||||
*/
|
||||
int
|
||||
keyboard_setTextInputRectNegative(void *arg)
|
||||
@@ -511,8 +509,8 @@ keyboard_setTextInputRectNegative(void *arg)
|
||||
/**
|
||||
* @brief Check call to SDL_GetScancodeFromKey
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromKey
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
|
||||
* @sa http://wiki.libsdl.org/SDL_GetScancodeFromKey
|
||||
* @sa http://wiki.libsdl.org/SDL_Keycode
|
||||
*/
|
||||
int
|
||||
keyboard_getScancodeFromKey(void *arg)
|
||||
@@ -535,8 +533,8 @@ keyboard_getScancodeFromKey(void *arg)
|
||||
/**
|
||||
* @brief Check call to SDL_GetScancodeFromName
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
|
||||
* @sa http://wiki.libsdl.org/SDL_GetScancodeFromName
|
||||
* @sa http://wiki.libsdl.org/SDL_Keycode
|
||||
*/
|
||||
int
|
||||
keyboard_getScancodeFromName(void *arg)
|
||||
@@ -608,13 +606,13 @@ _checkInvalidNameError()
|
||||
/**
|
||||
* @brief Check call to SDL_GetScancodeFromName with invalid data
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetScancodeFromName
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_Keycode
|
||||
* @sa http://wiki.libsdl.org/SDL_GetScancodeFromName
|
||||
* @sa http://wiki.libsdl.org/SDL_Keycode
|
||||
*/
|
||||
int
|
||||
keyboard_getScancodeFromNameNegative(void *arg)
|
||||
{
|
||||
char *name;
|
||||
const char *name;
|
||||
SDL_Scancode scancode;
|
||||
|
||||
/* Clear error message */
|
||||
@@ -627,9 +625,9 @@ keyboard_getScancodeFromNameNegative(void *arg)
|
||||
if (name == NULL) {
|
||||
return TEST_ABORTED;
|
||||
}
|
||||
scancode = SDL_GetScancodeFromName((const char *)name);
|
||||
scancode = SDL_GetScancodeFromName(name);
|
||||
SDLTest_AssertPass("Call to SDL_GetScancodeFromName('%s')", name);
|
||||
SDL_free(name);
|
||||
SDL_free((void *)name);
|
||||
SDLTest_AssertCheck(scancode == SDL_SCANCODE_UNKNOWN, "Validate return value from SDL_GetScancodeFromName, expected: %i, got: %i", SDL_SCANCODE_UNKNOWN, scancode);
|
||||
_checkInvalidNameError();
|
||||
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
/* !
|
||||
* \brief Tests SDL_Init() and SDL_Quit() of Joystick and Haptic subsystems
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_Init
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_Quit
|
||||
* http://wiki.libsdl.org/SDL_Init
|
||||
* http://wiki.libsdl.org/SDL_Quit
|
||||
*/
|
||||
static int main_testInitQuitJoystickHaptic (void *arg)
|
||||
{
|
||||
@@ -41,8 +41,8 @@ static int main_testInitQuitJoystickHaptic (void *arg)
|
||||
/* !
|
||||
* \brief Tests SDL_InitSubSystem() and SDL_QuitSubSystem()
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_Init
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_Quit
|
||||
* http://wiki.libsdl.org/SDL_Init
|
||||
* http://wiki.libsdl.org/SDL_Quit
|
||||
*/
|
||||
static int main_testInitQuitSubSystem (void *arg)
|
||||
{
|
||||
|
||||
@@ -192,8 +192,8 @@ static SDL_Cursor *_initArrowCursor(const char *image[])
|
||||
/**
|
||||
* @brief Check call to SDL_CreateCursor and SDL_FreeCursor
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_CreateCursor
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_FreeCursor
|
||||
* @sa http://wiki.libsdl.org/SDL_CreateCursor
|
||||
* @sa http://wiki.libsdl.org/SDL_FreeCursor
|
||||
*/
|
||||
int
|
||||
mouse_createFreeCursor(void *arg)
|
||||
@@ -218,8 +218,8 @@ mouse_createFreeCursor(void *arg)
|
||||
/**
|
||||
* @brief Check call to SDL_CreateColorCursor and SDL_FreeCursor
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_CreateColorCursor
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_FreeCursor
|
||||
* @sa http://wiki.libsdl.org/SDL_CreateColorCursor
|
||||
* @sa http://wiki.libsdl.org/SDL_FreeCursor
|
||||
*/
|
||||
int
|
||||
mouse_createFreeColorCursor(void *arg)
|
||||
@@ -275,7 +275,7 @@ void _changeCursorVisibility(int state)
|
||||
/**
|
||||
* @brief Check call to SDL_ShowCursor
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_ShowCursor
|
||||
* @sa http://wiki.libsdl.org/SDL_ShowCursor
|
||||
*/
|
||||
int
|
||||
mouse_showCursor(void *arg)
|
||||
@@ -305,7 +305,7 @@ mouse_showCursor(void *arg)
|
||||
/**
|
||||
* @brief Check call to SDL_SetCursor
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetCursor
|
||||
* @sa http://wiki.libsdl.org/SDL_SetCursor
|
||||
*/
|
||||
int
|
||||
mouse_setCursor(void *arg)
|
||||
@@ -338,7 +338,7 @@ mouse_setCursor(void *arg)
|
||||
/**
|
||||
* @brief Check call to SDL_GetCursor
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetCursor
|
||||
* @sa http://wiki.libsdl.org/SDL_GetCursor
|
||||
*/
|
||||
int
|
||||
mouse_getCursor(void *arg)
|
||||
@@ -356,8 +356,8 @@ mouse_getCursor(void *arg)
|
||||
/**
|
||||
* @brief Check call to SDL_GetRelativeMouseMode and SDL_SetRelativeMouseMode
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetRelativeMouseMode
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_SetRelativeMouseMode
|
||||
* @sa http://wiki.libsdl.org/SDL_GetRelativeMouseMode
|
||||
* @sa http://wiki.libsdl.org/SDL_SetRelativeMouseMode
|
||||
*/
|
||||
int
|
||||
mouse_getSetRelativeMouseMode(void *arg)
|
||||
@@ -440,7 +440,7 @@ void _destroyMouseSuiteTestWindow(SDL_Window *window)
|
||||
/**
|
||||
* @brief Check call to SDL_WarpMouseInWindow
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_WarpMouseInWindow
|
||||
* @sa http://wiki.libsdl.org/SDL_WarpMouseInWindow
|
||||
*/
|
||||
int
|
||||
mouse_warpMouseInWindow(void *arg)
|
||||
@@ -502,7 +502,7 @@ mouse_warpMouseInWindow(void *arg)
|
||||
/**
|
||||
* @brief Check call to SDL_GetMouseFocus
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.cgi/SDL_GetMouseFocus
|
||||
* @sa http://wiki.libsdl.org/SDL_GetMouseFocus
|
||||
*/
|
||||
int
|
||||
mouse_getMouseFocus(void *arg)
|
||||
@@ -527,6 +527,7 @@ mouse_getMouseFocus(void *arg)
|
||||
SDLTest_AssertPass("SDL_WarpMouseInWindow(...,%i,%i)", x, y);
|
||||
|
||||
/* Pump events to update focus state */
|
||||
SDL_Delay(100);
|
||||
SDL_PumpEvents();
|
||||
SDLTest_AssertPass("SDL_PumpEvents()");
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ Uint32 _RGBPixelFormats[] =
|
||||
SDL_PIXELFORMAT_BGRA8888,
|
||||
SDL_PIXELFORMAT_ARGB2101010
|
||||
};
|
||||
char* _RGBPixelFormatsVerbose[] =
|
||||
const char* _RGBPixelFormatsVerbose[] =
|
||||
{
|
||||
"SDL_PIXELFORMAT_INDEX1LSB",
|
||||
"SDL_PIXELFORMAT_INDEX1MSB",
|
||||
@@ -92,7 +92,7 @@ Uint32 _nonRGBPixelFormats[] =
|
||||
SDL_PIXELFORMAT_NV12,
|
||||
SDL_PIXELFORMAT_NV21
|
||||
};
|
||||
char* _nonRGBPixelFormatsVerbose[] =
|
||||
const char* _nonRGBPixelFormatsVerbose[] =
|
||||
{
|
||||
"SDL_PIXELFORMAT_YV12",
|
||||
"SDL_PIXELFORMAT_IYUV",
|
||||
@@ -110,7 +110,7 @@ Uint32 _invalidPixelFormats[] =
|
||||
0xfffffffe,
|
||||
0xffffffff
|
||||
};
|
||||
char* _invalidPixelFormatsVerbose[] =
|
||||
const char* _invalidPixelFormatsVerbose[] =
|
||||
{
|
||||
"SDL_PIXELFORMAT_UNKNOWN",
|
||||
"SDL_PIXELFORMAT_UNKNOWN"
|
||||
@@ -121,8 +121,8 @@ char* _invalidPixelFormatsVerbose[] =
|
||||
/**
|
||||
* @brief Call to SDL_AllocFormat and SDL_FreeFormat
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_AllocFormat
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_FreeFormat
|
||||
* @sa http://wiki.libsdl.org/SDL_AllocFormat
|
||||
* @sa http://wiki.libsdl.org/SDL_FreeFormat
|
||||
*/
|
||||
int
|
||||
pixels_allocFreeFormat(void *arg)
|
||||
@@ -228,7 +228,7 @@ pixels_allocFreeFormat(void *arg)
|
||||
/**
|
||||
* @brief Call to SDL_GetPixelFormatName
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetPixelFormatName
|
||||
* @sa http://wiki.libsdl.org/SDL_GetPixelFormatName
|
||||
*/
|
||||
int
|
||||
pixels_getPixelFormatName(void *arg)
|
||||
@@ -237,14 +237,14 @@ pixels_getPixelFormatName(void *arg)
|
||||
const char *error;
|
||||
int i;
|
||||
Uint32 format;
|
||||
char* result;
|
||||
const char *result;
|
||||
|
||||
/* Blank/undefined format */
|
||||
format = 0;
|
||||
SDLTest_Log("RGB Format: %s (%u)", unknownFormat, format);
|
||||
|
||||
/* Get name of format */
|
||||
result = (char *)SDL_GetPixelFormatName(format);
|
||||
result = SDL_GetPixelFormatName(format);
|
||||
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
@@ -259,7 +259,7 @@ pixels_getPixelFormatName(void *arg)
|
||||
SDLTest_Log("RGB Format: %s (%u)", _RGBPixelFormatsVerbose[i], format);
|
||||
|
||||
/* Get name of format */
|
||||
result = (char *)SDL_GetPixelFormatName(format);
|
||||
result = SDL_GetPixelFormatName(format);
|
||||
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
@@ -275,7 +275,7 @@ pixels_getPixelFormatName(void *arg)
|
||||
SDLTest_Log("non-RGB Format: %s (%u)", _nonRGBPixelFormatsVerbose[i], format);
|
||||
|
||||
/* Get name of format */
|
||||
result = (char *)SDL_GetPixelFormatName(format);
|
||||
result = SDL_GetPixelFormatName(format);
|
||||
SDLTest_AssertPass("Call to SDL_GetPixelFormatName()");
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
@@ -292,7 +292,7 @@ pixels_getPixelFormatName(void *arg)
|
||||
SDLTest_AssertPass("Call to SDL_ClearError()");
|
||||
for (i = 0; i < _numInvalidPixelFormats; i++) {
|
||||
format = _invalidPixelFormats[i];
|
||||
result = (char *)SDL_GetPixelFormatName(format);
|
||||
result = SDL_GetPixelFormatName(format);
|
||||
SDLTest_AssertPass("Call to SDL_GetPixelFormatName(%u)", format);
|
||||
SDLTest_AssertCheck(result != NULL, "Verify result is not NULL");
|
||||
if (result != NULL) {
|
||||
@@ -312,8 +312,8 @@ pixels_getPixelFormatName(void *arg)
|
||||
/**
|
||||
* @brief Call to SDL_AllocPalette and SDL_FreePalette
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_AllocPalette
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_FreePalette
|
||||
* @sa http://wiki.libsdl.org/SDL_AllocPalette
|
||||
* @sa http://wiki.libsdl.org/SDL_FreePalette
|
||||
*/
|
||||
int
|
||||
pixels_allocFreePalette(void *arg)
|
||||
@@ -402,7 +402,7 @@ pixels_allocFreePalette(void *arg)
|
||||
/**
|
||||
* @brief Call to SDL_CalculateGammaRamp
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_CalculateGammaRamp
|
||||
* @sa http://wiki.libsdl.org/SDL_CalculateGammaRamp
|
||||
*/
|
||||
int
|
||||
pixels_calcGammaRamp(void *arg)
|
||||
|
||||
@@ -101,11 +101,11 @@ int platform_testEndianessAndSwap(void *arg)
|
||||
/* !
|
||||
* \brief Tests SDL_GetXYZ() functions
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetPlatform
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetCPUCount
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetCPUCacheLineSize
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetRevision
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetRevisionNumber
|
||||
* http://wiki.libsdl.org/SDL_GetPlatform
|
||||
* http://wiki.libsdl.org/SDL_GetCPUCount
|
||||
* http://wiki.libsdl.org/SDL_GetCPUCacheLineSize
|
||||
* http://wiki.libsdl.org/SDL_GetRevision
|
||||
* http://wiki.libsdl.org/SDL_GetRevisionNumber
|
||||
*/
|
||||
int platform_testGetFunctions (void *arg)
|
||||
{
|
||||
@@ -141,60 +141,55 @@ int platform_testGetFunctions (void *arg)
|
||||
SDLTest_AssertPass("SDL_GetRevision()");
|
||||
SDLTest_AssertCheck(revision != NULL, "SDL_GetRevision() != NULL");
|
||||
|
||||
ret = SDL_GetRevisionNumber();
|
||||
SDLTest_AssertPass("SDL_GetRevisionNumber()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* !
|
||||
* \brief Tests SDL_HasXYZ() functions
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_Has3DNow
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasAltiVec
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasMMX
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasRDTSC
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE2
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE3
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE41
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasSSE42
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasAVX
|
||||
* http://wiki.libsdl.org/SDL_Has3DNow
|
||||
* http://wiki.libsdl.org/SDL_HasAltiVec
|
||||
* http://wiki.libsdl.org/SDL_HasMMX
|
||||
* http://wiki.libsdl.org/SDL_HasRDTSC
|
||||
* http://wiki.libsdl.org/SDL_HasSSE
|
||||
* http://wiki.libsdl.org/SDL_HasSSE2
|
||||
* http://wiki.libsdl.org/SDL_HasSSE3
|
||||
* http://wiki.libsdl.org/SDL_HasSSE41
|
||||
* http://wiki.libsdl.org/SDL_HasSSE42
|
||||
* http://wiki.libsdl.org/SDL_HasAVX
|
||||
*/
|
||||
int platform_testHasFunctions (void *arg)
|
||||
{
|
||||
int ret;
|
||||
|
||||
/* TODO: independently determine and compare values as well */
|
||||
|
||||
ret = SDL_HasRDTSC();
|
||||
SDL_HasRDTSC();
|
||||
SDLTest_AssertPass("SDL_HasRDTSC()");
|
||||
|
||||
ret = SDL_HasAltiVec();
|
||||
SDL_HasAltiVec();
|
||||
SDLTest_AssertPass("SDL_HasAltiVec()");
|
||||
|
||||
ret = SDL_HasMMX();
|
||||
SDL_HasMMX();
|
||||
SDLTest_AssertPass("SDL_HasMMX()");
|
||||
|
||||
ret = SDL_Has3DNow();
|
||||
SDL_Has3DNow();
|
||||
SDLTest_AssertPass("SDL_Has3DNow()");
|
||||
|
||||
ret = SDL_HasSSE();
|
||||
SDL_HasSSE();
|
||||
SDLTest_AssertPass("SDL_HasSSE()");
|
||||
|
||||
ret = SDL_HasSSE2();
|
||||
SDL_HasSSE2();
|
||||
SDLTest_AssertPass("SDL_HasSSE2()");
|
||||
|
||||
ret = SDL_HasSSE3();
|
||||
SDL_HasSSE3();
|
||||
SDLTest_AssertPass("SDL_HasSSE3()");
|
||||
|
||||
ret = SDL_HasSSE41();
|
||||
SDL_HasSSE41();
|
||||
SDLTest_AssertPass("SDL_HasSSE41()");
|
||||
|
||||
ret = SDL_HasSSE42();
|
||||
SDL_HasSSE42();
|
||||
SDLTest_AssertPass("SDL_HasSSE42()");
|
||||
|
||||
ret = SDL_HasAVX();
|
||||
SDL_HasAVX();
|
||||
SDLTest_AssertPass("SDL_HasAVX()");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
@@ -203,7 +198,7 @@ int platform_testHasFunctions (void *arg)
|
||||
/* !
|
||||
* \brief Tests SDL_GetVersion
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetVersion
|
||||
* http://wiki.libsdl.org/SDL_GetVersion
|
||||
*/
|
||||
int platform_testGetVersion(void *arg)
|
||||
{
|
||||
@@ -273,9 +268,9 @@ int platform_testDefaultInit(void *arg)
|
||||
/* !
|
||||
* \brief Tests SDL_Get/Set/ClearError
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetError
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetError
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_ClearError
|
||||
* http://wiki.libsdl.org/SDL_GetError
|
||||
* http://wiki.libsdl.org/SDL_SetError
|
||||
* http://wiki.libsdl.org/SDL_ClearError
|
||||
*/
|
||||
int platform_testGetSetClearError(void *arg)
|
||||
{
|
||||
@@ -327,7 +322,7 @@ int platform_testGetSetClearError(void *arg)
|
||||
/* !
|
||||
* \brief Tests SDL_SetError with empty input
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetError
|
||||
* http://wiki.libsdl.org/SDL_SetError
|
||||
*/
|
||||
int platform_testSetErrorEmptyInput(void *arg)
|
||||
{
|
||||
@@ -365,7 +360,7 @@ int platform_testSetErrorEmptyInput(void *arg)
|
||||
/* !
|
||||
* \brief Tests SDL_SetError with invalid input
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetError
|
||||
* http://wiki.libsdl.org/SDL_SetError
|
||||
*/
|
||||
int platform_testSetErrorInvalidInput(void *arg)
|
||||
{
|
||||
@@ -389,7 +384,7 @@ int platform_testSetErrorInvalidInput(void *arg)
|
||||
if (lastError != NULL)
|
||||
{
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0,
|
||||
SDLTest_AssertCheck(len == 0 || SDL_strcmp(lastError, "(null)") == 0,
|
||||
"SDL_GetError(): expected message len 0, was len: %i",
|
||||
(int) len);
|
||||
}
|
||||
@@ -409,7 +404,7 @@ int platform_testSetErrorInvalidInput(void *arg)
|
||||
if (lastError != NULL)
|
||||
{
|
||||
len = SDL_strlen(lastError);
|
||||
SDLTest_AssertCheck(len == 0,
|
||||
SDLTest_AssertCheck(len == 0 || SDL_strcmp( lastError, "(null)" ) == 0,
|
||||
"SDL_GetError(): expected message len 0, was len: %i",
|
||||
(int) len);
|
||||
}
|
||||
@@ -448,7 +443,7 @@ int platform_testSetErrorInvalidInput(void *arg)
|
||||
/* !
|
||||
* \brief Tests SDL_GetPowerInfo
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetPowerInfo
|
||||
* http://wiki.libsdl.org/SDL_GetPowerInfo
|
||||
*/
|
||||
int platform_testGetPowerInfo(void *arg)
|
||||
{
|
||||
|
||||
@@ -43,7 +43,7 @@ void _validateIntersectRectAndLineResults(
|
||||
* \brief Tests SDL_IntersectRectAndLine() clipping cases
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
|
||||
* http://wiki.libsdl.org/SDL_IntersectRectAndLine
|
||||
*/
|
||||
int
|
||||
rect_testIntersectRectAndLine (void *arg)
|
||||
@@ -114,7 +114,7 @@ rect_testIntersectRectAndLine (void *arg)
|
||||
* \brief Tests SDL_IntersectRectAndLine() non-clipping case line inside
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
|
||||
* http://wiki.libsdl.org/SDL_IntersectRectAndLine
|
||||
*/
|
||||
int
|
||||
rect_testIntersectRectAndLineInside (void *arg)
|
||||
@@ -181,7 +181,7 @@ rect_testIntersectRectAndLineInside (void *arg)
|
||||
* \brief Tests SDL_IntersectRectAndLine() non-clipping cases outside
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
|
||||
* http://wiki.libsdl.org/SDL_IntersectRectAndLine
|
||||
*/
|
||||
int
|
||||
rect_testIntersectRectAndLineOutside (void *arg)
|
||||
@@ -236,7 +236,7 @@ rect_testIntersectRectAndLineOutside (void *arg)
|
||||
* \brief Tests SDL_IntersectRectAndLine() with empty rectangle
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
|
||||
* http://wiki.libsdl.org/SDL_IntersectRectAndLine
|
||||
*/
|
||||
int
|
||||
rect_testIntersectRectAndLineEmpty (void *arg)
|
||||
@@ -271,7 +271,7 @@ rect_testIntersectRectAndLineEmpty (void *arg)
|
||||
* \brief Negative tests against SDL_IntersectRectAndLine() with invalid parameters
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRectAndLine
|
||||
* http://wiki.libsdl.org/SDL_IntersectRectAndLine
|
||||
*/
|
||||
int
|
||||
rect_testIntersectRectAndLineParam (void *arg)
|
||||
@@ -408,11 +408,37 @@ void _validateRectEqualsResults(
|
||||
refRectB->x, refRectB->y, refRectB->w, refRectB->h);
|
||||
}
|
||||
|
||||
/* !
|
||||
* \brief Private helper to check SDL_FRectEquals results
|
||||
*/
|
||||
void _validateFRectEqualsResults(
|
||||
SDL_bool equals, SDL_bool expectedEquals,
|
||||
SDL_FRect *rectA, SDL_FRect *rectB, SDL_FRect *refRectA, SDL_FRect *refRectB)
|
||||
{
|
||||
int cmpRes;
|
||||
SDLTest_AssertCheck(equals == expectedEquals,
|
||||
"Check for correct equals result: expected %s, got %s testing (%f,%f,%f,%f) and (%f,%f,%f,%f)",
|
||||
(expectedEquals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
|
||||
(equals == SDL_TRUE) ? "SDL_TRUE" : "SDL_FALSE",
|
||||
rectA->x, rectA->y, rectA->w, rectA->h,
|
||||
rectB->x, rectB->y, rectB->w, rectB->h);
|
||||
cmpRes = SDL_memcmp(rectA, refRectA, sizeof(*rectA));
|
||||
SDLTest_AssertCheck(cmpRes == 0,
|
||||
"Check that source rectangle A was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
|
||||
rectA->x, rectA->y, rectA->w, rectA->h,
|
||||
refRectA->x, refRectA->y, refRectA->w, refRectA->h);
|
||||
cmpRes = SDL_memcmp(rectB, refRectB, sizeof(*rectB));
|
||||
SDLTest_AssertCheck(cmpRes == 0,
|
||||
"Check that source rectangle B was not modified: got (%f,%f,%f,%f) expected (%f,%f,%f,%f)",
|
||||
rectB->x, rectB->y, rectB->w, rectB->h,
|
||||
refRectB->x, refRectB->y, refRectB->w, refRectB->h);
|
||||
}
|
||||
|
||||
/* !
|
||||
* \brief Tests SDL_IntersectRect() with B fully inside A
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
|
||||
* http://wiki.libsdl.org/SDL_IntersectRect
|
||||
*/
|
||||
int rect_testIntersectRectInside (void *arg)
|
||||
{
|
||||
@@ -440,7 +466,7 @@ int rect_testIntersectRectInside (void *arg)
|
||||
* \brief Tests SDL_IntersectRect() with B fully outside A
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
|
||||
* http://wiki.libsdl.org/SDL_IntersectRect
|
||||
*/
|
||||
int rect_testIntersectRectOutside (void *arg)
|
||||
{
|
||||
@@ -468,7 +494,7 @@ int rect_testIntersectRectOutside (void *arg)
|
||||
* \brief Tests SDL_IntersectRect() with B partially intersecting A
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
|
||||
* http://wiki.libsdl.org/SDL_IntersectRect
|
||||
*/
|
||||
int rect_testIntersectRectPartial (void *arg)
|
||||
{
|
||||
@@ -557,7 +583,7 @@ int rect_testIntersectRectPartial (void *arg)
|
||||
* \brief Tests SDL_IntersectRect() with 1x1 pixel sized rectangles
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
|
||||
* http://wiki.libsdl.org/SDL_IntersectRect
|
||||
*/
|
||||
int rect_testIntersectRectPoint (void *arg)
|
||||
{
|
||||
@@ -604,7 +630,7 @@ int rect_testIntersectRectPoint (void *arg)
|
||||
* \brief Tests SDL_IntersectRect() with empty rectangles
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
|
||||
* http://wiki.libsdl.org/SDL_IntersectRect
|
||||
*/
|
||||
int rect_testIntersectRectEmpty (void *arg)
|
||||
{
|
||||
@@ -676,7 +702,7 @@ int rect_testIntersectRectEmpty (void *arg)
|
||||
* \brief Negative tests against SDL_IntersectRect() with invalid parameters
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_IntersectRect
|
||||
* http://wiki.libsdl.org/SDL_IntersectRect
|
||||
*/
|
||||
int rect_testIntersectRectParam(void *arg)
|
||||
{
|
||||
@@ -706,7 +732,7 @@ int rect_testIntersectRectParam(void *arg)
|
||||
* \brief Tests SDL_HasIntersection() with B fully inside A
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
|
||||
* http://wiki.libsdl.org/SDL_HasIntersection
|
||||
*/
|
||||
int rect_testHasIntersectionInside (void *arg)
|
||||
{
|
||||
@@ -733,7 +759,7 @@ int rect_testHasIntersectionInside (void *arg)
|
||||
* \brief Tests SDL_HasIntersection() with B fully outside A
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
|
||||
* http://wiki.libsdl.org/SDL_HasIntersection
|
||||
*/
|
||||
int rect_testHasIntersectionOutside (void *arg)
|
||||
{
|
||||
@@ -760,7 +786,7 @@ int rect_testHasIntersectionOutside (void *arg)
|
||||
* \brief Tests SDL_HasIntersection() with B partially intersecting A
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
|
||||
* http://wiki.libsdl.org/SDL_HasIntersection
|
||||
*/
|
||||
int rect_testHasIntersectionPartial (void *arg)
|
||||
{
|
||||
@@ -827,7 +853,7 @@ int rect_testHasIntersectionPartial (void *arg)
|
||||
* \brief Tests SDL_HasIntersection() with 1x1 pixel sized rectangles
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
|
||||
* http://wiki.libsdl.org/SDL_HasIntersection
|
||||
*/
|
||||
int rect_testHasIntersectionPoint (void *arg)
|
||||
{
|
||||
@@ -873,7 +899,7 @@ int rect_testHasIntersectionPoint (void *arg)
|
||||
* \brief Tests SDL_HasIntersection() with empty rectangles
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
|
||||
* http://wiki.libsdl.org/SDL_HasIntersection
|
||||
*/
|
||||
int rect_testHasIntersectionEmpty (void *arg)
|
||||
{
|
||||
@@ -931,7 +957,7 @@ int rect_testHasIntersectionEmpty (void *arg)
|
||||
* \brief Negative tests against SDL_HasIntersection() with invalid parameters
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_HasIntersection
|
||||
* http://wiki.libsdl.org/SDL_HasIntersection
|
||||
*/
|
||||
int rect_testHasIntersectionParam(void *arg)
|
||||
{
|
||||
@@ -954,7 +980,7 @@ int rect_testHasIntersectionParam(void *arg)
|
||||
* \brief Test SDL_EnclosePoints() without clipping
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
|
||||
* http://wiki.libsdl.org/SDL_EnclosePoints
|
||||
*/
|
||||
int rect_testEnclosePoints(void *arg)
|
||||
{
|
||||
@@ -1024,7 +1050,7 @@ int rect_testEnclosePoints(void *arg)
|
||||
* \brief Test SDL_EnclosePoints() with repeated input points
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
|
||||
* http://wiki.libsdl.org/SDL_EnclosePoints
|
||||
*/
|
||||
int rect_testEnclosePointsRepeatedInput(void *arg)
|
||||
{
|
||||
@@ -1100,7 +1126,7 @@ int rect_testEnclosePointsRepeatedInput(void *arg)
|
||||
* \brief Test SDL_EnclosePoints() with clipping
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
|
||||
* http://wiki.libsdl.org/SDL_EnclosePoints
|
||||
*/
|
||||
int rect_testEnclosePointsWithClipping(void *arg)
|
||||
{
|
||||
@@ -1199,7 +1225,7 @@ int rect_testEnclosePointsWithClipping(void *arg)
|
||||
* \brief Negative tests against SDL_EnclosePoints() with invalid parameters
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_EnclosePoints
|
||||
* http://wiki.libsdl.org/SDL_EnclosePoints
|
||||
*/
|
||||
int rect_testEnclosePointsParam(void *arg)
|
||||
{
|
||||
@@ -1227,7 +1253,7 @@ int rect_testEnclosePointsParam(void *arg)
|
||||
* \brief Tests SDL_UnionRect() where rect B is outside rect A
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
|
||||
* http://wiki.libsdl.org/SDL_UnionRect
|
||||
*/
|
||||
int rect_testUnionRectOutside(void *arg)
|
||||
{
|
||||
@@ -1298,7 +1324,7 @@ int rect_testUnionRectOutside(void *arg)
|
||||
* \brief Tests SDL_UnionRect() where rect A or rect B are empty
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
|
||||
* http://wiki.libsdl.org/SDL_UnionRect
|
||||
*/
|
||||
int rect_testUnionRectEmpty(void *arg)
|
||||
{
|
||||
@@ -1363,7 +1389,7 @@ int rect_testUnionRectEmpty(void *arg)
|
||||
* \brief Tests SDL_UnionRect() where rect B is inside rect A
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
|
||||
* http://wiki.libsdl.org/SDL_UnionRect
|
||||
*/
|
||||
int rect_testUnionRectInside(void *arg)
|
||||
{
|
||||
@@ -1427,7 +1453,7 @@ int rect_testUnionRectInside(void *arg)
|
||||
* \brief Negative tests against SDL_UnionRect() with invalid parameters
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_UnionRect
|
||||
* http://wiki.libsdl.org/SDL_UnionRect
|
||||
*/
|
||||
int rect_testUnionRectParam(void *arg)
|
||||
{
|
||||
@@ -1455,7 +1481,7 @@ int rect_testUnionRectParam(void *arg)
|
||||
* \brief Tests SDL_RectEmpty() with various inputs
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
|
||||
* http://wiki.libsdl.org/SDL_RectEmpty
|
||||
*/
|
||||
int rect_testRectEmpty(void *arg)
|
||||
{
|
||||
@@ -1498,7 +1524,7 @@ int rect_testRectEmpty(void *arg)
|
||||
* \brief Negative tests against SDL_RectEmpty() with invalid parameters
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RectEmpty
|
||||
* http://wiki.libsdl.org/SDL_RectEmpty
|
||||
*/
|
||||
int rect_testRectEmptyParam(void *arg)
|
||||
{
|
||||
@@ -1515,7 +1541,7 @@ int rect_testRectEmptyParam(void *arg)
|
||||
* \brief Tests SDL_RectEquals() with various inputs
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RectEquals
|
||||
* http://wiki.libsdl.org/SDL_RectEquals
|
||||
*/
|
||||
int rect_testRectEquals(void *arg)
|
||||
{
|
||||
@@ -1545,7 +1571,7 @@ int rect_testRectEquals(void *arg)
|
||||
* \brief Negative tests against SDL_RectEquals() with invalid parameters
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RectEquals
|
||||
* http://wiki.libsdl.org/SDL_RectEquals
|
||||
*/
|
||||
int rect_testRectEqualsParam(void *arg)
|
||||
{
|
||||
@@ -1574,6 +1600,69 @@ int rect_testRectEqualsParam(void *arg)
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* !
|
||||
* \brief Tests SDL_FRectEquals() with various inputs
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/SDL_FRectEquals
|
||||
*/
|
||||
int rect_testFRectEquals(void *arg)
|
||||
{
|
||||
SDL_FRect refRectA;
|
||||
SDL_FRect refRectB;
|
||||
SDL_FRect rectA;
|
||||
SDL_FRect rectB;
|
||||
SDL_bool expectedResult;
|
||||
SDL_bool result;
|
||||
|
||||
/* Equals */
|
||||
refRectA.x=(float)SDLTest_RandomIntegerInRange(-1024, 1024);
|
||||
refRectA.y=(float)SDLTest_RandomIntegerInRange(-1024, 1024);
|
||||
refRectA.w=(float)SDLTest_RandomIntegerInRange(1, 1024);
|
||||
refRectA.h=(float)SDLTest_RandomIntegerInRange(1, 1024);
|
||||
refRectB = refRectA;
|
||||
expectedResult = SDL_TRUE;
|
||||
rectA = refRectA;
|
||||
rectB = refRectB;
|
||||
result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)&rectA, (const SDL_FRect *)&rectB);
|
||||
_validateFRectEqualsResults(result, expectedResult, &rectA, &rectB, &refRectA, &refRectB);
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* !
|
||||
* \brief Negative tests against SDL_FRectEquals() with invalid parameters
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/SDL_FRectEquals
|
||||
*/
|
||||
int rect_testFRectEqualsParam(void *arg)
|
||||
{
|
||||
SDL_FRect rectA;
|
||||
SDL_FRect rectB;
|
||||
SDL_bool result;
|
||||
|
||||
/* data setup -- For the purpose of this test, the values don't matter. */
|
||||
rectA.x=SDLTest_RandomFloat();
|
||||
rectA.y=SDLTest_RandomFloat();
|
||||
rectA.w=SDLTest_RandomFloat();
|
||||
rectA.h=SDLTest_RandomFloat();
|
||||
rectB.x=SDLTest_RandomFloat();
|
||||
rectB.y=SDLTest_RandomFloat();
|
||||
rectB.w=SDLTest_RandomFloat();
|
||||
rectB.h=SDLTest_RandomFloat();
|
||||
|
||||
/* invalid parameter combinations */
|
||||
result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)NULL, (const SDL_FRect *)&rectB);
|
||||
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st parameter is NULL");
|
||||
result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)&rectA, (const SDL_FRect *)NULL);
|
||||
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 2nd parameter is NULL");
|
||||
result = (SDL_bool)SDL_FRectEquals((const SDL_FRect *)NULL, (const SDL_FRect *)NULL);
|
||||
SDLTest_AssertCheck(result == SDL_FALSE, "Check that function returns SDL_FALSE when 1st and 2nd parameter are NULL");
|
||||
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* ================= Test References ================== */
|
||||
|
||||
/* Rect test cases */
|
||||
@@ -1673,17 +1762,24 @@ static const SDLTest_TestCaseReference rectTest28 =
|
||||
static const SDLTest_TestCaseReference rectTest29 =
|
||||
{ (SDLTest_TestCaseFp)rect_testRectEqualsParam, "rect_testRectEqualsParam", "Negative tests against SDL_RectEquals with invalid parameters", TEST_ENABLED };
|
||||
|
||||
/* SDL_FRectEquals */
|
||||
|
||||
static const SDLTest_TestCaseReference rectTest30 =
|
||||
{ (SDLTest_TestCaseFp)rect_testFRectEquals, "rect_testFRectEquals", "Tests SDL_FRectEquals with various inputs", TEST_ENABLED };
|
||||
|
||||
static const SDLTest_TestCaseReference rectTest31 =
|
||||
{ (SDLTest_TestCaseFp)rect_testFRectEqualsParam, "rect_testFRectEqualsParam", "Negative tests against SDL_FRectEquals with invalid parameters", TEST_ENABLED };
|
||||
|
||||
/* !
|
||||
* \brief Sequence of Rect test cases; functions that handle simple rectangles including overlaps and merges.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/CategoryRect
|
||||
* http://wiki.libsdl.org/CategoryRect
|
||||
*/
|
||||
static const SDLTest_TestCaseReference *rectTests[] = {
|
||||
&rectTest1, &rectTest2, &rectTest3, &rectTest4, &rectTest5, &rectTest6, &rectTest7, &rectTest8, &rectTest9, &rectTest10, &rectTest11, &rectTest12, &rectTest13, &rectTest14,
|
||||
&rectTest15, &rectTest16, &rectTest17, &rectTest18, &rectTest19, &rectTest20, &rectTest21, &rectTest22, &rectTest23, &rectTest24, &rectTest25, &rectTest26, &rectTest27,
|
||||
&rectTest28, &rectTest29, NULL
|
||||
&rectTest28, &rectTest29, &rectTest30, &rectTest31, NULL
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ void CleanupDestroyRenderer(void *arg)
|
||||
* @brief Tests call to SDL_GetNumRenderDrivers
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetNumRenderDrivers
|
||||
* http://wiki.libsdl.org/SDL_GetNumRenderDrivers
|
||||
*/
|
||||
int
|
||||
render_testGetNumRenderDrivers(void *arg)
|
||||
@@ -99,9 +99,9 @@ render_testGetNumRenderDrivers(void *arg)
|
||||
* @brief Tests the SDL primitives for rendering.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RenderFillRect
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RenderDrawLine
|
||||
* http://wiki.libsdl.org/SDL_SetRenderDrawColor
|
||||
* http://wiki.libsdl.org/SDL_RenderFillRect
|
||||
* http://wiki.libsdl.org/SDL_RenderDrawLine
|
||||
*
|
||||
*/
|
||||
int render_testPrimitives (void *arg)
|
||||
@@ -187,14 +187,14 @@ int render_testPrimitives (void *arg)
|
||||
|
||||
ret = SDL_RenderDrawLine(renderer, 79, 59, 50, 30 );
|
||||
SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
|
||||
|
||||
/* Make current */
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
|
||||
/* See if it's the same. */
|
||||
referenceSurface = SDLTest_ImagePrimitives();
|
||||
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
|
||||
|
||||
/* Make current */
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(referenceSurface);
|
||||
referenceSurface = NULL;
|
||||
@@ -206,9 +206,9 @@ int render_testPrimitives (void *arg)
|
||||
* @brief Tests the SDL primitives with alpha for rendering.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawBlendMode
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RenderFillRect
|
||||
* http://wiki.libsdl.org/SDL_SetRenderDrawColor
|
||||
* http://wiki.libsdl.org/SDL_SetRenderDrawBlendMode
|
||||
* http://wiki.libsdl.org/SDL_RenderFillRect
|
||||
*/
|
||||
int render_testPrimitivesBlend (void *arg)
|
||||
{
|
||||
@@ -335,13 +335,13 @@ int render_testPrimitivesBlend (void *arg)
|
||||
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
|
||||
SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_RenderDrawPoint, expected: 0, got: %i", checkFailCount3);
|
||||
|
||||
/* Make current */
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
/* See if it's the same. */
|
||||
referenceSurface = SDLTest_ImagePrimitivesBlend();
|
||||
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
|
||||
|
||||
/* Make current */
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_FreeSurface(referenceSurface);
|
||||
referenceSurface = NULL;
|
||||
@@ -355,8 +355,8 @@ int render_testPrimitivesBlend (void *arg)
|
||||
* @brief Tests some blitting routines.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
|
||||
* http://wiki.libsdl.org/SDL_RenderCopy
|
||||
* http://wiki.libsdl.org/SDL_DestroyTexture
|
||||
*/
|
||||
int
|
||||
render_testBlit(void *arg)
|
||||
@@ -404,13 +404,13 @@ render_testBlit(void *arg)
|
||||
}
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount1);
|
||||
|
||||
/* Make current */
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
/* See if it's the same */
|
||||
referenceSurface = SDLTest_ImageBlit();
|
||||
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
|
||||
|
||||
/* Make current */
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_DestroyTexture( tface );
|
||||
SDL_FreeSurface(referenceSurface);
|
||||
@@ -424,9 +424,9 @@ render_testBlit(void *arg)
|
||||
* @brief Blits doing color tests.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorMod
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
|
||||
* http://wiki.libsdl.org/SDL_SetTextureColorMod
|
||||
* http://wiki.libsdl.org/SDL_RenderCopy
|
||||
* http://wiki.libsdl.org/SDL_DestroyTexture
|
||||
*/
|
||||
int
|
||||
render_testBlitColor (void *arg)
|
||||
@@ -478,13 +478,13 @@ render_testBlitColor (void *arg)
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
|
||||
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
|
||||
|
||||
/* Make current */
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
/* See if it's the same. */
|
||||
referenceSurface = SDLTest_ImageBlitColor();
|
||||
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
|
||||
|
||||
/* Make current */
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_DestroyTexture( tface );
|
||||
SDL_FreeSurface(referenceSurface);
|
||||
@@ -498,9 +498,9 @@ render_testBlitColor (void *arg)
|
||||
* @brief Tests blitting with alpha.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetTextureAlphaMod
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
|
||||
* http://wiki.libsdl.org/SDL_SetTextureAlphaMod
|
||||
* http://wiki.libsdl.org/SDL_RenderCopy
|
||||
* http://wiki.libsdl.org/SDL_DestroyTexture
|
||||
*/
|
||||
int
|
||||
render_testBlitAlpha (void *arg)
|
||||
@@ -555,13 +555,13 @@ render_testBlitAlpha (void *arg)
|
||||
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", checkFailCount1);
|
||||
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
|
||||
|
||||
/* Make current */
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
/* See if it's the same. */
|
||||
referenceSurface = SDLTest_ImageBlitAlpha();
|
||||
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
|
||||
|
||||
/* Make current */
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
/* Clean up. */
|
||||
SDL_DestroyTexture( tface );
|
||||
SDL_FreeSurface(referenceSurface);
|
||||
@@ -576,8 +576,8 @@ render_testBlitAlpha (void *arg)
|
||||
* @brief Tests a blend mode.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetTextureBlendMode
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy
|
||||
* http://wiki.libsdl.org/SDL_SetTextureBlendMode
|
||||
* http://wiki.libsdl.org/SDL_RenderCopy
|
||||
*/
|
||||
static void
|
||||
_testBlitBlendMode( SDL_Texture * tface, int mode )
|
||||
@@ -626,10 +626,10 @@ _testBlitBlendMode( SDL_Texture * tface, int mode )
|
||||
* @brief Tests some more blitting routines.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorMod
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetTextureAlphaMod
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetTextureBlendMode
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
|
||||
* http://wiki.libsdl.org/SDL_SetTextureColorMod
|
||||
* http://wiki.libsdl.org/SDL_SetTextureAlphaMod
|
||||
* http://wiki.libsdl.org/SDL_SetTextureBlendMode
|
||||
* http://wiki.libsdl.org/SDL_DestroyTexture
|
||||
*/
|
||||
int
|
||||
render_testBlitBlend (void *arg)
|
||||
@@ -674,9 +674,10 @@ render_testBlitBlend (void *arg)
|
||||
_testBlitBlendMode( tface, SDL_BLENDMODE_NONE );
|
||||
referenceSurface = SDLTest_ImageBlitBlendNone();
|
||||
|
||||
/* Make current and compare */
|
||||
SDL_RenderPresent(renderer);
|
||||
/* Compare, then Present */
|
||||
_compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_FreeSurface(referenceSurface);
|
||||
referenceSurface = NULL;
|
||||
|
||||
@@ -684,9 +685,10 @@ render_testBlitBlend (void *arg)
|
||||
_testBlitBlendMode( tface, SDL_BLENDMODE_BLEND );
|
||||
referenceSurface = SDLTest_ImageBlitBlend();
|
||||
|
||||
/* Make current and compare */
|
||||
SDL_RenderPresent(renderer);
|
||||
/* Compare, then Present */
|
||||
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_FreeSurface(referenceSurface);
|
||||
referenceSurface = NULL;
|
||||
|
||||
@@ -694,9 +696,10 @@ render_testBlitBlend (void *arg)
|
||||
_testBlitBlendMode( tface, SDL_BLENDMODE_ADD );
|
||||
referenceSurface = SDLTest_ImageBlitBlendAdd();
|
||||
|
||||
/* Make current and compare */
|
||||
SDL_RenderPresent(renderer);
|
||||
/* Compare, then Present */
|
||||
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_FreeSurface(referenceSurface);
|
||||
referenceSurface = NULL;
|
||||
|
||||
@@ -704,9 +707,10 @@ render_testBlitBlend (void *arg)
|
||||
_testBlitBlendMode( tface, SDL_BLENDMODE_MOD);
|
||||
referenceSurface = SDLTest_ImageBlitBlendMod();
|
||||
|
||||
/* Make current and compare */
|
||||
SDL_RenderPresent(renderer);
|
||||
/* Compare, then Present */
|
||||
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_FreeSurface(referenceSurface);
|
||||
referenceSurface = NULL;
|
||||
|
||||
@@ -753,12 +757,13 @@ render_testBlitBlend (void *arg)
|
||||
/* Clean up. */
|
||||
SDL_DestroyTexture( tface );
|
||||
|
||||
/* Make current */
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
/* Check to see if final image matches. */
|
||||
referenceSurface = SDLTest_ImageBlitBlendAll();
|
||||
_compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
|
||||
|
||||
/* Make current */
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
SDL_FreeSurface(referenceSurface);
|
||||
referenceSurface = NULL;
|
||||
|
||||
@@ -779,8 +784,8 @@ _isSupported( int code )
|
||||
* @brief Test to see if we can vary the draw color. Helper function.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetRenderDrawColor
|
||||
* http://wiki.libsdl.org/SDL_SetRenderDrawColor
|
||||
* http://wiki.libsdl.org/SDL_GetRenderDrawColor
|
||||
*/
|
||||
static int
|
||||
_hasDrawColor (void)
|
||||
@@ -817,8 +822,8 @@ _hasDrawColor (void)
|
||||
* @brief Test to see if we can vary the blend mode. Helper function.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawBlendMode
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetRenderDrawBlendMode
|
||||
* http://wiki.libsdl.org/SDL_SetRenderDrawBlendMode
|
||||
* http://wiki.libsdl.org/SDL_GetRenderDrawBlendMode
|
||||
*/
|
||||
static int
|
||||
_hasBlendModes (void)
|
||||
@@ -874,7 +879,7 @@ _hasBlendModes (void)
|
||||
* @brief Loads the test image 'Face' as texture. Helper function.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_CreateTextureFromSurface
|
||||
* http://wiki.libsdl.org/SDL_CreateTextureFromSurface
|
||||
*/
|
||||
static SDL_Texture *
|
||||
_loadTestFace(void)
|
||||
@@ -902,9 +907,9 @@ _loadTestFace(void)
|
||||
* @brief Test to see if can set texture color mode. Helper function.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorMod
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetTextureColorMod
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
|
||||
* http://wiki.libsdl.org/SDL_SetTextureColorMod
|
||||
* http://wiki.libsdl.org/SDL_GetTextureColorMod
|
||||
* http://wiki.libsdl.org/SDL_DestroyTexture
|
||||
*/
|
||||
static int
|
||||
_hasTexColor (void)
|
||||
@@ -942,9 +947,9 @@ _hasTexColor (void)
|
||||
* @brief Test to see if we can vary the alpha of the texture. Helper function.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetTextureAlphaMod
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_GetTextureAlphaMod
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
|
||||
* http://wiki.libsdl.org/SDL_SetTextureAlphaMod
|
||||
* http://wiki.libsdl.org/SDL_GetTextureAlphaMod
|
||||
* http://wiki.libsdl.org/SDL_DestroyTexture
|
||||
*/
|
||||
static int
|
||||
_hasTexAlpha(void)
|
||||
@@ -984,9 +989,9 @@ _hasTexAlpha(void)
|
||||
* @param s Image to compare against.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RenderReadPixels
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_CreateRGBSurfaceFrom
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_FreeSurface
|
||||
* http://wiki.libsdl.org/SDL_RenderReadPixels
|
||||
* http://wiki.libsdl.org/SDL_CreateRGBSurfaceFrom
|
||||
* http://wiki.libsdl.org/SDL_FreeSurface
|
||||
*/
|
||||
static void
|
||||
_compare(SDL_Surface *referenceSurface, int allowable_error)
|
||||
@@ -1027,10 +1032,10 @@ _compare(SDL_Surface *referenceSurface, int allowable_error)
|
||||
* @brief Clears the screen. Helper function.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RenderClear
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RenderPresent
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawBlendMode
|
||||
* http://wiki.libsdl.org/SDL_SetRenderDrawColor
|
||||
* http://wiki.libsdl.org/SDL_RenderClear
|
||||
* http://wiki.libsdl.org/SDL_RenderPresent
|
||||
* http://wiki.libsdl.org/SDL_SetRenderDrawBlendMode
|
||||
*/
|
||||
static int
|
||||
_clearScreen(void)
|
||||
|
||||
@@ -88,8 +88,8 @@ RWopsTearDown(void *arg)
|
||||
* @brief Makes sure parameters work properly. Local helper function.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWseek
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWread
|
||||
* http://wiki.libsdl.org/SDL_RWseek
|
||||
* http://wiki.libsdl.org/SDL_RWread
|
||||
*/
|
||||
void
|
||||
_testGenericRWopsValidations(SDL_RWops *rw, int write)
|
||||
@@ -168,7 +168,7 @@ _testGenericRWopsValidations(SDL_RWops *rw, int write)
|
||||
/* !
|
||||
* Negative test for SDL_RWFromFile parameters
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
|
||||
* \sa http://wiki.libsdl.org/SDL_RWFromFile
|
||||
*
|
||||
*/
|
||||
int
|
||||
@@ -215,8 +215,8 @@ rwops_testParamNegative (void)
|
||||
/**
|
||||
* @brief Tests opening from memory.
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
* \sa http://wiki.libsdl.org/SDL_RWFromMem
|
||||
* \sa http://wiki.libsdl.org/SDL_RWClose
|
||||
*/
|
||||
int
|
||||
rwops_testMem (void)
|
||||
@@ -255,8 +255,8 @@ rwops_testMem (void)
|
||||
* @brief Tests opening from memory.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromConstMem
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
* http://wiki.libsdl.org/SDL_RWFromConstMem
|
||||
* http://wiki.libsdl.org/SDL_RWClose
|
||||
*/
|
||||
int
|
||||
rwops_testConstMem (void)
|
||||
@@ -291,8 +291,8 @@ rwops_testConstMem (void)
|
||||
* @brief Tests reading from file.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
* http://wiki.libsdl.org/SDL_RWFromFile
|
||||
* http://wiki.libsdl.org/SDL_RWClose
|
||||
*/
|
||||
int
|
||||
rwops_testFileRead(void)
|
||||
@@ -338,8 +338,8 @@ rwops_testFileRead(void)
|
||||
* @brief Tests writing from file.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
* http://wiki.libsdl.org/SDL_RWFromFile
|
||||
* http://wiki.libsdl.org/SDL_RWClose
|
||||
*/
|
||||
int
|
||||
rwops_testFileWrite(void)
|
||||
@@ -386,8 +386,8 @@ rwops_testFileWrite(void)
|
||||
* @brief Tests reading from file handle
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
* http://wiki.libsdl.org/SDL_RWFromFP
|
||||
* http://wiki.libsdl.org/SDL_RWClose
|
||||
*
|
||||
*/
|
||||
int
|
||||
@@ -436,8 +436,8 @@ rwops_testFPRead(void)
|
||||
* @brief Tests writing to file handle
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFP
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
* http://wiki.libsdl.org/SDL_RWFromFP
|
||||
* http://wiki.libsdl.org/SDL_RWClose
|
||||
*
|
||||
*/
|
||||
int
|
||||
@@ -484,8 +484,8 @@ rwops_testFPWrite(void)
|
||||
/**
|
||||
* @brief Tests alloc and free RW context.
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_AllocRW
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_FreeRW
|
||||
* \sa http://wiki.libsdl.org/SDL_AllocRW
|
||||
* \sa http://wiki.libsdl.org/SDL_FreeRW
|
||||
*/
|
||||
int
|
||||
rwops_testAllocFree (void)
|
||||
@@ -511,8 +511,8 @@ rwops_testAllocFree (void)
|
||||
/**
|
||||
* @brief Compare memory and file reads
|
||||
*
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromMem
|
||||
* \sa http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
|
||||
* \sa http://wiki.libsdl.org/SDL_RWFromMem
|
||||
* \sa http://wiki.libsdl.org/SDL_RWFromFile
|
||||
*/
|
||||
int
|
||||
rwops_testCompareRWFromMemWithRWFromFile(void)
|
||||
@@ -578,10 +578,10 @@ rwops_testCompareRWFromMemWithRWFromFile(void)
|
||||
* @brief Tests writing and reading from file using endian aware functions.
|
||||
*
|
||||
* \sa
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWFromFile
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_RWClose
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_ReadBE16
|
||||
* http://wiki.libsdl.org/moin.cgi/SDL_WriteBE16
|
||||
* http://wiki.libsdl.org/SDL_RWFromFile
|
||||
* http://wiki.libsdl.org/SDL_RWClose
|
||||
* http://wiki.libsdl.org/SDL_ReadBE16
|
||||
* http://wiki.libsdl.org/SDL_WriteBE16
|
||||
*/
|
||||
int
|
||||
rwops_testFileWriteReadEndian(void)
|
||||
|
||||
@@ -89,7 +89,6 @@ int
|
||||
sdltest_randomNumber(void *arg)
|
||||
{
|
||||
Sint64 result;
|
||||
Uint64 uresult;
|
||||
double dresult;
|
||||
Uint64 umax;
|
||||
Sint64 min, max;
|
||||
@@ -127,7 +126,7 @@ sdltest_randomNumber(void *arg)
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomSint32");
|
||||
SDLTest_AssertCheck(result >= min && result <= max, "Verify result value, expected: [%"SDL_PRIs64",%"SDL_PRIs64"], got: %"SDL_PRIs64, min, max, result);
|
||||
|
||||
uresult = SDLTest_RandomUint64();
|
||||
SDLTest_RandomUint64();
|
||||
SDLTest_AssertPass("Call to SDLTest_RandomUint64");
|
||||
|
||||
result = SDLTest_RandomSint64();
|
||||
@@ -1132,7 +1131,7 @@ sdltest_randomAsciiString(void *arg)
|
||||
SDLTest_AssertCheck(len >= 1 && len <= 255, "Validate that result length; expected: len=[1,255], got: %d", (int) len);
|
||||
nonAsciiCharacters = 0;
|
||||
for (i=0; i<len; i++) {
|
||||
if (iscntrl(result[i])) {
|
||||
if (SDL_iscntrl(result[i])) {
|
||||
nonAsciiCharacters++;
|
||||
}
|
||||
}
|
||||
@@ -1170,7 +1169,7 @@ sdltest_randomAsciiStringWithMaximumLength(void *arg)
|
||||
SDLTest_AssertCheck(len >= 1 && len <= targetLen, "Validate that result length; expected: len=[1,%d], got: %d", (int) targetLen, (int) len);
|
||||
nonAsciiCharacters = 0;
|
||||
for (i=0; i<len; i++) {
|
||||
if (iscntrl(result[i])) {
|
||||
if (SDL_iscntrl(result[i])) {
|
||||
nonAsciiCharacters++;
|
||||
}
|
||||
}
|
||||
@@ -1224,7 +1223,7 @@ sdltest_randomAsciiStringOfSize(void *arg)
|
||||
SDLTest_AssertCheck(len == targetLen, "Validate that result length; expected: len=%d, got: %d", (int) targetLen, (int) len);
|
||||
nonAsciiCharacters = 0;
|
||||
for (i=0; i<len; i++) {
|
||||
if (iscntrl(result[i])) {
|
||||
if (SDL_iscntrl(result[i])) {
|
||||
nonAsciiCharacters++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ int
|
||||
stdlib_snprintf(void *arg)
|
||||
{
|
||||
int result;
|
||||
int predicted;
|
||||
char text[1024];
|
||||
const char *expected;
|
||||
|
||||
@@ -60,55 +61,86 @@ stdlib_snprintf(void *arg)
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||
|
||||
result = SDL_snprintf(NULL, 0, "%s", "foo");
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(NULL, 0, \"%%s\", \"foo\")");
|
||||
SDLTest_AssertCheck(result == 3, "Check result value, expected: 3, got: %d", result);
|
||||
|
||||
result = SDL_snprintf(text, 2, "%s\n", "foo");
|
||||
expected = "f";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%s\\n\", \"foo\") with buffer size 2");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == 4, "Check result value, expected: 4, got: %d", result);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%f", 0.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%f", 0.0);
|
||||
expected = "0.000000";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 0.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%f", 1.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%f", 1.0);
|
||||
expected = "1.000000";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%.f", 1.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%.f", 1.0);
|
||||
expected = "1";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%#.f", 1.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%#.f", 1.0);
|
||||
expected = "1.";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%#.f\", 1.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%f", 1.0 + 1.0 / 3.0);
|
||||
expected = "1.333333";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%+f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%+f", 1.0 + 1.0 / 3.0);
|
||||
expected = "+1.333333";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%+f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%.2f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "1.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: %s, got: %s", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%6.2f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%6.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = " 1.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%6.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, sizeof(text), "%06.2f", 1.0 + 1.0 / 3.0);
|
||||
predicted = SDL_snprintf(NULL, 0, "%06.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "001.33";
|
||||
SDLTest_AssertPass("Call to SDL_snprintf(\"%%06.2f\", 1.0 + 1.0 / 3.0)");
|
||||
SDLTest_AssertCheck(SDL_strcmp(text, expected) == 0, "Check text, expected: '%s', got: '%s'", expected, text);
|
||||
SDLTest_AssertCheck(result == SDL_strlen(text), "Check result value, expected: %d, got: %d", (int) SDL_strlen(text), result);
|
||||
SDLTest_AssertCheck(predicted == result, "Check predicted value, expected: %d, got: %d", result, predicted);
|
||||
|
||||
result = SDL_snprintf(text, 5, "%06.2f", 1.0 + 1.0 / 3.0);
|
||||
expected = "001.";
|
||||
|
||||
@@ -265,7 +265,7 @@ video_createWindowVariousFlags(void *arg)
|
||||
w = SDLTest_RandomIntegerInRange(320, 1024);
|
||||
h = SDLTest_RandomIntegerInRange(320, 768);
|
||||
|
||||
for (fVariation = 0; fVariation < 13; fVariation++) {
|
||||
for (fVariation = 0; fVariation < 14; fVariation++) {
|
||||
switch(fVariation) {
|
||||
case 0:
|
||||
flags = SDL_WINDOW_FULLSCREEN;
|
||||
@@ -299,7 +299,7 @@ video_createWindowVariousFlags(void *arg)
|
||||
flags = SDL_WINDOW_MAXIMIZED;
|
||||
break;
|
||||
case 9:
|
||||
flags = SDL_WINDOW_INPUT_GRABBED;
|
||||
flags = SDL_WINDOW_MOUSE_GRABBED;
|
||||
break;
|
||||
case 10:
|
||||
flags = SDL_WINDOW_INPUT_FOCUS;
|
||||
@@ -310,6 +310,9 @@ video_createWindowVariousFlags(void *arg)
|
||||
case 12:
|
||||
flags = SDL_WINDOW_FOREIGN;
|
||||
break;
|
||||
case 13:
|
||||
flags = SDL_WINDOW_KEYBOARD_GRABBED;
|
||||
break;
|
||||
}
|
||||
|
||||
window = SDL_CreateWindow(title, x, y, w, h, flags);
|
||||
@@ -474,7 +477,6 @@ video_getClosestDisplayModeRandomResolution(void *arg)
|
||||
{
|
||||
SDL_DisplayMode target;
|
||||
SDL_DisplayMode closest;
|
||||
SDL_DisplayMode* dResult;
|
||||
int displayNum;
|
||||
int i;
|
||||
int variation;
|
||||
@@ -497,7 +499,7 @@ video_getClosestDisplayModeRandomResolution(void *arg)
|
||||
target.driverdata = 0;
|
||||
|
||||
/* Make call; may or may not find anything, so don't validate any further */
|
||||
dResult = SDL_GetClosestDisplayMode(i, &target, &closest);
|
||||
SDL_GetClosestDisplayMode(i, &target, &closest);
|
||||
SDLTest_AssertPass("Call to SDL_GetClosestDisplayMode(target=random/variation%d)", variation);
|
||||
}
|
||||
}
|
||||
@@ -508,7 +510,7 @@ video_getClosestDisplayModeRandomResolution(void *arg)
|
||||
/**
|
||||
* @brief Tests call to SDL_GetWindowBrightness
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowBrightness
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowBrightness
|
||||
*/
|
||||
int
|
||||
video_getWindowBrightness(void *arg)
|
||||
@@ -534,7 +536,7 @@ video_getWindowBrightness(void *arg)
|
||||
/**
|
||||
* @brief Tests call to SDL_GetWindowBrightness with invalid input
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowBrightness
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowBrightness
|
||||
*/
|
||||
int
|
||||
video_getWindowBrightnessNegative(void *arg)
|
||||
@@ -563,7 +565,7 @@ video_getWindowBrightnessNegative(void *arg)
|
||||
/**
|
||||
* @brief Tests call to SDL_GetWindowDisplayMode
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowDisplayMode
|
||||
*/
|
||||
int
|
||||
video_getWindowDisplayMode(void *arg)
|
||||
@@ -617,7 +619,7 @@ void _checkInvalidWindowError()
|
||||
/**
|
||||
* @brief Tests call to SDL_GetWindowDisplayMode with invalid input
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowDisplayMode
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowDisplayMode
|
||||
*/
|
||||
int
|
||||
video_getWindowDisplayModeNegative(void *arg)
|
||||
@@ -661,7 +663,7 @@ video_getWindowDisplayModeNegative(void *arg)
|
||||
/**
|
||||
* @brief Tests call to SDL_GetWindowGammaRamp
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowGammaRamp
|
||||
*/
|
||||
int
|
||||
video_getWindowGammaRamp(void *arg)
|
||||
@@ -722,7 +724,7 @@ video_getWindowGammaRamp(void *arg)
|
||||
/**
|
||||
* @brief Tests call to SDL_GetWindowGammaRamp with invalid input
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGammaRamp
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowGammaRamp
|
||||
*/
|
||||
int
|
||||
video_getWindowGammaRampNegative(void *arg)
|
||||
@@ -744,87 +746,213 @@ video_getWindowGammaRampNegative(void *arg)
|
||||
return TEST_COMPLETED;
|
||||
}
|
||||
|
||||
/* Helper for setting and checking the window grab state */
|
||||
/* Helper for setting and checking the window mouse grab state */
|
||||
void
|
||||
_setAndCheckWindowGrabState(SDL_Window* window, SDL_bool desiredState)
|
||||
_setAndCheckWindowMouseGrabState(SDL_Window* window, SDL_bool desiredState)
|
||||
{
|
||||
SDL_bool currentState;
|
||||
|
||||
/* Set state */
|
||||
SDL_SetWindowGrab(window, desiredState);
|
||||
SDLTest_AssertPass("Call to SDL_SetWindowGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
|
||||
SDL_SetWindowMouseGrab(window, desiredState);
|
||||
SDLTest_AssertPass("Call to SDL_SetWindowMouseGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
|
||||
|
||||
/* Get and check state */
|
||||
currentState = SDL_GetWindowGrab(window);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowGrab()");
|
||||
currentState = SDL_GetWindowMouseGrab(window);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()");
|
||||
SDLTest_AssertCheck(
|
||||
currentState == desiredState,
|
||||
"Validate returned state; expected: %s, got: %s",
|
||||
(desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
|
||||
(currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
|
||||
|
||||
if (desiredState) {
|
||||
SDLTest_AssertCheck(
|
||||
SDL_GetGrabbedWindow() == window,
|
||||
"Grabbed window should be to our window");
|
||||
SDLTest_AssertCheck(
|
||||
SDL_GetWindowGrab(window),
|
||||
"SDL_GetWindowGrab() should return SDL_TRUE");
|
||||
SDLTest_AssertCheck(
|
||||
SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED,
|
||||
"SDL_WINDOW_MOUSE_GRABBED should be set");
|
||||
} else {
|
||||
SDLTest_AssertCheck(
|
||||
!(SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_GRABBED),
|
||||
"SDL_WINDOW_MOUSE_GRABBED should be unset");
|
||||
}
|
||||
}
|
||||
|
||||
/* Helper for setting and checking the window keyboard grab state */
|
||||
void
|
||||
_setAndCheckWindowKeyboardGrabState(SDL_Window* window, SDL_bool desiredState)
|
||||
{
|
||||
SDL_bool currentState;
|
||||
|
||||
/* Set state */
|
||||
SDL_SetWindowKeyboardGrab(window, desiredState);
|
||||
SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(%s)", (desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
|
||||
|
||||
/* Get and check state */
|
||||
currentState = SDL_GetWindowKeyboardGrab(window);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()");
|
||||
SDLTest_AssertCheck(
|
||||
currentState == desiredState,
|
||||
"Validate returned state; expected: %s, got: %s",
|
||||
(desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
|
||||
(currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
|
||||
|
||||
if (desiredState) {
|
||||
SDLTest_AssertCheck(
|
||||
SDL_GetGrabbedWindow() == window,
|
||||
"Grabbed window should be set to our window");
|
||||
SDLTest_AssertCheck(
|
||||
SDL_GetWindowGrab(window),
|
||||
"SDL_GetWindowGrab() should return SDL_TRUE");
|
||||
SDLTest_AssertCheck(
|
||||
SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED,
|
||||
"SDL_WINDOW_KEYBOARD_GRABBED should be set");
|
||||
} else {
|
||||
SDLTest_AssertCheck(
|
||||
!(SDL_GetWindowFlags(window) & SDL_WINDOW_KEYBOARD_GRABBED),
|
||||
"SDL_WINDOW_KEYBOARD_GRABBED should be unset");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Tests call to SDL_GetWindowGrab and SDL_SetWindowGrab
|
||||
* @brief Tests keyboard and mouse grab support
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowGrab
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowGrab
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowGrab
|
||||
* @sa http://wiki.libsdl.org/SDL_SetWindowGrab
|
||||
*/
|
||||
int
|
||||
video_getSetWindowGrab(void *arg)
|
||||
{
|
||||
const char* title = "video_getSetWindowGrab Test Window";
|
||||
SDL_Window* window;
|
||||
SDL_bool originalState, dummyState, currentState, desiredState;
|
||||
SDL_bool originalMouseState, originalKeyboardState;
|
||||
|
||||
/* Call against new test window */
|
||||
window = _createVideoSuiteTestWindow(title);
|
||||
if (window == NULL) return TEST_ABORTED;
|
||||
|
||||
/* Get state */
|
||||
originalState = SDL_GetWindowGrab(window);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowGrab()");
|
||||
originalMouseState = SDL_GetWindowMouseGrab(window);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowMouseGrab()");
|
||||
originalKeyboardState = SDL_GetWindowKeyboardGrab(window);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab()");
|
||||
|
||||
/* F */
|
||||
_setAndCheckWindowGrabState(window, SDL_FALSE);
|
||||
_setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
|
||||
_setAndCheckWindowMouseGrabState(window, SDL_FALSE);
|
||||
SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
|
||||
"SDL_GetWindowGrab should return SDL_FALSE");
|
||||
SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
|
||||
"Expected NULL grabbed window");
|
||||
|
||||
/* F --> F */
|
||||
_setAndCheckWindowGrabState(window, SDL_FALSE);
|
||||
_setAndCheckWindowMouseGrabState(window, SDL_FALSE);
|
||||
_setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
|
||||
SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
|
||||
"Expected NULL grabbed window");
|
||||
|
||||
/* F --> T */
|
||||
_setAndCheckWindowGrabState(window, SDL_TRUE);
|
||||
_setAndCheckWindowMouseGrabState(window, SDL_TRUE);
|
||||
_setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
|
||||
SDLTest_AssertCheck(SDL_GetWindowGrab(window),
|
||||
"SDL_GetWindowGrab() should return SDL_TRUE");
|
||||
|
||||
/* T --> T */
|
||||
_setAndCheckWindowGrabState(window, SDL_TRUE);
|
||||
_setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
|
||||
_setAndCheckWindowMouseGrabState(window, SDL_TRUE);
|
||||
SDLTest_AssertCheck(SDL_GetWindowGrab(window),
|
||||
"SDL_GetWindowGrab() should return SDL_TRUE");
|
||||
|
||||
/* T --> F */
|
||||
_setAndCheckWindowGrabState(window, SDL_FALSE);
|
||||
/* M: T --> F */
|
||||
/* K: T --> T */
|
||||
_setAndCheckWindowKeyboardGrabState(window, SDL_TRUE);
|
||||
_setAndCheckWindowMouseGrabState(window, SDL_FALSE);
|
||||
SDLTest_AssertCheck(SDL_GetWindowGrab(window),
|
||||
"SDL_GetWindowGrab() should return SDL_TRUE");
|
||||
|
||||
/* M: F --> T */
|
||||
/* K: T --> F */
|
||||
_setAndCheckWindowMouseGrabState(window, SDL_TRUE);
|
||||
_setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
|
||||
SDLTest_AssertCheck(SDL_GetWindowGrab(window),
|
||||
"SDL_GetWindowGrab() should return SDL_TRUE");
|
||||
|
||||
/* M: T --> F */
|
||||
/* K: F --> F */
|
||||
_setAndCheckWindowMouseGrabState(window, SDL_FALSE);
|
||||
_setAndCheckWindowKeyboardGrabState(window, SDL_FALSE);
|
||||
SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
|
||||
"SDL_GetWindowGrab() should return SDL_FALSE");
|
||||
SDLTest_AssertCheck(SDL_GetGrabbedWindow() == NULL,
|
||||
"Expected NULL grabbed window");
|
||||
|
||||
/* Using the older SDL_SetWindowGrab API should only grab mouse by default */
|
||||
SDL_SetWindowGrab(window, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDL_SetWindowGrab(SDL_TRUE)");
|
||||
SDLTest_AssertCheck(SDL_GetWindowGrab(window),
|
||||
"SDL_GetWindowGrab() should return SDL_TRUE");
|
||||
SDLTest_AssertCheck(SDL_GetWindowMouseGrab(window),
|
||||
"SDL_GetWindowMouseGrab() should return SDL_TRUE");
|
||||
SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
|
||||
"SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
|
||||
SDL_SetWindowGrab(window, SDL_FALSE);
|
||||
SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
|
||||
"SDL_GetWindowGrab() should return SDL_FALSE");
|
||||
SDLTest_AssertCheck(!SDL_GetWindowMouseGrab(window),
|
||||
"SDL_GetWindowMouseGrab() should return SDL_FALSE");
|
||||
SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
|
||||
"SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
|
||||
|
||||
/* Now test with SDL_HINT_GRAB_KEYBOARD set. We should get keyboard grab now. */
|
||||
SDL_SetHint(SDL_HINT_GRAB_KEYBOARD, "1");
|
||||
SDL_SetWindowGrab(window, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDL_SetWindowGrab(SDL_TRUE)");
|
||||
SDLTest_AssertCheck(SDL_GetWindowGrab(window),
|
||||
"SDL_GetWindowGrab() should return SDL_TRUE");
|
||||
SDLTest_AssertCheck(SDL_GetWindowMouseGrab(window),
|
||||
"SDL_GetWindowMouseGrab() should return SDL_TRUE");
|
||||
SDLTest_AssertCheck(SDL_GetWindowKeyboardGrab(window),
|
||||
"SDL_GetWindowKeyboardGrab() should return SDL_TRUE");
|
||||
SDL_SetWindowGrab(window, SDL_FALSE);
|
||||
SDLTest_AssertCheck(!SDL_GetWindowGrab(window),
|
||||
"SDL_GetWindowGrab() should return SDL_FALSE");
|
||||
SDLTest_AssertCheck(!SDL_GetWindowMouseGrab(window),
|
||||
"SDL_GetWindowMouseGrab() should return SDL_FALSE");
|
||||
SDLTest_AssertCheck(!SDL_GetWindowKeyboardGrab(window),
|
||||
"SDL_GetWindowKeyboardGrab() should return SDL_FALSE");
|
||||
|
||||
/* Negative tests */
|
||||
dummyState = SDL_GetWindowGrab(NULL);
|
||||
SDL_GetWindowGrab(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowGrab(window=NULL)");
|
||||
_checkInvalidWindowError();
|
||||
|
||||
SDL_GetWindowKeyboardGrab(NULL);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowKeyboardGrab(window=NULL)");
|
||||
_checkInvalidWindowError();
|
||||
|
||||
SDL_SetWindowGrab(NULL, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)");
|
||||
_checkInvalidWindowError();
|
||||
|
||||
SDL_SetWindowGrab(NULL, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_FALSE)");
|
||||
SDL_SetWindowKeyboardGrab(NULL, SDL_FALSE);
|
||||
SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_FALSE)");
|
||||
_checkInvalidWindowError();
|
||||
|
||||
/* State should still be F */
|
||||
desiredState = SDL_FALSE;
|
||||
currentState = SDL_GetWindowGrab(window);
|
||||
SDLTest_AssertPass("Call to SDL_GetWindowGrab()");
|
||||
SDLTest_AssertCheck(
|
||||
currentState == desiredState,
|
||||
"Validate returned state; expected: %s, got: %s",
|
||||
(desiredState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE",
|
||||
(currentState == SDL_FALSE) ? "SDL_FALSE" : "SDL_TRUE");
|
||||
SDL_SetWindowGrab(NULL, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDL_SetWindowGrab(window=NULL,SDL_TRUE)");
|
||||
_checkInvalidWindowError();
|
||||
|
||||
SDL_SetWindowKeyboardGrab(NULL, SDL_TRUE);
|
||||
SDLTest_AssertPass("Call to SDL_SetWindowKeyboardGrab(window=NULL,SDL_TRUE)");
|
||||
_checkInvalidWindowError();
|
||||
|
||||
/* Restore state */
|
||||
_setAndCheckWindowGrabState(window, originalState);
|
||||
_setAndCheckWindowMouseGrabState(window, originalMouseState);
|
||||
_setAndCheckWindowKeyboardGrabState(window, originalKeyboardState);
|
||||
|
||||
/* Clean up */
|
||||
_destroyVideoSuiteTestWindow(window);
|
||||
@@ -836,8 +964,8 @@ video_getSetWindowGrab(void *arg)
|
||||
/**
|
||||
* @brief Tests call to SDL_GetWindowID and SDL_GetWindowFromID
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowID
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowFromID
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowID
|
||||
* @sa http://wiki.libsdl.org/SDL_SetWindowFromID
|
||||
*/
|
||||
int
|
||||
video_getWindowId(void *arg)
|
||||
@@ -892,7 +1020,7 @@ video_getWindowId(void *arg)
|
||||
/**
|
||||
* @brief Tests call to SDL_GetWindowPixelFormat
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowPixelFormat
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowPixelFormat
|
||||
*/
|
||||
int
|
||||
video_getWindowPixelFormat(void *arg)
|
||||
@@ -926,8 +1054,8 @@ video_getWindowPixelFormat(void *arg)
|
||||
/**
|
||||
* @brief Tests call to SDL_GetWindowPosition and SDL_SetWindowPosition
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowPosition
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowPosition
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowPosition
|
||||
* @sa http://wiki.libsdl.org/SDL_SetWindowPosition
|
||||
*/
|
||||
int
|
||||
video_getSetWindowPosition(void *arg)
|
||||
@@ -1069,8 +1197,8 @@ void _checkInvalidParameterError()
|
||||
/**
|
||||
* @brief Tests call to SDL_GetWindowSize and SDL_SetWindowSize
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowSize
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowSize
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowSize
|
||||
* @sa http://wiki.libsdl.org/SDL_SetWindowSize
|
||||
*/
|
||||
int
|
||||
video_getSetWindowSize(void *arg)
|
||||
@@ -1508,8 +1636,8 @@ video_getSetWindowMaximumSize(void *arg)
|
||||
/**
|
||||
* @brief Tests call to SDL_SetWindowData and SDL_GetWindowData
|
||||
*
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_SetWindowData
|
||||
* @sa http://wiki.libsdl.org/moin.fcg/SDL_GetWindowData
|
||||
* @sa http://wiki.libsdl.org/SDL_SetWindowData
|
||||
* @sa http://wiki.libsdl.org/SDL_GetWindowData
|
||||
*/
|
||||
int
|
||||
video_getSetWindowData(void *arg)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -128,7 +128,7 @@ init_system_cursor(const char *image[])
|
||||
}
|
||||
}
|
||||
}
|
||||
sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
|
||||
SDL_sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
|
||||
return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -32,6 +32,8 @@ static int cycle_direction = 1;
|
||||
static int current_alpha = 255;
|
||||
static int current_color = 255;
|
||||
static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
static Uint32 next_fps_check, frames;
|
||||
static const Uint32 fps_check_delay = 5000;
|
||||
|
||||
int done;
|
||||
|
||||
@@ -178,6 +180,7 @@ DrawRects(SDL_Renderer * renderer)
|
||||
void
|
||||
loop()
|
||||
{
|
||||
Uint32 now;
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
||||
@@ -203,13 +206,23 @@ loop()
|
||||
emscripten_cancel_main_loop();
|
||||
}
|
||||
#endif
|
||||
frames++;
|
||||
now = SDL_GetTicks();
|
||||
if (SDL_TICKS_PASSED(now, next_fps_check)) {
|
||||
/* Print out some timing information */
|
||||
const Uint32 then = next_fps_check - fps_check_delay;
|
||||
const double fps = ((double) frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
next_fps_check = now + fps_check_delay;
|
||||
frames = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
Uint32 then, now, frames;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
@@ -256,7 +269,12 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", NULL };
|
||||
static const char *options[] = {
|
||||
"[--blend none|blend|add|mod]",
|
||||
"[--cyclecolor]",
|
||||
"[--cyclealpha]",
|
||||
"[num_objects]",
|
||||
NULL };
|
||||
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||
return 1;
|
||||
}
|
||||
@@ -278,27 +296,20 @@ main(int argc, char *argv[])
|
||||
|
||||
/* Main render loop */
|
||||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
next_fps_check = SDL_GetTicks() + fps_check_delay;
|
||||
done = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
++frames;
|
||||
loop();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
SDLTest_CommonQuit(state);
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
double fps = ((double) frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -29,7 +29,7 @@ SDL_Surface *surface;
|
||||
int done;
|
||||
|
||||
void
|
||||
DrawChessBoard(SDL_Renderer * renderer)
|
||||
DrawChessBoard()
|
||||
{
|
||||
int row = 0,column = 0,x = 0;
|
||||
SDL_Rect rect, darea;
|
||||
@@ -90,7 +90,7 @@ loop()
|
||||
}
|
||||
}
|
||||
|
||||
DrawChessBoard(renderer);
|
||||
DrawChessBoard();
|
||||
|
||||
/* Got everything on rendering surface,
|
||||
now Update the drawing image on window screen */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 2020 Collabora Ltd.
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
@@ -41,6 +41,7 @@ static const struct
|
||||
CLS(SOUND),
|
||||
CLS(TOUCHSCREEN),
|
||||
CLS(ACCELEROMETER),
|
||||
CLS(TOUCHPAD),
|
||||
#undef CLS
|
||||
{ 0, NULL }
|
||||
};
|
||||
@@ -185,9 +186,7 @@ static const GuessTest guess_tests[] =
|
||||
.bus_type = 0x0003,
|
||||
.vendor_id = 0x054c,
|
||||
.product_id = 0x09cc,
|
||||
/* TODO: Should this be MOUSE? That's what it most closely
|
||||
* resembles */
|
||||
.expected = SDL_UDEV_DEVICE_UNKNOWN,
|
||||
.expected = SDL_UDEV_DEVICE_TOUCHPAD,
|
||||
/* SYN, KEY, ABS */
|
||||
.ev = { 0x0b },
|
||||
/* X, Y, multitouch */
|
||||
@@ -596,7 +595,7 @@ static const GuessTest guess_tests[] =
|
||||
* to the arrow, page up and page down keys, so it's a joystick
|
||||
* with a subset of a keyboard attached. */
|
||||
/* TODO: Should this be JOYSTICK, or even JOYSTICK|KEYBOARD? */
|
||||
.expected = SDL_UDEV_DEVICE_UNKNOWN,
|
||||
.expected = SDL_UDEV_DEVICE_KEYBOARD,
|
||||
/* SYN, KEY */
|
||||
.ev = { 0x03 },
|
||||
.keys = {
|
||||
@@ -608,7 +607,7 @@ static const GuessTest guess_tests[] =
|
||||
/* BTN_1, BTN_2, BTN_A, BTN_B, BTN_MODE */
|
||||
/* 0x100 */ 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x10,
|
||||
/* 0x140 */ ZEROx8,
|
||||
/* next, previous */
|
||||
/* next (keyboard page down), previous (keyboard page up) */
|
||||
/* 0x180 */ 0x00, 0x00, 0x80, 0x10, ZEROx4,
|
||||
},
|
||||
},
|
||||
@@ -659,7 +658,7 @@ static const GuessTest guess_tests[] =
|
||||
.name = "Wiimote - Classic Controller",
|
||||
/* TODO: Should this be JOYSTICK, or maybe JOYSTICK|KEYBOARD?
|
||||
* It's unusual in the same ways as the Wiimote */
|
||||
.expected = SDL_UDEV_DEVICE_UNKNOWN,
|
||||
.expected = SDL_UDEV_DEVICE_KEYBOARD,
|
||||
/* SYN, KEY, ABS */
|
||||
.ev = { 0x0b },
|
||||
/* Hat 1-3 */
|
||||
@@ -673,7 +672,7 @@ static const GuessTest guess_tests[] =
|
||||
/* A, B, X, Y, MODE, TL, TL2, TR, TR2 */
|
||||
/* 0x100 */ ZEROx4, 0x00, 0x13, 0xdb, 0x10,
|
||||
/* 0x140 */ ZEROx8,
|
||||
/* next, previous */
|
||||
/* next (keyboard page down), previous (keyboard page up) */
|
||||
/* 0x180 */ 0x00, 0x00, 0x80, 0x10, ZEROx4,
|
||||
},
|
||||
},
|
||||
@@ -718,9 +717,7 @@ static const GuessTest guess_tests[] =
|
||||
.vendor_id = 0x06cb,
|
||||
.product_id = 0x0000,
|
||||
.version = 0x0000,
|
||||
/* TODO: Should this be MOUSE? That's what it most closely
|
||||
* resembles */
|
||||
.expected = SDL_UDEV_DEVICE_UNKNOWN,
|
||||
.expected = SDL_UDEV_DEVICE_TOUCHPAD,
|
||||
/* SYN, KEY, ABS */
|
||||
.ev = { 0x0b },
|
||||
/* X, Y, pressure, multitouch */
|
||||
@@ -756,7 +753,8 @@ static const GuessTest guess_tests[] =
|
||||
},
|
||||
{
|
||||
.name = "Thinkpad ACPI buttons",
|
||||
.expected = SDL_UDEV_DEVICE_UNKNOWN,
|
||||
/* SDL treats this as a keyboard because it has a power button */
|
||||
.expected = SDL_UDEV_DEVICE_KEYBOARD,
|
||||
/* SYN, KEY, MSC, SW */
|
||||
.ev = { 0x33 },
|
||||
.keys = {
|
||||
@@ -815,7 +813,8 @@ static const GuessTest guess_tests[] =
|
||||
.vendor_id = 0x0000,
|
||||
.product_id = 0x0003,
|
||||
.version = 0x0000,
|
||||
.expected = SDL_UDEV_DEVICE_UNKNOWN,
|
||||
/* SDL treats KEY_SLEEP as indicating a keyboard */
|
||||
.expected = SDL_UDEV_DEVICE_KEYBOARD,
|
||||
/* SYN, KEY */
|
||||
.ev = { 0x03 },
|
||||
.keys = {
|
||||
@@ -841,7 +840,8 @@ static const GuessTest guess_tests[] =
|
||||
.vendor_id = 0x0000,
|
||||
.product_id = 0x0001,
|
||||
.version = 0x0000,
|
||||
.expected = SDL_UDEV_DEVICE_UNKNOWN,
|
||||
/* SDL treats KEY_POWER as indicating a keyboard */
|
||||
.expected = SDL_UDEV_DEVICE_KEYBOARD,
|
||||
/* SYN, KEY */
|
||||
.ev = { 0x03 },
|
||||
.keys = {
|
||||
@@ -856,7 +856,8 @@ static const GuessTest guess_tests[] =
|
||||
.vendor_id = 0x0000,
|
||||
.product_id = 0x0006,
|
||||
.version = 0x0000,
|
||||
.expected = SDL_UDEV_DEVICE_UNKNOWN,
|
||||
/* SDL treats brightness control, etc. as keyboard keys */
|
||||
.expected = SDL_UDEV_DEVICE_KEYBOARD,
|
||||
/* SYN, KEY */
|
||||
.ev = { 0x03 },
|
||||
.keys = {
|
||||
@@ -873,7 +874,7 @@ static const GuessTest guess_tests[] =
|
||||
.vendor_id = 0x17aa,
|
||||
.product_id = 0x5054,
|
||||
.version = 0x4101,
|
||||
.expected = SDL_UDEV_DEVICE_UNKNOWN,
|
||||
.expected = SDL_UDEV_DEVICE_KEYBOARD,
|
||||
/* SYN, KEY */
|
||||
.ev = { 0x03 },
|
||||
.keys = {
|
||||
@@ -911,9 +912,8 @@ static const GuessTest guess_tests[] =
|
||||
.product_id = 0x6009,
|
||||
/* For some reason the special keys like mute and wlan toggle
|
||||
* show up here instead of, or in addition to, as part of
|
||||
* the keyboard - so udev reports this as having keys too.
|
||||
* SDL currently doesn't. */
|
||||
.expected = SDL_UDEV_DEVICE_MOUSE,
|
||||
* the keyboard - so both udev and SDL report this as having keys too. */
|
||||
.expected = SDL_UDEV_DEVICE_MOUSE | SDL_UDEV_DEVICE_KEYBOARD,
|
||||
/* SYN, KEY, REL, MSC, LED */
|
||||
.ev = { 0x17, 0x00, 0x02 },
|
||||
/* X, Y */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -61,15 +61,16 @@ static const struct { int x; int y; double angle; } axis_positions[] = {
|
||||
{375, -20, 0.0}, /* TRIGGERRIGHT */
|
||||
};
|
||||
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
SDL_bool set_LED = SDL_FALSE;
|
||||
SDL_Texture *background_front, *background_back, *button, *axis;
|
||||
SDL_GameController *gamecontroller;
|
||||
SDL_GameController **gamecontrollers;
|
||||
int num_controllers = 0;
|
||||
static SDL_Window *window = NULL;
|
||||
static SDL_Renderer *screen = NULL;
|
||||
static SDL_bool retval = SDL_FALSE;
|
||||
static SDL_bool done = SDL_FALSE;
|
||||
static SDL_bool set_LED = SDL_FALSE;
|
||||
static int trigger_effect = 0;
|
||||
static SDL_Texture *background_front, *background_back, *button, *axis;
|
||||
static SDL_GameController *gamecontroller;
|
||||
static SDL_GameController **gamecontrollers;
|
||||
static int num_controllers = 0;
|
||||
|
||||
static void UpdateWindowTitle()
|
||||
{
|
||||
@@ -146,6 +147,7 @@ static void AddController(int device_index, SDL_bool verbose)
|
||||
controllers[num_controllers++] = controller;
|
||||
gamecontrollers = controllers;
|
||||
gamecontroller = controller;
|
||||
trigger_effect = 0;
|
||||
|
||||
if (verbose) {
|
||||
const char *name = SDL_GameControllerName(gamecontroller);
|
||||
@@ -154,18 +156,26 @@ static void AddController(int device_index, SDL_bool verbose)
|
||||
|
||||
if (SDL_GameControllerHasSensor(gamecontroller, SDL_SENSOR_ACCEL)) {
|
||||
if (verbose) {
|
||||
SDL_Log("Enabling accelerometer\n");
|
||||
SDL_Log("Enabling accelerometer at %.2f Hz\n", SDL_GameControllerGetSensorDataRate(gamecontroller, SDL_SENSOR_ACCEL));
|
||||
}
|
||||
SDL_GameControllerSetSensorEnabled(gamecontroller, SDL_SENSOR_ACCEL, SDL_TRUE);
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasSensor(gamecontroller, SDL_SENSOR_GYRO)) {
|
||||
if (verbose) {
|
||||
SDL_Log("Enabling gyro\n");
|
||||
SDL_Log("Enabling gyro at %.2f Hz\n", SDL_GameControllerGetSensorDataRate(gamecontroller, SDL_SENSOR_GYRO));
|
||||
}
|
||||
SDL_GameControllerSetSensorEnabled(gamecontroller, SDL_SENSOR_GYRO, SDL_TRUE);
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasRumble(gamecontroller)) {
|
||||
SDL_Log("Rumble supported");
|
||||
}
|
||||
|
||||
if (SDL_GameControllerHasRumbleTriggers(gamecontroller)) {
|
||||
SDL_Log("Trigger rumble supported");
|
||||
}
|
||||
|
||||
UpdateWindowTitle();
|
||||
}
|
||||
|
||||
@@ -234,17 +244,68 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
||||
return texture;
|
||||
}
|
||||
|
||||
static Uint16 ConvertAxisToRumble(Sint16 axis)
|
||||
static Uint16 ConvertAxisToRumble(Sint16 axisval)
|
||||
{
|
||||
/* Only start rumbling if the axis is past the halfway point */
|
||||
const Sint16 half_axis = (Sint16)SDL_ceil(SDL_JOYSTICK_AXIS_MAX / 2.0f);
|
||||
if (axis > half_axis) {
|
||||
return (Uint16)(axis - half_axis) * 4;
|
||||
if (axisval > half_axis) {
|
||||
return (Uint16)(axisval - half_axis) * 4;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* PS5 trigger effect documentation:
|
||||
https://controllers.fandom.com/wiki/Sony_DualSense#FFB_Trigger_Modes
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
Uint8 ucEnableBits1; /* 0 */
|
||||
Uint8 ucEnableBits2; /* 1 */
|
||||
Uint8 ucRumbleRight; /* 2 */
|
||||
Uint8 ucRumbleLeft; /* 3 */
|
||||
Uint8 ucHeadphoneVolume; /* 4 */
|
||||
Uint8 ucSpeakerVolume; /* 5 */
|
||||
Uint8 ucMicrophoneVolume; /* 6 */
|
||||
Uint8 ucAudioEnableBits; /* 7 */
|
||||
Uint8 ucMicLightMode; /* 8 */
|
||||
Uint8 ucAudioMuteBits; /* 9 */
|
||||
Uint8 rgucRightTriggerEffect[11]; /* 10 */
|
||||
Uint8 rgucLeftTriggerEffect[11]; /* 21 */
|
||||
Uint8 rgucUnknown1[6]; /* 32 */
|
||||
Uint8 ucLedFlags; /* 38 */
|
||||
Uint8 rgucUnknown2[2]; /* 39 */
|
||||
Uint8 ucLedAnim; /* 41 */
|
||||
Uint8 ucLedBrightness; /* 42 */
|
||||
Uint8 ucPadLights; /* 43 */
|
||||
Uint8 ucLedRed; /* 44 */
|
||||
Uint8 ucLedGreen; /* 45 */
|
||||
Uint8 ucLedBlue; /* 46 */
|
||||
} DS5EffectsState_t;
|
||||
|
||||
static void CyclePS5TriggerEffect()
|
||||
{
|
||||
DS5EffectsState_t state;
|
||||
|
||||
Uint8 effects[3][11] =
|
||||
{
|
||||
/* Clear trigger effect */
|
||||
{ 0x05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
/* Constant resistance across entire trigger pull */
|
||||
{ 0x01, 0, 110, 0, 0, 0, 0, 0, 0, 0, 0 },
|
||||
/* Resistance and vibration when trigger is pulled */
|
||||
{ 0x06, 15, 63, 128, 0, 0, 0, 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
trigger_effect = (trigger_effect + 1) % SDL_arraysize(effects);
|
||||
|
||||
SDL_zero(state);
|
||||
state.ucEnableBits1 |= (0x04 | 0x08); /* Modify right and left trigger effect respectively */
|
||||
SDL_memcpy(state.rgucRightTriggerEffect, effects[trigger_effect], sizeof(effects[trigger_effect]));
|
||||
SDL_memcpy(state.rgucLeftTriggerEffect, effects[trigger_effect], sizeof(effects[trigger_effect]));
|
||||
SDL_GameControllerSendEffect(gamecontroller, &state, sizeof(state));
|
||||
}
|
||||
|
||||
void
|
||||
loop(void *arg)
|
||||
{
|
||||
@@ -252,7 +313,11 @@ loop(void *arg)
|
||||
int i;
|
||||
SDL_bool showing_front = SDL_TRUE;
|
||||
|
||||
while (SDL_PollEvent(&event)) {
|
||||
/* Update to get the current event state */
|
||||
SDL_PumpEvents();
|
||||
|
||||
/* Process all currently pending events */
|
||||
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1) {
|
||||
switch (event.type) {
|
||||
case SDL_CONTROLLERDEVICEADDED:
|
||||
SDL_Log("Game controller device %d added.\n", (int) SDL_JoystickGetDeviceInstanceID(event.cdevice.which));
|
||||
@@ -267,7 +332,8 @@ loop(void *arg)
|
||||
case SDL_CONTROLLERTOUCHPADDOWN:
|
||||
case SDL_CONTROLLERTOUCHPADMOTION:
|
||||
case SDL_CONTROLLERTOUCHPADUP:
|
||||
SDL_Log("Controller touchpad %d finger %d %s %.2f, %.2f, %.2f\n",
|
||||
SDL_Log("Controller %d touchpad %d finger %d %s %.2f, %.2f, %.2f\n",
|
||||
event.ctouchpad.which,
|
||||
event.ctouchpad.touchpad,
|
||||
event.ctouchpad.finger,
|
||||
(event.type == SDL_CONTROLLERTOUCHPADDOWN ? "pressed at" :
|
||||
@@ -278,35 +344,57 @@ loop(void *arg)
|
||||
event.ctouchpad.pressure);
|
||||
break;
|
||||
|
||||
#define VERBOSE_SENSORS
|
||||
#ifdef VERBOSE_SENSORS
|
||||
case SDL_CONTROLLERSENSORUPDATE:
|
||||
SDL_Log("Controller sensor %s: %.2f, %.2f, %.2f\n",
|
||||
SDL_Log("Controller %d sensor %s: %.2f, %.2f, %.2f\n",
|
||||
event.csensor.which,
|
||||
event.csensor.sensor == SDL_SENSOR_ACCEL ? "accelerometer" :
|
||||
event.csensor.sensor == SDL_SENSOR_GYRO ? "gyro" : "unknown",
|
||||
event.csensor.data[0],
|
||||
event.csensor.data[1],
|
||||
event.csensor.data[2]);
|
||||
break;
|
||||
#endif /* VERBOSE_SENSORS */
|
||||
|
||||
#define VERBOSE_AXES
|
||||
#ifdef VERBOSE_AXES
|
||||
case SDL_CONTROLLERAXISMOTION:
|
||||
if (event.caxis.value <= (-SDL_JOYSTICK_AXIS_MAX / 2) || event.caxis.value >= (SDL_JOYSTICK_AXIS_MAX / 2)) {
|
||||
SetController(event.caxis.which);
|
||||
}
|
||||
SDL_Log("Controller axis %s changed to %d\n", SDL_GameControllerGetStringForAxis((SDL_GameControllerAxis)event.caxis.axis), event.caxis.value);
|
||||
SDL_Log("Controller %d axis %s changed to %d\n", event.caxis.which, SDL_GameControllerGetStringForAxis((SDL_GameControllerAxis)event.caxis.axis), event.caxis.value);
|
||||
break;
|
||||
#endif /* VERBOSE_AXES */
|
||||
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
case SDL_CONTROLLERBUTTONUP:
|
||||
if (event.type == SDL_CONTROLLERBUTTONDOWN) {
|
||||
SetController(event.cbutton.which);
|
||||
}
|
||||
SDL_Log("Controller button %s %s\n", SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released");
|
||||
SDL_Log("Controller %d button %s %s\n", event.cbutton.which, SDL_GameControllerGetStringForButton((SDL_GameControllerButton)event.cbutton.button), event.cbutton.state ? "pressed" : "released");
|
||||
|
||||
/* Cycle PS5 trigger effects when the microphone button is pressed */
|
||||
if (event.type == SDL_CONTROLLERBUTTONDOWN &&
|
||||
event.cbutton.button == SDL_CONTROLLER_BUTTON_MISC1 &&
|
||||
SDL_GameControllerGetType(gamecontroller) == SDL_CONTROLLER_TYPE_PS5) {
|
||||
CyclePS5TriggerEffect();
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym >= SDLK_0 && event.key.keysym.sym <= SDLK_9) {
|
||||
if (gamecontroller) {
|
||||
int player_index = (event.key.keysym.sym - SDLK_0);
|
||||
|
||||
SDL_GameControllerSetPlayerIndex(gamecontroller, player_index);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (event.key.keysym.sym != SDLK_ESCAPE) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
SDL_FALLTHROUGH;
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
@@ -336,7 +424,11 @@ loop(void *arg)
|
||||
if (SDL_GameControllerGetButton(gamecontroller, (SDL_GameControllerButton)i) == SDL_PRESSED) {
|
||||
SDL_bool on_front = (i < SDL_CONTROLLER_BUTTON_PADDLE1 || i > SDL_CONTROLLER_BUTTON_PADDLE4);
|
||||
if (on_front == showing_front) {
|
||||
const SDL_Rect dst = { button_positions[i].x, button_positions[i].y, 50, 50 };
|
||||
SDL_Rect dst;
|
||||
dst.x = button_positions[i].x;
|
||||
dst.y = button_positions[i].y;
|
||||
dst.w = 50;
|
||||
dst.h = 50;
|
||||
SDL_RenderCopyEx(screen, button, NULL, &dst, 0, NULL, SDL_FLIP_NONE);
|
||||
}
|
||||
}
|
||||
@@ -347,12 +439,20 @@ loop(void *arg)
|
||||
const Sint16 deadzone = 8000; /* !!! FIXME: real deadzone */
|
||||
const Sint16 value = SDL_GameControllerGetAxis(gamecontroller, (SDL_GameControllerAxis)(i));
|
||||
if (value < -deadzone) {
|
||||
const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
|
||||
const double angle = axis_positions[i].angle;
|
||||
SDL_Rect dst;
|
||||
dst.x = axis_positions[i].x;
|
||||
dst.y = axis_positions[i].y;
|
||||
dst.w = 50;
|
||||
dst.h = 50;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
} else if (value > deadzone) {
|
||||
const SDL_Rect dst = { axis_positions[i].x, axis_positions[i].y, 50, 50 };
|
||||
const double angle = axis_positions[i].angle + 180.0;
|
||||
SDL_Rect dst;
|
||||
dst.x = axis_positions[i].x;
|
||||
dst.y = axis_positions[i].y;
|
||||
dst.w = 50;
|
||||
dst.h = 50;
|
||||
SDL_RenderCopyEx(screen, axis, NULL, &dst, angle, NULL, SDL_FLIP_NONE);
|
||||
}
|
||||
}
|
||||
@@ -386,23 +486,25 @@ loop(void *arg)
|
||||
}
|
||||
}
|
||||
|
||||
/* Update rumble based on trigger state */
|
||||
{
|
||||
Sint16 left = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERLEFT);
|
||||
Sint16 right = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
|
||||
Uint16 low_frequency_rumble = ConvertAxisToRumble(left);
|
||||
Uint16 high_frequency_rumble = ConvertAxisToRumble(right);
|
||||
SDL_GameControllerRumble(gamecontroller, low_frequency_rumble, high_frequency_rumble, 250);
|
||||
}
|
||||
if (trigger_effect == 0) {
|
||||
/* Update rumble based on trigger state */
|
||||
{
|
||||
Sint16 left = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERLEFT);
|
||||
Sint16 right = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
|
||||
Uint16 low_frequency_rumble = ConvertAxisToRumble(left);
|
||||
Uint16 high_frequency_rumble = ConvertAxisToRumble(right);
|
||||
SDL_GameControllerRumble(gamecontroller, low_frequency_rumble, high_frequency_rumble, 250);
|
||||
}
|
||||
|
||||
/* Update trigger rumble based on thumbstick state */
|
||||
{
|
||||
Sint16 left = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_LEFTY);
|
||||
Sint16 right = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_RIGHTY);
|
||||
Uint16 left_rumble = ConvertAxisToRumble(~left);
|
||||
Uint16 right_rumble = ConvertAxisToRumble(~right);
|
||||
/* Update trigger rumble based on thumbstick state */
|
||||
{
|
||||
Sint16 left = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_LEFTY);
|
||||
Sint16 right = SDL_GameControllerGetAxis(gamecontroller, SDL_CONTROLLER_AXIS_RIGHTY);
|
||||
Uint16 left_rumble = ConvertAxisToRumble(~left);
|
||||
Uint16 right_rumble = ConvertAxisToRumble(~right);
|
||||
|
||||
SDL_GameControllerRumbleTriggers(gamecontroller, left_rumble, right_rumble, 250);
|
||||
SDL_GameControllerRumbleTriggers(gamecontroller, left_rumble, right_rumble, 250);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -424,8 +526,12 @@ main(int argc, char *argv[])
|
||||
char guid[64];
|
||||
|
||||
SDL_SetHint(SDL_HINT_ACCELEROMETER_AS_JOYSTICK, "0");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_JOY_CONS, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS4_RUMBLE, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI_PS5_RUMBLE, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_ROG_CHAKRAM, "1");
|
||||
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
|
||||
SDL_SetHint(SDL_HINT_LINUX_JOYSTICK_DEADZONES, "1");
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
@@ -435,7 +541,7 @@ main(int argc, char *argv[])
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt");
|
||||
|
||||
/* Print information about the mappings */
|
||||
@@ -463,11 +569,14 @@ main(int argc, char *argv[])
|
||||
controller_count++;
|
||||
name = SDL_GameControllerNameForIndex(i);
|
||||
switch (SDL_GameControllerTypeForIndex(i)) {
|
||||
case SDL_CONTROLLER_TYPE_XBOX360:
|
||||
description = "XBox 360 Controller";
|
||||
case SDL_CONTROLLER_TYPE_AMAZON_LUNA:
|
||||
description = "Amazon Luna Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_XBOXONE:
|
||||
description = "XBox One Controller";
|
||||
case SDL_CONTROLLER_TYPE_GOOGLE_STADIA:
|
||||
description = "Google Stadia Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
|
||||
description = "Nintendo Switch Pro Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_PS3:
|
||||
description = "PS3 Controller";
|
||||
@@ -475,8 +584,14 @@ main(int argc, char *argv[])
|
||||
case SDL_CONTROLLER_TYPE_PS4:
|
||||
description = "PS4 Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_NINTENDO_SWITCH_PRO:
|
||||
description = "Nintendo Switch Pro Controller";
|
||||
case SDL_CONTROLLER_TYPE_PS5:
|
||||
description = "PS5 Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_XBOX360:
|
||||
description = "XBox 360 Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_XBOXONE:
|
||||
description = "XBox One Controller";
|
||||
break;
|
||||
case SDL_CONTROLLER_TYPE_VIRTUAL:
|
||||
description = "Virtual Game Controller";
|
||||
@@ -554,6 +669,12 @@ main(int argc, char *argv[])
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Reset trigger state */
|
||||
if (trigger_effect != 0) {
|
||||
trigger_effect = -1;
|
||||
CyclePS5TriggerEffect();
|
||||
}
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
SDL_QuitSubSystem(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
|
||||
|
||||
303
test/testgeometry.c
Normal file
303
test/testgeometry.c
Normal file
@@ -0,0 +1,303 @@
|
||||
/*
|
||||
Copyright (C) 1997-2022 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.
|
||||
*/
|
||||
|
||||
/* Simple program: draw a RGB triangle, with texture */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static SDL_bool use_texture = SDL_FALSE;
|
||||
static SDL_Texture **sprites;
|
||||
static SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
|
||||
static double angle = 0.0;
|
||||
static int sprite_w, sprite_h;
|
||||
|
||||
int done;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
SDL_free(sprites);
|
||||
SDLTest_CommonQuit(state);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
int
|
||||
LoadSprite(const char *file)
|
||||
{
|
||||
int i;
|
||||
SDL_Surface *temp;
|
||||
|
||||
/* Load the sprite image */
|
||||
temp = SDL_LoadBMP(file);
|
||||
if (temp == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
|
||||
return (-1);
|
||||
}
|
||||
sprite_w = temp->w;
|
||||
sprite_h = temp->h;
|
||||
|
||||
/* Set transparent pixel as the pixel at (0,0) */
|
||||
if (temp->format->palette) {
|
||||
SDL_SetColorKey(temp, 1, *(Uint8 *) temp->pixels);
|
||||
} else {
|
||||
switch (temp->format->BitsPerPixel) {
|
||||
case 15:
|
||||
SDL_SetColorKey(temp, 1, (*(Uint16 *) temp->pixels) & 0x00007FFF);
|
||||
break;
|
||||
case 16:
|
||||
SDL_SetColorKey(temp, 1, *(Uint16 *) temp->pixels);
|
||||
break;
|
||||
case 24:
|
||||
SDL_SetColorKey(temp, 1, (*(Uint32 *) temp->pixels) & 0x00FFFFFF);
|
||||
break;
|
||||
case 32:
|
||||
SDL_SetColorKey(temp, 1, *(Uint32 *) temp->pixels);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create textures from the image */
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
sprites[i] = SDL_CreateTextureFromSurface(renderer, temp);
|
||||
if (!sprites[i]) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
|
||||
SDL_FreeSurface(temp);
|
||||
return (-1);
|
||||
}
|
||||
if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
|
||||
SDL_FreeSurface(temp);
|
||||
SDL_DestroyTexture(sprites[i]);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
SDL_FreeSurface(temp);
|
||||
|
||||
/* We're ready to roll. :) */
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
int i;
|
||||
SDL_Event event;
|
||||
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
|
||||
if (event.type == SDL_MOUSEMOTION) {
|
||||
if (event.motion.state) {
|
||||
int xrel, yrel;
|
||||
int window_w, window_h;
|
||||
SDL_Window *window = SDL_GetWindowFromID(event.motion.windowID);
|
||||
SDL_GetWindowSize(window, &window_w, &window_h);
|
||||
xrel = event.motion.xrel;
|
||||
yrel = event.motion.yrel;
|
||||
if (event.motion.y < window_h / 2) {
|
||||
angle += xrel;
|
||||
} else {
|
||||
angle -= xrel;
|
||||
}
|
||||
if (event.motion.x < window_w / 2) {
|
||||
angle -= yrel;
|
||||
} else {
|
||||
angle += yrel;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
if (state->windows[i] == NULL)
|
||||
continue;
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
{
|
||||
SDL_Rect viewport;
|
||||
SDL_Vertex verts[3];
|
||||
double a;
|
||||
double d;
|
||||
int cx, cy;
|
||||
|
||||
/* Query the sizes */
|
||||
SDL_RenderGetViewport(renderer, &viewport);
|
||||
SDL_zeroa(verts);
|
||||
cx = viewport.x + viewport.w / 2;
|
||||
cy = viewport.y + viewport.h / 2;
|
||||
d = (viewport.w + viewport.h) / 5;
|
||||
|
||||
a = (angle * 3.1415) / 180.0;
|
||||
verts[0].position.x = cx + d * SDL_cos(a);
|
||||
verts[0].position.y = cy + d * SDL_sin(a);
|
||||
verts[0].color.r = 0xFF;
|
||||
verts[0].color.g = 0;
|
||||
verts[0].color.b = 0;
|
||||
verts[0].color.a = 0xFF;
|
||||
|
||||
a = ((angle + 120) * 3.1415) / 180.0;
|
||||
verts[1].position.x = cx + d * SDL_cos(a);
|
||||
verts[1].position.y = cy + d * SDL_sin(a);
|
||||
verts[1].color.r = 0;
|
||||
verts[1].color.g = 0xFF;
|
||||
verts[1].color.b = 0;
|
||||
verts[1].color.a = 0xFF;
|
||||
|
||||
a = ((angle + 240) * 3.1415) / 180.0;
|
||||
verts[2].position.x = cx + d * SDL_cos(a);
|
||||
verts[2].position.y = cy + d * SDL_sin(a);
|
||||
verts[2].color.r = 0;
|
||||
verts[2].color.g = 0;
|
||||
verts[2].color.b = 0xFF;
|
||||
verts[2].color.a = 0xFF;
|
||||
|
||||
if (use_texture) {
|
||||
verts[0].tex_coord.x = 0.5;
|
||||
verts[0].tex_coord.y = 0.0;
|
||||
verts[1].tex_coord.x = 1.0;
|
||||
verts[1].tex_coord.y = 1.0;
|
||||
verts[2].tex_coord.x = 0.0;
|
||||
verts[2].tex_coord.y = 1.0;
|
||||
}
|
||||
|
||||
SDL_RenderGeometry(renderer, sprites[i], verts, 3, NULL, 0);
|
||||
}
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (done) {
|
||||
emscripten_cancel_main_loop();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
const char *icon = "icon.bmp";
|
||||
Uint32 then, now, frames;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
consumed = -1;
|
||||
if (SDL_strcasecmp(argv[i], "--blend") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
if (SDL_strcasecmp(argv[i + 1], "none") == 0) {
|
||||
blendMode = SDL_BLENDMODE_NONE;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "blend") == 0) {
|
||||
blendMode = SDL_BLENDMODE_BLEND;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "add") == 0) {
|
||||
blendMode = SDL_BLENDMODE_ADD;
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "mod") == 0) {
|
||||
blendMode = SDL_BLENDMODE_MOD;
|
||||
consumed = 2;
|
||||
}
|
||||
}
|
||||
} else if (SDL_strcasecmp(argv[i], "--use-texture") == 0) {
|
||||
use_texture = SDL_TRUE;
|
||||
consumed = 1;
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
static const char *options[] = { "[--blend none|blend|add|mod]", "[--use-texture]", NULL };
|
||||
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||
return 1;
|
||||
}
|
||||
i += consumed;
|
||||
}
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
/* Create the windows, initialize the renderers, and load the textures */
|
||||
sprites =
|
||||
(SDL_Texture **) SDL_malloc(state->num_windows * sizeof(*sprites));
|
||||
if (!sprites) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
/* Create the windows and initialize the renderers */
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
SDL_SetRenderDrawBlendMode(renderer, blendMode);
|
||||
SDL_SetRenderDrawColor(renderer, 0xA0, 0xA0, 0xA0, 0xFF);
|
||||
SDL_RenderClear(renderer);
|
||||
sprites[i] = NULL;
|
||||
}
|
||||
if (use_texture) {
|
||||
if (LoadSprite(icon) < 0) {
|
||||
quit(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
/* Main render loop */
|
||||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
++frames;
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
double fps = ((double) frames * 1000) / (now - then);
|
||||
SDL_Log("%2.2f frames per second\n", fps);
|
||||
}
|
||||
|
||||
quit(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -90,6 +90,7 @@ setpix(SDL_Surface *screen, float _x, float _y, unsigned int col)
|
||||
*pixmem32 = colour;
|
||||
}
|
||||
|
||||
#if 0 /* unused */
|
||||
static void
|
||||
drawLine(SDL_Surface *screen, float x0, float y0, float x1, float y1, unsigned int col)
|
||||
{
|
||||
@@ -98,6 +99,7 @@ drawLine(SDL_Surface *screen, float x0, float y0, float x1, float y1, unsigned i
|
||||
setpix(screen, x1 + t * (x0 - x1), y1 + t * (y0 - y1), col);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
drawCircle(SDL_Surface *screen, float x, float y, float r, unsigned int c)
|
||||
@@ -188,7 +190,8 @@ loop(void)
|
||||
case SDLK_i: {
|
||||
for (i = 0; i < SDL_GetNumTouchDevices(); ++i) {
|
||||
const SDL_TouchID id = SDL_GetTouchDevice(i);
|
||||
SDL_Log("Fingers Down on device %"SDL_PRIs64": %d", id, SDL_GetNumTouchFingers(id));
|
||||
const char *name = SDL_GetTouchName(i);
|
||||
SDL_Log("Fingers Down on device %"SDL_PRIs64" (%s): %d", id, name, SDL_GetNumTouchFingers(id));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -213,7 +216,7 @@ loop(void)
|
||||
|
||||
#if VERBOSE
|
||||
case SDL_FINGERMOTION:
|
||||
SDL_Log("Finger: %"SDL_PRIs64",x: %f, y: %f",event.tfinger.fingerId,
|
||||
SDL_Log("Finger: %"SDL_PRIs64", x: %f, y: %f",event.tfinger.fingerId,
|
||||
event.tfinger.x,event.tfinger.y);
|
||||
break;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -238,10 +238,10 @@ main(int argc, char *argv[])
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
if (SDL_strcasecmp(argv[i], "--fsaa") == 0 && i+1 < argc) {
|
||||
fsaa = atoi(argv[i+1]);
|
||||
fsaa = SDL_atoi(argv[i+1]);
|
||||
consumed = 2;
|
||||
} else if (SDL_strcasecmp(argv[i], "--accel") == 0 && i+1 < argc) {
|
||||
accel = atoi(argv[i+1]);
|
||||
accel = SDL_atoi(argv[i+1]);
|
||||
consumed = 2;
|
||||
} else {
|
||||
consumed = -1;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -22,8 +22,10 @@
|
||||
|
||||
#if defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__NACL__) \
|
||||
|| defined(__WINDOWS__) || defined(__LINUX__)
|
||||
#ifndef HAVE_OPENGLES2
|
||||
#define HAVE_OPENGLES2
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENGLES2
|
||||
|
||||
@@ -36,6 +38,18 @@ typedef struct GLES2_Context
|
||||
#undef SDL_PROC
|
||||
} GLES2_Context;
|
||||
|
||||
typedef struct shader_data
|
||||
{
|
||||
GLuint shader_program, shader_frag, shader_vert;
|
||||
|
||||
GLint attr_position;
|
||||
GLint attr_color, attr_mvp;
|
||||
|
||||
int angle_x, angle_y, angle_z;
|
||||
|
||||
GLuint position_buffer;
|
||||
GLuint color_buffer;
|
||||
} shader_data;
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static SDL_GLContext *context = NULL;
|
||||
@@ -195,13 +209,13 @@ multiply_matrix(float *lhs, float *rhs, float *r)
|
||||
* source: Passed-in shader source code.
|
||||
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
|
||||
*/
|
||||
void
|
||||
static void
|
||||
process_shader(GLuint *shader, const char * source, GLint shader_type)
|
||||
{
|
||||
GLint status = GL_FALSE;
|
||||
const char *shaders[1] = { NULL };
|
||||
char buffer[1024];
|
||||
GLsizei length;
|
||||
GLsizei length = 0;
|
||||
|
||||
/* Create shader and load into GL. */
|
||||
*shader = GL_CHECK(ctx.glCreateShader(shader_type));
|
||||
@@ -219,13 +233,35 @@ process_shader(GLuint *shader, const char * source, GLint shader_type)
|
||||
|
||||
/* Dump debug info (source and log) if compilation failed. */
|
||||
if(status != GL_TRUE) {
|
||||
ctx.glGetProgramInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
|
||||
ctx.glGetShaderInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
|
||||
buffer[length] = '\0';
|
||||
SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr);
|
||||
SDL_Log("Shader compilation failed: %s", buffer);
|
||||
fflush(stderr);
|
||||
quit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
link_program(struct shader_data *data)
|
||||
{
|
||||
GLint status = GL_FALSE;
|
||||
char buffer[1024];
|
||||
GLsizei length = 0;
|
||||
|
||||
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_vert));
|
||||
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_frag));
|
||||
GL_CHECK(ctx.glLinkProgram(data->shader_program));
|
||||
GL_CHECK(ctx.glGetProgramiv(data->shader_program, GL_LINK_STATUS, &status));
|
||||
|
||||
if(status != GL_TRUE) {
|
||||
ctx.glGetProgramInfoLog(data->shader_program, sizeof(buffer), &length, &buffer[0]);
|
||||
buffer[length] = '\0';
|
||||
SDL_Log("Program linking failed: %s", buffer);
|
||||
fflush(stderr);
|
||||
quit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
/* 3D data. Vertex range -0.5..0.5 in all axes.
|
||||
* Z -0.5 is near, 0.5 is far. */
|
||||
const float _vertices[] =
|
||||
@@ -361,17 +397,6 @@ const char* _shader_frag_src =
|
||||
" gl_FragColor = vec4(vv3color, 1.0); "
|
||||
" } ";
|
||||
|
||||
typedef struct shader_data
|
||||
{
|
||||
GLuint shader_program, shader_frag, shader_vert;
|
||||
|
||||
GLint attr_position;
|
||||
GLint attr_color, attr_mvp;
|
||||
|
||||
int angle_x, angle_y, angle_z;
|
||||
|
||||
} shader_data;
|
||||
|
||||
static void
|
||||
Render(unsigned int width, unsigned int height, shader_data* data)
|
||||
{
|
||||
@@ -668,9 +693,7 @@ main(int argc, char *argv[])
|
||||
data->shader_program = GL_CHECK(ctx.glCreateProgram());
|
||||
|
||||
/* Attach shaders and link shader_program */
|
||||
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_vert));
|
||||
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_frag));
|
||||
GL_CHECK(ctx.glLinkProgram(data->shader_program));
|
||||
link_program(data);
|
||||
|
||||
/* Get attribute locations of non-fixed attributes like color and texture coordinates. */
|
||||
data->attr_position = GL_CHECK(ctx.glGetAttribLocation(data->shader_program, "av4position"));
|
||||
@@ -686,8 +709,18 @@ main(int argc, char *argv[])
|
||||
GL_CHECK(ctx.glEnableVertexAttribArray(data->attr_color));
|
||||
|
||||
/* Populate attributes for position, color and texture coordinates etc. */
|
||||
GL_CHECK(ctx.glVertexAttribPointer(data->attr_position, 3, GL_FLOAT, GL_FALSE, 0, _vertices));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(data->attr_color, 3, GL_FLOAT, GL_FALSE, 0, _colors));
|
||||
|
||||
GL_CHECK(ctx.glGenBuffers(1, &data->position_buffer));
|
||||
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, data->position_buffer));
|
||||
GL_CHECK(ctx.glBufferData(GL_ARRAY_BUFFER, sizeof(_vertices), _vertices, GL_STATIC_DRAW));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(data->attr_position, 3, GL_FLOAT, GL_FALSE, 0, 0));
|
||||
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||
|
||||
GL_CHECK(ctx.glGenBuffers(1, &data->color_buffer));
|
||||
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, data->color_buffer));
|
||||
GL_CHECK(ctx.glBufferData(GL_ARRAY_BUFFER, sizeof(_colors), _colors, GL_STATIC_DRAW));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(data->attr_color, 3, GL_FLOAT, GL_FALSE, 0, 0));
|
||||
GL_CHECK(ctx.glBindBuffer(GL_ARRAY_BUFFER, 0));
|
||||
|
||||
GL_CHECK(ctx.glEnable(GL_CULL_FACE));
|
||||
GL_CHECK(ctx.glEnable(GL_DEPTH_TEST));
|
||||
|
||||
805
test/testgles2_sdf.c
Normal file
805
test/testgles2_sdf.c
Normal file
@@ -0,0 +1,805 @@
|
||||
/*
|
||||
Copyright (C) 1997-2022 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.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
|
||||
#if defined(__IPHONEOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__NACL__) \
|
||||
|| defined(__WINDOWS__) || defined(__LINUX__)
|
||||
#define HAVE_OPENGLES2
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_OPENGLES2
|
||||
|
||||
#include "SDL_opengles2.h"
|
||||
|
||||
typedef struct GLES2_Context
|
||||
{
|
||||
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
|
||||
#include "../src/render/opengles2/SDL_gles2funcs.h"
|
||||
#undef SDL_PROC
|
||||
} GLES2_Context;
|
||||
|
||||
|
||||
static SDL_Surface *g_surf_sdf = NULL;
|
||||
GLenum g_texture;
|
||||
GLenum g_texture_type = GL_TEXTURE_2D;
|
||||
GLfloat g_verts[24];
|
||||
typedef enum
|
||||
{
|
||||
GLES2_ATTRIBUTE_POSITION = 0,
|
||||
GLES2_ATTRIBUTE_TEXCOORD = 1,
|
||||
GLES2_ATTRIBUTE_ANGLE = 2,
|
||||
GLES2_ATTRIBUTE_CENTER = 3,
|
||||
} GLES2_Attribute;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GLES2_UNIFORM_PROJECTION,
|
||||
GLES2_UNIFORM_TEXTURE,
|
||||
GLES2_UNIFORM_COLOR,
|
||||
} GLES2_Uniform;
|
||||
|
||||
|
||||
GLuint g_uniform_locations[16];
|
||||
|
||||
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static SDL_GLContext *context = NULL;
|
||||
static int depth = 16;
|
||||
static GLES2_Context ctx;
|
||||
|
||||
static int LoadContext(GLES2_Context * data)
|
||||
{
|
||||
#if SDL_VIDEO_DRIVER_UIKIT
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#elif SDL_VIDEO_DRIVER_ANDROID
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#elif SDL_VIDEO_DRIVER_PANDORA
|
||||
#define __SDL_NOGETPROCADDR__
|
||||
#endif
|
||||
|
||||
#if defined __SDL_NOGETPROCADDR__
|
||||
#define SDL_PROC(ret,func,params) data->func=func;
|
||||
#else
|
||||
#define SDL_PROC(ret,func,params) \
|
||||
do { \
|
||||
data->func = SDL_GL_GetProcAddress(#func); \
|
||||
if ( ! data->func ) { \
|
||||
return SDL_SetError("Couldn't load GLES2 function %s: %s", #func, SDL_GetError()); \
|
||||
} \
|
||||
} while ( 0 );
|
||||
#endif /* __SDL_NOGETPROCADDR__ */
|
||||
|
||||
#include "../src/render/opengles2/SDL_gles2funcs.h"
|
||||
#undef SDL_PROC
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
quit(int rc)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (context != NULL) {
|
||||
for (i = 0; i < state->num_windows; i++) {
|
||||
if (context[i]) {
|
||||
SDL_GL_DeleteContext(context[i]);
|
||||
}
|
||||
}
|
||||
|
||||
SDL_free(context);
|
||||
}
|
||||
|
||||
SDLTest_CommonQuit(state);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
#define GL_CHECK(x) \
|
||||
x; \
|
||||
{ \
|
||||
GLenum glError = ctx.glGetError(); \
|
||||
if(glError != GL_NO_ERROR) { \
|
||||
SDL_Log("glGetError() = %i (0x%.8x) at line %i\n", glError, glError, __LINE__); \
|
||||
quit(1); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Create shader, load in source, compile, dump debug as necessary.
|
||||
*
|
||||
* shader: Pointer to return created shader ID.
|
||||
* source: Passed-in shader source code.
|
||||
* shader_type: Passed to GL, e.g. GL_VERTEX_SHADER.
|
||||
*/
|
||||
void
|
||||
process_shader(GLuint *shader, const char * source, GLint shader_type)
|
||||
{
|
||||
GLint status = GL_FALSE;
|
||||
const char *shaders[1] = { NULL };
|
||||
char buffer[1024];
|
||||
GLsizei length;
|
||||
|
||||
/* Create shader and load into GL. */
|
||||
*shader = GL_CHECK(ctx.glCreateShader(shader_type));
|
||||
|
||||
shaders[0] = source;
|
||||
|
||||
GL_CHECK(ctx.glShaderSource(*shader, 1, shaders, NULL));
|
||||
|
||||
/* Clean up shader source. */
|
||||
shaders[0] = NULL;
|
||||
|
||||
/* Try compiling the shader. */
|
||||
GL_CHECK(ctx.glCompileShader(*shader));
|
||||
GL_CHECK(ctx.glGetShaderiv(*shader, GL_COMPILE_STATUS, &status));
|
||||
|
||||
/* Dump debug info (source and log) if compilation failed. */
|
||||
if(status != GL_TRUE) {
|
||||
ctx.glGetProgramInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
|
||||
buffer[length] = '\0';
|
||||
SDL_Log("Shader compilation failed: %s", buffer);fflush(stderr);
|
||||
quit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Notes on a_angle:
|
||||
* It is a vector containing sine and cosine for rotation matrix
|
||||
* To get correct rotation for most cases when a_angle is disabled cosine
|
||||
* value is decremented by 1.0 to get proper output with 0.0 which is default value
|
||||
*/
|
||||
static const Uint8 GLES2_VertexSrc_Default_[] = " \
|
||||
uniform mat4 u_projection; \
|
||||
attribute vec2 a_position; \
|
||||
attribute vec2 a_texCoord; \
|
||||
attribute vec2 a_angle; \
|
||||
attribute vec2 a_center; \
|
||||
varying vec2 v_texCoord; \
|
||||
\
|
||||
void main() \
|
||||
{ \
|
||||
float s = a_angle[0]; \
|
||||
float c = a_angle[1] + 1.0; \
|
||||
mat2 rotationMatrix = mat2(c, -s, s, c); \
|
||||
vec2 position = rotationMatrix * (a_position - a_center) + a_center; \
|
||||
v_texCoord = a_texCoord; \
|
||||
gl_Position = u_projection * vec4(position, 0.0, 1.0);\
|
||||
gl_PointSize = 1.0; \
|
||||
} \
|
||||
";
|
||||
|
||||
static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_[] = " \
|
||||
precision mediump float; \
|
||||
uniform sampler2D u_texture; \
|
||||
uniform vec4 u_color; \
|
||||
varying vec2 v_texCoord; \
|
||||
\
|
||||
void main() \
|
||||
{ \
|
||||
gl_FragColor = texture2D(u_texture, v_texCoord); \
|
||||
gl_FragColor *= u_color; \
|
||||
} \
|
||||
";
|
||||
|
||||
/* RGB to ABGR conversion */
|
||||
static const Uint8 GLES2_FragmentSrc_TextureABGRSrc_SDF[] = " \
|
||||
#extension GL_OES_standard_derivatives : enable\n\
|
||||
\
|
||||
precision mediump float; \
|
||||
uniform sampler2D u_texture; \
|
||||
uniform vec4 u_color; \
|
||||
varying vec2 v_texCoord; \
|
||||
\
|
||||
void main() \
|
||||
{ \
|
||||
vec4 abgr = texture2D(u_texture, v_texCoord); \
|
||||
\
|
||||
float sigDist = abgr.a; \
|
||||
\
|
||||
float w = fwidth( sigDist );\
|
||||
float alpha = clamp(smoothstep(0.5 - w, 0.5 + w, sigDist), 0.0, 1.0); \
|
||||
\
|
||||
gl_FragColor = vec4(abgr.rgb, abgr.a * alpha); \
|
||||
gl_FragColor.rgb *= gl_FragColor.a; \
|
||||
gl_FragColor *= u_color; \
|
||||
} \
|
||||
";
|
||||
|
||||
/* RGB to ABGR conversion DEBUG */
|
||||
static const char *GLES2_FragmentSrc_TextureABGRSrc_SDF_dbg = " \
|
||||
#extension GL_OES_standard_derivatives : enable\n\
|
||||
\
|
||||
precision mediump float; \
|
||||
uniform sampler2D u_texture; \
|
||||
uniform vec4 u_color; \
|
||||
varying vec2 v_texCoord; \
|
||||
\
|
||||
void main() \
|
||||
{ \
|
||||
vec4 abgr = texture2D(u_texture, v_texCoord); \
|
||||
\
|
||||
float a = abgr.a; \
|
||||
gl_FragColor = vec4(a, a, a, 1.0); \
|
||||
} \
|
||||
";
|
||||
|
||||
|
||||
static float g_val = 1.0f;
|
||||
static int g_use_SDF = 1;
|
||||
static int g_use_SDF_debug = 0;
|
||||
static float g_angle = 0.0f;
|
||||
static float matrix_mvp[4][4];
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct shader_data
|
||||
{
|
||||
GLuint shader_program, shader_frag, shader_vert;
|
||||
|
||||
GLint attr_position;
|
||||
GLint attr_color, attr_mvp;
|
||||
|
||||
} shader_data;
|
||||
|
||||
static void
|
||||
Render(unsigned int width, unsigned int height, shader_data* data)
|
||||
{
|
||||
float *verts = g_verts;
|
||||
ctx.glViewport(0, 0, 640, 480);
|
||||
|
||||
GL_CHECK(ctx.glClear(GL_COLOR_BUFFER_BIT));
|
||||
|
||||
GL_CHECK(ctx.glUniformMatrix4fv(g_uniform_locations[GLES2_UNIFORM_PROJECTION], 1, GL_FALSE, (const float *)matrix_mvp));
|
||||
GL_CHECK(ctx.glUniform4f(g_uniform_locations[GLES2_UNIFORM_COLOR], 1.0f, 1.0f, 1.0f, 1.0f));
|
||||
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_ANGLE, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *) (verts + 16)));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *) (verts + 8)));
|
||||
GL_CHECK(ctx.glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, (const GLvoid *) verts));
|
||||
|
||||
GL_CHECK(ctx.glDrawArrays(GL_TRIANGLE_STRIP, 0, 4));
|
||||
}
|
||||
|
||||
|
||||
void renderCopy_angle(float degree_angle)
|
||||
{
|
||||
const float radian_angle = (float)(3.141592 * degree_angle) / 180.0;
|
||||
const GLfloat s = (GLfloat) SDL_sin(radian_angle);
|
||||
const GLfloat c = (GLfloat) SDL_cos(radian_angle) - 1.0f;
|
||||
GLfloat *verts = g_verts + 16;
|
||||
*(verts++) = s;
|
||||
*(verts++) = c;
|
||||
*(verts++) = s;
|
||||
*(verts++) = c;
|
||||
*(verts++) = s;
|
||||
*(verts++) = c;
|
||||
*(verts++) = s;
|
||||
*(verts++) = c;
|
||||
}
|
||||
|
||||
|
||||
void renderCopy_position(SDL_Rect *srcrect, SDL_Rect *dstrect)
|
||||
{
|
||||
GLfloat minx, miny, maxx, maxy;
|
||||
GLfloat minu, maxu, minv, maxv;
|
||||
GLfloat *verts = g_verts;
|
||||
|
||||
minx = dstrect->x;
|
||||
miny = dstrect->y;
|
||||
maxx = dstrect->x + dstrect->w;
|
||||
maxy = dstrect->y + dstrect->h;
|
||||
|
||||
minu = (GLfloat) srcrect->x / g_surf_sdf->w;
|
||||
maxu = (GLfloat) (srcrect->x + srcrect->w) / g_surf_sdf->w;
|
||||
minv = (GLfloat) srcrect->y / g_surf_sdf->h;
|
||||
maxv = (GLfloat) (srcrect->y + srcrect->h) / g_surf_sdf->h;
|
||||
|
||||
*(verts++) = minx;
|
||||
*(verts++) = miny;
|
||||
*(verts++) = maxx;
|
||||
*(verts++) = miny;
|
||||
*(verts++) = minx;
|
||||
*(verts++) = maxy;
|
||||
*(verts++) = maxx;
|
||||
*(verts++) = maxy;
|
||||
|
||||
*(verts++) = minu;
|
||||
*(verts++) = minv;
|
||||
*(verts++) = maxu;
|
||||
*(verts++) = minv;
|
||||
*(verts++) = minu;
|
||||
*(verts++) = maxv;
|
||||
*(verts++) = maxu;
|
||||
*(verts++) = maxv;
|
||||
}
|
||||
|
||||
int done;
|
||||
Uint32 frames;
|
||||
shader_data *datas;
|
||||
|
||||
void loop()
|
||||
{
|
||||
SDL_Event event;
|
||||
int i;
|
||||
int status;
|
||||
|
||||
/* Check for events */
|
||||
++frames;
|
||||
while (SDL_PollEvent(&event) && !done) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
{
|
||||
const int sym = event.key.keysym.sym;
|
||||
|
||||
if (sym == SDLK_TAB) {
|
||||
SDL_Log("Tab");
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (sym == SDLK_LEFT) g_val -= 0.05;
|
||||
if (sym == SDLK_RIGHT) g_val += 0.05;
|
||||
if (sym == SDLK_UP) g_angle -= 1;
|
||||
if (sym == SDLK_DOWN) g_angle += 1;
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case SDL_WINDOWEVENT:
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_RESIZED:
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
if (event.window.windowID == SDL_GetWindowID(state->windows[i])) {
|
||||
int w, h;
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
break;
|
||||
}
|
||||
/* Change view port to the new window dimensions */
|
||||
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
||||
ctx.glViewport(0, 0, w, h);
|
||||
state->window_w = event.window.data1;
|
||||
state->window_h = event.window.data2;
|
||||
/* Update window content */
|
||||
Render(event.window.data1, event.window.data2, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
SDLTest_CommonEvent(state, &event, &done);
|
||||
}
|
||||
|
||||
|
||||
matrix_mvp[3][0] = -1.0f;
|
||||
matrix_mvp[3][3] = 1.0f;
|
||||
|
||||
matrix_mvp[0][0] = 2.0f / 640.0;
|
||||
matrix_mvp[1][1] = -2.0f / 480.0;
|
||||
matrix_mvp[3][1] = 1.0f;
|
||||
|
||||
if (0)
|
||||
{
|
||||
float *f = (float *) matrix_mvp;
|
||||
SDL_Log("-----------------------------------");
|
||||
SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
|
||||
SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
|
||||
SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
|
||||
SDL_Log("[ %f, %f, %f, %f ]", *f++, *f++, *f++, *f++);
|
||||
SDL_Log("-----------------------------------");
|
||||
}
|
||||
|
||||
renderCopy_angle(g_angle);
|
||||
|
||||
{
|
||||
int w, h;
|
||||
SDL_Rect rs, rd;
|
||||
|
||||
SDL_GL_GetDrawableSize(state->windows[0], &w, &h);
|
||||
|
||||
rs.x = 0; rs.y = 0; rs.w = g_surf_sdf->w; rs.h = g_surf_sdf->h;
|
||||
rd.w = g_surf_sdf->w * g_val; rd.h = g_surf_sdf->h * g_val;
|
||||
rd.x = (w - rd.w) / 2; rd.y = (h - rd.h) / 2;
|
||||
renderCopy_position(&rs, &rd);
|
||||
}
|
||||
|
||||
|
||||
if (!done) {
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
|
||||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
Render(state->window_w, state->window_h, &datas[i]);
|
||||
SDL_GL_SwapWindow(state->windows[i]);
|
||||
}
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
else {
|
||||
emscripten_cancel_main_loop();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int fsaa, accel;
|
||||
int value;
|
||||
int i;
|
||||
SDL_DisplayMode mode;
|
||||
Uint32 then, now;
|
||||
int status;
|
||||
shader_data *data;
|
||||
|
||||
/* Initialize parameters */
|
||||
fsaa = 0;
|
||||
accel = 0;
|
||||
|
||||
/* Initialize test framework */
|
||||
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
|
||||
if (!state) {
|
||||
return 1;
|
||||
}
|
||||
for (i = 1; i < argc;) {
|
||||
int consumed;
|
||||
|
||||
consumed = SDLTest_CommonArg(state, i);
|
||||
if (consumed == 0) {
|
||||
if (SDL_strcasecmp(argv[i], "--fsaa") == 0) {
|
||||
++fsaa;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcasecmp(argv[i], "--accel") == 0) {
|
||||
++accel;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcasecmp(argv[i], "--zdepth") == 0) {
|
||||
i++;
|
||||
if (!argv[i]) {
|
||||
consumed = -1;
|
||||
} else {
|
||||
depth = SDL_atoi(argv[i]);
|
||||
consumed = 1;
|
||||
}
|
||||
} else {
|
||||
consumed = -1;
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
static const char *options[] = { "[--fsaa]", "[--accel]", "[--zdepth %d]", NULL };
|
||||
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||
quit(1);
|
||||
}
|
||||
i += consumed;
|
||||
}
|
||||
|
||||
/* Set OpenGL parameters */
|
||||
state->window_flags |= SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;
|
||||
state->gl_red_size = 5;
|
||||
state->gl_green_size = 5;
|
||||
state->gl_blue_size = 5;
|
||||
state->gl_depth_size = depth;
|
||||
state->gl_major_version = 2;
|
||||
state->gl_minor_version = 0;
|
||||
state->gl_profile_mask = SDL_GL_CONTEXT_PROFILE_ES;
|
||||
|
||||
if (fsaa) {
|
||||
state->gl_multisamplebuffers=1;
|
||||
state->gl_multisamplesamples=fsaa;
|
||||
}
|
||||
if (accel) {
|
||||
state->gl_accelerated=1;
|
||||
}
|
||||
if (!SDLTest_CommonInit(state)) {
|
||||
quit(2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
context = (SDL_GLContext *)SDL_calloc(state->num_windows, sizeof(context));
|
||||
if (context == NULL) {
|
||||
SDL_Log("Out of memory!\n");
|
||||
quit(2);
|
||||
}
|
||||
|
||||
/* Create OpenGL ES contexts */
|
||||
for (i = 0; i < state->num_windows; i++) {
|
||||
context[i] = SDL_GL_CreateContext(state->windows[i]);
|
||||
if (!context[i]) {
|
||||
SDL_Log("SDL_GL_CreateContext(): %s\n", SDL_GetError());
|
||||
quit(2);
|
||||
}
|
||||
}
|
||||
|
||||
/* Important: call this *after* creating the context */
|
||||
if (LoadContext(&ctx) < 0) {
|
||||
SDL_Log("Could not load GLES2 functions\n");
|
||||
quit(2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
SDL_memset(matrix_mvp, 0, sizeof (matrix_mvp));
|
||||
|
||||
{
|
||||
SDL_Surface *tmp;
|
||||
char *f;
|
||||
g_use_SDF = 1;
|
||||
g_use_SDF_debug = 0;
|
||||
|
||||
if (g_use_SDF) {
|
||||
f = "testgles2_sdf_img_sdf.bmp";
|
||||
} else {
|
||||
f = "testgles2_sdf_img_normal.bmp";
|
||||
}
|
||||
|
||||
SDL_Log("SDF is %s", g_use_SDF ? "enabled" : "disabled");
|
||||
|
||||
/* Load SDF BMP image */
|
||||
#if 1
|
||||
tmp = SDL_LoadBMP(f);
|
||||
if (tmp == NULL) {
|
||||
SDL_Log("missing image file: %s", f);
|
||||
exit(-1);
|
||||
} else {
|
||||
SDL_Log("Load image file: %s", f);
|
||||
}
|
||||
|
||||
#else
|
||||
/* Generate SDF image using SDL_ttf */
|
||||
|
||||
#include "SDL_ttf.h"
|
||||
char *font_file = "./font/DroidSansFallback.ttf";
|
||||
char *str = "Abcde";
|
||||
SDL_Color color = { 0, 0,0, 255};
|
||||
|
||||
TTF_Init();
|
||||
TTF_Font *font = TTF_OpenFont(font_file, 72);
|
||||
|
||||
if (font == NULL) {
|
||||
SDL_Log("Cannot open font %s", font_file);
|
||||
}
|
||||
|
||||
TTF_SetFontSDF(font, g_use_SDF);
|
||||
SDL_Surface *tmp = TTF_RenderUTF8_Blended(font, str, color);
|
||||
|
||||
SDL_Log("err: %s", SDL_GetError());
|
||||
if (tmp == NULL) {
|
||||
SDL_Log("can't render text");
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_SaveBMP(tmp, f);
|
||||
|
||||
TTF_CloseFont(font);
|
||||
TTF_Quit();
|
||||
#endif
|
||||
g_surf_sdf = SDL_ConvertSurfaceFormat(tmp, SDL_PIXELFORMAT_ABGR8888, 0);
|
||||
|
||||
SDL_SetSurfaceBlendMode(g_surf_sdf, SDL_BLENDMODE_BLEND);
|
||||
}
|
||||
|
||||
|
||||
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
|
||||
SDL_GL_SetSwapInterval(1);
|
||||
} else {
|
||||
SDL_GL_SetSwapInterval(0);
|
||||
}
|
||||
|
||||
SDL_GetCurrentDisplayMode(0, &mode);
|
||||
SDL_Log("Screen bpp: %d\n", SDL_BITSPERPIXEL(mode.format));
|
||||
SDL_Log("\n");
|
||||
SDL_Log("Vendor : %s\n", ctx.glGetString(GL_VENDOR));
|
||||
SDL_Log("Renderer : %s\n", ctx.glGetString(GL_RENDERER));
|
||||
SDL_Log("Version : %s\n", ctx.glGetString(GL_VERSION));
|
||||
SDL_Log("Extensions : %s\n", ctx.glGetString(GL_EXTENSIONS));
|
||||
SDL_Log("\n");
|
||||
|
||||
status = SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_RED_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_RED_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_GREEN_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_GREEN_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_BLUE_SIZE: requested %d, got %d\n", 5, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_BLUE_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_DEPTH_SIZE: requested %d, got %d\n", depth, value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_DEPTH_SIZE: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
if (fsaa) {
|
||||
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_MULTISAMPLEBUFFERS: requested 1, got %d\n", value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_MULTISAMPLEBUFFERS: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
status = SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_MULTISAMPLESAMPLES: requested %d, got %d\n", fsaa,
|
||||
value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_MULTISAMPLESAMPLES: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
if (accel) {
|
||||
status = SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &value);
|
||||
if (!status) {
|
||||
SDL_Log("SDL_GL_ACCELERATED_VISUAL: requested 1, got %d\n", value);
|
||||
} else {
|
||||
SDL_Log( "Failed to get SDL_GL_ACCELERATED_VISUAL: %s\n",
|
||||
SDL_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
datas = (shader_data *)SDL_calloc(state->num_windows, sizeof(shader_data));
|
||||
|
||||
/* Set rendering settings for each context */
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
|
||||
int w, h;
|
||||
status = SDL_GL_MakeCurrent(state->windows[i], context[i]);
|
||||
if (status) {
|
||||
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
|
||||
|
||||
/* Continue for next window */
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
int format = GL_RGBA;
|
||||
int type = GL_UNSIGNED_BYTE;
|
||||
|
||||
GL_CHECK(ctx.glGenTextures(1, &g_texture));
|
||||
|
||||
ctx.glActiveTexture(GL_TEXTURE0);
|
||||
ctx.glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
ctx.glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
ctx.glBindTexture(g_texture_type, g_texture);
|
||||
|
||||
ctx.glTexParameteri(g_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
ctx.glTexParameteri(g_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
ctx.glTexParameteri(g_texture_type, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
ctx.glTexParameteri(g_texture_type, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
GL_CHECK(ctx.glTexImage2D(g_texture_type, 0, format, g_surf_sdf->w, g_surf_sdf->h, 0, format, type, NULL));
|
||||
GL_CHECK(ctx.glTexSubImage2D(g_texture_type, 0, 0 /* xoffset */, 0 /* yoffset */, g_surf_sdf->w, g_surf_sdf->h, format, type, g_surf_sdf->pixels));
|
||||
}
|
||||
|
||||
|
||||
SDL_GL_GetDrawableSize(state->windows[i], &w, &h);
|
||||
ctx.glViewport(0, 0, w, h);
|
||||
|
||||
data = &datas[i];
|
||||
|
||||
/* Shader Initialization */
|
||||
process_shader(&data->shader_vert, GLES2_VertexSrc_Default_, GL_VERTEX_SHADER);
|
||||
|
||||
if (g_use_SDF) {
|
||||
if (g_use_SDF_debug == 0) {
|
||||
process_shader(&data->shader_frag, GLES2_FragmentSrc_TextureABGRSrc_SDF, GL_FRAGMENT_SHADER);
|
||||
} else {
|
||||
process_shader(&data->shader_frag, GLES2_FragmentSrc_TextureABGRSrc_SDF_dbg, GL_FRAGMENT_SHADER);
|
||||
}
|
||||
} else {
|
||||
process_shader(&data->shader_frag, GLES2_FragmentSrc_TextureABGRSrc_, GL_FRAGMENT_SHADER);
|
||||
}
|
||||
|
||||
/* Create shader_program (ready to attach shaders) */
|
||||
data->shader_program = GL_CHECK(ctx.glCreateProgram());
|
||||
|
||||
/* Attach shaders and link shader_program */
|
||||
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_vert));
|
||||
GL_CHECK(ctx.glAttachShader(data->shader_program, data->shader_frag));
|
||||
GL_CHECK(ctx.glLinkProgram(data->shader_program));
|
||||
|
||||
ctx.glBindAttribLocation(data->shader_program, GLES2_ATTRIBUTE_POSITION, "a_position");
|
||||
ctx.glBindAttribLocation(data->shader_program, GLES2_ATTRIBUTE_TEXCOORD, "a_texCoord");
|
||||
ctx.glBindAttribLocation(data->shader_program, GLES2_ATTRIBUTE_ANGLE, "a_angle");
|
||||
ctx.glBindAttribLocation(data->shader_program, GLES2_ATTRIBUTE_CENTER, "a_center");
|
||||
|
||||
/* Predetermine locations of uniform variables */
|
||||
g_uniform_locations[GLES2_UNIFORM_PROJECTION] = ctx.glGetUniformLocation(data->shader_program, "u_projection");
|
||||
g_uniform_locations[GLES2_UNIFORM_TEXTURE] = ctx.glGetUniformLocation(data->shader_program, "u_texture");
|
||||
g_uniform_locations[GLES2_UNIFORM_COLOR] = ctx.glGetUniformLocation(data->shader_program, "u_color");
|
||||
|
||||
GL_CHECK(ctx.glUseProgram(data->shader_program));
|
||||
|
||||
ctx.glEnableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_ANGLE);
|
||||
ctx.glDisableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_CENTER);
|
||||
ctx.glEnableVertexAttribArray(GLES2_ATTRIBUTE_POSITION);
|
||||
ctx.glEnableVertexAttribArray((GLenum) GLES2_ATTRIBUTE_TEXCOORD);
|
||||
|
||||
|
||||
ctx.glUniform1i(g_uniform_locations[GLES2_UNIFORM_TEXTURE], 0); /* always texture unit 0. */
|
||||
ctx.glActiveTexture(GL_TEXTURE0);
|
||||
ctx.glBindTexture(g_texture_type, g_texture);
|
||||
GL_CHECK(ctx.glClearColor(1, 1, 1, 1));
|
||||
|
||||
// SDL_BLENDMODE_BLEND
|
||||
GL_CHECK(ctx.glEnable(GL_BLEND));
|
||||
ctx.glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
|
||||
ctx.glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* Main render loop */
|
||||
frames = 0;
|
||||
then = SDL_GetTicks();
|
||||
done = 0;
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop(loop, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop();
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Print out some timing information */
|
||||
now = SDL_GetTicks();
|
||||
if (now > then) {
|
||||
SDL_Log("%2.2f frames per second\n",
|
||||
((double) frames * 1000) / (now - then));
|
||||
}
|
||||
#if !defined(__ANDROID__) && !defined(__NACL__)
|
||||
quit(0);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* HAVE_OPENGLES2 */
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Log("No OpenGL ES support on this system\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* HAVE_OPENGLES2 */
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
BIN
test/testgles2_sdf_img_normal.bmp
Normal file
BIN
test/testgles2_sdf_img_normal.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 66 KiB |
BIN
test/testgles2_sdf_img_sdf.bmp
Normal file
BIN
test/testgles2_sdf_img_sdf.bmp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
@@ -14,10 +14,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
/*
|
||||
* includes
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h> /* strstr */
|
||||
#include <ctype.h> /* isdigit */
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifndef SDL_HAPTIC_DISABLED
|
||||
@@ -29,7 +25,7 @@ static SDL_Haptic *haptic;
|
||||
* prototypes
|
||||
*/
|
||||
static void abort_execution(void);
|
||||
static void HapticPrintSupported(SDL_Haptic * haptic);
|
||||
static void HapticPrintSupported(SDL_Haptic *);
|
||||
|
||||
|
||||
/**
|
||||
@@ -55,7 +51,7 @@ main(int argc, char **argv)
|
||||
index = -1;
|
||||
if (argc > 1) {
|
||||
name = argv[1];
|
||||
if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
|
||||
if ((SDL_strcmp(name, "--help") == 0) || (SDL_strcmp(name, "-h") == 0)) {
|
||||
SDL_Log("USAGE: %s [device]\n"
|
||||
"If device is a two-digit number it'll use it as an index, otherwise\n"
|
||||
"it'll use it as if it were part of the device's name.\n",
|
||||
@@ -63,9 +59,9 @@ main(int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
i = strlen(name);
|
||||
if ((i < 3) && isdigit(name[0]) && ((i == 1) || isdigit(name[1]))) {
|
||||
index = atoi(name);
|
||||
i = SDL_strlen(name);
|
||||
if ((i < 3) && SDL_isdigit(name[0]) && ((i == 1) || SDL_isdigit(name[1]))) {
|
||||
index = SDL_atoi(name);
|
||||
name = NULL;
|
||||
}
|
||||
}
|
||||
@@ -82,7 +78,7 @@ main(int argc, char **argv)
|
||||
/* Try to find matching device */
|
||||
else {
|
||||
for (i = 0; i < SDL_NumHaptics(); i++) {
|
||||
if (strstr(SDL_HapticName(i), name) != NULL)
|
||||
if (SDL_strstr(SDL_HapticName(i), name) != NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -110,7 +106,7 @@ main(int argc, char **argv)
|
||||
SDL_ClearError();
|
||||
|
||||
/* Create effects. */
|
||||
memset(&efx, 0, sizeof(efx));
|
||||
SDL_memset(&efx, 0, sizeof(efx));
|
||||
nefx = 0;
|
||||
supported = SDL_HapticQuery(haptic);
|
||||
|
||||
@@ -314,13 +310,13 @@ abort_execution(void)
|
||||
* Displays information about the haptic device.
|
||||
*/
|
||||
static void
|
||||
HapticPrintSupported(SDL_Haptic * haptic)
|
||||
HapticPrintSupported(SDL_Haptic * ptr)
|
||||
{
|
||||
unsigned int supported;
|
||||
|
||||
supported = SDL_HapticQuery(haptic);
|
||||
supported = SDL_HapticQuery(ptr);
|
||||
SDL_Log(" Supported effects [%d effects, %d playing]:\n",
|
||||
SDL_HapticNumEffects(haptic), SDL_HapticNumEffectsPlaying(haptic));
|
||||
SDL_HapticNumEffects(ptr), SDL_HapticNumEffectsPlaying(ptr));
|
||||
if (supported & SDL_HAPTIC_CONSTANT)
|
||||
SDL_Log(" constant\n");
|
||||
if (supported & SDL_HAPTIC_SINE)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -42,6 +42,8 @@ main(int argc, char *argv[])
|
||||
"UCS4",
|
||||
"UCS-4",
|
||||
};
|
||||
|
||||
const char * fname;
|
||||
char buffer[BUFSIZ];
|
||||
char *ucs4;
|
||||
char *test[2];
|
||||
@@ -52,12 +54,10 @@ main(int argc, char *argv[])
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
if (!argv[1]) {
|
||||
argv[1] = "utf8.txt";
|
||||
}
|
||||
file = fopen(argv[1], "rb");
|
||||
fname = (argc < 2) ? "utf8.txt" : argv[1];
|
||||
file = fopen(fname, "rb");
|
||||
if (!file) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", argv[1]);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to open %s\n", fname);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -35,7 +35,7 @@
|
||||
#define DEFAULT_FONT "NoDefaultFont.ttf"
|
||||
#endif
|
||||
#else
|
||||
#define DEFAULT_FONT "unifont-9.0.02.hex"
|
||||
#define DEFAULT_FONT "unifont-13.0.06.hex"
|
||||
#endif
|
||||
#define MAX_TEXT_LENGTH 256
|
||||
|
||||
@@ -648,12 +648,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
for (argc--, argv++; argc > 0; argc--, argv++)
|
||||
{
|
||||
if (strcmp(argv[0], "--help") == 0) {
|
||||
if (SDL_strcmp(argv[0], "--help") == 0) {
|
||||
usage();
|
||||
return 0;
|
||||
}
|
||||
|
||||
else if (strcmp(argv[0], "--font") == 0)
|
||||
else if (SDL_strcmp(argv[0], "--font") == 0)
|
||||
{
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -38,14 +38,14 @@ static SDL_Joystick *joystick = NULL;
|
||||
static SDL_bool done = SDL_FALSE;
|
||||
|
||||
static void
|
||||
PrintJoystick(SDL_Joystick *joystick)
|
||||
PrintJoystick(SDL_Joystick *joy)
|
||||
{
|
||||
const char *type;
|
||||
char guid[64];
|
||||
|
||||
SDL_assert(SDL_JoystickFromInstanceID(SDL_JoystickInstanceID(joystick)) == joystick);
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), guid, sizeof (guid));
|
||||
switch (SDL_JoystickGetType(joystick)) {
|
||||
SDL_assert(SDL_JoystickFromInstanceID(SDL_JoystickInstanceID(joy)) == joy);
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joy), guid, sizeof (guid));
|
||||
switch (SDL_JoystickGetType(joy)) {
|
||||
case SDL_JOYSTICK_TYPE_GAMECONTROLLER:
|
||||
type = "Game Controller";
|
||||
break;
|
||||
@@ -78,21 +78,28 @@ PrintJoystick(SDL_Joystick *joystick)
|
||||
break;
|
||||
}
|
||||
SDL_Log("Joystick\n");
|
||||
SDL_Log(" name: %s\n", SDL_JoystickName(joystick));
|
||||
SDL_Log(" type: %s\n", type);
|
||||
SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joystick));
|
||||
SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joystick));
|
||||
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joystick));
|
||||
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
|
||||
SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick));
|
||||
SDL_Log(" guid: %s\n", guid);
|
||||
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joystick), SDL_JoystickGetProduct(joystick));
|
||||
SDL_Log(" name: %s\n", SDL_JoystickName(joy));
|
||||
SDL_Log(" type: %s\n", type);
|
||||
SDL_Log(" LED: %s\n", SDL_JoystickHasLED(joy) ? "yes" : "no");
|
||||
SDL_Log(" rumble: %s\n", SDL_JoystickHasRumble(joy) ? "yes" : "no");
|
||||
SDL_Log("trigger rumble: %s\n", SDL_JoystickHasRumbleTriggers(joy) ? "yes" : "no");
|
||||
SDL_Log(" axes: %d\n", SDL_JoystickNumAxes(joy));
|
||||
SDL_Log(" balls: %d\n", SDL_JoystickNumBalls(joy));
|
||||
SDL_Log(" hats: %d\n", SDL_JoystickNumHats(joy));
|
||||
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joy));
|
||||
SDL_Log(" instance id: %d\n", SDL_JoystickInstanceID(joy));
|
||||
SDL_Log(" guid: %s\n", guid);
|
||||
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joy), SDL_JoystickGetProduct(joy));
|
||||
}
|
||||
|
||||
static void
|
||||
DrawRect(SDL_Renderer *r, const int x, const int y, const int w, const int h)
|
||||
{
|
||||
const SDL_Rect area = { x, y, w, h };
|
||||
SDL_Rect area;
|
||||
area.x = x;
|
||||
area.y = y;
|
||||
area.w = w;
|
||||
area.h = h;
|
||||
SDL_RenderFillRect(r, &area);
|
||||
}
|
||||
|
||||
@@ -179,7 +186,7 @@ loop(void *arg)
|
||||
(event.key.keysym.sym != SDLK_AC_BACK)) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
SDL_FALLTHROUGH;
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
case SDL_QUIT:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -44,7 +44,7 @@ main(int argc, char *argv[])
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "--hello") == 0) {
|
||||
if (SDL_strcmp(argv[1], "--hello") == 0) {
|
||||
hello = 1;
|
||||
libname = argv[2];
|
||||
symname = "puts";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -61,9 +61,9 @@ button_messagebox(void *eventNumber)
|
||||
if (success == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
if (eventNumber) {
|
||||
SDL_UserEvent event;
|
||||
SDL_Event event;
|
||||
event.type = (intptr_t)eventNumber;
|
||||
SDL_PushEvent((SDL_Event*)&event);
|
||||
SDL_PushEvent(&event);
|
||||
return 1;
|
||||
} else {
|
||||
quit(2);
|
||||
@@ -72,9 +72,9 @@ button_messagebox(void *eventNumber)
|
||||
SDL_Log("Pressed button: %d, %s\n", button, button == -1 ? "[closed]" : button == 1 ? "Cancel" : "OK");
|
||||
|
||||
if (eventNumber) {
|
||||
SDL_UserEvent event;
|
||||
SDL_Event event;
|
||||
event.type = (intptr_t)eventNumber;
|
||||
SDL_PushEvent((SDL_Event*)&event);
|
||||
SDL_PushEvent(&event);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -189,9 +189,15 @@ main(int argc, char *argv[])
|
||||
SDL_Event event;
|
||||
SDL_Window *window = SDL_CreateWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, 0);
|
||||
|
||||
/* On wayland, no window will actually show until something has
|
||||
actually been displayed.
|
||||
*/
|
||||
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
success = SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR,
|
||||
"Simple MessageBox",
|
||||
"This is a simple error MessageBox with a parent window",
|
||||
"This is a simple error MessageBox with a parent window. Press a key or close the window after dismissing this messagebox.",
|
||||
window);
|
||||
if (success == -1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error Presenting MessageBox: %s\n", SDL_GetError());
|
||||
|
||||
231
test/testmouse.c
Normal file
231
test/testmouse.c
Normal file
@@ -0,0 +1,231 @@
|
||||
/*
|
||||
Copyright (C) 1997-2022 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.
|
||||
*/
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#include <emscripten/emscripten.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h> /* exit() */
|
||||
|
||||
#ifdef __IPHONEOS__
|
||||
#define SCREEN_WIDTH 320
|
||||
#define SCREEN_HEIGHT 480
|
||||
#else
|
||||
#define SCREEN_WIDTH 640
|
||||
#define SCREEN_HEIGHT 480
|
||||
#endif
|
||||
|
||||
static SDL_Window *window;
|
||||
|
||||
typedef struct _Line {
|
||||
struct _Line *next;
|
||||
|
||||
int x1, y1, x2, y2;
|
||||
Uint8 r, g, b;
|
||||
} Line;
|
||||
|
||||
static Line *active = NULL;
|
||||
static Line *lines = NULL;
|
||||
static int buttons = 0;
|
||||
|
||||
static SDL_bool wheel_x_active = SDL_FALSE;
|
||||
static SDL_bool wheel_y_active = SDL_FALSE;
|
||||
static float wheel_x = SCREEN_WIDTH * 0.5f;
|
||||
static float wheel_y = SCREEN_HEIGHT * 0.5f;
|
||||
|
||||
static SDL_bool done = SDL_FALSE;
|
||||
|
||||
void
|
||||
DrawLine(SDL_Renderer * renderer, Line * line)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, line->r, line->g, line->b, 255);
|
||||
SDL_RenderDrawLine(renderer, line->x1, line->y1, line->x2, line->y2);
|
||||
}
|
||||
|
||||
void
|
||||
DrawLines(SDL_Renderer * renderer)
|
||||
{
|
||||
Line *next = lines;
|
||||
while (next != NULL) {
|
||||
DrawLine(renderer, next);
|
||||
next = next->next;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
AppendLine(Line *line)
|
||||
{
|
||||
if (lines) {
|
||||
Line *next = lines;
|
||||
while (next->next != NULL) {
|
||||
next = next->next;
|
||||
}
|
||||
next->next = line;
|
||||
} else {
|
||||
lines = line;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop(void *arg)
|
||||
{
|
||||
SDL_Renderer *renderer = (SDL_Renderer *)arg;
|
||||
SDL_Event event;
|
||||
|
||||
/* Check for events */
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_MOUSEWHEEL:
|
||||
if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) {
|
||||
event.wheel.preciseX *= -1.0f;
|
||||
event.wheel.preciseY *= -1.0f;
|
||||
event.wheel.x *= -1;
|
||||
event.wheel.y *= -1;
|
||||
}
|
||||
if (event.wheel.preciseX != 0.0f) {
|
||||
wheel_x_active = SDL_TRUE;
|
||||
/* "positive to the right and negative to the left" */
|
||||
wheel_x += event.wheel.preciseX * 10.0f;
|
||||
}
|
||||
if (event.wheel.preciseY != 0.0f) {
|
||||
wheel_y_active = SDL_TRUE;
|
||||
/* "positive away from the user and negative towards the user" */
|
||||
wheel_y -= event.wheel.preciseY * 10.0f;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_MOUSEMOTION:
|
||||
if (!active)
|
||||
break;
|
||||
|
||||
active->x2 = event.motion.x;
|
||||
active->y2 = event.motion.y;
|
||||
break;
|
||||
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
if (!active) {
|
||||
active = SDL_calloc(1, sizeof(*active));
|
||||
active->x1 = active->x2 = event.button.x;
|
||||
active->y1 = active->y2 = event.button.y;
|
||||
}
|
||||
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT: active->r = 255; buttons |= SDL_BUTTON_LMASK; break;
|
||||
case SDL_BUTTON_MIDDLE: active->g = 255; buttons |= SDL_BUTTON_MMASK; break;
|
||||
case SDL_BUTTON_RIGHT: active->b = 255; buttons |= SDL_BUTTON_RMASK; break;
|
||||
case SDL_BUTTON_X1: active->r = 255; active->b = 255; buttons |= SDL_BUTTON_X1MASK; break;
|
||||
case SDL_BUTTON_X2: active->g = 255; active->b = 255; buttons |= SDL_BUTTON_X2MASK; break;
|
||||
}
|
||||
break;
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
if (!active)
|
||||
break;
|
||||
|
||||
switch (event.button.button) {
|
||||
case SDL_BUTTON_LEFT: buttons &= ~SDL_BUTTON_LMASK; break;
|
||||
case SDL_BUTTON_MIDDLE: buttons &= ~SDL_BUTTON_MMASK; break;
|
||||
case SDL_BUTTON_RIGHT: buttons &= ~SDL_BUTTON_RMASK; break;
|
||||
case SDL_BUTTON_X1: buttons &= ~SDL_BUTTON_X1MASK; break;
|
||||
case SDL_BUTTON_X2: buttons &= ~SDL_BUTTON_X2MASK; break;
|
||||
}
|
||||
|
||||
if (buttons == 0) {
|
||||
AppendLine(active);
|
||||
active = NULL;
|
||||
}
|
||||
break;
|
||||
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
/* Mouse wheel */
|
||||
SDL_SetRenderDrawColor(renderer, 0, 255, 128, 255);
|
||||
if (wheel_x_active) {
|
||||
SDL_RenderDrawLine(renderer, wheel_x, 0, wheel_x, SCREEN_HEIGHT);
|
||||
}
|
||||
if (wheel_y_active) {
|
||||
SDL_RenderDrawLine(renderer, 0, wheel_y, SCREEN_WIDTH, wheel_y);
|
||||
}
|
||||
|
||||
/* Lines from mouse clicks */
|
||||
DrawLines(renderer);
|
||||
if (active)
|
||||
DrawLine(renderer, active);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (done) {
|
||||
emscripten_cancel_main_loop();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
SDL_Renderer *renderer;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
/* Initialize SDL (Note: video is required to start event loop) */
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* Create a window to display joystick axis position */
|
||||
window = SDL_CreateWindow("Mouse Test", SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, SCREEN_WIDTH,
|
||||
SCREEN_HEIGHT, 0);
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
renderer = SDL_CreateRenderer(window, -1, 0);
|
||||
if (renderer == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
SDL_DestroyWindow(window);
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
/* Main render loop */
|
||||
#ifdef __EMSCRIPTEN__
|
||||
emscripten_set_main_loop_arg(loop, renderer, 0, 1);
|
||||
#else
|
||||
while (!done) {
|
||||
loop(renderer);
|
||||
}
|
||||
#endif
|
||||
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -33,20 +33,20 @@ callback_data cbd[64];
|
||||
void SDLCALL
|
||||
play_through_once(void *arg, Uint8 * stream, int len)
|
||||
{
|
||||
callback_data *cbd = (callback_data *) arg;
|
||||
Uint8 *waveptr = sound + cbd->soundpos;
|
||||
int waveleft = soundlen - cbd->soundpos;
|
||||
callback_data *cbdata = (callback_data *) arg;
|
||||
Uint8 *waveptr = sound + cbdata->soundpos;
|
||||
int waveleft = soundlen - cbdata->soundpos;
|
||||
int cpy = len;
|
||||
if (cpy > waveleft)
|
||||
cpy = waveleft;
|
||||
|
||||
SDL_memcpy(stream, waveptr, cpy);
|
||||
len -= cpy;
|
||||
cbd->soundpos += cpy;
|
||||
cbdata->soundpos += cpy;
|
||||
if (len > 0) {
|
||||
stream += cpy;
|
||||
SDL_memset(stream, spec.silence, len);
|
||||
SDL_AtomicSet(&cbd->done, 1);
|
||||
SDL_AtomicSet(&cbdata->done, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,13 +180,11 @@ main(int argc, char **argv)
|
||||
if (devcount < 1) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Don't see any specific audio devices!\n");
|
||||
} else {
|
||||
if (argv[1] == NULL) {
|
||||
argv[1] = "sample.wav";
|
||||
}
|
||||
const char *file = (argc < 2) ? "sample.wav" : argv[1];
|
||||
|
||||
/* Load the wave file into memory */
|
||||
if (SDL_LoadWAV(argv[1], &spec, &sound, &soundlen) == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", argv[1],
|
||||
if (SDL_LoadWAV(file, &spec, &sound, &soundlen) == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s\n", file,
|
||||
SDL_GetError());
|
||||
} else {
|
||||
test_multi_audio(devcount);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -53,7 +53,7 @@ quit(int rc)
|
||||
}
|
||||
|
||||
SDL_Texture *
|
||||
LoadSprite(SDL_Renderer *renderer, char *file)
|
||||
LoadSprite(SDL_Renderer *renderer, const char *file)
|
||||
{
|
||||
SDL_Surface *temp;
|
||||
SDL_Texture *sprite;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -14,46 +14,44 @@
|
||||
|
||||
#ifdef TEST_NATIVE_OS2
|
||||
|
||||
#define WIN_CLIENT_CLASS "SDL Test"
|
||||
#define WIN_CLIENT_CLASS "SDL Test"
|
||||
|
||||
static void *CreateWindowNative(int w, int h);
|
||||
static void DestroyWindowNative(void *window);
|
||||
|
||||
NativeWindowFactory OS2WindowFactory = {
|
||||
"DIVE",
|
||||
CreateWindowNative,
|
||||
DestroyWindowNative
|
||||
"DIVE",
|
||||
CreateWindowNative,
|
||||
DestroyWindowNative
|
||||
};
|
||||
|
||||
static void *CreateWindowNative(int w, int h)
|
||||
{
|
||||
HWND hwnd;
|
||||
HWND hwndFrame;
|
||||
ULONG ulFrameFlags = FCF_TASKLIST | FCF_DLGBORDER | FCF_TITLEBAR |
|
||||
FCF_SYSMENU | FCF_SHELLPOSITION |
|
||||
FCF_SIZEBORDER | FCF_MINBUTTON | FCF_MAXBUTTON;
|
||||
HWND hwnd, hwndFrame;
|
||||
ULONG ulFrameFlags = FCF_TASKLIST | FCF_DLGBORDER | FCF_TITLEBAR |
|
||||
FCF_SYSMENU | FCF_SHELLPOSITION |
|
||||
FCF_SIZEBORDER | FCF_MINBUTTON | FCF_MAXBUTTON;
|
||||
|
||||
WinRegisterClass( 0, WIN_CLIENT_CLASS, WinDefWindowProc,
|
||||
CS_SIZEREDRAW | CS_MOVENOTIFY,
|
||||
sizeof(ULONG) ); // We should have minimum 4 bytes.
|
||||
WinRegisterClass(0, WIN_CLIENT_CLASS, WinDefWindowProc,
|
||||
CS_SIZEREDRAW | CS_MOVENOTIFY,
|
||||
sizeof(ULONG)); /* We should have minimum 4 bytes. */
|
||||
|
||||
hwndFrame = WinCreateStdWindow( HWND_DESKTOP, 0, &ulFrameFlags,
|
||||
WIN_CLIENT_CLASS, "SDL Test", 0, 0, 1, &hwnd );
|
||||
if ( hwndFrame == NULLHANDLE )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
hwndFrame = WinCreateStdWindow(HWND_DESKTOP, 0, &ulFrameFlags,
|
||||
WIN_CLIENT_CLASS, "SDL Test", 0, 0, 1, &hwnd);
|
||||
if (hwndFrame == NULLHANDLE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
WinSetWindowPos( hwndFrame, HWND_TOP, 0, 0, w, h,
|
||||
SWP_ZORDER | SWP_ACTIVATE | SWP_SIZE | SWP_SHOW );
|
||||
WinSetWindowPos(hwndFrame, HWND_TOP, 0, 0, w, h,
|
||||
SWP_ZORDER | SWP_ACTIVATE | SWP_SIZE | SWP_SHOW);
|
||||
|
||||
return (void *)hwndFrame; // We may returns client or frame window handle
|
||||
// for SDL_CreateWindowFrom().
|
||||
return (void *)hwndFrame; /* We may return client or frame window
|
||||
handle for SDL_CreateWindowFrom(). */
|
||||
}
|
||||
|
||||
static void DestroyWindowNative(void *window)
|
||||
{
|
||||
WinDestroyWindow( (HWND)window );
|
||||
WinDestroyWindow((HWND) window);
|
||||
}
|
||||
|
||||
#endif /* TEST_NATIVE_OS2 */
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -144,7 +144,6 @@ SDL_Texture *MooseTexture;
|
||||
SDL_Rect displayrect;
|
||||
int window_w;
|
||||
int window_h;
|
||||
SDL_Window *window;
|
||||
SDL_Renderer *renderer;
|
||||
int paused = 0;
|
||||
int i;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -25,31 +25,31 @@ badsize(size_t sizeoftype, size_t hardcodetype)
|
||||
return sizeoftype != hardcodetype;
|
||||
}
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT8, SDL_MAX_SINT8 == 127);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT8, SDL_MIN_SINT8 == -128);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT8, SDL_MAX_UINT8 == 255);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT8, SDL_MIN_UINT8 == 0);
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT16, SDL_MAX_SINT16 == 32767);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT16, SDL_MIN_SINT16 == -32768);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT16, SDL_MAX_UINT16 == 65535);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT16, SDL_MIN_UINT16 == 0);
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT32, SDL_MAX_SINT32 == 2147483647);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT32, SDL_MIN_SINT32 == ~0x7fffffff); /* Instead of -2147483648, which is treated as unsigned by some compilers */
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT32, SDL_MAX_UINT32 == 4294967295u);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT32, SDL_MIN_UINT32 == 0);
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT64, SDL_MAX_SINT64 == 9223372036854775807ll);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT64, SDL_MIN_SINT64 == ~0x7fffffffffffffffll); /* Instead of -9223372036854775808, which is treated as unsigned by compilers */
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT64, SDL_MAX_UINT64 == 18446744073709551615ull);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT64, SDL_MIN_UINT64 == 0);
|
||||
|
||||
int
|
||||
TestTypes(SDL_bool verbose)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT8, SDL_MAX_SINT8 == 127);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT8, SDL_MIN_SINT8 == -128);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT8, SDL_MAX_UINT8 == 255);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT8, SDL_MIN_UINT8 == 0);
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT16, SDL_MAX_SINT16 == 32767);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT16, SDL_MIN_SINT16 == -32768);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT16, SDL_MAX_UINT16 == 65535);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT16, SDL_MIN_UINT16 == 0);
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT32, SDL_MAX_SINT32 == 2147483647);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT32, SDL_MIN_SINT32 == ~0x7fffffff); /* Instead of -2147483648, which is treated as unsigned by some compilers */
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT32, SDL_MAX_UINT32 == 4294967295u);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT32, SDL_MIN_UINT32 == 0);
|
||||
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_SINT64, SDL_MAX_SINT64 == 9223372036854775807ll);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_SINT64, SDL_MIN_SINT64 == ~0x7fffffffffffffffll); /* Instead of -9223372036854775808, which is treated as unsigned by compilers */
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MAX_UINT64, SDL_MAX_UINT64 == 18446744073709551615ull);
|
||||
SDL_COMPILE_TIME_ASSERT(SDL_MIN_UINT64, SDL_MIN_UINT64 == 0);
|
||||
|
||||
if (badsize(sizeof(Uint8), 1)) {
|
||||
if (verbose)
|
||||
SDL_Log("sizeof(Uint8) != 1, instead = %u\n",
|
||||
@@ -381,6 +381,7 @@ TestCPUInfo(SDL_bool verbose)
|
||||
SDL_Log("AVX %s\n", SDL_HasAVX()? "detected" : "not detected");
|
||||
SDL_Log("AVX2 %s\n", SDL_HasAVX2()? "detected" : "not detected");
|
||||
SDL_Log("AVX-512F %s\n", SDL_HasAVX512F()? "detected" : "not detected");
|
||||
SDL_Log("ARM SIMD %s\n", SDL_HasARMSIMD()? "detected" : "not detected");
|
||||
SDL_Log("NEON %s\n", SDL_HasNEON()? "detected" : "not detected");
|
||||
SDL_Log("System RAM %d MB\n", SDL_GetSystemRAM());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -19,7 +19,7 @@ report_power(void)
|
||||
{
|
||||
int seconds, percent;
|
||||
const SDL_PowerState state = SDL_GetPowerInfo(&seconds, &percent);
|
||||
char *statestr = NULL;
|
||||
const char *statestr = NULL;
|
||||
|
||||
SDL_Log("SDL-reported power info...\n");
|
||||
switch (state) {
|
||||
@@ -55,7 +55,7 @@ report_power(void)
|
||||
SDL_Log("Time left: unknown\n");
|
||||
} else {
|
||||
SDL_Log("Time left: %d minutes, %d seconds\n", (int) (seconds / 60),
|
||||
(int) (seconds % 60));
|
||||
(int) (seconds % 60));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -54,9 +54,9 @@ main(int argc, char *argv[])
|
||||
int success;
|
||||
Uint64 seed = 0;
|
||||
if (argv[1][0] == '0' && argv[1][1] == 'x')
|
||||
success = SDL_sscanf(argv[1] + 2, "%llx", &seed);
|
||||
success = SDL_sscanf(argv[1] + 2, "%"SDL_PRIx64, &seed);
|
||||
else
|
||||
success = SDL_sscanf(argv[1], "%llu", &seed);
|
||||
success = SDL_sscanf(argv[1], "%"SDL_PRIu64, &seed);
|
||||
if (!success) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid seed. Use a decimal or hexadecimal number.\n");
|
||||
return 1;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -28,10 +28,10 @@ SDL_Rect rect;
|
||||
SDL_Event event;
|
||||
|
||||
static void
|
||||
DrawRects(SDL_Renderer * renderer, SDL_Rect * rect)
|
||||
DrawRects(SDL_Renderer * renderer)
|
||||
{
|
||||
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
|
||||
SDL_RenderFillRect(renderer, rect);
|
||||
SDL_RenderFillRect(renderer, &rect);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -63,7 +63,7 @@ loop(){
|
||||
if (rect.x > viewport.x + viewport.w) rect.x -= viewport.w;
|
||||
if (rect.y > viewport.y + viewport.h) rect.y -= viewport.h;
|
||||
|
||||
DrawRects(renderer, &rect);
|
||||
DrawRects(renderer);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -46,7 +46,7 @@ quit(int rc)
|
||||
}
|
||||
|
||||
SDL_Texture *
|
||||
LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
|
||||
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
||||
{
|
||||
SDL_Surface *temp;
|
||||
SDL_Texture *texture;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -25,10 +25,6 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
/*
|
||||
* includes
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h> /* strstr */
|
||||
#include <ctype.h> /* isdigit */
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
#ifndef SDL_HAPTIC_DISABLED
|
||||
@@ -56,7 +52,7 @@ main(int argc, char **argv)
|
||||
if (argc > 1) {
|
||||
size_t l;
|
||||
name = argv[1];
|
||||
if ((strcmp(name, "--help") == 0) || (strcmp(name, "-h") == 0)) {
|
||||
if ((SDL_strcmp(name, "--help") == 0) || (SDL_strcmp(name, "-h") == 0)) {
|
||||
SDL_Log("USAGE: %s [device]\n"
|
||||
"If device is a two-digit number it'll use it as an index, otherwise\n"
|
||||
"it'll use it as if it were part of the device's name.\n",
|
||||
@@ -83,7 +79,7 @@ main(int argc, char **argv)
|
||||
/* Try to find matching device */
|
||||
else {
|
||||
for (i = 0; i < SDL_NumHaptics(); i++) {
|
||||
if (strstr(SDL_HapticName(i), name) != NULL)
|
||||
if (SDL_strstr(SDL_HapticName(i), name) != NULL)
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -47,7 +47,7 @@ quit(int rc)
|
||||
}
|
||||
|
||||
SDL_Texture *
|
||||
LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
|
||||
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
||||
{
|
||||
SDL_Surface *temp;
|
||||
SDL_Texture *texture;
|
||||
|
||||
248
test/testsem.c
248
test/testsem.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -19,27 +19,21 @@
|
||||
#include "SDL.h"
|
||||
|
||||
#define NUM_THREADS 10
|
||||
/* This value should be smaller than the maximum count of the */
|
||||
/* semaphore implementation: */
|
||||
#define NUM_OVERHEAD_OPS 10000
|
||||
#define NUM_OVERHEAD_OPS_MULT 10
|
||||
|
||||
static SDL_sem *sem;
|
||||
int alive = 1;
|
||||
int alive;
|
||||
|
||||
int SDLCALL
|
||||
ThreadFunc(void *data)
|
||||
{
|
||||
int threadnum = (int) (uintptr_t) data;
|
||||
while (alive) {
|
||||
SDL_SemWait(sem);
|
||||
SDL_Log("Thread number %d has got the semaphore (value = %d)!\n",
|
||||
threadnum, SDL_SemValue(sem));
|
||||
SDL_Delay(200);
|
||||
SDL_SemPost(sem);
|
||||
SDL_Log("Thread number %d has released the semaphore (value = %d)!\n",
|
||||
threadnum, SDL_SemValue(sem));
|
||||
SDL_Delay(1); /* For the scheduler */
|
||||
}
|
||||
SDL_Log("Thread number %d exiting.\n", threadnum);
|
||||
return 0;
|
||||
}
|
||||
typedef struct Thread_State {
|
||||
SDL_Thread * thread;
|
||||
int number;
|
||||
SDL_bool flag;
|
||||
int loop_count;
|
||||
int content_count;
|
||||
} Thread_State;
|
||||
|
||||
static void
|
||||
killed(int sig)
|
||||
@@ -47,6 +41,60 @@ killed(int sig)
|
||||
alive = 0;
|
||||
}
|
||||
|
||||
static int SDLCALL
|
||||
ThreadFuncRealWorld(void *data)
|
||||
{
|
||||
Thread_State *state = (Thread_State *) data;
|
||||
while (alive) {
|
||||
SDL_SemWait(sem);
|
||||
SDL_Log("Thread number %d has got the semaphore (value = %d)!\n",
|
||||
state->number, SDL_SemValue(sem));
|
||||
SDL_Delay(200);
|
||||
SDL_SemPost(sem);
|
||||
SDL_Log("Thread number %d has released the semaphore (value = %d)!\n",
|
||||
state->number, SDL_SemValue(sem));
|
||||
++state->loop_count;
|
||||
SDL_Delay(1); /* For the scheduler */
|
||||
}
|
||||
SDL_Log("Thread number %d exiting.\n", state->number);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
TestRealWorld(int init_sem) {
|
||||
Thread_State thread_states[NUM_THREADS] = { {0} };
|
||||
int i;
|
||||
int loop_count;
|
||||
|
||||
sem = SDL_CreateSemaphore(init_sem);
|
||||
|
||||
SDL_Log("Running %d threads, semaphore value = %d\n", NUM_THREADS,
|
||||
init_sem);
|
||||
alive = 1;
|
||||
/* Create all the threads */
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Thread%u", (unsigned int) i);
|
||||
thread_states[i].number = i;
|
||||
thread_states[i].thread = SDL_CreateThread(ThreadFuncRealWorld, name, (void *) &thread_states[i]);
|
||||
}
|
||||
|
||||
/* Wait 10 seconds */
|
||||
SDL_Delay(10 * 1000);
|
||||
|
||||
/* Wait for all threads to finish */
|
||||
SDL_Log("Waiting for threads to finish\n");
|
||||
alive = 0;
|
||||
loop_count = 0;
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
SDL_WaitThread(thread_states[i].thread, NULL);
|
||||
loop_count += thread_states[i].loop_count;
|
||||
}
|
||||
SDL_Log("Finished waiting for threads, ran %d loops in total\n\n", loop_count);
|
||||
|
||||
SDL_DestroySemaphore(sem);
|
||||
}
|
||||
|
||||
static void
|
||||
TestWaitTimeout(void)
|
||||
{
|
||||
@@ -65,21 +113,137 @@ TestWaitTimeout(void)
|
||||
duration = end_ticks - start_ticks;
|
||||
|
||||
/* Accept a little offset in the effective wait */
|
||||
if (duration > 1900 && duration < 2050)
|
||||
SDL_Log("Wait done.\n");
|
||||
else
|
||||
SDL_Log("Wait took %d milliseconds\n", duration);
|
||||
SDL_assert(duration > 1900 && duration < 2050);
|
||||
SDL_Log("Wait took %d milliseconds\n\n", duration);
|
||||
|
||||
/* Check to make sure the return value indicates timed out */
|
||||
if (retval != SDL_MUTEX_TIMEDOUT)
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_SemWaitTimeout returned: %d; expected: %d\n", retval, SDL_MUTEX_TIMEDOUT);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_SemWaitTimeout returned: %d; expected: %d\n\n", retval, SDL_MUTEX_TIMEDOUT);
|
||||
|
||||
SDL_DestroySemaphore(sem);
|
||||
}
|
||||
|
||||
static void
|
||||
TestOverheadUncontended(void)
|
||||
{
|
||||
Uint32 start_ticks;
|
||||
Uint32 end_ticks;
|
||||
Uint32 duration;
|
||||
int i, j;
|
||||
|
||||
sem = SDL_CreateSemaphore(0);
|
||||
SDL_Log("Doing %d uncontended Post/Wait operations on semaphore\n", NUM_OVERHEAD_OPS * NUM_OVERHEAD_OPS_MULT);
|
||||
|
||||
start_ticks = SDL_GetTicks();
|
||||
for (i = 0; i < NUM_OVERHEAD_OPS_MULT; i++){
|
||||
for (j = 0; j < NUM_OVERHEAD_OPS; j++) {
|
||||
SDL_SemPost(sem);
|
||||
}
|
||||
for (j = 0; j < NUM_OVERHEAD_OPS; j++) {
|
||||
SDL_SemWait(sem);
|
||||
}
|
||||
}
|
||||
end_ticks = SDL_GetTicks();
|
||||
|
||||
duration = end_ticks - start_ticks;
|
||||
SDL_Log("Took %d milliseconds\n\n", duration);
|
||||
|
||||
SDL_DestroySemaphore(sem);
|
||||
}
|
||||
|
||||
static int SDLCALL
|
||||
ThreadFuncOverheadContended(void *data)
|
||||
{
|
||||
Thread_State *state = (Thread_State *) data;
|
||||
|
||||
if (state->flag) {
|
||||
while(alive) {
|
||||
if (SDL_SemTryWait(sem) == SDL_MUTEX_TIMEDOUT) {
|
||||
++state->content_count;
|
||||
}
|
||||
++state->loop_count;
|
||||
}
|
||||
} else {
|
||||
while(alive) {
|
||||
/* Timeout needed to allow check on alive flag */
|
||||
if (SDL_SemWaitTimeout(sem, 50) == SDL_MUTEX_TIMEDOUT) {
|
||||
++state->content_count;
|
||||
}
|
||||
++state->loop_count;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
TestOverheadContended(SDL_bool try_wait)
|
||||
{
|
||||
Uint32 start_ticks;
|
||||
Uint32 end_ticks;
|
||||
Uint32 duration;
|
||||
Thread_State thread_states[NUM_THREADS] = { {0} };
|
||||
char textBuffer[1024];
|
||||
int loop_count;
|
||||
int content_count;
|
||||
int i, j;
|
||||
size_t len;
|
||||
|
||||
sem = SDL_CreateSemaphore(0);
|
||||
SDL_Log("Doing %d contended %s operations on semaphore using %d threads\n",
|
||||
NUM_OVERHEAD_OPS * NUM_OVERHEAD_OPS_MULT, try_wait ? "Post/TryWait" : "Post/WaitTimeout", NUM_THREADS);
|
||||
alive = 1;
|
||||
/* Create multiple threads to starve the semaphore and cause contention */
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Thread%u", (unsigned int) i);
|
||||
thread_states[i].flag = try_wait;
|
||||
thread_states[i].thread = SDL_CreateThread(ThreadFuncOverheadContended, name, (void *) &thread_states[i]);
|
||||
}
|
||||
|
||||
start_ticks = SDL_GetTicks();
|
||||
for (i = 0; i < NUM_OVERHEAD_OPS_MULT; i++) {
|
||||
for (j = 0; j < NUM_OVERHEAD_OPS; j++) {
|
||||
SDL_SemPost(sem);
|
||||
}
|
||||
/* Make sure threads consumed everything */
|
||||
while (SDL_SemValue(sem)) { }
|
||||
}
|
||||
end_ticks = SDL_GetTicks();
|
||||
|
||||
alive = 0;
|
||||
loop_count = 0;
|
||||
content_count = 0;
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
SDL_WaitThread(thread_states[i].thread, NULL);
|
||||
loop_count += thread_states[i].loop_count;
|
||||
content_count += thread_states[i].content_count;
|
||||
}
|
||||
SDL_assert_release((loop_count - content_count) == NUM_OVERHEAD_OPS * NUM_OVERHEAD_OPS_MULT);
|
||||
|
||||
duration = end_ticks - start_ticks;
|
||||
SDL_Log("Took %d milliseconds, threads %s %d out of %d times in total (%.2f%%)\n",
|
||||
duration, try_wait ? "where contended" : "timed out", content_count,
|
||||
loop_count, ((float)content_count * 100) / loop_count);
|
||||
/* Print how many semaphores where consumed per thread */
|
||||
SDL_snprintf(textBuffer, sizeof(textBuffer), "{ ");
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
if (i > 0) {
|
||||
len = SDL_strlen(textBuffer);
|
||||
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, ", ");
|
||||
}
|
||||
len = SDL_strlen(textBuffer);
|
||||
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, "%d", thread_states[i].loop_count - thread_states[i].content_count);
|
||||
}
|
||||
len = SDL_strlen(textBuffer);
|
||||
SDL_snprintf(textBuffer + len, sizeof(textBuffer) - len, " }\n");
|
||||
SDL_Log("%s\n", textBuffer);
|
||||
|
||||
SDL_DestroySemaphore(sem);
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
SDL_Thread *threads[NUM_THREADS];
|
||||
uintptr_t i;
|
||||
int init_sem;
|
||||
|
||||
/* Enable standard application logging */
|
||||
@@ -98,33 +262,19 @@ main(int argc, char **argv)
|
||||
signal(SIGTERM, killed);
|
||||
signal(SIGINT, killed);
|
||||
|
||||
init_sem = atoi(argv[1]);
|
||||
sem = SDL_CreateSemaphore(init_sem);
|
||||
|
||||
SDL_Log("Running %d threads, semaphore value = %d\n", NUM_THREADS,
|
||||
init_sem);
|
||||
/* Create all the threads */
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
char name[64];
|
||||
SDL_snprintf(name, sizeof (name), "Thread%u", (unsigned int) i);
|
||||
threads[i] = SDL_CreateThread(ThreadFunc, name, (void *) i);
|
||||
init_sem = SDL_atoi(argv[1]);
|
||||
if (init_sem > 0) {
|
||||
TestRealWorld(init_sem);
|
||||
}
|
||||
|
||||
/* Wait 10 seconds */
|
||||
SDL_Delay(10 * 1000);
|
||||
|
||||
/* Wait for all threads to finish */
|
||||
SDL_Log("Waiting for threads to finish\n");
|
||||
alive = 0;
|
||||
for (i = 0; i < NUM_THREADS; ++i) {
|
||||
SDL_WaitThread(threads[i], NULL);
|
||||
}
|
||||
SDL_Log("Finished waiting for threads\n");
|
||||
|
||||
SDL_DestroySemaphore(sem);
|
||||
|
||||
TestWaitTimeout();
|
||||
|
||||
TestOverheadUncontended();
|
||||
|
||||
TestOverheadContended(SDL_FALSE);
|
||||
|
||||
TestOverheadContended(SDL_TRUE);
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -95,7 +95,11 @@ main(int argc, char **argv)
|
||||
|
||||
SDL_CreateWindow("Sensor Test", 0, 0, 0, 0, SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
while (!done) {
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
/* Update to get the current event state */
|
||||
SDL_PumpEvents();
|
||||
|
||||
/* Process all currently pending events */
|
||||
while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_FIRSTEVENT, SDL_LASTEVENT) == 1) {
|
||||
switch (event.type) {
|
||||
case SDL_SENSORUPDATE:
|
||||
HandleSensorEvent(&event.sensor);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -126,21 +126,52 @@ static PFNGLUSEPROGRAMOBJECTARBPROC glUseProgramObjectARB;
|
||||
|
||||
static SDL_bool CompileShader(GLhandleARB shader, const char *source)
|
||||
{
|
||||
GLint status;
|
||||
GLint status = 0;
|
||||
|
||||
glShaderSourceARB(shader, 1, &source, NULL);
|
||||
glCompileShaderARB(shader);
|
||||
glGetObjectParameterivARB(shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
|
||||
if (status == 0) {
|
||||
GLint length;
|
||||
GLint length = 0;
|
||||
char *info;
|
||||
|
||||
glGetObjectParameterivARB(shader, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
|
||||
info = SDL_stack_alloc(char, length+1);
|
||||
glGetInfoLogARB(shader, length, NULL, info);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile shader:\n%s\n%s", source, info);
|
||||
SDL_stack_free(info);
|
||||
info = (char *) SDL_malloc(length + 1);
|
||||
if (!info) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
|
||||
} else {
|
||||
glGetInfoLogARB(shader, length, NULL, info);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to compile shader:\n%s\n%s", source, info);
|
||||
SDL_free(info);
|
||||
}
|
||||
return SDL_FALSE;
|
||||
} else {
|
||||
return SDL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool LinkProgram(ShaderData *data)
|
||||
{
|
||||
GLint status = 0;
|
||||
|
||||
glAttachObjectARB(data->program, data->vert_shader);
|
||||
glAttachObjectARB(data->program, data->frag_shader);
|
||||
glLinkProgramARB(data->program);
|
||||
|
||||
glGetObjectParameterivARB(data->program, GL_OBJECT_LINK_STATUS_ARB, &status);
|
||||
if (status == 0) {
|
||||
GLint length = 0;
|
||||
char *info;
|
||||
|
||||
glGetObjectParameterivARB(data->program, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
|
||||
info = (char *) SDL_malloc(length + 1);
|
||||
if (!info) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Out of memory!");
|
||||
} else {
|
||||
glGetInfoLogARB(data->program, length, NULL, info);
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to link program:\n%s", info);
|
||||
SDL_free(info);
|
||||
}
|
||||
return SDL_FALSE;
|
||||
} else {
|
||||
return SDL_TRUE;
|
||||
@@ -171,9 +202,9 @@ static SDL_bool CompileShaderProgram(ShaderData *data)
|
||||
}
|
||||
|
||||
/* ... and in the darkness bind them */
|
||||
glAttachObjectARB(data->program, data->vert_shader);
|
||||
glAttachObjectARB(data->program, data->frag_shader);
|
||||
glLinkProgramARB(data->program);
|
||||
if (!LinkProgram(data)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
/* Set up some uniform variables */
|
||||
glUseProgramObjectARB(data->program);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -39,6 +39,7 @@ static int sprite_w, sprite_h;
|
||||
static SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND;
|
||||
static Uint32 next_fps_check, frames;
|
||||
static const Uint32 fps_check_delay = 5000;
|
||||
static int use_rendergeometry = 0;
|
||||
|
||||
/* Number of iterations to move sprites - used for visual tests. */
|
||||
/* -1: infinite random moves (default); >=0: enables N deterministic moves */
|
||||
@@ -175,7 +176,38 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
||||
temp.y = 1;
|
||||
temp.w = sprite_w;
|
||||
temp.h = sprite_h;
|
||||
SDL_RenderFillRect(renderer, &temp);
|
||||
if (use_rendergeometry == 0) {
|
||||
SDL_RenderFillRect(renderer, &temp);
|
||||
} else {
|
||||
/* Draw two triangles, filled, uniform */
|
||||
SDL_Color color;
|
||||
SDL_Vertex verts[3];
|
||||
SDL_zeroa(verts);
|
||||
color.r = 0xFF;
|
||||
color.g = 0xFF;
|
||||
color.b = 0xFF;
|
||||
color.a = 0xFF;
|
||||
|
||||
verts[0].position.x = (float)temp.x;
|
||||
verts[0].position.y = (float)temp.y;
|
||||
verts[0].color = color;
|
||||
|
||||
verts[1].position.x = (float)temp.x + temp.w;
|
||||
verts[1].position.y = (float)temp.y;
|
||||
verts[1].color = color;
|
||||
|
||||
verts[2].position.x = (float)temp.x + temp.w;
|
||||
verts[2].position.y = (float)temp.y + temp.h;
|
||||
verts[2].color = color;
|
||||
|
||||
SDL_RenderGeometry(renderer, NULL, verts, 3, NULL, 0);
|
||||
|
||||
verts[1].position.x = (float)temp.x;
|
||||
verts[1].position.y = (float)temp.y + temp.h;
|
||||
verts[1].color = color;
|
||||
|
||||
SDL_RenderGeometry(renderer, NULL, verts, 3, NULL, 0);
|
||||
}
|
||||
SDL_RenderCopy(renderer, sprite, NULL, &temp);
|
||||
temp.x = viewport.w-sprite_w-1;
|
||||
temp.y = 1;
|
||||
@@ -220,7 +252,7 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Countdown sprite-move iterations and disable color changes at iteration end - used for visual tests. */
|
||||
if (iterations > 0) {
|
||||
iterations--;
|
||||
@@ -232,11 +264,160 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
||||
}
|
||||
|
||||
/* Draw sprites */
|
||||
for (i = 0; i < num_sprites; ++i) {
|
||||
position = &positions[i];
|
||||
if (use_rendergeometry == 0) {
|
||||
for (i = 0; i < num_sprites; ++i) {
|
||||
position = &positions[i];
|
||||
|
||||
/* Blit the sprite onto the screen */
|
||||
SDL_RenderCopy(renderer, sprite, NULL, position);
|
||||
/* Blit the sprite onto the screen */
|
||||
SDL_RenderCopy(renderer, sprite, NULL, position);
|
||||
}
|
||||
} else if (use_rendergeometry == 1) {
|
||||
/*
|
||||
* 0--1
|
||||
* | /|
|
||||
* |/ |
|
||||
* 3--2
|
||||
*
|
||||
* Draw sprite2 as triangles that can be recombined as rect by software renderer
|
||||
*/
|
||||
SDL_Vertex *verts = (SDL_Vertex *) SDL_malloc(num_sprites * sizeof (SDL_Vertex) * 6);
|
||||
SDL_Vertex *verts2 = verts;
|
||||
if (verts) {
|
||||
SDL_Color color;
|
||||
SDL_GetTextureColorMod(sprite, &color.r, &color.g, &color.b);
|
||||
SDL_GetTextureAlphaMod(sprite, &color.a);
|
||||
for (i = 0; i < num_sprites; ++i) {
|
||||
position = &positions[i];
|
||||
/* 0 */
|
||||
verts->position.x = (float)position->x;
|
||||
verts->position.y = (float)position->y;
|
||||
verts->color = color;
|
||||
verts->tex_coord.x = 0.0f;
|
||||
verts->tex_coord.y = 0.0f;
|
||||
verts++;
|
||||
/* 1 */
|
||||
verts->position.x = (float)position->x + position->w;
|
||||
verts->position.y = (float)position->y;
|
||||
verts->color = color;
|
||||
verts->tex_coord.x = 1.0f;
|
||||
verts->tex_coord.y = 0.0f;
|
||||
verts++;
|
||||
/* 2 */
|
||||
verts->position.x = (float)position->x + position->w;
|
||||
verts->position.y = (float)position->y + position->h;
|
||||
verts->color = color;
|
||||
verts->tex_coord.x = 1.0f;
|
||||
verts->tex_coord.y = 1.0f;
|
||||
verts++;
|
||||
/* 0 */
|
||||
verts->position.x = (float)position->x;
|
||||
verts->position.y = (float)position->y;
|
||||
verts->color = color;
|
||||
verts->tex_coord.x = 0.0f;
|
||||
verts->tex_coord.y = 0.0f;
|
||||
verts++;
|
||||
/* 2 */
|
||||
verts->position.x = (float)position->x + position->w;
|
||||
verts->position.y = (float)position->y + position->h;
|
||||
verts->color = color;
|
||||
verts->tex_coord.x = 1.0f;
|
||||
verts->tex_coord.y = 1.0f;
|
||||
verts++;
|
||||
/* 3 */
|
||||
verts->position.x = (float)position->x;
|
||||
verts->position.y = (float)position->y + position->h;
|
||||
verts->color = color;
|
||||
verts->tex_coord.x = 0.0f;
|
||||
verts->tex_coord.y = 1.0f;
|
||||
verts++;
|
||||
}
|
||||
|
||||
/* Blit sprites as triangles onto the screen */
|
||||
SDL_RenderGeometry(renderer, sprite, verts2, num_sprites * 6, NULL, 0);
|
||||
SDL_free(verts2);
|
||||
}
|
||||
} else if (use_rendergeometry == 2) {
|
||||
/* 0-----1
|
||||
* |\ A /|
|
||||
* | \ / |
|
||||
* |D 2 B|
|
||||
* | / \ |
|
||||
* |/ C \|
|
||||
* 3-----4
|
||||
*
|
||||
* Draw sprite2 as triangles that can *not* be recombined as rect by software renderer
|
||||
* Use an 'indices' array
|
||||
*/
|
||||
SDL_Vertex *verts = (SDL_Vertex *) SDL_malloc(num_sprites * sizeof (SDL_Vertex) * 5);
|
||||
SDL_Vertex *verts2 = verts;
|
||||
int *indices = (int *) SDL_malloc(num_sprites * sizeof (int) * 4 * 3);
|
||||
int *indices2 = indices;
|
||||
if (verts && indices) {
|
||||
int pos = 0;
|
||||
SDL_Color color;
|
||||
SDL_GetTextureColorMod(sprite, &color.r, &color.g, &color.b);
|
||||
SDL_GetTextureAlphaMod(sprite, &color.a);
|
||||
for (i = 0; i < num_sprites; ++i) {
|
||||
position = &positions[i];
|
||||
/* 0 */
|
||||
verts->position.x = (float)position->x;
|
||||
verts->position.y = (float)position->y;
|
||||
verts->color = color;
|
||||
verts->tex_coord.x = 0.0f;
|
||||
verts->tex_coord.y = 0.0f;
|
||||
verts++;
|
||||
/* 1 */
|
||||
verts->position.x = (float)position->x + position->w;
|
||||
verts->position.y = (float)position->y;
|
||||
verts->color = color;
|
||||
verts->tex_coord.x = 1.0f;
|
||||
verts->tex_coord.y = 0.0f;
|
||||
verts++;
|
||||
/* 2 */
|
||||
verts->position.x = (float)position->x + position->w / 2.0f;
|
||||
verts->position.y = (float)position->y + position->h / 2.0f;
|
||||
verts->color = color;
|
||||
verts->tex_coord.x = 0.5f;
|
||||
verts->tex_coord.y = 0.5f;
|
||||
verts++;
|
||||
/* 3 */
|
||||
verts->position.x = (float)position->x;
|
||||
verts->position.y = (float)position->y + position->h;
|
||||
verts->color = color;
|
||||
verts->tex_coord.x = 0.0f;
|
||||
verts->tex_coord.y = 1.0f;
|
||||
verts++;
|
||||
/* 4 */
|
||||
verts->position.x = (float)position->x + position->w;
|
||||
verts->position.y = (float)position->y + position->h;
|
||||
verts->color = color;
|
||||
verts->tex_coord.x = 1.0f;
|
||||
verts->tex_coord.y = 1.0f;
|
||||
verts++;
|
||||
/* A */
|
||||
*indices++ = pos + 0;
|
||||
*indices++ = pos + 1;
|
||||
*indices++ = pos + 2;
|
||||
/* B */
|
||||
*indices++ = pos + 1;
|
||||
*indices++ = pos + 2;
|
||||
*indices++ = pos + 4;
|
||||
/* C */
|
||||
*indices++ = pos + 3;
|
||||
*indices++ = pos + 2;
|
||||
*indices++ = pos + 4;
|
||||
/* D */
|
||||
*indices++ = pos + 3;
|
||||
*indices++ = pos + 2;
|
||||
*indices++ = pos + 0;
|
||||
pos += 5;
|
||||
}
|
||||
}
|
||||
|
||||
/* Blit sprites as triangles onto the screen */
|
||||
SDL_RenderGeometry(renderer, sprite, verts2, num_sprites * 5, indices2, num_sprites * 4 * 3);
|
||||
SDL_free(verts2);
|
||||
SDL_free(indices2);
|
||||
}
|
||||
|
||||
/* Update the screen! */
|
||||
@@ -331,6 +512,20 @@ main(int argc, char *argv[])
|
||||
} else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
|
||||
cycle_alpha = SDL_TRUE;
|
||||
consumed = 1;
|
||||
} else if (SDL_strcasecmp(argv[i], "--use-rendergeometry") == 0) {
|
||||
if (argv[i + 1]) {
|
||||
if (SDL_strcasecmp(argv[i + 1], "mode1") == 0) {
|
||||
/* Draw sprite2 as triangles that can be recombined as rect by software renderer */
|
||||
use_rendergeometry = 1;
|
||||
} else if (SDL_strcasecmp(argv[i + 1], "mode2") == 0) {
|
||||
/* Draw sprite2 as triangles that can *not* be recombined as rect by software renderer
|
||||
* Use an 'indices' array */
|
||||
use_rendergeometry = 2;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
consumed = 2;
|
||||
} else if (SDL_isdigit(*argv[i])) {
|
||||
num_sprites = SDL_atoi(argv[i]);
|
||||
consumed = 1;
|
||||
@@ -340,7 +535,15 @@ main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
if (consumed < 0) {
|
||||
static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", "[--iterations N]", "[num_sprites]", "[icon.bmp]", NULL };
|
||||
static const char *options[] = {
|
||||
"[--blend none|blend|add|mod]",
|
||||
"[--cyclecolor]",
|
||||
"[--cyclealpha]",
|
||||
"[--iterations N]",
|
||||
"[--use-rendergeometry mode1|mode2]",
|
||||
"[num_sprites]",
|
||||
"[icon.bmp]",
|
||||
NULL };
|
||||
SDLTest_CommonLogUsage(state, argv[0], options);
|
||||
quit(1);
|
||||
}
|
||||
@@ -374,7 +577,7 @@ main(int argc, char *argv[])
|
||||
quit(2);
|
||||
}
|
||||
|
||||
/* Position sprites and set their velocities using the fuzzer */
|
||||
/* Position sprites and set their velocities using the fuzzer */
|
||||
if (iterations >= 0) {
|
||||
/* Deterministic seed - used for visual tests */
|
||||
seed = (Uint64)iterations;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -43,7 +43,7 @@ quit(int rc)
|
||||
}
|
||||
|
||||
int
|
||||
LoadSprite(char *file, SDL_Renderer *renderer)
|
||||
LoadSprite(const char *file)
|
||||
{
|
||||
SDL_Surface *temp;
|
||||
|
||||
@@ -92,7 +92,7 @@ LoadSprite(char *file, SDL_Renderer *renderer)
|
||||
}
|
||||
|
||||
void
|
||||
MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
|
||||
MoveSprites()
|
||||
{
|
||||
int i;
|
||||
int window_w = WINDOW_WIDTH;
|
||||
@@ -136,7 +136,7 @@ void loop()
|
||||
done = 1;
|
||||
}
|
||||
}
|
||||
MoveSprites(renderer, sprite);
|
||||
MoveSprites();
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (done) {
|
||||
emscripten_cancel_main_loop();
|
||||
@@ -158,7 +158,7 @@ main(int argc, char *argv[])
|
||||
quit(2);
|
||||
}
|
||||
|
||||
if (LoadSprite("icon.bmp", renderer) < 0) {
|
||||
if (LoadSprite("icon.bmp") < 0) {
|
||||
quit(2);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -67,7 +67,7 @@ void quit(int rc)
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
void UpdateTexture(SDL_Texture *texture, int frame)
|
||||
void UpdateTexture(SDL_Texture *texture)
|
||||
{
|
||||
SDL_Color *color;
|
||||
Uint8 *src;
|
||||
@@ -110,7 +110,7 @@ loop()
|
||||
}
|
||||
|
||||
frame = (frame + 1) % MOOSEFRAMES_COUNT;
|
||||
UpdateTexture(MooseTexture, frame);
|
||||
UpdateTexture(MooseTexture);
|
||||
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderCopy(renderer, MooseTexture, NULL, NULL);
|
||||
|
||||
200
test/testsurround.c
Normal file
200
test/testsurround.c
Normal file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
Copyright (C) 1997-2022 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.
|
||||
*/
|
||||
|
||||
/* Program to test surround sound audio channels */
|
||||
#include "SDL_config.h"
|
||||
|
||||
#include "SDL.h"
|
||||
|
||||
static int total_channels;
|
||||
static int active_channel;
|
||||
|
||||
#define SAMPLE_RATE_HZ 48000
|
||||
#define CHANNEL_TEST_TIME_SEC 5
|
||||
#define MAX_AMPLITUDE SDL_MAX_SINT16
|
||||
|
||||
#define SINE_FREQ_HZ 500
|
||||
#define LFE_SINE_FREQ_HZ 50
|
||||
|
||||
/* The channel layout is defined in SDL_audio.h */
|
||||
const char*
|
||||
get_channel_name(int channel_index, int channel_count)
|
||||
{
|
||||
switch (channel_index) {
|
||||
case 0:
|
||||
return "Front Left";
|
||||
case 1:
|
||||
return "Front Right";
|
||||
case 2:
|
||||
switch (channel_count) {
|
||||
case 3:
|
||||
return "Low Frequency Effects";
|
||||
case 4:
|
||||
return "Back Left";
|
||||
default:
|
||||
return "Front Center";
|
||||
}
|
||||
case 3:
|
||||
switch (channel_count) {
|
||||
case 4:
|
||||
return "Back Right";
|
||||
case 5:
|
||||
return "Back Left";
|
||||
default:
|
||||
return "Low Frequency Effects";
|
||||
}
|
||||
case 4:
|
||||
switch (channel_count) {
|
||||
case 5:
|
||||
return "Back Right";
|
||||
case 7:
|
||||
return "Back Center";
|
||||
case 6:
|
||||
case 8:
|
||||
return "Back Left";
|
||||
}
|
||||
case 5:
|
||||
switch (channel_count) {
|
||||
case 7:
|
||||
return "Back Left";
|
||||
case 6:
|
||||
case 8:
|
||||
return "Back Right";
|
||||
}
|
||||
case 6:
|
||||
switch (channel_count) {
|
||||
case 7:
|
||||
return "Back Right";
|
||||
case 8:
|
||||
return "Side Left";
|
||||
}
|
||||
case 7:
|
||||
return "Side Right";
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SDL_bool
|
||||
is_lfe_channel(int channel_index, int channel_count)
|
||||
{
|
||||
return (channel_count == 3 && channel_index == 2) || (channel_count >= 6 && channel_index == 3);
|
||||
}
|
||||
|
||||
void SDLCALL
|
||||
fill_buffer(void* unused, Uint8* stream, int len)
|
||||
{
|
||||
Sint16* buffer = (Sint16*)stream;
|
||||
int samples = len / sizeof(Sint16);
|
||||
static int total_samples = 0;
|
||||
int i;
|
||||
|
||||
SDL_memset(stream, 0, len);
|
||||
|
||||
/* This can happen for a short time when switching devices */
|
||||
if (active_channel == total_channels) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Play a sine wave on the active channel only */
|
||||
for (i = active_channel; i < samples; i += total_channels) {
|
||||
float time = (float)total_samples++ / SAMPLE_RATE_HZ;
|
||||
int sine_freq = is_lfe_channel(active_channel, total_channels) ? LFE_SINE_FREQ_HZ : SINE_FREQ_HZ;
|
||||
int amplitude;
|
||||
|
||||
/* Gradually ramp up and down to avoid audible pops when switching between channels */
|
||||
if (total_samples < SAMPLE_RATE_HZ) {
|
||||
amplitude = total_samples * MAX_AMPLITUDE / SAMPLE_RATE_HZ;
|
||||
} else if (total_samples > (CHANNEL_TEST_TIME_SEC - 1) * SAMPLE_RATE_HZ) {
|
||||
amplitude = (CHANNEL_TEST_TIME_SEC * SAMPLE_RATE_HZ - total_samples) * MAX_AMPLITUDE / SAMPLE_RATE_HZ;
|
||||
} else {
|
||||
amplitude = MAX_AMPLITUDE;
|
||||
}
|
||||
|
||||
buffer[i] = (Sint16)(SDL_sin(6.283185f * sine_freq * time) * amplitude);
|
||||
|
||||
/* Reset our state for next callback if this channel test is finished */
|
||||
if (total_samples == CHANNEL_TEST_TIME_SEC * SAMPLE_RATE_HZ) {
|
||||
total_samples = 0;
|
||||
active_channel++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Enable standard application logging */
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
|
||||
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError());
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Show the list of available drivers */
|
||||
SDL_Log("Available audio drivers:");
|
||||
for (i = 0; i < SDL_GetNumAudioDrivers(); ++i) {
|
||||
SDL_Log("%i: %s", i, SDL_GetAudioDriver(i));
|
||||
}
|
||||
|
||||
SDL_Log("Using audio driver: %s\n", SDL_GetCurrentAudioDriver());
|
||||
|
||||
for (i = 0; i < SDL_GetNumAudioDevices(0); i++) {
|
||||
const char *devname = SDL_GetAudioDeviceName(i, 0);
|
||||
int j;
|
||||
SDL_AudioSpec spec;
|
||||
SDL_AudioDeviceID dev;
|
||||
|
||||
if (SDL_GetAudioDeviceSpec(i, 0, &spec) != 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GetAudioSpec() failed: %s\n", SDL_GetError());
|
||||
continue;
|
||||
}
|
||||
|
||||
spec.freq = SAMPLE_RATE_HZ;
|
||||
spec.format = AUDIO_S16SYS;
|
||||
spec.samples = 4096;
|
||||
spec.callback = fill_buffer;
|
||||
|
||||
dev = SDL_OpenAudioDevice(devname, 0, &spec, NULL, 0);
|
||||
if (dev == 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_OpenAudioDevice() failed: %s\n", SDL_GetError());
|
||||
continue;
|
||||
}
|
||||
|
||||
SDL_Log("Testing audio device: %s (%d channels)\n", devname, spec.channels);
|
||||
|
||||
/* These are used by the fill_buffer callback */
|
||||
total_channels = spec.channels;
|
||||
active_channel = 0;
|
||||
|
||||
SDL_PauseAudioDevice(dev, 0);
|
||||
|
||||
for (j = 0; j < total_channels; j++) {
|
||||
int sine_freq = is_lfe_channel(j, total_channels) ? LFE_SINE_FREQ_HZ : SINE_FREQ_HZ;
|
||||
|
||||
SDL_Log("Playing %d Hz test tone on channel: %s\n", sine_freq, get_channel_name(j, total_channels));
|
||||
|
||||
/* fill_buffer() will increment the active channel */
|
||||
SDL_Delay(CHANNEL_TEST_TIME_SEC * 1000);
|
||||
}
|
||||
|
||||
SDL_CloseAudioDevice(dev);
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -42,6 +42,7 @@ main(int argc, char *argv[])
|
||||
{
|
||||
int i, desired;
|
||||
SDL_TimerID t1, t2, t3;
|
||||
Uint64 start64, now64;
|
||||
Uint32 start32, now32;
|
||||
Uint64 start, now;
|
||||
|
||||
@@ -53,10 +54,25 @@ main(int argc, char *argv[])
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Verify SDL_GetTicks* acts monotonically increasing, and not erratic. */
|
||||
SDL_Log("Sanity-checking GetTicks\n");
|
||||
for (i = 0; i < 1000; ++i) {
|
||||
start64 = SDL_GetTicks64();
|
||||
start32 = SDL_GetTicks();
|
||||
SDL_Delay(1);
|
||||
now64 = SDL_GetTicks64() - start64;
|
||||
now32 = SDL_GetTicks() - start32;
|
||||
if (now32 > 100 || now64 > 100) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "testtimer.c: Delta time erratic at iter %d. Delay 1ms = %d ms in ticks, %d ms in ticks64\n", i, (int)now32, (int)now64);
|
||||
SDL_Quit();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Start the timer */
|
||||
desired = 0;
|
||||
if (argv[1]) {
|
||||
desired = atoi(argv[1]);
|
||||
desired = SDL_atoi(argv[1]);
|
||||
}
|
||||
if (desired == 0) {
|
||||
desired = DEFAULT_RESOLUTION;
|
||||
@@ -108,12 +124,14 @@ main(int argc, char *argv[])
|
||||
SDL_Log("1 million iterations of ticktock took %f ms\n", (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
|
||||
|
||||
SDL_Log("Performance counter frequency: %"SDL_PRIu64"\n", SDL_GetPerformanceFrequency());
|
||||
start64 = SDL_GetTicks64();
|
||||
start32 = SDL_GetTicks();
|
||||
start = SDL_GetPerformanceCounter();
|
||||
SDL_Delay(1000);
|
||||
now = SDL_GetPerformanceCounter();
|
||||
now64 = SDL_GetTicks64();
|
||||
now32 = SDL_GetTicks();
|
||||
SDL_Log("Delay 1 second = %d ms in ticks, %f ms according to performance counter\n", (now32-start32), (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
|
||||
SDL_Log("Delay 1 second = %d ms in ticks, %d ms in ticks64, %f ms according to performance counter\n", (int) (now32-start32), (int) (now64-start64), (double)((now - start)*1000) / SDL_GetPerformanceFrequency());
|
||||
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -35,13 +35,13 @@ main(int argc, char *argv[])
|
||||
SDL_Log("Compiled with SDL older than 2.0\n");
|
||||
#endif
|
||||
SDL_VERSION(&compiled);
|
||||
SDL_Log("Compiled version: %d.%d.%d.%d (%s)\n",
|
||||
SDL_Log("Compiled version: %d.%d.%d (%s)\n",
|
||||
compiled.major, compiled.minor, compiled.patch,
|
||||
SDL_REVISION_NUMBER, SDL_REVISION);
|
||||
SDL_REVISION);
|
||||
SDL_GetVersion(&linked);
|
||||
SDL_Log("Linked version: %d.%d.%d.%d (%s)\n",
|
||||
SDL_Log("Linked version: %d.%d.%d (%s)\n",
|
||||
linked.major, linked.minor, linked.patch,
|
||||
SDL_GetRevisionNumber(), SDL_GetRevision());
|
||||
SDL_GetRevision());
|
||||
SDL_Quit();
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -43,7 +43,7 @@ quit(int rc)
|
||||
}
|
||||
|
||||
int
|
||||
LoadSprite(char *file, SDL_Renderer *renderer)
|
||||
LoadSprite(const char *file, SDL_Renderer *renderer)
|
||||
{
|
||||
SDL_Surface *temp;
|
||||
|
||||
@@ -92,7 +92,7 @@ LoadSprite(char *file, SDL_Renderer *renderer)
|
||||
}
|
||||
|
||||
void
|
||||
DrawOnViewport(SDL_Renderer * renderer, SDL_Rect viewport)
|
||||
DrawOnViewport(SDL_Renderer * renderer)
|
||||
{
|
||||
SDL_Rect rect;
|
||||
|
||||
@@ -174,7 +174,7 @@ loop()
|
||||
continue;
|
||||
|
||||
/* Draw using viewport */
|
||||
DrawOnViewport(state->renderers[i], viewport);
|
||||
DrawOnViewport(state->renderers[i]);
|
||||
|
||||
/* Update the screen! */
|
||||
if (use_target) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
144
test/testwm2.c
144
test/testwm2.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -18,6 +18,7 @@
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
#include "SDL_test_font.h"
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
int done;
|
||||
@@ -38,6 +39,8 @@ static const char *cursorNames[] = {
|
||||
};
|
||||
int system_cursor = -1;
|
||||
SDL_Cursor *cursor = NULL;
|
||||
SDL_bool relative_mode = SDL_FALSE;
|
||||
int highlighted_mode = -1;
|
||||
|
||||
/* Call this instead of exit(), so we can clean up SDL: atexit() is evil. */
|
||||
static void
|
||||
@@ -47,6 +50,99 @@ quit(int rc)
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
/* Draws the modes menu, and stores the mode index under the mouse in highlighted_mode */
|
||||
static void
|
||||
draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_Rect viewport)
|
||||
{
|
||||
SDL_DisplayMode mode;
|
||||
char text[1024];
|
||||
const int lineHeight = 10;
|
||||
const int display_index = SDL_GetWindowDisplayIndex(window);
|
||||
const int num_modes = SDL_GetNumDisplayModes(display_index);
|
||||
int i;
|
||||
int column_chars = 0;
|
||||
int text_length;
|
||||
int x, y;
|
||||
int table_top;
|
||||
SDL_Point mouse_pos = { -1, -1 };
|
||||
|
||||
/* Get mouse position */
|
||||
if (SDL_GetMouseFocus() == window) {
|
||||
int window_x, window_y;
|
||||
float logical_x, logical_y;
|
||||
|
||||
SDL_GetMouseState(&window_x, &window_y);
|
||||
SDL_RenderWindowToLogical(renderer, window_x, window_y, &logical_x, &logical_y);
|
||||
|
||||
mouse_pos.x = (int)logical_x;
|
||||
mouse_pos.y = (int)logical_y;
|
||||
}
|
||||
|
||||
x = 0;
|
||||
y = viewport.y;
|
||||
|
||||
y += lineHeight;
|
||||
|
||||
SDL_snprintf(text, sizeof(text), "Click on a mode to set it with SDL_SetWindowDisplayMode");
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDLTest_DrawString(renderer, x, y, text);
|
||||
y += lineHeight;
|
||||
|
||||
SDL_snprintf(text, sizeof(text), "Press Ctrl+Enter to toggle SDL_WINDOW_FULLSCREEN");
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDLTest_DrawString(renderer, x, y, text);
|
||||
y += lineHeight;
|
||||
|
||||
table_top = y;
|
||||
|
||||
/* Clear the cached mode under the mouse */
|
||||
if (window == SDL_GetMouseFocus()) {
|
||||
highlighted_mode = -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < num_modes; ++i) {
|
||||
SDL_Rect cell_rect;
|
||||
|
||||
if (0 != SDL_GetDisplayMode(display_index, i, &mode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
SDL_snprintf(text, sizeof(text), "%d: %dx%d@%dHz",
|
||||
i, mode.w, mode.h, mode.refresh_rate);
|
||||
|
||||
/* Update column width */
|
||||
text_length = (int)SDL_strlen(text);
|
||||
column_chars = SDL_max(column_chars, text_length);
|
||||
|
||||
/* Check if under mouse */
|
||||
cell_rect.x = x;
|
||||
cell_rect.y = y;
|
||||
cell_rect.w = text_length * FONT_CHARACTER_SIZE;
|
||||
cell_rect.h = lineHeight;
|
||||
|
||||
if (SDL_PointInRect(&mouse_pos, &cell_rect)) {
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
|
||||
/* Update cached mode under the mouse */
|
||||
if (window == SDL_GetMouseFocus()) {
|
||||
highlighted_mode = i;
|
||||
}
|
||||
} else {
|
||||
SDL_SetRenderDrawColor(renderer, 170, 170, 170, 255);
|
||||
}
|
||||
|
||||
SDLTest_DrawString(renderer, x, y, text);
|
||||
y += lineHeight;
|
||||
|
||||
if (y + lineHeight > (viewport.y + viewport.h)) {
|
||||
/* Advance to next column */
|
||||
x += (column_chars + 1) * FONT_CHARACTER_SIZE;
|
||||
y = table_top;
|
||||
column_chars = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
loop()
|
||||
{
|
||||
@@ -76,6 +172,17 @@ loop()
|
||||
SDL_GetDisplayName(SDL_GetWindowDisplayIndex(window)));
|
||||
}
|
||||
}
|
||||
if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
|
||||
relative_mode = SDL_GetRelativeMouseMode();
|
||||
if (relative_mode) {
|
||||
SDL_SetRelativeMouseMode(SDL_FALSE);
|
||||
}
|
||||
}
|
||||
if (event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) {
|
||||
if (relative_mode) {
|
||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event.type == SDL_KEYUP) {
|
||||
SDL_bool updateCursor = SDL_FALSE;
|
||||
@@ -100,12 +207,43 @@ loop()
|
||||
SDL_SetCursor(cursor);
|
||||
}
|
||||
}
|
||||
if (event.type == SDL_MOUSEBUTTONUP) {
|
||||
SDL_Window* window = SDL_GetMouseFocus();
|
||||
if (highlighted_mode != -1 && window != NULL) {
|
||||
const int display_index = SDL_GetWindowDisplayIndex(window);
|
||||
SDL_DisplayMode mode;
|
||||
if (0 != SDL_GetDisplayMode(display_index, highlighted_mode, &mode)) {
|
||||
SDL_Log("Couldn't get display mode");
|
||||
} else {
|
||||
SDL_SetWindowDisplayMode(window, &mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Window* window = state->windows[i];
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
SDL_RenderClear(renderer);
|
||||
SDL_RenderPresent(renderer);
|
||||
if (window != NULL && renderer != NULL) {
|
||||
int y = 0;
|
||||
SDL_Rect viewport, menurect;
|
||||
|
||||
SDL_RenderGetViewport(renderer, &viewport);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
|
||||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDLTest_CommonDrawWindowInfo(renderer, state->windows[i], &y);
|
||||
|
||||
menurect.x = 0;
|
||||
menurect.y = y;
|
||||
menurect.w = viewport.w;
|
||||
menurect.h = viewport.h - y;
|
||||
draw_modes_menu(window, renderer, menurect);
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
}
|
||||
#ifdef __EMSCRIPTEN__
|
||||
if (done) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
@@ -31,9 +31,9 @@ static void RGBtoYUV(Uint8 * rgb, int *yuv, SDL_YUV_CONVERSION_MODE mode, int mo
|
||||
// This formula is from Microsoft's documentation:
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/dd206750(v=vs.85).aspx
|
||||
// L = Kr * R + Kb * B + (1 - Kr - Kb) * G
|
||||
// Y = floor(2^(M-8) * (219*(L-Z)/S + 16) + 0.5);
|
||||
// U = clip3(0, (2^M)-1, floor(2^(M-8) * (112*(B-L) / ((1-Kb)*S) + 128) + 0.5));
|
||||
// V = clip3(0, (2^M)-1, floor(2^(M-8) * (112*(R-L) / ((1-Kr)*S) + 128) + 0.5));
|
||||
// Y = SDL_floor(2^(M-8) * (219*(L-Z)/S + 16) + 0.5);
|
||||
// U = clip3(0, (2^M)-1, SDL_floor(2^(M-8) * (112*(B-L) / ((1-Kb)*S) + 128) + 0.5));
|
||||
// V = clip3(0, (2^M)-1, SDL_floor(2^(M-8) * (112*(R-L) / ((1-Kr)*S) + 128) + 0.5));
|
||||
float S, Z, R, G, B, L, Kr, Kb, Y, U, V;
|
||||
|
||||
if (mode == SDL_YUV_CONVERSION_BT709) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2020 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2022 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
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user