SDL/test/testgles2.c

911 lines
24 KiB
C
Raw Normal View History

/*
2023-01-09 10:41:41 -07:00
Copyright (C) 1997-2023 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>
#ifdef __EMSCRIPTEN__
#include <emscripten/emscripten.h>
#endif
#include <SDL3/SDL_test_common.h>
#include <SDL3/SDL_main.h>
#if defined(__IOS__) || defined(__ANDROID__) || defined(__EMSCRIPTEN__) || defined(__WINDOWS__) || defined(__LINUX__)
#define HAVE_OPENGLES2
#endif
#ifdef HAVE_OPENGLES2
#include <SDL3/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;
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;
typedef struct thread_data
{
SDL_Thread *thread;
int done;
int index;
} thread_data;
static SDLTest_CommonState *state;
static SDL_GLContext *context = NULL;
static int depth = 16;
static GLES2_Context ctx;
static int LoadContext(GLES2_Context *data)
{
Fix uses of undefined macro identifiers (-Wundef) * Fix -Wundef warnings due to use of unguarded SDL_LOADSO_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_WINDOWS * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_ANDROID * Fix -Wundef warnings due to use of unguarded SDL_LOADSO_DUMMY * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_COCOA * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_UIKIT * Fix -Wundef warnings due to use of unguarded SDL_TIMERS_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_EVENTS_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_TIMER_DUMMY * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_HAPTIC_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_SENSOR_DISABLED * Fix -Wundef warnings due to use of unguarded __ANDROID__ * Fix -Wundef warnings due to use of unguarded __IOS__ * Fix -Wundef warnings due to use of unguarded EMULATE_CAS * Fix -Wundef warnings due to use of unguarded SDL_ATOMIC_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_THREADS_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_SNDIO * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_NETBSD * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_WASAPI * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_DSOUND * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_HAIKU * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_COREAUDIO * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_AAUDIO * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_OPENSLES * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_ANDROID * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_PS2 * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_PSP * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_VITA * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_N3DS * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_EMSCRIPTEN * Fix -Wundef warnings due to use of unguarded SDL_NEON_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_ALTIVEC_BLITTERS * Fix -Wundef warnings due to use of unguarded __VITA__ * Fix -Wundef warnings due to use of unguarded __3DS__ * Fix -Wundef warnings due to use of unguarded SDL_DYNAPI_PROC_NO_VARARGS * Fix -Wundef warnings due to use of unguarded __APPLE__ * Fix -Wundef warnings due to use of unguarded __WINRT__ * Fix -Wundef warnings due to use of unguarded SDL_HIDAPI_DISABLED * Fix -Wundef warnings due to use of unguarded __TVOS__ * Fix -Wundef warnings due to use of unguarded HAVE_DRIVER_BACKEND * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_XINPUT * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_WGI * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_DINPUT * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_MFI * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_EMSCRIPTEN * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_PS2 * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_PSP * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_VITA * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_N3DS * Fix -Wundef warnings due to use of unguarded __MACOS__ * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_D3D * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_WINRT * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_RPI * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_VITA_PVR_OGL * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_VIVANTE * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_D3D11 * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_D3D12 * Fix -Wundef warnings due to use of unguarded SDL_RENDER_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_METAL * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_PS2 * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_PSP * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_VITA_GXM * Fix -Wundef warnings due to use of unguarded SDL_ARM_SIMD_BLITTERS * Fix -Wundef warnings due to use of unguarded SDL_ARM_NEON_BLITTERS * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_HAIKU * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_PS2 * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_PSP * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_VITA * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_N3DS * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_KMSDRM * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_RISCOS * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_EMSCRIPTEN * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_NGAGE * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_METAL * Fix -Wundef warnings due to use of unguarded SDL_LSX_INTRINSICS * Fix -Wundef warnings due to use of unguarded HAVE_PTHREAD_NP_H * Fix -Wundef warnings due to use of unguarded __RISCOS__ * Fix -Wundef warnings due to use of unguarded FAKE_RECURSIVE_MUTEX * Fix -Wundef warnings due to use of unguarded USE_POSIX_SPAWN * textureData is only needed when SDL is built with YUV support * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_ALSA * Fix -Wundef warnings due to use of unguarded SDL_SSE3_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_SSE4_2_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_SSE4_1_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_AVX512F_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_SSE2_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_AVX_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_AVX2_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_SSE_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_MMX_INTRINSICS * Fix -Wundef warnings due to use of unguarded HAVE_CLOCK_GETTIME * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_DISK * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_DUMMY * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_DUMMY * Fix -Wundef warnings due to use of unguarded HAVE_GCC_ATOMICS * Fix -Wundef warnings due to use of unguarded HAVE_GCC_SYNC_LOCK_TEST_AND_SET * Fix -Wundef warnings due to use of unguarded SDL_USE_LIBDBUS * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_JACK * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_VIRTUAL * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_LINUX * Fix -Wundef warnings due to use of unguarded HAVE_LIBC * Fix -Wundef warnings due to disabling SDL_LIBC * Fix -Wundef warnings due to use of unguarded HAVE_PLATFORM_BACKEND * Fix -Wundef warnings due to use of unguarded DEBUG * Fix -Wundef warnings due to use of unguarded HAVE_LINUX_INPUT_H * Fix -Werror=unused-variable when building with SDL_LIBC=OFF * Fix -Wundef warnings due to use of unguqrded SDL_USE_LIBUDEV * Use SDL alloc functions in libusb/hid.c * Fix -Wundef warnings due to use of unguarded HAVE_LIBUDEV_H * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_VULKAN * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_OFFSCREEN * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_OGL * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_GLX * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_ES * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_ES2 * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_OGL_ES2 * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_OSS * Remove SDL_AUDIO_DRIVER_SUNAUDIO reference since it is never set * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_PIPEWIRE * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_PULSEAUDIO * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XCURSOR * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XDBE * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XFIXES * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XINPUT2 * Fix -Wundef warnings due to use of unguarded #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH * Fix -Wundef warnings due to use of unguarded #if SDL_VIDEO_DRIVER_X11_XRANDR * Fix -Wundef warnings due to use of unguarded #if SDL_VIDEO_DRIVER_X11_XSCRNSAVER * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XSHAPE * Don't call XShape functions when XShape is diabled * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_WAYLAND * Fix -Wundef warnings due to use of unuarded SDL_VIDEO_DRIVER_X11 * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_RISCOS * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_EGL * Disable array when compiled with SDL_EVENTS=OFF * Fix -Wundef warnings due to use of unguarded SDL_INPUT_LINUXEV * Fix -Wundef warnings due to use of unguarded SDL_THREAD_PTHREAD * Fix -Wundef warnings due to use of unguarded SDL_THREAD_WINDOWS * Fix -Wundef warnings due to use of unguarded SDL_THREAD_PS2 * Fix -Wundef warnings due to use of unguarded SDL_THREAD_PSP * Fix -Wundef warnings due to use of unguarded SDL_THREAD_VITA * Fix -Wundef warnings due to use of unguarded SDL_THREAD_N3DS * Fix -Wundef warnings due to use of unguarded SDL_THREAD_STDCPP * Fix -Wundef warnings due to use of unguarded SDL_THREAD_NGAGE * Fix -Wundef warnings due to use of unguarded __WINDOWS__ * Fix -Wundef warnings due to use of unguarded __WINGDK__ * Fix -Wundef warnings due to use of unguarded __ANDROID__ * Fix -Wundef warnings due to use of unguarded SDL_THREAD_GENERIC_COND_SUFFIX * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_VITA_PIB * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_VITA_PVR * Fix -Wundef warnings due to use of unguarded SDL_FILE_DISABLED * Fix -Wundef warnings due to use of unguarded __XBOXONE__ * Fix -Wundef warnings due to use of unguarded __XBOXSERIES__ * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_WGL * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_QNX * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_DISK * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_QNX * Fix -Wundef warnings due to use of unguarded DEBUG_RAZOR * Fix -Wundef warnings due to use of unguarded WINAPI_FAMILY_PHONE_APP * Fix -Wundef warnings due to use of unguarded SDL_MAC_NO_SANDBOX * Fix -Wundef warnings due to use of unguarded __(IPHONE|APPLETV|MAC)_OS_VERSION_MAX_ALLOWED * Fix C4090 warning ('function': different 'const' qualifiers) * ci: use -isystem for include dirs of pspdev toolchain * cmake: add -Wundef option * Fix remaining -Wundef warnings due to use of unguarded SDL_VIDEO_VULKAN and SDL_VIDEO_METAL * Fix -Wundef warnings due to use of unguarded __MACOS__ * DEBUG_CONVERT is guaranteed to be defined in src/audio/SDL_audiocvt.c * Fix -Wundef warnings due to use of unguarded HAVE_NANOSLEEP * Fix -Wundef warnings due to use of unguarded HAVE_DXGI_H * Fix -Wundef warnings due to use of unguarded HAVE_LINUX_INPUT_H * fix SDL_VIDEO_DRIVER_WAYLAND * fix SDL_VIDEO_DRIVER_X11 * Fix -Wundef warnings due to use of unguarded HAVE_MMDEVICEAPI_H * Fix -Wundef warnings due to use of unguarded HAVE_PTHREAD_SETNAME_NP * Fix -Wundef warnings due to use of unguarded HAVE_PTHREAD_SET_NAME_NP * Fix -Wundef warnings due to use of unguarded HAVE_SETJMP * Fix -Wundef warnings due to use of unguarded HAVE_SIGNAL_H * Fix -Wundef warnings due to use of unguarded HAVE_TPCSHRD_H * Fix -Wundef warnings due to use of unguarded MACOSX_COREAUDIO * Fix -Wundef warnings due to use of unguarded SDL_HAPTIC_DINPUT * Fix -Wundef warnings due to use of unguarded SDL_HAPTIC_IOKIT * Fix -Wundef warnings due to use of unguarded SDL_HAPTIC_XINPUT * Fix -Wundef warnings due to use of unguarded SDL_IPHONE_KEYBOARD * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_RAWINPUT * Fix -Wundef warnings due to use of unguarded SDL_POWER_ANDROID * Fix -Wundef warnings due to use of unguarded SDL_POWER_EMSCRIPTEN * Fix -Wundef warnings due to use of unguarded SDL_POWER_HAIKU * Fix -Wundef warnings due to use of unguarded SDL_POWER_LINUX * Fix -Wundef warnings due to use of unguarded SDL_POWER_MACOSX * Fix -Wundef warnings due to use of unguarded SDL_POWER_PSP * Fix -Wundef warnings due to use of unguarded SDL_POWER_UIKIT * Fix -Wundef warnings due to use of unguarded SDL_POWER_VITA * Fix -Wundef warnings due to use of unguarded SDL_POWER_WINDOWS * Fix -Wundef warnings due to use of unguarded SDL_THREAD_PTHREAD_RECURSIVE_MUTEX * Fix -Wundef warnings due to use of unguarded SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_VIVANTE_VDK * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_WAYLAND * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_CGL * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_EGL * Fix -Wundef warnings due to use of unguarded __MACOS__ * Fix -Wundef warnings due to use of unguarded __OpenBSD__ * Fix -Wundef warnings due to use of unguarded __FreeBSD__ * Fix -Wundef warnings due to use of unguarded __MWERKS__ * Fix -Wundef warnings due to use of unguarded __WIN32__ * Fix -Wundef warnings due to use of unguarded SDL_IPHONE_LAUNCHSCREEN * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_ES2 * Remove unused HAVE_CONST, HAVE_INLINE and HAVE_VOLATILE * Revert "Use SDL alloc functions in libusb/hid.c" This reverts commit 847c64b00da12ca08bef9e947eb948e378eeaef8. * Handle FAKE_RECURSIVE_MUTEX in similar way as SDL2 * Don't use defined in macro
2023-03-29 15:49:01 -06:00
#ifdef SDL_VIDEO_DRIVER_UIKIT
#define __SDL_NOGETPROCADDR__
Fix uses of undefined macro identifiers (-Wundef) * Fix -Wundef warnings due to use of unguarded SDL_LOADSO_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_WINDOWS * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_ANDROID * Fix -Wundef warnings due to use of unguarded SDL_LOADSO_DUMMY * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_COCOA * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_UIKIT * Fix -Wundef warnings due to use of unguarded SDL_TIMERS_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_EVENTS_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_TIMER_DUMMY * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_HAPTIC_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_SENSOR_DISABLED * Fix -Wundef warnings due to use of unguarded __ANDROID__ * Fix -Wundef warnings due to use of unguarded __IOS__ * Fix -Wundef warnings due to use of unguarded EMULATE_CAS * Fix -Wundef warnings due to use of unguarded SDL_ATOMIC_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_THREADS_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_SNDIO * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_NETBSD * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_WASAPI * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_DSOUND * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_HAIKU * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_COREAUDIO * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_AAUDIO * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_OPENSLES * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_ANDROID * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_PS2 * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_PSP * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_VITA * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_N3DS * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_EMSCRIPTEN * Fix -Wundef warnings due to use of unguarded SDL_NEON_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_ALTIVEC_BLITTERS * Fix -Wundef warnings due to use of unguarded __VITA__ * Fix -Wundef warnings due to use of unguarded __3DS__ * Fix -Wundef warnings due to use of unguarded SDL_DYNAPI_PROC_NO_VARARGS * Fix -Wundef warnings due to use of unguarded __APPLE__ * Fix -Wundef warnings due to use of unguarded __WINRT__ * Fix -Wundef warnings due to use of unguarded SDL_HIDAPI_DISABLED * Fix -Wundef warnings due to use of unguarded __TVOS__ * Fix -Wundef warnings due to use of unguarded HAVE_DRIVER_BACKEND * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_XINPUT * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_WGI * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_DINPUT * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_MFI * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_EMSCRIPTEN * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_PS2 * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_PSP * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_VITA * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_N3DS * Fix -Wundef warnings due to use of unguarded __MACOS__ * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_D3D * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_WINRT * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_RPI * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_VITA_PVR_OGL * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_VIVANTE * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_D3D11 * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_D3D12 * Fix -Wundef warnings due to use of unguarded SDL_RENDER_DISABLED * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_METAL * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_PS2 * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_PSP * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_VITA_GXM * Fix -Wundef warnings due to use of unguarded SDL_ARM_SIMD_BLITTERS * Fix -Wundef warnings due to use of unguarded SDL_ARM_NEON_BLITTERS * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_HAIKU * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_PS2 * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_PSP * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_VITA * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_N3DS * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_KMSDRM * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_RISCOS * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_EMSCRIPTEN * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_NGAGE * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_METAL * Fix -Wundef warnings due to use of unguarded SDL_LSX_INTRINSICS * Fix -Wundef warnings due to use of unguarded HAVE_PTHREAD_NP_H * Fix -Wundef warnings due to use of unguarded __RISCOS__ * Fix -Wundef warnings due to use of unguarded FAKE_RECURSIVE_MUTEX * Fix -Wundef warnings due to use of unguarded USE_POSIX_SPAWN * textureData is only needed when SDL is built with YUV support * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_ALSA * Fix -Wundef warnings due to use of unguarded SDL_SSE3_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_SSE4_2_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_SSE4_1_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_AVX512F_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_SSE2_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_AVX_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_AVX2_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_SSE_INTRINSICS * Fix -Wundef warnings due to use of unguarded SDL_MMX_INTRINSICS * Fix -Wundef warnings due to use of unguarded HAVE_CLOCK_GETTIME * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_DISK * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_DUMMY * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_DUMMY * Fix -Wundef warnings due to use of unguarded HAVE_GCC_ATOMICS * Fix -Wundef warnings due to use of unguarded HAVE_GCC_SYNC_LOCK_TEST_AND_SET * Fix -Wundef warnings due to use of unguarded SDL_USE_LIBDBUS * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_JACK * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_VIRTUAL * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_LINUX * Fix -Wundef warnings due to use of unguarded HAVE_LIBC * Fix -Wundef warnings due to disabling SDL_LIBC * Fix -Wundef warnings due to use of unguarded HAVE_PLATFORM_BACKEND * Fix -Wundef warnings due to use of unguarded DEBUG * Fix -Wundef warnings due to use of unguarded HAVE_LINUX_INPUT_H * Fix -Werror=unused-variable when building with SDL_LIBC=OFF * Fix -Wundef warnings due to use of unguqrded SDL_USE_LIBUDEV * Use SDL alloc functions in libusb/hid.c * Fix -Wundef warnings due to use of unguarded HAVE_LIBUDEV_H * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_VULKAN * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_OFFSCREEN * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_OGL * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_GLX * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_ES * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_ES2 * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_RENDER_OGL_ES2 * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_OSS * Remove SDL_AUDIO_DRIVER_SUNAUDIO reference since it is never set * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_PIPEWIRE * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_PULSEAUDIO * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XCURSOR * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XDBE * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XFIXES * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XINPUT2 * Fix -Wundef warnings due to use of unguarded #if SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH * Fix -Wundef warnings due to use of unguarded #if SDL_VIDEO_DRIVER_X11_XRANDR * Fix -Wundef warnings due to use of unguarded #if SDL_VIDEO_DRIVER_X11_XSCRNSAVER * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_XSHAPE * Don't call XShape functions when XShape is diabled * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_WAYLAND * Fix -Wundef warnings due to use of unuarded SDL_VIDEO_DRIVER_X11 * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_RISCOS * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_EGL * Disable array when compiled with SDL_EVENTS=OFF * Fix -Wundef warnings due to use of unguarded SDL_INPUT_LINUXEV * Fix -Wundef warnings due to use of unguarded SDL_THREAD_PTHREAD * Fix -Wundef warnings due to use of unguarded SDL_THREAD_WINDOWS * Fix -Wundef warnings due to use of unguarded SDL_THREAD_PS2 * Fix -Wundef warnings due to use of unguarded SDL_THREAD_PSP * Fix -Wundef warnings due to use of unguarded SDL_THREAD_VITA * Fix -Wundef warnings due to use of unguarded SDL_THREAD_N3DS * Fix -Wundef warnings due to use of unguarded SDL_THREAD_STDCPP * Fix -Wundef warnings due to use of unguarded SDL_THREAD_NGAGE * Fix -Wundef warnings due to use of unguarded __WINDOWS__ * Fix -Wundef warnings due to use of unguarded __WINGDK__ * Fix -Wundef warnings due to use of unguarded __ANDROID__ * Fix -Wundef warnings due to use of unguarded SDL_THREAD_GENERIC_COND_SUFFIX * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_VITA_PIB * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_VITA_PVR * Fix -Wundef warnings due to use of unguarded SDL_FILE_DISABLED * Fix -Wundef warnings due to use of unguarded __XBOXONE__ * Fix -Wundef warnings due to use of unguarded __XBOXSERIES__ * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_WGL * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_QNX * Fix -Wundef warnings due to use of unguarded SDL_AUDIO_DRIVER_DISK * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_QNX * Fix -Wundef warnings due to use of unguarded DEBUG_RAZOR * Fix -Wundef warnings due to use of unguarded WINAPI_FAMILY_PHONE_APP * Fix -Wundef warnings due to use of unguarded SDL_MAC_NO_SANDBOX * Fix -Wundef warnings due to use of unguarded __(IPHONE|APPLETV|MAC)_OS_VERSION_MAX_ALLOWED * Fix C4090 warning ('function': different 'const' qualifiers) * ci: use -isystem for include dirs of pspdev toolchain * cmake: add -Wundef option * Fix remaining -Wundef warnings due to use of unguarded SDL_VIDEO_VULKAN and SDL_VIDEO_METAL * Fix -Wundef warnings due to use of unguarded __MACOS__ * DEBUG_CONVERT is guaranteed to be defined in src/audio/SDL_audiocvt.c * Fix -Wundef warnings due to use of unguarded HAVE_NANOSLEEP * Fix -Wundef warnings due to use of unguarded HAVE_DXGI_H * Fix -Wundef warnings due to use of unguarded HAVE_LINUX_INPUT_H * fix SDL_VIDEO_DRIVER_WAYLAND * fix SDL_VIDEO_DRIVER_X11 * Fix -Wundef warnings due to use of unguarded HAVE_MMDEVICEAPI_H * Fix -Wundef warnings due to use of unguarded HAVE_PTHREAD_SETNAME_NP * Fix -Wundef warnings due to use of unguarded HAVE_PTHREAD_SET_NAME_NP * Fix -Wundef warnings due to use of unguarded HAVE_SETJMP * Fix -Wundef warnings due to use of unguarded HAVE_SIGNAL_H * Fix -Wundef warnings due to use of unguarded HAVE_TPCSHRD_H * Fix -Wundef warnings due to use of unguarded MACOSX_COREAUDIO * Fix -Wundef warnings due to use of unguarded SDL_HAPTIC_DINPUT * Fix -Wundef warnings due to use of unguarded SDL_HAPTIC_IOKIT * Fix -Wundef warnings due to use of unguarded SDL_HAPTIC_XINPUT * Fix -Wundef warnings due to use of unguarded SDL_IPHONE_KEYBOARD * Fix -Wundef warnings due to use of unguarded SDL_JOYSTICK_RAWINPUT * Fix -Wundef warnings due to use of unguarded SDL_POWER_ANDROID * Fix -Wundef warnings due to use of unguarded SDL_POWER_EMSCRIPTEN * Fix -Wundef warnings due to use of unguarded SDL_POWER_HAIKU * Fix -Wundef warnings due to use of unguarded SDL_POWER_LINUX * Fix -Wundef warnings due to use of unguarded SDL_POWER_MACOSX * Fix -Wundef warnings due to use of unguarded SDL_POWER_PSP * Fix -Wundef warnings due to use of unguarded SDL_POWER_UIKIT * Fix -Wundef warnings due to use of unguarded SDL_POWER_VITA * Fix -Wundef warnings due to use of unguarded SDL_POWER_WINDOWS * Fix -Wundef warnings due to use of unguarded SDL_THREAD_PTHREAD_RECURSIVE_MUTEX * Fix -Wundef warnings due to use of unguarded SDL_THREAD_PTHREAD_RECURSIVE_MUTEX_NP * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_VIVANTE_VDK * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_WAYLAND * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_HAS_XKBKEYCODETOKEYSYM * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_DRIVER_X11_SUPPORTS_GENERIC_EVENTS * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_CGL * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_EGL * Fix -Wundef warnings due to use of unguarded __MACOS__ * Fix -Wundef warnings due to use of unguarded __OpenBSD__ * Fix -Wundef warnings due to use of unguarded __FreeBSD__ * Fix -Wundef warnings due to use of unguarded __MWERKS__ * Fix -Wundef warnings due to use of unguarded __WIN32__ * Fix -Wundef warnings due to use of unguarded SDL_IPHONE_LAUNCHSCREEN * Fix -Wundef warnings due to use of unguarded SDL_VIDEO_OPENGL_ES2 * Remove unused HAVE_CONST, HAVE_INLINE and HAVE_VOLATILE * Revert "Use SDL alloc functions in libusb/hid.c" This reverts commit 847c64b00da12ca08bef9e947eb948e378eeaef8. * Handle FAKE_RECURSIVE_MUTEX in similar way as SDL2 * Don't use defined in macro
2023-03-29 15:49:01 -06:00
#elif defined(SDL_VIDEO_DRIVER_ANDROID)
#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 = (ret (APIENTRY *) params)SDL_GL_GetProcAddress(#func); \
if (!data->func) { \
2017-03-26 13:00:19 -06:00
return SDL_SetError("Couldn't load GLES2 function %s: %s", #func, SDL_GetError()); \
} \
} while (0);
2015-12-25 05:41:23 -07:00
#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); \
} \
}
/**
* Simulates desktop's glRotatef. The matrix is returned in column-major
* order.
*/
static void
rotate_matrix(float angle, float x, float y, float z, float *r)
{
float radians, c, s, c1, u[3], length;
int i, j;
radians = (angle * SDL_PI_F) / 180.0f;
c = SDL_cosf(radians);
s = SDL_sinf(radians);
c1 = 1.0f - SDL_cosf(radians);
length = (float)SDL_sqrt(x * x + y * y + z * z);
u[0] = x / length;
u[1] = y / length;
u[2] = z / length;
for (i = 0; i < 16; i++) {
r[i] = 0.0;
}
r[15] = 1.0;
for (i = 0; i < 3; i++) {
r[i * 4 + (i + 1) % 3] = u[(i + 2) % 3] * s;
r[i * 4 + (i + 2) % 3] = -u[(i + 1) % 3] * s;
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
r[i * 4 + j] += c1 * u[i] * u[j] + (i == j ? c : 0.0f);
}
}
}
/**
* Simulates gluPerspectiveMatrix
*/
static void
perspective_matrix(float fovy, float aspect, float znear, float zfar, float *r)
{
int i;
float f;
f = 1.0f / SDL_tanf(fovy * 0.5f);
for (i = 0; i < 16; i++) {
r[i] = 0.0;
}
r[0] = f / aspect;
r[5] = f;
r[10] = (znear + zfar) / (znear - zfar);
r[11] = -1.0f;
r[14] = (2.0f * znear * zfar) / (znear - zfar);
r[15] = 0.0f;
}
/**
* Multiplies lhs by rhs and writes out to r. All matrices are 4x4 and column
* major. In-place multiplication is supported.
*/
static void
2022-12-01 14:07:03 -07:00
multiply_matrix(const float *lhs, const float *rhs, float *r)
{
int i, j, k;
float tmp[16];
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
tmp[j * 4 + i] = 0.0;
for (k = 0; k < 4; k++) {
tmp[j * 4 + i] += lhs[k * 4 + i] * rhs[j * 4 + k];
}
}
}
for (i = 0; i < 16; i++) {
r[i] = tmp[i];
}
}
/**
* 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.
*/
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 = 0;
/* 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.glGetShaderInfoLog(*shader, sizeof(buffer), &length, &buffer[0]);
buffer[length] = '\0';
SDL_Log("Shader compilation failed: %s", buffer);
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);
quit(-1);
}
}
/* 3D data. Vertex range -0.5..0.5 in all axes.
* Z -0.5 is near, 0.5 is far. */
static const float g_vertices[] = {
/* Front face. */
/* Bottom left */
-0.5,
0.5,
-0.5,
0.5,
-0.5,
-0.5,
-0.5,
-0.5,
-0.5,
/* Top right */
-0.5,
0.5,
-0.5,
0.5,
0.5,
-0.5,
0.5,
-0.5,
-0.5,
/* Left face */
/* Bottom left */
-0.5,
0.5,
0.5,
-0.5,
-0.5,
-0.5,
-0.5,
-0.5,
0.5,
/* Top right */
-0.5,
0.5,
0.5,
-0.5,
0.5,
-0.5,
-0.5,
-0.5,
-0.5,
/* Top face */
/* Bottom left */
-0.5,
0.5,
0.5,
0.5,
0.5,
-0.5,
-0.5,
0.5,
-0.5,
/* Top right */
-0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
0.5,
-0.5,
/* Right face */
/* Bottom left */
0.5,
0.5,
-0.5,
0.5,
-0.5,
0.5,
0.5,
-0.5,
-0.5,
/* Top right */
0.5,
0.5,
-0.5,
0.5,
0.5,
0.5,
0.5,
-0.5,
0.5,
/* Back face */
/* Bottom left */
0.5,
0.5,
0.5,
-0.5,
-0.5,
0.5,
0.5,
-0.5,
0.5,
/* Top right */
0.5,
0.5,
0.5,
-0.5,
0.5,
0.5,
-0.5,
-0.5,
0.5,
/* Bottom face */
/* Bottom left */
-0.5,
-0.5,
-0.5,
0.5,
-0.5,
0.5,
-0.5,
-0.5,
0.5,
/* Top right */
-0.5,
-0.5,
-0.5,
0.5,
-0.5,
-0.5,
0.5,
-0.5,
0.5,
};
static const float g_colors[] = {
/* Front face */
/* Bottom left */
1.0, 0.0, 0.0, /* red */
0.0, 0.0, 1.0, /* blue */
0.0, 1.0, 0.0, /* green */
/* Top right */
1.0, 0.0, 0.0, /* red */
1.0, 1.0, 0.0, /* yellow */
0.0, 0.0, 1.0, /* blue */
/* Left face */
/* Bottom left */
1.0, 1.0, 1.0, /* white */
0.0, 1.0, 0.0, /* green */
0.0, 1.0, 1.0, /* cyan */
/* Top right */
1.0, 1.0, 1.0, /* white */
1.0, 0.0, 0.0, /* red */
0.0, 1.0, 0.0, /* green */
/* Top face */
/* Bottom left */
1.0, 1.0, 1.0, /* white */
1.0, 1.0, 0.0, /* yellow */
1.0, 0.0, 0.0, /* red */
/* Top right */
1.0, 1.0, 1.0, /* white */
0.0, 0.0, 0.0, /* black */
1.0, 1.0, 0.0, /* yellow */
/* Right face */
/* Bottom left */
1.0, 1.0, 0.0, /* yellow */
1.0, 0.0, 1.0, /* magenta */
0.0, 0.0, 1.0, /* blue */
/* Top right */
1.0, 1.0, 0.0, /* yellow */
0.0, 0.0, 0.0, /* black */
1.0, 0.0, 1.0, /* magenta */
/* Back face */
/* Bottom left */
0.0, 0.0, 0.0, /* black */
0.0, 1.0, 1.0, /* cyan */
1.0, 0.0, 1.0, /* magenta */
/* Top right */
0.0, 0.0, 0.0, /* black */
1.0, 1.0, 1.0, /* white */
0.0, 1.0, 1.0, /* cyan */
/* Bottom face */
/* Bottom left */
0.0, 1.0, 0.0, /* green */
1.0, 0.0, 1.0, /* magenta */
0.0, 1.0, 1.0, /* cyan */
/* Top right */
0.0, 1.0, 0.0, /* green */
0.0, 0.0, 1.0, /* blue */
1.0, 0.0, 1.0, /* magenta */
};
static const char *g_shader_vert_src =
" attribute vec4 av4position; "
" attribute vec3 av3color; "
" uniform mat4 mvp; "
" varying vec3 vv3color; "
" void main() { "
" vv3color = av3color; "
" gl_Position = mvp * av4position; "
" } ";
static const char *g_shader_frag_src =
" precision lowp float; "
" varying vec3 vv3color; "
" void main() { "
" gl_FragColor = vec4(vv3color, 1.0); "
" } ";
static void
Render(unsigned int width, unsigned int height, shader_data *data)
{
float matrix_rotate[16], matrix_modelview[16], matrix_perspective[16], matrix_mvp[16];
/*
* Do some rotation with Euler angles. It is not a fixed axis as
* quaterions would be, but the effect is cool.
*/
rotate_matrix((float)data->angle_x, 1.0f, 0.0f, 0.0f, matrix_modelview);
rotate_matrix((float)data->angle_y, 0.0f, 1.0f, 0.0f, matrix_rotate);
multiply_matrix(matrix_rotate, matrix_modelview, matrix_modelview);
rotate_matrix((float)data->angle_z, 0.0f, 1.0f, 0.0f, matrix_rotate);
multiply_matrix(matrix_rotate, matrix_modelview, matrix_modelview);
/* Pull the camera back from the cube */
matrix_modelview[14] -= 2.5;
perspective_matrix(45.0f, (float)width / height, 0.01f, 100.0f, matrix_perspective);
multiply_matrix(matrix_perspective, matrix_modelview, matrix_mvp);
GL_CHECK(ctx.glUniformMatrix4fv(data->attr_mvp, 1, GL_FALSE, matrix_mvp));
data->angle_x += 3;
data->angle_y += 2;
data->angle_z += 1;
if (data->angle_x >= 360) {
data->angle_x -= 360;
}
if (data->angle_x < 0) {
data->angle_x += 360;
}
if (data->angle_y >= 360) {
data->angle_y -= 360;
}
if (data->angle_y < 0) {
data->angle_y += 360;
}
if (data->angle_z >= 360) {
data->angle_z -= 360;
}
if (data->angle_z < 0) {
data->angle_z += 360;
}
GL_CHECK(ctx.glViewport(0, 0, width, height));
GL_CHECK(ctx.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
GL_CHECK(ctx.glDrawArrays(GL_TRIANGLES, 0, 36));
}
static int done;
static Uint32 frames;
static shader_data *datas;
2023-03-08 09:58:26 -07:00
#ifndef __EMSCRIPTEN__
static thread_data *threads;
2023-03-08 09:58:26 -07:00
#endif
static void
render_window(int index)
{
int w, h, status;
if (!state->windows[index]) {
return;
}
status = SDL_GL_MakeCurrent(state->windows[index], context[index]);
if (status) {
SDL_Log("SDL_GL_MakeCurrent(): %s\n", SDL_GetError());
return;
}
SDL_GetWindowSizeInPixels(state->windows[index], &w, &h);
Render(w, h, &datas[index]);
SDL_GL_SwapWindow(state->windows[index]);
++frames;
}
2022-11-01 06:10:46 -06:00
#ifndef __EMSCRIPTEN__
static int SDLCALL
render_thread_fn(void *render_ctx)
{
thread_data *thread = render_ctx;
while (!done && !thread->done && state->windows[thread->index]) {
render_window(thread->index);
}
SDL_GL_MakeCurrent(state->windows[thread->index], NULL);
return 0;
}
static void
loop_threaded(void)
{
SDL_Event event;
int i;
/* Wait for events */
while (SDL_WaitEvent(&event) && !done) {
if (event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED) {
SDL_Window *window = SDL_GetWindowFromID(event.window.windowID);
if (window) {
for (i = 0; i < state->num_windows; ++i) {
if (window == state->windows[i]) {
/* Stop the render thread when the window is closed */
threads[i].done = 1;
if (threads[i].thread) {
SDL_WaitThread(threads[i].thread, NULL);
threads[i].thread = NULL;
}
break;
}
}
}
}
SDLTest_CommonEvent(state, &event, &done);
}
}
2022-11-01 06:10:46 -06:00
#endif
static void
loop(void)
{
SDL_Event event;
int i;
/* Check for events */
while (SDL_PollEvent(&event) && !done) {
SDLTest_CommonEvent(state, &event, &done);
}
if (!done) {
for (i = 0; i < state->num_windows; ++i) {
render_window(i);
}
}
#ifdef __EMSCRIPTEN__
else {
emscripten_cancel_main_loop();
}
#endif
}
int main(int argc, char *argv[])
{
int fsaa, accel, threaded;
int value;
int i;
const SDL_DisplayMode *mode;
Uint64 then, now;
int status;
shader_data *data;
/* Initialize parameters */
fsaa = 0;
accel = 0;
threaded = 0;
/* Initialize test framework */
state = SDLTest_CommonCreateState(argv, SDL_INIT_VIDEO);
if (state == NULL) {
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], "--threaded") == 0) {
++threaded;
consumed = 1;
} else if (SDL_strcasecmp(argv[i], "--zdepth") == 0) {
i++;
if (!argv[i]) {
consumed = -1;
} else {
char *endptr = NULL;
depth = (int)SDL_strtol(argv[i], &endptr, 0);
if (endptr != argv[i] && *endptr == '\0') {
consumed = 1;
} else {
consumed = -1;
}
}
} else {
consumed = -1;
}
}
if (consumed < 0) {
2022-08-16 18:50:59 -06:00
static const char *options[] = { "[--fsaa]", "[--accel]", "[--zdepth %d]", "[--threaded]", 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;
}
if (state->render_flags & SDL_RENDERER_PRESENTVSYNC) {
SDL_GL_SetSwapInterval(1);
} else {
SDL_GL_SetSwapInterval(0);
}
mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());
SDL_Log("Threaded : %s\n", threaded ? "yes" : "no");
if (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;
}
SDL_GetWindowSizeInPixels(state->windows[i], &w, &h);
ctx.glViewport(0, 0, w, h);
data = &datas[i];
data->angle_x = 0;
data->angle_y = 0;
data->angle_z = 0;
/* Shader Initialization */
process_shader(&data->shader_vert, g_shader_vert_src, GL_VERTEX_SHADER);
process_shader(&data->shader_frag, g_shader_frag_src, GL_FRAGMENT_SHADER);
/* Create shader_program (ready to attach shaders) */
data->shader_program = GL_CHECK(ctx.glCreateProgram());
/* Attach shaders and link 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"));
data->attr_color = GL_CHECK(ctx.glGetAttribLocation(data->shader_program, "av3color"));
/* Get uniform locations */
data->attr_mvp = GL_CHECK(ctx.glGetUniformLocation(data->shader_program, "mvp"));
GL_CHECK(ctx.glUseProgram(data->shader_program));
/* Enable attributes for position, color and texture coordinates etc. */
GL_CHECK(ctx.glEnableVertexAttribArray(data->attr_position));
GL_CHECK(ctx.glEnableVertexAttribArray(data->attr_color));
/* Populate attributes for position, color and texture coordinates etc. */
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(g_vertices), g_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(g_colors), g_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));
SDL_GL_MakeCurrent(state->windows[i], NULL);
}
/* Main render loop */
frames = 0;
then = SDL_GetTicks();
done = 0;
#ifdef __EMSCRIPTEN__
emscripten_set_main_loop(loop, 0, 1);
#else
if (threaded) {
threads = (thread_data *)SDL_calloc(state->num_windows, sizeof(thread_data));
/* Start a render thread for each window */
for (i = 0; i < state->num_windows; ++i) {
threads[i].index = i;
threads[i].thread = SDL_CreateThread(render_thread_fn, "RenderThread", &threads[i]);
}
while (!done) {
loop_threaded();
}
/* Join the remaining render threads (if any) */
for (i = 0; i < state->num_windows; ++i) {
threads[i].done = 1;
if (threads[i].thread) {
SDL_WaitThread(threads[i].thread, NULL);
}
}
} 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));
}
2022-11-22 10:10:47 -07:00
#if !defined(__ANDROID__)
quit(0);
2022-11-22 10:10:47 -07:00
#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 */