SDL: better GLES3 support, non-working GLES3 sample app
This commit is contained in:
@@ -4,5 +4,5 @@ include jni/Settings.mk
|
||||
|
||||
APP_STL := gnustl_static
|
||||
APP_CFLAGS := -O3 -DNDEBUG -g # arm-linux-androideabi-4.4.3 crashes in -O0 mode on SDL sources
|
||||
APP_PLATFORM := android-14 # Android 4.0, it should be backward compatible to previous versions
|
||||
APP_PLATFORM := android-18 # Android 4.3, the first one with GLES3 support
|
||||
APP_PIE := true # This feature makes executables incompatible to Android API 15 or lower, but executables without PIE will not run on Android 5.0 and newer
|
||||
|
||||
@@ -36,6 +36,8 @@ APPLICATION_ADDITIONAL_CPPFLAGS :=
|
||||
|
||||
APPLICATION_ADDITIONAL_LDFLAGS :=
|
||||
|
||||
APPLICATION_GLES_LIBRARY := -lGLESv1_CM
|
||||
|
||||
APPLICATION_OVERLAPS_SYSTEM_HEADERS := n
|
||||
|
||||
APPLICATION_SUBDIRS_BUILD := src/*
|
||||
|
||||
@@ -51,11 +51,10 @@ LOCAL_STATIC_LIBRARIES := $(filter $(APP_AVAILABLE_STATIC_LIBS), $(COMPILED_LIBR
|
||||
|
||||
APP_STL := gnustl_static
|
||||
|
||||
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog -lz # -lgnustl_static
|
||||
LOCAL_LDLIBS := $(APPLICATION_GLES_LIBRARY) -ldl -llog -lz # -lgnustl_static
|
||||
|
||||
LOCAL_LDFLAGS := -Lobj/local/$(TARGET_ARCH_ABI)
|
||||
|
||||
|
||||
LOCAL_LDFLAGS += $(APPLICATION_ADDITIONAL_LDFLAGS)
|
||||
|
||||
LOCAL_CPP_EXTENSION := .cpp .cxx .cc
|
||||
|
||||
Submodule project/jni/application/ninslash/src updated: d50a673b56...ec8223f1e2
295
project/jni/application/test-gles3/AndroidAppSettings.cfg
Normal file
295
project/jni/application/test-gles3/AndroidAppSettings.cfg
Normal file
@@ -0,0 +1,295 @@
|
||||
# The application settings for Android libSDL port
|
||||
|
||||
# Specify application name (e.x. My Application)
|
||||
AppName="GLES3 SDL test"
|
||||
|
||||
# Specify reversed site name of application (e.x. com.mysite.myapp)
|
||||
AppFullName=gles3.sdl.test
|
||||
|
||||
# Application version code (integer)
|
||||
AppVersionCode=1
|
||||
|
||||
# Application user-visible version name (string)
|
||||
AppVersionName="1"
|
||||
|
||||
# Specify path to download application data in zip archive in the form 'Description|URL|MirrorURL^Description2|URL2|MirrorURL2^...'
|
||||
# If you'll start Description with '!' symbol it will be enabled by default, other downloads should be selected by user from startup config menu
|
||||
# If the URL in in the form ':dir/file.dat:http://URL/' it will be downloaded as binary BLOB to the application dir and not unzipped
|
||||
# If the URL does not contain 'http://' it is treated as file from 'project/jni/application/src/AndroidData' dir -
|
||||
# these files are put inside .apk package by build system
|
||||
# You can specify Google Play expansion files in the form 'obb:main.12345' or 'obb:patch.12345' where 12345 is the app version, first associated with the file
|
||||
AppDataDownloadUrl="!!Data|data.zip"
|
||||
|
||||
# Reset SDL config when updating application to the new version (y) / (n)
|
||||
ResetSdlConfigForThisVersion=n
|
||||
|
||||
# Delete application data files when upgrading (specify file/dir paths separated by spaces)
|
||||
DeleteFilesOnUpgrade="%"
|
||||
|
||||
# Here you may type readme text, which will be shown during startup. Format is:
|
||||
# Text in English, use \\\\n to separate lines (that's four backslashes)^de:Text in Deutsch^ru:Text in Russian^button:Button that will open some URL:http://url-to-open/
|
||||
ReadmeText='^text'
|
||||
|
||||
# libSDL version to use (1.2/1.3/2.0)
|
||||
LibSdlVersion=1.2
|
||||
|
||||
# Specify screen orientation: (v)ertical/(p)ortrait or (h)orizontal/(l)andscape
|
||||
ScreenOrientation=h
|
||||
|
||||
# Video color depth - 16 BPP is the fastest and supported for all modes, 24 bpp is supported only
|
||||
# with SwVideoMode=y, SDL_OPENGL mode supports everything. (16)/(24)/(32)
|
||||
VideoDepthBpp=24
|
||||
|
||||
# Enable OpenGL depth buffer (needed only for 3-d applications, small speed decrease) (y) or (n)
|
||||
NeedDepthBuffer=n
|
||||
|
||||
# Enable OpenGL stencil buffer (needed only for 3-d applications, small speed decrease) (y) or (n)
|
||||
NeedStencilBuffer=n
|
||||
|
||||
# Use GLES 2.x context
|
||||
# you need this option only if you're developing 3-d app (y) or (n)
|
||||
NeedGles2=n
|
||||
|
||||
# Use GLES 3.x context
|
||||
# you need this option only if you're developing 3-d app (y) or (n)
|
||||
NeedGles3=y
|
||||
|
||||
# Use glshim library for provide OpenGL 1.x functionality to OpenGL ES accelerated cards (y) or (n)
|
||||
UseGlshim=n
|
||||
|
||||
# Application uses software video buffer - you're calling SDL_SetVideoMode() without SDL_HWSURFACE and without SDL_OPENGL,
|
||||
# this will allow small speed optimization. Enable this even when you're using SDL_HWSURFACE. (y) or (n)
|
||||
SwVideoMode=n
|
||||
|
||||
# Application video output will be resized to fit into native device screen (y)/(n)
|
||||
SdlVideoResize=n
|
||||
|
||||
# Application resizing will keep 4:3 aspect ratio, with black bars at sides (y)/(n)
|
||||
SdlVideoResizeKeepAspect=n
|
||||
|
||||
# Do not allow device to sleep when the application is in foreground, set this for video players or apps which use accelerometer
|
||||
InhibitSuspend=y
|
||||
|
||||
# Create Android service, so the app is less likely to be killed while in background
|
||||
CreateService=n
|
||||
|
||||
# Application does not call SDL_Flip() or SDL_UpdateRects() appropriately, or draws from non-main thread -
|
||||
# enabling the compatibility mode will force screen update every 100 milliseconds, which is laggy and inefficient (y) or (n)
|
||||
CompatibilityHacksForceScreenUpdate=n
|
||||
|
||||
# Application does not call SDL_Flip() or SDL_UpdateRects() after mouse click (ScummVM and all Amiga emulators do that) -
|
||||
# force screen update by moving mouse cursor a little after each click (y) or (n)
|
||||
CompatibilityHacksForceScreenUpdateMouseClick=n
|
||||
|
||||
# Application initializes SDL audio/video inside static constructors (which is bad, you won't be able to run ndk-gdb) (y)/(n)
|
||||
CompatibilityHacksStaticInit=n
|
||||
|
||||
# On-screen Android soft text input emulates hardware keyboard, this will only work with Hackers Keyboard app (y)/(n)
|
||||
CompatibilityHacksTextInputEmulatesHwKeyboard=n
|
||||
|
||||
# Built-in text input keyboards with custom layouts for emulators, requires CompatibilityHacksTextInputEmulatesHwKeyboard=y
|
||||
# 0 or empty - standard Android keyboard
|
||||
# 1 - Simple QWERTY keyboard, no function keys, no arrow keys
|
||||
# 2 - Commodore 64 keyboard
|
||||
# 3 - Amiga keyboard
|
||||
# 4 - Atari800 keyboard
|
||||
TextInputKeyboard=0
|
||||
|
||||
# Hack for broken devices: prevent audio chopping, by sleeping a bit after pushing each audio chunk (y)/(n)
|
||||
CompatibilityHacksPreventAudioChopping=n
|
||||
|
||||
# Hack for broken apps: application ignores audio buffer size returned by SDL (y)/(n)
|
||||
CompatibilityHacksAppIgnoresAudioBufferSize=n
|
||||
|
||||
# Hack for VCMI: preload additional shared libraries before aplication start
|
||||
CompatibilityHacksAdditionalPreloadedSharedLibraries=""
|
||||
|
||||
# Hack for Free Heroes 2, which redraws the screen inside SDL_PumpEvents(): slow and compatible SDL event queue -
|
||||
# do not use it with accelerometer/gyroscope, or your app may freeze at random (y)/(n)
|
||||
CompatibilityHacksSlowCompatibleEventQueue=n
|
||||
|
||||
# Save and restore OpenGL state when drawing on-screen keyboard for apps that use SDL_OPENGL
|
||||
CompatibilityHacksTouchscreenKeyboardSaveRestoreOpenGLState=n
|
||||
|
||||
# Application uses SDL_UpdateRects() properly, and does not draw in any region outside those rects.
|
||||
# This improves drawing speed, but I know only one application that does that, and it's written by me (y)/(n)
|
||||
CompatibilityHacksProperUsageOfSDL_UpdateRects=
|
||||
|
||||
# Application uses mouse (y) or (n), this will show mouse emulation dialog to the user
|
||||
AppUsesMouse=y
|
||||
|
||||
# Application needs two-button mouse, will also enable advanced point-and-click features (y) or (n)
|
||||
AppNeedsTwoButtonMouse=n
|
||||
|
||||
# Right mouse button can do long-press/drag&drop action, necessary for some games (y) or (n)
|
||||
# If you disable it, swiping with two fingers will send mouse wheel events
|
||||
RightMouseButtonLongPress=
|
||||
|
||||
# Show SDL mouse cursor, for applications that do not draw cursor at all (y) or (n)
|
||||
ShowMouseCursor=n
|
||||
|
||||
# Screen follows mouse cursor, when it's covered by soft keyboard, this works only in software video mode (y) or (n)
|
||||
ScreenFollowsMouse=
|
||||
|
||||
# Generate more touch events, by default SDL generates one event per one video frame, this is useful for drawing apps (y) or (n)
|
||||
GenerateSubframeTouchEvents=
|
||||
|
||||
# Force relative (laptop) mouse movement mode, useful when both on-screen keyboard and mouse are needed (y) or (n)
|
||||
ForceRelativeMouseMode=n
|
||||
|
||||
# Show on-screen dpad/joystick, that will act as arrow keys (y) or (n)
|
||||
AppNeedsArrowKeys=n
|
||||
|
||||
# On-screen dpad/joystick will appear under finger when it touches the screen (y) or (n)
|
||||
# Joystick always follows finger, so moving mouse requires touching the screen with other finger
|
||||
FloatingScreenJoystick=
|
||||
|
||||
# Application needs text input (y) or (n), enables button for text input on screen
|
||||
AppNeedsTextInput=y
|
||||
|
||||
# Application uses joystick (y) or (n), the on-screen DPAD will be used as joystick 0 axes 0-1
|
||||
# This will disable AppNeedsArrowKeys option
|
||||
AppUsesJoystick=n
|
||||
|
||||
# Application uses second on-screen joystick, as SDL joystick 0 axes 2-3 (y)/(n)
|
||||
AppUsesSecondJoystick=n
|
||||
|
||||
# Application uses third on-screen joystick, as SDL joystick 0 axes 20-21 (y)/(n)
|
||||
AppUsesThirdJoystick=
|
||||
|
||||
# Application uses accelerometer (y) or (n), the accelerometer will be used as joystick 1 axes 0-1 and 5-7
|
||||
AppUsesAccelerometer=n
|
||||
|
||||
# Application uses gyroscope (y) or (n), the gyroscope will be used as joystick 1 axes 2-4
|
||||
AppUsesGyroscope=n
|
||||
|
||||
# Application uses orientation sensor (y) or (n), reported as joystick 1 axes 8-10
|
||||
AppUsesOrientationSensor=
|
||||
|
||||
# Use gyroscope to move mouse cursor (y) or (n), it eats battery, and can be disabled in settings, do not use with AppUsesGyroscope setting
|
||||
MoveMouseWithGyroscope=
|
||||
|
||||
# Application uses multitouch (y) or (n), multitouch events are passed as SDL_JOYBALLMOTION events for the joystick 0
|
||||
AppUsesMultitouch=n
|
||||
|
||||
# Application records audio (it will use any available source, such a s microphone)
|
||||
# API is defined in file SDL_android.h: int SDL_ANDROID_OpenAudioRecording(SDL_AudioSpec *spec); void SDL_ANDROID_CloseAudioRecording(void);
|
||||
# This option will add additional permission to Android manifest (y)/(n)
|
||||
AppRecordsAudio=n
|
||||
|
||||
# Application needs to access SD card. Always disable it, unless you want to access user photos and downloads. (y) / (n)
|
||||
AccessSdCard=
|
||||
|
||||
# Application needs Internet access. If you disable it, you'll have to bundle all your data files inside .apk (y) / (n)
|
||||
AccessInternet=
|
||||
|
||||
# Immersive mode - Android will hide on-screen Home/Back keys. Looks bad if you invoke Android keyboard. (y) / (n)
|
||||
ImmersiveMode=
|
||||
|
||||
# Application implements Android-specific routines to put to background, and will not draw anything to screen
|
||||
# between SDL_ACTIVEEVENT lost / gained notifications - you should check for them
|
||||
# rigth after SDL_Flip(), if (n) then SDL_Flip() will block till app in background (y) or (n)
|
||||
# This option is reported to be buggy, sometimes failing to restore video state
|
||||
NonBlockingSwapBuffers=n
|
||||
|
||||
# Redefine common hardware keys to SDL keysyms
|
||||
# BACK hardware key is available on all devices, MENU is available on pre-ICS devices, other keys may be absent
|
||||
# SEARCH and CALL by default return same keycode as DPAD_CENTER - one of those keys is available on most devices
|
||||
# Use word NO_REMAP if you want to preserve native functionality for certain key (volume keys are 3-rd and 4-th)
|
||||
# Keys: TOUCHSCREEN (works only when AppUsesMouse=n), DPAD_CENTER/SEARCH, VOLUMEUP, VOLUMEDOWN, MENU, BACK, CAMERA
|
||||
RedefinedKeys="RETURN"
|
||||
|
||||
# Number of virtual keyboard keys (currently 6 is maximum)
|
||||
AppTouchscreenKeyboardKeysAmount=0
|
||||
|
||||
# Redefine on-screen keyboard keys to SDL keysyms - 6 keyboard keys + 4 multitouch gestures (zoom in/out and rotate left/right)
|
||||
RedefinedKeysScreenKb="RETURN"
|
||||
|
||||
# Names for on-screen keyboard keys, such as Fire, Jump, Run etc, separated by spaces, they are used in SDL config menu
|
||||
RedefinedKeysScreenKbNames="RETURN"
|
||||
|
||||
# On-screen keys theme
|
||||
# 0 = Ultimate Droid by Sean Stieber (green, with cross joystick)
|
||||
# 1 = Simple Theme by Beholder (white, with cross joystick)
|
||||
# 2 = Sun by Sirea (yellow, with round joystick)
|
||||
# 3 = Keen by Gerstrong (multicolor, with round joystick)
|
||||
# 4 = Retro by Santiago Radeff (red/white, with cross joystick)
|
||||
# 5 = GameBoy from RetroArch
|
||||
# 6 = PlayStation from RetroArch
|
||||
# 7 = SuperNintendo from RetroArch
|
||||
# 8 = DualShock from RetroArch
|
||||
# 9 = Nintendo64 from RetroArch
|
||||
TouchscreenKeysTheme=2
|
||||
|
||||
# Redefine gamepad keys to SDL keysyms, button order is:
|
||||
# A B X Y L1 R1 L2 R2 LThumb RThumb
|
||||
RedefinedKeysGamepad="RETURN"
|
||||
|
||||
# How long to show startup menu button, in msec, 0 to disable startup menu
|
||||
StartupMenuButtonTimeout=0
|
||||
|
||||
# Menu items to hide from startup menu, available menu items:
|
||||
# SettingsMenu.OkButton SettingsMenu.DummyMenu SettingsMenu.MainMenu SettingsMenuMisc.DownloadConfig SettingsMenuMisc.OptionalDownloadConfig SettingsMenuMisc.AudioConfig SettingsMenuMisc.VideoSettingsConfig SettingsMenuMisc.ShowReadme SettingsMenuMisc.GyroscopeCalibration SettingsMenuMisc.CommandlineConfig SettingsMenuMisc.ResetToDefaultsConfig SettingsMenuMouse.MouseConfigMainMenu SettingsMenuMouse.DisplaySizeConfig SettingsMenuMouse.LeftClickConfig SettingsMenuMouse.RightClickConfig SettingsMenuMouse.AdditionalMouseConfig SettingsMenuMouse.JoystickMouseConfig SettingsMenuMouse.TouchPressureMeasurementTool SettingsMenuMouse.CalibrateTouchscreenMenu SettingsMenuKeyboard.KeyboardConfigMainMenu SettingsMenuKeyboard.ScreenKeyboardSizeConfig SettingsMenuKeyboard.ScreenKeyboardDrawSizeConfig SettingsMenuKeyboard.ScreenKeyboardThemeConfig SettingsMenuKeyboard.ScreenKeyboardTransparencyConfig SettingsMenuKeyboard.RemapHwKeysConfig SettingsMenuKeyboard.RemapScreenKbConfig SettingsMenuKeyboard.ScreenGesturesConfig SettingsMenuKeyboard.CustomizeScreenKbLayout SettingsMenuKeyboard.ScreenKeyboardAdvanced
|
||||
HiddenMenuOptions=''
|
||||
|
||||
# Menu items to show at startup - this is Java code snippet, leave empty for default
|
||||
# new SettingsMenuMisc.ShowReadme(), (AppUsesMouse \&\& \! ForceRelativeMouseMode \? new SettingsMenuMouse.DisplaySizeConfig(true) : new SettingsMenu.DummyMenu()), new SettingsMenuMisc.OptionalDownloadConfig(true), new SettingsMenuMisc.GyroscopeCalibration()
|
||||
# Available menu items:
|
||||
# SettingsMenu.OkButton SettingsMenu.DummyMenu SettingsMenu.MainMenu SettingsMenuMisc.DownloadConfig SettingsMenuMisc.OptionalDownloadConfig SettingsMenuMisc.AudioConfig SettingsMenuMisc.VideoSettingsConfig SettingsMenuMisc.ShowReadme SettingsMenuMisc.GyroscopeCalibration SettingsMenuMisc.CommandlineConfig SettingsMenuMisc.ResetToDefaultsConfig SettingsMenuMouse.MouseConfigMainMenu SettingsMenuMouse.DisplaySizeConfig SettingsMenuMouse.LeftClickConfig SettingsMenuMouse.RightClickConfig SettingsMenuMouse.AdditionalMouseConfig SettingsMenuMouse.JoystickMouseConfig SettingsMenuMouse.TouchPressureMeasurementTool SettingsMenuMouse.CalibrateTouchscreenMenu SettingsMenuKeyboard.KeyboardConfigMainMenu SettingsMenuKeyboard.ScreenKeyboardSizeConfig SettingsMenuKeyboard.ScreenKeyboardDrawSizeConfig SettingsMenuKeyboard.ScreenKeyboardThemeConfig SettingsMenuKeyboard.ScreenKeyboardTransparencyConfig SettingsMenuKeyboard.RemapHwKeysConfig SettingsMenuKeyboard.RemapScreenKbConfig SettingsMenuKeyboard.ScreenGesturesConfig SettingsMenuKeyboard.CustomizeScreenKbLayout SettingsMenuKeyboard.ScreenKeyboardAdvanced
|
||||
FirstStartMenuOptions=''
|
||||
|
||||
# Minimum amount of RAM application requires, in Mb, SDL will print warning to user if it's lower
|
||||
AppMinimumRAM=0
|
||||
|
||||
# GCC version, or 'clang' for CLANG
|
||||
NDK_TOOLCHAIN_VERSION=
|
||||
|
||||
# Specify architectures to compile, 'all' or 'y' to compile for all architectures.
|
||||
# Available architectures: armeabi armeabi-v7a x86 mips arm64-v8a
|
||||
MultiABI='armeabi-v7a'
|
||||
|
||||
# Optional shared libraries to compile - removing some of them will save space
|
||||
# MP3 support by libMAD is encumbered by patents and libMAD is GPL-ed
|
||||
# Available libraries: mad (GPL-ed!) sdl_mixer sdl_image sdl_ttf sdl_net sdl_blitpool sdl_gfx sdl_sound intl xml2 lua jpeg png ogg flac tremor vorbis freetype xerces curl theora fluidsynth lzma lzo2 mikmod openal timidity zzip bzip2 yaml-cpp python boost_date_time boost_filesystem boost_iostreams boost_program_options boost_regex boost_signals boost_system boost_thread glu avcodec avdevice avfilter avformat avresample avutil swscale swresample bzip2
|
||||
CompiledLibraries="sdl_image"
|
||||
|
||||
# Application uses custom build script AndroidBuild.sh instead of Android.mk (y) or (n)
|
||||
CustomBuildScript=n
|
||||
|
||||
# Aditional CFLAGS for application
|
||||
AppCflags='-O2'
|
||||
|
||||
# Aditional C++-specific compiler flags for application, added after AppCflags
|
||||
AppCppflags=''
|
||||
|
||||
# Additional LDFLAGS for application
|
||||
AppLdflags=''
|
||||
|
||||
# If application has headers with the same name as system headers, this option tries to fix compiler flags to make it compilable
|
||||
AppOverlapsSystemHeaders=
|
||||
|
||||
# Build only following subdirs (empty will build all dirs, ignored with custom script)
|
||||
AppSubdirsBuild=''
|
||||
|
||||
# Exclude these files from build
|
||||
AppBuildExclude=''
|
||||
|
||||
# Application command line parameters, including app name as 0-th param
|
||||
AppCmdline=''
|
||||
|
||||
# Screen size is used by Google Play to prevent an app to be installed on devices with smaller screens
|
||||
# Minimum screen size that application supports: (s)mall / (m)edium / (l)arge
|
||||
MinimumScreenSize=s
|
||||
|
||||
# Your AdMob Publisher ID, (n) if you don't want advertisements
|
||||
AdmobPublisherId=n
|
||||
|
||||
# Your AdMob test device ID, to receive a test ad
|
||||
AdmobTestDeviceId=
|
||||
|
||||
# Your AdMob banner size (BANNER/FULL_BANNER/LEADERBOARD/MEDIUM_RECTANGLE/SMART_BANNER/WIDE_SKYSCRAPER/FULL_WIDTH:Height/Width:AUTO_HEIGHT/Width:Height)
|
||||
AdmobBannerSize=
|
||||
|
||||
# Google Play Game Services application ID, required for cloud saves to work
|
||||
GooglePlayGameServicesId=
|
||||
|
||||
BIN
project/jni/application/test-gles3/AndroidData/data.zip
Normal file
BIN
project/jni/application/test-gles3/AndroidData/data.zip
Normal file
Binary file not shown.
4
project/jni/application/test-gles3/Makefile
Normal file
4
project/jni/application/test-gles3/Makefile
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
sdl_hello: *.cpp
|
||||
g++ -g3 -O0 -o $@ $? `sdl-config --cflags` `sdl-config --libs` -lGL -lSDL_image
|
||||
unzip -o AndroidData/*.zip
|
||||
184
project/jni/application/test-gles3/esShader.c
Normal file
184
project/jni/application/test-gles3/esShader.c
Normal file
@@ -0,0 +1,184 @@
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2013 Dan Ginsburg, Budirijanto Purnomo
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
//
|
||||
// Book: OpenGL(R) ES 3.0 Programming Guide, 2nd Edition
|
||||
// Authors: Dan Ginsburg, Budirijanto Purnomo, Dave Shreiner, Aaftab Munshi
|
||||
// ISBN-10: 0-321-93388-5
|
||||
// ISBN-13: 978-0-321-93388-1
|
||||
// Publisher: Addison-Wesley Professional
|
||||
// URLs: http://www.opengles-book.com
|
||||
// http://my.safaribooksonline.com/book/animation-and-3d/9780133440133
|
||||
//
|
||||
// ESShader.c
|
||||
//
|
||||
// Utility functions for loading shaders and creating program objects.
|
||||
//
|
||||
|
||||
///
|
||||
// Includes
|
||||
//
|
||||
#include "esUtil.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Private Functions
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Public Functions
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
///
|
||||
/// \brief Load a shader, check for compile errors, print error messages to output log
|
||||
/// \param type Type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
|
||||
/// \param shaderSrc Shader source string
|
||||
/// \return A new shader object on success, 0 on failure
|
||||
//
|
||||
GLuint ESUTIL_API esLoadShader ( GLenum type, const char *shaderSrc )
|
||||
{
|
||||
GLuint shader;
|
||||
GLint compiled;
|
||||
|
||||
// Create the shader object
|
||||
shader = glCreateShader ( type );
|
||||
|
||||
if ( shader == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Load the shader source
|
||||
glShaderSource ( shader, 1, &shaderSrc, NULL );
|
||||
|
||||
// Compile the shader
|
||||
glCompileShader ( shader );
|
||||
|
||||
// Check the compile status
|
||||
glGetShaderiv ( shader, GL_COMPILE_STATUS, &compiled );
|
||||
|
||||
if ( !compiled )
|
||||
{
|
||||
GLint infoLen = 0;
|
||||
|
||||
glGetShaderiv ( shader, GL_INFO_LOG_LENGTH, &infoLen );
|
||||
|
||||
if ( infoLen > 1 )
|
||||
{
|
||||
char *infoLog = malloc ( sizeof ( char ) * infoLen );
|
||||
|
||||
glGetShaderInfoLog ( shader, infoLen, NULL, infoLog );
|
||||
esLogMessage ( "Error compiling shader:\n%s\n", infoLog );
|
||||
|
||||
free ( infoLog );
|
||||
}
|
||||
|
||||
glDeleteShader ( shader );
|
||||
return 0;
|
||||
}
|
||||
|
||||
return shader;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
///
|
||||
/// \brief Load a vertex and fragment shader, create a program object, link program.
|
||||
// Errors output to log.
|
||||
/// \param vertShaderSrc Vertex shader source code
|
||||
/// \param fragShaderSrc Fragment shader source code
|
||||
/// \return A new program object linked with the vertex/fragment shader pair, 0 on failure
|
||||
//
|
||||
GLuint ESUTIL_API esLoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc )
|
||||
{
|
||||
GLuint vertexShader;
|
||||
GLuint fragmentShader;
|
||||
GLuint programObject;
|
||||
GLint linked;
|
||||
|
||||
// Load the vertex/fragment shaders
|
||||
vertexShader = esLoadShader ( GL_VERTEX_SHADER, vertShaderSrc );
|
||||
|
||||
if ( vertexShader == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
fragmentShader = esLoadShader ( GL_FRAGMENT_SHADER, fragShaderSrc );
|
||||
|
||||
if ( fragmentShader == 0 )
|
||||
{
|
||||
glDeleteShader ( vertexShader );
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Create the program object
|
||||
programObject = glCreateProgram ( );
|
||||
|
||||
if ( programObject == 0 )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
glAttachShader ( programObject, vertexShader );
|
||||
glAttachShader ( programObject, fragmentShader );
|
||||
|
||||
// Link the program
|
||||
glLinkProgram ( programObject );
|
||||
|
||||
// Check the link status
|
||||
glGetProgramiv ( programObject, GL_LINK_STATUS, &linked );
|
||||
|
||||
if ( !linked )
|
||||
{
|
||||
GLint infoLen = 0;
|
||||
|
||||
glGetProgramiv ( programObject, GL_INFO_LOG_LENGTH, &infoLen );
|
||||
|
||||
if ( infoLen > 1 )
|
||||
{
|
||||
char *infoLog = malloc ( sizeof ( char ) * infoLen );
|
||||
|
||||
glGetProgramInfoLog ( programObject, infoLen, NULL, infoLog );
|
||||
esLogMessage ( "Error linking program:\n%s\n", infoLog );
|
||||
|
||||
free ( infoLog );
|
||||
}
|
||||
|
||||
glDeleteProgram ( programObject );
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Free up no longer needed shader resources
|
||||
glDeleteShader ( vertexShader );
|
||||
glDeleteShader ( fragmentShader );
|
||||
|
||||
return programObject;
|
||||
}
|
||||
367
project/jni/application/test-gles3/esShapes.c
Normal file
367
project/jni/application/test-gles3/esShapes.c
Normal file
@@ -0,0 +1,367 @@
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2013 Dan Ginsburg, Budirijanto Purnomo
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
//
|
||||
// Book: OpenGL(R) ES 3.0 Programming Guide, 2nd Edition
|
||||
// Authors: Dan Ginsburg, Budirijanto Purnomo, Dave Shreiner, Aaftab Munshi
|
||||
// ISBN-10: 0-321-93388-5
|
||||
// ISBN-13: 978-0-321-93388-1
|
||||
// Publisher: Addison-Wesley Professional
|
||||
// URLs: http://www.opengles-book.com
|
||||
// http://my.safaribooksonline.com/book/animation-and-3d/9780133440133
|
||||
//
|
||||
// ESShapes.c
|
||||
//
|
||||
// Utility functions for generating shapes
|
||||
//
|
||||
|
||||
///
|
||||
// Includes
|
||||
//
|
||||
#include "esUtil.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
|
||||
///
|
||||
// Defines
|
||||
//
|
||||
#define ES_PI (3.14159265f)
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Private Functions
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Public Functions
|
||||
//
|
||||
//
|
||||
|
||||
//
|
||||
/// \brief Generates geometry for a sphere. Allocates memory for the vertex data and stores
|
||||
/// the results in the arrays. Generate index list for a TRIANGLE_STRIP
|
||||
/// \param numSlices The number of slices in the sphere
|
||||
/// \param vertices If not NULL, will contain array of float3 positions
|
||||
/// \param normals If not NULL, will contain array of float3 normals
|
||||
/// \param texCoords If not NULL, will contain array of float2 texCoords
|
||||
/// \param indices If not NULL, will contain the array of indices for the triangle strip
|
||||
/// \return The number of indices required for rendering the buffers (the number of indices stored in the indices array
|
||||
/// if it is not NULL ) as a GL_TRIANGLE_STRIP
|
||||
//
|
||||
int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals,
|
||||
GLfloat **texCoords, GLuint **indices )
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int numParallels = numSlices / 2;
|
||||
int numVertices = ( numParallels + 1 ) * ( numSlices + 1 );
|
||||
int numIndices = numParallels * numSlices * 6;
|
||||
float angleStep = ( 2.0f * ES_PI ) / ( ( float ) numSlices );
|
||||
|
||||
// Allocate memory for buffers
|
||||
if ( vertices != NULL )
|
||||
{
|
||||
*vertices = malloc ( sizeof ( GLfloat ) * 3 * numVertices );
|
||||
}
|
||||
|
||||
if ( normals != NULL )
|
||||
{
|
||||
*normals = malloc ( sizeof ( GLfloat ) * 3 * numVertices );
|
||||
}
|
||||
|
||||
if ( texCoords != NULL )
|
||||
{
|
||||
*texCoords = malloc ( sizeof ( GLfloat ) * 2 * numVertices );
|
||||
}
|
||||
|
||||
if ( indices != NULL )
|
||||
{
|
||||
*indices = malloc ( sizeof ( GLuint ) * numIndices );
|
||||
}
|
||||
|
||||
for ( i = 0; i < numParallels + 1; i++ )
|
||||
{
|
||||
for ( j = 0; j < numSlices + 1; j++ )
|
||||
{
|
||||
int vertex = ( i * ( numSlices + 1 ) + j ) * 3;
|
||||
|
||||
if ( vertices )
|
||||
{
|
||||
( *vertices ) [vertex + 0] = radius * sinf ( angleStep * ( float ) i ) *
|
||||
sinf ( angleStep * ( float ) j );
|
||||
( *vertices ) [vertex + 1] = radius * cosf ( angleStep * ( float ) i );
|
||||
( *vertices ) [vertex + 2] = radius * sinf ( angleStep * ( float ) i ) *
|
||||
cosf ( angleStep * ( float ) j );
|
||||
}
|
||||
|
||||
if ( normals )
|
||||
{
|
||||
( *normals ) [vertex + 0] = ( *vertices ) [vertex + 0] / radius;
|
||||
( *normals ) [vertex + 1] = ( *vertices ) [vertex + 1] / radius;
|
||||
( *normals ) [vertex + 2] = ( *vertices ) [vertex + 2] / radius;
|
||||
}
|
||||
|
||||
if ( texCoords )
|
||||
{
|
||||
int texIndex = ( i * ( numSlices + 1 ) + j ) * 2;
|
||||
( *texCoords ) [texIndex + 0] = ( float ) j / ( float ) numSlices;
|
||||
( *texCoords ) [texIndex + 1] = ( 1.0f - ( float ) i ) / ( float ) ( numParallels - 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the indices
|
||||
if ( indices != NULL )
|
||||
{
|
||||
GLuint *indexBuf = ( *indices );
|
||||
|
||||
for ( i = 0; i < numParallels ; i++ )
|
||||
{
|
||||
for ( j = 0; j < numSlices; j++ )
|
||||
{
|
||||
*indexBuf++ = i * ( numSlices + 1 ) + j;
|
||||
*indexBuf++ = ( i + 1 ) * ( numSlices + 1 ) + j;
|
||||
*indexBuf++ = ( i + 1 ) * ( numSlices + 1 ) + ( j + 1 );
|
||||
|
||||
*indexBuf++ = i * ( numSlices + 1 ) + j;
|
||||
*indexBuf++ = ( i + 1 ) * ( numSlices + 1 ) + ( j + 1 );
|
||||
*indexBuf++ = i * ( numSlices + 1 ) + ( j + 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return numIndices;
|
||||
}
|
||||
|
||||
//
|
||||
/// \brief Generates geometry for a cube. Allocates memory for the vertex data and stores
|
||||
/// the results in the arrays. Generate index list for a TRIANGLES
|
||||
/// \param scale The size of the cube, use 1.0 for a unit cube.
|
||||
/// \param vertices If not NULL, will contain array of float3 positions
|
||||
/// \param normals If not NULL, will contain array of float3 normals
|
||||
/// \param texCoords If not NULL, will contain array of float2 texCoords
|
||||
/// \param indices If not NULL, will contain the array of indices for the triangle strip
|
||||
/// \return The number of indices required for rendering the buffers (the number of indices stored in the indices array
|
||||
/// if it is not NULL ) as a GL_TRIANGLE_STRIP
|
||||
//
|
||||
int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals,
|
||||
GLfloat **texCoords, GLuint **indices )
|
||||
{
|
||||
int i;
|
||||
int numVertices = 24;
|
||||
int numIndices = 36;
|
||||
|
||||
GLfloat cubeVerts[] =
|
||||
{
|
||||
-0.5f, -0.5f, -0.5f,
|
||||
-0.5f, -0.5f, 0.5f,
|
||||
0.5f, -0.5f, 0.5f,
|
||||
0.5f, -0.5f, -0.5f,
|
||||
-0.5f, 0.5f, -0.5f,
|
||||
-0.5f, 0.5f, 0.5f,
|
||||
0.5f, 0.5f, 0.5f,
|
||||
0.5f, 0.5f, -0.5f,
|
||||
-0.5f, -0.5f, -0.5f,
|
||||
-0.5f, 0.5f, -0.5f,
|
||||
0.5f, 0.5f, -0.5f,
|
||||
0.5f, -0.5f, -0.5f,
|
||||
-0.5f, -0.5f, 0.5f,
|
||||
-0.5f, 0.5f, 0.5f,
|
||||
0.5f, 0.5f, 0.5f,
|
||||
0.5f, -0.5f, 0.5f,
|
||||
-0.5f, -0.5f, -0.5f,
|
||||
-0.5f, -0.5f, 0.5f,
|
||||
-0.5f, 0.5f, 0.5f,
|
||||
-0.5f, 0.5f, -0.5f,
|
||||
0.5f, -0.5f, -0.5f,
|
||||
0.5f, -0.5f, 0.5f,
|
||||
0.5f, 0.5f, 0.5f,
|
||||
0.5f, 0.5f, -0.5f,
|
||||
};
|
||||
|
||||
GLfloat cubeNormals[] =
|
||||
{
|
||||
0.0f, -1.0f, 0.0f,
|
||||
0.0f, -1.0f, 0.0f,
|
||||
0.0f, -1.0f, 0.0f,
|
||||
0.0f, -1.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f,
|
||||
0.0f, 1.0f, 0.0f,
|
||||
0.0f, 0.0f, -1.0f,
|
||||
0.0f, 0.0f, -1.0f,
|
||||
0.0f, 0.0f, -1.0f,
|
||||
0.0f, 0.0f, -1.0f,
|
||||
0.0f, 0.0f, 1.0f,
|
||||
0.0f, 0.0f, 1.0f,
|
||||
0.0f, 0.0f, 1.0f,
|
||||
0.0f, 0.0f, 1.0f,
|
||||
-1.0f, 0.0f, 0.0f,
|
||||
-1.0f, 0.0f, 0.0f,
|
||||
-1.0f, 0.0f, 0.0f,
|
||||
-1.0f, 0.0f, 0.0f,
|
||||
1.0f, 0.0f, 0.0f,
|
||||
1.0f, 0.0f, 0.0f,
|
||||
1.0f, 0.0f, 0.0f,
|
||||
1.0f, 0.0f, 0.0f,
|
||||
};
|
||||
|
||||
GLfloat cubeTex[] =
|
||||
{
|
||||
0.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
1.0f, 0.0f,
|
||||
1.0f, 1.0f,
|
||||
0.0f, 1.0f,
|
||||
0.0f, 0.0f,
|
||||
0.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
0.0f, 0.0f,
|
||||
0.0f, 1.0f,
|
||||
1.0f, 1.0f,
|
||||
1.0f, 0.0f,
|
||||
};
|
||||
|
||||
// Allocate memory for buffers
|
||||
if ( vertices != NULL )
|
||||
{
|
||||
*vertices = malloc ( sizeof ( GLfloat ) * 3 * numVertices );
|
||||
memcpy ( *vertices, cubeVerts, sizeof ( cubeVerts ) );
|
||||
|
||||
for ( i = 0; i < numVertices * 3; i++ )
|
||||
{
|
||||
( *vertices ) [i] *= scale;
|
||||
}
|
||||
}
|
||||
|
||||
if ( normals != NULL )
|
||||
{
|
||||
*normals = malloc ( sizeof ( GLfloat ) * 3 * numVertices );
|
||||
memcpy ( *normals, cubeNormals, sizeof ( cubeNormals ) );
|
||||
}
|
||||
|
||||
if ( texCoords != NULL )
|
||||
{
|
||||
*texCoords = malloc ( sizeof ( GLfloat ) * 2 * numVertices );
|
||||
memcpy ( *texCoords, cubeTex, sizeof ( cubeTex ) ) ;
|
||||
}
|
||||
|
||||
|
||||
// Generate the indices
|
||||
if ( indices != NULL )
|
||||
{
|
||||
GLuint cubeIndices[] =
|
||||
{
|
||||
0, 2, 1,
|
||||
0, 3, 2,
|
||||
4, 5, 6,
|
||||
4, 6, 7,
|
||||
8, 9, 10,
|
||||
8, 10, 11,
|
||||
12, 15, 14,
|
||||
12, 14, 13,
|
||||
16, 17, 18,
|
||||
16, 18, 19,
|
||||
20, 23, 22,
|
||||
20, 22, 21
|
||||
};
|
||||
|
||||
*indices = malloc ( sizeof ( GLuint ) * numIndices );
|
||||
memcpy ( *indices, cubeIndices, sizeof ( cubeIndices ) );
|
||||
}
|
||||
|
||||
return numIndices;
|
||||
}
|
||||
|
||||
//
|
||||
/// \brief Generates a square grid consisting of triangles. Allocates memory for the vertex data and stores
|
||||
/// the results in the arrays. Generate index list as TRIANGLES.
|
||||
/// \param size create a grid of size by size (number of triangles = (size-1)*(size-1)*2)
|
||||
/// \param vertices If not NULL, will contain array of float3 positions
|
||||
/// \param indices If not NULL, will contain the array of indices for the triangle strip
|
||||
/// \return The number of indices required for rendering the buffers (the number of indices stored in the indices array
|
||||
/// if it is not NULL ) as a GL_TRIANGLES
|
||||
//
|
||||
int ESUTIL_API esGenSquareGrid ( int size, GLfloat **vertices, GLuint **indices )
|
||||
{
|
||||
int i, j;
|
||||
int numIndices = ( size - 1 ) * ( size - 1 ) * 2 * 3;
|
||||
|
||||
// Allocate memory for buffers
|
||||
if ( vertices != NULL )
|
||||
{
|
||||
int numVertices = size * size;
|
||||
float stepSize = ( float ) size - 1;
|
||||
*vertices = malloc ( sizeof ( GLfloat ) * 3 * numVertices );
|
||||
|
||||
for ( i = 0; i < size; ++i ) // row
|
||||
{
|
||||
for ( j = 0; j < size; ++j ) // column
|
||||
{
|
||||
( *vertices ) [ 3 * ( j + i * size ) ] = i / stepSize;
|
||||
( *vertices ) [ 3 * ( j + i * size ) + 1 ] = j / stepSize;
|
||||
( *vertices ) [ 3 * ( j + i * size ) + 2 ] = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Generate the indices
|
||||
if ( indices != NULL )
|
||||
{
|
||||
*indices = malloc ( sizeof ( GLuint ) * numIndices );
|
||||
|
||||
for ( i = 0; i < size - 1; ++i )
|
||||
{
|
||||
for ( j = 0; j < size - 1; ++j )
|
||||
{
|
||||
// two triangles per quad
|
||||
( *indices ) [ 6 * ( j + i * ( size - 1 ) ) ] = j + ( i ) * ( size ) ;
|
||||
( *indices ) [ 6 * ( j + i * ( size - 1 ) ) + 1 ] = j + ( i ) * ( size ) + 1;
|
||||
( *indices ) [ 6 * ( j + i * ( size - 1 ) ) + 2 ] = j + ( i + 1 ) * ( size ) + 1;
|
||||
|
||||
( *indices ) [ 6 * ( j + i * ( size - 1 ) ) + 3 ] = j + ( i ) * ( size ) ;
|
||||
( *indices ) [ 6 * ( j + i * ( size - 1 ) ) + 4 ] = j + ( i + 1 ) * ( size ) + 1;
|
||||
( *indices ) [ 6 * ( j + i * ( size - 1 ) ) + 5 ] = j + ( i + 1 ) * ( size ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return numIndices;
|
||||
}
|
||||
314
project/jni/application/test-gles3/esTransform.c
Normal file
314
project/jni/application/test-gles3/esTransform.c
Normal file
@@ -0,0 +1,314 @@
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2013 Dan Ginsburg, Budirijanto Purnomo
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
//
|
||||
// Book: OpenGL(R) ES 3.0 Programming Guide, 2nd Edition
|
||||
// Authors: Dan Ginsburg, Budirijanto Purnomo, Dave Shreiner, Aaftab Munshi
|
||||
// ISBN-10: 0-321-93388-5
|
||||
// ISBN-13: 978-0-321-93388-1
|
||||
// Publisher: Addison-Wesley Professional
|
||||
// URLs: http://www.opengles-book.com
|
||||
// http://my.safaribooksonline.com/book/animation-and-3d/9780133440133
|
||||
//
|
||||
// ESUtil.c
|
||||
//
|
||||
// A utility library for OpenGL ES. This library provides a
|
||||
// basic common framework for the example applications in the
|
||||
// OpenGL ES 3.0 Programming Guide.
|
||||
//
|
||||
|
||||
///
|
||||
// Includes
|
||||
//
|
||||
#include "esUtil.h"
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PI 3.1415926535897932384626433832795f
|
||||
|
||||
void ESUTIL_API
|
||||
esScale ( ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz )
|
||||
{
|
||||
result->m[0][0] *= sx;
|
||||
result->m[0][1] *= sx;
|
||||
result->m[0][2] *= sx;
|
||||
result->m[0][3] *= sx;
|
||||
|
||||
result->m[1][0] *= sy;
|
||||
result->m[1][1] *= sy;
|
||||
result->m[1][2] *= sy;
|
||||
result->m[1][3] *= sy;
|
||||
|
||||
result->m[2][0] *= sz;
|
||||
result->m[2][1] *= sz;
|
||||
result->m[2][2] *= sz;
|
||||
result->m[2][3] *= sz;
|
||||
}
|
||||
|
||||
void ESUTIL_API
|
||||
esTranslate ( ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz )
|
||||
{
|
||||
result->m[3][0] += ( result->m[0][0] * tx + result->m[1][0] * ty + result->m[2][0] * tz );
|
||||
result->m[3][1] += ( result->m[0][1] * tx + result->m[1][1] * ty + result->m[2][1] * tz );
|
||||
result->m[3][2] += ( result->m[0][2] * tx + result->m[1][2] * ty + result->m[2][2] * tz );
|
||||
result->m[3][3] += ( result->m[0][3] * tx + result->m[1][3] * ty + result->m[2][3] * tz );
|
||||
}
|
||||
|
||||
void ESUTIL_API
|
||||
esRotate ( ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z )
|
||||
{
|
||||
GLfloat sinAngle, cosAngle;
|
||||
GLfloat mag = sqrtf ( x * x + y * y + z * z );
|
||||
|
||||
sinAngle = sinf ( angle * PI / 180.0f );
|
||||
cosAngle = cosf ( angle * PI / 180.0f );
|
||||
|
||||
if ( mag > 0.0f )
|
||||
{
|
||||
GLfloat xx, yy, zz, xy, yz, zx, xs, ys, zs;
|
||||
GLfloat oneMinusCos;
|
||||
ESMatrix rotMat;
|
||||
|
||||
x /= mag;
|
||||
y /= mag;
|
||||
z /= mag;
|
||||
|
||||
xx = x * x;
|
||||
yy = y * y;
|
||||
zz = z * z;
|
||||
xy = x * y;
|
||||
yz = y * z;
|
||||
zx = z * x;
|
||||
xs = x * sinAngle;
|
||||
ys = y * sinAngle;
|
||||
zs = z * sinAngle;
|
||||
oneMinusCos = 1.0f - cosAngle;
|
||||
|
||||
rotMat.m[0][0] = ( oneMinusCos * xx ) + cosAngle;
|
||||
rotMat.m[0][1] = ( oneMinusCos * xy ) - zs;
|
||||
rotMat.m[0][2] = ( oneMinusCos * zx ) + ys;
|
||||
rotMat.m[0][3] = 0.0F;
|
||||
|
||||
rotMat.m[1][0] = ( oneMinusCos * xy ) + zs;
|
||||
rotMat.m[1][1] = ( oneMinusCos * yy ) + cosAngle;
|
||||
rotMat.m[1][2] = ( oneMinusCos * yz ) - xs;
|
||||
rotMat.m[1][3] = 0.0F;
|
||||
|
||||
rotMat.m[2][0] = ( oneMinusCos * zx ) - ys;
|
||||
rotMat.m[2][1] = ( oneMinusCos * yz ) + xs;
|
||||
rotMat.m[2][2] = ( oneMinusCos * zz ) + cosAngle;
|
||||
rotMat.m[2][3] = 0.0F;
|
||||
|
||||
rotMat.m[3][0] = 0.0F;
|
||||
rotMat.m[3][1] = 0.0F;
|
||||
rotMat.m[3][2] = 0.0F;
|
||||
rotMat.m[3][3] = 1.0F;
|
||||
|
||||
esMatrixMultiply ( result, &rotMat, result );
|
||||
}
|
||||
}
|
||||
|
||||
void ESUTIL_API
|
||||
esFrustum ( ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ )
|
||||
{
|
||||
float deltaX = right - left;
|
||||
float deltaY = top - bottom;
|
||||
float deltaZ = farZ - nearZ;
|
||||
ESMatrix frust;
|
||||
|
||||
if ( ( nearZ <= 0.0f ) || ( farZ <= 0.0f ) ||
|
||||
( deltaX <= 0.0f ) || ( deltaY <= 0.0f ) || ( deltaZ <= 0.0f ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
frust.m[0][0] = 2.0f * nearZ / deltaX;
|
||||
frust.m[0][1] = frust.m[0][2] = frust.m[0][3] = 0.0f;
|
||||
|
||||
frust.m[1][1] = 2.0f * nearZ / deltaY;
|
||||
frust.m[1][0] = frust.m[1][2] = frust.m[1][3] = 0.0f;
|
||||
|
||||
frust.m[2][0] = ( right + left ) / deltaX;
|
||||
frust.m[2][1] = ( top + bottom ) / deltaY;
|
||||
frust.m[2][2] = - ( nearZ + farZ ) / deltaZ;
|
||||
frust.m[2][3] = -1.0f;
|
||||
|
||||
frust.m[3][2] = -2.0f * nearZ * farZ / deltaZ;
|
||||
frust.m[3][0] = frust.m[3][1] = frust.m[3][3] = 0.0f;
|
||||
|
||||
esMatrixMultiply ( result, &frust, result );
|
||||
}
|
||||
|
||||
|
||||
void ESUTIL_API
|
||||
esPerspective ( ESMatrix *result, float fovy, float aspect, float nearZ, float farZ )
|
||||
{
|
||||
GLfloat frustumW, frustumH;
|
||||
|
||||
frustumH = tanf ( fovy / 360.0f * PI ) * nearZ;
|
||||
frustumW = frustumH * aspect;
|
||||
|
||||
esFrustum ( result, -frustumW, frustumW, -frustumH, frustumH, nearZ, farZ );
|
||||
}
|
||||
|
||||
void ESUTIL_API
|
||||
esOrtho ( ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ )
|
||||
{
|
||||
float deltaX = right - left;
|
||||
float deltaY = top - bottom;
|
||||
float deltaZ = farZ - nearZ;
|
||||
ESMatrix ortho;
|
||||
|
||||
if ( ( deltaX == 0.0f ) || ( deltaY == 0.0f ) || ( deltaZ == 0.0f ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
esMatrixLoadIdentity ( &ortho );
|
||||
ortho.m[0][0] = 2.0f / deltaX;
|
||||
ortho.m[3][0] = - ( right + left ) / deltaX;
|
||||
ortho.m[1][1] = 2.0f / deltaY;
|
||||
ortho.m[3][1] = - ( top + bottom ) / deltaY;
|
||||
ortho.m[2][2] = -2.0f / deltaZ;
|
||||
ortho.m[3][2] = - ( nearZ + farZ ) / deltaZ;
|
||||
|
||||
esMatrixMultiply ( result, &ortho, result );
|
||||
}
|
||||
|
||||
|
||||
void ESUTIL_API
|
||||
esMatrixMultiply ( ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB )
|
||||
{
|
||||
ESMatrix tmp;
|
||||
int i;
|
||||
|
||||
for ( i = 0; i < 4; i++ )
|
||||
{
|
||||
tmp.m[i][0] = ( srcA->m[i][0] * srcB->m[0][0] ) +
|
||||
( srcA->m[i][1] * srcB->m[1][0] ) +
|
||||
( srcA->m[i][2] * srcB->m[2][0] ) +
|
||||
( srcA->m[i][3] * srcB->m[3][0] ) ;
|
||||
|
||||
tmp.m[i][1] = ( srcA->m[i][0] * srcB->m[0][1] ) +
|
||||
( srcA->m[i][1] * srcB->m[1][1] ) +
|
||||
( srcA->m[i][2] * srcB->m[2][1] ) +
|
||||
( srcA->m[i][3] * srcB->m[3][1] ) ;
|
||||
|
||||
tmp.m[i][2] = ( srcA->m[i][0] * srcB->m[0][2] ) +
|
||||
( srcA->m[i][1] * srcB->m[1][2] ) +
|
||||
( srcA->m[i][2] * srcB->m[2][2] ) +
|
||||
( srcA->m[i][3] * srcB->m[3][2] ) ;
|
||||
|
||||
tmp.m[i][3] = ( srcA->m[i][0] * srcB->m[0][3] ) +
|
||||
( srcA->m[i][1] * srcB->m[1][3] ) +
|
||||
( srcA->m[i][2] * srcB->m[2][3] ) +
|
||||
( srcA->m[i][3] * srcB->m[3][3] ) ;
|
||||
}
|
||||
|
||||
memcpy ( result, &tmp, sizeof ( ESMatrix ) );
|
||||
}
|
||||
|
||||
|
||||
void ESUTIL_API
|
||||
esMatrixLoadIdentity ( ESMatrix *result )
|
||||
{
|
||||
memset ( result, 0x0, sizeof ( ESMatrix ) );
|
||||
result->m[0][0] = 1.0f;
|
||||
result->m[1][1] = 1.0f;
|
||||
result->m[2][2] = 1.0f;
|
||||
result->m[3][3] = 1.0f;
|
||||
}
|
||||
|
||||
void ESUTIL_API
|
||||
esMatrixLookAt ( ESMatrix *result,
|
||||
float posX, float posY, float posZ,
|
||||
float lookAtX, float lookAtY, float lookAtZ,
|
||||
float upX, float upY, float upZ )
|
||||
{
|
||||
float axisX[3], axisY[3], axisZ[3];
|
||||
float length;
|
||||
|
||||
// axisZ = lookAt - pos
|
||||
axisZ[0] = lookAtX - posX;
|
||||
axisZ[1] = lookAtY - posY;
|
||||
axisZ[2] = lookAtZ - posZ;
|
||||
|
||||
// normalize axisZ
|
||||
length = sqrtf ( axisZ[0] * axisZ[0] + axisZ[1] * axisZ[1] + axisZ[2] * axisZ[2] );
|
||||
|
||||
if ( length != 0.0f )
|
||||
{
|
||||
axisZ[0] /= length;
|
||||
axisZ[1] /= length;
|
||||
axisZ[2] /= length;
|
||||
}
|
||||
|
||||
// axisX = up X axisZ
|
||||
axisX[0] = upY * axisZ[2] - upZ * axisZ[1];
|
||||
axisX[1] = upZ * axisZ[0] - upX * axisZ[2];
|
||||
axisX[2] = upX * axisZ[1] - upY * axisZ[0];
|
||||
|
||||
// normalize axisX
|
||||
length = sqrtf ( axisX[0] * axisX[0] + axisX[1] * axisX[1] + axisX[2] * axisX[2] );
|
||||
|
||||
if ( length != 0.0f )
|
||||
{
|
||||
axisX[0] /= length;
|
||||
axisX[1] /= length;
|
||||
axisX[2] /= length;
|
||||
}
|
||||
|
||||
// axisY = axisZ x axisX
|
||||
axisY[0] = axisZ[1] * axisX[2] - axisZ[2] * axisX[1];
|
||||
axisY[1] = axisZ[2] * axisX[0] - axisZ[0] * axisX[2];
|
||||
axisY[2] = axisZ[0] * axisX[1] - axisZ[1] * axisX[0];
|
||||
|
||||
// normalize axisY
|
||||
length = sqrtf ( axisY[0] * axisY[0] + axisY[1] * axisY[1] + axisY[2] * axisY[2] );
|
||||
|
||||
if ( length != 0.0f )
|
||||
{
|
||||
axisY[0] /= length;
|
||||
axisY[1] /= length;
|
||||
axisY[2] /= length;
|
||||
}
|
||||
|
||||
memset ( result, 0x0, sizeof ( ESMatrix ) );
|
||||
|
||||
result->m[0][0] = -axisX[0];
|
||||
result->m[0][1] = axisY[0];
|
||||
result->m[0][2] = -axisZ[0];
|
||||
|
||||
result->m[1][0] = -axisX[1];
|
||||
result->m[1][1] = axisY[1];
|
||||
result->m[1][2] = -axisZ[1];
|
||||
|
||||
result->m[2][0] = -axisX[2];
|
||||
result->m[2][1] = axisY[2];
|
||||
result->m[2][2] = -axisZ[2];
|
||||
|
||||
// translate (-posX, -posY, -posZ)
|
||||
result->m[3][0] = axisX[0] * posX + axisX[1] * posY + axisX[2] * posZ;
|
||||
result->m[3][1] = -axisY[0] * posX - axisY[1] * posY - axisY[2] * posZ;
|
||||
result->m[3][2] = axisZ[0] * posX + axisZ[1] * posY + axisZ[2] * posZ;
|
||||
result->m[3][3] = 1.0f;
|
||||
}
|
||||
325
project/jni/application/test-gles3/esUtil.h
Normal file
325
project/jni/application/test-gles3/esUtil.h
Normal file
@@ -0,0 +1,325 @@
|
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) 2013 Dan Ginsburg, Budirijanto Purnomo
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
//
|
||||
// Book: OpenGL(R) ES 3.0 Programming Guide, 2nd Edition
|
||||
// Authors: Dan Ginsburg, Budirijanto Purnomo, Dave Shreiner, Aaftab Munshi
|
||||
// ISBN-10: 0-321-93388-5
|
||||
// ISBN-13: 978-0-321-93388-1
|
||||
// Publisher: Addison-Wesley Professional
|
||||
// URLs: http://www.opengles-book.com
|
||||
// http://my.safaribooksonline.com/book/animation-and-3d/9780133440133
|
||||
//
|
||||
//
|
||||
/// \file ESUtil.h
|
||||
/// \brief A utility library for OpenGL ES. This library provides a
|
||||
/// basic common framework for the example applications in the
|
||||
/// OpenGL ES 3.0 Programming Guide.
|
||||
//
|
||||
#ifndef ESUTIL_H
|
||||
#define ESUTIL_H
|
||||
|
||||
///
|
||||
// Includes
|
||||
//
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <OpenGLES/ES3/gl.h>
|
||||
#else
|
||||
#include <GLES3/gl3.h>
|
||||
#include <EGL/egl.h>
|
||||
#include <EGL/eglext.h>
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
///
|
||||
// Macros
|
||||
//
|
||||
#ifdef WIN32
|
||||
#define ESUTIL_API __cdecl
|
||||
#define ESCALLBACK __cdecl
|
||||
#else
|
||||
#define ESUTIL_API
|
||||
#define ESCALLBACK
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GLfloat m[4][4];
|
||||
} ESMatrix;
|
||||
|
||||
typedef struct ESContext ESContext;
|
||||
|
||||
struct ESContext
|
||||
{
|
||||
/// Put platform specific data here
|
||||
void *platformData;
|
||||
|
||||
/// Put your user data here...
|
||||
void *userData;
|
||||
|
||||
/// Window width
|
||||
GLint width;
|
||||
|
||||
/// Window height
|
||||
GLint height;
|
||||
|
||||
#ifndef __APPLE__
|
||||
/// Display handle
|
||||
EGLNativeDisplayType eglNativeDisplay;
|
||||
|
||||
/// Window handle
|
||||
EGLNativeWindowType eglNativeWindow;
|
||||
|
||||
/// EGL display
|
||||
EGLDisplay eglDisplay;
|
||||
|
||||
/// EGL context
|
||||
EGLContext eglContext;
|
||||
|
||||
/// EGL surface
|
||||
EGLSurface eglSurface;
|
||||
#endif
|
||||
|
||||
/// Callbacks
|
||||
void ( ESCALLBACK *drawFunc ) ( ESContext * );
|
||||
void ( ESCALLBACK *shutdownFunc ) ( ESContext * );
|
||||
void ( ESCALLBACK *keyFunc ) ( ESContext *, unsigned char, int, int );
|
||||
void ( ESCALLBACK *updateFunc ) ( ESContext *, float deltaTime );
|
||||
};
|
||||
|
||||
|
||||
///
|
||||
// Public Functions
|
||||
//
|
||||
|
||||
//
|
||||
/// \brief Create a window with the specified parameters
|
||||
/// \param esContext Application context
|
||||
/// \param title Name for title bar of window
|
||||
/// \param width Width in pixels of window to create
|
||||
/// \param height Height in pixels of window to create
|
||||
/// \param flags Bitfield for the window creation flags
|
||||
/// ES_WINDOW_RGB - specifies that the color buffer should have R,G,B channels
|
||||
/// ES_WINDOW_ALPHA - specifies that the color buffer should have alpha
|
||||
/// ES_WINDOW_DEPTH - specifies that a depth buffer should be created
|
||||
/// ES_WINDOW_STENCIL - specifies that a stencil buffer should be created
|
||||
/// ES_WINDOW_MULTISAMPLE - specifies that a multi-sample buffer should be created
|
||||
/// \return GL_TRUE if window creation is succesful, GL_FALSE otherwise
|
||||
GLboolean ESUTIL_API esCreateWindow ( ESContext *esContext, const char *title, GLint width, GLint height, GLuint flags );
|
||||
|
||||
//
|
||||
/// \brief Register a draw callback function to be used to render each frame
|
||||
/// \param esContext Application context
|
||||
/// \param drawFunc Draw callback function that will be used to render the scene
|
||||
//
|
||||
void ESUTIL_API esRegisterDrawFunc ( ESContext *esContext, void ( ESCALLBACK *drawFunc ) ( ESContext * ) );
|
||||
|
||||
//
|
||||
/// \brief Register a callback function to be called on shutdown
|
||||
/// \param esContext Application context
|
||||
/// \param shutdownFunc Shutdown callback function
|
||||
//
|
||||
void ESUTIL_API esRegisterShutdownFunc ( ESContext *esContext, void ( ESCALLBACK *shutdownFunc ) ( ESContext * ) );
|
||||
|
||||
//
|
||||
/// \brief Register an update callback function to be used to update on each time step
|
||||
/// \param esContext Application context
|
||||
/// \param updateFunc Update callback function that will be used to render the scene
|
||||
//
|
||||
void ESUTIL_API esRegisterUpdateFunc ( ESContext *esContext, void ( ESCALLBACK *updateFunc ) ( ESContext *, float ) );
|
||||
|
||||
//
|
||||
/// \brief Register an keyboard input processing callback function
|
||||
/// \param esContext Application context
|
||||
/// \param keyFunc Key callback function for application processing of keyboard input
|
||||
//
|
||||
void ESUTIL_API esRegisterKeyFunc ( ESContext *esContext,
|
||||
void ( ESCALLBACK *drawFunc ) ( ESContext *, unsigned char, int, int ) );
|
||||
//
|
||||
/// \brief Log a message to the debug output for the platform
|
||||
/// \param formatStr Format string for error log.
|
||||
//
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
#define esLogMessage(...) __android_log_print(ANDROID_LOG_INFO, "Test-GLES3", __VA_ARGS__)
|
||||
#else
|
||||
void ESUTIL_API esLogMessage ( const char *formatStr, ... );
|
||||
#endif
|
||||
|
||||
//
|
||||
///
|
||||
/// \brief Load a shader, check for compile errors, print error messages to output log
|
||||
/// \param type Type of shader (GL_VERTEX_SHADER or GL_FRAGMENT_SHADER)
|
||||
/// \param shaderSrc Shader source string
|
||||
/// \return A new shader object on success, 0 on failure
|
||||
//
|
||||
GLuint ESUTIL_API esLoadShader ( GLenum type, const char *shaderSrc );
|
||||
|
||||
//
|
||||
///
|
||||
/// \brief Load a vertex and fragment shader, create a program object, link program.
|
||||
/// Errors output to log.
|
||||
/// \param vertShaderSrc Vertex shader source code
|
||||
/// \param fragShaderSrc Fragment shader source code
|
||||
/// \return A new program object linked with the vertex/fragment shader pair, 0 on failure
|
||||
//
|
||||
GLuint ESUTIL_API esLoadProgram ( const char *vertShaderSrc, const char *fragShaderSrc );
|
||||
|
||||
|
||||
//
|
||||
/// \brief Generates geometry for a sphere. Allocates memory for the vertex data and stores
|
||||
/// the results in the arrays. Generate index list for a TRIANGLE_STRIP
|
||||
/// \param numSlices The number of slices in the sphere
|
||||
/// \param vertices If not NULL, will contain array of float3 positions
|
||||
/// \param normals If not NULL, will contain array of float3 normals
|
||||
/// \param texCoords If not NULL, will contain array of float2 texCoords
|
||||
/// \param indices If not NULL, will contain the array of indices for the triangle strip
|
||||
/// \return The number of indices required for rendering the buffers (the number of indices stored in the indices array
|
||||
/// if it is not NULL ) as a GL_TRIANGLE_STRIP
|
||||
//
|
||||
int ESUTIL_API esGenSphere ( int numSlices, float radius, GLfloat **vertices, GLfloat **normals,
|
||||
GLfloat **texCoords, GLuint **indices );
|
||||
|
||||
//
|
||||
/// \brief Generates geometry for a cube. Allocates memory for the vertex data and stores
|
||||
/// the results in the arrays. Generate index list for a TRIANGLES
|
||||
/// \param scale The size of the cube, use 1.0 for a unit cube.
|
||||
/// \param vertices If not NULL, will contain array of float3 positions
|
||||
/// \param normals If not NULL, will contain array of float3 normals
|
||||
/// \param texCoords If not NULL, will contain array of float2 texCoords
|
||||
/// \param indices If not NULL, will contain the array of indices for the triangle strip
|
||||
/// \return The number of indices required for rendering the buffers (the number of indices stored in the indices array
|
||||
/// if it is not NULL ) as a GL_TRIANGLES
|
||||
//
|
||||
int ESUTIL_API esGenCube ( float scale, GLfloat **vertices, GLfloat **normals,
|
||||
GLfloat **texCoords, GLuint **indices );
|
||||
|
||||
//
|
||||
/// \brief Generates a square grid consisting of triangles. Allocates memory for the vertex data and stores
|
||||
/// the results in the arrays. Generate index list as TRIANGLES.
|
||||
/// \param size create a grid of size by size (number of triangles = (size-1)*(size-1)*2)
|
||||
/// \param vertices If not NULL, will contain array of float3 positions
|
||||
/// \param indices If not NULL, will contain the array of indices for the triangle strip
|
||||
/// \return The number of indices required for rendering the buffers (the number of indices stored in the indices array
|
||||
/// if it is not NULL ) as a GL_TRIANGLES
|
||||
//
|
||||
int ESUTIL_API esGenSquareGrid ( int size, GLfloat **vertices, GLuint **indices );
|
||||
|
||||
//
|
||||
/// \brief Loads a 8-bit, 24-bit or 32-bit TGA image from a file
|
||||
/// \param ioContext Context related to IO facility on the platform
|
||||
/// \param fileName Name of the file on disk
|
||||
/// \param width Width of loaded image in pixels
|
||||
/// \param height Height of loaded image in pixels
|
||||
/// \return Pointer to loaded image. NULL on failure.
|
||||
//
|
||||
char *ESUTIL_API esLoadTGA ( void *ioContext, const char *fileName, int *width, int *height );
|
||||
|
||||
|
||||
//
|
||||
/// \brief multiply matrix specified by result with a scaling matrix and return new matrix in result
|
||||
/// \param result Specifies the input matrix. Scaled matrix is returned in result.
|
||||
/// \param sx, sy, sz Scale factors along the x, y and z axes respectively
|
||||
//
|
||||
void ESUTIL_API esScale ( ESMatrix *result, GLfloat sx, GLfloat sy, GLfloat sz );
|
||||
|
||||
//
|
||||
/// \brief multiply matrix specified by result with a translation matrix and return new matrix in result
|
||||
/// \param result Specifies the input matrix. Translated matrix is returned in result.
|
||||
/// \param tx, ty, tz Scale factors along the x, y and z axes respectively
|
||||
//
|
||||
void ESUTIL_API esTranslate ( ESMatrix *result, GLfloat tx, GLfloat ty, GLfloat tz );
|
||||
|
||||
//
|
||||
/// \brief multiply matrix specified by result with a rotation matrix and return new matrix in result
|
||||
/// \param result Specifies the input matrix. Rotated matrix is returned in result.
|
||||
/// \param angle Specifies the angle of rotation, in degrees.
|
||||
/// \param x, y, z Specify the x, y and z coordinates of a vector, respectively
|
||||
//
|
||||
void ESUTIL_API esRotate ( ESMatrix *result, GLfloat angle, GLfloat x, GLfloat y, GLfloat z );
|
||||
|
||||
//
|
||||
// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result
|
||||
/// \param result Specifies the input matrix. new matrix is returned in result.
|
||||
/// \param left, right Coordinates for the left and right vertical clipping planes
|
||||
/// \param bottom, top Coordinates for the bottom and top horizontal clipping planes
|
||||
/// \param nearZ, farZ Distances to the near and far depth clipping planes. Both distances must be positive.
|
||||
//
|
||||
void ESUTIL_API esFrustum ( ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ );
|
||||
|
||||
//
|
||||
/// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result
|
||||
/// \param result Specifies the input matrix. new matrix is returned in result.
|
||||
/// \param fovy Field of view y angle in degrees
|
||||
/// \param aspect Aspect ratio of screen
|
||||
/// \param nearZ Near plane distance
|
||||
/// \param farZ Far plane distance
|
||||
//
|
||||
void ESUTIL_API esPerspective ( ESMatrix *result, float fovy, float aspect, float nearZ, float farZ );
|
||||
|
||||
//
|
||||
/// \brief multiply matrix specified by result with a perspective matrix and return new matrix in result
|
||||
/// \param result Specifies the input matrix. new matrix is returned in result.
|
||||
/// \param left, right Coordinates for the left and right vertical clipping planes
|
||||
/// \param bottom, top Coordinates for the bottom and top horizontal clipping planes
|
||||
/// \param nearZ, farZ Distances to the near and far depth clipping planes. These values are negative if plane is behind the viewer
|
||||
//
|
||||
void ESUTIL_API esOrtho ( ESMatrix *result, float left, float right, float bottom, float top, float nearZ, float farZ );
|
||||
|
||||
//
|
||||
/// \brief perform the following operation - result matrix = srcA matrix * srcB matrix
|
||||
/// \param result Returns multiplied matrix
|
||||
/// \param srcA, srcB Input matrices to be multiplied
|
||||
//
|
||||
void ESUTIL_API esMatrixMultiply ( ESMatrix *result, ESMatrix *srcA, ESMatrix *srcB );
|
||||
|
||||
//
|
||||
//// \brief return an indentity matrix
|
||||
//// \param result returns identity matrix
|
||||
//
|
||||
void ESUTIL_API esMatrixLoadIdentity ( ESMatrix *result );
|
||||
|
||||
//
|
||||
/// \brief Generate a transformation matrix from eye position, look at and up vectors
|
||||
/// \param result Returns transformation matrix
|
||||
/// \param posX, posY, posZ eye position
|
||||
/// \param lookAtX, lookAtY, lookAtZ look at vector
|
||||
/// \param upX, upY, upZ up vector
|
||||
//
|
||||
void ESUTIL_API
|
||||
esMatrixLookAt ( ESMatrix *result,
|
||||
float posX, float posY, float posZ,
|
||||
float lookAtX, float lookAtY, float lookAtZ,
|
||||
float upX, float upY, float upZ );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // ESUTIL_H
|
||||
BIN
project/jni/application/test-gles3/icon.png
Normal file
BIN
project/jni/application/test-gles3/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
274
project/jni/application/test-gles3/main.cpp
Normal file
274
project/jni/application/test-gles3/main.cpp
Normal file
@@ -0,0 +1,274 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <SDL.h>
|
||||
#include <SDL_image.h>
|
||||
|
||||
#include "esUtil.h"
|
||||
|
||||
#ifdef __ANDROID__
|
||||
#include <android/log.h>
|
||||
#define printf(...) __android_log_print(ANDROID_LOG_INFO, "Test-GLES3", __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
int screenWidth = 0;
|
||||
int screenHeight = 0;
|
||||
|
||||
GLuint drawTextureProgram = 0;
|
||||
GLint drawTextureSamplerLocation = 0;
|
||||
|
||||
static void initSDL()
|
||||
{
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
|
||||
SDL_EnableUNICODE(1);
|
||||
|
||||
screenWidth = SDL_GetVideoInfo()->current_w;
|
||||
screenHeight = SDL_GetVideoInfo()->current_h;
|
||||
|
||||
if ( ! SDL_SetVideoMode(screenWidth, screenHeight, 24, SDL_OPENGL|SDL_DOUBLEBUF|SDL_FULLSCREEN) )
|
||||
{
|
||||
printf("Couldn't set GL video mode: %s\n", SDL_GetError());
|
||||
SDL_Quit();
|
||||
exit(2);
|
||||
}
|
||||
SDL_WM_SetCaption("test", "test");
|
||||
}
|
||||
|
||||
void loadShaders()
|
||||
{
|
||||
char vShaderStr[] =
|
||||
"#version 300 es \n"
|
||||
"precision mediump float; \n"
|
||||
"layout(location = 0) in vec4 a_position; \n"
|
||||
"layout(location = 1) in vec2 a_texCoord; \n"
|
||||
"out vec2 v_texCoord; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" gl_Position = a_position; \n"
|
||||
" v_texCoord = a_texCoord; \n"
|
||||
"} \n";
|
||||
|
||||
char fShaderStr[] =
|
||||
"#version 300 es \n"
|
||||
"precision mediump float; \n"
|
||||
"in vec2 v_texCoord; \n"
|
||||
"layout(location = 0) out vec4 outColor; \n"
|
||||
"uniform sampler2D s_texture; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" outColor = texture( s_texture, v_texCoord ); \n"
|
||||
"} \n";
|
||||
|
||||
// Load the shaders and get a linked program object
|
||||
drawTextureProgram = esLoadProgram ( vShaderStr, fShaderStr );
|
||||
|
||||
// Get the sampler location
|
||||
drawTextureSamplerLocation = glGetUniformLocation ( drawTextureProgram, "s_texture" );
|
||||
}
|
||||
|
||||
static void initGL()
|
||||
{
|
||||
glViewport(0, 0, screenWidth, screenHeight);
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glActiveTexture ( GL_TEXTURE0 );
|
||||
|
||||
loadShaders();
|
||||
}
|
||||
|
||||
static void clearScreen()
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); // Always clear your scene before rendering, unless you're sure that you'll fill whole screen with textures/models etc
|
||||
}
|
||||
|
||||
struct Sprite {
|
||||
|
||||
Sprite(const char * path)
|
||||
{
|
||||
w = h = texture = 0;
|
||||
imagePath = path;
|
||||
loadTexture();
|
||||
}
|
||||
|
||||
bool loadTexture()
|
||||
{
|
||||
SDL_Surface *pic;
|
||||
|
||||
pic = IMG_Load(imagePath.c_str());
|
||||
|
||||
if (!pic)
|
||||
{
|
||||
printf("Error: image %s cannot be loaded\n", imagePath.c_str());
|
||||
return false;
|
||||
}
|
||||
if (pic->format->BitsPerPixel != 32 && pic->format->BitsPerPixel != 24)
|
||||
{
|
||||
printf("Error: image %s is %dbpp - it should be either 24bpp or 32bpp, images with palette are not supported\n", imagePath.c_str(), pic->format->BitsPerPixel);
|
||||
SDL_FreeSurface(pic);
|
||||
return false;
|
||||
}
|
||||
|
||||
GLenum glFormat = (pic->format->BitsPerPixel == 32 ? GL_RGBA : GL_RGB);
|
||||
w = pic->w;
|
||||
h = pic->h;
|
||||
// GLES3 always supports non-power-of-two textures, no need to recalculate texture dimensions
|
||||
|
||||
glGenTextures(1, &texture);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, glFormat, w, h, 0, glFormat, GL_UNSIGNED_BYTE, pic->pixels);
|
||||
SDL_FreeSurface(pic);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
disableRepeat();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void disableRepeat()
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
void enableRepeat()
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
}
|
||||
|
||||
void enableMirroredRepeat()
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
|
||||
}
|
||||
|
||||
void draw(GLfloat x, GLfloat y, GLfloat width, GLfloat height, GLfloat tex_x1 = 0.0f, GLfloat tex_y1 = 0.0f, GLfloat tex_x2 = 1.0f, GLfloat tex_y2 = 1.0f)
|
||||
{
|
||||
if (texture == 0)
|
||||
return;
|
||||
|
||||
glUseProgram( drawTextureProgram );
|
||||
|
||||
GLfloat coords[] = {
|
||||
x, y, // Position 0
|
||||
tex_x1, tex_y1, // TexCoord 0
|
||||
x, y + width, // Position 1
|
||||
tex_x1, tex_y2, // TexCoord 1
|
||||
x + height, y + width, // Position 2
|
||||
tex_x2, tex_y2, // TexCoord 2
|
||||
x + height, y, // Position 3
|
||||
tex_x2, tex_y1 // TexCoord 3
|
||||
};
|
||||
|
||||
// Load the vertex position
|
||||
glVertexAttribPointer( 0, 2, GL_FLOAT, GL_FALSE, 4 * sizeof ( GLfloat ), coords );
|
||||
// Load the texture coordinate
|
||||
glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof ( GLfloat ), &coords[2] );
|
||||
|
||||
glEnableVertexAttribArray( 0 );
|
||||
glEnableVertexAttribArray( 1 );
|
||||
|
||||
glActiveTexture( GL_TEXTURE0 );
|
||||
glBindTexture( GL_TEXTURE_2D, texture );
|
||||
|
||||
glUniform1i ( drawTextureSamplerLocation, 0 );
|
||||
|
||||
glDrawArrays ( GL_TRIANGLE_FAN, 0, 4 );
|
||||
}
|
||||
|
||||
void draw(GLfloat x, GLfloat y)
|
||||
{
|
||||
draw(x, y, w, h);
|
||||
}
|
||||
|
||||
GLuint texture;
|
||||
int w, h;
|
||||
std::string imagePath;
|
||||
};
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
initSDL();
|
||||
initGL();
|
||||
|
||||
std::vector<Sprite> sprites;
|
||||
sprites.push_back(Sprite("test.png"));
|
||||
sprites.push_back(Sprite("element0.png"));
|
||||
sprites.push_back(Sprite("element1.png"));
|
||||
sprites.push_back(Sprite("element2.png"));
|
||||
sprites.push_back(Sprite("element3.png"));
|
||||
sprites.push_back(Sprite("stars.jpg"));
|
||||
sprites.back().enableMirroredRepeat(); // Looks nice
|
||||
|
||||
int coords[][2] = { {0, 0},
|
||||
{200, 0},
|
||||
{300, 200},
|
||||
{400, 300} };
|
||||
|
||||
float pulse = 1.0f, pulseChange = 0.01f;
|
||||
int anim = 1;
|
||||
|
||||
while ( ! SDL_GetKeyState(NULL)[SDLK_ESCAPE] ) // Exit by pressing Back button
|
||||
{
|
||||
// clearScreen(); // Do not clear screen, we will fill the screens with tiled background image instead
|
||||
sprites[5].draw(0, 0, screenWidth, screenHeight, 0, 0, (float) screenWidth / sprites[5].w, (float) screenHeight / sprites[5].h);
|
||||
|
||||
int mouseX = 0, mouseY = 0, buttons = 0;
|
||||
buttons = SDL_GetMouseState(&mouseX, &mouseY);
|
||||
sprites[0].draw(mouseX - sprites[0].w/2, mouseY - sprites[0].h/2);
|
||||
|
||||
sprites[1].draw(coords[0][0], coords[0][1]);
|
||||
sprites[2].draw(coords[1][0], coords[1][1], sprites[2].w * pulse * 4, sprites[2].h * pulse * 4);
|
||||
sprites[3].draw(coords[2][0], coords[2][1], sprites[3].w * pulse * 4, sprites[3].h * 2);
|
||||
sprites[4].draw(coords[3][0], coords[3][1], sprites[4].w, sprites[4].h * pulse * 2);
|
||||
|
||||
SDL_GL_SwapBuffers();
|
||||
SDL_Event event;
|
||||
while( SDL_PollEvent(&event) )
|
||||
{
|
||||
if(event.type == SDL_VIDEORESIZE)
|
||||
{
|
||||
// GL context was destroyed - reload all textures
|
||||
initGL();
|
||||
for(int i = 0; i < sprites.size(); i++)
|
||||
sprites[i].loadTexture();
|
||||
}
|
||||
|
||||
if(event.type == SDL_KEYUP || event.type == SDL_KEYDOWN)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_INFO, "Hello", "SDL key event: evt %s state %s key %4d %12s scancode %4d mod %2d unicode %d", event.type == SDL_KEYUP ? "UP " : "DOWN" , event.key.state == SDL_PRESSED ? "PRESSED " : "RELEASED", (int)event.key.keysym.sym, SDL_GetKeyName(event.key.keysym.sym), (int)event.key.keysym.scancode, (int)event.key.keysym.mod, (int)event.key.keysym.unicode);
|
||||
if(event.key.keysym.sym == SDLK_ESCAPE)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Some kinda animation
|
||||
|
||||
pulse += pulseChange;
|
||||
if(pulse >= 1.0f)
|
||||
pulseChange = -0.01f;
|
||||
if(pulse <= 0)
|
||||
pulseChange = 0.01f;
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
coords[i][0] += anim;
|
||||
coords[i][1] += anim;
|
||||
}
|
||||
if( coords[0][0] < 0 )
|
||||
anim = 1;
|
||||
if( coords[3][1] > screenHeight )
|
||||
anim = -1;
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
return 0;
|
||||
}
|
||||
@@ -185,53 +185,54 @@ main(int argc, char *argv[])
|
||||
|
||||
while ( ! SDL_GetKeyState(NULL)[SDLK_ESCAPE] ) // Exit by pressing Back button
|
||||
{
|
||||
clearScreen();
|
||||
int mouseX = 0, mouseY = 0, buttons = 0;
|
||||
buttons = SDL_GetMouseState(&mouseX, &mouseY);
|
||||
clearScreen();
|
||||
int mouseX = 0, mouseY = 0, buttons = 0;
|
||||
buttons = SDL_GetMouseState(&mouseX, &mouseY);
|
||||
|
||||
sprites[0].draw(mouseX - sprites[0].w/2, mouseY - sprites[0].h/2, sprites[0].w, sprites[0].h, buttons ? 0 : 1, 1, 1, pulse);
|
||||
sprites[1].draw(coords[0][0], coords[0][1]);
|
||||
sprites[2].draw(coords[1][0], coords[1][1], sprites[2].w * pulse * 4, sprites[2].h * pulse * 4);
|
||||
sprites[3].draw(coords[2][0], coords[2][1], sprites[3].w * pulse * 4, sprites[3].h * 2);
|
||||
sprites[4].draw(coords[3][0], coords[3][1], sprites[4].w, sprites[4].h * pulse * 2);
|
||||
sprites[2].draw(coords[1][0] + 300, coords[1][1] + sprites[2].h * pulse * 3, sprites[2].w * 3, sprites[2].h * 3, pulse, pulse, 1.0f - pulse );
|
||||
|
||||
sprites[1].draw(coords[0][0], coords[0][1]);
|
||||
sprites[2].draw(coords[1][0], coords[1][1], sprites[2].w * pulse * 4, sprites[2].h * pulse * 4);
|
||||
sprites[3].draw(coords[2][0], coords[2][1], sprites[3].w * pulse * 4, sprites[3].h * 2);
|
||||
sprites[4].draw(coords[3][0], coords[3][1], sprites[4].w, sprites[4].h * pulse * 2);
|
||||
sprites[0].draw(mouseX - sprites[0].w/2, mouseY - sprites[0].h/2, sprites[0].w, sprites[0].h, buttons ? 0 : 1, 1, 1, pulse);
|
||||
|
||||
SDL_GL_SwapBuffers();
|
||||
SDL_Event event;
|
||||
while( SDL_PollEvent(&event) )
|
||||
{
|
||||
if(event.type == SDL_VIDEORESIZE)
|
||||
SDL_GL_SwapBuffers();
|
||||
SDL_Event event;
|
||||
while( SDL_PollEvent(&event) )
|
||||
{
|
||||
// Reload textures to OpenGL
|
||||
initGL();
|
||||
for(int i = 0; i < sprites.size(); i++)
|
||||
sprites[i].loadTexture();
|
||||
if(event.type == SDL_VIDEORESIZE)
|
||||
{
|
||||
// Reload textures to OpenGL
|
||||
initGL();
|
||||
for(int i = 0; i < sprites.size(); i++)
|
||||
sprites[i].loadTexture();
|
||||
}
|
||||
if(event.type == SDL_KEYUP || event.type == SDL_KEYDOWN)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_INFO, "Hello", "SDL key event: evt %s state %s key %4d %12s scancode %4d mod %2d unicode %d", event.type == SDL_KEYUP ? "UP " : "DOWN" , event.key.state == SDL_PRESSED ? "PRESSED " : "RELEASED", (int)event.key.keysym.sym, SDL_GetKeyName(event.key.keysym.sym), (int)event.key.keysym.scancode, (int)event.key.keysym.mod, (int)event.key.keysym.unicode);
|
||||
if(event.key.keysym.sym == SDLK_ESCAPE)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if(event.type == SDL_KEYUP || event.type == SDL_KEYDOWN)
|
||||
|
||||
// Some kinda animation
|
||||
|
||||
pulse += pulseChange;
|
||||
if(pulse > 1.0f)
|
||||
pulseChange = -0.01f;
|
||||
if(pulse < 0)
|
||||
pulseChange = 0.01f;
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_INFO, "Hello", "SDL key event: evt %s state %s key %4d %12s scancode %4d mod %2d unicode %d", event.type == SDL_KEYUP ? "UP " : "DOWN" , event.key.state == SDL_PRESSED ? "PRESSED " : "RELEASED", (int)event.key.keysym.sym, SDL_GetKeyName(event.key.keysym.sym), (int)event.key.keysym.scancode, (int)event.key.keysym.mod, (int)event.key.keysym.unicode);
|
||||
if(event.key.keysym.sym == SDLK_ESCAPE)
|
||||
return 0;
|
||||
coords[i][0] += anim;
|
||||
coords[i][1] += anim;
|
||||
}
|
||||
}
|
||||
|
||||
// Some kinda animation
|
||||
|
||||
pulse += pulseChange;
|
||||
if(pulse > 1.0f)
|
||||
pulseChange = -0.01f;
|
||||
if(pulse < 0)
|
||||
pulseChange = 0.01f;
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
coords[i][0] += anim;
|
||||
coords[i][1] += anim;
|
||||
}
|
||||
if( coords[0][0] < 0 )
|
||||
anim = 1;
|
||||
if( coords[3][1] > screenHeight )
|
||||
anim = -1;
|
||||
if( coords[0][0] < 0 )
|
||||
anim = 1;
|
||||
if( coords[3][1] > screenHeight )
|
||||
anim = -1;
|
||||
}
|
||||
|
||||
SDL_Quit();
|
||||
|
||||
@@ -57,10 +57,10 @@ LOCAL_SRC_FILES := $(foreach F, $(SDL_SRCS), $(addprefix $(dir $(F)),$(notdir $(
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := sdl_native_helpers # Not really a dependency, needed for CustomBuildScript
|
||||
|
||||
ifdef USE_GLSHIM
|
||||
ifdef USE_GLSHIM
|
||||
LOCAL_STATIC_LIBRARIES := glshim
|
||||
endif
|
||||
|
||||
LOCAL_LDLIBS := -lGLESv1_CM -ldl -llog
|
||||
LOCAL_LDLIBS := $(APPLICATION_GLES_LIBRARY) -ldl -llog
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
@@ -43,8 +43,6 @@ If you compile this code with SDL 1.3 or newer, or use in some other way, the li
|
||||
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES/glext.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
@@ -61,6 +59,8 @@ If you compile this code with SDL 1.3 or newer, or use in some other way, the li
|
||||
#define DEBUGOUT(...)
|
||||
#endif
|
||||
|
||||
#include "SDL_opengles.h"
|
||||
|
||||
#ifdef USE_GLSHIM
|
||||
#include <GL/gl.h>
|
||||
#endif
|
||||
@@ -493,8 +493,10 @@ SDL_Surface *ANDROID_SetVideoMode(_THIS, SDL_Surface *current,
|
||||
HwSurfaceList[HwSurfaceCount-1] = current;
|
||||
DEBUGOUT("ANDROID_SetVideoMode() HwSurfaceCount %d HwSurfaceList %p", HwSurfaceCount, HwSurfaceList);
|
||||
}
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
glViewport(0, 0, SDL_ANDROID_sRealWindowWidth, SDL_ANDROID_sRealWindowHeight);
|
||||
glOrthof(0, SDL_ANDROID_sRealWindowWidth, SDL_ANDROID_sRealWindowHeight, 0, 0, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Allocate the new pixel format for the screen */
|
||||
@@ -1038,6 +1040,7 @@ static void ANDROID_FlipHWSurfaceInternal(int numrects, SDL_Rect *rects)
|
||||
SDL_RenderCopy((struct SDL_Texture *)SDL_CurrentVideoSurface->hwdata, &rect, &dstrect);
|
||||
int buttons = SDL_GetMouseState(NULL, NULL);
|
||||
// Do it old-fashioned way with direct GL calls
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrthof( 0.0f, SDL_ANDROID_sFakeWindowWidth, SDL_ANDROID_sFakeWindowHeight, 0.0f, 0.0f, 1.0f );
|
||||
@@ -1051,6 +1054,7 @@ static void ANDROID_FlipHWSurfaceInternal(int numrects, SDL_Rect *rects)
|
||||
glDrawArrays(GL_LINE_LOOP, 0, 4);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glPopMatrix();
|
||||
#endif
|
||||
}
|
||||
#ifdef VIDEO_DEBUG
|
||||
if( SDL_ANDROID_VideoDebugRect.w > 0 )
|
||||
@@ -1206,8 +1210,10 @@ void SDL_ANDROID_VideoContextRecreated()
|
||||
SDL_PrivateAndroidSetDesktopMode(SDL_VideoWindow, SDL_ANDROID_sRealWindowWidth, SDL_ANDROID_sRealWindowHeight);
|
||||
SDL_SelectRenderer(SDL_VideoWindow); // Re-apply glOrtho() and blend modes
|
||||
// Re-apply our custom 4:3 screen aspect ratio
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
glViewport(0, 0, SDL_ANDROID_sRealWindowWidth, SDL_ANDROID_sRealWindowHeight);
|
||||
glOrthof(0, SDL_ANDROID_sRealWindowWidth, SDL_ANDROID_sWindowHeight, 0, 0, 1);
|
||||
#endif
|
||||
for( i = 0; i < HwSurfaceCount; i++ )
|
||||
{
|
||||
// Allocate HW texture
|
||||
|
||||
@@ -27,14 +27,14 @@ If you compile this code with SDL 1.3 or newer, or use in some other way, the li
|
||||
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES/glext.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <string.h> // for memset()
|
||||
|
||||
#include "SDL_opengles.h"
|
||||
|
||||
#include "SDL_config.h"
|
||||
#include "SDL_version.h"
|
||||
|
||||
@@ -124,7 +124,7 @@ static inline JNIEnv *GetJavaEnv(void)
|
||||
{
|
||||
JavaVM *vm = SDL_ANDROID_JavaVM();
|
||||
JNIEnv *ret = NULL;
|
||||
(*vm)->GetEnv(vm, &ret, JNI_VERSION_1_6);
|
||||
(*vm)->GetEnv(vm, (void **) &ret, JNI_VERSION_1_6);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@ int SDL_ANDROID_CallJavaSwapBuffers()
|
||||
if( !glContextLost )
|
||||
{
|
||||
// Clear part of screen not used by SDL - on Android the screen contains garbage after each frame
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
if( SDL_ANDROID_ForceClearScreenRectAmount > 0 )
|
||||
{
|
||||
int i;
|
||||
@@ -157,7 +158,7 @@ int SDL_ANDROID_CallJavaSwapBuffers()
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
#endif
|
||||
SDL_ANDROID_drawTouchscreenKeyboard();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,229 +0,0 @@
|
||||
/* list of OpenGL ES functions sorted alphabetically
|
||||
If you need to use a GLES function from the SDL video subsystem,
|
||||
change it's entry from SDL_PROC_UNUSED to SDL_PROC and rebuild.
|
||||
*/
|
||||
#define SDL_PROC_UNUSED(ret,func,params)
|
||||
|
||||
SDL_PROC_UNUSED(void, glAlphaFunc, (GLenum func, GLclampf ref))
|
||||
SDL_PROC(void, glClearColor,
|
||||
(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha))
|
||||
SDL_PROC_UNUSED(void, glClearDepthf, (GLclampf depth))
|
||||
SDL_PROC_UNUSED(void, glClipPlanef, (GLenum plane, const GLfloat * equation))
|
||||
SDL_PROC(void, glColor4f,
|
||||
(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha))
|
||||
SDL_PROC_UNUSED(void, glDepthRangef, (GLclampf zNear, GLclampf zFar))
|
||||
SDL_PROC_UNUSED(void, glFogf, (GLenum pname, GLfloat param))
|
||||
SDL_PROC_UNUSED(void, glFogfv, (GLenum pname, const GLfloat * params))
|
||||
SDL_PROC_UNUSED(void, glFrustumf,
|
||||
(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top,
|
||||
GLfloat zNear, GLfloat zFar))
|
||||
SDL_PROC_UNUSED(void, glGetClipPlanef, (GLenum pname, GLfloat eqn[4]))
|
||||
SDL_PROC(void, glGetFloatv, (GLenum pname, GLfloat * params))
|
||||
SDL_PROC_UNUSED(void, glGetLightfv,
|
||||
(GLenum light, GLenum pname, GLfloat * params))
|
||||
SDL_PROC_UNUSED(void, glGetMaterialfv,
|
||||
(GLenum face, GLenum pname, GLfloat * params))
|
||||
SDL_PROC_UNUSED(void, glGetTexEnvfv,
|
||||
(GLenum env, GLenum pname, GLfloat * params))
|
||||
SDL_PROC_UNUSED(void, glGetTexParameterfv,
|
||||
(GLenum target, GLenum pname, GLfloat * params))
|
||||
SDL_PROC_UNUSED(void, glLightModelf, (GLenum pname, GLfloat param))
|
||||
SDL_PROC_UNUSED(void, glLightModelfv, (GLenum pname, const GLfloat * params))
|
||||
SDL_PROC_UNUSED(void, glLightf, (GLenum light, GLenum pname, GLfloat param))
|
||||
SDL_PROC_UNUSED(void, glLightfv,
|
||||
(GLenum light, GLenum pname, const GLfloat * params))
|
||||
SDL_PROC_UNUSED(void, glLineWidth, (GLfloat width))
|
||||
SDL_PROC_UNUSED(void, glLoadMatrixf, (const GLfloat * m))
|
||||
SDL_PROC_UNUSED(void, glMaterialf, (GLenum face, GLenum pname, GLfloat param))
|
||||
SDL_PROC_UNUSED(void, glMaterialfv,
|
||||
(GLenum face, GLenum pname, const GLfloat * params))
|
||||
SDL_PROC_UNUSED(void, glMultMatrixf, (const GLfloat * m))
|
||||
SDL_PROC_UNUSED(void, glMultiTexCoord4f,
|
||||
(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q))
|
||||
SDL_PROC_UNUSED(void, glNormal3f, (GLfloat nx, GLfloat ny, GLfloat nz))
|
||||
SDL_PROC(void, glOrthof,
|
||||
(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top,
|
||||
GLfloat zNear, GLfloat zFar))
|
||||
SDL_PROC_UNUSED(void, glPointParameterf, (GLenum pname, GLfloat param))
|
||||
SDL_PROC_UNUSED(void, glPointParameterfv,
|
||||
(GLenum pname, const GLfloat * params))
|
||||
SDL_PROC_UNUSED(void, glPointSize, (GLfloat size))
|
||||
SDL_PROC_UNUSED(void, glPolygonOffset, (GLfloat factor, GLfloat units))
|
||||
SDL_PROC_UNUSED(void, glRotatef,
|
||||
(GLfloat angle, GLfloat x, GLfloat y, GLfloat z))
|
||||
SDL_PROC_UNUSED(void, glScalef, (GLfloat x, GLfloat y, GLfloat z))
|
||||
SDL_PROC(void, glTexEnvf, (GLenum target, GLenum pname, GLfloat param))
|
||||
SDL_PROC_UNUSED(void, glTexEnvfv,
|
||||
(GLenum target, GLenum pname, const GLfloat * params))
|
||||
SDL_PROC(void, glTexParameterf, (GLenum target, GLenum pname, GLfloat param))
|
||||
SDL_PROC_UNUSED(void, glTexParameterfv,
|
||||
(GLenum target, GLenum pname, const GLfloat * params))
|
||||
SDL_PROC_UNUSED(void, glTranslatef, (GLfloat x, GLfloat y, GLfloat z))
|
||||
|
||||
/* Available in both Common and Common-Lite profiles */
|
||||
SDL_PROC_UNUSED(void, glActiveTexture, (GLenum texture))
|
||||
SDL_PROC_UNUSED(void, glAlphaFuncx, (GLenum func, GLclampx ref))
|
||||
SDL_PROC_UNUSED(void, glBindBuffer, (GLenum target, GLuint buffer))
|
||||
SDL_PROC(void, glBindTexture, (GLenum target, GLuint texture))
|
||||
SDL_PROC(void, glBlendFunc, (GLenum sfactor, GLenum dfactor))
|
||||
SDL_PROC_UNUSED(void, glBufferData,
|
||||
(GLenum target, GLsizeiptr size, const GLvoid * data,
|
||||
GLenum usage))
|
||||
SDL_PROC_UNUSED(void, glBufferSubData,
|
||||
(GLenum target, GLintptr offset, GLsizeiptr size,
|
||||
const GLvoid * data))
|
||||
SDL_PROC(void, glClear, (GLbitfield mask))
|
||||
SDL_PROC_UNUSED(void, glClearColorx,
|
||||
(GLclampx red, GLclampx green, GLclampx blue, GLclampx alpha))
|
||||
SDL_PROC_UNUSED(void, glClearDepthx, (GLclampx depth))
|
||||
SDL_PROC_UNUSED(void, glClearStencil, (GLint s))
|
||||
SDL_PROC_UNUSED(void, glClientActiveTexture, (GLenum texture))
|
||||
SDL_PROC_UNUSED(void, glClipPlanex, (GLenum plane, const GLfixed * equation))
|
||||
SDL_PROC_UNUSED(void, glColor4ub,
|
||||
(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha))
|
||||
SDL_PROC_UNUSED(void, glColor4x,
|
||||
(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha))
|
||||
SDL_PROC_UNUSED(void, glColorMask,
|
||||
(GLboolean red, GLboolean green, GLboolean blue,
|
||||
GLboolean alpha))
|
||||
SDL_PROC(void, glColorPointer,
|
||||
(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer))
|
||||
SDL_PROC_UNUSED(void, glCompressedTexImage2D,
|
||||
(GLenum target, GLint level, GLenum internalformat,
|
||||
GLsizei width, GLsizei height, GLint border,
|
||||
GLsizei imageSize, const GLvoid * data))
|
||||
SDL_PROC_UNUSED(void, glCompressedTexSubImage2D,
|
||||
(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
||||
GLsizei width, GLsizei height, GLenum format,
|
||||
GLsizei imageSize, const GLvoid * data))
|
||||
SDL_PROC_UNUSED(void, glCopyTexImage2D,
|
||||
(GLenum target, GLint level, GLenum internalformat, GLint x,
|
||||
GLint y, GLsizei width, GLsizei height, GLint border))
|
||||
SDL_PROC_UNUSED(void, glCopyTexSubImage2D,
|
||||
(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
||||
GLint x, GLint y, GLsizei width, GLsizei height))
|
||||
SDL_PROC_UNUSED(void, glCullFace, (GLenum mode))
|
||||
SDL_PROC_UNUSED(void, glDeleteBuffers, (GLsizei n, const GLuint * buffers))
|
||||
SDL_PROC_UNUSED(void, glDeleteTextures, (GLsizei n, const GLuint * textures))
|
||||
SDL_PROC_UNUSED(void, glDepthFunc, (GLenum func))
|
||||
SDL_PROC_UNUSED(void, glDepthMask, (GLboolean flag))
|
||||
SDL_PROC_UNUSED(void, glDepthRangex, (GLclampx zNear, GLclampx zFar))
|
||||
SDL_PROC(void, glDisable, (GLenum cap))
|
||||
SDL_PROC(void, glDisableClientState, (GLenum array))
|
||||
SDL_PROC(void, glDrawArrays, (GLenum mode, GLint first, GLsizei count))
|
||||
SDL_PROC_UNUSED(void, glDrawElements,
|
||||
(GLenum mode, GLsizei count, GLenum type,
|
||||
const GLvoid * indices))
|
||||
SDL_PROC(void, glEnable, (GLenum cap))
|
||||
SDL_PROC(void, glEnableClientState, (GLenum array))
|
||||
SDL_PROC_UNUSED(void, glFinish, (void))
|
||||
SDL_PROC_UNUSED(void, glFlush, (void))
|
||||
SDL_PROC_UNUSED(void, glFogx, (GLenum pname, GLfixed param))
|
||||
SDL_PROC_UNUSED(void, glFogxv, (GLenum pname, const GLfixed * params))
|
||||
SDL_PROC_UNUSED(void, glFrontFace, (GLenum mode))
|
||||
SDL_PROC_UNUSED(void, glFrustumx,
|
||||
(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top,
|
||||
GLfixed zNear, GLfixed zFar))
|
||||
SDL_PROC_UNUSED(void, glGetBooleanv, (GLenum pname, GLboolean * params))
|
||||
SDL_PROC_UNUSED(void, glGetBufferParameteriv,
|
||||
(GLenum target, GLenum pname, GLint * params))
|
||||
SDL_PROC_UNUSED(void, glGetClipPlanex, (GLenum pname, GLfixed eqn[4]))
|
||||
SDL_PROC_UNUSED(void, glGenBuffers, (GLsizei n, GLuint * buffers))
|
||||
SDL_PROC(void, glGenTextures, (GLsizei n, GLuint * textures))
|
||||
SDL_PROC(GLenum, glGetError, (void))
|
||||
SDL_PROC_UNUSED(void, glGetFixedv, (GLenum pname, GLfixed * params))
|
||||
SDL_PROC(void, glGetIntegerv, (GLenum pname, GLint * params))
|
||||
SDL_PROC_UNUSED(void, glGetLightxv,
|
||||
(GLenum light, GLenum pname, GLfixed * params))
|
||||
SDL_PROC_UNUSED(void, glGetMaterialxv,
|
||||
(GLenum face, GLenum pname, GLfixed * params))
|
||||
SDL_PROC_UNUSED(void, glGetPointerv, (GLenum pname, void **params))
|
||||
SDL_PROC_UNUSED(const GLubyte *, glGetString, (GLenum name))
|
||||
SDL_PROC_UNUSED(void, glGetTexEnviv,
|
||||
(GLenum env, GLenum pname, GLint * params))
|
||||
SDL_PROC_UNUSED(void, glGetTexEnvxv,
|
||||
(GLenum env, GLenum pname, GLfixed * params))
|
||||
SDL_PROC_UNUSED(void, glGetTexParameteriv,
|
||||
(GLenum target, GLenum pname, GLint * params))
|
||||
SDL_PROC_UNUSED(void, glGetTexParameterxv,
|
||||
(GLenum target, GLenum pname, GLfixed * params))
|
||||
SDL_PROC_UNUSED(void, glHint, (GLenum target, GLenum mode))
|
||||
SDL_PROC_UNUSED(GLboolean, glIsBuffer, (GLuint buffer))
|
||||
SDL_PROC_UNUSED(GLboolean, glIsEnabled, (GLenum cap))
|
||||
SDL_PROC_UNUSED(GLboolean, glIsTexture, (GLuint texture))
|
||||
SDL_PROC_UNUSED(void, glLightModelx, (GLenum pname, GLfixed param))
|
||||
SDL_PROC_UNUSED(void, glLightModelxv, (GLenum pname, const GLfixed * params))
|
||||
SDL_PROC_UNUSED(void, glLightx, (GLenum light, GLenum pname, GLfixed param))
|
||||
SDL_PROC_UNUSED(void, glLightxv,
|
||||
(GLenum light, GLenum pname, const GLfixed * params))
|
||||
SDL_PROC_UNUSED(void, glLineWidthx, (GLfixed width))
|
||||
SDL_PROC(void, glLoadIdentity, (void))
|
||||
SDL_PROC_UNUSED(void, glLoadMatrixx, (const GLfixed * m))
|
||||
SDL_PROC_UNUSED(void, glLogicOp, (GLenum opcode))
|
||||
SDL_PROC_UNUSED(void, glMaterialx, (GLenum face, GLenum pname, GLfixed param))
|
||||
SDL_PROC_UNUSED(void, glMaterialxv,
|
||||
(GLenum face, GLenum pname, const GLfixed * params))
|
||||
SDL_PROC(void, glMatrixMode, (GLenum mode))
|
||||
SDL_PROC_UNUSED(void, glMultMatrixx, (const GLfixed * m))
|
||||
SDL_PROC_UNUSED(void, glMultiTexCoord4x,
|
||||
(GLenum target, GLfixed s, GLfixed t, GLfixed r, GLfixed q))
|
||||
SDL_PROC_UNUSED(void, glNormal3x, (GLfixed nx, GLfixed ny, GLfixed nz))
|
||||
SDL_PROC_UNUSED(void, glNormalPointer,
|
||||
(GLenum type, GLsizei stride, const GLvoid * pointer))
|
||||
SDL_PROC_UNUSED(void, glOrthox,
|
||||
(GLfixed left, GLfixed right, GLfixed bottom, GLfixed top,
|
||||
GLfixed zNear, GLfixed zFar))
|
||||
SDL_PROC(void, glPixelStorei, (GLenum pname, GLint param))
|
||||
SDL_PROC_UNUSED(void, glPointParameterx, (GLenum pname, GLfixed param))
|
||||
SDL_PROC_UNUSED(void, glPointParameterxv,
|
||||
(GLenum pname, const GLfixed * params))
|
||||
SDL_PROC_UNUSED(void, glPointSizex, (GLfixed size))
|
||||
SDL_PROC_UNUSED(void, glPolygonOffsetx, (GLfixed factor, GLfixed units))
|
||||
SDL_PROC_UNUSED(void, glPopMatrix, (void))
|
||||
SDL_PROC_UNUSED(void, glPushMatrix, (void))
|
||||
SDL_PROC_UNUSED(void, glReadPixels,
|
||||
(GLint x, GLint y, GLsizei width, GLsizei height,
|
||||
GLenum format, GLenum type, GLvoid * pixels))
|
||||
SDL_PROC_UNUSED(void, glRotatex,
|
||||
(GLfixed angle, GLfixed x, GLfixed y, GLfixed z))
|
||||
SDL_PROC_UNUSED(void, glSampleCoverage, (GLclampf value, GLboolean invert))
|
||||
SDL_PROC_UNUSED(void, glSampleCoveragex, (GLclampx value, GLboolean invert))
|
||||
SDL_PROC_UNUSED(void, glScalex, (GLfixed x, GLfixed y, GLfixed z))
|
||||
SDL_PROC(void, glScissor, (GLint x, GLint y, GLsizei width, GLsizei height))
|
||||
SDL_PROC_UNUSED(void, glShadeModel, (GLenum mode))
|
||||
SDL_PROC_UNUSED(void, glStencilFunc, (GLenum func, GLint ref, GLuint mask))
|
||||
SDL_PROC_UNUSED(void, glStencilMask, (GLuint mask))
|
||||
SDL_PROC_UNUSED(void, glStencilOp, (GLenum fail, GLenum zfail, GLenum zpass))
|
||||
SDL_PROC(void, glTexCoordPointer,
|
||||
(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer))
|
||||
SDL_PROC_UNUSED(void, glTexEnvi, (GLenum target, GLenum pname, GLint param))
|
||||
SDL_PROC_UNUSED(void, glTexEnvx, (GLenum target, GLenum pname, GLfixed param))
|
||||
SDL_PROC_UNUSED(void, glTexEnviv,
|
||||
(GLenum target, GLenum pname, const GLint * params))
|
||||
SDL_PROC_UNUSED(void, glTexEnvxv,
|
||||
(GLenum target, GLenum pname, const GLfixed * params))
|
||||
SDL_PROC(void, glTexImage2D,
|
||||
(GLenum target, GLint level, GLint internalformat, GLsizei width,
|
||||
GLsizei height, GLint border, GLenum format, GLenum type,
|
||||
const GLvoid * pixels))
|
||||
SDL_PROC(void, glTexParameteri, (GLenum target, GLenum pname, GLint param))
|
||||
SDL_PROC_UNUSED(void, glTexParameterx,
|
||||
(GLenum target, GLenum pname, GLfixed param))
|
||||
SDL_PROC(void, glTexParameteriv,
|
||||
(GLenum target, GLenum pname, const GLint * params))
|
||||
SDL_PROC_UNUSED(void, glTexParameterxv,
|
||||
(GLenum target, GLenum pname, const GLfixed * params))
|
||||
SDL_PROC(void, glTexSubImage2D,
|
||||
(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
||||
GLsizei width, GLsizei height, GLenum format, GLenum type,
|
||||
const GLvoid * pixels))
|
||||
SDL_PROC_UNUSED(void, glTranslatex, (GLfixed x, GLfixed y, GLfixed z))
|
||||
SDL_PROC(void, glVertexPointer,
|
||||
(GLint size, GLenum type, GLsizei stride, const GLvoid * pointer))
|
||||
SDL_PROC(void, glViewport, (GLint x, GLint y, GLsizei width, GLsizei height))
|
||||
|
||||
/* extension functions used */
|
||||
SDL_PROC(void, glDrawTexiOES,
|
||||
(GLint x, GLint y, GLint z, GLint width, GLint height))
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -158,9 +158,6 @@ typedef struct
|
||||
SDL_bool GL_OES_draw_texture_supported;
|
||||
|
||||
/* OpenGL ES functions */
|
||||
#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
|
||||
#include "SDL_glesfuncs.h"
|
||||
#undef SDL_PROC
|
||||
|
||||
} GLES_RenderData;
|
||||
|
||||
@@ -195,12 +192,6 @@ GLES_SetError(const char *prefix, GLenum result)
|
||||
case GL_INVALID_OPERATION:
|
||||
error = "GL_INVALID_OPERATION";
|
||||
break;
|
||||
case GL_STACK_OVERFLOW:
|
||||
error = "GL_STACK_OVERFLOW";
|
||||
break;
|
||||
case GL_STACK_UNDERFLOW:
|
||||
error = "GL_STACK_UNDERFLOW";
|
||||
break;
|
||||
case GL_OUT_OF_MEMORY:
|
||||
error = "GL_OUT_OF_MEMORY";
|
||||
break;
|
||||
@@ -214,12 +205,6 @@ GLES_SetError(const char *prefix, GLenum result)
|
||||
static int
|
||||
GLES_LoadFunctions(GLES_RenderData * data)
|
||||
{
|
||||
|
||||
#define SDL_PROC(ret,func,params) \
|
||||
data->func = func;
|
||||
#include "SDL_glesfuncs.h"
|
||||
#undef SDL_PROC
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -342,15 +327,15 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
|
||||
renderer->info.max_texture_width = value;
|
||||
data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
|
||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
|
||||
renderer->info.max_texture_height = value;
|
||||
|
||||
/* Set up parameters for rendering */
|
||||
data->blendMode = -1;
|
||||
data->glDisable(GL_DEPTH_TEST);
|
||||
data->glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
data->updateSize = SDL_TRUE;
|
||||
|
||||
return renderer;
|
||||
@@ -359,7 +344,7 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
|
||||
static int
|
||||
GLES_ActivateRenderer(SDL_Renderer * renderer)
|
||||
{
|
||||
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
|
||||
SDL_Window *window = renderer->window;
|
||||
|
||||
@@ -369,26 +354,27 @@ GLES_ActivateRenderer(SDL_Renderer * renderer)
|
||||
|
||||
/* Set up parameters for rendering */
|
||||
data->blendMode = -1;
|
||||
data->glDisable(GL_DEPTH_TEST);
|
||||
data->glDisable(GL_CULL_FACE);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDisable(GL_CULL_FACE);
|
||||
data->updateSize = SDL_TRUE;
|
||||
|
||||
if (data->updateSize) {
|
||||
data->glMatrixMode(GL_PROJECTION);
|
||||
data->glLoadIdentity();
|
||||
data->glMatrixMode(GL_MODELVIEW);
|
||||
data->glLoadIdentity();
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
#if SDL_VIDEO_RENDER_RESIZE
|
||||
data->glViewport(0, 0, window->display->desktop_mode.w, window->display->desktop_mode.h);
|
||||
data->glOrthof(0.0, (GLfloat) window->display->desktop_mode.w, (GLfloat) window->display->desktop_mode.h,
|
||||
glViewport(0, 0, window->display->desktop_mode.w, window->display->desktop_mode.h);
|
||||
glOrthof(0.0, (GLfloat) window->display->desktop_mode.w, (GLfloat) window->display->desktop_mode.h,
|
||||
0.0, 0.0, 1.0);
|
||||
#else
|
||||
data->glViewport(0, 0, window->w, window->h);
|
||||
data->glOrthof(0.0, (GLfloat) window->w, (GLfloat) window->h,
|
||||
glViewport(0, 0, window->w, window->h);
|
||||
glOrthof(0.0, (GLfloat) window->w, (GLfloat) window->h,
|
||||
0.0, 0.0, 1.0);
|
||||
#endif
|
||||
data->updateSize = SDL_FALSE;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -475,9 +461,9 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
|
||||
texture->driverdata = data;
|
||||
|
||||
renderdata->glGetError();
|
||||
renderdata->glEnable(GL_TEXTURE_2D);
|
||||
renderdata->glGenTextures(1, &data->texture);
|
||||
glGetError();
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glGenTextures(1, &data->texture);
|
||||
|
||||
data->type = GL_TEXTURE_2D;
|
||||
/* no NPOV textures allowed in OpenGL ES (yet) */
|
||||
@@ -491,21 +477,21 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
||||
|
||||
data->format = format;
|
||||
data->formattype = type;
|
||||
renderdata->glBindTexture(data->type, data->texture);
|
||||
renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
|
||||
glBindTexture(data->type, data->texture);
|
||||
glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
|
||||
GL_NEAREST);
|
||||
renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
|
||||
glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
|
||||
GL_NEAREST);
|
||||
renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
|
||||
glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
|
||||
GL_CLAMP_TO_EDGE);
|
||||
renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
|
||||
glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
|
||||
GL_CLAMP_TO_EDGE);
|
||||
|
||||
renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
|
||||
glTexImage2D(data->type, 0, internalFormat, texture_w,
|
||||
texture_h, 0, format, type, NULL);
|
||||
renderdata->glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
result = renderdata->glGetError();
|
||||
result = glGetError();
|
||||
if (result != GL_NO_ERROR) {
|
||||
GLES_SetError("glTexImage2D()", result);
|
||||
return -1;
|
||||
@@ -545,8 +531,8 @@ SetupTextureUpdate(GLES_RenderData * renderdata, SDL_Texture * texture,
|
||||
int pitch)
|
||||
{
|
||||
GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
|
||||
renderdata->glBindTexture(data->type, data->texture);
|
||||
renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glBindTexture(data->type, data->texture);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
}
|
||||
|
||||
static int
|
||||
@@ -609,8 +595,8 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
void * temp_ptr;
|
||||
int i;
|
||||
|
||||
renderdata->glGetError();
|
||||
renderdata->glEnable(data->type);
|
||||
glGetError();
|
||||
glEnable(data->type);
|
||||
SetupTextureUpdate(renderdata, texture, pitch);
|
||||
|
||||
if( rect->w * bpp == pitch ) {
|
||||
@@ -626,7 +612,7 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
}
|
||||
}
|
||||
|
||||
renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
|
||||
glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
|
||||
rect->h, data->format, data->formattype,
|
||||
temp_buffer);
|
||||
|
||||
@@ -634,8 +620,8 @@ GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
SDL_free(temp_buffer);
|
||||
}
|
||||
|
||||
renderdata->glDisable(data->type);
|
||||
result = renderdata->glGetError();
|
||||
glDisable(data->type);
|
||||
result = glGetError();
|
||||
if (result != GL_NO_ERROR) {
|
||||
GLES_SetError("glTexSubImage2D()", result);
|
||||
return -1;
|
||||
@@ -681,52 +667,55 @@ GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
static void
|
||||
GLES_SetBlendMode(GLES_RenderData * data, int blendMode, int isprimitive)
|
||||
{
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
if (blendMode != data->blendMode) {
|
||||
switch (blendMode) {
|
||||
case SDL_BLENDMODE_NONE:
|
||||
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
data->glDisable(GL_BLEND);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
glDisable(GL_BLEND);
|
||||
break;
|
||||
case SDL_BLENDMODE_MASK:
|
||||
if (isprimitive) {
|
||||
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
data->glDisable(GL_BLEND);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
glDisable(GL_BLEND);
|
||||
/* The same as SDL_BLENDMODE_NONE */
|
||||
blendMode = SDL_BLENDMODE_NONE;
|
||||
break;
|
||||
}
|
||||
/* fall through */
|
||||
case SDL_BLENDMODE_BLEND:
|
||||
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
data->glEnable(GL_BLEND);
|
||||
data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
break;
|
||||
case SDL_BLENDMODE_ADD:
|
||||
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
data->glEnable(GL_BLEND);
|
||||
data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
|
||||
break;
|
||||
case SDL_BLENDMODE_MOD:
|
||||
data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
data->glEnable(GL_BLEND);
|
||||
data->glBlendFunc(GL_ZERO, GL_SRC_COLOR);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_ZERO, GL_SRC_COLOR);
|
||||
break;
|
||||
}
|
||||
data->blendMode = blendMode;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static int
|
||||
GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
|
||||
int count)
|
||||
{
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
|
||||
int i;
|
||||
GLshort *vertices;
|
||||
|
||||
GLES_SetBlendMode(data, renderer->blendMode, 1);
|
||||
|
||||
data->glColor4f((GLfloat) renderer->r * inv255f,
|
||||
glColor4f((GLfloat) renderer->r * inv255f,
|
||||
(GLfloat) renderer->g * inv255f,
|
||||
(GLfloat) renderer->b * inv255f,
|
||||
(GLfloat) renderer->a * inv255f);
|
||||
@@ -736,12 +725,12 @@ GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
|
||||
vertices[2*i+0] = (GLshort)points[i].x;
|
||||
vertices[2*i+1] = (GLshort)points[i].y;
|
||||
}
|
||||
data->glVertexPointer(2, GL_SHORT, 0, vertices);
|
||||
data->glEnableClientState(GL_VERTEX_ARRAY);
|
||||
data->glDrawArrays(GL_POINTS, 0, count);
|
||||
data->glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_SHORT, 0, vertices);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glDrawArrays(GL_POINTS, 0, count);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
SDL_stack_free(vertices);
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -749,13 +738,14 @@ static int
|
||||
GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
|
||||
int count)
|
||||
{
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
|
||||
int i;
|
||||
GLshort *vertices;
|
||||
|
||||
GLES_SetBlendMode(data, renderer->blendMode, 1);
|
||||
|
||||
data->glColor4f((GLfloat) renderer->r * inv255f,
|
||||
glColor4f((GLfloat) renderer->r * inv255f,
|
||||
(GLfloat) renderer->g * inv255f,
|
||||
(GLfloat) renderer->b * inv255f,
|
||||
(GLfloat) renderer->a * inv255f);
|
||||
@@ -765,19 +755,19 @@ GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
|
||||
vertices[2*i+0] = (GLshort)points[i].x;
|
||||
vertices[2*i+1] = (GLshort)points[i].y;
|
||||
}
|
||||
data->glVertexPointer(2, GL_SHORT, 0, vertices);
|
||||
data->glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_SHORT, 0, vertices);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
if (count > 2 &&
|
||||
points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
|
||||
/* GL_LINE_LOOP takes care of the final segment */
|
||||
--count;
|
||||
data->glDrawArrays(GL_LINE_LOOP, 0, count);
|
||||
glDrawArrays(GL_LINE_LOOP, 0, count);
|
||||
} else {
|
||||
data->glDrawArrays(GL_LINE_STRIP, 0, count);
|
||||
glDrawArrays(GL_LINE_STRIP, 0, count);
|
||||
}
|
||||
data->glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
SDL_stack_free(vertices);
|
||||
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -785,17 +775,18 @@ static int
|
||||
GLES_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
|
||||
int count)
|
||||
{
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
|
||||
int i;
|
||||
|
||||
GLES_SetBlendMode(data, renderer->blendMode, 1);
|
||||
|
||||
data->glColor4f((GLfloat) renderer->r * inv255f,
|
||||
glColor4f((GLfloat) renderer->r * inv255f,
|
||||
(GLfloat) renderer->g * inv255f,
|
||||
(GLfloat) renderer->b * inv255f,
|
||||
(GLfloat) renderer->a * inv255f);
|
||||
|
||||
data->glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
for (i = 0; i < count; ++i) {
|
||||
const SDL_Rect *rect = rects[i];
|
||||
GLshort minx = rect->x;
|
||||
@@ -812,11 +803,11 @@ GLES_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
|
||||
vertices[6] = maxx;
|
||||
vertices[7] = maxy;
|
||||
|
||||
data->glVertexPointer(2, GL_SHORT, 0, vertices);
|
||||
data->glDrawArrays(GL_LINE_LOOP, 0, 4);
|
||||
glVertexPointer(2, GL_SHORT, 0, vertices);
|
||||
glDrawArrays(GL_LINE_LOOP, 0, 4);
|
||||
}
|
||||
data->glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -824,17 +815,18 @@ static int
|
||||
GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
|
||||
int count)
|
||||
{
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
|
||||
int i;
|
||||
|
||||
GLES_SetBlendMode(data, renderer->blendMode, 1);
|
||||
|
||||
data->glColor4f((GLfloat) renderer->r * inv255f,
|
||||
glColor4f((GLfloat) renderer->r * inv255f,
|
||||
(GLfloat) renderer->g * inv255f,
|
||||
(GLfloat) renderer->b * inv255f,
|
||||
(GLfloat) renderer->a * inv255f);
|
||||
|
||||
data->glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
for (i = 0; i < count; ++i) {
|
||||
const SDL_Rect *rect = rects[i];
|
||||
GLshort minx = rect->x;
|
||||
@@ -851,11 +843,11 @@ GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
|
||||
vertices[6] = maxx;
|
||||
vertices[7] = maxy;
|
||||
|
||||
data->glVertexPointer(2, GL_SHORT, 0, vertices);
|
||||
data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glVertexPointer(2, GL_SHORT, 0, vertices);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
data->glDisableClientState(GL_VERTEX_ARRAY);
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -863,7 +855,7 @@ static int
|
||||
GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
const SDL_Rect * srcrect, const SDL_Rect * dstrect)
|
||||
{
|
||||
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
|
||||
GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
|
||||
int minx, miny, maxx, maxy;
|
||||
@@ -872,7 +864,7 @@ GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
void *temp_buffer; /* used for reformatting dirty rect pixels */
|
||||
void *temp_ptr;
|
||||
|
||||
data->glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
if (texturedata->dirty.list) {
|
||||
SDL_DirtyRect *dirty;
|
||||
@@ -882,7 +874,7 @@ GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
|
||||
SetupTextureUpdate(data, texture, pitch);
|
||||
|
||||
data->glBindTexture(texturedata->type, texturedata->texture);
|
||||
glBindTexture(texturedata->type, texturedata->texture);
|
||||
for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
|
||||
SDL_Rect *rect = &dirty->rect;
|
||||
pixels =
|
||||
@@ -906,7 +898,7 @@ GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
}
|
||||
}
|
||||
|
||||
data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
|
||||
glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
|
||||
rect->w, rect->h, texturedata->format,
|
||||
texturedata->formattype, temp_buffer);
|
||||
|
||||
@@ -917,15 +909,15 @@ GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
SDL_ClearDirtyRects(&texturedata->dirty);
|
||||
}
|
||||
|
||||
data->glBindTexture(texturedata->type, texturedata->texture);
|
||||
glBindTexture(texturedata->type, texturedata->texture);
|
||||
|
||||
if (texture->modMode) {
|
||||
data->glColor4f((GLfloat) texture->r * inv255f,
|
||||
glColor4f((GLfloat) texture->r * inv255f,
|
||||
(GLfloat) texture->g * inv255f,
|
||||
(GLfloat) texture->b * inv255f,
|
||||
(GLfloat) texture->a * inv255f);
|
||||
} else {
|
||||
data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
}
|
||||
|
||||
GLES_SetBlendMode(data, texture->blendMode, 0);
|
||||
@@ -933,16 +925,16 @@ GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
switch (texture->scaleMode) {
|
||||
case SDL_SCALEMODE_NONE:
|
||||
case SDL_SCALEMODE_FAST:
|
||||
data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
|
||||
glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
|
||||
GL_NEAREST);
|
||||
data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
|
||||
glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
|
||||
GL_NEAREST);
|
||||
break;
|
||||
case SDL_SCALEMODE_SLOW:
|
||||
case SDL_SCALEMODE_BEST:
|
||||
data->glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
|
||||
glTexParameteri(texturedata->type, GL_TEXTURE_MIN_FILTER,
|
||||
GL_LINEAR);
|
||||
data->glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
|
||||
glTexParameteri(texturedata->type, GL_TEXTURE_MAG_FILTER,
|
||||
GL_LINEAR);
|
||||
break;
|
||||
}
|
||||
@@ -955,10 +947,10 @@ GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
cropRect[1] = srcrect->y + srcrect->h;
|
||||
cropRect[2] = srcrect->w;
|
||||
cropRect[3] = -srcrect->h;
|
||||
data->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES,
|
||||
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES,
|
||||
cropRect);
|
||||
//__android_log_print(ANDROID_LOG_INFO, "libSDL", "GLES_RenderCopy glDrawTexiOES(%d, %d, %d, %d) cropRect %d:%d:%d:%d", dstrect->x, window->display->desktop_mode.h - dstrect->y - dstrect->h, dstrect->w, dstrect->h, cropRect[0], cropRect[1], cropRect[2], cropRect[3]);
|
||||
data->glDrawTexiOES(dstrect->x,
|
||||
glDrawTexiOES(dstrect->x,
|
||||
#if SDL_VIDEO_RENDER_RESIZE
|
||||
window->display->desktop_mode.h - dstrect->y - dstrect->h,
|
||||
#else
|
||||
@@ -1002,17 +994,17 @@ GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
|
||||
texCoords[6] = maxu;
|
||||
texCoords[7] = maxv;
|
||||
|
||||
data->glVertexPointer(2, GL_SHORT, 0, vertices);
|
||||
data->glEnableClientState(GL_VERTEX_ARRAY);
|
||||
data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
|
||||
data->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
data->glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
data->glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glVertexPointer(2, GL_SHORT, 0, vertices);
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
data->glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,15 +32,14 @@ If you compile this code with SDL 1.3 or newer, or use in some other way, the li
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <string.h> // for memset()
|
||||
#include <GLES/gl.h>
|
||||
#include <GLES/glext.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "SDL_opengles.h"
|
||||
|
||||
#include "SDL_config.h"
|
||||
|
||||
#include "SDL_version.h"
|
||||
|
||||
//#include "SDL_opengles.h"
|
||||
#include "SDL_screenkeyboard.h"
|
||||
#include "../SDL_sysvideo.h"
|
||||
#include "SDL_androidvideo.h"
|
||||
@@ -153,6 +152,8 @@ oldGlState;
|
||||
|
||||
static inline void beginDrawingTex()
|
||||
{
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
|
||||
#ifndef SDL_TOUCHSCREEN_KEYBOARD_SAVE_RESTORE_OPENGL_STATE
|
||||
// Make the video somehow work on emulator
|
||||
oldGlState.texture2d = GL_TRUE;
|
||||
@@ -170,7 +171,6 @@ static inline void beginDrawingTex()
|
||||
// However GLES 1.1 spec defines all theese values, so it's a device fault for not implementing them
|
||||
oldGlState.texture2d = glIsEnabled(GL_TEXTURE_2D);
|
||||
glGetIntegerv(GL_ACTIVE_TEXTURE, &oldGlState.texunitId);
|
||||
glGetIntegerv(GL_CLIENT_ACTIVE_TEXTURE, &oldGlState.clientTexunitId);
|
||||
#endif
|
||||
|
||||
//R_DumpOpenGlState();
|
||||
@@ -186,7 +186,6 @@ static inline void beginDrawingTex()
|
||||
*/
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glClientActiveTexture(GL_TEXTURE0);
|
||||
|
||||
#ifdef SDL_TOUCHSCREEN_KEYBOARD_SAVE_RESTORE_OPENGL_STATE
|
||||
glGetIntegerv(GL_TEXTURE_BINDING_2D, &oldGlState.textureId);
|
||||
@@ -195,15 +194,15 @@ static inline void beginDrawingTex()
|
||||
oldGlState.blend = glIsEnabled(GL_BLEND);
|
||||
glGetIntegerv(GL_BLEND_SRC, &oldGlState.blend1);
|
||||
glGetIntegerv(GL_BLEND_DST, &oldGlState.blend2);
|
||||
glGetBooleanv(GL_COLOR_ARRAY, &oldGlState.colorArray);
|
||||
//glGetBooleanv(GL_COLOR_ARRAY, &oldGlState.colorArray);
|
||||
// It's very unlikely that some app will use GL_TEXTURE_CROP_RECT_OES, so just skip it
|
||||
#endif
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glEnable(GL_BLEND);
|
||||
glDisable(GL_CULL_FACE);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
//static const GLfloat color[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
//glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, color);
|
||||
@@ -213,27 +212,31 @@ static inline void beginDrawingTex()
|
||||
//glDisableClientState(GL_NORMAL_ARRAY);
|
||||
//glDisableClientState(GL_VERTEX_ARRAY);
|
||||
//glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void endDrawingTex()
|
||||
{
|
||||
// Restore OpenGL state
|
||||
if( oldGlState.texture2d == GL_FALSE )
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
glBindTexture(GL_TEXTURE_2D, oldGlState.textureId);
|
||||
glColor4f(oldGlState.color[0], oldGlState.color[1], oldGlState.color[2], oldGlState.color[3]);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, oldGlState.texEnvMode);
|
||||
if( oldGlState.blend == GL_FALSE )
|
||||
glDisable(GL_BLEND);
|
||||
glBlendFunc(oldGlState.blend1, oldGlState.blend2);
|
||||
glActiveTexture(oldGlState.texunitId);
|
||||
glClientActiveTexture(oldGlState.clientTexunitId);
|
||||
|
||||
if( oldGlState.texture2d == GL_FALSE )
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glColor4f(oldGlState.color[0], oldGlState.color[1], oldGlState.color[2], oldGlState.color[3]);
|
||||
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, oldGlState.texEnvMode);
|
||||
if( oldGlState.colorArray )
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void drawCharTexFlip(GLTexture_t * tex, SDL_Rect * src, SDL_Rect * dest, int flipX, int flipY, float r, float g, float b, float a)
|
||||
{
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
GLint cropRect[4];
|
||||
|
||||
if( !dest->h || !dest->w )
|
||||
@@ -269,6 +272,7 @@ static inline void drawCharTexFlip(GLTexture_t * tex, SDL_Rect * src, SDL_Rect *
|
||||
}
|
||||
glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, cropRect);
|
||||
glDrawTexiOES(dest->x + SDL_ANDROID_ScreenVisibleRect.x, SDL_ANDROID_sRealWindowHeight - dest->y - dest->h - SDL_ANDROID_ScreenVisibleRect.y, 0, dest->w, dest->h);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void drawCharTex(GLTexture_t * tex, SDL_Rect * src, SDL_Rect * dest, float r, float g, float b, float a)
|
||||
@@ -1336,6 +1340,7 @@ extern DECLSPEC int SDL_ANDROID_ScreenKeyboardUpdateToNewVideoMode(int oldx, int
|
||||
*/
|
||||
void R_DumpOpenGlState(void)
|
||||
{
|
||||
#if SDL_VIDEO_OPENGL_ES_VERSION == 1
|
||||
#define CAPABILITY( X ) {GL_ ## X, # X}
|
||||
/* List taken from here: http://www.khronos.org/opengles/sdk/1.1/docs/man/glIsEnabled.xml */
|
||||
const struct { GLenum idx; const char * text; } openGLCaps[] = {
|
||||
@@ -1423,4 +1428,5 @@ void R_DumpOpenGlState(void)
|
||||
|
||||
glActiveTexture(activeTexUnit);
|
||||
glClientActiveTexture(activeClientTexUnit);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -3184,7 +3184,6 @@ SDL_bool
|
||||
SDL_GL_ExtensionSupported(const char *extension)
|
||||
{
|
||||
#if SDL_VIDEO_OPENGL || SDL_VIDEO_OPENGL_ES
|
||||
const GLubyte *(APIENTRY * glGetStringFunc) (GLenum);
|
||||
const char *extensions;
|
||||
const char *start;
|
||||
const char *where, *terminator;
|
||||
@@ -3200,12 +3199,7 @@ SDL_GL_ExtensionSupported(const char *extension)
|
||||
return SDL_FALSE;
|
||||
}
|
||||
/* Lookup the available extensions */
|
||||
glGetStringFunc = SDL_GL_GetProcAddress("glGetString");
|
||||
if (glGetStringFunc) {
|
||||
extensions = (const char *) glGetStringFunc(GL_EXTENSIONS);
|
||||
} else {
|
||||
extensions = NULL;
|
||||
}
|
||||
extensions = (const char *) glGetString(GL_EXTENSIONS);
|
||||
if (!extensions) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user