Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
authorSam Lantinga <slouken@libsdl.org>
Wed, 02 Feb 2011 14:34:54 -0800
changeset 5154fb424691cfc7
parent 5153 3e4086b3bcd2
child 5155 f3ebd1950442
Moved the rendering code out to a separate directory in the hope that it can someday be completely decoupled from the rest of the library and be expanded to an awesome 2D on 3D library.
VisualC/SDL/SDL_VS2008.vcproj
VisualC/SDL/SDL_VS2010.vcxproj
VisualC/SDL_VS2008.sln
VisualC/SDL_VS2010.sln
Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj
Xcode/SDL/SDL.xcodeproj/project.pbxproj
configure.in
include/SDL_rect.h
include/SDL_video.h
src/events/SDL_events.c
src/render/SDL_render.c
src/render/SDL_sysrender.h
src/render/direct3d/SDL_d3drender.c
src/render/opengl/SDL_renderer_gl.c
src/render/opengles/SDL_renderer_gles.c
src/render/software/SDL_renderer_sw.c
src/video/SDL_pixels_c.h
src/video/SDL_rect.c
src/video/SDL_rect_c.h
src/video/SDL_renderer_gl.c
src/video/SDL_renderer_gl.h
src/video/SDL_renderer_gles.c
src/video/SDL_renderer_gles.h
src/video/SDL_renderer_sw.c
src/video/SDL_renderer_sw.h
src/video/SDL_sysvideo.h
src/video/SDL_video.c
src/video/directfb/SDL_DirectFB_render.c
src/video/dummy/SDL_nullrender.c
src/video/dummy/SDL_nullrender_c.h
src/video/dummy/SDL_nullvideo.c
src/video/uikit/SDL_uikitvideo.m
src/video/uikit/SDL_uikitwindow.m
src/video/windows/SDL_d3drender.c
src/video/windows/SDL_d3drender.h
src/video/windows/SDL_windowskeyboard.c
src/video/windows/SDL_windowsvideo.c
src/video/windows/SDL_windowsvideo.h
src/video/x11/SDL_x11video.h
     1.1 --- a/VisualC/SDL/SDL_VS2008.vcproj	Wed Feb 02 14:34:24 2011 -0800
     1.2 +++ b/VisualC/SDL/SDL_VS2008.vcproj	Wed Feb 02 14:34:54 2011 -0800
     1.3 @@ -30,7 +30,7 @@
     1.4  			<Tool
     1.5  				Name="VCPreBuildEventTool"
     1.6  				Description="Making sure basic SDL headers are in place..."
     1.7 -				CommandLine="echo Copying SDL_config_windows.h to SDL_config.h...&#x0D;&#x0A;copy /Y &quot;$(ProjectDir)\..\..\include\SDL_config_windows.h&quot; &quot;$(ProjectDir)\..\..\include\SDL_config.h&quot;&#x0D;&#x0A;&#x0D;&#x0A;if exist &quot;$(ProjectDir)\..\..\include\SDL_revision.h&quot; goto SDLREVISIONOKAY&#x0D;&#x0A;echo Creating stub SDL_revision.h file...&#x0D;&#x0A;echo #define SDL_REVISION &quot;hg-0:baadfood&quot; &gt;&quot;$(ProjectDir)\..\..\include\SDL_revision.h&quot;&#x0D;&#x0A;:SDLREVISIONOKAY&#x0D;&#x0A;"
     1.8 +				CommandLine="echo Copying SDL_config_windows.h to SDL_config.h...&#x0D;&#x0A;xcopy /d /q /y &quot;$(ProjectDir)\..\..\include\SDL_config_windows.h&quot; &quot;$(ProjectDir)\..\..\include\SDL_config.h&quot;&#x0D;&#x0A;&#x0D;&#x0A;if exist &quot;$(ProjectDir)\..\..\include\SDL_revision.h&quot; goto SDLREVISIONOKAY&#x0D;&#x0A;echo Creating stub SDL_revision.h file...&#x0D;&#x0A;echo #define SDL_REVISION &quot;hg-0:baadf00d&quot; &gt;&quot;$(ProjectDir)\..\..\include\SDL_revision.h&quot;&#x0D;&#x0A;:SDLREVISIONOKAY&#x0D;&#x0A;"
     1.9  			/>
    1.10  			<Tool
    1.11  				Name="VCCustomBuildTool"
    1.12 @@ -201,7 +201,7 @@
    1.13  			<Tool
    1.14  				Name="VCPreBuildEventTool"
    1.15  				Description="Making sure basic SDL headers are in place..."
    1.16 -				CommandLine="echo Copying SDL_config_windows.h to SDL_config.h...&#x0D;&#x0A;copy /Y &quot;$(ProjectDir)\..\..\include\SDL_config_windows.h&quot; &quot;$(ProjectDir)\..\..\include\SDL_config.h&quot;&#x0D;&#x0A;&#x0D;&#x0A;if exist &quot;$(ProjectDir)\..\..\include\SDL_revision.h&quot; goto SDLREVISIONOKAY&#x0D;&#x0A;echo Creating stub SDL_revision.h file...&#x0D;&#x0A;echo #define SDL_REVISION &quot;hg-0:baadfood&quot; &gt;&quot;$(ProjectDir)\..\..\include\SDL_revision.h&quot;&#x0D;&#x0A;:SDLREVISIONOKAY&#x0D;&#x0A;"
    1.17 +				CommandLine="echo Copying SDL_config_windows.h to SDL_config.h...&#x0D;&#x0A;xcopy /d /q /y &quot;$(ProjectDir)\..\..\include\SDL_config_windows.h&quot; &quot;$(ProjectDir)\..\..\include\SDL_config.h&quot;&#x0D;&#x0A;&#x0D;&#x0A;if exist &quot;$(ProjectDir)\..\..\include\SDL_revision.h&quot; goto SDLREVISIONOKAY&#x0D;&#x0A;echo Creating stub SDL_revision.h file...&#x0D;&#x0A;echo #define SDL_REVISION &quot;hg-0:baadf00d&quot; &gt;&quot;$(ProjectDir)\..\..\include\SDL_revision.h&quot;&#x0D;&#x0A;:SDLREVISIONOKAY&#x0D;&#x0A;"
    1.18  			/>
    1.19  			<Tool
    1.20  				Name="VCCustomBuildTool"
    1.21 @@ -386,6 +386,10 @@
    1.22  				>
    1.23  			</File>
    1.24  			<File
    1.25 +				RelativePath="..\..\include\SDL_blendmode.h"
    1.26 +				>
    1.27 +			</File>
    1.28 +			<File
    1.29  				RelativePath="..\..\include\SDL_clipboard.h"
    1.30  				>
    1.31  			</File>
    1.32 @@ -422,10 +426,18 @@
    1.33  				>
    1.34  			</File>
    1.35  			<File
    1.36 +				RelativePath="..\..\include\SDL_gesture.h"
    1.37 +				>
    1.38 +			</File>
    1.39 +			<File
    1.40  				RelativePath="..\..\include\SDL_haptic.h"
    1.41  				>
    1.42  			</File>
    1.43  			<File
    1.44 +				RelativePath="..\..\include\SDL_input.h"
    1.45 +				>
    1.46 +			</File>
    1.47 +			<File
    1.48  				RelativePath="..\..\include\SDL_joystick.h"
    1.49  				>
    1.50  			</File>
    1.51 @@ -486,6 +498,10 @@
    1.52  				>
    1.53  			</File>
    1.54  			<File
    1.55 +				RelativePath="..\..\include\SDL_render.h"
    1.56 +				>
    1.57 +			</File>
    1.58 +			<File
    1.59  				RelativePath="..\..\include\SDL_revision.h"
    1.60  				>
    1.61  			</File>
    1.62 @@ -498,6 +514,10 @@
    1.63  				>
    1.64  			</File>
    1.65  			<File
    1.66 +				RelativePath="..\..\include\SDL_shape.h"
    1.67 +				>
    1.68 +			</File>
    1.69 +			<File
    1.70  				RelativePath="..\..\include\SDL_stdinc.h"
    1.71  				>
    1.72  			</File>
    1.73 @@ -518,6 +538,10 @@
    1.74  				>
    1.75  			</File>
    1.76  			<File
    1.77 +				RelativePath="..\..\include\SDL_touch.h"
    1.78 +				>
    1.79 +			</File>
    1.80 +			<File
    1.81  				RelativePath="..\..\include\SDL_types.h"
    1.82  				>
    1.83  			</File>
    1.84 @@ -751,11 +775,7 @@
    1.85  			>
    1.86  		</File>
    1.87  		<File
    1.88 -			RelativePath="..\..\src\video\windows\SDL_d3drender.c"
    1.89 -			>
    1.90 -		</File>
    1.91 -		<File
    1.92 -			RelativePath="..\..\src\video\windows\SDL_d3drender.h"
    1.93 +			RelativePath="..\..\src\render\direct3d\SDL_d3drender.c"
    1.94  			>
    1.95  		</File>
    1.96  		<File
    1.97 @@ -943,14 +963,6 @@
    1.98  			>
    1.99  		</File>
   1.100  		<File
   1.101 -			RelativePath="..\..\src\video\dummy\SDL_nullrender.c"
   1.102 -			>
   1.103 -		</File>
   1.104 -		<File
   1.105 -			RelativePath="..\..\src\video\dummy\SDL_nullrender_c.h"
   1.106 -			>
   1.107 -		</File>
   1.108 -		<File
   1.109  			RelativePath="..\..\src\video\dummy\SDL_nullvideo.c"
   1.110  			>
   1.111  		</File>
   1.112 @@ -987,19 +999,15 @@
   1.113  			>
   1.114  		</File>
   1.115  		<File
   1.116 -			RelativePath="..\..\src\video\SDL_renderer_gl.c"
   1.117 +			RelativePath="..\..\src\render\SDL_render.c"
   1.118  			>
   1.119  		</File>
   1.120  		<File
   1.121 -			RelativePath="..\..\src\video\SDL_renderer_gl.h"
   1.122 +			RelativePath="..\..\src\render\opengl\SDL_renderer_gl.c"
   1.123  			>
   1.124  		</File>
   1.125  		<File
   1.126 -			RelativePath="..\..\src\video\SDL_renderer_sw.c"
   1.127 -			>
   1.128 -		</File>
   1.129 -		<File
   1.130 -			RelativePath="..\..\src\video\SDL_renderer_sw.h"
   1.131 +			RelativePath="..\..\src\render\software\SDL_renderer_sw.c"
   1.132  			>
   1.133  		</File>
   1.134  		<File
   1.135 @@ -1075,6 +1083,10 @@
   1.136  			>
   1.137  		</File>
   1.138  		<File
   1.139 +			RelativePath="..\..\src\render\SDL_sysrender.h"
   1.140 +			>
   1.141 +		</File>
   1.142 +		<File
   1.143  			RelativePath="..\..\src\thread\windows\SDL_syssem.c"
   1.144  			>
   1.145  		</File>
     2.1 --- a/VisualC/SDL/SDL_VS2010.vcxproj	Wed Feb 02 14:34:24 2011 -0800
     2.2 +++ b/VisualC/SDL/SDL_VS2010.vcxproj	Wed Feb 02 14:34:54 2011 -0800
     2.3 @@ -75,7 +75,7 @@
     2.4      <PreBuildEvent>
     2.5        <Message>Making sure basic SDL headers are in place...</Message>
     2.6        <Command>echo Copying SDL_config_windows.h to SDL_config.h...
     2.7 -copy /Y "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h"
     2.8 +xcopy /d /q /y "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h"
     2.9  
    2.10  if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY
    2.11  echo Creating stub SDL_revision.h file...
    2.12 @@ -153,7 +153,7 @@
    2.13      <PreBuildEvent>
    2.14        <Message>Making sure basic SDL headers are in place...</Message>
    2.15        <Command>echo Copying SDL_config_windows.h to SDL_config.h...
    2.16 -copy /Y "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h"
    2.17 +xcopy /d /q /y "$(ProjectDir)\..\..\include\SDL_config_windows.h" "$(ProjectDir)\..\..\include\SDL_config.h"
    2.18  
    2.19  if exist "$(ProjectDir)\..\..\include\SDL_revision.h" goto SDLREVISIONOKAY
    2.20  echo Creating stub SDL_revision.h file...
    2.21 @@ -231,6 +231,7 @@
    2.22      <ClInclude Include="..\..\include\SDL_assert.h" />
    2.23      <ClInclude Include="..\..\include\SDL_atomic.h" />
    2.24      <ClInclude Include="..\..\include\SDL_audio.h" />
    2.25 +    <ClInclude Include="..\..\include\SDL_blendmode.h" />
    2.26      <ClInclude Include="..\..\include\SDL_clipboard.h" />
    2.27      <ClInclude Include="..\..\include\SDL_compat.h" />
    2.28      <ClInclude Include="..\..\include\SDL_config.h" />
    2.29 @@ -240,7 +241,9 @@
    2.30      <ClInclude Include="..\..\include\SDL_endian.h" />
    2.31      <ClInclude Include="..\..\include\SDL_error.h" />
    2.32      <ClInclude Include="..\..\include\SDL_events.h" />
    2.33 +    <ClInclude Include="..\..\include\SDL_gesture.h" />
    2.34      <ClInclude Include="..\..\include\SDL_haptic.h" />
    2.35 +    <ClInclude Include="..\..\include\SDL_input.h" />
    2.36      <ClInclude Include="..\..\include\SDL_joystick.h" />
    2.37      <ClInclude Include="..\..\include\SDL_keyboard.h" />
    2.38      <ClInclude Include="..\..\include\SDL_keysym.h" />
    2.39 @@ -256,6 +259,7 @@
    2.40      <ClInclude Include="..\..\include\SDL_power.h" />
    2.41      <ClInclude Include="..\..\include\SDL_quit.h" />
    2.42      <ClInclude Include="..\..\include\SDL_rect.h" />
    2.43 +    <ClInclude Include="..\..\include\SDL_render.h" />
    2.44      <ClInclude Include="..\..\include\SDL_revision.h" />
    2.45      <ClInclude Include="..\..\include\SDL_rwops.h" />
    2.46      <ClInclude Include="..\..\include\SDL_scancode.h" />
    2.47 @@ -265,6 +269,7 @@
    2.48      <ClInclude Include="..\..\include\SDL_syswm.h" />
    2.49      <ClInclude Include="..\..\include\SDL_thread.h" />
    2.50      <ClInclude Include="..\..\include\SDL_timer.h" />
    2.51 +    <ClInclude Include="..\..\include\SDL_touch.h" />
    2.52      <ClInclude Include="..\..\include\SDL_types.h" />
    2.53      <ClInclude Include="..\..\include\SDL_version.h" />
    2.54      <ClInclude Include="..\..\include\SDL_video.h" />
    2.55 @@ -277,6 +282,7 @@
    2.56      <ClInclude Include="..\..\src\events\SDL_touch_c.h" />
    2.57      <ClInclude Include="..\..\src\libm\math.h" />
    2.58      <ClInclude Include="..\..\src\libm\math_private.h" />
    2.59 +    <ClInclude Include="..\..\src\render\SDL_sysrender.h" />
    2.60      <ClInclude Include="..\..\src\video\mmx.h" />
    2.61      <ClInclude Include="..\..\src\video\SDL_alphamult.h" />
    2.62      <ClInclude Include="..\..\src\audio\SDL_audio_c.h" />
    2.63 @@ -287,7 +293,6 @@
    2.64      <ClInclude Include="..\..\src\video\SDL_blit_copy.h" />
    2.65      <ClInclude Include="..\..\src\video\SDL_blit_slow.h" />
    2.66      <ClInclude Include="..\..\src\video\SDL_shape_internals.h" />
    2.67 -    <ClInclude Include="..\..\src\video\windows\SDL_d3drender.h" />
    2.68      <ClInclude Include="..\..\src\audio\windib\SDL_dibaudio.h" />
    2.69      <ClInclude Include="..\..\src\audio\disk\SDL_diskaudio.h" />
    2.70      <ClInclude Include="..\..\src\video\SDL_draw.h" />
    2.71 @@ -306,12 +311,9 @@
    2.72      <ClInclude Include="..\..\src\audio\SDL_mixer_MMX_VC.h" />
    2.73      <ClInclude Include="..\..\src\events\SDL_mouse_c.h" />
    2.74      <ClInclude Include="..\..\src\video\dummy\SDL_nullevents_c.h" />
    2.75 -    <ClInclude Include="..\..\src\video\dummy\SDL_nullrender_c.h" />
    2.76      <ClInclude Include="..\..\src\video\dummy\SDL_nullvideo.h" />
    2.77      <ClInclude Include="..\..\src\video\SDL_pixels_c.h" />
    2.78      <ClInclude Include="..\..\src\video\SDL_rect_c.h" />
    2.79 -    <ClInclude Include="..\..\src\video\SDL_renderer_gl.h" />
    2.80 -    <ClInclude Include="..\..\src\video\SDL_renderer_sw.h" />
    2.81      <ClInclude Include="..\..\src\video\SDL_RLEaccel_c.h" />
    2.82      <ClInclude Include="..\..\src\video\SDL_stretch_c.h" />
    2.83      <ClInclude Include="..\..\src\audio\SDL_sysaudio.h" />
    2.84 @@ -360,6 +362,10 @@
    2.85      <ClCompile Include="..\..\src\libm\s_floor.c" />
    2.86      <ClCompile Include="..\..\src\libm\s_scalbn.c" />
    2.87      <ClCompile Include="..\..\src\libm\s_sin.c" />
    2.88 +    <ClCompile Include="..\..\src\render\direct3d\SDL_d3drender.c" />
    2.89 +    <ClCompile Include="..\..\src\render\opengl\SDL_renderer_gl.c" />
    2.90 +    <ClCompile Include="..\..\src\render\SDL_render.c" />
    2.91 +    <ClCompile Include="..\..\src\render\software\SDL_renderer_sw.c" />
    2.92      <ClCompile Include="..\..\src\SDL.c" />
    2.93      <ClCompile Include="..\..\src\video\SDL_alphamult.c" />
    2.94      <ClCompile Include="..\..\src\SDL_assert.c" />
    2.95 @@ -386,7 +392,6 @@
    2.96      <ClCompile Include="..\..\src\cpuinfo\SDL_cpuinfo.c" />
    2.97      <ClCompile Include="..\..\src\video\SDL_clipboard.c" />
    2.98      <ClCompile Include="..\..\src\video\SDL_shape.c" />
    2.99 -    <ClCompile Include="..\..\src\video\windows\SDL_d3drender.c" />
   2.100      <ClCompile Include="..\..\src\audio\windib\SDL_dibaudio.c" />
   2.101      <ClCompile Include="..\..\src\audio\disk\SDL_diskaudio.c" />
   2.102      <ClCompile Include="..\..\src\video\SDL_drawline.c" />
   2.103 @@ -413,15 +418,12 @@
   2.104      <ClCompile Include="..\..\src\joystick\windows\SDL_mmjoystick.c" />
   2.105      <ClCompile Include="..\..\src\events\SDL_mouse.c" />
   2.106      <ClCompile Include="..\..\src\video\dummy\SDL_nullevents.c" />
   2.107 -    <ClCompile Include="..\..\src\video\dummy\SDL_nullrender.c" />
   2.108      <ClCompile Include="..\..\src\video\dummy\SDL_nullvideo.c" />
   2.109      <ClCompile Include="..\..\src\video\SDL_pixels.c" />
   2.110      <ClCompile Include="..\..\src\power\SDL_power.c" />
   2.111      <ClCompile Include="..\..\src\stdlib\SDL_qsort.c" />
   2.112      <ClCompile Include="..\..\src\events\SDL_quit.c" />
   2.113      <ClCompile Include="..\..\src\video\SDL_rect.c" />
   2.114 -    <ClCompile Include="..\..\src\video\SDL_renderer_gl.c" />
   2.115 -    <ClCompile Include="..\..\src\video\SDL_renderer_sw.c" />
   2.116      <ClCompile Include="..\..\src\video\SDL_RLEaccel.c" />
   2.117      <ClCompile Include="..\..\src\file\SDL_rwops.c" />
   2.118      <ClCompile Include="..\..\src\stdlib\SDL_stdlib.c" />
   2.119 @@ -456,4 +458,4 @@
   2.120    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   2.121    <ImportGroup Label="ExtensionTargets">
   2.122    </ImportGroup>
   2.123 -</Project>
   2.124 +</Project>
   2.125 \ No newline at end of file
     3.1 --- a/VisualC/SDL_VS2008.sln	Wed Feb 02 14:34:24 2011 -0800
     3.2 +++ b/VisualC/SDL_VS2008.sln	Wed Feb 02 14:34:54 2011 -0800
     3.3 @@ -84,12 +84,6 @@
     3.4  		{DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}
     3.5  	EndProjectSection
     3.6  EndProject
     3.7 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testpalette", "tests\testpalette\testpalette_VS2008.vcproj", "{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}"
     3.8 -	ProjectSection(ProjectDependencies) = postProject
     3.9 -		{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}
    3.10 -		{DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}
    3.11 -	EndProjectSection
    3.12 -EndProject
    3.13  Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testplatform", "tests\testplatform\testplatform_VS2008.vcproj", "{26932B24-EFC6-4E3A-B277-ED653DA37968}"
    3.14  	ProjectSection(ProjectDependencies) = postProject
    3.15  		{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}
    3.16 @@ -301,15 +295,6 @@
    3.17  		{B51E0D74-F0A2-45A2-BD2A-8B7D95B8204A}.Release|Win32.ActiveCfg = Release|Win32
    3.18  		{B51E0D74-F0A2-45A2-BD2A-8B7D95B8204A}.Release|Win32.Build.0 = Release|Win32
    3.19  		{B51E0D74-F0A2-45A2-BD2A-8B7D95B8204A}.Release|x64.ActiveCfg = Release|Win32
    3.20 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Debug|Win32.ActiveCfg = Debug|Win32
    3.21 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Debug|Win32.Build.0 = Debug|Win32
    3.22 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Debug|x64.ActiveCfg = Debug|Win32
    3.23 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Release_NoSTDIO|Win32.ActiveCfg = Release|Win32
    3.24 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Release_NoSTDIO|Win32.Build.0 = Release|Win32
    3.25 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Release_NoSTDIO|x64.ActiveCfg = Release|Win32
    3.26 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Release|Win32.ActiveCfg = Release|Win32
    3.27 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Release|Win32.Build.0 = Release|Win32
    3.28 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Release|x64.ActiveCfg = Release|Win32
    3.29  		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.ActiveCfg = Debug|Win32
    3.30  		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|Win32.Build.0 = Debug|Win32
    3.31  		{26932B24-EFC6-4E3A-B277-ED653DA37968}.Debug|x64.ActiveCfg = Debug|Win32
    3.32 @@ -418,7 +403,6 @@
    3.33  		{55812185-D13C-4022-9C81-32E0F4A08304} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
    3.34  		{9E320A14-B443-4DD7-8725-B7020DCFF730} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
    3.35  		{B51E0D74-F0A2-45A2-BD2A-8B7D95B8204A} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
    3.36 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
    3.37  		{26932B24-EFC6-4E3A-B277-ED653DA37968} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
    3.38  		{C4E04D18-EF76-4B42-B4C2-16A1BACDC0A3} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
    3.39  		{5D0930C0-7C91-4ECE-9014-7B7DDE9502E5} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
     4.1 --- a/VisualC/SDL_VS2010.sln	Wed Feb 02 14:34:24 2011 -0800
     4.2 +++ b/VisualC/SDL_VS2010.sln	Wed Feb 02 14:34:54 2011 -0800
     4.3 @@ -49,12 +49,6 @@
     4.4  		{DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}
     4.5  	EndProjectSection
     4.6  EndProject
     4.7 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testpalette", "tests\testpalette\testpalette_VS2010.vcxproj", "{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}"
     4.8 -	ProjectSection(ProjectDependencies) = postProject
     4.9 -		{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}
    4.10 -		{DA956FD3-E142-46F2-9DD5-C78BEBB56B7A} = {DA956FD3-E142-46F2-9DD5-C78BEBB56B7A}
    4.11 -	EndProjectSection
    4.12 -EndProject
    4.13  Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testvidinfo", "tests\testvidinfo\testvidinfo_VS2010.vcxproj", "{575FD095-EDAB-4BD4-B733-CD4A874F6FB0}"
    4.14  	ProjectSection(ProjectDependencies) = postProject
    4.15  		{81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68} = {81CE8DAF-EBB2-4761-8E45-B71ABCCA8C68}
    4.16 @@ -230,14 +224,6 @@
    4.17  		{55812185-D13C-4022-9C81-32E0F4A08304}.Release|Win32.ActiveCfg = Release|Win32
    4.18  		{55812185-D13C-4022-9C81-32E0F4A08304}.Release|Win32.Build.0 = Release|Win32
    4.19  		{55812185-D13C-4022-9C81-32E0F4A08304}.Release|x64.ActiveCfg = Release|Win32
    4.20 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Debug|Win32.ActiveCfg = Debug|Win32
    4.21 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Debug|Win32.Build.0 = Debug|Win32
    4.22 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Debug|x64.ActiveCfg = Debug|Win32
    4.23 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Release_NoSTDIO|Win32.ActiveCfg = Release|Win32
    4.24 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Release_NoSTDIO|x64.ActiveCfg = Release|Win32
    4.25 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Release|Win32.ActiveCfg = Release|Win32
    4.26 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Release|Win32.Build.0 = Release|Win32
    4.27 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC}.Release|x64.ActiveCfg = Release|Win32
    4.28  		{575FD095-EDAB-4BD4-B733-CD4A874F6FB0}.Debug|Win32.ActiveCfg = Debug|Win32
    4.29  		{575FD095-EDAB-4BD4-B733-CD4A874F6FB0}.Debug|Win32.Build.0 = Debug|Win32
    4.30  		{575FD095-EDAB-4BD4-B733-CD4A874F6FB0}.Debug|x64.ActiveCfg = Debug|Win32
    4.31 @@ -361,7 +347,6 @@
    4.32  		{D974A0DF-3E2E-445C-A2EB-E899E9B582CB} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
    4.33  		{272D976B-A1DF-4DEB-BD7F-5C0D330E0C7D} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
    4.34  		{55812185-D13C-4022-9C81-32E0F4A08304} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
    4.35 -		{493A8F38-5DA5-4E2D-B5E9-9E69EE4ED1DC} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
    4.36  		{575FD095-EDAB-4BD4-B733-CD4A874F6FB0} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
    4.37  		{0FFD1A21-11DB-492C-A989-E4F195B0C441} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
    4.38  		{6AF0724B-BAC1-4C9D-AFBF-F63B4A2FB8FB} = {CE748C1F-3C21-4825-AA6A-F895A023F7E7}
     5.1 --- a/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Wed Feb 02 14:34:24 2011 -0800
     5.2 +++ b/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj/project.pbxproj	Wed Feb 02 14:34:54 2011 -0800
     5.3 @@ -62,6 +62,11 @@
     5.4  		0098A5631195B4D900343137 /* OpenGLES.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0098A5621195B4D900343137 /* OpenGLES.framework */; };
     5.5  		0098A5651195B4D900343137 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0098A5641195B4D900343137 /* UIKit.framework */; };
     5.6  		0098A5851195B5E200343137 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0098A5841195B5E200343137 /* QuartzCore.framework */; };
     5.7 +		041B2CD912FA0E9E0087D585 /* SDL_render.h in Headers */ = {isa = PBXBuildFile; fileRef = 041B2CD812FA0E9E0087D585 /* SDL_render.h */; settings = {ATTRIBUTES = (Public, ); }; };
     5.8 +		041B2CF012FA0F680087D585 /* SDL_renderer_gles.c in Sources */ = {isa = PBXBuildFile; fileRef = 041B2CE912FA0F680087D585 /* SDL_renderer_gles.c */; };
     5.9 +		041B2CF112FA0F680087D585 /* SDL_render.c in Sources */ = {isa = PBXBuildFile; fileRef = 041B2CEA12FA0F680087D585 /* SDL_render.c */; };
    5.10 +		041B2CF212FA0F680087D585 /* SDL_sysrender.h in Headers */ = {isa = PBXBuildFile; fileRef = 041B2CEB12FA0F680087D585 /* SDL_sysrender.h */; };
    5.11 +		041B2CF312FA0F680087D585 /* SDL_renderer_sw.c in Sources */ = {isa = PBXBuildFile; fileRef = 041B2CED12FA0F680087D585 /* SDL_renderer_sw.c */; };
    5.12  		0420497011E6F03D007E7EC9 /* SDL_clipboardevents_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 0420496E11E6F03D007E7EC9 /* SDL_clipboardevents_c.h */; };
    5.13  		0420497111E6F03D007E7EC9 /* SDL_clipboardevents.c in Sources */ = {isa = PBXBuildFile; fileRef = 0420496F11E6F03D007E7EC9 /* SDL_clipboardevents.c */; };
    5.14  		043DD76F10FD8A0000DED673 /* SDL_alphamult.c in Sources */ = {isa = PBXBuildFile; fileRef = 043DD76B10FD8A0000DED673 /* SDL_alphamult.c */; };
    5.15 @@ -69,8 +74,8 @@
    5.16  		043DD77110FD8A0000DED673 /* SDL_blendfillrect.c in Sources */ = {isa = PBXBuildFile; fileRef = 043DD76D10FD8A0000DED673 /* SDL_blendfillrect.c */; };
    5.17  		043DD77210FD8A0000DED673 /* SDL_drawrect.c in Sources */ = {isa = PBXBuildFile; fileRef = 043DD76E10FD8A0000DED673 /* SDL_drawrect.c */; };
    5.18  		04461DEE0EA76BA3006C462D /* SDL_haptic.h in Headers */ = {isa = PBXBuildFile; fileRef = 04461DED0EA76BA3006C462D /* SDL_haptic.h */; settings = {ATTRIBUTES = (Public, ); }; };
    5.19 -		044E5FB511E6069F0076F181 /* SDL_clipboard.h in Headers */ = {isa = PBXBuildFile; fileRef = 044E5FB311E6069F0076F181 /* SDL_clipboard.h */; };
    5.20 -		044E5FB611E6069F0076F181 /* SDL_input.h in Headers */ = {isa = PBXBuildFile; fileRef = 044E5FB411E6069F0076F181 /* SDL_input.h */; };
    5.21 +		044E5FB511E6069F0076F181 /* SDL_clipboard.h in Headers */ = {isa = PBXBuildFile; fileRef = 044E5FB311E6069F0076F181 /* SDL_clipboard.h */; settings = {ATTRIBUTES = (Public, ); }; };
    5.22 +		044E5FB611E6069F0076F181 /* SDL_input.h in Headers */ = {isa = PBXBuildFile; fileRef = 044E5FB411E6069F0076F181 /* SDL_input.h */; settings = {ATTRIBUTES = (Public, ); }; };
    5.23  		044E5FB811E606EB0076F181 /* SDL_clipboard.c in Sources */ = {isa = PBXBuildFile; fileRef = 044E5FB711E606EB0076F181 /* SDL_clipboard.c */; };
    5.24  		0463873F0F0B5B7D0041FD65 /* SDL_blendline.c in Sources */ = {isa = PBXBuildFile; fileRef = 046387370F0B5B7D0041FD65 /* SDL_blendline.c */; };
    5.25  		046387400F0B5B7D0041FD65 /* SDL_blendpoint.c in Sources */ = {isa = PBXBuildFile; fileRef = 046387380F0B5B7D0041FD65 /* SDL_blendpoint.c */; };
    5.26 @@ -86,10 +91,6 @@
    5.27  		047AF1B30EA98D6C00811173 /* SDL_sysloadso.c in Sources */ = {isa = PBXBuildFile; fileRef = 047AF1B20EA98D6C00811173 /* SDL_sysloadso.c */; };
    5.28  		0495E68A0E97408800152DFE /* SDL_glesfuncs.h in Headers */ = {isa = PBXBuildFile; fileRef = 0495E6840E97408800152DFE /* SDL_glesfuncs.h */; };
    5.29  		0495E68B0E97408800152DFE /* SDL_glfuncs.h in Headers */ = {isa = PBXBuildFile; fileRef = 0495E6850E97408800152DFE /* SDL_glfuncs.h */; };
    5.30 -		0495E68C0E97408800152DFE /* SDL_renderer_gl.c in Sources */ = {isa = PBXBuildFile; fileRef = 0495E6860E97408800152DFE /* SDL_renderer_gl.c */; };
    5.31 -		0495E68D0E97408800152DFE /* SDL_renderer_gl.h in Headers */ = {isa = PBXBuildFile; fileRef = 0495E6870E97408800152DFE /* SDL_renderer_gl.h */; };
    5.32 -		0495E68E0E97408800152DFE /* SDL_renderer_gles.c in Sources */ = {isa = PBXBuildFile; fileRef = 0495E6880E97408800152DFE /* SDL_renderer_gles.c */; };
    5.33 -		0495E68F0E97408800152DFE /* SDL_renderer_gles.h in Headers */ = {isa = PBXBuildFile; fileRef = 0495E6890E97408800152DFE /* SDL_renderer_gles.h */; };
    5.34  		04B2ECEC1025CE4800F9BC5F /* SDL_atomic.h in Headers */ = {isa = PBXBuildFile; fileRef = 04B2ECE61025CE4800F9BC5F /* SDL_atomic.h */; settings = {ATTRIBUTES = (Public, ); }; };
    5.35  		04B2ECED1025CE4800F9BC5F /* SDL_power.h in Headers */ = {isa = PBXBuildFile; fileRef = 04B2ECE71025CE4800F9BC5F /* SDL_power.h */; settings = {ATTRIBUTES = (Public, ); }; };
    5.36  		04B2ECEE1025CE4800F9BC5F /* SDL_revision.h in Headers */ = {isa = PBXBuildFile; fileRef = 04B2ECE81025CE4800F9BC5F /* SDL_revision.h */; settings = {ATTRIBUTES = (Public, ); }; };
    5.37 @@ -98,16 +99,15 @@
    5.38  		04BA9D6411EF474A00B60E01 /* SDL_gesture.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BA9D6011EF474A00B60E01 /* SDL_gesture.c */; };
    5.39  		04BA9D6511EF474A00B60E01 /* SDL_touch_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D6111EF474A00B60E01 /* SDL_touch_c.h */; };
    5.40  		04BA9D6611EF474A00B60E01 /* SDL_touch.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BA9D6211EF474A00B60E01 /* SDL_touch.c */; };
    5.41 -		04BA9D7D11EF497E00B60E01 /* SDL_gesture.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D7B11EF497E00B60E01 /* SDL_gesture.h */; };
    5.42 -		04BA9D7E11EF497E00B60E01 /* SDL_touch.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D7C11EF497E00B60E01 /* SDL_touch.h */; };
    5.43 -		04EC8B521025D12900431D42 /* SDL_config_iphoneos.h in Headers */ = {isa = PBXBuildFile; fileRef = 04EC8B501025D12900431D42 /* SDL_config_iphoneos.h */; };
    5.44 -		04F2AF541104ABC300D6DDF7 /* SDL_assert.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F2AF531104ABC300D6DDF7 /* SDL_assert.h */; };
    5.45 +		04BA9D7D11EF497E00B60E01 /* SDL_gesture.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D7B11EF497E00B60E01 /* SDL_gesture.h */; settings = {ATTRIBUTES = (Public, ); }; };
    5.46 +		04BA9D7E11EF497E00B60E01 /* SDL_touch.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BA9D7C11EF497E00B60E01 /* SDL_touch.h */; settings = {ATTRIBUTES = (Public, ); }; };
    5.47 +		04EC8B521025D12900431D42 /* SDL_config_iphoneos.h in Headers */ = {isa = PBXBuildFile; fileRef = 04EC8B501025D12900431D42 /* SDL_config_iphoneos.h */; settings = {ATTRIBUTES = (Public, ); }; };
    5.48 +		04F2AF541104ABC300D6DDF7 /* SDL_assert.h in Headers */ = {isa = PBXBuildFile; fileRef = 04F2AF531104ABC300D6DDF7 /* SDL_assert.h */; settings = {ATTRIBUTES = (Public, ); }; };
    5.49  		04F2AF561104ABD200D6DDF7 /* SDL_assert.c in Sources */ = {isa = PBXBuildFile; fileRef = 04F2AF551104ABD200D6DDF7 /* SDL_assert.c */; };
    5.50  		04FFAB8B12E23B8D00BA343D /* SDL_atomic.c in Sources */ = {isa = PBXBuildFile; fileRef = 04FFAB8912E23B8D00BA343D /* SDL_atomic.c */; };
    5.51  		04FFAB8C12E23B8D00BA343D /* SDL_spinlock.c in Sources */ = {isa = PBXBuildFile; fileRef = 04FFAB8A12E23B8D00BA343D /* SDL_spinlock.c */; };
    5.52 -		04FFAB9612E23BDC00BA343D /* SDL_blendmode.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */; };
    5.53 -		04FFAB9712E23BDC00BA343D /* SDL_scalemode.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9412E23BDC00BA343D /* SDL_scalemode.h */; };
    5.54 -		04FFAB9812E23BDC00BA343D /* SDL_shape.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9512E23BDC00BA343D /* SDL_shape.h */; };
    5.55 +		04FFAB9612E23BDC00BA343D /* SDL_blendmode.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */; settings = {ATTRIBUTES = (Public, ); }; };
    5.56 +		04FFAB9812E23BDC00BA343D /* SDL_shape.h in Headers */ = {isa = PBXBuildFile; fileRef = 04FFAB9512E23BDC00BA343D /* SDL_shape.h */; settings = {ATTRIBUTES = (Public, ); }; };
    5.57  		56ED04E1118A8EE200A56AA6 /* SDL_power.c in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E0118A8EE200A56AA6 /* SDL_power.c */; };
    5.58  		56ED04E3118A8EFD00A56AA6 /* SDL_syspower.m in Sources */ = {isa = PBXBuildFile; fileRef = 56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */; };
    5.59  		FD24846D0E5655AE0021E198 /* SDL_uikitkeyboard.h in Headers */ = {isa = PBXBuildFile; fileRef = FD24846B0E5655AE0021E198 /* SDL_uikitkeyboard.h */; };
    5.60 @@ -198,7 +198,6 @@
    5.61  		FD689F270E26E5D900F90B21 /* SDL_uikitopenglview.m in Sources */ = {isa = PBXBuildFile; fileRef = FD689F170E26E5D900F90B21 /* SDL_uikitopenglview.m */; };
    5.62  		FD689FCE0E26E9D400F90B21 /* SDL_uikitappdelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = FD689FCC0E26E9D400F90B21 /* SDL_uikitappdelegate.m */; };
    5.63  		FD689FCF0E26E9D400F90B21 /* SDL_uikitappdelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = FD689FCD0E26E9D400F90B21 /* SDL_uikitappdelegate.h */; };
    5.64 -		FD6C83B60DEA66E500ABEE55 /* SDL_systimer.h in Headers */ = {isa = PBXBuildFile; fileRef = FD99BA2D0DD52EDC00FB1D6B /* SDL_systimer.h */; };
    5.65  		FD8BD7AC0E27DCA400B52CD5 /* SDL_opengles.h in Headers */ = {isa = PBXBuildFile; fileRef = FD8BD7AB0E27DCA400B52CD5 /* SDL_opengles.h */; settings = {ATTRIBUTES = (Public, ); }; };
    5.66  		FD8BD8250E27E25900B52CD5 /* SDL_sysloadso.c in Sources */ = {isa = PBXBuildFile; fileRef = FD8BD8190E27E25900B52CD5 /* SDL_sysloadso.c */; };
    5.67  		FDA6844D0DF2374E00F98A1A /* SDL_blit.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA683000DF2374E00F98A1A /* SDL_blit.c */; };
    5.68 @@ -218,9 +217,6 @@
    5.69  		FDA6845C0DF2374E00F98A1A /* SDL_pixels.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA6830F0DF2374E00F98A1A /* SDL_pixels.c */; };
    5.70  		FDA6845D0DF2374E00F98A1A /* SDL_pixels_c.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA683100DF2374E00F98A1A /* SDL_pixels_c.h */; };
    5.71  		FDA6845E0DF2374E00F98A1A /* SDL_rect.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA683110DF2374E00F98A1A /* SDL_rect.c */; };
    5.72 -		FDA6845F0DF2374E00F98A1A /* SDL_rect_c.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA683120DF2374E00F98A1A /* SDL_rect_c.h */; };
    5.73 -		FDA684600DF2374E00F98A1A /* SDL_renderer_sw.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA683130DF2374E00F98A1A /* SDL_renderer_sw.c */; };
    5.74 -		FDA684610DF2374E00F98A1A /* SDL_renderer_sw.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA683140DF2374E00F98A1A /* SDL_renderer_sw.h */; };
    5.75  		FDA684620DF2374E00F98A1A /* SDL_RLEaccel.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA683150DF2374E00F98A1A /* SDL_RLEaccel.c */; };
    5.76  		FDA684630DF2374E00F98A1A /* SDL_RLEaccel_c.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA683160DF2374E00F98A1A /* SDL_RLEaccel_c.h */; };
    5.77  		FDA684640DF2374E00F98A1A /* SDL_stretch.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA683170DF2374E00F98A1A /* SDL_stretch.c */; };
    5.78 @@ -232,8 +228,6 @@
    5.79  		FDA6846B0DF2374E00F98A1A /* SDL_yuv_sw_c.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA6831E0DF2374E00F98A1A /* SDL_yuv_sw_c.h */; };
    5.80  		FDA685FB0DF244C800F98A1A /* SDL_nullevents.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA685F50DF244C800F98A1A /* SDL_nullevents.c */; };
    5.81  		FDA685FC0DF244C800F98A1A /* SDL_nullevents_c.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA685F60DF244C800F98A1A /* SDL_nullevents_c.h */; };
    5.82 -		FDA685FD0DF244C800F98A1A /* SDL_nullrender.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA685F70DF244C800F98A1A /* SDL_nullrender.c */; };
    5.83 -		FDA685FE0DF244C800F98A1A /* SDL_nullrender_c.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA685F80DF244C800F98A1A /* SDL_nullrender_c.h */; };
    5.84  		FDA685FF0DF244C800F98A1A /* SDL_nullvideo.c in Sources */ = {isa = PBXBuildFile; fileRef = FDA685F90DF244C800F98A1A /* SDL_nullvideo.c */; };
    5.85  		FDA686000DF244C800F98A1A /* SDL_nullvideo.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA685FA0DF244C800F98A1A /* SDL_nullvideo.h */; };
    5.86  		FDC656480E560DF800311C8E /* jumphack.c in Sources */ = {isa = PBXBuildFile; fileRef = FDC656440E560DF800311C8E /* jumphack.c */; };
    5.87 @@ -323,6 +317,11 @@
    5.88  		0098A5621195B4D900343137 /* OpenGLES.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = OpenGLES.framework; path = System/Library/Frameworks/OpenGLES.framework; sourceTree = SDKROOT; };
    5.89  		0098A5641195B4D900343137 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
    5.90  		0098A5841195B5E200343137 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
    5.91 +		041B2CD812FA0E9E0087D585 /* SDL_render.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_render.h; path = ../../include/SDL_render.h; sourceTree = SOURCE_ROOT; };
    5.92 +		041B2CE912FA0F680087D585 /* SDL_renderer_gles.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_renderer_gles.c; sourceTree = "<group>"; };
    5.93 +		041B2CEA12FA0F680087D585 /* SDL_render.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_render.c; sourceTree = "<group>"; };
    5.94 +		041B2CEB12FA0F680087D585 /* SDL_sysrender.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_sysrender.h; sourceTree = "<group>"; };
    5.95 +		041B2CED12FA0F680087D585 /* SDL_renderer_sw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_renderer_sw.c; sourceTree = "<group>"; };
    5.96  		0420496E11E6F03D007E7EC9 /* SDL_clipboardevents_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_clipboardevents_c.h; sourceTree = "<group>"; };
    5.97  		0420496F11E6F03D007E7EC9 /* SDL_clipboardevents.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_clipboardevents.c; sourceTree = "<group>"; };
    5.98  		043DD76B10FD8A0000DED673 /* SDL_alphamult.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_alphamult.c; sourceTree = "<group>"; };
    5.99 @@ -347,10 +346,6 @@
   5.100  		047AF1B20EA98D6C00811173 /* SDL_sysloadso.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_sysloadso.c; sourceTree = "<group>"; };
   5.101  		0495E6840E97408800152DFE /* SDL_glesfuncs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_glesfuncs.h; sourceTree = "<group>"; };
   5.102  		0495E6850E97408800152DFE /* SDL_glfuncs.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_glfuncs.h; sourceTree = "<group>"; };
   5.103 -		0495E6860E97408800152DFE /* SDL_renderer_gl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_renderer_gl.c; sourceTree = "<group>"; };
   5.104 -		0495E6870E97408800152DFE /* SDL_renderer_gl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_renderer_gl.h; sourceTree = "<group>"; };
   5.105 -		0495E6880E97408800152DFE /* SDL_renderer_gles.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_renderer_gles.c; sourceTree = "<group>"; };
   5.106 -		0495E6890E97408800152DFE /* SDL_renderer_gles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_renderer_gles.h; sourceTree = "<group>"; };
   5.107  		04B2ECE61025CE4800F9BC5F /* SDL_atomic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_atomic.h; path = ../../include/SDL_atomic.h; sourceTree = SOURCE_ROOT; };
   5.108  		04B2ECE71025CE4800F9BC5F /* SDL_power.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_power.h; path = ../../include/SDL_power.h; sourceTree = SOURCE_ROOT; };
   5.109  		04B2ECE81025CE4800F9BC5F /* SDL_revision.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_revision.h; path = ../../include/SDL_revision.h; sourceTree = SOURCE_ROOT; };
   5.110 @@ -367,7 +362,6 @@
   5.111  		04FFAB8912E23B8D00BA343D /* SDL_atomic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_atomic.c; sourceTree = "<group>"; };
   5.112  		04FFAB8A12E23B8D00BA343D /* SDL_spinlock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_spinlock.c; sourceTree = "<group>"; };
   5.113  		04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_blendmode.h; path = ../../include/SDL_blendmode.h; sourceTree = SOURCE_ROOT; };
   5.114 -		04FFAB9412E23BDC00BA343D /* SDL_scalemode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_scalemode.h; path = ../../include/SDL_scalemode.h; sourceTree = SOURCE_ROOT; };
   5.115  		04FFAB9512E23BDC00BA343D /* SDL_shape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_shape.h; path = ../../include/SDL_shape.h; sourceTree = SOURCE_ROOT; };
   5.116  		56ED04E0118A8EE200A56AA6 /* SDL_power.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_power.c; path = ../../src/power/SDL_power.c; sourceTree = SOURCE_ROOT; };
   5.117  		56ED04E2118A8EFD00A56AA6 /* SDL_syspower.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SDL_syspower.m; path = ../../src/power/uikit/SDL_syspower.m; sourceTree = SOURCE_ROOT; };
   5.118 @@ -458,7 +452,6 @@
   5.119  		FD99B98E0DD52EDC00FB1D6B /* default_cursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = default_cursor.h; sourceTree = "<group>"; };
   5.120  		FD99B98F0DD52EDC00FB1D6B /* scancodes_darwin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scancodes_darwin.h; sourceTree = "<group>"; };
   5.121  		FD99B9900DD52EDC00FB1D6B /* scancodes_linux.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scancodes_linux.h; sourceTree = "<group>"; };
   5.122 -		FD99B9910DD52EDC00FB1D6B /* scancodes_win32.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scancodes_win32.h; sourceTree = "<group>"; };
   5.123  		FD99B9920DD52EDC00FB1D6B /* scancodes_xfree86.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scancodes_xfree86.h; sourceTree = "<group>"; };
   5.124  		FD99B9930DD52EDC00FB1D6B /* SDL_events.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_events.c; sourceTree = "<group>"; };
   5.125  		FD99B9940DD52EDC00FB1D6B /* SDL_events_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_events_c.h; sourceTree = "<group>"; };
   5.126 @@ -486,7 +479,6 @@
   5.127  		FD99BA140DD52EDC00FB1D6B /* SDL_systhread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_systhread.h; sourceTree = "<group>"; };
   5.128  		FD99BA150DD52EDC00FB1D6B /* SDL_thread.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_thread.c; sourceTree = "<group>"; };
   5.129  		FD99BA160DD52EDC00FB1D6B /* SDL_thread_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_thread_c.h; sourceTree = "<group>"; };
   5.130 -		FD99BA2D0DD52EDC00FB1D6B /* SDL_systimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_systimer.h; sourceTree = "<group>"; };
   5.131  		FD99BA2E0DD52EDC00FB1D6B /* SDL_timer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_timer.c; sourceTree = "<group>"; };
   5.132  		FD99BA2F0DD52EDC00FB1D6B /* SDL_timer_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_timer_c.h; sourceTree = "<group>"; };
   5.133  		FD99BA310DD52EDC00FB1D6B /* SDL_systimer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_systimer.c; sourceTree = "<group>"; };
   5.134 @@ -507,9 +499,6 @@
   5.135  		FDA6830F0DF2374E00F98A1A /* SDL_pixels.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_pixels.c; sourceTree = "<group>"; };
   5.136  		FDA683100DF2374E00F98A1A /* SDL_pixels_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_pixels_c.h; sourceTree = "<group>"; };
   5.137  		FDA683110DF2374E00F98A1A /* SDL_rect.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_rect.c; sourceTree = "<group>"; };
   5.138 -		FDA683120DF2374E00F98A1A /* SDL_rect_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_rect_c.h; sourceTree = "<group>"; };
   5.139 -		FDA683130DF2374E00F98A1A /* SDL_renderer_sw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_renderer_sw.c; sourceTree = "<group>"; };
   5.140 -		FDA683140DF2374E00F98A1A /* SDL_renderer_sw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_renderer_sw.h; sourceTree = "<group>"; };
   5.141  		FDA683150DF2374E00F98A1A /* SDL_RLEaccel.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_RLEaccel.c; sourceTree = "<group>"; };
   5.142  		FDA683160DF2374E00F98A1A /* SDL_RLEaccel_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_RLEaccel_c.h; sourceTree = "<group>"; };
   5.143  		FDA683170DF2374E00F98A1A /* SDL_stretch.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_stretch.c; sourceTree = "<group>"; };
   5.144 @@ -521,8 +510,6 @@
   5.145  		FDA6831E0DF2374E00F98A1A /* SDL_yuv_sw_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_yuv_sw_c.h; sourceTree = "<group>"; };
   5.146  		FDA685F50DF244C800F98A1A /* SDL_nullevents.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_nullevents.c; sourceTree = "<group>"; };
   5.147  		FDA685F60DF244C800F98A1A /* SDL_nullevents_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_nullevents_c.h; sourceTree = "<group>"; };
   5.148 -		FDA685F70DF244C800F98A1A /* SDL_nullrender.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_nullrender.c; sourceTree = "<group>"; };
   5.149 -		FDA685F80DF244C800F98A1A /* SDL_nullrender_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_nullrender_c.h; sourceTree = "<group>"; };
   5.150  		FDA685F90DF244C800F98A1A /* SDL_nullvideo.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_nullvideo.c; sourceTree = "<group>"; };
   5.151  		FDA685FA0DF244C800F98A1A /* SDL_nullvideo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_nullvideo.h; sourceTree = "<group>"; };
   5.152  		FDC261780E3A3FC8001C4554 /* keyinfotable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = keyinfotable.h; sourceTree = "<group>"; };
   5.153 @@ -668,6 +655,34 @@
   5.154  			path = cocoa;
   5.155  			sourceTree = "<group>";
   5.156  		};
   5.157 +		041B2CE312FA0F680087D585 /* render */ = {
   5.158 +			isa = PBXGroup;
   5.159 +			children = (
   5.160 +				041B2CE812FA0F680087D585 /* opengles */,
   5.161 +				041B2CEA12FA0F680087D585 /* SDL_render.c */,
   5.162 +				041B2CEB12FA0F680087D585 /* SDL_sysrender.h */,
   5.163 +				041B2CEC12FA0F680087D585 /* software */,
   5.164 +			);
   5.165 +			name = render;
   5.166 +			path = ../../src/render;
   5.167 +			sourceTree = SOURCE_ROOT;
   5.168 +		};
   5.169 +		041B2CE812FA0F680087D585 /* opengles */ = {
   5.170 +			isa = PBXGroup;
   5.171 +			children = (
   5.172 +				041B2CE912FA0F680087D585 /* SDL_renderer_gles.c */,
   5.173 +			);
   5.174 +			path = opengles;
   5.175 +			sourceTree = "<group>";
   5.176 +		};
   5.177 +		041B2CEC12FA0F680087D585 /* software */ = {
   5.178 +			isa = PBXGroup;
   5.179 +			children = (
   5.180 +				041B2CED12FA0F680087D585 /* SDL_renderer_sw.c */,
   5.181 +			);
   5.182 +			path = software;
   5.183 +			sourceTree = "<group>";
   5.184 +		};
   5.185  		047677B60EA769DF008ABAF1 /* haptic */ = {
   5.186  			isa = PBXGroup;
   5.187  			children = (
   5.188 @@ -849,15 +864,13 @@
   5.189  		FD99B8BC0DD52E5C00FB1D6B /* Public Headers */ = {
   5.190  			isa = PBXGroup;
   5.191  			children = (
   5.192 -				04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */,
   5.193 -				04FFAB9412E23BDC00BA343D /* SDL_scalemode.h */,
   5.194 -				04FFAB9512E23BDC00BA343D /* SDL_shape.h */,
   5.195  				FD99B8CC0DD52EB400FB1D6B /* begin_code.h */,
   5.196  				FD99B8CD0DD52EB400FB1D6B /* close_code.h */,
   5.197  				FD99B8F50DD52EB400FB1D6B /* SDL.h */,
   5.198  				04F2AF531104ABC300D6DDF7 /* SDL_assert.h */,
   5.199  				04B2ECE61025CE4800F9BC5F /* SDL_atomic.h */,
   5.200  				FD99B8CF0DD52EB400FB1D6B /* SDL_audio.h */,
   5.201 +				04FFAB9312E23BDC00BA343D /* SDL_blendmode.h */,
   5.202  				044E5FB311E6069F0076F181 /* SDL_clipboard.h */,
   5.203  				FD99B8D10DD52EB400FB1D6B /* SDL_compat.h */,
   5.204  				04B2ED061025CF9E00F9BC5F /* SDL_config.h */,
   5.205 @@ -885,9 +898,11 @@
   5.206  				04B2ECE71025CE4800F9BC5F /* SDL_power.h */,
   5.207  				FD99B8E90DD52EB400FB1D6B /* SDL_quit.h */,
   5.208  				FD99B8EA0DD52EB400FB1D6B /* SDL_rect.h */,
   5.209 +				041B2CD812FA0E9E0087D585 /* SDL_render.h */,
   5.210  				04B2ECE81025CE4800F9BC5F /* SDL_revision.h */,
   5.211  				FD99B8EB0DD52EB400FB1D6B /* SDL_rwops.h */,
   5.212  				FD99B8EC0DD52EB400FB1D6B /* SDL_scancode.h */,
   5.213 +				04FFAB9512E23BDC00BA343D /* SDL_shape.h */,
   5.214  				FD99B8ED0DD52EB400FB1D6B /* SDL_stdinc.h */,
   5.215  				FD99B8EE0DD52EB400FB1D6B /* SDL_surface.h */,
   5.216  				FD99B8EF0DD52EB400FB1D6B /* SDL_syswm.h */,
   5.217 @@ -904,13 +919,6 @@
   5.218  		FD99B8BD0DD52E6D00FB1D6B /* Library Source */ = {
   5.219  			isa = PBXGroup;
   5.220  			children = (
   5.221 -				04F2AF551104ABD200D6DDF7 /* SDL_assert.c */,
   5.222 -				FD99B9D30DD52EDC00FB1D6B /* SDL_compat.c */,
   5.223 -				FD99B9D40DD52EDC00FB1D6B /* SDL_error_c.h */,
   5.224 -				FD99B9D50DD52EDC00FB1D6B /* SDL_error.c */,
   5.225 -				FD99B9D60DD52EDC00FB1D6B /* SDL_fatal.c */,
   5.226 -				FD99B9D70DD52EDC00FB1D6B /* SDL_fatal.h */,
   5.227 -				FD99B9D80DD52EDC00FB1D6B /* SDL.c */,
   5.228  				04B2ECEF1025CEB900F9BC5F /* atomic */,
   5.229  				FD99B8FB0DD52EDC00FB1D6B /* audio */,
   5.230  				FD99B98A0DD52EDC00FB1D6B /* cpuinfo */,
   5.231 @@ -920,10 +928,18 @@
   5.232  				FD5F9D080E0E08B3008E885B /* joystick */,
   5.233  				FD8BD8150E27E25900B52CD5 /* loadso */,
   5.234  				56ED04DE118A8E9A00A56AA6 /* power */,
   5.235 +				041B2CE312FA0F680087D585 /* render */,
   5.236  				FD3F4A6F0DEA620800C5B771 /* stdlib */,
   5.237  				FD99B9E00DD52EDC00FB1D6B /* thread */,
   5.238  				FD99BA1E0DD52EDC00FB1D6B /* timer */,
   5.239  				FDA682420DF2374D00F98A1A /* video */,
   5.240 +				04F2AF551104ABD200D6DDF7 /* SDL_assert.c */,
   5.241 +				FD99B9D30DD52EDC00FB1D6B /* SDL_compat.c */,
   5.242 +				FD99B9D40DD52EDC00FB1D6B /* SDL_error_c.h */,
   5.243 +				FD99B9D50DD52EDC00FB1D6B /* SDL_error.c */,
   5.244 +				FD99B9D60DD52EDC00FB1D6B /* SDL_fatal.c */,
   5.245 +				FD99B9D70DD52EDC00FB1D6B /* SDL_fatal.h */,
   5.246 +				FD99B9D80DD52EDC00FB1D6B /* SDL.c */,
   5.247  			);
   5.248  			name = "Library Source";
   5.249  			sourceTree = "<group>";
   5.250 @@ -982,7 +998,6 @@
   5.251  				FD99B98E0DD52EDC00FB1D6B /* default_cursor.h */,
   5.252  				FD99B98F0DD52EDC00FB1D6B /* scancodes_darwin.h */,
   5.253  				FD99B9900DD52EDC00FB1D6B /* scancodes_linux.h */,
   5.254 -				FD99B9910DD52EDC00FB1D6B /* scancodes_win32.h */,
   5.255  				FD99B9920DD52EDC00FB1D6B /* scancodes_xfree86.h */,
   5.256  				0420496E11E6F03D007E7EC9 /* SDL_clipboardevents_c.h */,
   5.257  				0420496F11E6F03D007E7EC9 /* SDL_clipboardevents.c */,
   5.258 @@ -1039,10 +1054,9 @@
   5.259  		FD99BA1E0DD52EDC00FB1D6B /* timer */ = {
   5.260  			isa = PBXGroup;
   5.261  			children = (
   5.262 -				FD99BA2D0DD52EDC00FB1D6B /* SDL_systimer.h */,
   5.263 +				FD99BA300DD52EDC00FB1D6B /* unix */,
   5.264  				FD99BA2E0DD52EDC00FB1D6B /* SDL_timer.c */,
   5.265  				FD99BA2F0DD52EDC00FB1D6B /* SDL_timer_c.h */,
   5.266 -				FD99BA300DD52EDC00FB1D6B /* unix */,
   5.267  			);
   5.268  			name = timer;
   5.269  			path = ../../src/timer;
   5.270 @@ -1059,15 +1073,10 @@
   5.271  		FDA682420DF2374D00F98A1A /* video */ = {
   5.272  			isa = PBXGroup;
   5.273  			children = (
   5.274 -				044E5FB711E606EB0076F181 /* SDL_clipboard.c */,
   5.275  				FD689F090E26E5D900F90B21 /* uikit */,
   5.276  				FDA685F40DF244C800F98A1A /* dummy */,
   5.277  				0495E6850E97408800152DFE /* SDL_glfuncs.h */,
   5.278  				0495E6840E97408800152DFE /* SDL_glesfuncs.h */,
   5.279 -				0495E6860E97408800152DFE /* SDL_renderer_gl.c */,
   5.280 -				0495E6870E97408800152DFE /* SDL_renderer_gl.h */,
   5.281 -				0495E6880E97408800152DFE /* SDL_renderer_gles.c */,
   5.282 -				0495E6890E97408800152DFE /* SDL_renderer_gles.h */,
   5.283  				043DD76B10FD8A0000DED673 /* SDL_alphamult.c */,
   5.284  				043DD76C10FD8A0000DED673 /* SDL_alphamult.h */,
   5.285  				043DD76D10FD8A0000DED673 /* SDL_blendfillrect.c */,
   5.286 @@ -1087,6 +1096,7 @@
   5.287  				FDA6830A0DF2374E00F98A1A /* SDL_blit_slow.c */,
   5.288  				0463873A0F0B5B7D0041FD65 /* SDL_blit_slow.h */,
   5.289  				FDA6830B0DF2374E00F98A1A /* SDL_bmp.c */,
   5.290 +				044E5FB711E606EB0076F181 /* SDL_clipboard.c */,
   5.291  				0463873B0F0B5B7D0041FD65 /* SDL_draw.h */,
   5.292  				0463873C0F0B5B7D0041FD65 /* SDL_drawline.c */,
   5.293  				0463873D0F0B5B7D0041FD65 /* SDL_drawpoint.c */,
   5.294 @@ -1097,9 +1107,6 @@
   5.295  				FDA6830F0DF2374E00F98A1A /* SDL_pixels.c */,
   5.296  				FDA683100DF2374E00F98A1A /* SDL_pixels_c.h */,
   5.297  				FDA683110DF2374E00F98A1A /* SDL_rect.c */,
   5.298 -				FDA683120DF2374E00F98A1A /* SDL_rect_c.h */,
   5.299 -				FDA683130DF2374E00F98A1A /* SDL_renderer_sw.c */,
   5.300 -				FDA683140DF2374E00F98A1A /* SDL_renderer_sw.h */,
   5.301  				FDA683150DF2374E00F98A1A /* SDL_RLEaccel.c */,
   5.302  				FDA683160DF2374E00F98A1A /* SDL_RLEaccel_c.h */,
   5.303  				FDA683170DF2374E00F98A1A /* SDL_stretch.c */,
   5.304 @@ -1119,8 +1126,6 @@
   5.305  			children = (
   5.306  				FDA685F50DF244C800F98A1A /* SDL_nullevents.c */,
   5.307  				FDA685F60DF244C800F98A1A /* SDL_nullevents_c.h */,
   5.308 -				FDA685F70DF244C800F98A1A /* SDL_nullrender.c */,
   5.309 -				FDA685F80DF244C800F98A1A /* SDL_nullrender_c.h */,
   5.310  				FDA685F90DF244C800F98A1A /* SDL_nullvideo.c */,
   5.311  				FDA685FA0DF244C800F98A1A /* SDL_nullvideo.h */,
   5.312  			);
   5.313 @@ -1134,7 +1139,6 @@
   5.314  			isa = PBXHeadersBuildPhase;
   5.315  			buildActionMask = 2147483647;
   5.316  			files = (
   5.317 -				FD6C83B60DEA66E500ABEE55 /* SDL_systimer.h in Headers */,
   5.318  				FD3F495C0DEA5B2100C5B771 /* begin_code.h in Headers */,
   5.319  				FD3F495D0DEA5B2100C5B771 /* close_code.h in Headers */,
   5.320  				FD3F495F0DEA5B2100C5B771 /* SDL_audio.h in Headers */,
   5.321 @@ -1173,13 +1177,10 @@
   5.322  				FDA684550DF2374E00F98A1A /* SDL_blit_copy.h in Headers */,
   5.323  				FDA6845B0DF2374E00F98A1A /* SDL_leaks.h in Headers */,
   5.324  				FDA6845D0DF2374E00F98A1A /* SDL_pixels_c.h in Headers */,
   5.325 -				FDA6845F0DF2374E00F98A1A /* SDL_rect_c.h in Headers */,
   5.326 -				FDA684610DF2374E00F98A1A /* SDL_renderer_sw.h in Headers */,
   5.327  				FDA684630DF2374E00F98A1A /* SDL_RLEaccel_c.h in Headers */,
   5.328  				FDA684670DF2374E00F98A1A /* SDL_sysvideo.h in Headers */,
   5.329  				FDA6846B0DF2374E00F98A1A /* SDL_yuv_sw_c.h in Headers */,
   5.330  				FDA685FC0DF244C800F98A1A /* SDL_nullevents_c.h in Headers */,
   5.331 -				FDA685FE0DF244C800F98A1A /* SDL_nullrender_c.h in Headers */,
   5.332  				FDA686000DF244C800F98A1A /* SDL_nullvideo.h in Headers */,
   5.333  				FD5F9D300E0E08B3008E885B /* SDL_joystick_c.h in Headers */,
   5.334  				FD5F9D310E0E08B3008E885B /* SDL_sysjoystick.h in Headers */,
   5.335 @@ -1196,8 +1197,6 @@
   5.336  				FD24846D0E5655AE0021E198 /* SDL_uikitkeyboard.h in Headers */,
   5.337  				0495E68A0E97408800152DFE /* SDL_glesfuncs.h in Headers */,
   5.338  				0495E68B0E97408800152DFE /* SDL_glfuncs.h in Headers */,
   5.339 -				0495E68D0E97408800152DFE /* SDL_renderer_gl.h in Headers */,
   5.340 -				0495E68F0E97408800152DFE /* SDL_renderer_gles.h in Headers */,
   5.341  				047677BD0EA76A31008ABAF1 /* SDL_syshaptic.h in Headers */,
   5.342  				04461DEE0EA76BA3006C462D /* SDL_haptic.h in Headers */,
   5.343  				046387420F0B5B7D0041FD65 /* SDL_blit_slow.h in Headers */,
   5.344 @@ -1218,8 +1217,9 @@
   5.345  				04BA9D7D11EF497E00B60E01 /* SDL_gesture.h in Headers */,
   5.346  				04BA9D7E11EF497E00B60E01 /* SDL_touch.h in Headers */,
   5.347  				04FFAB9612E23BDC00BA343D /* SDL_blendmode.h in Headers */,
   5.348 -				04FFAB9712E23BDC00BA343D /* SDL_scalemode.h in Headers */,
   5.349  				04FFAB9812E23BDC00BA343D /* SDL_shape.h in Headers */,
   5.350 +				041B2CD912FA0E9E0087D585 /* SDL_render.h in Headers */,
   5.351 +				041B2CF212FA0F680087D585 /* SDL_sysrender.h in Headers */,
   5.352  			);
   5.353  			runOnlyForDeploymentPostprocessing = 0;
   5.354  		};
   5.355 @@ -1423,7 +1423,6 @@
   5.356  				FDA6845A0DF2374E00F98A1A /* SDL_gamma.c in Sources */,
   5.357  				FDA6845C0DF2374E00F98A1A /* SDL_pixels.c in Sources */,
   5.358  				FDA6845E0DF2374E00F98A1A /* SDL_rect.c in Sources */,
   5.359 -				FDA684600DF2374E00F98A1A /* SDL_renderer_sw.c in Sources */,
   5.360  				FDA684620DF2374E00F98A1A /* SDL_RLEaccel.c in Sources */,
   5.361  				FDA684640DF2374E00F98A1A /* SDL_stretch.c in Sources */,
   5.362  				FDA684660DF2374E00F98A1A /* SDL_surface.c in Sources */,
   5.363 @@ -1431,7 +1430,6 @@
   5.364  				FDA684690DF2374E00F98A1A /* SDL_yuv_mmx.c in Sources */,
   5.365  				FDA6846A0DF2374E00F98A1A /* SDL_yuv_sw.c in Sources */,
   5.366  				FDA685FB0DF244C800F98A1A /* SDL_nullevents.c in Sources */,
   5.367 -				FDA685FD0DF244C800F98A1A /* SDL_nullrender.c in Sources */,
   5.368  				FDA685FF0DF244C800F98A1A /* SDL_nullvideo.c in Sources */,
   5.369  				FD5F9D2F0E0E08B3008E885B /* SDL_joystick.c in Sources */,
   5.370  				FD689EFB0E26E57800F90B21 /* SDL_coreaudio_iphone.c in Sources */,
   5.371 @@ -1446,8 +1444,6 @@
   5.372  				FD689FCE0E26E9D400F90B21 /* SDL_uikitappdelegate.m in Sources */,
   5.373  				FD8BD8250E27E25900B52CD5 /* SDL_sysloadso.c in Sources */,
   5.374  				FDC656480E560DF800311C8E /* jumphack.c in Sources */,
   5.375 -				0495E68C0E97408800152DFE /* SDL_renderer_gl.c in Sources */,
   5.376 -				0495E68E0E97408800152DFE /* SDL_renderer_gles.c in Sources */,
   5.377  				047677BB0EA76A31008ABAF1 /* SDL_syshaptic.c in Sources */,
   5.378  				047677BC0EA76A31008ABAF1 /* SDL_haptic.c in Sources */,
   5.379  				047AF1B30EA98D6C00811173 /* SDL_sysloadso.c in Sources */,
   5.380 @@ -1470,6 +1466,9 @@
   5.381  				04BA9D6611EF474A00B60E01 /* SDL_touch.c in Sources */,
   5.382  				04FFAB8B12E23B8D00BA343D /* SDL_atomic.c in Sources */,
   5.383  				04FFAB8C12E23B8D00BA343D /* SDL_spinlock.c in Sources */,
   5.384 +				041B2CF012FA0F680087D585 /* SDL_renderer_gles.c in Sources */,
   5.385 +				041B2CF112FA0F680087D585 /* SDL_render.c in Sources */,
   5.386 +				041B2CF312FA0F680087D585 /* SDL_renderer_sw.c in Sources */,
   5.387  			);
   5.388  			runOnlyForDeploymentPostprocessing = 0;
   5.389  		};
     6.1 --- a/Xcode/SDL/SDL.xcodeproj/project.pbxproj	Wed Feb 02 14:34:24 2011 -0800
     6.2 +++ b/Xcode/SDL/SDL.xcodeproj/project.pbxproj	Wed Feb 02 14:34:54 2011 -0800
     6.3 @@ -121,12 +121,20 @@
     6.4  		00D8DA281195093100638393 /* SDL_at.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D8DA151195093100638393 /* SDL_at.c */; };
     6.5  		00D8DA291195093100638393 /* surface.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D8DA181195093100638393 /* surface.c */; };
     6.6  		00D8DA2A1195093100638393 /* testsdl.c in Sources */ = {isa = PBXBuildFile; fileRef = 00D8DA1A1195093100638393 /* testsdl.c */; };
     6.7 +		041B2C9512FA0D2A0087D585 /* SDL_render.h in Headers */ = {isa = PBXBuildFile; fileRef = 041B2C9412FA0D2A0087D585 /* SDL_render.h */; settings = {ATTRIBUTES = (Public, ); }; };
     6.8 +		041B2C9612FA0D2A0087D585 /* SDL_render.h in Headers */ = {isa = PBXBuildFile; fileRef = 041B2C9412FA0D2A0087D585 /* SDL_render.h */; };
     6.9 +		041B2CA312FA0D680087D585 /* SDL_renderer_gl.c in Sources */ = {isa = PBXBuildFile; fileRef = 041B2C9B12FA0D680087D585 /* SDL_renderer_gl.c */; };
    6.10 +		041B2CA512FA0D680087D585 /* SDL_render.c in Sources */ = {isa = PBXBuildFile; fileRef = 041B2C9E12FA0D680087D585 /* SDL_render.c */; };
    6.11 +		041B2CA612FA0D680087D585 /* SDL_sysrender.h in Headers */ = {isa = PBXBuildFile; fileRef = 041B2C9F12FA0D680087D585 /* SDL_sysrender.h */; };
    6.12 +		041B2CA712FA0D680087D585 /* SDL_renderer_sw.c in Sources */ = {isa = PBXBuildFile; fileRef = 041B2CA112FA0D680087D585 /* SDL_renderer_sw.c */; };
    6.13 +		041B2CA912FA0D680087D585 /* SDL_renderer_gl.c in Sources */ = {isa = PBXBuildFile; fileRef = 041B2C9B12FA0D680087D585 /* SDL_renderer_gl.c */; };
    6.14 +		041B2CAB12FA0D680087D585 /* SDL_render.c in Sources */ = {isa = PBXBuildFile; fileRef = 041B2C9E12FA0D680087D585 /* SDL_render.c */; };
    6.15 +		041B2CAC12FA0D680087D585 /* SDL_sysrender.h in Headers */ = {isa = PBXBuildFile; fileRef = 041B2C9F12FA0D680087D585 /* SDL_sysrender.h */; };
    6.16 +		041B2CAD12FA0D680087D585 /* SDL_renderer_sw.c in Sources */ = {isa = PBXBuildFile; fileRef = 041B2CA112FA0D680087D585 /* SDL_renderer_sw.c */; };
    6.17  		044E5F8511E6051C0076F181 /* SDL_clipboard.h in Headers */ = {isa = PBXBuildFile; fileRef = 044E5F8411E6051C0076F181 /* SDL_clipboard.h */; settings = {ATTRIBUTES = (Public, ); }; };
    6.18  		044E5F8611E6051C0076F181 /* SDL_clipboard.h in Headers */ = {isa = PBXBuildFile; fileRef = 044E5F8411E6051C0076F181 /* SDL_clipboard.h */; };
    6.19  		0469A10B12EE4BF100B846D6 /* SDL_blendmode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0469A10912EE4BF100B846D6 /* SDL_blendmode.h */; settings = {ATTRIBUTES = (Public, ); }; };
    6.20 -		0469A10C12EE4BF100B846D6 /* SDL_scalemode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0469A10A12EE4BF100B846D6 /* SDL_scalemode.h */; settings = {ATTRIBUTES = (Public, ); }; };
    6.21  		0469A10D12EE4BF100B846D6 /* SDL_blendmode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0469A10912EE4BF100B846D6 /* SDL_blendmode.h */; };
    6.22 -		0469A10E12EE4BF100B846D6 /* SDL_scalemode.h in Headers */ = {isa = PBXBuildFile; fileRef = 0469A10A12EE4BF100B846D6 /* SDL_scalemode.h */; };
    6.23  		04BD000812E6671800899322 /* SDL_diskaudio.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFD8812E6671700899322 /* SDL_diskaudio.c */; };
    6.24  		04BD000912E6671800899322 /* SDL_diskaudio.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFD8912E6671700899322 /* SDL_diskaudio.h */; };
    6.25  		04BD001012E6671800899322 /* SDL_dummyaudio.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFD9412E6671700899322 /* SDL_dummyaudio.c */; };
    6.26 @@ -155,7 +163,6 @@
    6.27  		04BD004312E6671800899322 /* default_cursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFDD712E6671700899322 /* default_cursor.h */; };
    6.28  		04BD004412E6671800899322 /* scancodes_darwin.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFDD812E6671700899322 /* scancodes_darwin.h */; };
    6.29  		04BD004512E6671800899322 /* scancodes_linux.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFDD912E6671700899322 /* scancodes_linux.h */; };
    6.30 -		04BD004612E6671800899322 /* scancodes_win32.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFDDA12E6671700899322 /* scancodes_win32.h */; };
    6.31  		04BD004712E6671800899322 /* scancodes_xfree86.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFDDB12E6671700899322 /* scancodes_xfree86.h */; };
    6.32  		04BD004812E6671800899322 /* SDL_clipboardevents.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFDDC12E6671700899322 /* SDL_clipboardevents.c */; };
    6.33  		04BD004912E6671800899322 /* SDL_clipboardevents_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFDDD12E6671700899322 /* SDL_clipboardevents_c.h */; };
    6.34 @@ -212,7 +219,6 @@
    6.35  		04BD00C912E6671800899322 /* SDL_systhread.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFE8B12E6671800899322 /* SDL_systhread.h */; };
    6.36  		04BD00CA12E6671800899322 /* SDL_thread.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFE8C12E6671800899322 /* SDL_thread.c */; };
    6.37  		04BD00CB12E6671800899322 /* SDL_thread_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFE8D12E6671800899322 /* SDL_thread_c.h */; };
    6.38 -		04BD00D612E6671800899322 /* SDL_systimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFE9E12E6671800899322 /* SDL_systimer.h */; };
    6.39  		04BD00D712E6671800899322 /* SDL_timer.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFE9F12E6671800899322 /* SDL_timer.c */; };
    6.40  		04BD00D812E6671800899322 /* SDL_timer_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFEA012E6671800899322 /* SDL_timer_c.h */; };
    6.41  		04BD00D912E6671800899322 /* SDL_systimer.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFEA212E6671800899322 /* SDL_systimer.c */; };
    6.42 @@ -236,8 +242,6 @@
    6.43  		04BD010412E6671800899322 /* SDL_cocoawindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFED312E6671800899322 /* SDL_cocoawindow.m */; };
    6.44  		04BD011712E6671800899322 /* SDL_nullevents.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFEE812E6671800899322 /* SDL_nullevents.c */; };
    6.45  		04BD011812E6671800899322 /* SDL_nullevents_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFEE912E6671800899322 /* SDL_nullevents_c.h */; };
    6.46 -		04BD011912E6671800899322 /* SDL_nullrender.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFEEA12E6671800899322 /* SDL_nullrender.c */; };
    6.47 -		04BD011A12E6671800899322 /* SDL_nullrender_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFEEB12E6671800899322 /* SDL_nullrender_c.h */; };
    6.48  		04BD011B12E6671800899322 /* SDL_nullvideo.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFEEC12E6671800899322 /* SDL_nullvideo.c */; };
    6.49  		04BD011C12E6671800899322 /* SDL_nullvideo.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFEED12E6671800899322 /* SDL_nullvideo.h */; };
    6.50  		04BD013212E6671800899322 /* mmx.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF0412E6671800899322 /* mmx.h */; };
    6.51 @@ -273,13 +277,6 @@
    6.52  		04BD018C12E6671800899322 /* SDL_pixels.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF6512E6671800899322 /* SDL_pixels.c */; };
    6.53  		04BD018D12E6671800899322 /* SDL_pixels_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF6612E6671800899322 /* SDL_pixels_c.h */; };
    6.54  		04BD018E12E6671800899322 /* SDL_rect.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF6712E6671800899322 /* SDL_rect.c */; };
    6.55 -		04BD018F12E6671800899322 /* SDL_rect_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF6812E6671800899322 /* SDL_rect_c.h */; };
    6.56 -		04BD019012E6671800899322 /* SDL_renderer_gl.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF6912E6671800899322 /* SDL_renderer_gl.c */; };
    6.57 -		04BD019112E6671800899322 /* SDL_renderer_gl.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF6A12E6671800899322 /* SDL_renderer_gl.h */; };
    6.58 -		04BD019212E6671800899322 /* SDL_renderer_gles.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF6B12E6671800899322 /* SDL_renderer_gles.c */; };
    6.59 -		04BD019312E6671800899322 /* SDL_renderer_gles.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF6C12E6671800899322 /* SDL_renderer_gles.h */; };
    6.60 -		04BD019412E6671800899322 /* SDL_renderer_sw.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF6D12E6671800899322 /* SDL_renderer_sw.c */; };
    6.61 -		04BD019512E6671800899322 /* SDL_renderer_sw.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF6E12E6671800899322 /* SDL_renderer_sw.h */; };
    6.62  		04BD019612E6671800899322 /* SDL_RLEaccel.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF6F12E6671800899322 /* SDL_RLEaccel.c */; };
    6.63  		04BD019712E6671800899322 /* SDL_RLEaccel_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF7012E6671800899322 /* SDL_RLEaccel_c.h */; };
    6.64  		04BD019812E6671800899322 /* SDL_shape.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF7112E6671800899322 /* SDL_shape.c */; };
    6.65 @@ -311,8 +308,6 @@
    6.66  		04BD01EC12E6671800899322 /* SDL_x11opengl.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFFC912E6671800899322 /* SDL_x11opengl.h */; };
    6.67  		04BD01ED12E6671800899322 /* SDL_x11opengles.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFFCA12E6671800899322 /* SDL_x11opengles.c */; };
    6.68  		04BD01EE12E6671800899322 /* SDL_x11opengles.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFFCB12E6671800899322 /* SDL_x11opengles.h */; };
    6.69 -		04BD01EF12E6671800899322 /* SDL_x11render.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFFCC12E6671800899322 /* SDL_x11render.c */; };
    6.70 -		04BD01F012E6671800899322 /* SDL_x11render.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFFCD12E6671800899322 /* SDL_x11render.h */; };
    6.71  		04BD01F112E6671800899322 /* SDL_x11shape.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFFCE12E6671800899322 /* SDL_x11shape.c */; };
    6.72  		04BD01F212E6671800899322 /* SDL_x11shape.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFFCF12E6671800899322 /* SDL_x11shape.h */; };
    6.73  		04BD01F312E6671800899322 /* SDL_x11sym.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFFD012E6671800899322 /* SDL_x11sym.h */; };
    6.74 @@ -381,7 +376,6 @@
    6.75  		04BD025E12E6671800899322 /* default_cursor.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFDD712E6671700899322 /* default_cursor.h */; };
    6.76  		04BD025F12E6671800899322 /* scancodes_darwin.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFDD812E6671700899322 /* scancodes_darwin.h */; };
    6.77  		04BD026012E6671800899322 /* scancodes_linux.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFDD912E6671700899322 /* scancodes_linux.h */; };
    6.78 -		04BD026112E6671800899322 /* scancodes_win32.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFDDA12E6671700899322 /* scancodes_win32.h */; };
    6.79  		04BD026212E6671800899322 /* scancodes_xfree86.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFDDB12E6671700899322 /* scancodes_xfree86.h */; };
    6.80  		04BD026312E6671800899322 /* SDL_clipboardevents.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFDDC12E6671700899322 /* SDL_clipboardevents.c */; };
    6.81  		04BD026412E6671800899322 /* SDL_clipboardevents_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFDDD12E6671700899322 /* SDL_clipboardevents_c.h */; };
    6.82 @@ -438,7 +432,6 @@
    6.83  		04BD02E312E6671800899322 /* SDL_systhread.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFE8B12E6671800899322 /* SDL_systhread.h */; };
    6.84  		04BD02E412E6671800899322 /* SDL_thread.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFE8C12E6671800899322 /* SDL_thread.c */; };
    6.85  		04BD02E512E6671800899322 /* SDL_thread_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFE8D12E6671800899322 /* SDL_thread_c.h */; };
    6.86 -		04BD02F012E6671800899322 /* SDL_systimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFE9E12E6671800899322 /* SDL_systimer.h */; };
    6.87  		04BD02F112E6671800899322 /* SDL_timer.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFE9F12E6671800899322 /* SDL_timer.c */; };
    6.88  		04BD02F212E6671800899322 /* SDL_timer_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFEA012E6671800899322 /* SDL_timer_c.h */; };
    6.89  		04BD02F312E6671800899322 /* SDL_systimer.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFEA212E6671800899322 /* SDL_systimer.c */; };
    6.90 @@ -462,8 +455,6 @@
    6.91  		04BD031E12E6671800899322 /* SDL_cocoawindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFED312E6671800899322 /* SDL_cocoawindow.m */; };
    6.92  		04BD033112E6671800899322 /* SDL_nullevents.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFEE812E6671800899322 /* SDL_nullevents.c */; };
    6.93  		04BD033212E6671800899322 /* SDL_nullevents_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFEE912E6671800899322 /* SDL_nullevents_c.h */; };
    6.94 -		04BD033312E6671800899322 /* SDL_nullrender.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFEEA12E6671800899322 /* SDL_nullrender.c */; };
    6.95 -		04BD033412E6671800899322 /* SDL_nullrender_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFEEB12E6671800899322 /* SDL_nullrender_c.h */; };
    6.96  		04BD033512E6671800899322 /* SDL_nullvideo.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFEEC12E6671800899322 /* SDL_nullvideo.c */; };
    6.97  		04BD033612E6671800899322 /* SDL_nullvideo.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFEED12E6671800899322 /* SDL_nullvideo.h */; };
    6.98  		04BD034C12E6671800899322 /* mmx.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF0412E6671800899322 /* mmx.h */; };
    6.99 @@ -499,13 +490,6 @@
   6.100  		04BD03A612E6671800899322 /* SDL_pixels.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF6512E6671800899322 /* SDL_pixels.c */; };
   6.101  		04BD03A712E6671800899322 /* SDL_pixels_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF6612E6671800899322 /* SDL_pixels_c.h */; };
   6.102  		04BD03A812E6671800899322 /* SDL_rect.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF6712E6671800899322 /* SDL_rect.c */; };
   6.103 -		04BD03A912E6671800899322 /* SDL_rect_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF6812E6671800899322 /* SDL_rect_c.h */; };
   6.104 -		04BD03AA12E6671800899322 /* SDL_renderer_gl.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF6912E6671800899322 /* SDL_renderer_gl.c */; };
   6.105 -		04BD03AB12E6671800899322 /* SDL_renderer_gl.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF6A12E6671800899322 /* SDL_renderer_gl.h */; };
   6.106 -		04BD03AC12E6671800899322 /* SDL_renderer_gles.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF6B12E6671800899322 /* SDL_renderer_gles.c */; };
   6.107 -		04BD03AD12E6671800899322 /* SDL_renderer_gles.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF6C12E6671800899322 /* SDL_renderer_gles.h */; };
   6.108 -		04BD03AE12E6671800899322 /* SDL_renderer_sw.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF6D12E6671800899322 /* SDL_renderer_sw.c */; };
   6.109 -		04BD03AF12E6671800899322 /* SDL_renderer_sw.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF6E12E6671800899322 /* SDL_renderer_sw.h */; };
   6.110  		04BD03B012E6671800899322 /* SDL_RLEaccel.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF6F12E6671800899322 /* SDL_RLEaccel.c */; };
   6.111  		04BD03B112E6671800899322 /* SDL_RLEaccel_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFF7012E6671800899322 /* SDL_RLEaccel_c.h */; };
   6.112  		04BD03B212E6671800899322 /* SDL_shape.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFF7112E6671800899322 /* SDL_shape.c */; };
   6.113 @@ -537,8 +521,6 @@
   6.114  		04BD040412E6671800899322 /* SDL_x11opengl.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFFC912E6671800899322 /* SDL_x11opengl.h */; };
   6.115  		04BD040512E6671800899322 /* SDL_x11opengles.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFFCA12E6671800899322 /* SDL_x11opengles.c */; };
   6.116  		04BD040612E6671800899322 /* SDL_x11opengles.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFFCB12E6671800899322 /* SDL_x11opengles.h */; };
   6.117 -		04BD040712E6671800899322 /* SDL_x11render.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFFCC12E6671800899322 /* SDL_x11render.c */; };
   6.118 -		04BD040812E6671800899322 /* SDL_x11render.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFFCD12E6671800899322 /* SDL_x11render.h */; };
   6.119  		04BD040912E6671800899322 /* SDL_x11shape.c in Sources */ = {isa = PBXBuildFile; fileRef = 04BDFFCE12E6671800899322 /* SDL_x11shape.c */; };
   6.120  		04BD040A12E6671800899322 /* SDL_x11shape.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFFCF12E6671800899322 /* SDL_x11shape.h */; };
   6.121  		04BD040B12E6671800899322 /* SDL_x11sym.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BDFFD012E6671800899322 /* SDL_x11sym.h */; };
   6.122 @@ -714,9 +696,13 @@
   6.123  		00D8DA191195093100638393 /* surface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = surface.h; sourceTree = "<group>"; };
   6.124  		00D8DA1A1195093100638393 /* testsdl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = testsdl.c; path = ../../test/automated/testsdl.c; sourceTree = SOURCE_ROOT; };
   6.125  		00F5D79E0990CA0D0051C449 /* UniversalBinaryNotes.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = UniversalBinaryNotes.rtf; sourceTree = "<group>"; };
   6.126 +		041B2C9412FA0D2A0087D585 /* SDL_render.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_render.h; path = ../../include/SDL_render.h; sourceTree = SOURCE_ROOT; };
   6.127 +		041B2C9B12FA0D680087D585 /* SDL_renderer_gl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_renderer_gl.c; sourceTree = "<group>"; };
   6.128 +		041B2C9E12FA0D680087D585 /* SDL_render.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_render.c; sourceTree = "<group>"; };
   6.129 +		041B2C9F12FA0D680087D585 /* SDL_sysrender.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_sysrender.h; sourceTree = "<group>"; };
   6.130 +		041B2CA112FA0D680087D585 /* SDL_renderer_sw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_renderer_sw.c; sourceTree = "<group>"; };
   6.131  		044E5F8411E6051C0076F181 /* SDL_clipboard.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_clipboard.h; path = ../../include/SDL_clipboard.h; sourceTree = SOURCE_ROOT; };
   6.132  		0469A10912EE4BF100B846D6 /* SDL_blendmode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_blendmode.h; path = ../../include/SDL_blendmode.h; sourceTree = SOURCE_ROOT; };
   6.133 -		0469A10A12EE4BF100B846D6 /* SDL_scalemode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_scalemode.h; path = ../../include/SDL_scalemode.h; sourceTree = SOURCE_ROOT; };
   6.134  		04BDFD7412E6671700899322 /* SDL_atomic.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_atomic.c; sourceTree = "<group>"; };
   6.135  		04BDFD7512E6671700899322 /* SDL_spinlock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_spinlock.c; sourceTree = "<group>"; };
   6.136  		04BDFD8812E6671700899322 /* SDL_diskaudio.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_diskaudio.c; sourceTree = "<group>"; };
   6.137 @@ -747,7 +733,6 @@
   6.138  		04BDFDD712E6671700899322 /* default_cursor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = default_cursor.h; sourceTree = "<group>"; };
   6.139  		04BDFDD812E6671700899322 /* scancodes_darwin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scancodes_darwin.h; sourceTree = "<group>"; };
   6.140  		04BDFDD912E6671700899322 /* scancodes_linux.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scancodes_linux.h; sourceTree = "<group>"; };
   6.141 -		04BDFDDA12E6671700899322 /* scancodes_win32.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scancodes_win32.h; sourceTree = "<group>"; };
   6.142  		04BDFDDB12E6671700899322 /* scancodes_xfree86.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = scancodes_xfree86.h; sourceTree = "<group>"; };
   6.143  		04BDFDDC12E6671700899322 /* SDL_clipboardevents.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_clipboardevents.c; sourceTree = "<group>"; };
   6.144  		04BDFDDD12E6671700899322 /* SDL_clipboardevents_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_clipboardevents_c.h; sourceTree = "<group>"; };
   6.145 @@ -804,7 +789,6 @@
   6.146  		04BDFE8B12E6671800899322 /* SDL_systhread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_systhread.h; sourceTree = "<group>"; };
   6.147  		04BDFE8C12E6671800899322 /* SDL_thread.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_thread.c; sourceTree = "<group>"; };
   6.148  		04BDFE8D12E6671800899322 /* SDL_thread_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_thread_c.h; sourceTree = "<group>"; };
   6.149 -		04BDFE9E12E6671800899322 /* SDL_systimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_systimer.h; sourceTree = "<group>"; };
   6.150  		04BDFE9F12E6671800899322 /* SDL_timer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_timer.c; sourceTree = "<group>"; };
   6.151  		04BDFEA012E6671800899322 /* SDL_timer_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_timer_c.h; sourceTree = "<group>"; };
   6.152  		04BDFEA212E6671800899322 /* SDL_systimer.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_systimer.c; sourceTree = "<group>"; };
   6.153 @@ -828,8 +812,6 @@
   6.154  		04BDFED312E6671800899322 /* SDL_cocoawindow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SDL_cocoawindow.m; sourceTree = "<group>"; };
   6.155  		04BDFEE812E6671800899322 /* SDL_nullevents.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_nullevents.c; sourceTree = "<group>"; };
   6.156  		04BDFEE912E6671800899322 /* SDL_nullevents_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_nullevents_c.h; sourceTree = "<group>"; };
   6.157 -		04BDFEEA12E6671800899322 /* SDL_nullrender.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_nullrender.c; sourceTree = "<group>"; };
   6.158 -		04BDFEEB12E6671800899322 /* SDL_nullrender_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_nullrender_c.h; sourceTree = "<group>"; };
   6.159  		04BDFEEC12E6671800899322 /* SDL_nullvideo.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_nullvideo.c; sourceTree = "<group>"; };
   6.160  		04BDFEED12E6671800899322 /* SDL_nullvideo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_nullvideo.h; sourceTree = "<group>"; };
   6.161  		04BDFF0412E6671800899322 /* mmx.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = mmx.h; sourceTree = "<group>"; };
   6.162 @@ -865,13 +847,6 @@
   6.163  		04BDFF6512E6671800899322 /* SDL_pixels.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_pixels.c; sourceTree = "<group>"; };
   6.164  		04BDFF6612E6671800899322 /* SDL_pixels_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_pixels_c.h; sourceTree = "<group>"; };
   6.165  		04BDFF6712E6671800899322 /* SDL_rect.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_rect.c; sourceTree = "<group>"; };
   6.166 -		04BDFF6812E6671800899322 /* SDL_rect_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_rect_c.h; sourceTree = "<group>"; };
   6.167 -		04BDFF6912E6671800899322 /* SDL_renderer_gl.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_renderer_gl.c; sourceTree = "<group>"; };
   6.168 -		04BDFF6A12E6671800899322 /* SDL_renderer_gl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_renderer_gl.h; sourceTree = "<group>"; };
   6.169 -		04BDFF6B12E6671800899322 /* SDL_renderer_gles.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_renderer_gles.c; sourceTree = "<group>"; };
   6.170 -		04BDFF6C12E6671800899322 /* SDL_renderer_gles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_renderer_gles.h; sourceTree = "<group>"; };
   6.171 -		04BDFF6D12E6671800899322 /* SDL_renderer_sw.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_renderer_sw.c; sourceTree = "<group>"; };
   6.172 -		04BDFF6E12E6671800899322 /* SDL_renderer_sw.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_renderer_sw.h; sourceTree = "<group>"; };
   6.173  		04BDFF6F12E6671800899322 /* SDL_RLEaccel.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_RLEaccel.c; sourceTree = "<group>"; };
   6.174  		04BDFF7012E6671800899322 /* SDL_RLEaccel_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_RLEaccel_c.h; sourceTree = "<group>"; };
   6.175  		04BDFF7112E6671800899322 /* SDL_shape.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_shape.c; sourceTree = "<group>"; };
   6.176 @@ -903,8 +878,6 @@
   6.177  		04BDFFC912E6671800899322 /* SDL_x11opengl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_x11opengl.h; sourceTree = "<group>"; };
   6.178  		04BDFFCA12E6671800899322 /* SDL_x11opengles.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_x11opengles.c; sourceTree = "<group>"; };
   6.179  		04BDFFCB12E6671800899322 /* SDL_x11opengles.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_x11opengles.h; sourceTree = "<group>"; };
   6.180 -		04BDFFCC12E6671800899322 /* SDL_x11render.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_x11render.c; sourceTree = "<group>"; };
   6.181 -		04BDFFCD12E6671800899322 /* SDL_x11render.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_x11render.h; sourceTree = "<group>"; };
   6.182  		04BDFFCE12E6671800899322 /* SDL_x11shape.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_x11shape.c; sourceTree = "<group>"; };
   6.183  		04BDFFCF12E6671800899322 /* SDL_x11shape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_x11shape.h; sourceTree = "<group>"; };
   6.184  		04BDFFD012E6671800899322 /* SDL_x11sym.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_x11sym.h; sourceTree = "<group>"; };
   6.185 @@ -969,7 +942,6 @@
   6.186  		0C5AF5FE01191D2B7F000001 /* SDL_video.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SDL_video.h; path = ../../include/SDL_video.h; sourceTree = SOURCE_ROOT; };
   6.187  		0C5AF5FF01191D2B7F000001 /* SDL.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SDL.h; path = ../../include/SDL.h; sourceTree = SOURCE_ROOT; };
   6.188  		453773811207C518002F0F45 /* SDL_shape.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_shape.h; path = ../../include/SDL_shape.h; sourceTree = SOURCE_ROOT; };
   6.189 -		8C93F0EA11F803710014F54D /* gestureSDLTest-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "gestureSDLTest-Info.plist"; sourceTree = "<group>"; };
   6.190  		8CB0A77611F6A87F00CBA2DE /* SDL_gesture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_gesture.h; path = ../../include/SDL_gesture.h; sourceTree = SOURCE_ROOT; };
   6.191  		8CB0A77711F6A87F00CBA2DE /* SDL_touch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_touch.h; path = ../../include/SDL_touch.h; sourceTree = SOURCE_ROOT; };
   6.192  		B29A290D04E5B28700A80002 /* SDL_loadso.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = SDL_loadso.h; path = ../../include/SDL_loadso.h; sourceTree = "<group>"; };
   6.193 @@ -1180,9 +1152,9 @@
   6.194  				00CFA67E106B44CE00758660 /* SDL_power.h */,
   6.195  				0C5AF5F701191D2B7F000001 /* SDL_quit.h */,
   6.196  				00CFA67F106B44CE00758660 /* SDL_rect.h */,
   6.197 +				041B2C9412FA0D2A0087D585 /* SDL_render.h */,
   6.198  				00A6EBD91078D569001EEA06 /* SDL_revision.h */,
   6.199  				0C5AF5F801191D2B7F000001 /* SDL_rwops.h */,
   6.200 -				0469A10A12EE4BF100B846D6 /* SDL_scalemode.h */,
   6.201  				00CFA680106B44CE00758660 /* SDL_scancode.h */,
   6.202  				453773811207C518002F0F45 /* SDL_shape.h */,
   6.203  				00162D3909BD1FA90037C8D0 /* SDL_stdinc.h */,
   6.204 @@ -1211,6 +1183,34 @@
   6.205  			name = Products;
   6.206  			sourceTree = "<group>";
   6.207  		};
   6.208 +		041B2C9712FA0D680087D585 /* render */ = {
   6.209 +			isa = PBXGroup;
   6.210 +			children = (
   6.211 +				041B2C9A12FA0D680087D585 /* opengl */,
   6.212 +				041B2CA012FA0D680087D585 /* software */,
   6.213 +				041B2C9E12FA0D680087D585 /* SDL_render.c */,
   6.214 +				041B2C9F12FA0D680087D585 /* SDL_sysrender.h */,
   6.215 +			);
   6.216 +			name = render;
   6.217 +			path = ../../src/render;
   6.218 +			sourceTree = SOURCE_ROOT;
   6.219 +		};
   6.220 +		041B2C9A12FA0D680087D585 /* opengl */ = {
   6.221 +			isa = PBXGroup;
   6.222 +			children = (
   6.223 +				041B2C9B12FA0D680087D585 /* SDL_renderer_gl.c */,
   6.224 +			);
   6.225 +			path = opengl;
   6.226 +			sourceTree = "<group>";
   6.227 +		};
   6.228 +		041B2CA012FA0D680087D585 /* software */ = {
   6.229 +			isa = PBXGroup;
   6.230 +			children = (
   6.231 +				041B2CA112FA0D680087D585 /* SDL_renderer_sw.c */,
   6.232 +			);
   6.233 +			path = software;
   6.234 +			sourceTree = "<group>";
   6.235 +		};
   6.236  		04BDFD7312E6671700899322 /* atomic */ = {
   6.237  			isa = PBXGroup;
   6.238  			children = (
   6.239 @@ -1292,7 +1292,6 @@
   6.240  				04BDFDD712E6671700899322 /* default_cursor.h */,
   6.241  				04BDFDD812E6671700899322 /* scancodes_darwin.h */,
   6.242  				04BDFDD912E6671700899322 /* scancodes_linux.h */,
   6.243 -				04BDFDDA12E6671700899322 /* scancodes_win32.h */,
   6.244  				04BDFDDB12E6671700899322 /* scancodes_xfree86.h */,
   6.245  				04BDFDDC12E6671700899322 /* SDL_clipboardevents.c */,
   6.246  				04BDFDDD12E6671700899322 /* SDL_clipboardevents_c.h */,
   6.247 @@ -1462,7 +1461,6 @@
   6.248  			isa = PBXGroup;
   6.249  			children = (
   6.250  				04BDFEA112E6671800899322 /* unix */,
   6.251 -				04BDFE9E12E6671800899322 /* SDL_systimer.h */,
   6.252  				04BDFE9F12E6671800899322 /* SDL_timer.c */,
   6.253  				04BDFEA012E6671800899322 /* SDL_timer_c.h */,
   6.254  			);
   6.255 @@ -1518,13 +1516,6 @@
   6.256  				04BDFF6512E6671800899322 /* SDL_pixels.c */,
   6.257  				04BDFF6612E6671800899322 /* SDL_pixels_c.h */,
   6.258  				04BDFF6712E6671800899322 /* SDL_rect.c */,
   6.259 -				04BDFF6812E6671800899322 /* SDL_rect_c.h */,
   6.260 -				04BDFF6912E6671800899322 /* SDL_renderer_gl.c */,
   6.261 -				04BDFF6A12E6671800899322 /* SDL_renderer_gl.h */,
   6.262 -				04BDFF6B12E6671800899322 /* SDL_renderer_gles.c */,
   6.263 -				04BDFF6C12E6671800899322 /* SDL_renderer_gles.h */,
   6.264 -				04BDFF6D12E6671800899322 /* SDL_renderer_sw.c */,
   6.265 -				04BDFF6E12E6671800899322 /* SDL_renderer_sw.h */,
   6.266  				04BDFF6F12E6671800899322 /* SDL_RLEaccel.c */,
   6.267  				04BDFF7012E6671800899322 /* SDL_RLEaccel_c.h */,
   6.268  				04BDFF7112E6671800899322 /* SDL_shape.c */,
   6.269 @@ -1571,8 +1562,6 @@
   6.270  			children = (
   6.271  				04BDFEE812E6671800899322 /* SDL_nullevents.c */,
   6.272  				04BDFEE912E6671800899322 /* SDL_nullevents_c.h */,
   6.273 -				04BDFEEA12E6671800899322 /* SDL_nullrender.c */,
   6.274 -				04BDFEEB12E6671800899322 /* SDL_nullrender_c.h */,
   6.275  				04BDFEEC12E6671800899322 /* SDL_nullvideo.c */,
   6.276  				04BDFEED12E6671800899322 /* SDL_nullvideo.h */,
   6.277  			);
   6.278 @@ -1602,8 +1591,6 @@
   6.279  				04BDFFC912E6671800899322 /* SDL_x11opengl.h */,
   6.280  				04BDFFCA12E6671800899322 /* SDL_x11opengles.c */,
   6.281  				04BDFFCB12E6671800899322 /* SDL_x11opengles.h */,
   6.282 -				04BDFFCC12E6671800899322 /* SDL_x11render.c */,
   6.283 -				04BDFFCD12E6671800899322 /* SDL_x11render.h */,
   6.284  				04BDFFCE12E6671800899322 /* SDL_x11shape.c */,
   6.285  				04BDFFCF12E6671800899322 /* SDL_x11shape.h */,
   6.286  				04BDFFD012E6671800899322 /* SDL_x11sym.h */,
   6.287 @@ -1715,7 +1702,6 @@
   6.288  				BECDF66B0761BA81005FE872 /* Info-Framework.plist */,
   6.289  				BEC562FE0761C0E800A33029 /* Linked Frameworks */,
   6.290  				00D8D9F11195090700638393 /* testsdl-Info.plist */,
   6.291 -				8C93F0EA11F803710014F54D /* gestureSDLTest-Info.plist */,
   6.292  			);
   6.293  			comments = "To build Universal Binaries, we have experimented with a variety of different options.\nThe complication is that we must retain compatibility with at least 10.2. \nThe Universal Binary defaults only work for > 10.3.9\n\nSo far, we have found:\ngcc 4.0.0 with Xcode 2.1 always links against libgcc_s. gcc 4.0.1 from Xcode 2.2 fixes this problem.\n\nBut gcc 4.0 will not work with < 10.3.9 because we continue to get an undefined symbol to _fprintf$LDBL128.\nSo we must use gcc 3.3 on PPC to accomplish 10.2 support. (But 4.0 is required for i386.)\n\nSetting the deployment target to 10.4 will disable prebinding, so for PPC, we set it less than 10.4 to preserve prebinding for legacy support.\n\nSetting the PPC SDKROOT to /Developers/SDKs/MacOSX10.2.8.sdk will link to 63.0.0 libSystem.B.dylib. Leaving it at current or 10.4u links to 88.1.2. However, as long as we are using gcc 3.3, it doesn't seem to matter as testing has demonstrated both will run. We have decided not to invoke the 10.2.8 SDK because it is not a default installed component with Xcode which will probably cause most people problems. However, rather than deleting the SDKROOT_ppc entry entirely, we have mapped it to 10.4u in case we decide we need to change this setting.\n\nTo use Altivec or SSE, we needed architecture specific flags:\nOTHER_CFLAGS_ppc\nOTHER_CFLAGS_i386\nOTHER_CFLAGS=$(OTHER_CFLAGS_($CURRENT_ARCH))\n\nThe general OTHER_CFLAGS needed to be manually mapped to architecture specific options because Xcode didn't do this automatically for us.\n\n\n";
   6.294  			name = SDLFramework;
   6.295 @@ -1740,6 +1726,7 @@
   6.296  				04BDFDFF12E6671700899322 /* joystick */,
   6.297  				04BDFE2F12E6671700899322 /* loadso */,
   6.298  				04BDFE4512E6671700899322 /* power */,
   6.299 +				041B2C9712FA0D680087D585 /* render */,
   6.300  				04BDFE5D12E6671700899322 /* stdlib */,
   6.301  				04BDFE6412E6671800899322 /* thread */,
   6.302  				04BDFE9512E6671800899322 /* timer */,
   6.303 @@ -1872,7 +1859,6 @@
   6.304  				04BD004312E6671800899322 /* default_cursor.h in Headers */,
   6.305  				04BD004412E6671800899322 /* scancodes_darwin.h in Headers */,
   6.306  				04BD004512E6671800899322 /* scancodes_linux.h in Headers */,
   6.307 -				04BD004612E6671800899322 /* scancodes_win32.h in Headers */,
   6.308  				04BD004712E6671800899322 /* scancodes_xfree86.h in Headers */,
   6.309  				04BD004912E6671800899322 /* SDL_clipboardevents_c.h in Headers */,
   6.310  				04BD004B12E6671800899322 /* SDL_events_c.h in Headers */,
   6.311 @@ -1895,7 +1881,6 @@
   6.312  				04BD00C212E6671800899322 /* SDL_systhread_c.h in Headers */,
   6.313  				04BD00C912E6671800899322 /* SDL_systhread.h in Headers */,
   6.314  				04BD00CB12E6671800899322 /* SDL_thread_c.h in Headers */,
   6.315 -				04BD00D612E6671800899322 /* SDL_systimer.h in Headers */,
   6.316  				04BD00D812E6671800899322 /* SDL_timer_c.h in Headers */,
   6.317  				04BD00F312E6671800899322 /* SDL_cocoaclipboard.h in Headers */,
   6.318  				04BD00F512E6671800899322 /* SDL_cocoaevents.h in Headers */,
   6.319 @@ -1907,7 +1892,6 @@
   6.320  				04BD010112E6671800899322 /* SDL_cocoavideo.h in Headers */,
   6.321  				04BD010312E6671800899322 /* SDL_cocoawindow.h in Headers */,
   6.322  				04BD011812E6671800899322 /* SDL_nullevents_c.h in Headers */,
   6.323 -				04BD011A12E6671800899322 /* SDL_nullrender_c.h in Headers */,
   6.324  				04BD011C12E6671800899322 /* SDL_nullvideo.h in Headers */,
   6.325  				04BD013212E6671800899322 /* mmx.h in Headers */,
   6.326  				04BD017012E6671800899322 /* SDL_alphamult.h in Headers */,
   6.327 @@ -1920,10 +1904,6 @@
   6.328  				04BD018A12E6671800899322 /* SDL_glfuncs.h in Headers */,
   6.329  				04BD018B12E6671800899322 /* SDL_leaks.h in Headers */,
   6.330  				04BD018D12E6671800899322 /* SDL_pixels_c.h in Headers */,
   6.331 -				04BD018F12E6671800899322 /* SDL_rect_c.h in Headers */,
   6.332 -				04BD019112E6671800899322 /* SDL_renderer_gl.h in Headers */,
   6.333 -				04BD019312E6671800899322 /* SDL_renderer_gles.h in Headers */,
   6.334 -				04BD019512E6671800899322 /* SDL_renderer_sw.h in Headers */,
   6.335  				04BD019712E6671800899322 /* SDL_RLEaccel_c.h in Headers */,
   6.336  				04BD019912E6671800899322 /* SDL_shape_internals.h in Headers */,
   6.337  				04BD019C12E6671800899322 /* SDL_sysvideo.h in Headers */,
   6.338 @@ -1938,7 +1918,6 @@
   6.339  				04BD01EA12E6671800899322 /* SDL_x11mouse.h in Headers */,
   6.340  				04BD01EC12E6671800899322 /* SDL_x11opengl.h in Headers */,
   6.341  				04BD01EE12E6671800899322 /* SDL_x11opengles.h in Headers */,
   6.342 -				04BD01F012E6671800899322 /* SDL_x11render.h in Headers */,
   6.343  				04BD01F212E6671800899322 /* SDL_x11shape.h in Headers */,
   6.344  				04BD01F312E6671800899322 /* SDL_x11sym.h in Headers */,
   6.345  				04BD01F512E6671800899322 /* SDL_x11touch.h in Headers */,
   6.346 @@ -1961,7 +1940,8 @@
   6.347  				04BD020812E6671800899322 /* Xvproto.h in Headers */,
   6.348  				04BD021512E6671800899322 /* Xvlibint.h in Headers */,
   6.349  				0469A10B12EE4BF100B846D6 /* SDL_blendmode.h in Headers */,
   6.350 -				0469A10C12EE4BF100B846D6 /* SDL_scalemode.h in Headers */,
   6.351 +				041B2C9512FA0D2A0087D585 /* SDL_render.h in Headers */,
   6.352 +				041B2CA612FA0D680087D585 /* SDL_sysrender.h in Headers */,
   6.353  			);
   6.354  			runOnlyForDeploymentPostprocessing = 0;
   6.355  		};
   6.356 @@ -2002,7 +1982,6 @@
   6.357  				04BD025E12E6671800899322 /* default_cursor.h in Headers */,
   6.358  				04BD025F12E6671800899322 /* scancodes_darwin.h in Headers */,
   6.359  				04BD026012E6671800899322 /* scancodes_linux.h in Headers */,
   6.360 -				04BD026112E6671800899322 /* scancodes_win32.h in Headers */,
   6.361  				04BD026212E6671800899322 /* scancodes_xfree86.h in Headers */,
   6.362  				04BD026412E6671800899322 /* SDL_clipboardevents_c.h in Headers */,
   6.363  				04BD026612E6671800899322 /* SDL_events_c.h in Headers */,
   6.364 @@ -2025,7 +2004,6 @@
   6.365  				04BD02DC12E6671800899322 /* SDL_systhread_c.h in Headers */,
   6.366  				04BD02E312E6671800899322 /* SDL_systhread.h in Headers */,
   6.367  				04BD02E512E6671800899322 /* SDL_thread_c.h in Headers */,
   6.368 -				04BD02F012E6671800899322 /* SDL_systimer.h in Headers */,
   6.369  				04BD02F212E6671800899322 /* SDL_timer_c.h in Headers */,
   6.370  				04BD030D12E6671800899322 /* SDL_cocoaclipboard.h in Headers */,
   6.371  				04BD030F12E6671800899322 /* SDL_cocoaevents.h in Headers */,
   6.372 @@ -2037,7 +2015,6 @@
   6.373  				04BD031B12E6671800899322 /* SDL_cocoavideo.h in Headers */,
   6.374  				04BD031D12E6671800899322 /* SDL_cocoawindow.h in Headers */,
   6.375  				04BD033212E6671800899322 /* SDL_nullevents_c.h in Headers */,
   6.376 -				04BD033412E6671800899322 /* SDL_nullrender_c.h in Headers */,
   6.377  				04BD033612E6671800899322 /* SDL_nullvideo.h in Headers */,
   6.378  				04BD034C12E6671800899322 /* mmx.h in Headers */,
   6.379  				04BD038A12E6671800899322 /* SDL_alphamult.h in Headers */,
   6.380 @@ -2050,10 +2027,6 @@
   6.381  				04BD03A412E6671800899322 /* SDL_glfuncs.h in Headers */,
   6.382  				04BD03A512E6671800899322 /* SDL_leaks.h in Headers */,
   6.383  				04BD03A712E6671800899322 /* SDL_pixels_c.h in Headers */,
   6.384 -				04BD03A912E6671800899322 /* SDL_rect_c.h in Headers */,
   6.385 -				04BD03AB12E6671800899322 /* SDL_renderer_gl.h in Headers */,
   6.386 -				04BD03AD12E6671800899322 /* SDL_renderer_gles.h in Headers */,
   6.387 -				04BD03AF12E6671800899322 /* SDL_renderer_sw.h in Headers */,
   6.388  				04BD03B112E6671800899322 /* SDL_RLEaccel_c.h in Headers */,
   6.389  				04BD03B312E6671800899322 /* SDL_shape_internals.h in Headers */,
   6.390  				04BD03B612E6671800899322 /* SDL_sysvideo.h in Headers */,
   6.391 @@ -2068,7 +2041,6 @@
   6.392  				04BD040212E6671800899322 /* SDL_x11mouse.h in Headers */,
   6.393  				04BD040412E6671800899322 /* SDL_x11opengl.h in Headers */,
   6.394  				04BD040612E6671800899322 /* SDL_x11opengles.h in Headers */,
   6.395 -				04BD040812E6671800899322 /* SDL_x11render.h in Headers */,
   6.396  				04BD040A12E6671800899322 /* SDL_x11shape.h in Headers */,
   6.397  				04BD040B12E6671800899322 /* SDL_x11sym.h in Headers */,
   6.398  				04BD040D12E6671800899322 /* SDL_x11touch.h in Headers */,
   6.399 @@ -2091,7 +2063,8 @@
   6.400  				04BD042012E6671800899322 /* Xvproto.h in Headers */,
   6.401  				04BD042C12E6671800899322 /* Xvlibint.h in Headers */,
   6.402  				0469A10D12EE4BF100B846D6 /* SDL_blendmode.h in Headers */,
   6.403 -				0469A10E12EE4BF100B846D6 /* SDL_scalemode.h in Headers */,
   6.404 +				041B2C9612FA0D2A0087D585 /* SDL_render.h in Headers */,
   6.405 +				041B2CAC12FA0D680087D585 /* SDL_sysrender.h in Headers */,
   6.406  			);
   6.407  			runOnlyForDeploymentPostprocessing = 0;
   6.408  		};
   6.409 @@ -2411,7 +2384,6 @@
   6.410  				04BD010212E6671800899322 /* SDL_cocoavideo.m in Sources */,
   6.411  				04BD010412E6671800899322 /* SDL_cocoawindow.m in Sources */,
   6.412  				04BD011712E6671800899322 /* SDL_nullevents.c in Sources */,
   6.413 -				04BD011912E6671800899322 /* SDL_nullrender.c in Sources */,
   6.414  				04BD011B12E6671800899322 /* SDL_nullvideo.c in Sources */,
   6.415  				04BD016F12E6671800899322 /* SDL_alphamult.c in Sources */,
   6.416  				04BD017112E6671800899322 /* SDL_blendfillrect.c in Sources */,
   6.417 @@ -2435,9 +2407,6 @@
   6.418  				04BD018812E6671800899322 /* SDL_gamma.c in Sources */,
   6.419  				04BD018C12E6671800899322 /* SDL_pixels.c in Sources */,
   6.420  				04BD018E12E6671800899322 /* SDL_rect.c in Sources */,
   6.421 -				04BD019012E6671800899322 /* SDL_renderer_gl.c in Sources */,
   6.422 -				04BD019212E6671800899322 /* SDL_renderer_gles.c in Sources */,
   6.423 -				04BD019412E6671800899322 /* SDL_renderer_sw.c in Sources */,
   6.424  				04BD019612E6671800899322 /* SDL_RLEaccel.c in Sources */,
   6.425  				04BD019812E6671800899322 /* SDL_shape.c in Sources */,
   6.426  				04BD019A12E6671800899322 /* SDL_stretch.c in Sources */,
   6.427 @@ -2455,7 +2424,6 @@
   6.428  				04BD01E912E6671800899322 /* SDL_x11mouse.c in Sources */,
   6.429  				04BD01EB12E6671800899322 /* SDL_x11opengl.c in Sources */,
   6.430  				04BD01ED12E6671800899322 /* SDL_x11opengles.c in Sources */,
   6.431 -				04BD01EF12E6671800899322 /* SDL_x11render.c in Sources */,
   6.432  				04BD01F112E6671800899322 /* SDL_x11shape.c in Sources */,
   6.433  				04BD01F412E6671800899322 /* SDL_x11touch.c in Sources */,
   6.434  				04BD01F612E6671800899322 /* SDL_x11video.c in Sources */,
   6.435 @@ -2472,6 +2440,9 @@
   6.436  				04BD021312E6671800899322 /* VisCmap.c in Sources */,
   6.437  				04BD021412E6671800899322 /* Xv.c in Sources */,
   6.438  				04BD021612E6671800899322 /* XF86VMode.c in Sources */,
   6.439 +				041B2CA312FA0D680087D585 /* SDL_renderer_gl.c in Sources */,
   6.440 +				041B2CA512FA0D680087D585 /* SDL_render.c in Sources */,
   6.441 +				041B2CA712FA0D680087D585 /* SDL_renderer_sw.c in Sources */,
   6.442  			);
   6.443  			runOnlyForDeploymentPostprocessing = 0;
   6.444  		};
   6.445 @@ -2540,7 +2511,6 @@
   6.446  				04BD031C12E6671800899322 /* SDL_cocoavideo.m in Sources */,
   6.447  				04BD031E12E6671800899322 /* SDL_cocoawindow.m in Sources */,
   6.448  				04BD033112E6671800899322 /* SDL_nullevents.c in Sources */,
   6.449 -				04BD033312E6671800899322 /* SDL_nullrender.c in Sources */,
   6.450  				04BD033512E6671800899322 /* SDL_nullvideo.c in Sources */,
   6.451  				04BD038912E6671800899322 /* SDL_alphamult.c in Sources */,
   6.452  				04BD038B12E6671800899322 /* SDL_blendfillrect.c in Sources */,
   6.453 @@ -2564,9 +2534,6 @@
   6.454  				04BD03A212E6671800899322 /* SDL_gamma.c in Sources */,
   6.455  				04BD03A612E6671800899322 /* SDL_pixels.c in Sources */,
   6.456  				04BD03A812E6671800899322 /* SDL_rect.c in Sources */,
   6.457 -				04BD03AA12E6671800899322 /* SDL_renderer_gl.c in Sources */,
   6.458 -				04BD03AC12E6671800899322 /* SDL_renderer_gles.c in Sources */,
   6.459 -				04BD03AE12E6671800899322 /* SDL_renderer_sw.c in Sources */,
   6.460  				04BD03B012E6671800899322 /* SDL_RLEaccel.c in Sources */,
   6.461  				04BD03B212E6671800899322 /* SDL_shape.c in Sources */,
   6.462  				04BD03B412E6671800899322 /* SDL_stretch.c in Sources */,
   6.463 @@ -2584,7 +2551,6 @@
   6.464  				04BD040112E6671800899322 /* SDL_x11mouse.c in Sources */,
   6.465  				04BD040312E6671800899322 /* SDL_x11opengl.c in Sources */,
   6.466  				04BD040512E6671800899322 /* SDL_x11opengles.c in Sources */,
   6.467 -				04BD040712E6671800899322 /* SDL_x11render.c in Sources */,
   6.468  				04BD040912E6671800899322 /* SDL_x11shape.c in Sources */,
   6.469  				04BD040C12E6671800899322 /* SDL_x11touch.c in Sources */,
   6.470  				04BD040E12E6671800899322 /* SDL_x11video.c in Sources */,
   6.471 @@ -2601,6 +2567,9 @@
   6.472  				04BD042A12E6671800899322 /* VisCmap.c in Sources */,
   6.473  				04BD042B12E6671800899322 /* Xv.c in Sources */,
   6.474  				04BD042D12E6671800899322 /* XF86VMode.c in Sources */,
   6.475 +				041B2CA912FA0D680087D585 /* SDL_renderer_gl.c in Sources */,
   6.476 +				041B2CAB12FA0D680087D585 /* SDL_render.c in Sources */,
   6.477 +				041B2CAD12FA0D680087D585 /* SDL_renderer_sw.c in Sources */,
   6.478  			);
   6.479  			runOnlyForDeploymentPostprocessing = 0;
   6.480  		};
     7.1 --- a/configure.in	Wed Feb 02 14:34:24 2011 -0800
     7.2 +++ b/configure.in	Wed Feb 02 14:34:54 2011 -0800
     7.3 @@ -330,11 +330,13 @@
     7.4  
     7.5  # Standard C sources
     7.6  SOURCES="$SOURCES $srcdir/src/*.c"
     7.7 +SOURCES="$SOURCES $srcdir/src/atomic/*.c"
     7.8  SOURCES="$SOURCES $srcdir/src/audio/*.c"
     7.9 -SOURCES="$SOURCES $srcdir/src/atomic/*.c"
    7.10  SOURCES="$SOURCES $srcdir/src/cpuinfo/*.c"
    7.11  SOURCES="$SOURCES $srcdir/src/events/*.c"
    7.12  SOURCES="$SOURCES $srcdir/src/file/*.c"
    7.13 +SOURCES="$SOURCES $srcdir/src/render/*.c"
    7.14 +SOURCES="$SOURCES $srcdir/src/render/*/*.c"
    7.15  SOURCES="$SOURCES $srcdir/src/stdlib/*.c"
    7.16  SOURCES="$SOURCES $srcdir/src/thread/*.c"
    7.17  SOURCES="$SOURCES $srcdir/src/timer/*.c"
     8.1 --- a/include/SDL_rect.h	Wed Feb 02 14:34:24 2011 -0800
     8.2 +++ b/include/SDL_rect.h	Wed Feb 02 14:34:54 2011 -0800
     8.3 @@ -70,6 +70,25 @@
     8.4  } SDL_Rect;
     8.5  
     8.6  /**
     8.7 + *  \brief A structure used to track dirty rectangles
     8.8 + *  
     8.9 + *  \sa SDL_AddDirtyRect
    8.10 + *  \sa SDL_ClearDirtyRects
    8.11 + *  \sa SDL_FreeDirtyRects
    8.12 + */
    8.13 +typedef struct SDL_DirtyRect
    8.14 +{
    8.15 +    SDL_Rect rect;
    8.16 +    struct SDL_DirtyRect *next;
    8.17 +} SDL_DirtyRect;
    8.18 +
    8.19 +typedef struct SDL_DirtyRectList
    8.20 +{
    8.21 +    SDL_DirtyRect *list;
    8.22 +    SDL_DirtyRect *free;
    8.23 +} SDL_DirtyRectList;
    8.24 +
    8.25 +/**
    8.26   *  \brief Returns true if the rectangle has no area.
    8.27   */
    8.28  #define SDL_RectEmpty(X)    (((X)->w <= 0) || ((X)->h <= 0))
    8.29 @@ -124,6 +143,22 @@
    8.30                                                            int *Y1, int *X2,
    8.31                                                            int *Y2);
    8.32  
    8.33 +/**
    8.34 + *  \brief Add a rectangle to a dirty rectangle list
    8.35 + */
    8.36 +extern DECLSPEC void SDLCALL SDL_AddDirtyRect(SDL_DirtyRectList * list, const SDL_Rect * rect);
    8.37 +
    8.38 +/**
    8.39 + *  \brief Remove all rectangles associated with a dirty rectangle list
    8.40 + */
    8.41 +extern DECLSPEC void SDLCALL SDL_ClearDirtyRects(SDL_DirtyRectList * list);
    8.42 +
    8.43 +/**
    8.44 + *  \brief Free memory associated with a dirty rectangle list
    8.45 + */
    8.46 +extern DECLSPEC void SDLCALL SDL_FreeDirtyRects(SDL_DirtyRectList * list);
    8.47 +
    8.48 +
    8.49  /* Ends C function definitions when using C++ */
    8.50  #ifdef __cplusplus
    8.51  /* *INDENT-OFF* */
     9.1 --- a/include/SDL_video.h	Wed Feb 02 14:34:24 2011 -0800
     9.2 +++ b/include/SDL_video.h	Wed Feb 02 14:34:54 2011 -0800
     9.3 @@ -356,6 +356,11 @@
     9.4                                                       SDL_DisplayMode * mode);
     9.5  
     9.6  /**
     9.7 + *  \brief Get the pixel format associated with the window.
     9.8 + */
     9.9 +extern DECLSPEC Uint32 SDLCALL SDL_GetWindowPixelFormat(SDL_Window * window);
    9.10 +
    9.11 +/**
    9.12   *  \brief Set the gamma correction for each of the color channels on the 
    9.13   *         currently selected display.
    9.14   *  
    10.1 --- a/src/events/SDL_events.c	Wed Feb 02 14:34:24 2011 -0800
    10.2 +++ b/src/events/SDL_events.c	Wed Feb 02 14:34:54 2011 -0800
    10.3 @@ -116,8 +116,6 @@
    10.4  int
    10.5  SDL_StartEventLoop(void)
    10.6  {
    10.7 -    int retcode;
    10.8 -
    10.9      /* Clean out the event queue */
   10.10      SDL_EventQ.lock = NULL;
   10.11      SDL_StopEventLoop();
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/render/SDL_render.c	Wed Feb 02 14:34:54 2011 -0800
    11.3 @@ -0,0 +1,1113 @@
    11.4 +/*
    11.5 +    SDL - Simple DirectMedia Layer
    11.6 +    Copyright (C) 1997-2010 Sam Lantinga
    11.7 +
    11.8 +    This library is free software; you can redistribute it and/or
    11.9 +    modify it under the terms of the GNU Lesser General Public
   11.10 +    License as published by the Free Software Foundation; either
   11.11 +    version 2.1 of the License, or (at your option) any later version.
   11.12 +
   11.13 +    This library is distributed in the hope that it will be useful,
   11.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   11.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   11.16 +    Lesser General Public License for more details.
   11.17 +
   11.18 +    You should have received a copy of the GNU Lesser General Public
   11.19 +    License along with this library; if not, write to the Free Software
   11.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   11.21 +
   11.22 +    Sam Lantinga
   11.23 +    slouken@libsdl.org
   11.24 +*/
   11.25 +#include "SDL_config.h"
   11.26 +
   11.27 +/* The SDL 2D rendering system */
   11.28 +
   11.29 +#include "SDL_render.h"
   11.30 +#include "SDL_sysrender.h"
   11.31 +#include "../video/SDL_pixels_c.h"
   11.32 +
   11.33 +
   11.34 +#define CHECK_RENDERER_MAGIC(renderer, retval) \
   11.35 +    if (!renderer || renderer->magic != &renderer_magic) { \
   11.36 +        SDL_SetError("Invalid renderer"); \
   11.37 +        return retval; \
   11.38 +    }
   11.39 +
   11.40 +#define CHECK_TEXTURE_MAGIC(texture, retval) \
   11.41 +    if (!texture || texture->magic != &texture_magic) { \
   11.42 +        SDL_SetError("Invalid texture"); \
   11.43 +        return retval; \
   11.44 +    }
   11.45 +
   11.46 +
   11.47 +static const SDL_RenderDriver *render_drivers[] = {
   11.48 +#if SDL_VIDEO_RENDER_D3D
   11.49 +    &D3D_RenderDriver,
   11.50 +#endif
   11.51 +#if SDL_VIDEO_RENDER_OGL
   11.52 +    &GL_RenderDriver,
   11.53 +#endif
   11.54 +#if SDL_VIDEO_RENDER_OGL_ES
   11.55 +    &GL_ES_RenderDriver,
   11.56 +#endif
   11.57 +    &SW_RenderDriver
   11.58 +};
   11.59 +static char renderer_magic;
   11.60 +static char texture_magic;
   11.61 +
   11.62 +int
   11.63 +SDL_GetNumRenderDrivers(void)
   11.64 +{
   11.65 +    return SDL_arraysize(render_drivers);
   11.66 +}
   11.67 +
   11.68 +int
   11.69 +SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info)
   11.70 +{
   11.71 +    if (index < 0 || index >= SDL_GetNumRenderDrivers()) {
   11.72 +        SDL_SetError("index must be in the range of 0 - %d",
   11.73 +                     SDL_GetNumRenderDrivers() - 1);
   11.74 +        return -1;
   11.75 +    }
   11.76 +    *info = render_drivers[index]->info;
   11.77 +    return 0;
   11.78 +}
   11.79 +
   11.80 +static int
   11.81 +SDL_RendererEventWatch(void *userdata, SDL_Event *event)
   11.82 +{
   11.83 +    SDL_Renderer *renderer = (SDL_Renderer *)userdata;
   11.84 +
   11.85 +    if (event->type == SDL_WINDOWEVENT && renderer->WindowEvent) {
   11.86 +        SDL_Window *window = SDL_GetWindowFromID(event->window.windowID);
   11.87 +        if (window == renderer->window) {
   11.88 +            renderer->WindowEvent(renderer, &event->window);
   11.89 +        }
   11.90 +    }
   11.91 +    return 0;
   11.92 +}
   11.93 +
   11.94 +SDL_Renderer *
   11.95 +SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags)
   11.96 +{
   11.97 +    SDL_Renderer *renderer = NULL;
   11.98 +    int n = SDL_GetNumRenderDrivers();
   11.99 +
  11.100 +    if (index < 0) {
  11.101 +        char *override = SDL_getenv("SDL_VIDEO_RENDERER");
  11.102 +
  11.103 +        if (override) {
  11.104 +            for (index = 0; index < n; ++index) {
  11.105 +                const SDL_RenderDriver *driver = render_drivers[index];
  11.106 +
  11.107 +                if (SDL_strcasecmp(override, driver->info.name) == 0) {
  11.108 +                    /* Create a new renderer instance */
  11.109 +                    renderer = driver->CreateRenderer(window, flags);
  11.110 +                    break;
  11.111 +                }
  11.112 +            }
  11.113 +        } else {
  11.114 +            for (index = 0; index < n; ++index) {
  11.115 +                const SDL_RenderDriver *driver = render_drivers[index];
  11.116 +
  11.117 +                if ((driver->info.flags & flags) == flags) {
  11.118 +                    /* Create a new renderer instance */
  11.119 +                    renderer = driver->CreateRenderer(window, flags);
  11.120 +                    if (renderer) {
  11.121 +                        /* Yay, we got one! */
  11.122 +                        break;
  11.123 +                    }
  11.124 +                }
  11.125 +            }
  11.126 +        }
  11.127 +        if (index == n) {
  11.128 +            SDL_SetError("Couldn't find matching render driver");
  11.129 +            return NULL;
  11.130 +        }
  11.131 +    } else {
  11.132 +        if (index >= SDL_GetNumRenderDrivers()) {
  11.133 +            SDL_SetError("index must be -1 or in the range of 0 - %d",
  11.134 +                         SDL_GetNumRenderDrivers() - 1);
  11.135 +            return NULL;
  11.136 +        }
  11.137 +        /* Create a new renderer instance */
  11.138 +        renderer = render_drivers[index]->CreateRenderer(window, flags);
  11.139 +    }
  11.140 +
  11.141 +    if (renderer) {
  11.142 +        renderer->magic = &renderer_magic;
  11.143 +
  11.144 +        SDL_AddEventWatch(SDL_RendererEventWatch, renderer);
  11.145 +    }
  11.146 +    return renderer;
  11.147 +}
  11.148 +
  11.149 +int
  11.150 +SDL_GetRendererInfo(SDL_Renderer * renderer, SDL_RendererInfo * info)
  11.151 +{
  11.152 +    CHECK_RENDERER_MAGIC(renderer, -1);
  11.153 +
  11.154 +    *info = renderer->info;
  11.155 +    return 0;
  11.156 +}
  11.157 +
  11.158 +SDL_Texture *
  11.159 +SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int h)
  11.160 +{
  11.161 +    SDL_Texture *texture;
  11.162 +
  11.163 +    CHECK_RENDERER_MAGIC(renderer, NULL);
  11.164 +
  11.165 +    if (w <= 0 || h <= 0) {
  11.166 +        SDL_SetError("Texture dimensions can't be 0");
  11.167 +        return 0;
  11.168 +    }
  11.169 +    texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
  11.170 +    if (!texture) {
  11.171 +        SDL_OutOfMemory();
  11.172 +        return 0;
  11.173 +    }
  11.174 +    texture->magic = &texture_magic;
  11.175 +    texture->format = format;
  11.176 +    texture->access = access;
  11.177 +    texture->w = w;
  11.178 +    texture->h = h;
  11.179 +    texture->r = 255;
  11.180 +    texture->g = 255;
  11.181 +    texture->b = 255;
  11.182 +    texture->a = 255;
  11.183 +    texture->renderer = renderer;
  11.184 +    texture->next = renderer->textures;
  11.185 +    if (renderer->textures) {
  11.186 +        renderer->textures->prev = texture;
  11.187 +    }
  11.188 +    renderer->textures = texture;
  11.189 +
  11.190 +    if (renderer->CreateTexture(renderer, texture) < 0) {
  11.191 +        SDL_DestroyTexture(texture);
  11.192 +        return 0;
  11.193 +    }
  11.194 +    return texture;
  11.195 +}
  11.196 +
  11.197 +SDL_Texture *
  11.198 +SDL_CreateTextureFromSurface(SDL_Renderer * renderer, Uint32 format, SDL_Surface * surface)
  11.199 +{
  11.200 +    SDL_Texture *texture;
  11.201 +    Uint32 requested_format = format;
  11.202 +    SDL_PixelFormat *fmt;
  11.203 +    int bpp;
  11.204 +    Uint32 Rmask, Gmask, Bmask, Amask;
  11.205 +
  11.206 +    CHECK_RENDERER_MAGIC(renderer, NULL);
  11.207 +
  11.208 +    if (!surface) {
  11.209 +        SDL_SetError("SDL_CreateTextureFromSurface() passed NULL surface");
  11.210 +        return NULL;
  11.211 +    }
  11.212 +    fmt = surface->format;
  11.213 +
  11.214 +    if (format) {
  11.215 +        if (!SDL_PixelFormatEnumToMasks
  11.216 +            (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
  11.217 +            SDL_SetError("Unknown pixel format");
  11.218 +            return 0;
  11.219 +        }
  11.220 +    } else {
  11.221 +        SDL_bool hasColorkey;
  11.222 +        SDL_BlendMode blendMode;
  11.223 +        SDL_bool hasBlending;
  11.224 +
  11.225 +        hasColorkey = (SDL_GetColorKey(surface, NULL) == 0);
  11.226 +
  11.227 +        SDL_GetSurfaceBlendMode(surface, &blendMode);
  11.228 +        hasBlending = (blendMode == SDL_BLENDMODE_BLEND);
  11.229 +
  11.230 +        if (surface->format->Amask || (!hasColorkey && !hasBlending)) {
  11.231 +            Uint32 it;
  11.232 +            int pfmt;
  11.233 +
  11.234 +            /* Pixel formats, sorted by best first */
  11.235 +            static const Uint32 sdl_pformats[] = {
  11.236 +                SDL_PIXELFORMAT_ARGB8888,
  11.237 +                SDL_PIXELFORMAT_RGBA8888,
  11.238 +                SDL_PIXELFORMAT_ABGR8888,
  11.239 +                SDL_PIXELFORMAT_BGRA8888,
  11.240 +                SDL_PIXELFORMAT_RGB888,
  11.241 +                SDL_PIXELFORMAT_BGR888,
  11.242 +                SDL_PIXELFORMAT_RGB24,
  11.243 +                SDL_PIXELFORMAT_BGR24,
  11.244 +                SDL_PIXELFORMAT_RGB565,
  11.245 +                SDL_PIXELFORMAT_BGR565,
  11.246 +                SDL_PIXELFORMAT_ARGB1555,
  11.247 +                SDL_PIXELFORMAT_RGBA5551,
  11.248 +                SDL_PIXELFORMAT_ABGR1555,
  11.249 +                SDL_PIXELFORMAT_BGRA5551,
  11.250 +                SDL_PIXELFORMAT_RGB555,
  11.251 +                SDL_PIXELFORMAT_BGR555,
  11.252 +                SDL_PIXELFORMAT_ARGB4444,
  11.253 +                SDL_PIXELFORMAT_RGBA4444,
  11.254 +                SDL_PIXELFORMAT_ABGR4444,
  11.255 +                SDL_PIXELFORMAT_BGRA4444,
  11.256 +                SDL_PIXELFORMAT_RGB444,
  11.257 +                SDL_PIXELFORMAT_ARGB2101010,
  11.258 +                SDL_PIXELFORMAT_RGB332,
  11.259 +                SDL_PIXELFORMAT_UNKNOWN
  11.260 +            };
  11.261 +
  11.262 +            bpp = fmt->BitsPerPixel;
  11.263 +            Rmask = fmt->Rmask;
  11.264 +            Gmask = fmt->Gmask;
  11.265 +            Bmask = fmt->Bmask;
  11.266 +            Amask = fmt->Amask;
  11.267 +
  11.268 +            format =
  11.269 +                SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
  11.270 +            if (!format) {
  11.271 +                SDL_SetError("Unknown pixel format");
  11.272 +                return 0;
  11.273 +            }
  11.274 +
  11.275 +            /* Search requested format in the supported texture */
  11.276 +            /* formats by current renderer                      */
  11.277 +            for (it = 0; it < renderer->info.num_texture_formats; it++) {
  11.278 +                if (renderer->info.texture_formats[it] == format) {
  11.279 +                    break;
  11.280 +                }
  11.281 +            }
  11.282 +
  11.283 +            /* If requested format can't be found, search any best */
  11.284 +            /* format which renderer provides                      */
  11.285 +            if (it == renderer->info.num_texture_formats) {
  11.286 +                pfmt = 0;
  11.287 +                for (;;) {
  11.288 +                    if (sdl_pformats[pfmt] == SDL_PIXELFORMAT_UNKNOWN) {
  11.289 +                        break;
  11.290 +                    }
  11.291 +
  11.292 +                    for (it = 0; it < renderer->info.num_texture_formats;
  11.293 +                         it++) {
  11.294 +                        if (renderer->info.texture_formats[it] ==
  11.295 +                            sdl_pformats[pfmt]) {
  11.296 +                            break;
  11.297 +                        }
  11.298 +                    }
  11.299 +
  11.300 +                    if (it != renderer->info.num_texture_formats) {
  11.301 +                        /* The best format has been found */
  11.302 +                        break;
  11.303 +                    }
  11.304 +                    pfmt++;
  11.305 +                }
  11.306 +
  11.307 +                /* If any format can't be found, then return an error */
  11.308 +                if (it == renderer->info.num_texture_formats) {
  11.309 +                    SDL_SetError
  11.310 +                        ("Any of the supported pixel formats can't be found");
  11.311 +                    return 0;
  11.312 +                }
  11.313 +
  11.314 +                /* Convert found pixel format back to color masks */
  11.315 +                if (SDL_PixelFormatEnumToMasks
  11.316 +                    (renderer->info.texture_formats[it], &bpp, &Rmask, &Gmask,
  11.317 +                     &Bmask, &Amask) != SDL_TRUE) {
  11.318 +                    SDL_SetError("Unknown pixel format");
  11.319 +                    return 0;
  11.320 +                }
  11.321 +            }
  11.322 +        } else {
  11.323 +            /* Need a format with alpha */
  11.324 +            Uint32 it;
  11.325 +            int apfmt;
  11.326 +
  11.327 +            /* Pixel formats with alpha, sorted by best first */
  11.328 +            static const Uint32 sdl_alpha_pformats[] = {
  11.329 +                SDL_PIXELFORMAT_ARGB8888,
  11.330 +                SDL_PIXELFORMAT_RGBA8888,
  11.331 +                SDL_PIXELFORMAT_ABGR8888,
  11.332 +                SDL_PIXELFORMAT_BGRA8888,
  11.333 +                SDL_PIXELFORMAT_ARGB1555,
  11.334 +                SDL_PIXELFORMAT_RGBA5551,
  11.335 +                SDL_PIXELFORMAT_ABGR1555,
  11.336 +                SDL_PIXELFORMAT_BGRA5551,
  11.337 +                SDL_PIXELFORMAT_ARGB4444,
  11.338 +                SDL_PIXELFORMAT_RGBA4444,
  11.339 +                SDL_PIXELFORMAT_ABGR4444,
  11.340 +                SDL_PIXELFORMAT_BGRA4444,
  11.341 +                SDL_PIXELFORMAT_ARGB2101010,
  11.342 +                SDL_PIXELFORMAT_UNKNOWN
  11.343 +            };
  11.344 +
  11.345 +            if (surface->format->Amask) {
  11.346 +                /* If surface already has alpha, then try an original */
  11.347 +                /* surface format first                               */
  11.348 +                bpp = fmt->BitsPerPixel;
  11.349 +                Rmask = fmt->Rmask;
  11.350 +                Gmask = fmt->Gmask;
  11.351 +                Bmask = fmt->Bmask;
  11.352 +                Amask = fmt->Amask;
  11.353 +            } else {
  11.354 +                bpp = 32;
  11.355 +                Rmask = 0x00FF0000;
  11.356 +                Gmask = 0x0000FF00;
  11.357 +                Bmask = 0x000000FF;
  11.358 +                Amask = 0xFF000000;
  11.359 +            }
  11.360 +
  11.361 +            format =
  11.362 +                SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
  11.363 +            if (!format) {
  11.364 +                SDL_SetError("Unknown pixel format");
  11.365 +                return 0;
  11.366 +            }
  11.367 +
  11.368 +            /* Search this format in the supported texture formats */
  11.369 +            /* by current renderer                                 */
  11.370 +            for (it = 0; it < renderer->info.num_texture_formats; it++) {
  11.371 +                if (renderer->info.texture_formats[it] == format) {
  11.372 +                    break;
  11.373 +                }
  11.374 +            }
  11.375 +
  11.376 +            /* If this format can't be found, search any best       */
  11.377 +            /* compatible format with alpha which renderer provides */
  11.378 +            if (it == renderer->info.num_texture_formats) {
  11.379 +                apfmt = 0;
  11.380 +                for (;;) {
  11.381 +                    if (sdl_alpha_pformats[apfmt] == SDL_PIXELFORMAT_UNKNOWN) {
  11.382 +                        break;
  11.383 +                    }
  11.384 +
  11.385 +                    for (it = 0; it < renderer->info.num_texture_formats;
  11.386 +                         it++) {
  11.387 +                        if (renderer->info.texture_formats[it] ==
  11.388 +                            sdl_alpha_pformats[apfmt]) {
  11.389 +                            break;
  11.390 +                        }
  11.391 +                    }
  11.392 +
  11.393 +                    if (it != renderer->info.num_texture_formats) {
  11.394 +                        /* Compatible format has been found */
  11.395 +                        break;
  11.396 +                    }
  11.397 +                    apfmt++;
  11.398 +                }
  11.399 +
  11.400 +                /* If compatible format can't be found, then return an error */
  11.401 +                if (it == renderer->info.num_texture_formats) {
  11.402 +                    SDL_SetError("Compatible pixel format can't be found");
  11.403 +                    return 0;
  11.404 +                }
  11.405 +
  11.406 +                /* Convert found pixel format back to color masks */
  11.407 +                if (SDL_PixelFormatEnumToMasks
  11.408 +                    (renderer->info.texture_formats[it], &bpp, &Rmask, &Gmask,
  11.409 +                     &Bmask, &Amask) != SDL_TRUE) {
  11.410 +                    SDL_SetError("Unknown pixel format");
  11.411 +                    return 0;
  11.412 +                }
  11.413 +            }
  11.414 +        }
  11.415 +
  11.416 +        format = SDL_MasksToPixelFormatEnum(bpp, Rmask, Gmask, Bmask, Amask);
  11.417 +        if (!format) {
  11.418 +            SDL_SetError("Unknown pixel format");
  11.419 +            return 0;
  11.420 +        }
  11.421 +    }
  11.422 +
  11.423 +    texture =
  11.424 +        SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
  11.425 +                          surface->w, surface->h);
  11.426 +    if (!texture && !requested_format) {
  11.427 +        SDL_DisplayMode desktop_mode;
  11.428 +        SDL_GetDesktopDisplayMode(&desktop_mode);
  11.429 +        format = desktop_mode.format;
  11.430 +        texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_STATIC,
  11.431 +                                    surface->w, surface->h);
  11.432 +    }
  11.433 +    if (!texture) {
  11.434 +        return 0;
  11.435 +    }
  11.436 +    if (bpp == fmt->BitsPerPixel && Rmask == fmt->Rmask && Gmask == fmt->Gmask
  11.437 +        && Bmask == fmt->Bmask && Amask == fmt->Amask) {
  11.438 +        if (SDL_MUSTLOCK(surface)) {
  11.439 +            SDL_LockSurface(surface);
  11.440 +            SDL_UpdateTexture(texture, NULL, surface->pixels,
  11.441 +                              surface->pitch);
  11.442 +            SDL_UnlockSurface(surface);
  11.443 +        } else {
  11.444 +            SDL_UpdateTexture(texture, NULL, surface->pixels,
  11.445 +                              surface->pitch);
  11.446 +        }
  11.447 +    } else {
  11.448 +        SDL_PixelFormat dst_fmt;
  11.449 +        SDL_Surface *dst = NULL;
  11.450 +
  11.451 +        /* Set up a destination surface for the texture update */
  11.452 +        SDL_InitFormat(&dst_fmt, bpp, Rmask, Gmask, Bmask, Amask);
  11.453 +        dst = SDL_ConvertSurface(surface, &dst_fmt, 0);
  11.454 +        if (dst) {
  11.455 +            SDL_UpdateTexture(texture, NULL, dst->pixels, dst->pitch);
  11.456 +            SDL_FreeSurface(dst);
  11.457 +        }
  11.458 +        if (!dst) {
  11.459 +            SDL_DestroyTexture(texture);
  11.460 +            return 0;
  11.461 +        }
  11.462 +    }
  11.463 +
  11.464 +    {
  11.465 +        Uint8 r, g, b, a;
  11.466 +        SDL_BlendMode blendMode;
  11.467 +
  11.468 +        SDL_GetSurfaceColorMod(surface, &r, &g, &b);
  11.469 +        SDL_SetTextureColorMod(texture, r, g, b);
  11.470 +
  11.471 +        SDL_GetSurfaceAlphaMod(surface, &a);
  11.472 +        SDL_SetTextureAlphaMod(texture, a);
  11.473 +
  11.474 +        if (SDL_GetColorKey(surface, NULL) == 0) {
  11.475 +            /* We converted to a texture with alpha format */
  11.476 +            SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
  11.477 +        } else {
  11.478 +            SDL_GetSurfaceBlendMode(surface, &blendMode);
  11.479 +            SDL_SetTextureBlendMode(texture, blendMode);
  11.480 +        }
  11.481 +    }
  11.482 +    return texture;
  11.483 +}
  11.484 +
  11.485 +int
  11.486 +SDL_QueryTexture(SDL_Texture * texture, Uint32 * format, int *access,
  11.487 +                 int *w, int *h)
  11.488 +{
  11.489 +    CHECK_TEXTURE_MAGIC(texture, -1);
  11.490 +
  11.491 +    if (format) {
  11.492 +        *format = texture->format;
  11.493 +    }
  11.494 +    if (access) {
  11.495 +        *access = texture->access;
  11.496 +    }
  11.497 +    if (w) {
  11.498 +        *w = texture->w;
  11.499 +    }
  11.500 +    if (h) {
  11.501 +        *h = texture->h;
  11.502 +    }
  11.503 +    return 0;
  11.504 +}
  11.505 +
  11.506 +int
  11.507 +SDL_QueryTexturePixels(SDL_Texture * texture, void **pixels, int *pitch)
  11.508 +{
  11.509 +    SDL_Renderer *renderer;
  11.510 +
  11.511 +    CHECK_TEXTURE_MAGIC(texture, -1);
  11.512 +
  11.513 +    renderer = texture->renderer;
  11.514 +    if (!renderer->QueryTexturePixels) {
  11.515 +        SDL_Unsupported();
  11.516 +        return -1;
  11.517 +    }
  11.518 +    return renderer->QueryTexturePixels(renderer, texture, pixels, pitch);
  11.519 +}
  11.520 +
  11.521 +int
  11.522 +SDL_SetTextureColorMod(SDL_Texture * texture, Uint8 r, Uint8 g, Uint8 b)
  11.523 +{
  11.524 +    SDL_Renderer *renderer;
  11.525 +
  11.526 +    CHECK_TEXTURE_MAGIC(texture, -1);
  11.527 +
  11.528 +    renderer = texture->renderer;
  11.529 +    if (r < 255 || g < 255 || b < 255) {
  11.530 +        texture->modMode |= SDL_TEXTUREMODULATE_COLOR;
  11.531 +    } else {
  11.532 +        texture->modMode &= ~SDL_TEXTUREMODULATE_COLOR;
  11.533 +    }
  11.534 +    texture->r = r;
  11.535 +    texture->g = g;
  11.536 +    texture->b = b;
  11.537 +    if (renderer->SetTextureColorMod) {
  11.538 +        return renderer->SetTextureColorMod(renderer, texture);
  11.539 +    } else {
  11.540 +        return 0;
  11.541 +    }
  11.542 +}
  11.543 +
  11.544 +int
  11.545 +SDL_GetTextureColorMod(SDL_Texture * texture, Uint8 * r, Uint8 * g,
  11.546 +                       Uint8 * b)
  11.547 +{
  11.548 +    SDL_Renderer *renderer;
  11.549 +
  11.550 +    CHECK_TEXTURE_MAGIC(texture, -1);
  11.551 +
  11.552 +    renderer = texture->renderer;
  11.553 +    if (r) {
  11.554 +        *r = texture->r;
  11.555 +    }
  11.556 +    if (g) {
  11.557 +        *g = texture->g;
  11.558 +    }
  11.559 +    if (b) {
  11.560 +        *b = texture->b;
  11.561 +    }
  11.562 +    return 0;
  11.563 +}
  11.564 +
  11.565 +int
  11.566 +SDL_SetTextureAlphaMod(SDL_Texture * texture, Uint8 alpha)
  11.567 +{
  11.568 +    SDL_Renderer *renderer;
  11.569 +
  11.570 +    CHECK_TEXTURE_MAGIC(texture, -1);
  11.571 +
  11.572 +    renderer = texture->renderer;
  11.573 +    if (alpha < 255) {
  11.574 +        texture->modMode |= SDL_TEXTUREMODULATE_ALPHA;
  11.575 +    } else {
  11.576 +        texture->modMode &= ~SDL_TEXTUREMODULATE_ALPHA;
  11.577 +    }
  11.578 +    texture->a = alpha;
  11.579 +    if (renderer->SetTextureAlphaMod) {
  11.580 +        return renderer->SetTextureAlphaMod(renderer, texture);
  11.581 +    } else {
  11.582 +        return 0;
  11.583 +    }
  11.584 +}
  11.585 +
  11.586 +int
  11.587 +SDL_GetTextureAlphaMod(SDL_Texture * texture, Uint8 * alpha)
  11.588 +{
  11.589 +    CHECK_TEXTURE_MAGIC(texture, -1);
  11.590 +
  11.591 +    if (alpha) {
  11.592 +        *alpha = texture->a;
  11.593 +    }
  11.594 +    return 0;
  11.595 +}
  11.596 +
  11.597 +int
  11.598 +SDL_SetTextureBlendMode(SDL_Texture * texture, SDL_BlendMode blendMode)
  11.599 +{
  11.600 +    SDL_Renderer *renderer;
  11.601 +
  11.602 +    CHECK_TEXTURE_MAGIC(texture, -1);
  11.603 +
  11.604 +    renderer = texture->renderer;
  11.605 +    texture->blendMode = blendMode;
  11.606 +    if (renderer->SetTextureBlendMode) {
  11.607 +        return renderer->SetTextureBlendMode(renderer, texture);
  11.608 +    } else {
  11.609 +        return 0;
  11.610 +    }
  11.611 +}
  11.612 +
  11.613 +int
  11.614 +SDL_GetTextureBlendMode(SDL_Texture * texture, SDL_BlendMode *blendMode)
  11.615 +{
  11.616 +    CHECK_TEXTURE_MAGIC(texture, -1);
  11.617 +
  11.618 +    if (blendMode) {
  11.619 +        *blendMode = texture->blendMode;
  11.620 +    }
  11.621 +    return 0;
  11.622 +}
  11.623 +
  11.624 +int
  11.625 +SDL_UpdateTexture(SDL_Texture * texture, const SDL_Rect * rect,
  11.626 +                  const void *pixels, int pitch)
  11.627 +{
  11.628 +    SDL_Renderer *renderer;
  11.629 +    SDL_Rect full_rect;
  11.630 +
  11.631 +    CHECK_TEXTURE_MAGIC(texture, -1);
  11.632 +
  11.633 +    renderer = texture->renderer;
  11.634 +    if (!renderer->UpdateTexture) {
  11.635 +        SDL_Unsupported();
  11.636 +        return -1;
  11.637 +    }
  11.638 +    if (!rect) {
  11.639 +        full_rect.x = 0;
  11.640 +        full_rect.y = 0;
  11.641 +        full_rect.w = texture->w;
  11.642 +        full_rect.h = texture->h;
  11.643 +        rect = &full_rect;
  11.644 +    }
  11.645 +    return renderer->UpdateTexture(renderer, texture, rect, pixels, pitch);
  11.646 +}
  11.647 +
  11.648 +int
  11.649 +SDL_LockTexture(SDL_Texture * texture, const SDL_Rect * rect, int markDirty,
  11.650 +                void **pixels, int *pitch)
  11.651 +{
  11.652 +    SDL_Renderer *renderer;
  11.653 +    SDL_Rect full_rect;
  11.654 +
  11.655 +    CHECK_TEXTURE_MAGIC(texture, -1);
  11.656 +
  11.657 +    if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
  11.658 +        SDL_SetError("SDL_LockTexture(): texture must be streaming");
  11.659 +        return -1;
  11.660 +    }
  11.661 +    renderer = texture->renderer;
  11.662 +    if (!renderer->LockTexture) {
  11.663 +        SDL_Unsupported();
  11.664 +        return -1;
  11.665 +    }
  11.666 +    if (!rect) {
  11.667 +        full_rect.x = 0;
  11.668 +        full_rect.y = 0;
  11.669 +        full_rect.w = texture->w;
  11.670 +        full_rect.h = texture->h;
  11.671 +        rect = &full_rect;
  11.672 +    }
  11.673 +    return renderer->LockTexture(renderer, texture, rect, markDirty, pixels,
  11.674 +                                 pitch);
  11.675 +}
  11.676 +
  11.677 +void
  11.678 +SDL_UnlockTexture(SDL_Texture * texture)
  11.679 +{
  11.680 +    SDL_Renderer *renderer;
  11.681 +
  11.682 +    CHECK_TEXTURE_MAGIC(texture, );
  11.683 +
  11.684 +    if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
  11.685 +        return;
  11.686 +    }
  11.687 +    renderer = texture->renderer;
  11.688 +    if (!renderer->UnlockTexture) {
  11.689 +        return;
  11.690 +    }
  11.691 +    renderer->UnlockTexture(renderer, texture);
  11.692 +}
  11.693 +
  11.694 +void
  11.695 +SDL_DirtyTexture(SDL_Texture * texture, int numrects,
  11.696 +                 const SDL_Rect * rects)
  11.697 +{
  11.698 +    SDL_Renderer *renderer;
  11.699 +
  11.700 +    CHECK_TEXTURE_MAGIC(texture, );
  11.701 +
  11.702 +    if (texture->access != SDL_TEXTUREACCESS_STREAMING) {
  11.703 +        return;
  11.704 +    }
  11.705 +    renderer = texture->renderer;
  11.706 +    if (!renderer->DirtyTexture) {
  11.707 +        return;
  11.708 +    }
  11.709 +    renderer->DirtyTexture(renderer, texture, numrects, rects);
  11.710 +}
  11.711 +
  11.712 +int
  11.713 +SDL_SetRenderDrawColor(SDL_Renderer * renderer,
  11.714 +                       Uint8 r, Uint8 g, Uint8 b, Uint8 a)
  11.715 +{
  11.716 +    CHECK_RENDERER_MAGIC(renderer, -1);
  11.717 +
  11.718 +    renderer->r = r;
  11.719 +    renderer->g = g;
  11.720 +    renderer->b = b;
  11.721 +    renderer->a = a;
  11.722 +    return 0;
  11.723 +}
  11.724 +
  11.725 +int
  11.726 +SDL_GetRenderDrawColor(SDL_Renderer * renderer,
  11.727 +                       Uint8 * r, Uint8 * g, Uint8 * b, Uint8 * a)
  11.728 +{
  11.729 +    CHECK_RENDERER_MAGIC(renderer, -1);
  11.730 +
  11.731 +    if (r) {
  11.732 +        *r = renderer->r;
  11.733 +    }
  11.734 +    if (g) {
  11.735 +        *g = renderer->g;
  11.736 +    }
  11.737 +    if (b) {
  11.738 +        *b = renderer->b;
  11.739 +    }
  11.740 +    if (a) {
  11.741 +        *a = renderer->a;
  11.742 +    }
  11.743 +    return 0;
  11.744 +}
  11.745 +
  11.746 +int
  11.747 +SDL_SetRenderDrawBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode)
  11.748 +{
  11.749 +    CHECK_RENDERER_MAGIC(renderer, -1);
  11.750 +
  11.751 +    renderer->blendMode = blendMode;
  11.752 +    return 0;
  11.753 +}
  11.754 +
  11.755 +int
  11.756 +SDL_GetRenderDrawBlendMode(SDL_Renderer * renderer, SDL_BlendMode *blendMode)
  11.757 +{
  11.758 +    CHECK_RENDERER_MAGIC(renderer, -1);
  11.759 +
  11.760 +    *blendMode = renderer->blendMode;
  11.761 +    return 0;
  11.762 +}
  11.763 +
  11.764 +int
  11.765 +SDL_RenderClear(SDL_Renderer * renderer)
  11.766 +{
  11.767 +    CHECK_RENDERER_MAGIC(renderer, -1);
  11.768 +
  11.769 +    if (!renderer->RenderClear) {
  11.770 +        SDL_BlendMode blendMode = renderer->blendMode;
  11.771 +        int status;
  11.772 +
  11.773 +        if (blendMode >= SDL_BLENDMODE_BLEND) {
  11.774 +            SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
  11.775 +        }
  11.776 +
  11.777 +        status = SDL_RenderFillRect(renderer, NULL);
  11.778 +
  11.779 +        if (blendMode >= SDL_BLENDMODE_BLEND) {
  11.780 +            SDL_SetRenderDrawBlendMode(renderer, blendMode);
  11.781 +        }
  11.782 +        return status;
  11.783 +    }
  11.784 +    return renderer->RenderClear(renderer);
  11.785 +}
  11.786 +
  11.787 +int
  11.788 +SDL_RenderDrawPoint(SDL_Renderer * renderer, int x, int y)
  11.789 +{
  11.790 +    SDL_Point point;
  11.791 +
  11.792 +    point.x = x;
  11.793 +    point.y = y;
  11.794 +    return SDL_RenderDrawPoints(renderer, &point, 1);
  11.795 +}
  11.796 +
  11.797 +int
  11.798 +SDL_RenderDrawPoints(SDL_Renderer * renderer,
  11.799 +                     const SDL_Point * points, int count)
  11.800 +{
  11.801 +    CHECK_RENDERER_MAGIC(renderer, -1);
  11.802 +
  11.803 +    if (!points) {
  11.804 +        SDL_SetError("SDL_RenderDrawPoints(): Passed NULL points");
  11.805 +        return -1;
  11.806 +    }
  11.807 +    if (count < 1) {
  11.808 +        return 0;
  11.809 +    }
  11.810 +    return renderer->RenderDrawPoints(renderer, points, count);
  11.811 +}
  11.812 +
  11.813 +int
  11.814 +SDL_RenderDrawLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
  11.815 +{
  11.816 +    SDL_Point points[2];
  11.817 +
  11.818 +    points[0].x = x1;
  11.819 +    points[0].y = y1;
  11.820 +    points[1].x = x2;
  11.821 +    points[1].y = y2;
  11.822 +    return SDL_RenderDrawLines(renderer, points, 2);
  11.823 +}
  11.824 +
  11.825 +int
  11.826 +SDL_RenderDrawLines(SDL_Renderer * renderer,
  11.827 +                    const SDL_Point * points, int count)
  11.828 +{
  11.829 +    CHECK_RENDERER_MAGIC(renderer, -1);
  11.830 +
  11.831 +    if (!points) {
  11.832 +        SDL_SetError("SDL_RenderDrawLines(): Passed NULL points");
  11.833 +        return -1;
  11.834 +    }
  11.835 +    if (count < 2) {
  11.836 +        return 0;
  11.837 +    }
  11.838 +    return renderer->RenderDrawLines(renderer, points, count);
  11.839 +}
  11.840 +
  11.841 +int
  11.842 +SDL_RenderDrawRect(SDL_Renderer * renderer, const SDL_Rect * rect)
  11.843 +{
  11.844 +    SDL_Rect full_rect;
  11.845 +    SDL_Point points[5];
  11.846 +
  11.847 +    CHECK_RENDERER_MAGIC(renderer, -1);
  11.848 +
  11.849 +    /* If 'rect' == NULL, then outline the whole surface */
  11.850 +    if (!rect) {
  11.851 +        SDL_Window *window = renderer->window;
  11.852 +
  11.853 +        full_rect.x = 0;
  11.854 +        full_rect.y = 0;
  11.855 +        SDL_GetWindowSize(window, &full_rect.w, &full_rect.h);
  11.856 +        rect = &full_rect;
  11.857 +    }
  11.858 +
  11.859 +    points[0].x = rect->x;
  11.860 +    points[0].y = rect->y;
  11.861 +    points[1].x = rect->x+rect->w-1;
  11.862 +    points[1].y = rect->y;
  11.863 +    points[2].x = rect->x+rect->w-1;
  11.864 +    points[2].y = rect->y+rect->h-1;
  11.865 +    points[3].x = rect->x;
  11.866 +    points[3].y = rect->y+rect->h-1;
  11.867 +    points[4].x = rect->x;
  11.868 +    points[4].y = rect->y;
  11.869 +    return SDL_RenderDrawLines(renderer, points, 5);
  11.870 +}
  11.871 +
  11.872 +int
  11.873 +SDL_RenderDrawRects(SDL_Renderer * renderer,
  11.874 +                    const SDL_Rect ** rects, int count)
  11.875 +{
  11.876 +    int i;
  11.877 +
  11.878 +    CHECK_RENDERER_MAGIC(renderer, -1);
  11.879 +
  11.880 +    if (!rects) {
  11.881 +        SDL_SetError("SDL_RenderDrawRects(): Passed NULL rects");
  11.882 +        return -1;
  11.883 +    }
  11.884 +    if (count < 1) {
  11.885 +        return 0;
  11.886 +    }
  11.887 +
  11.888 +    /* Check for NULL rect, which means fill entire window */
  11.889 +    for (i = 0; i < count; ++i) {
  11.890 +        if (SDL_RenderDrawRect(renderer, rects[i]) < 0) {
  11.891 +            return -1;
  11.892 +        }
  11.893 +    }
  11.894 +    return 0;
  11.895 +}
  11.896 +
  11.897 +int
  11.898 +SDL_RenderFillRect(SDL_Renderer * renderer, const SDL_Rect * rect)
  11.899 +{
  11.900 +    return SDL_RenderFillRects(renderer, &rect, 1);
  11.901 +}
  11.902 +
  11.903 +int
  11.904 +SDL_RenderFillRects(SDL_Renderer * renderer,
  11.905 +                    const SDL_Rect ** rects, int count)
  11.906 +{
  11.907 +    int i;
  11.908 +
  11.909 +    CHECK_RENDERER_MAGIC(renderer, -1);
  11.910 +
  11.911 +    if (!rects) {
  11.912 +        SDL_SetError("SDL_RenderFillRects(): Passed NULL rects");
  11.913 +        return -1;
  11.914 +    }
  11.915 +    if (count < 1) {
  11.916 +        return 0;
  11.917 +    }
  11.918 +
  11.919 +    /* Check for NULL rect, which means fill entire window */
  11.920 +    for (i = 0; i < count; ++i) {
  11.921 +        if (rects[i] == NULL) {
  11.922 +            SDL_Window *window = renderer->window;
  11.923 +            SDL_Rect full_rect;
  11.924 +            const SDL_Rect *rect;
  11.925 +
  11.926 +            full_rect.x = 0;
  11.927 +            full_rect.y = 0;
  11.928 +            SDL_GetWindowSize(window, &full_rect.w, &full_rect.h);
  11.929 +            rect = &full_rect;
  11.930 +            return renderer->RenderFillRects(renderer, &rect, 1);
  11.931 +        }
  11.932 +    }
  11.933 +    return renderer->RenderFillRects(renderer, rects, count);
  11.934 +}
  11.935 +
  11.936 +int
  11.937 +SDL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
  11.938 +               const SDL_Rect * srcrect, const SDL_Rect * dstrect)
  11.939 +{
  11.940 +    SDL_Window *window;
  11.941 +    SDL_Rect real_srcrect;
  11.942 +    SDL_Rect real_dstrect;
  11.943 +
  11.944 +    CHECK_RENDERER_MAGIC(renderer, -1);
  11.945 +    CHECK_TEXTURE_MAGIC(texture, -1);
  11.946 +
  11.947 +    if (renderer != texture->renderer) {
  11.948 +        SDL_SetError("Texture was not created with this renderer");
  11.949 +        return -1;
  11.950 +    }
  11.951 +    window = renderer->window;
  11.952 +
  11.953 +    real_srcrect.x = 0;
  11.954 +    real_srcrect.y = 0;
  11.955 +    real_srcrect.w = texture->w;
  11.956 +    real_srcrect.h = texture->h;
  11.957 +    if (srcrect) {
  11.958 +        if (!SDL_IntersectRect(srcrect, &real_srcrect, &real_srcrect)) {
  11.959 +            return 0;
  11.960 +        }
  11.961 +    }
  11.962 +
  11.963 +    real_dstrect.x = 0;
  11.964 +    real_dstrect.y = 0;
  11.965 +    SDL_GetWindowSize(window, &real_dstrect.w, &real_dstrect.h);
  11.966 +    if (dstrect) {
  11.967 +        if (!SDL_IntersectRect(dstrect, &real_dstrect, &real_dstrect)) {
  11.968 +            return 0;
  11.969 +        }
  11.970 +        /* Clip srcrect by the same amount as dstrect was clipped */
  11.971 +        if (dstrect->w != real_dstrect.w) {
  11.972 +            int deltax = (real_dstrect.x - dstrect->x);
  11.973 +            int deltaw = (real_dstrect.w - dstrect->w);
  11.974 +            real_srcrect.x += (deltax * real_srcrect.w) / dstrect->w;
  11.975 +            real_srcrect.w += (deltaw * real_srcrect.w) / dstrect->w;
  11.976 +        }
  11.977 +        if (dstrect->h != real_dstrect.h) {
  11.978 +            int deltay = (real_dstrect.y - dstrect->y);
  11.979 +            int deltah = (real_dstrect.h - dstrect->h);
  11.980 +            real_srcrect.y += (deltay * real_srcrect.h) / dstrect->h;
  11.981 +            real_srcrect.h += (deltah * real_srcrect.h) / dstrect->h;
  11.982 +        }
  11.983 +    }
  11.984 +
  11.985 +    return renderer->RenderCopy(renderer, texture, &real_srcrect,
  11.986 +                                &real_dstrect);
  11.987 +}
  11.988 +
  11.989 +int
  11.990 +SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
  11.991 +                     Uint32 format, void * pixels, int pitch)
  11.992 +{
  11.993 +    SDL_Window *window;
  11.994 +    SDL_Rect real_rect;
  11.995 +
  11.996 +    CHECK_RENDERER_MAGIC(renderer, -1);
  11.997 +
  11.998 +    if (!renderer->RenderReadPixels) {
  11.999 +        SDL_Unsupported();
 11.1000 +        return -1;
 11.1001 +    }
 11.1002 +    window = renderer->window;
 11.1003 +
 11.1004 +    if (!format) {
 11.1005 +        format = SDL_GetWindowPixelFormat(window);
 11.1006 +    }
 11.1007 +
 11.1008 +    real_rect.x = 0;
 11.1009 +    real_rect.y = 0;
 11.1010 +    SDL_GetWindowSize(window, &real_rect.w, &real_rect.h);
 11.1011 +    if (rect) {
 11.1012 +        if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
 11.1013 +            return 0;
 11.1014 +        }
 11.1015 +        if (real_rect.y > rect->y) {
 11.1016 +            pixels = (Uint8 *)pixels + pitch * (real_rect.y - rect->y);
 11.1017 +        }
 11.1018 +        if (real_rect.x > rect->x) {
 11.1019 +            int bpp = SDL_BYTESPERPIXEL(SDL_GetWindowPixelFormat(window));
 11.1020 +            pixels = (Uint8 *)pixels + bpp * (real_rect.x - rect->x);
 11.1021 +        }
 11.1022 +    }
 11.1023 +
 11.1024 +    return renderer->RenderReadPixels(renderer, &real_rect,
 11.1025 +                                      format, pixels, pitch);
 11.1026 +}
 11.1027 +
 11.1028 +int
 11.1029 +SDL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
 11.1030 +                      Uint32 format, const void * pixels, int pitch)
 11.1031 +{
 11.1032 +    SDL_Window *window;
 11.1033 +    SDL_Rect real_rect;
 11.1034 +
 11.1035 +    CHECK_RENDERER_MAGIC(renderer, -1);
 11.1036 +
 11.1037 +    if (!renderer->RenderWritePixels) {
 11.1038 +        SDL_Unsupported();
 11.1039 +        return -1;
 11.1040 +    }
 11.1041 +    window = renderer->window;
 11.1042 +
 11.1043 +    if (!format) {
 11.1044 +        format = SDL_GetWindowPixelFormat(window);
 11.1045 +    }
 11.1046 +
 11.1047 +    real_rect.x = 0;
 11.1048 +    real_rect.y = 0;
 11.1049 +    SDL_GetWindowSize(window, &real_rect.w, &real_rect.h);
 11.1050 +    if (rect) {
 11.1051 +        if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) {
 11.1052 +            return 0;
 11.1053 +        }
 11.1054 +        if (real_rect.y > rect->y) {
 11.1055 +            pixels = (const Uint8 *)pixels + pitch * (real_rect.y - rect->y);
 11.1056 +        }
 11.1057 +        if (real_rect.x > rect->x) {
 11.1058 +            int bpp = SDL_BYTESPERPIXEL(SDL_GetWindowPixelFormat(window));
 11.1059 +            pixels = (const Uint8 *)pixels + bpp * (real_rect.x - rect->x);
 11.1060 +        }
 11.1061 +    }
 11.1062 +
 11.1063 +    return renderer->RenderWritePixels(renderer, &real_rect,
 11.1064 +                                       format, pixels, pitch);
 11.1065 +}
 11.1066 +
 11.1067 +void
 11.1068 +SDL_RenderPresent(SDL_Renderer * renderer)
 11.1069 +{
 11.1070 +    CHECK_RENDERER_MAGIC(renderer, );
 11.1071 +
 11.1072 +    renderer->RenderPresent(renderer);
 11.1073 +}
 11.1074 +
 11.1075 +void
 11.1076 +SDL_DestroyTexture(SDL_Texture * texture)
 11.1077 +{
 11.1078 +    SDL_Renderer *renderer;
 11.1079 +
 11.1080 +    CHECK_TEXTURE_MAGIC(texture, );
 11.1081 +    texture->magic = NULL;
 11.1082 +
 11.1083 +    renderer = texture->renderer;
 11.1084 +    if (texture->next) {
 11.1085 +        texture->next->prev = texture->prev;
 11.1086 +    }
 11.1087 +    if (texture->prev) {
 11.1088 +        texture->prev->next = texture->next;
 11.1089 +    } else {
 11.1090 +        renderer->textures = texture->next;
 11.1091 +    }
 11.1092 +
 11.1093 +    renderer->DestroyTexture(renderer, texture);
 11.1094 +    SDL_free(texture);
 11.1095 +}
 11.1096 +
 11.1097 +void
 11.1098 +SDL_DestroyRenderer(SDL_Renderer * renderer)
 11.1099 +{
 11.1100 +    CHECK_RENDERER_MAGIC(renderer, );
 11.1101 +
 11.1102 +    SDL_DelEventWatch(SDL_RendererEventWatch, renderer);
 11.1103 +
 11.1104 +    /* Free existing textures for this renderer */
 11.1105 +    while (renderer->textures) {
 11.1106 +        SDL_DestroyTexture(renderer->textures);
 11.1107 +    }
 11.1108 +
 11.1109 +    /* It's no longer magical... */
 11.1110 +    renderer->magic = NULL;
 11.1111 +
 11.1112 +    /* Free the renderer instance */
 11.1113 +    renderer->DestroyRenderer(renderer);
 11.1114 +}
 11.1115 +
 11.1116 +/* vi: set ts=4 sw=4 expandtab: */
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/render/SDL_sysrender.h	Wed Feb 02 14:34:54 2011 -0800
    12.3 @@ -0,0 +1,133 @@
    12.4 +/*
    12.5 +    SDL - Simple DirectMedia Layer
    12.6 +    Copyright (C) 1997-2010 Sam Lantinga
    12.7 +
    12.8 +    This library is free software; you can redistribute it and/or
    12.9 +    modify it under the terms of the GNU Lesser General Public
   12.10 +    License as published by the Free Software Foundation; either
   12.11 +    version 2.1 of the License, or (at your option) any later version.
   12.12 +
   12.13 +    This library is distributed in the hope that it will be useful,
   12.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   12.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12.16 +    Lesser General Public License for more details.
   12.17 +
   12.18 +    You should have received a copy of the GNU Lesser General Public
   12.19 +    License along with this library; if not, write to the Free Software
   12.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   12.21 +
   12.22 +    Sam Lantinga
   12.23 +    slouken@libsdl.org
   12.24 +*/
   12.25 +#include "SDL_config.h"
   12.26 +
   12.27 +#ifndef _SDL_sysrender_h
   12.28 +#define _SDL_sysrender_h
   12.29 +
   12.30 +#include "SDL_render.h"
   12.31 +#include "SDL_events.h"
   12.32 +
   12.33 +/* The SDL 2D rendering system */
   12.34 +
   12.35 +typedef struct SDL_RenderDriver SDL_RenderDriver;
   12.36 +
   12.37 +/* Define the SDL texture structure */
   12.38 +struct SDL_Texture
   12.39 +{
   12.40 +    const void *magic;
   12.41 +    Uint32 format;              /**< The pixel format of the texture */
   12.42 +    int access;                 /**< SDL_TextureAccess */
   12.43 +    int w;                      /**< The width of the texture */
   12.44 +    int h;                      /**< The height of the texture */
   12.45 +    int modMode;                /**< The texture modulation mode */
   12.46 +    SDL_BlendMode blendMode;    /**< The texture blend mode */
   12.47 +    Uint8 r, g, b, a;           /**< Texture modulation values */
   12.48 +
   12.49 +    SDL_Renderer *renderer;
   12.50 +
   12.51 +    void *driverdata;           /**< Driver specific texture representation */
   12.52 +
   12.53 +    SDL_Texture *prev;
   12.54 +    SDL_Texture *next;
   12.55 +};
   12.56 +
   12.57 +/* Define the SDL renderer structure */
   12.58 +struct SDL_Renderer
   12.59 +{
   12.60 +    const void *magic;
   12.61 +
   12.62 +    void (*WindowEvent) (SDL_Renderer * renderer, const SDL_WindowEvent *event);
   12.63 +    int (*CreateTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
   12.64 +    int (*QueryTexturePixels) (SDL_Renderer * renderer, SDL_Texture * texture,
   12.65 +                               void **pixels, int *pitch);
   12.66 +    int (*SetTextureColorMod) (SDL_Renderer * renderer,
   12.67 +                               SDL_Texture * texture);
   12.68 +    int (*SetTextureAlphaMod) (SDL_Renderer * renderer,
   12.69 +                               SDL_Texture * texture);
   12.70 +    int (*SetTextureBlendMode) (SDL_Renderer * renderer,
   12.71 +                                SDL_Texture * texture);
   12.72 +    int (*UpdateTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
   12.73 +                          const SDL_Rect * rect, const void *pixels,
   12.74 +                          int pitch);
   12.75 +    int (*LockTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
   12.76 +                        const SDL_Rect * rect, int markDirty, void **pixels,
   12.77 +                        int *pitch);
   12.78 +    void (*UnlockTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
   12.79 +    void (*DirtyTexture) (SDL_Renderer * renderer, SDL_Texture * texture,
   12.80 +                          int numrects, const SDL_Rect * rects);
   12.81 +    int (*RenderClear) (SDL_Renderer * renderer);
   12.82 +    int (*RenderDrawPoints) (SDL_Renderer * renderer, const SDL_Point * points,
   12.83 +                             int count);
   12.84 +    int (*RenderDrawLines) (SDL_Renderer * renderer, const SDL_Point * points,
   12.85 +                            int count);
   12.86 +    int (*RenderFillRects) (SDL_Renderer * renderer, const SDL_Rect ** rects,
   12.87 +                            int count);
   12.88 +    int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
   12.89 +                       const SDL_Rect * srcrect, const SDL_Rect * dstrect);
   12.90 +    int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
   12.91 +                             Uint32 format, void * pixels, int pitch);
   12.92 +    int (*RenderWritePixels) (SDL_Renderer * renderer, const SDL_Rect * rect,
   12.93 +                              Uint32 format, const void * pixels, int pitch);
   12.94 +    void (*RenderPresent) (SDL_Renderer * renderer);
   12.95 +    void (*DestroyTexture) (SDL_Renderer * renderer, SDL_Texture * texture);
   12.96 +
   12.97 +    void (*DestroyRenderer) (SDL_Renderer * renderer);
   12.98 +
   12.99 +    /* The current renderer info */
  12.100 +    SDL_RendererInfo info;
  12.101 +
  12.102 +    /* The window associated with the renderer */
  12.103 +    SDL_Window *window;
  12.104 +
  12.105 +    /* The list of textures */
  12.106 +    SDL_Texture *textures;
  12.107 +
  12.108 +    Uint8 r, g, b, a;                   /**< Color for drawing operations values */
  12.109 +    SDL_BlendMode blendMode;            /**< The drawing blend mode */
  12.110 +
  12.111 +    void *driverdata;
  12.112 +};
  12.113 +
  12.114 +/* Define the SDL render driver structure */
  12.115 +struct SDL_RenderDriver
  12.116 +{
  12.117 +    SDL_Renderer *(*CreateRenderer) (SDL_Window * window, Uint32 flags);
  12.118 +
  12.119 +    /* Info about the renderer capabilities */
  12.120 +    SDL_RendererInfo info;
  12.121 +};
  12.122 +
  12.123 +#if SDL_VIDEO_RENDER_D3D
  12.124 +extern SDL_RenderDriver D3D_RenderDriver;
  12.125 +#endif
  12.126 +#if SDL_VIDEO_RENDER_OGL
  12.127 +extern SDL_RenderDriver GL_RenderDriver;
  12.128 +#endif
  12.129 +#if SDL_VIDEO_RENDER_OGL_ES
  12.130 +extern SDL_RenderDriver GL_ES_RenderDriver;
  12.131 +#endif
  12.132 +extern SDL_RenderDriver SW_RenderDriver;
  12.133 +
  12.134 +#endif /* _SDL_sysrender_h */
  12.135 +
  12.136 +/* vi: set ts=4 sw=4 expandtab: */
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/render/direct3d/SDL_d3drender.c	Wed Feb 02 14:34:54 2011 -0800
    13.3 @@ -0,0 +1,1260 @@
    13.4 +/*
    13.5 +    SDL - Simple DirectMedia Layer
    13.6 +    Copyright (C) 1997-2010 Sam Lantinga
    13.7 +
    13.8 +    This library is free software; you can redistribute it and/or
    13.9 +    modify it under the terms of the GNU Lesser General Public
   13.10 +    License as published by the Free Software Foundation; either
   13.11 +    version 2.1 of the License, or (at your option) any later version.
   13.12 +
   13.13 +    This library is distributed in the hope that it will be useful,
   13.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13.16 +    Lesser General Public License for more details.
   13.17 +
   13.18 +    You should have received a copy of the GNU Lesser General Public
   13.19 +    License along with this library; if not, write to the Free Software
   13.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   13.21 +
   13.22 +    Sam Lantinga
   13.23 +    slouken@libsdl.org
   13.24 +*/
   13.25 +#include "SDL_config.h"
   13.26 +
   13.27 +#if SDL_VIDEO_RENDER_D3D
   13.28 +
   13.29 +#include "../../core/windows/SDL_windows.h"
   13.30 +
   13.31 +#include "SDL_loadso.h"
   13.32 +#include "SDL_syswm.h"
   13.33 +#include "../SDL_sysrender.h"
   13.34 +#include "../../video/SDL_yuv_sw_c.h"
   13.35 +
   13.36 +#if SDL_VIDEO_RENDER_D3D
   13.37 +#define D3D_DEBUG_INFO
   13.38 +#include <d3d9.h>
   13.39 +#endif
   13.40 +
   13.41 +#ifdef ASSEMBLE_SHADER
   13.42 +///////////////////////////////////////////////////////////////////////////
   13.43 +// ID3DXBuffer:
   13.44 +// ------------
   13.45 +// The buffer object is used by D3DX to return arbitrary size data.
   13.46 +//
   13.47 +// GetBufferPointer -
   13.48 +//    Returns a pointer to the beginning of the buffer.
   13.49 +//
   13.50 +// GetBufferSize -
   13.51 +//    Returns the size of the buffer, in bytes.
   13.52 +///////////////////////////////////////////////////////////////////////////
   13.53 +
   13.54 +typedef interface ID3DXBuffer ID3DXBuffer;
   13.55 +typedef interface ID3DXBuffer *LPD3DXBUFFER;
   13.56 +
   13.57 +// {8BA5FB08-5195-40e2-AC58-0D989C3A0102}
   13.58 +DEFINE_GUID(IID_ID3DXBuffer, 
   13.59 +0x8ba5fb08, 0x5195, 0x40e2, 0xac, 0x58, 0xd, 0x98, 0x9c, 0x3a, 0x1, 0x2);
   13.60 +
   13.61 +#undef INTERFACE
   13.62 +#define INTERFACE ID3DXBuffer
   13.63 +
   13.64 +typedef interface ID3DXBuffer {
   13.65 +    const struct ID3DXBufferVtbl FAR* lpVtbl;
   13.66 +} ID3DXBuffer;
   13.67 +typedef const struct ID3DXBufferVtbl ID3DXBufferVtbl;
   13.68 +const struct ID3DXBufferVtbl
   13.69 +{
   13.70 +    // IUnknown
   13.71 +    STDMETHOD(QueryInterface)(THIS_ REFIID iid, LPVOID *ppv) PURE;
   13.72 +    STDMETHOD_(ULONG, AddRef)(THIS) PURE;
   13.73 +    STDMETHOD_(ULONG, Release)(THIS) PURE;
   13.74 +
   13.75 +    // ID3DXBuffer
   13.76 +    STDMETHOD_(LPVOID, GetBufferPointer)(THIS) PURE;
   13.77 +    STDMETHOD_(DWORD, GetBufferSize)(THIS) PURE;
   13.78 +};
   13.79 +
   13.80 +HRESULT WINAPI
   13.81 +    D3DXAssembleShader(
   13.82 +        LPCSTR                          pSrcData,
   13.83 +        UINT                            SrcDataLen,
   13.84 +        CONST LPVOID*                   pDefines,
   13.85 +        LPVOID                          pInclude,
   13.86 +        DWORD                           Flags,
   13.87 +        LPD3DXBUFFER*                   ppShader,
   13.88 +        LPD3DXBUFFER*                   ppErrorMsgs);
   13.89 +
   13.90 +#endif /* ASSEMBLE_SHADER */
   13.91 +
   13.92 +
   13.93 +/* Direct3D renderer implementation */
   13.94 +
   13.95 +#if 1                           /* This takes more memory but you won't lose your texture data */
   13.96 +#define D3DPOOL_SDL    D3DPOOL_MANAGED
   13.97 +#define SDL_MEMORY_POOL_MANAGED
   13.98 +#else
   13.99 +#define D3DPOOL_SDL    D3DPOOL_DEFAULT
  13.100 +#define SDL_MEMORY_POOL_DEFAULT
  13.101 +#endif
  13.102 +
  13.103 +static SDL_Renderer *D3D_CreateRenderer(SDL_Window * window, Uint32 flags);
  13.104 +static int D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
  13.105 +static int D3D_QueryTexturePixels(SDL_Renderer * renderer,
  13.106 +                                  SDL_Texture * texture, void **pixels,
  13.107 +                                  int *pitch);
  13.108 +static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  13.109 +                             const SDL_Rect * rect, const void *pixels,
  13.110 +                             int pitch);
  13.111 +static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  13.112 +                           const SDL_Rect * rect, int markDirty,
  13.113 +                           void **pixels, int *pitch);
  13.114 +static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
  13.115 +static void D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  13.116 +                             int numrects, const SDL_Rect * rects);
  13.117 +static int D3D_RenderDrawPoints(SDL_Renderer * renderer,
  13.118 +                                const SDL_Point * points, int count);
  13.119 +static int D3D_RenderDrawLines(SDL_Renderer * renderer,
  13.120 +                               const SDL_Point * points, int count);
  13.121 +static int D3D_RenderFillRects(SDL_Renderer * renderer,
  13.122 +                               const SDL_Rect ** rects, int count);
  13.123 +static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
  13.124 +                          const SDL_Rect * srcrect, const SDL_Rect * dstrect);
  13.125 +static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
  13.126 +                                Uint32 format, void * pixels, int pitch);
  13.127 +static int D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
  13.128 +                                 Uint32 format, const void * pixels, int pitch);
  13.129 +static void D3D_RenderPresent(SDL_Renderer * renderer);
  13.130 +static void D3D_DestroyTexture(SDL_Renderer * renderer,
  13.131 +                               SDL_Texture * texture);
  13.132 +static void D3D_DestroyRenderer(SDL_Renderer * renderer);
  13.133 +
  13.134 +
  13.135 +SDL_RenderDriver D3D_RenderDriver = {
  13.136 +    D3D_CreateRenderer,
  13.137 +    {
  13.138 +     "d3d",
  13.139 +     (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
  13.140 +     0,
  13.141 +     {0},
  13.142 +     0,
  13.143 +     0}
  13.144 +};
  13.145 +
  13.146 +typedef struct
  13.147 +{
  13.148 +    void* d3dDLL;
  13.149 +    IDirect3D9 *d3d;
  13.150 +    IDirect3DDevice9 *device;
  13.151 +    UINT adapter;
  13.152 +    D3DPRESENT_PARAMETERS pparams;
  13.153 +    SDL_bool beginScene;
  13.154 +} D3D_RenderData;
  13.155 +
  13.156 +typedef struct
  13.157 +{
  13.158 +    SDL_SW_YUVTexture *yuv;
  13.159 +    Uint32 format;
  13.160 +    IDirect3DTexture9 *texture;
  13.161 +} D3D_TextureData;
  13.162 +
  13.163 +typedef struct
  13.164 +{
  13.165 +    float x, y, z;
  13.166 +    float rhw;
  13.167 +    DWORD color;
  13.168 +    float u, v;
  13.169 +} Vertex;
  13.170 +
  13.171 +static void
  13.172 +D3D_SetError(const char *prefix, HRESULT result)
  13.173 +{
  13.174 +    const char *error;
  13.175 +
  13.176 +    switch (result) {
  13.177 +    case D3DERR_WRONGTEXTUREFORMAT:
  13.178 +        error = "WRONGTEXTUREFORMAT";
  13.179 +        break;
  13.180 +    case D3DERR_UNSUPPORTEDCOLOROPERATION:
  13.181 +        error = "UNSUPPORTEDCOLOROPERATION";
  13.182 +        break;
  13.183 +    case D3DERR_UNSUPPORTEDCOLORARG:
  13.184 +        error = "UNSUPPORTEDCOLORARG";
  13.185 +        break;
  13.186 +    case D3DERR_UNSUPPORTEDALPHAOPERATION:
  13.187 +        error = "UNSUPPORTEDALPHAOPERATION";
  13.188 +        break;
  13.189 +    case D3DERR_UNSUPPORTEDALPHAARG:
  13.190 +        error = "UNSUPPORTEDALPHAARG";
  13.191 +        break;
  13.192 +    case D3DERR_TOOMANYOPERATIONS:
  13.193 +        error = "TOOMANYOPERATIONS";
  13.194 +        break;
  13.195 +    case D3DERR_CONFLICTINGTEXTUREFILTER:
  13.196 +        error = "CONFLICTINGTEXTUREFILTER";
  13.197 +        break;
  13.198 +    case D3DERR_UNSUPPORTEDFACTORVALUE:
  13.199 +        error = "UNSUPPORTEDFACTORVALUE";
  13.200 +        break;
  13.201 +    case D3DERR_CONFLICTINGRENDERSTATE:
  13.202 +        error = "CONFLICTINGRENDERSTATE";
  13.203 +        break;
  13.204 +    case D3DERR_UNSUPPORTEDTEXTUREFILTER:
  13.205 +        error = "UNSUPPORTEDTEXTUREFILTER";
  13.206 +        break;
  13.207 +    case D3DERR_CONFLICTINGTEXTUREPALETTE:
  13.208 +        error = "CONFLICTINGTEXTUREPALETTE";
  13.209 +        break;
  13.210 +    case D3DERR_DRIVERINTERNALERROR:
  13.211 +        error = "DRIVERINTERNALERROR";
  13.212 +        break;
  13.213 +    case D3DERR_NOTFOUND:
  13.214 +        error = "NOTFOUND";
  13.215 +        break;
  13.216 +    case D3DERR_MOREDATA:
  13.217 +        error = "MOREDATA";
  13.218 +        break;
  13.219 +    case D3DERR_DEVICELOST:
  13.220 +        error = "DEVICELOST";
  13.221 +        break;
  13.222 +    case D3DERR_DEVICENOTRESET:
  13.223 +        error = "DEVICENOTRESET";
  13.224 +        break;
  13.225 +    case D3DERR_NOTAVAILABLE:
  13.226 +        error = "NOTAVAILABLE";
  13.227 +        break;
  13.228 +    case D3DERR_OUTOFVIDEOMEMORY:
  13.229 +        error = "OUTOFVIDEOMEMORY";
  13.230 +        break;
  13.231 +    case D3DERR_INVALIDDEVICE:
  13.232 +        error = "INVALIDDEVICE";
  13.233 +        break;
  13.234 +    case D3DERR_INVALIDCALL:
  13.235 +        error = "INVALIDCALL";
  13.236 +        break;
  13.237 +    case D3DERR_DRIVERINVALIDCALL:
  13.238 +        error = "DRIVERINVALIDCALL";
  13.239 +        break;
  13.240 +    case D3DERR_WASSTILLDRAWING:
  13.241 +        error = "WASSTILLDRAWING";
  13.242 +        break;
  13.243 +    default:
  13.244 +        error = "UNKNOWN";
  13.245 +        break;
  13.246 +    }
  13.247 +    SDL_SetError("%s: %s", prefix, error);
  13.248 +}
  13.249 +
  13.250 +static D3DFORMAT
  13.251 +PixelFormatToD3DFMT(Uint32 format)
  13.252 +{
  13.253 +    switch (format) {
  13.254 +    case SDL_PIXELFORMAT_INDEX8:
  13.255 +        return D3DFMT_P8;
  13.256 +    case SDL_PIXELFORMAT_RGB332:
  13.257 +        return D3DFMT_R3G3B2;
  13.258 +    case SDL_PIXELFORMAT_RGB444:
  13.259 +        return D3DFMT_X4R4G4B4;
  13.260 +    case SDL_PIXELFORMAT_RGB555:
  13.261 +        return D3DFMT_X1R5G5B5;
  13.262 +    case SDL_PIXELFORMAT_ARGB4444:
  13.263 +        return D3DFMT_A4R4G4B4;
  13.264 +    case SDL_PIXELFORMAT_ARGB1555:
  13.265 +        return D3DFMT_A1R5G5B5;
  13.266 +    case SDL_PIXELFORMAT_RGB565:
  13.267 +        return D3DFMT_R5G6B5;
  13.268 +    case SDL_PIXELFORMAT_RGB888:
  13.269 +        return D3DFMT_X8R8G8B8;
  13.270 +    case SDL_PIXELFORMAT_ARGB8888:
  13.271 +        return D3DFMT_A8R8G8B8;
  13.272 +    case SDL_PIXELFORMAT_ARGB2101010:
  13.273 +        return D3DFMT_A2R10G10B10;
  13.274 +    case SDL_PIXELFORMAT_YV12:
  13.275 +        return MAKEFOURCC('Y','V','1','2');
  13.276 +    case SDL_PIXELFORMAT_IYUV:
  13.277 +        return MAKEFOURCC('I','4','2','0');
  13.278 +    case SDL_PIXELFORMAT_UYVY:
  13.279 +        return D3DFMT_UYVY;
  13.280 +    case SDL_PIXELFORMAT_YUY2:
  13.281 +        return D3DFMT_YUY2;
  13.282 +    default:
  13.283 +        return D3DFMT_UNKNOWN;
  13.284 +    }
  13.285 +}
  13.286 +
  13.287 +static SDL_bool
  13.288 +D3D_IsTextureFormatAvailable(IDirect3D9 * d3d, UINT adapter,
  13.289 +                             D3DFORMAT display_format,
  13.290 +                             D3DFORMAT texture_format)
  13.291 +{
  13.292 +    HRESULT result;
  13.293 +
  13.294 +    result = IDirect3D9_CheckDeviceFormat(d3d, adapter,
  13.295 +                                          D3DDEVTYPE_HAL,
  13.296 +                                          display_format,
  13.297 +                                          0,
  13.298 +                                          D3DRTYPE_TEXTURE,
  13.299 +                                          texture_format);
  13.300 +    return FAILED(result) ? SDL_FALSE : SDL_TRUE;
  13.301 +}
  13.302 +
  13.303 +static void
  13.304 +UpdateYUVTextureData(SDL_Texture * texture)
  13.305 +{
  13.306 +    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
  13.307 +    SDL_Rect rect;
  13.308 +    RECT d3drect;
  13.309 +    D3DLOCKED_RECT locked;
  13.310 +    HRESULT result;
  13.311 +
  13.312 +    d3drect.left = 0;
  13.313 +    d3drect.right = texture->w;
  13.314 +    d3drect.top = 0;
  13.315 +    d3drect.bottom = texture->h;
  13.316 +
  13.317 +    result =
  13.318 +        IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect, 0);
  13.319 +    if (FAILED(result)) {
  13.320 +        return;
  13.321 +    }
  13.322 +
  13.323 +    rect.x = 0;
  13.324 +    rect.y = 0;
  13.325 +    rect.w = texture->w;
  13.326 +    rect.h = texture->h;
  13.327 +    SDL_SW_CopyYUVToRGB(data->yuv, &rect, data->format, texture->w,
  13.328 +                        texture->h, locked.pBits, locked.Pitch);
  13.329 +
  13.330 +    IDirect3DTexture9_UnlockRect(data->texture, 0);
  13.331 +}
  13.332 +
  13.333 +static void
  13.334 +D3D_AddTextureFormats(D3D_RenderData *data, SDL_RendererInfo *info)
  13.335 +{
  13.336 +    int i;
  13.337 +    int formats[] = {
  13.338 +        SDL_PIXELFORMAT_RGB332,
  13.339 +        SDL_PIXELFORMAT_RGB444,
  13.340 +        SDL_PIXELFORMAT_RGB555,
  13.341 +        SDL_PIXELFORMAT_ARGB4444,
  13.342 +        SDL_PIXELFORMAT_ARGB1555,
  13.343 +        SDL_PIXELFORMAT_RGB565,
  13.344 +        SDL_PIXELFORMAT_RGB888,
  13.345 +        SDL_PIXELFORMAT_ARGB8888,
  13.346 +        SDL_PIXELFORMAT_ARGB2101010,
  13.347 +    };
  13.348 +
  13.349 +    info->num_texture_formats = 0;
  13.350 +    for (i = 0; i < SDL_arraysize(formats); ++i) {
  13.351 +        if (D3D_IsTextureFormatAvailable
  13.352 +            (data->d3d, data->adapter, data->pparams.BackBufferFormat, PixelFormatToD3DFMT(formats[i]))) {
  13.353 +            info->texture_formats[info->num_texture_formats++] = formats[i];
  13.354 +        }
  13.355 +    }
  13.356 +    info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YV12;
  13.357 +    info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_IYUV;
  13.358 +    info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YUY2;
  13.359 +    info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_UYVY;
  13.360 +    info->texture_formats[info->num_texture_formats++] = SDL_PIXELFORMAT_YVYU;
  13.361 +}
  13.362 +
  13.363 +SDL_Renderer *
  13.364 +D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
  13.365 +{
  13.366 +    SDL_Renderer *renderer;
  13.367 +    D3D_RenderData *data;
  13.368 +    SDL_SysWMinfo windowinfo;
  13.369 +    HRESULT result;
  13.370 +    D3DPRESENT_PARAMETERS pparams;
  13.371 +    IDirect3DSwapChain9 *chain;
  13.372 +    D3DCAPS9 caps;
  13.373 +
  13.374 +    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
  13.375 +    if (!renderer) {
  13.376 +        SDL_OutOfMemory();
  13.377 +        return NULL;
  13.378 +    }
  13.379 +
  13.380 +    data = (D3D_RenderData *) SDL_calloc(1, sizeof(*data));
  13.381 +    if (!data) {
  13.382 +        SDL_free(renderer);
  13.383 +        SDL_OutOfMemory();
  13.384 +        return NULL;
  13.385 +    }
  13.386 +
  13.387 +    data->d3dDLL = SDL_LoadObject("D3D9.DLL");
  13.388 +    if (data->d3dDLL) {
  13.389 +        IDirect3D9 *(WINAPI * D3DCreate) (UINT SDKVersion);
  13.390 +
  13.391 +        D3DCreate =
  13.392 +            (IDirect3D9 * (WINAPI *) (UINT)) SDL_LoadFunction(data->d3dDLL,
  13.393 +                                                            "Direct3DCreate9");
  13.394 +        if (D3DCreate) {
  13.395 +            data->d3d = D3DCreate(D3D_SDK_VERSION);
  13.396 +        }
  13.397 +        if (!data->d3d) {
  13.398 +            SDL_UnloadObject(data->d3dDLL);
  13.399 +            data->d3dDLL = NULL;
  13.400 +        }
  13.401 +    }
  13.402 +    if (!data->d3d) {
  13.403 +        SDL_free(renderer);
  13.404 +        SDL_free(data);
  13.405 +        SDL_SetError("Unable to create Direct3D interface");
  13.406 +        return NULL;
  13.407 +    }
  13.408 +
  13.409 +    renderer->CreateTexture = D3D_CreateTexture;
  13.410 +    renderer->QueryTexturePixels = D3D_QueryTexturePixels;
  13.411 +    renderer->UpdateTexture = D3D_UpdateTexture;
  13.412 +    renderer->LockTexture = D3D_LockTexture;
  13.413 +    renderer->UnlockTexture = D3D_UnlockTexture;
  13.414 +    renderer->DirtyTexture = D3D_DirtyTexture;
  13.415 +    renderer->RenderDrawPoints = D3D_RenderDrawPoints;
  13.416 +    renderer->RenderDrawLines = D3D_RenderDrawLines;
  13.417 +    renderer->RenderFillRects = D3D_RenderFillRects;
  13.418 +    renderer->RenderCopy = D3D_RenderCopy;
  13.419 +    renderer->RenderReadPixels = D3D_RenderReadPixels;
  13.420 +    renderer->RenderWritePixels = D3D_RenderWritePixels;
  13.421 +    renderer->RenderPresent = D3D_RenderPresent;
  13.422 +    renderer->DestroyTexture = D3D_DestroyTexture;
  13.423 +    renderer->DestroyRenderer = D3D_DestroyRenderer;
  13.424 +    renderer->info = D3D_RenderDriver.info;
  13.425 +    renderer->window = window;
  13.426 +    renderer->driverdata = data;
  13.427 +
  13.428 +    renderer->info.flags = SDL_RENDERER_ACCELERATED;
  13.429 +
  13.430 +    SDL_VERSION(&windowinfo.version);
  13.431 +    SDL_GetWindowWMInfo(window, &windowinfo);
  13.432 +
  13.433 +    SDL_zero(pparams);
  13.434 +    pparams.hDeviceWindow = windowinfo.info.win.window;
  13.435 +    pparams.BackBufferWidth = window->w;
  13.436 +    pparams.BackBufferHeight = window->h;
  13.437 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
  13.438 +        pparams.BackBufferFormat =
  13.439 +            PixelFormatToD3DFMT(window->fullscreen_mode.format);
  13.440 +    } else {
  13.441 +        pparams.BackBufferFormat = D3DFMT_UNKNOWN;
  13.442 +    }
  13.443 +    pparams.BackBufferCount = 1;
  13.444 +    pparams.SwapEffect = D3DSWAPEFFECT_DISCARD;
  13.445 +
  13.446 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
  13.447 +        pparams.Windowed = FALSE;
  13.448 +        pparams.FullScreen_RefreshRateInHz =
  13.449 +            window->fullscreen_mode.refresh_rate;
  13.450 +    } else {
  13.451 +        pparams.Windowed = TRUE;
  13.452 +        pparams.FullScreen_RefreshRateInHz = 0;
  13.453 +    }
  13.454 +    if (flags & SDL_RENDERER_PRESENTVSYNC) {
  13.455 +        pparams.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
  13.456 +    } else {
  13.457 +        pparams.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
  13.458 +    }
  13.459 +
  13.460 +    /* FIXME: Which adapter? */
  13.461 +    data->adapter = D3DADAPTER_DEFAULT;
  13.462 +    IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps);
  13.463 +
  13.464 +    result = IDirect3D9_CreateDevice(data->d3d, data->adapter,
  13.465 +                                     D3DDEVTYPE_HAL,
  13.466 +                                     pparams.hDeviceWindow,
  13.467 +                                     (caps.
  13.468 +                                      DevCaps &
  13.469 +                                      D3DDEVCAPS_HWTRANSFORMANDLIGHT) ?
  13.470 +                                     D3DCREATE_HARDWARE_VERTEXPROCESSING :
  13.471 +                                     D3DCREATE_SOFTWARE_VERTEXPROCESSING,
  13.472 +                                     &pparams, &data->device);
  13.473 +    if (FAILED(result)) {
  13.474 +        D3D_DestroyRenderer(renderer);
  13.475 +        D3D_SetError("CreateDevice()", result);
  13.476 +        return NULL;
  13.477 +    }
  13.478 +    data->beginScene = SDL_TRUE;
  13.479 +
  13.480 +    /* Get presentation parameters to fill info */
  13.481 +    result = IDirect3DDevice9_GetSwapChain(data->device, 0, &chain);
  13.482 +    if (FAILED(result)) {
  13.483 +        D3D_DestroyRenderer(renderer);
  13.484 +        D3D_SetError("GetSwapChain()", result);
  13.485 +        return NULL;
  13.486 +    }
  13.487 +    result = IDirect3DSwapChain9_GetPresentParameters(chain, &pparams);
  13.488 +    if (FAILED(result)) {
  13.489 +        IDirect3DSwapChain9_Release(chain);
  13.490 +        D3D_DestroyRenderer(renderer);
  13.491 +        D3D_SetError("GetPresentParameters()", result);
  13.492 +        return NULL;
  13.493 +    }
  13.494 +    IDirect3DSwapChain9_Release(chain);
  13.495 +    if (pparams.PresentationInterval == D3DPRESENT_INTERVAL_ONE) {
  13.496 +        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
  13.497 +    }
  13.498 +    data->pparams = pparams;
  13.499 +
  13.500 +    D3D_AddTextureFormats(data, &renderer->info);
  13.501 +
  13.502 +    IDirect3DDevice9_GetDeviceCaps(data->device, &caps);
  13.503 +    renderer->info.max_texture_width = caps.MaxTextureWidth;
  13.504 +    renderer->info.max_texture_height = caps.MaxTextureHeight;
  13.505 +
  13.506 +    /* Set up parameters for rendering */
  13.507 +    IDirect3DDevice9_SetVertexShader(data->device, NULL);
  13.508 +    IDirect3DDevice9_SetFVF(data->device,
  13.509 +                            D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
  13.510 +    IDirect3DDevice9_SetRenderState(data->device, D3DRS_ZENABLE, D3DZB_FALSE);
  13.511 +    IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
  13.512 +                                    D3DCULL_NONE);
  13.513 +    IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
  13.514 +    /* Enable color modulation by diffuse color */
  13.515 +    IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLOROP,
  13.516 +                                          D3DTOP_MODULATE);
  13.517 +    IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG1,
  13.518 +                                          D3DTA_TEXTURE);
  13.519 +    IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_COLORARG2,
  13.520 +                                          D3DTA_DIFFUSE);
  13.521 +    /* Enable alpha modulation by diffuse alpha */
  13.522 +    IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAOP,
  13.523 +                                          D3DTOP_MODULATE);
  13.524 +    IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG1,
  13.525 +                                          D3DTA_TEXTURE);
  13.526 +    IDirect3DDevice9_SetTextureStageState(data->device, 0, D3DTSS_ALPHAARG2,
  13.527 +                                          D3DTA_DIFFUSE);
  13.528 +    /* Disable second texture stage, since we're done */
  13.529 +    IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_COLOROP,
  13.530 +                                          D3DTOP_DISABLE);
  13.531 +    IDirect3DDevice9_SetTextureStageState(data->device, 1, D3DTSS_ALPHAOP,
  13.532 +                                          D3DTOP_DISABLE);
  13.533 +
  13.534 +    return renderer;
  13.535 +}
  13.536 +
  13.537 +static int
  13.538 +D3D_Reset(SDL_Renderer * renderer)
  13.539 +{
  13.540 +    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
  13.541 +    HRESULT result;
  13.542 +
  13.543 +    result = IDirect3DDevice9_Reset(data->device, &data->pparams);
  13.544 +    if (FAILED(result)) {
  13.545 +        if (result == D3DERR_DEVICELOST) {
  13.546 +            /* Don't worry about it, we'll reset later... */
  13.547 +            return 0;
  13.548 +        } else {
  13.549 +            D3D_SetError("Reset()", result);
  13.550 +            return -1;
  13.551 +        }
  13.552 +    }
  13.553 +    IDirect3DDevice9_SetVertexShader(data->device, NULL);
  13.554 +    IDirect3DDevice9_SetFVF(data->device,
  13.555 +                            D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1);
  13.556 +    IDirect3DDevice9_SetRenderState(data->device, D3DRS_CULLMODE,
  13.557 +                                    D3DCULL_NONE);
  13.558 +    IDirect3DDevice9_SetRenderState(data->device, D3DRS_LIGHTING, FALSE);
  13.559 +    return 0;
  13.560 +}
  13.561 +
  13.562 +/* FIXME: This needs to be called... when? */
  13.563 +#if 0
  13.564 +static int
  13.565 +D3D_DisplayModeChanged(SDL_Renderer * renderer)
  13.566 +{
  13.567 +    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
  13.568 +    SDL_Window *window = renderer->window;
  13.569 +    SDL_VideoDisplay *display = window->display;
  13.570 +
  13.571 +    data->pparams.BackBufferWidth = window->w;
  13.572 +    data->pparams.BackBufferHeight = window->h;
  13.573 +    if (window->flags & SDL_WINDOW_FULLSCREEN) {
  13.574 +        data->pparams.BackBufferFormat =
  13.575 +            PixelFormatToD3DFMT(window->fullscreen_mode.format);
  13.576 +    } else {
  13.577 +        data->pparams.BackBufferFormat = D3DFMT_UNKNOWN;
  13.578 +    }
  13.579 +    return D3D_Reset(renderer);
  13.580 +}
  13.581 +#endif
  13.582 +
  13.583 +static int
  13.584 +D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  13.585 +{
  13.586 +    D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
  13.587 +    SDL_Window *window = renderer->window;
  13.588 +    D3DFORMAT display_format = renderdata->pparams.BackBufferFormat;
  13.589 +    D3D_TextureData *data;
  13.590 +    HRESULT result;
  13.591 +
  13.592 +    data = (D3D_TextureData *) SDL_calloc(1, sizeof(*data));
  13.593 +    if (!data) {
  13.594 +        SDL_OutOfMemory();
  13.595 +        return -1;
  13.596 +    }
  13.597 +
  13.598 +    texture->driverdata = data;
  13.599 +
  13.600 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format) &&
  13.601 +        (texture->format != SDL_PIXELFORMAT_YUY2 ||
  13.602 +         !D3D_IsTextureFormatAvailable(renderdata->d3d, renderdata->adapter,
  13.603 +                                       display_format, PixelFormatToD3DFMT(texture->format)))
  13.604 +        && (texture->format != SDL_PIXELFORMAT_YVYU
  13.605 +            || !D3D_IsTextureFormatAvailable(renderdata->d3d, renderdata->adapter,
  13.606 +                                             display_format, PixelFormatToD3DFMT(texture->format)))) {
  13.607 +        data->yuv =
  13.608 +            SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
  13.609 +        if (!data->yuv) {
  13.610 +            return -1;
  13.611 +        }
  13.612 +        data->format = SDL_GetWindowPixelFormat(window);
  13.613 +    } else {
  13.614 +        data->format = texture->format;
  13.615 +    }
  13.616 +
  13.617 +    result =
  13.618 +        IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
  13.619 +                                       texture->h, 1, 0,
  13.620 +                                       PixelFormatToD3DFMT(data->format),
  13.621 +                                       D3DPOOL_SDL, &data->texture, NULL);
  13.622 +    if (FAILED(result)) {
  13.623 +        D3D_SetError("CreateTexture()", result);
  13.624 +        return -1;
  13.625 +    }
  13.626 +
  13.627 +    return 0;
  13.628 +}
  13.629 +
  13.630 +static int
  13.631 +D3D_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
  13.632 +                       void **pixels, int *pitch)
  13.633 +{
  13.634 +    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
  13.635 +
  13.636 +    if (data->yuv) {
  13.637 +        return SDL_SW_QueryYUVTexturePixels(data->yuv, pixels, pitch);
  13.638 +    } else {
  13.639 +        /* D3D textures don't have their pixels hanging out */
  13.640 +        return -1;
  13.641 +    }
  13.642 +}
  13.643 +
  13.644 +static int
  13.645 +D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  13.646 +                  const SDL_Rect * rect, const void *pixels, int pitch)
  13.647 +{
  13.648 +    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
  13.649 +    D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata;
  13.650 +
  13.651 +    if (data->yuv) {
  13.652 +        if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) {
  13.653 +            return -1;
  13.654 +        }
  13.655 +        UpdateYUVTextureData(texture);
  13.656 +        return 0;
  13.657 +    } else {
  13.658 +#ifdef SDL_MEMORY_POOL_DEFAULT
  13.659 +        IDirect3DTexture9 *temp;
  13.660 +        RECT d3drect;
  13.661 +        D3DLOCKED_RECT locked;
  13.662 +        const Uint8 *src;
  13.663 +        Uint8 *dst;
  13.664 +        int row, length;
  13.665 +        HRESULT result;
  13.666 +
  13.667 +        result =
  13.668 +            IDirect3DDevice9_CreateTexture(renderdata->device, texture->w,
  13.669 +                                           texture->h, 1, 0,
  13.670 +                                           PixelFormatToD3DFMT(texture->
  13.671 +                                                               format),
  13.672 +                                           D3DPOOL_SYSTEMMEM, &temp, NULL);
  13.673 +        if (FAILED(result)) {
  13.674 +            D3D_SetError("CreateTexture()", result);
  13.675 +            return -1;
  13.676 +        }
  13.677 +
  13.678 +        d3drect.left = rect->x;
  13.679 +        d3drect.right = rect->x + rect->w;
  13.680 +        d3drect.top = rect->y;
  13.681 +        d3drect.bottom = rect->y + rect->h;
  13.682 +
  13.683 +        result = IDirect3DTexture9_LockRect(temp, 0, &locked, &d3drect, 0);
  13.684 +        if (FAILED(result)) {
  13.685 +            IDirect3DTexture9_Release(temp);
  13.686 +            D3D_SetError("LockRect()", result);
  13.687 +            return -1;
  13.688 +        }
  13.689 +
  13.690 +        src = pixels;
  13.691 +        dst = locked.pBits;
  13.692 +        length = rect->w * SDL_BYTESPERPIXEL(texture->format);
  13.693 +        for (row = 0; row < rect->h; ++row) {
  13.694 +            SDL_memcpy(dst, src, length);
  13.695 +            src += pitch;
  13.696 +            dst += locked.Pitch;
  13.697 +        }
  13.698 +        IDirect3DTexture9_UnlockRect(temp, 0);
  13.699 +
  13.700 +        result =
  13.701 +            IDirect3DDevice9_UpdateTexture(renderdata->device,
  13.702 +                                           (IDirect3DBaseTexture9 *) temp,
  13.703 +                                           (IDirect3DBaseTexture9 *)
  13.704 +                                           data->texture);
  13.705 +        IDirect3DTexture9_Release(temp);
  13.706 +        if (FAILED(result)) {
  13.707 +            D3D_SetError("UpdateTexture()", result);
  13.708 +            return -1;
  13.709 +        }
  13.710 +#else
  13.711 +        RECT d3drect;
  13.712 +        D3DLOCKED_RECT locked;
  13.713 +        const Uint8 *src;
  13.714 +        Uint8 *dst;
  13.715 +        int row, length;
  13.716 +        HRESULT result;
  13.717 +
  13.718 +        d3drect.left = rect->x;
  13.719 +        d3drect.right = rect->x + rect->w;
  13.720 +        d3drect.top = rect->y;
  13.721 +        d3drect.bottom = rect->y + rect->h;
  13.722 +
  13.723 +        result =
  13.724 +            IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect,
  13.725 +                                       0);
  13.726 +        if (FAILED(result)) {
  13.727 +            D3D_SetError("LockRect()", result);
  13.728 +            return -1;
  13.729 +        }
  13.730 +
  13.731 +        src = pixels;
  13.732 +        dst = locked.pBits;
  13.733 +        length = rect->w * SDL_BYTESPERPIXEL(texture->format);
  13.734 +        for (row = 0; row < rect->h; ++row) {
  13.735 +            SDL_memcpy(dst, src, length);
  13.736 +            src += pitch;
  13.737 +            dst += locked.Pitch;
  13.738 +        }
  13.739 +        IDirect3DTexture9_UnlockRect(data->texture, 0);
  13.740 +#endif // SDL_MEMORY_POOL_DEFAULT
  13.741 +
  13.742 +        return 0;
  13.743 +    }
  13.744 +}
  13.745 +
  13.746 +static int
  13.747 +D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  13.748 +                const SDL_Rect * rect, int markDirty, void **pixels,
  13.749 +                int *pitch)
  13.750 +{
  13.751 +    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
  13.752 +
  13.753 +    if (data->yuv) {
  13.754 +        return SDL_SW_LockYUVTexture(data->yuv, rect, markDirty, pixels,
  13.755 +                                     pitch);
  13.756 +    } else {
  13.757 +        RECT d3drect;
  13.758 +        D3DLOCKED_RECT locked;
  13.759 +        HRESULT result;
  13.760 +
  13.761 +        d3drect.left = rect->x;
  13.762 +        d3drect.right = rect->x + rect->w;
  13.763 +        d3drect.top = rect->y;
  13.764 +        d3drect.bottom = rect->y + rect->h;
  13.765 +
  13.766 +        result =
  13.767 +            IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect,
  13.768 +                                       markDirty ? 0 :
  13.769 +                                       D3DLOCK_NO_DIRTY_UPDATE);
  13.770 +        if (FAILED(result)) {
  13.771 +            D3D_SetError("LockRect()", result);
  13.772 +            return -1;
  13.773 +        }
  13.774 +        *pixels = locked.pBits;
  13.775 +        *pitch = locked.Pitch;
  13.776 +        return 0;
  13.777 +    }
  13.778 +}
  13.779 +
  13.780 +static void
  13.781 +D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  13.782 +{
  13.783 +    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
  13.784 +
  13.785 +    if (data->yuv) {
  13.786 +        SDL_SW_UnlockYUVTexture(data->yuv);
  13.787 +        UpdateYUVTextureData(texture);
  13.788 +    } else {
  13.789 +        IDirect3DTexture9_UnlockRect(data->texture, 0);
  13.790 +    }
  13.791 +}
  13.792 +
  13.793 +static void
  13.794 +D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
  13.795 +                 const SDL_Rect * rects)
  13.796 +{
  13.797 +    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
  13.798 +    RECT d3drect;
  13.799 +    int i;
  13.800 +
  13.801 +    for (i = 0; i < numrects; ++i) {
  13.802 +        const SDL_Rect *rect = &rects[i];
  13.803 +
  13.804 +        d3drect.left = rect->x;
  13.805 +        d3drect.right = rect->x + rect->w;
  13.806 +        d3drect.top = rect->y;
  13.807 +        d3drect.bottom = rect->y + rect->h;
  13.808 +
  13.809 +        IDirect3DTexture9_AddDirtyRect(data->texture, &d3drect);
  13.810 +    }
  13.811 +}
  13.812 +
  13.813 +static void
  13.814 +D3D_SetBlendMode(D3D_RenderData * data, int blendMode)
  13.815 +{
  13.816 +    switch (blendMode) {
  13.817 +    case SDL_BLENDMODE_NONE:
  13.818 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
  13.819 +                                        FALSE);
  13.820 +        break;
  13.821 +    case SDL_BLENDMODE_BLEND:
  13.822 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
  13.823 +                                        TRUE);
  13.824 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
  13.825 +                                        D3DBLEND_SRCALPHA);
  13.826 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
  13.827 +                                        D3DBLEND_INVSRCALPHA);
  13.828 +        break;
  13.829 +    case SDL_BLENDMODE_ADD:
  13.830 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_ALPHABLENDENABLE,
  13.831 +                                        TRUE);
  13.832 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_SRCBLEND,
  13.833 +                                        D3DBLEND_SRCALPHA);
  13.834 +        IDirect3DDevice9_SetRenderState(data->device, D3DRS_DESTBLEND,
  13.835 +                                        D3DBLEND_ONE);
  13.836 +        break;
  13.837 +    }
  13.838 +}
  13.839 +
  13.840 +static int
  13.841 +D3D_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
  13.842 +                     int count)
  13.843 +{
  13.844 +    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
  13.845 +    DWORD color;
  13.846 +    Vertex *vertices;
  13.847 +    int i;
  13.848 +    HRESULT result;
  13.849 +
  13.850 +    if (data->beginScene) {
  13.851 +        IDirect3DDevice9_BeginScene(data->device);
  13.852 +        data->beginScene = SDL_FALSE;
  13.853 +    }
  13.854 +
  13.855 +    D3D_SetBlendMode(data, renderer->blendMode);
  13.856 +
  13.857 +    result =
  13.858 +        IDirect3DDevice9_SetTexture(data->device, 0,
  13.859 +                                    (IDirect3DBaseTexture9 *) 0);
  13.860 +    if (FAILED(result)) {
  13.861 +        D3D_SetError("SetTexture()", result);
  13.862 +        return -1;
  13.863 +    }
  13.864 +
  13.865 +    color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
  13.866 +
  13.867 +    vertices = SDL_stack_alloc(Vertex, count);
  13.868 +    for (i = 0; i < count; ++i) {
  13.869 +        vertices[i].x = (float) points[i].x;
  13.870 +        vertices[i].y = (float) points[i].y;
  13.871 +        vertices[i].z = 0.0f;
  13.872 +        vertices[i].rhw = 1.0f;
  13.873 +        vertices[i].color = color;
  13.874 +        vertices[i].u = 0.0f;
  13.875 +        vertices[i].v = 0.0f;
  13.876 +    }
  13.877 +    result =
  13.878 +        IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, count,
  13.879 +                                         vertices, sizeof(*vertices));
  13.880 +    SDL_stack_free(vertices);
  13.881 +    if (FAILED(result)) {
  13.882 +        D3D_SetError("DrawPrimitiveUP()", result);
  13.883 +        return -1;
  13.884 +    }
  13.885 +    return 0;
  13.886 +}
  13.887 +
  13.888 +static int
  13.889 +D3D_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
  13.890 +                    int count)
  13.891 +{
  13.892 +    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
  13.893 +    DWORD color;
  13.894 +    Vertex *vertices;
  13.895 +    int i;
  13.896 +    HRESULT result;
  13.897 +
  13.898 +    if (data->beginScene) {
  13.899 +        IDirect3DDevice9_BeginScene(data->device);
  13.900 +        data->beginScene = SDL_FALSE;
  13.901 +    }
  13.902 +
  13.903 +    D3D_SetBlendMode(data, renderer->blendMode);
  13.904 +
  13.905 +    result =
  13.906 +        IDirect3DDevice9_SetTexture(data->device, 0,
  13.907 +                                    (IDirect3DBaseTexture9 *) 0);
  13.908 +    if (FAILED(result)) {
  13.909 +        D3D_SetError("SetTexture()", result);
  13.910 +        return -1;
  13.911 +    }
  13.912 +
  13.913 +    color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
  13.914 +
  13.915 +    vertices = SDL_stack_alloc(Vertex, count);
  13.916 +    for (i = 0; i < count; ++i) {
  13.917 +        vertices[i].x = (float) points[i].x;
  13.918 +        vertices[i].y = (float) points[i].y;
  13.919 +        vertices[i].z = 0.0f;
  13.920 +        vertices[i].rhw = 1.0f;
  13.921 +        vertices[i].color = color;
  13.922 +        vertices[i].u = 0.0f;
  13.923 +        vertices[i].v = 0.0f;
  13.924 +    }
  13.925 +    result =
  13.926 +        IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, count-1,
  13.927 +                                         vertices, sizeof(*vertices));
  13.928 +
  13.929 +    /* DirectX 9 has the same line rasterization semantics as GDI,
  13.930 +       so we need to close the endpoint of the line */
  13.931 +    if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
  13.932 +        vertices[0].x = (float) points[count-1].x;
  13.933 +        vertices[0].y = (float) points[count-1].y;
  13.934 +        result = IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, 1, vertices, sizeof(*vertices));
  13.935 +    }
  13.936 +
  13.937 +    SDL_stack_free(vertices);
  13.938 +    if (FAILED(result)) {
  13.939 +        D3D_SetError("DrawPrimitiveUP()", result);
  13.940 +        return -1;
  13.941 +    }
  13.942 +    return 0;
  13.943 +}
  13.944 +
  13.945 +static int
  13.946 +D3D_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
  13.947 +                    int count)
  13.948 +{
  13.949 +    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
  13.950 +    DWORD color;
  13.951 +    int i;
  13.952 +    float minx, miny, maxx, maxy;
  13.953 +    Vertex vertices[4];
  13.954 +    HRESULT result;
  13.955 +
  13.956 +    if (data->beginScene) {
  13.957 +        IDirect3DDevice9_BeginScene(data->device);
  13.958 +        data->beginScene = SDL_FALSE;
  13.959 +    }
  13.960 +
  13.961 +    D3D_SetBlendMode(data, renderer->blendMode);
  13.962 +
  13.963 +    result =
  13.964 +        IDirect3DDevice9_SetTexture(data->device, 0,
  13.965 +                                    (IDirect3DBaseTexture9 *) 0);
  13.966 +    if (FAILED(result)) {
  13.967 +        D3D_SetError("SetTexture()", result);
  13.968 +        return -1;
  13.969 +    }
  13.970 +
  13.971 +    color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
  13.972 +
  13.973 +    for (i = 0; i < count; ++i) {
  13.974 +        const SDL_Rect *rect = rects[i];
  13.975 +
  13.976 +        minx = (float) rect->x;
  13.977 +        miny = (float) rect->y;
  13.978 +        maxx = (float) rect->x + rect->w;
  13.979 +        maxy = (float) rect->y + rect->h;
  13.980 +
  13.981 +        vertices[0].x = minx;
  13.982 +        vertices[0].y = miny;
  13.983 +        vertices[0].z = 0.0f;
  13.984 +        vertices[0].rhw = 1.0f;
  13.985 +        vertices[0].color = color;
  13.986 +        vertices[0].u = 0.0f;
  13.987 +        vertices[0].v = 0.0f;
  13.988 +
  13.989 +        vertices[1].x = maxx;
  13.990 +        vertices[1].y = miny;
  13.991 +        vertices[1].z = 0.0f;
  13.992 +        vertices[1].rhw = 1.0f;
  13.993 +        vertices[1].color = color;
  13.994 +        vertices[1].u = 0.0f;
  13.995 +        vertices[1].v = 0.0f;
  13.996 +
  13.997 +        vertices[2].x = maxx;
  13.998 +        vertices[2].y = maxy;
  13.999 +        vertices[2].z = 0.0f;
 13.1000 +        vertices[2].rhw = 1.0f;
 13.1001 +        vertices[2].color = color;
 13.1002 +        vertices[2].u = 0.0f;
 13.1003 +        vertices[2].v = 0.0f;
 13.1004 +
 13.1005 +        vertices[3].x = minx;
 13.1006 +        vertices[3].y = maxy;
 13.1007 +        vertices[3].z = 0.0f;
 13.1008 +        vertices[3].rhw = 1.0f;
 13.1009 +        vertices[3].color = color;
 13.1010 +        vertices[3].u = 0.0f;
 13.1011 +        vertices[3].v = 0.0f;
 13.1012 +
 13.1013 +        result =
 13.1014 +            IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN,
 13.1015 +                                             2, vertices, sizeof(*vertices));
 13.1016 +        if (FAILED(result)) {
 13.1017 +            D3D_SetError("DrawPrimitiveUP()", result);
 13.1018 +            return -1;
 13.1019 +        }
 13.1020 +    }
 13.1021 +    return 0;
 13.1022 +}
 13.1023 +
 13.1024 +static int
 13.1025 +D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
 13.1026 +               const SDL_Rect * srcrect, const SDL_Rect * dstrect)
 13.1027 +{
 13.1028 +    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
 13.1029 +    D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
 13.1030 +    LPDIRECT3DPIXELSHADER9 shader = NULL;
 13.1031 +    float minx, miny, maxx, maxy;
 13.1032 +    float minu, maxu, minv, maxv;
 13.1033 +    DWORD color;
 13.1034 +    Vertex vertices[4];
 13.1035 +    HRESULT result;
 13.1036 +
 13.1037 +    if (data->beginScene) {
 13.1038 +        IDirect3DDevice9_BeginScene(data->device);
 13.1039 +        data->beginScene = SDL_FALSE;
 13.1040 +    }
 13.1041 +
 13.1042 +    minx = (float) dstrect->x - 0.5f;
 13.1043 +    miny = (float) dstrect->y - 0.5f;
 13.1044 +    maxx = (float) dstrect->x + dstrect->w - 0.5f;
 13.1045 +    maxy = (float) dstrect->y + dstrect->h - 0.5f;
 13.1046 +
 13.1047 +    minu = (float) srcrect->x / texture->w;
 13.1048 +    maxu = (float) (srcrect->x + srcrect->w) / texture->w;
 13.1049 +    minv = (float) srcrect->y / texture->h;
 13.1050 +    maxv = (float) (srcrect->y + srcrect->h) / texture->h;
 13.1051 +
 13.1052 +    color = D3DCOLOR_ARGB(texture->a, texture->r, texture->g, texture->b);
 13.1053 +
 13.1054 +    vertices[0].x = minx;
 13.1055 +    vertices[0].y = miny;
 13.1056 +    vertices[0].z = 0.0f;
 13.1057 +    vertices[0].rhw = 1.0f;
 13.1058 +    vertices[0].color = color;
 13.1059 +    vertices[0].u = minu;
 13.1060 +    vertices[0].v = minv;
 13.1061 +
 13.1062 +    vertices[1].x = maxx;
 13.1063 +    vertices[1].y = miny;
 13.1064 +    vertices[1].z = 0.0f;
 13.1065 +    vertices[1].rhw = 1.0f;
 13.1066 +    vertices[1].color = color;
 13.1067 +    vertices[1].u = maxu;
 13.1068 +    vertices[1].v = minv;
 13.1069 +
 13.1070 +    vertices[2].x = maxx;
 13.1071 +    vertices[2].y = maxy;
 13.1072 +    vertices[2].z = 0.0f;
 13.1073 +    vertices[2].rhw = 1.0f;
 13.1074 +    vertices[2].color = color;
 13.1075 +    vertices[2].u = maxu;
 13.1076 +    vertices[2].v = maxv;
 13.1077 +
 13.1078 +    vertices[3].x = minx;
 13.1079 +    vertices[3].y = maxy;
 13.1080 +    vertices[3].z = 0.0f;
 13.1081 +    vertices[3].rhw = 1.0f;
 13.1082 +    vertices[3].color = color;
 13.1083 +    vertices[3].u = minu;
 13.1084 +    vertices[3].v = maxv;
 13.1085 +
 13.1086 +    D3D_SetBlendMode(data, texture->blendMode);
 13.1087 +
 13.1088 +    IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MINFILTER,
 13.1089 +                                     D3DTEXF_LINEAR);
 13.1090 +    IDirect3DDevice9_SetSamplerState(data->device, 0, D3DSAMP_MAGFILTER,
 13.1091 +                                     D3DTEXF_LINEAR);
 13.1092 +
 13.1093 +    result =
 13.1094 +        IDirect3DDevice9_SetTexture(data->device, 0, (IDirect3DBaseTexture9 *)
 13.1095 +                                    texturedata->texture);
 13.1096 +    if (FAILED(result)) {
 13.1097 +        D3D_SetError("SetTexture()", result);
 13.1098 +        return -1;
 13.1099 +    }
 13.1100 +    if (shader) {
 13.1101 +        result = IDirect3DDevice9_SetPixelShader(data->device, shader);
 13.1102 +        if (FAILED(result)) {
 13.1103 +            D3D_SetError("SetShader()", result);
 13.1104 +            return -1;
 13.1105 +        }
 13.1106 +    }
 13.1107 +    result =
 13.1108 +        IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2,
 13.1109 +                                         vertices, sizeof(*vertices));
 13.1110 +    if (FAILED(result)) {
 13.1111 +        D3D_SetError("DrawPrimitiveUP()", result);
 13.1112 +        return -1;
 13.1113 +    }
 13.1114 +    if (shader) {
 13.1115 +        result = IDirect3DDevice9_SetPixelShader(data->device, NULL);
 13.1116 +        if (FAILED(result)) {
 13.1117 +            D3D_SetError("SetShader()", result);
 13.1118 +            return -1;
 13.1119 +        }
 13.1120 +    }
 13.1121 +    return 0;
 13.1122 +}
 13.1123 +
 13.1124 +static int
 13.1125 +D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
 13.1126 +                     Uint32 format, void * pixels, int pitch)
 13.1127 +{
 13.1128 +    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
 13.1129 +    SDL_Window *window = renderer->window;
 13.1130 +    SDL_VideoDisplay *display = window->display;
 13.1131 +    D3DSURFACE_DESC desc;
 13.1132 +    LPDIRECT3DSURFACE9 backBuffer;
 13.1133 +    LPDIRECT3DSURFACE9 surface;
 13.1134 +    RECT d3drect;
 13.1135 +    D3DLOCKED_RECT locked;
 13.1136 +    HRESULT result;
 13.1137 +
 13.1138 +    result = IDirect3DDevice9_GetBackBuffer(data->device, 0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer);
 13.1139 +    if (FAILED(result)) {
 13.1140 +        D3D_SetError("GetBackBuffer()", result);
 13.1141 +        return -1;
 13.1142 +    }
 13.1143 +
 13.1144 +    result = IDirect3DSurface9_GetDesc(backBuffer, &desc);
 13.1145 +    if (FAILED(result)) {
 13.1146 +        D3D_SetError("GetDesc()", result);
 13.1147 +        IDirect3DSurface9_Release(backBuffer);
 13.1148 +        return -1;
 13.1149 +    }
 13.1150 +
 13.1151 +    result = IDirect3DDevice9_CreateOffscreenPlainSurface(data->device, desc.Width, desc.Height, desc.Format, D3DPOOL_SYSTEMMEM, &surface, NULL);
 13.1152 +    if (FAILED(result)) {
 13.1153 +        D3D_SetError("CreateOffscreenPlainSurface()", result);
 13.1154 +        IDirect3DSurface9_Release(backBuffer);
 13.1155 +        return -1;
 13.1156 +    }
 13.1157 +
 13.1158 +    result = IDirect3DDevice9_GetRenderTargetData(data->device, backBuffer, surface);
 13.1159 +    if (FAILED(result)) {
 13.1160 +        D3D_SetError("GetRenderTargetData()", result);
 13.1161 +        IDirect3DSurface9_Release(surface);
 13.1162 +        IDirect3DSurface9_Release(backBuffer);
 13.1163 +        return -1;
 13.1164 +    }
 13.1165 +
 13.1166 +    d3drect.left = rect->x;
 13.1167 +    d3drect.right = rect->x + rect->w;
 13.1168 +    d3drect.top = rect->y;
 13.1169 +    d3drect.bottom = rect->y + rect->h;
 13.1170 +
 13.1171 +    result = IDirect3DSurface9_LockRect(surface, &locked, &d3drect, D3DLOCK_READONLY);
 13.1172 +    if (FAILED(result)) {
 13.1173 +        D3D_SetError("LockRect()", result);
 13.1174 +        IDirect3DSurface9_Release(surface);
 13.1175 +        IDirect3DSurface9_Release(backBuffer);
 13.1176 +        return -1;
 13.1177 +    }
 13.1178 +
 13.1179 +    SDL_ConvertPixels(rect->w, rect->h,
 13.1180 +                      display->current_mode.format, locked.pBits, locked.Pitch,
 13.1181 +                      format, pixels, pitch);
 13.1182 +
 13.1183 +    IDirect3DSurface9_UnlockRect(surface);
 13.1184 +
 13.1185 +    IDirect3DSurface9_Release(surface);
 13.1186 +    IDirect3DSurface9_Release(backBuffer);
 13.1187 +
 13.1188 +    return 0;
 13.1189 +}
 13.1190 +
 13.1191 +static int
 13.1192 +D3D_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
 13.1193 +                      Uint32 format, const void * pixels, int pitch)
 13.1194 +{
 13.1195 +    /* Work in progress */
 13.1196 +    SDL_Unsupported();
 13.1197 +    return -1;
 13.1198 +}
 13.1199 +
 13.1200 +static void
 13.1201 +D3D_RenderPresent(SDL_Renderer * renderer)
 13.1202 +{
 13.1203 +    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
 13.1204 +    HRESULT result;
 13.1205 +
 13.1206 +    if (!data->beginScene) {
 13.1207 +        IDirect3DDevice9_EndScene(data->device);
 13.1208 +        data->beginScene = SDL_TRUE;
 13.1209 +    }
 13.1210 +
 13.1211 +    result = IDirect3DDevice9_TestCooperativeLevel(data->device);
 13.1212 +    if (result == D3DERR_DEVICELOST) {
 13.1213 +        /* We'll reset later */
 13.1214 +        return;
 13.1215 +    }
 13.1216 +    if (result == D3DERR_DEVICENOTRESET) {
 13.1217 +        D3D_Reset(renderer);
 13.1218 +    }
 13.1219 +    result = IDirect3DDevice9_Present(data->device, NULL, NULL, NULL, NULL);
 13.1220 +    if (FAILED(result)) {
 13.1221 +        D3D_SetError("Present()", result);
 13.1222 +    }
 13.1223 +}
 13.1224 +
 13.1225 +static void
 13.1226 +D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
 13.1227 +{
 13.1228 +    D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
 13.1229 +
 13.1230 +    if (!data) {
 13.1231 +        return;
 13.1232 +    }
 13.1233 +    if (data->yuv) {
 13.1234 +        SDL_SW_DestroyYUVTexture(data->yuv);
 13.1235 +    }
 13.1236 +    if (data->texture) {
 13.1237 +        IDirect3DTexture9_Release(data->texture);
 13.1238 +    }
 13.1239 +    SDL_free(data);
 13.1240 +    texture->driverdata = NULL;
 13.1241 +}
 13.1242 +
 13.1243 +static void
 13.1244 +D3D_DestroyRenderer(SDL_Renderer * renderer)
 13.1245 +{
 13.1246 +    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
 13.1247 +
 13.1248 +    if (data) {
 13.1249 +        if (data->device) {
 13.1250 +            IDirect3DDevice9_Release(data->device);
 13.1251 +        }
 13.1252 +        if (data->d3d) {
 13.1253 +            IDirect3D9_Release(data->d3d);
 13.1254 +            SDL_UnloadObject(data->d3dDLL);
 13.1255 +        }
 13.1256 +        SDL_free(data);
 13.1257 +    }
 13.1258 +    SDL_free(renderer);
 13.1259 +}
 13.1260 +
 13.1261 +#endif /* SDL_VIDEO_RENDER_D3D */
 13.1262 +
 13.1263 +/* vi: set ts=4 sw=4 expandtab: */
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/src/render/opengl/SDL_renderer_gl.c	Wed Feb 02 14:34:54 2011 -0800
    14.3 @@ -0,0 +1,1285 @@
    14.4 +/*
    14.5 +    SDL - Simple DirectMedia Layer
    14.6 +    Copyright (C) 1997-2010 Sam Lantinga
    14.7 +
    14.8 +    This library is free software; you can redistribute it and/or
    14.9 +    modify it under the terms of the GNU Lesser General Public
   14.10 +    License as published by the Free Software Foundation; either
   14.11 +    version 2.1 of the License, or (at your option) any later version.
   14.12 +
   14.13 +    This library is distributed in the hope that it will be useful,
   14.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   14.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   14.16 +    Lesser General Public License for more details.
   14.17 +
   14.18 +    You should have received a copy of the GNU Lesser General Public
   14.19 +    License along with this library; if not, write to the Free Software
   14.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   14.21 +
   14.22 +    Sam Lantinga
   14.23 +    slouken@libsdl.org
   14.24 +*/
   14.25 +#include "SDL_config.h"
   14.26 +
   14.27 +#if SDL_VIDEO_RENDER_OGL
   14.28 +
   14.29 +#include "SDL_opengl.h"
   14.30 +#include "../SDL_sysrender.h"
   14.31 +
   14.32 +#ifdef __MACOSX__
   14.33 +#include <OpenGL/OpenGL.h>
   14.34 +#endif
   14.35 +
   14.36 +
   14.37 +/* OpenGL renderer implementation */
   14.38 +
   14.39 +/* Details on optimizing the texture path on Mac OS X:
   14.40 +   http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/chapter_10_section_2.html
   14.41 +*/
   14.42 +
   14.43 +/* !!! FIXME: this should go in a higher level than the GL renderer. */
   14.44 +static __inline__ int
   14.45 +bytes_per_pixel(const Uint32 format)
   14.46 +{
   14.47 +    if (!SDL_ISPIXELFORMAT_FOURCC(format)) {
   14.48 +        return SDL_BYTESPERPIXEL(format);
   14.49 +    }
   14.50 +
   14.51 +    /* FOURCC format */
   14.52 +    switch (format) {
   14.53 +    case SDL_PIXELFORMAT_YV12:
   14.54 +    case SDL_PIXELFORMAT_IYUV:
   14.55 +    case SDL_PIXELFORMAT_YUY2:
   14.56 +    case SDL_PIXELFORMAT_UYVY:
   14.57 +    case SDL_PIXELFORMAT_YVYU:
   14.58 +        return 2;
   14.59 +    default:
   14.60 +        return 1;               /* shouldn't ever hit this. */
   14.61 +    }
   14.62 +}
   14.63 +
   14.64 +/* Used to re-create the window with OpenGL capability */
   14.65 +extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   14.66 +
   14.67 +static const float inv255f = 1.0f / 255.0f;
   14.68 +
   14.69 +static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags);
   14.70 +static void GL_WindowEvent(SDL_Renderer * renderer,
   14.71 +                           const SDL_WindowEvent *event);
   14.72 +static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
   14.73 +static int GL_QueryTexturePixels(SDL_Renderer * renderer,
   14.74 +                                 SDL_Texture * texture, void **pixels,
   14.75 +                                 int *pitch);
   14.76 +static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   14.77 +                            const SDL_Rect * rect, const void *pixels,
   14.78 +                            int pitch);
   14.79 +static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   14.80 +                          const SDL_Rect * rect, int markDirty, void **pixels,
   14.81 +                          int *pitch);
   14.82 +static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
   14.83 +static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   14.84 +                            int numrects, const SDL_Rect * rects);
   14.85 +static int GL_RenderClear(SDL_Renderer * renderer);
   14.86 +static int GL_RenderDrawPoints(SDL_Renderer * renderer,
   14.87 +                               const SDL_Point * points, int count);
   14.88 +static int GL_RenderDrawLines(SDL_Renderer * renderer,
   14.89 +                              const SDL_Point * points, int count);
   14.90 +static int GL_RenderFillRects(SDL_Renderer * renderer,
   14.91 +                              const SDL_Rect ** rects, int count);
   14.92 +static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   14.93 +                         const SDL_Rect * srcrect, const SDL_Rect * dstrect);
   14.94 +static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   14.95 +                               Uint32 pixel_format, void * pixels, int pitch);
   14.96 +static int GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   14.97 +                                Uint32 pixel_format, const void * pixels, int pitch);
   14.98 +static void GL_RenderPresent(SDL_Renderer * renderer);
   14.99 +static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
  14.100 +static void GL_DestroyRenderer(SDL_Renderer * renderer);
  14.101 +
  14.102 +
  14.103 +SDL_RenderDriver GL_RenderDriver = {
  14.104 +    GL_CreateRenderer,
  14.105 +    {
  14.106 +     "opengl",
  14.107 +     (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
  14.108 +     13,
  14.109 +     {
  14.110 +      SDL_PIXELFORMAT_RGB332,
  14.111 +      SDL_PIXELFORMAT_RGB444,
  14.112 +      SDL_PIXELFORMAT_RGB555,
  14.113 +      SDL_PIXELFORMAT_ARGB4444,
  14.114 +      SDL_PIXELFORMAT_ARGB1555,
  14.115 +      SDL_PIXELFORMAT_RGB565,
  14.116 +      SDL_PIXELFORMAT_RGB24,
  14.117 +      SDL_PIXELFORMAT_BGR24,
  14.118 +      SDL_PIXELFORMAT_RGB888,
  14.119 +      SDL_PIXELFORMAT_BGR888,
  14.120 +      SDL_PIXELFORMAT_ARGB8888,
  14.121 +      SDL_PIXELFORMAT_ABGR8888,
  14.122 +      SDL_PIXELFORMAT_ARGB2101010},
  14.123 +     0,
  14.124 +     0}
  14.125 +};
  14.126 +
  14.127 +typedef struct
  14.128 +{
  14.129 +    SDL_GLContext context;
  14.130 +    SDL_bool updateSize;
  14.131 +    SDL_bool GL_ARB_texture_rectangle_supported;
  14.132 +    SDL_bool GL_EXT_paletted_texture_supported;
  14.133 +    SDL_bool GL_APPLE_ycbcr_422_supported;
  14.134 +    SDL_bool GL_MESA_ycbcr_texture_supported;
  14.135 +    SDL_bool GL_ARB_fragment_program_supported;
  14.136 +    int blendMode;
  14.137 +
  14.138 +    /* OpenGL functions */
  14.139 +#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
  14.140 +#include "../../video/SDL_glfuncs.h"
  14.141 +#undef SDL_PROC
  14.142 +
  14.143 +    void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
  14.144 +                                 const GLvoid * pointer);
  14.145 +
  14.146 +    PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
  14.147 +    PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB;
  14.148 +    PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB;
  14.149 +    PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB;
  14.150 +    PFNGLGENPROGRAMSARBPROC glGenProgramsARB;
  14.151 +    PFNGLBINDPROGRAMARBPROC glBindProgramARB;
  14.152 +    PFNGLPROGRAMSTRINGARBPROC glProgramStringARB;
  14.153 +
  14.154 +    /* (optional) fragment programs */
  14.155 +    GLuint fragment_program_UYVY;
  14.156 +} GL_RenderData;
  14.157 +
  14.158 +typedef struct
  14.159 +{
  14.160 +    GLuint texture;
  14.161 +    GLuint shader;
  14.162 +    GLenum type;
  14.163 +    GLfloat texw;
  14.164 +    GLfloat texh;
  14.165 +    GLenum format;
  14.166 +    GLenum formattype;
  14.167 +    Uint8 *palette;
  14.168 +    void *pixels;
  14.169 +    int pitch;
  14.170 +    SDL_DirtyRectList dirty;
  14.171 +    int HACK_RYAN_FIXME;
  14.172 +} GL_TextureData;
  14.173 +
  14.174 +
  14.175 +static void
  14.176 +GL_SetError(const char *prefix, GLenum result)
  14.177 +{
  14.178 +    const char *error;
  14.179 +
  14.180 +    switch (result) {
  14.181 +    case GL_NO_ERROR:
  14.182 +        error = "GL_NO_ERROR";
  14.183 +        break;
  14.184 +    case GL_INVALID_ENUM:
  14.185 +        error = "GL_INVALID_ENUM";
  14.186 +        break;
  14.187 +    case GL_INVALID_VALUE:
  14.188 +        error = "GL_INVALID_VALUE";
  14.189 +        break;
  14.190 +    case GL_INVALID_OPERATION:
  14.191 +        error = "GL_INVALID_OPERATION";
  14.192 +        break;
  14.193 +    case GL_STACK_OVERFLOW:
  14.194 +        error = "GL_STACK_OVERFLOW";
  14.195 +        break;
  14.196 +    case GL_STACK_UNDERFLOW:
  14.197 +        error = "GL_STACK_UNDERFLOW";
  14.198 +        break;
  14.199 +    case GL_OUT_OF_MEMORY:
  14.200 +        error = "GL_OUT_OF_MEMORY";
  14.201 +        break;
  14.202 +    case GL_TABLE_TOO_LARGE:
  14.203 +        error = "GL_TABLE_TOO_LARGE";
  14.204 +        break;
  14.205 +    default:
  14.206 +        error = "UNKNOWN";
  14.207 +        break;
  14.208 +    }
  14.209 +    SDL_SetError("%s: %s", prefix, error);
  14.210 +}
  14.211 +
  14.212 +static int
  14.213 +GL_LoadFunctions(GL_RenderData * data)
  14.214 +{
  14.215 +#ifdef __SDL_NOGETPROCADDR__
  14.216 +#define SDL_PROC(ret,func,params) data->func=func;
  14.217 +#else
  14.218 +#define SDL_PROC(ret,func,params) \
  14.219 +    do { \
  14.220 +        data->func = SDL_GL_GetProcAddress(#func); \
  14.221 +        if ( ! data->func ) { \
  14.222 +            SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
  14.223 +            return -1; \
  14.224 +        } \
  14.225 +    } while ( 0 );
  14.226 +#endif /* __SDL_NOGETPROCADDR__ */
  14.227 +
  14.228 +#include "../../video/SDL_glfuncs.h"
  14.229 +#undef SDL_PROC
  14.230 +    return 0;
  14.231 +}
  14.232 +
  14.233 +SDL_Renderer *
  14.234 +GL_CreateRenderer(SDL_Window * window, Uint32 flags)
  14.235 +{
  14.236 +    SDL_Renderer *renderer;
  14.237 +    GL_RenderData *data;
  14.238 +    GLint value;
  14.239 +    Uint32 window_flags;
  14.240 +
  14.241 +    window_flags = SDL_GetWindowFlags(window);
  14.242 +    if (!(window_flags & SDL_WINDOW_OPENGL)) {
  14.243 +        if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
  14.244 +            return NULL;
  14.245 +        }
  14.246 +    }
  14.247 +
  14.248 +    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
  14.249 +    if (!renderer) {
  14.250 +        SDL_OutOfMemory();
  14.251 +        return NULL;
  14.252 +    }
  14.253 +
  14.254 +    data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
  14.255 +    if (!data) {
  14.256 +        GL_DestroyRenderer(renderer);
  14.257 +        SDL_OutOfMemory();
  14.258 +        return NULL;
  14.259 +    }
  14.260 +
  14.261 +    renderer->WindowEvent = GL_WindowEvent;
  14.262 +    renderer->CreateTexture = GL_CreateTexture;
  14.263 +    renderer->QueryTexturePixels = GL_QueryTexturePixels;
  14.264 +    renderer->UpdateTexture = GL_UpdateTexture;
  14.265 +    renderer->LockTexture = GL_LockTexture;
  14.266 +    renderer->UnlockTexture = GL_UnlockTexture;
  14.267 +    renderer->DirtyTexture = GL_DirtyTexture;
  14.268 +    renderer->RenderClear = GL_RenderClear;
  14.269 +    renderer->RenderDrawPoints = GL_RenderDrawPoints;
  14.270 +    renderer->RenderDrawLines = GL_RenderDrawLines;
  14.271 +    renderer->RenderFillRects = GL_RenderFillRects;
  14.272 +    renderer->RenderCopy = GL_RenderCopy;
  14.273 +    renderer->RenderReadPixels = GL_RenderReadPixels;
  14.274 +    renderer->RenderWritePixels = GL_RenderWritePixels;
  14.275 +    renderer->RenderPresent = GL_RenderPresent;
  14.276 +    renderer->DestroyTexture = GL_DestroyTexture;
  14.277 +    renderer->DestroyRenderer = GL_DestroyRenderer;
  14.278 +    renderer->info = GL_RenderDriver.info;
  14.279 +    renderer->window = window;
  14.280 +    renderer->driverdata = data;
  14.281 +
  14.282 +    renderer->info.flags = SDL_RENDERER_ACCELERATED;
  14.283 +
  14.284 +    if (GL_LoadFunctions(data) < 0) {
  14.285 +        GL_DestroyRenderer(renderer);
  14.286 +        return NULL;
  14.287 +    }
  14.288 +
  14.289 +    data->context = SDL_GL_CreateContext(window);
  14.290 +    if (!data->context) {
  14.291 +        GL_DestroyRenderer(renderer);
  14.292 +        return NULL;
  14.293 +    }
  14.294 +    if (SDL_GL_MakeCurrent(window, data->context) < 0) {
  14.295 +        GL_DestroyRenderer(renderer);
  14.296 +        return NULL;
  14.297 +    }
  14.298 +#ifdef __MACOSX__
  14.299 +    /* Enable multi-threaded rendering */
  14.300 +    /* Disabled until Ryan finishes his VBO/PBO code...
  14.301 +       CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine);
  14.302 +     */
  14.303 +#endif
  14.304 +
  14.305 +    if (flags & SDL_RENDERER_PRESENTVSYNC) {
  14.306 +        SDL_GL_SetSwapInterval(1);
  14.307 +    } else {
  14.308 +        SDL_GL_SetSwapInterval(0);
  14.309 +    }
  14.310 +    if (SDL_GL_GetSwapInterval() > 0) {
  14.311 +        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
  14.312 +    }
  14.313 +
  14.314 +    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
  14.315 +    renderer->info.max_texture_width = value;
  14.316 +    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
  14.317 +    renderer->info.max_texture_height = value;
  14.318 +
  14.319 +    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
  14.320 +        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
  14.321 +        data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
  14.322 +    }
  14.323 +    if (SDL_GL_ExtensionSupported("GL_APPLE_ycbcr_422")) {
  14.324 +        data->GL_APPLE_ycbcr_422_supported = SDL_TRUE;
  14.325 +    }
  14.326 +    if (SDL_GL_ExtensionSupported("GL_MESA_ycbcr_texture")) {
  14.327 +        data->GL_MESA_ycbcr_texture_supported = SDL_TRUE;
  14.328 +    }
  14.329 +    if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
  14.330 +        data->glTextureRangeAPPLE =
  14.331 +            (void (*)(GLenum, GLsizei, const GLvoid *))
  14.332 +            SDL_GL_GetProcAddress("glTextureRangeAPPLE");
  14.333 +    }
  14.334 +
  14.335 +    /* we might use fragment programs for YUV data, etc. */
  14.336 +    if (SDL_GL_ExtensionSupported("GL_ARB_fragment_program")) {
  14.337 +        /* !!! FIXME: this doesn't check for errors. */
  14.338 +        /* !!! FIXME: this should really reuse the glfuncs.h stuff. */
  14.339 +        data->glGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC)
  14.340 +            SDL_GL_GetProcAddress("glGetProgramivARB");
  14.341 +        data->glGetProgramStringARB = (PFNGLGETPROGRAMSTRINGARBPROC)
  14.342 +            SDL_GL_GetProcAddress("glGetProgramStringARB");
  14.343 +        data->glProgramLocalParameter4fvARB =
  14.344 +            (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC)
  14.345 +            SDL_GL_GetProcAddress("glProgramLocalParameter4fvARB");
  14.346 +        data->glDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC)
  14.347 +            SDL_GL_GetProcAddress("glDeleteProgramsARB");
  14.348 +        data->glGenProgramsARB = (PFNGLGENPROGRAMSARBPROC)
  14.349 +            SDL_GL_GetProcAddress("glGenProgramsARB");
  14.350 +        data->glBindProgramARB = (PFNGLBINDPROGRAMARBPROC)
  14.351 +            SDL_GL_GetProcAddress("glBindProgramARB");
  14.352 +        data->glProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC)
  14.353 +            SDL_GL_GetProcAddress("glProgramStringARB");
  14.354 +        data->GL_ARB_fragment_program_supported = SDL_TRUE;
  14.355 +    }
  14.356 +
  14.357 +    /* Set up parameters for rendering */
  14.358 +    data->blendMode = -1;
  14.359 +    data->glDisable(GL_DEPTH_TEST);
  14.360 +    data->glDisable(GL_CULL_FACE);
  14.361 +    /* This ended up causing video discrepancies between OpenGL and Direct3D */
  14.362 +    /*data->glEnable(GL_LINE_SMOOTH);*/
  14.363 +    if (data->GL_ARB_texture_rectangle_supported) {
  14.364 +        data->glEnable(GL_TEXTURE_RECTANGLE_ARB);
  14.365 +    } else {
  14.366 +        data->glEnable(GL_TEXTURE_2D);
  14.367 +    }
  14.368 +    data->updateSize = SDL_TRUE;
  14.369 +
  14.370 +    return renderer;
  14.371 +}
  14.372 +
  14.373 +static SDL_GLContext SDL_CurrentContext = NULL;
  14.374 +
  14.375 +static int
  14.376 +GL_ActivateRenderer(SDL_Renderer * renderer)
  14.377 +{
  14.378 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
  14.379 +    SDL_Window *window = renderer->window;
  14.380 +
  14.381 +    if (SDL_CurrentContext != data->context) {
  14.382 +        if (SDL_GL_MakeCurrent(window, data->context) < 0) {
  14.383 +            return -1;
  14.384 +        }
  14.385 +        SDL_CurrentContext = data->context;
  14.386 +    }
  14.387 +    if (data->updateSize) {
  14.388 +        int w, h;
  14.389 +
  14.390 +        SDL_GetWindowSize(window, &w, &h);
  14.391 +        data->glMatrixMode(GL_PROJECTION);
  14.392 +        data->glLoadIdentity();
  14.393 +        data->glMatrixMode(GL_MODELVIEW);
  14.394 +        data->glLoadIdentity();
  14.395 +        data->glViewport(0, 0, w, h);
  14.396 +        data->glOrtho(0.0, (GLdouble) w, (GLdouble) h, 0.0, 0.0, 1.0);
  14.397 +        data->updateSize = SDL_FALSE;
  14.398 +    }
  14.399 +    return 0;
  14.400 +}
  14.401 +
  14.402 +static void
  14.403 +GL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
  14.404 +{
  14.405 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
  14.406 +
  14.407 +    if (event->event == SDL_WINDOWEVENT_RESIZED) {
  14.408 +        /* Rebind the context to the window area and update matrices */
  14.409 +        SDL_CurrentContext = NULL;
  14.410 +        data->updateSize = SDL_TRUE;
  14.411 +    }
  14.412 +}
  14.413 +
  14.414 +static __inline__ int
  14.415 +power_of_2(int input)
  14.416 +{
  14.417 +    int value = 1;
  14.418 +
  14.419 +    while (value < input) {
  14.420 +        value <<= 1;
  14.421 +    }
  14.422 +    return value;
  14.423 +}
  14.424 +
  14.425 +
  14.426 +//#define DEBUG_PROGRAM_COMPILE 1
  14.427 +
  14.428 +static void
  14.429 +set_shader_error(GL_RenderData * data, const char *prefix)
  14.430 +{
  14.431 +    GLint pos = 0;
  14.432 +    const GLubyte *errstr;
  14.433 +    data->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
  14.434 +    errstr = data->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
  14.435 +    SDL_SetError("%s: shader compile error at position %d: %s",
  14.436 +           prefix, (int) pos, (const char *) errstr);
  14.437 +}
  14.438 +
  14.439 +static GLuint
  14.440 +compile_shader(GL_RenderData * data, GLenum shader_type, const char *_code)
  14.441 +{
  14.442 +    const int have_texture_rects = data->GL_ARB_texture_rectangle_supported;
  14.443 +    const char *replacement = have_texture_rects ? "RECT" : "2D";
  14.444 +    const size_t replacementlen = SDL_strlen(replacement);
  14.445 +    const char *token = "%TEXTURETARGET%";
  14.446 +    const size_t tokenlen = SDL_strlen(token);
  14.447 +    char *code = NULL;
  14.448 +    char *ptr = NULL;
  14.449 +    GLuint program = 0;
  14.450 +
  14.451 +    /*
  14.452 +     * The TEX instruction needs a different target depending on what we use.
  14.453 +     *  To handle this, we use "%TEXTURETARGET%" and replace the string before
  14.454 +     *  compiling the shader.
  14.455 +     */
  14.456 +    code = SDL_strdup(_code);
  14.457 +    if (code == NULL)
  14.458 +        return 0;
  14.459 +
  14.460 +    for (ptr = SDL_strstr(code, token); ptr; ptr = SDL_strstr(ptr + 1, token)) {
  14.461 +        SDL_memcpy(ptr, replacement, replacementlen);
  14.462 +        SDL_memmove(ptr + replacementlen, ptr + tokenlen,
  14.463 +                    SDL_strlen(ptr + tokenlen) + 1);
  14.464 +    }
  14.465 +
  14.466 +#if DEBUG_PROGRAM_COMPILE
  14.467 +    printf("compiling shader:\n%s\n\n", code);
  14.468 +#endif
  14.469 +
  14.470 +    data->glGetError();         /* flush any existing error state. */
  14.471 +    data->glGenProgramsARB(1, &program);
  14.472 +    data->glBindProgramARB(shader_type, program);
  14.473 +    data->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB,
  14.474 +                             (GLsizei)SDL_strlen(code), code);
  14.475 +
  14.476 +    SDL_free(code);
  14.477 +
  14.478 +    if (data->glGetError() == GL_INVALID_OPERATION) {
  14.479 +#if DEBUG_PROGRAM_COMPILE
  14.480 +        GLint pos = 0;
  14.481 +        const GLubyte *errstr;
  14.482 +        data->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
  14.483 +        errstr = data->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
  14.484 +        printf("program compile error at position %d: %s\n\n",
  14.485 +               (int) pos, (const char *) errstr);
  14.486 +#endif
  14.487 +        data->glBindProgramARB(shader_type, 0);
  14.488 +        data->glDeleteProgramsARB(1, &program);
  14.489 +        return 0;
  14.490 +    }
  14.491 +
  14.492 +    return program;
  14.493 +}
  14.494 +
  14.495 +
  14.496 +/*
  14.497 + * Fragment program that renders from UYVY textures.
  14.498 + * The UYVY to RGB equasion is:
  14.499 + *   R = 1.164(Y-16) + 1.596(Cr-128)
  14.500 + *   G = 1.164(Y-16) - 0.813(Cr-128) - 0.391(Cb-128)
  14.501 + *   B = 1.164(Y-16) + 2.018(Cb-128)
  14.502 + * Byte layout is Cb, Y1, Cr, Y2, stored in the R, G, B, A channels.
  14.503 + * 4 bytes == 2 pixels: Y1/Cb/Cr, Y2/Cb/Cr
  14.504 + *
  14.505 + * !!! FIXME: this ignores blendmodes, etc.
  14.506 + * !!! FIXME: this could be more efficient...use a dot product for green, etc.
  14.507 + */
  14.508 +static const char *fragment_program_UYVY_source_code = "!!ARBfp1.0\n"
  14.509 +    /* outputs... */
  14.510 +    "OUTPUT outcolor = result.color;\n"
  14.511 +    /* scratch registers... */
  14.512 +    "TEMP uyvy;\n" "TEMP luminance;\n" "TEMP work;\n"
  14.513 +    /* Halve the coordinates to grab the correct 32 bits for the fragment. */
  14.514 +    "MUL work, fragment.texcoord, { 0.5, 1.0, 1.0, 1.0 };\n"
  14.515 +    /* Sample the YUV texture. Cb, Y1, Cr, Y2, are stored in x, y, z, w. */
  14.516 +    "TEX uyvy, work, texture[0], %TEXTURETARGET%;\n"
  14.517 +    /* Do subtractions (128/255, 16/255, 128/255, 16/255) */
  14.518 +    "SUB uyvy, uyvy, { 0.501960784313726, 0.06274509803922, 0.501960784313726, 0.06274509803922 };\n"
  14.519 +    /* Choose the luminance component by texcoord. */
  14.520 +    /* !!! FIXME: laziness wins out for now... just average Y1 and Y2. */
  14.521 +    "ADD luminance, uyvy.yyyy, uyvy.wwww;\n"
  14.522 +    "MUL luminance, luminance, { 0.5, 0.5, 0.5, 0.5 };\n"
  14.523 +    /* Multiply luminance by its magic value. */
  14.524 +    "MUL luminance, luminance, { 1.164, 1.164, 1.164, 1.164 };\n"
  14.525 +    /* uyvy.xyzw becomes Cr/Cr/Cb/Cb, with multiplications. */
  14.526 +    "MUL uyvy, uyvy.zzxx, { 1.596, -0.813, 2.018, -0.391 };\n"
  14.527 +    /* Add luminance to Cr and Cb, store to RGB channels. */
  14.528 +    "ADD work.rgb, luminance, uyvy;\n"
  14.529 +    /* Do final addition for Green channel.  (!!! FIXME: this should be a DPH?) */
  14.530 +    "ADD work.g, work.g, uyvy.w;\n"
  14.531 +    /* Make sure alpha channel is fully opaque.  (!!! FIXME: blend modes!) */
  14.532 +    "MOV work.a, { 1.0 };\n"
  14.533 +    /* Store out the final fragment color... */
  14.534 +    "MOV outcolor, work;\n"
  14.535 +    /* ...and we're done! */
  14.536 +    "END\n";
  14.537 +
  14.538 +static __inline__ SDL_bool
  14.539 +convert_format(GL_RenderData *renderdata, Uint32 pixel_format,
  14.540 +               GLint* internalFormat, GLenum* format, GLenum* type)
  14.541 +{
  14.542 +    switch (pixel_format) {
  14.543 +    case SDL_PIXELFORMAT_RGB332:
  14.544 +        *internalFormat = GL_R3_G3_B2;
  14.545 +        *format = GL_RGB;
  14.546 +        *type = GL_UNSIGNED_BYTE_3_3_2;
  14.547 +        break;
  14.548 +    case SDL_PIXELFORMAT_RGB444:
  14.549 +        *internalFormat = GL_RGB4;
  14.550 +        *format = GL_RGB;
  14.551 +        *type = GL_UNSIGNED_SHORT_4_4_4_4;
  14.552 +        break;
  14.553 +    case SDL_PIXELFORMAT_RGB555:
  14.554 +        *internalFormat = GL_RGB5;
  14.555 +        *format = GL_RGB;
  14.556 +        *type = GL_UNSIGNED_SHORT_5_5_5_1;
  14.557 +        break;
  14.558 +    case SDL_PIXELFORMAT_ARGB4444:
  14.559 +        *internalFormat = GL_RGBA4;
  14.560 +        *format = GL_BGRA;
  14.561 +        *type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
  14.562 +        break;
  14.563 +    case SDL_PIXELFORMAT_ARGB1555:
  14.564 +        *internalFormat = GL_RGB5_A1;
  14.565 +        *format = GL_BGRA;
  14.566 +        *type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
  14.567 +        break;
  14.568 +    case SDL_PIXELFORMAT_RGB565:
  14.569 +        *internalFormat = GL_RGB8;
  14.570 +        *format = GL_RGB;
  14.571 +        *type = GL_UNSIGNED_SHORT_5_6_5;
  14.572 +        break;
  14.573 +    case SDL_PIXELFORMAT_RGB24:
  14.574 +        *internalFormat = GL_RGB8;
  14.575 +        *format = GL_RGB;
  14.576 +        *type = GL_UNSIGNED_BYTE;
  14.577 +        break;
  14.578 +    case SDL_PIXELFORMAT_RGB888:
  14.579 +        *internalFormat = GL_RGB8;
  14.580 +        *format = GL_BGRA;
  14.581 +        *type = GL_UNSIGNED_BYTE;
  14.582 +        break;
  14.583 +    case SDL_PIXELFORMAT_BGR24:
  14.584 +        *internalFormat = GL_RGB8;
  14.585 +        *format = GL_BGR;
  14.586 +        *type = GL_UNSIGNED_BYTE;
  14.587 +        break;
  14.588 +    case SDL_PIXELFORMAT_BGR888:
  14.589 +        *internalFormat = GL_RGB8;
  14.590 +        *format = GL_RGBA;
  14.591 +        *type = GL_UNSIGNED_BYTE;
  14.592 +        break;
  14.593 +    case SDL_PIXELFORMAT_ARGB8888:
  14.594 +#ifdef __MACOSX__
  14.595 +        *internalFormat = GL_RGBA;
  14.596 +        *format = GL_BGRA;
  14.597 +        *type = GL_UNSIGNED_INT_8_8_8_8_REV;
  14.598 +#else
  14.599 +        *internalFormat = GL_RGBA8;
  14.600 +        *format = GL_BGRA;
  14.601 +        *type = GL_UNSIGNED_BYTE;
  14.602 +#endif
  14.603 +        break;
  14.604 +    case SDL_PIXELFORMAT_ABGR8888:
  14.605 +        *internalFormat = GL_RGBA8;
  14.606 +        *format = GL_RGBA;
  14.607 +        *type = GL_UNSIGNED_BYTE;
  14.608 +        break;
  14.609 +    case SDL_PIXELFORMAT_ARGB2101010:
  14.610 +        *internalFormat = GL_RGB10_A2;
  14.611 +        *format = GL_BGRA;
  14.612 +        *type = GL_UNSIGNED_INT_2_10_10_10_REV;
  14.613 +        break;
  14.614 +    case SDL_PIXELFORMAT_UYVY:
  14.615 +        if (renderdata->GL_APPLE_ycbcr_422_supported) {
  14.616 +            *internalFormat = GL_RGB;
  14.617 +            *format = GL_YCBCR_422_APPLE;
  14.618 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  14.619 +            *type = GL_UNSIGNED_SHORT_8_8_APPLE;
  14.620 +#else
  14.621 +            *type = GL_UNSIGNED_SHORT_8_8_REV_APPLE;
  14.622 +#endif
  14.623 +        } else if (renderdata->GL_MESA_ycbcr_texture_supported) {
  14.624 +            *internalFormat = GL_YCBCR_MESA;
  14.625 +            *format = GL_YCBCR_MESA;
  14.626 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  14.627 +            *type = GL_UNSIGNED_SHORT_8_8_MESA;
  14.628 +#else
  14.629 +            *type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
  14.630 +#endif
  14.631 +        } else if (renderdata->GL_ARB_fragment_program_supported) {
  14.632 +            *internalFormat = GL_RGBA;
  14.633 +            *format = GL_RGBA;
  14.634 +            *type = GL_UNSIGNED_BYTE;
  14.635 +        } else {
  14.636 +            return SDL_FALSE;
  14.637 +        }
  14.638 +        break;
  14.639 +    case SDL_PIXELFORMAT_YUY2:
  14.640 +        if (renderdata->GL_APPLE_ycbcr_422_supported) {
  14.641 +            *internalFormat = GL_RGB;
  14.642 +            *format = GL_YCBCR_422_APPLE;
  14.643 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  14.644 +            *type = GL_UNSIGNED_SHORT_8_8_REV_APPLE;
  14.645 +#else
  14.646 +            *type = GL_UNSIGNED_SHORT_8_8_APPLE;
  14.647 +#endif
  14.648 +        } else if (renderdata->GL_MESA_ycbcr_texture_supported) {
  14.649 +            *internalFormat = GL_YCBCR_MESA;
  14.650 +            *format = GL_YCBCR_MESA;
  14.651 +#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  14.652 +            *type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
  14.653 +#else
  14.654 +            *type = GL_UNSIGNED_SHORT_8_8_MESA;
  14.655 +#endif
  14.656 +        } else {
  14.657 +            return SDL_FALSE;
  14.658 +        }
  14.659 +        break;
  14.660 +    default:
  14.661 +        return SDL_FALSE;
  14.662 +    }
  14.663 +    return SDL_TRUE;
  14.664 +}
  14.665 +
  14.666 +static int
  14.667 +GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  14.668 +{
  14.669 +    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
  14.670 +    GL_TextureData *data;
  14.671 +    GLint internalFormat;
  14.672 +    GLenum format, type;
  14.673 +    int texture_w, texture_h;
  14.674 +    GLuint shader = 0;
  14.675 +    GLenum result;
  14.676 +
  14.677 +    GL_ActivateRenderer(renderer);
  14.678 +
  14.679 +    if (!convert_format(renderdata, texture->format, &internalFormat,
  14.680 +                        &format, &type)) {
  14.681 +        SDL_SetError("Texture format %s not supported by OpenGL",
  14.682 +                     SDL_GetPixelFormatName(texture->format));
  14.683 +        return -1;
  14.684 +    }
  14.685 +    if (texture->format == SDL_PIXELFORMAT_UYVY &&
  14.686 +        !renderdata->GL_APPLE_ycbcr_422_supported &&
  14.687 +        !renderdata->GL_MESA_ycbcr_texture_supported &&
  14.688 +        renderdata->GL_ARB_fragment_program_supported) {
  14.689 +        if (renderdata->fragment_program_UYVY == 0) {
  14.690 +            renderdata->fragment_program_UYVY =
  14.691 +                compile_shader(renderdata, GL_FRAGMENT_PROGRAM_ARB,
  14.692 +                               fragment_program_UYVY_source_code);
  14.693 +            if (renderdata->fragment_program_UYVY == 0) {
  14.694 +                set_shader_error(renderdata, "UYVY");
  14.695 +                return -1;
  14.696 +            }
  14.697 +        }
  14.698 +        shader = renderdata->fragment_program_UYVY;
  14.699 +    }
  14.700 +
  14.701 +    data = (GL_TextureData *) SDL_calloc(1, sizeof(*data));
  14.702 +    if (!data) {
  14.703 +        SDL_OutOfMemory();
  14.704 +        return -1;
  14.705 +    }
  14.706 +
  14.707 +    data->shader = shader;
  14.708 +
  14.709 +    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
  14.710 +        data->pitch = texture->w * bytes_per_pixel(texture->format);
  14.711 +        data->pixels = SDL_malloc(texture->h * data->pitch);
  14.712 +        if (!data->pixels) {
  14.713 +            SDL_OutOfMemory();
  14.714 +            SDL_free(data);
  14.715 +            return -1;
  14.716 +        }
  14.717 +    }
  14.718 +
  14.719 +    texture->driverdata = data;
  14.720 +
  14.721 +    renderdata->glGetError();
  14.722 +    renderdata->glGenTextures(1, &data->texture);
  14.723 +    if (renderdata->GL_ARB_texture_rectangle_supported) {
  14.724 +        data->type = GL_TEXTURE_RECTANGLE_ARB;
  14.725 +        texture_w = texture->w;
  14.726 +        texture_h = texture->h;
  14.727 +        data->texw = (GLfloat) texture_w;
  14.728 +        data->texh = (GLfloat) texture_h;
  14.729 +    } else {
  14.730 +        data->type = GL_TEXTURE_2D;
  14.731 +        texture_w = power_of_2(texture->w);
  14.732 +        texture_h = power_of_2(texture->h);
  14.733 +        data->texw = (GLfloat) (texture->w) / texture_w;
  14.734 +        data->texh = (GLfloat) texture->h / texture_h;
  14.735 +    }
  14.736 +
  14.737 +    /* YUV formats use RGBA but are really two bytes per pixel */
  14.738 +    if (internalFormat == GL_RGBA && bytes_per_pixel(texture->format) < 4) {
  14.739 +        texture_w /= 2;
  14.740 +        if (data->type == GL_TEXTURE_2D) {
  14.741 +            data->texw *= 2.0f;
  14.742 +        }
  14.743 +        data->HACK_RYAN_FIXME = 2;
  14.744 +    } else {
  14.745 +        data->HACK_RYAN_FIXME = 1;
  14.746 +    }
  14.747 +
  14.748 +    data->format = format;
  14.749 +    data->formattype = type;
  14.750 +    renderdata->glEnable(data->type);
  14.751 +    renderdata->glBindTexture(data->type, data->texture);
  14.752 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
  14.753 +                                GL_LINEAR);
  14.754 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
  14.755 +                                GL_LINEAR);
  14.756 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
  14.757 +                                GL_CLAMP_TO_EDGE);
  14.758 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
  14.759 +                                GL_CLAMP_TO_EDGE);
  14.760 +#ifdef __MACOSX__
  14.761 +#ifndef GL_TEXTURE_STORAGE_HINT_APPLE
  14.762 +#define GL_TEXTURE_STORAGE_HINT_APPLE       0x85BC
  14.763 +#endif
  14.764 +#ifndef STORAGE_CACHED_APPLE
  14.765 +#define STORAGE_CACHED_APPLE                0x85BE
  14.766 +#endif
  14.767 +#ifndef STORAGE_SHARED_APPLE
  14.768 +#define STORAGE_SHARED_APPLE                0x85BF
  14.769 +#endif
  14.770 +    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
  14.771 +        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
  14.772 +                                    GL_STORAGE_SHARED_APPLE);
  14.773 +    } else {
  14.774 +        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
  14.775 +                                    GL_STORAGE_CACHED_APPLE);
  14.776 +    }
  14.777 +/* This causes a crash in testoverlay for some reason.  Apple bug? */
  14.778 +#if 0
  14.779 +    if (texture->access == SDL_TEXTUREACCESS_STREAMING
  14.780 +        && texture->format == SDL_PIXELFORMAT_ARGB8888) {
  14.781 +        /*
  14.782 +           if (renderdata->glTextureRangeAPPLE) {
  14.783 +           renderdata->glTextureRangeAPPLE(data->type,
  14.784 +           texture->h * data->pitch,
  14.785 +           data->pixels);
  14.786 +           }
  14.787 +         */
  14.788 +        renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
  14.789 +        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
  14.790 +                                 texture_h, 0, format, type, data->pixels);
  14.791 +    } else
  14.792 +#endif
  14.793 +#endif
  14.794 +    {
  14.795 +        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
  14.796 +                                 texture_h, 0, format, type, NULL);
  14.797 +    }
  14.798 +    renderdata->glDisable(data->type);
  14.799 +    result = renderdata->glGetError();
  14.800 +    if (result != GL_NO_ERROR) {
  14.801 +        GL_SetError("glTexImage2D()", result);
  14.802 +        return -1;
  14.803 +    }
  14.804 +    return 0;
  14.805 +}
  14.806 +
  14.807 +static int
  14.808 +GL_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
  14.809 +                      void **pixels, int *pitch)
  14.810 +{
  14.811 +    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
  14.812 +
  14.813 +    *pixels = data->pixels;
  14.814 +    *pitch = data->pitch;
  14.815 +    return 0;
  14.816 +}
  14.817 +
  14.818 +static void
  14.819 +SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture,
  14.820 +                   int pitch)
  14.821 +{
  14.822 +    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  14.823 +    renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
  14.824 +                              (pitch / bytes_per_pixel(texture->format)) /
  14.825 +                              ((GL_TextureData *) texture->driverdata)->
  14.826 +                              HACK_RYAN_FIXME);
  14.827 +}
  14.828 +
  14.829 +static int
  14.830 +GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  14.831 +                 const SDL_Rect * rect, const void *pixels, int pitch)
  14.832 +{
  14.833 +    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
  14.834 +    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
  14.835 +    GLenum result;
  14.836 +
  14.837 +    GL_ActivateRenderer(renderer);
  14.838 +
  14.839 +    renderdata->glGetError();
  14.840 +    SetupTextureUpdate(renderdata, texture, pitch);
  14.841 +    renderdata->glEnable(data->type);
  14.842 +    renderdata->glBindTexture(data->type, data->texture);
  14.843 +    renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
  14.844 +                                rect->h, data->format, data->formattype,
  14.845 +                                pixels);
  14.846 +    renderdata->glDisable(data->type);
  14.847 +    result = renderdata->glGetError();
  14.848 +    if (result != GL_NO_ERROR) {
  14.849 +        GL_SetError("glTexSubImage2D()", result);
  14.850 +        return -1;
  14.851 +    }
  14.852 +    return 0;
  14.853 +}
  14.854 +
  14.855 +static int
  14.856 +GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  14.857 +               const SDL_Rect * rect, int markDirty, void **pixels,
  14.858 +               int *pitch)
  14.859 +{
  14.860 +    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
  14.861 +
  14.862 +    if (markDirty) {
  14.863 +        SDL_AddDirtyRect(&data->dirty, rect);
  14.864 +    }
  14.865 +
  14.866 +    *pixels =
  14.867 +        (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
  14.868 +                  rect->x * bytes_per_pixel(texture->format));
  14.869 +    *pitch = data->pitch;
  14.870 +    return 0;
  14.871 +}
  14.872 +
  14.873 +static void
  14.874 +GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  14.875 +{
  14.876 +}
  14.877 +
  14.878 +static void
  14.879 +GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects,
  14.880 +                const SDL_Rect * rects)
  14.881 +{
  14.882 +    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
  14.883 +    int i;
  14.884 +
  14.885 +    for (i = 0; i < numrects; ++i) {
  14.886 +        SDL_AddDirtyRect(&data->dirty, &rects[i]);
  14.887 +    }
  14.888 +}
  14.889 +
  14.890 +static void
  14.891 +GL_SetBlendMode(GL_RenderData * data, int blendMode)
  14.892 +{
  14.893 +    if (blendMode != data->blendMode) {
  14.894 +        switch (blendMode) {
  14.895 +        case SDL_BLENDMODE_NONE:
  14.896 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  14.897 +            data->glDisable(GL_BLEND);
  14.898 +            break;
  14.899 +        case SDL_BLENDMODE_BLEND:
  14.900 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  14.901 +            data->glEnable(GL_BLEND);
  14.902 +            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  14.903 +            break;
  14.904 +        case SDL_BLENDMODE_ADD:
  14.905 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  14.906 +            data->glEnable(GL_BLEND);
  14.907 +            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  14.908 +            break;
  14.909 +        }
  14.910 +        data->blendMode = blendMode;
  14.911 +    }
  14.912 +}
  14.913 +
  14.914 +static int
  14.915 +GL_RenderClear(SDL_Renderer * renderer)
  14.916 +{
  14.917 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
  14.918 +
  14.919 +    GL_ActivateRenderer(renderer);
  14.920 +
  14.921 +    data->glClearColor((GLfloat) renderer->r * inv255f,
  14.922 +                       (GLfloat) renderer->g * inv255f,
  14.923 +                       (GLfloat) renderer->b * inv255f,
  14.924 +                       (GLfloat) renderer->a * inv255f);
  14.925 +
  14.926 +    data->glClear(GL_COLOR_BUFFER_BIT);
  14.927 +
  14.928 +    return 0;
  14.929 +}
  14.930 +
  14.931 +static int
  14.932 +GL_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
  14.933 +                    int count)
  14.934 +{
  14.935 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
  14.936 +    int i;
  14.937 +
  14.938 +    GL_ActivateRenderer(renderer);
  14.939 +
  14.940 +    GL_SetBlendMode(data, renderer->blendMode);
  14.941 +
  14.942 +    data->glColor4f((GLfloat) renderer->r * inv255f,
  14.943 +                    (GLfloat) renderer->g * inv255f,
  14.944 +                    (GLfloat) renderer->b * inv255f,
  14.945 +                    (GLfloat) renderer->a * inv255f);
  14.946 +
  14.947 +    data->glBegin(GL_POINTS);
  14.948 +    for (i = 0; i < count; ++i) {
  14.949 +        data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
  14.950 +    }
  14.951 +    data->glEnd();
  14.952 +
  14.953 +    return 0;
  14.954 +}
  14.955 +
  14.956 +static int
  14.957 +GL_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
  14.958 +                   int count)
  14.959 +{
  14.960 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
  14.961 +    int i;
  14.962 +
  14.963 +    GL_ActivateRenderer(renderer);
  14.964 +
  14.965 +    GL_SetBlendMode(data, renderer->blendMode);
  14.966 +
  14.967 +    data->glColor4f((GLfloat) renderer->r * inv255f,
  14.968 +                    (GLfloat) renderer->g * inv255f,
  14.969 +                    (GLfloat) renderer->b * inv255f,
  14.970 +                    (GLfloat) renderer->a * inv255f);
  14.971 +
  14.972 +    if (count > 2 && 
  14.973 +        points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
  14.974 +        data->glBegin(GL_LINE_LOOP);
  14.975 +        /* GL_LINE_LOOP takes care of the final segment */
  14.976 +        --count;
  14.977 +        for (i = 0; i < count; ++i) {
  14.978 +            data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
  14.979 +        }
  14.980 +        data->glEnd();
  14.981 +    } else {
  14.982 +#if defined(__APPLE__) || defined(__WIN32__)
  14.983 +#else
  14.984 +        int x1, y1, x2, y2;
  14.985 +#endif
  14.986 +
  14.987 +        data->glBegin(GL_LINE_STRIP);
  14.988 +        for (i = 0; i < count; ++i) {
  14.989 +            data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y);
  14.990 +        }
  14.991 +        data->glEnd();
  14.992 +
  14.993 +        /* The line is half open, so we need one more point to complete it.
  14.994 +         * http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html
  14.995 +         * If we have to, we can use vertical line and horizontal line textures
  14.996 +         * for vertical and horizontal lines, and then create custom textures
  14.997 +         * for diagonal lines and software render those.  It's terrible, but at
  14.998 +         * least it would be pixel perfect.
  14.999 +         */
 14.1000 +        data->glBegin(GL_POINTS);
 14.1001 +#if defined(__APPLE__) || defined(__WIN32__)
 14.1002 +        /* Mac OS X and Windows seem to always leave the second point open */
 14.1003 +        data->glVertex2f(0.5f + points[count-1].x, 0.5f + points[count-1].y);
 14.1004 +#else
 14.1005 +        /* Linux seems to leave the right-most or bottom-most point open */
 14.1006 +        x1 = points[0].x;
 14.1007 +        y1 = points[0].y;
 14.1008 +        x2 = points[count-1].x;
 14.1009 +        y2 = points[count-1].y;
 14.1010 +
 14.1011 +        if (x1 > x2) {
 14.1012 +            data->glVertex2f(0.5f + x1, 0.5f + y1);
 14.1013 +        } else if (x2 > x1) {
 14.1014 +            data->glVertex2f(0.5f + x2, 0.5f + y2);
 14.1015 +        } else if (y1 > y2) {
 14.1016 +            data->glVertex2f(0.5f + x1, 0.5f + y1);
 14.1017 +        } else if (y2 > y1) {
 14.1018 +            data->glVertex2f(0.5f + x2, 0.5f + y2);
 14.1019 +        }
 14.1020 +#endif
 14.1021 +        data->glEnd();
 14.1022 +    }
 14.1023 +
 14.1024 +    return 0;
 14.1025 +}
 14.1026 +
 14.1027 +static int
 14.1028 +GL_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
 14.1029 +{
 14.1030 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
 14.1031 +    int i;
 14.1032 +
 14.1033 +    GL_ActivateRenderer(renderer);
 14.1034 +
 14.1035 +    GL_SetBlendMode(data, renderer->blendMode);
 14.1036 +
 14.1037 +    data->glColor4f((GLfloat) renderer->r * inv255f,
 14.1038 +                    (GLfloat) renderer->g * inv255f,
 14.1039 +                    (GLfloat) renderer->b * inv255f,
 14.1040 +                    (GLfloat) renderer->a * inv255f);
 14.1041 +
 14.1042 +    for (i = 0; i < count; ++i) {
 14.1043 +        const SDL_Rect *rect = rects[i];
 14.1044 +
 14.1045 +        data->glRecti(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
 14.1046 +    }
 14.1047 +
 14.1048 +    return 0;
 14.1049 +}
 14.1050 +
 14.1051 +static int
 14.1052 +GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
 14.1053 +              const SDL_Rect * srcrect, const SDL_Rect * dstrect)
 14.1054 +{
 14.1055 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
 14.1056 +    GL_TextureData *texturedata = (GL_TextureData *) texture->driverdata;
 14.1057 +    int minx, miny, maxx, maxy;
 14.1058 +    GLfloat minu, maxu, minv, maxv;
 14.1059 +
 14.1060 +    GL_ActivateRenderer(renderer);
 14.1061 +
 14.1062 +    if (texturedata->dirty.list) {
 14.1063 +        SDL_DirtyRect *dirty;
 14.1064 +        void *pixels;
 14.1065 +        int bpp = bytes_per_pixel(texture->format);
 14.1066 +        int pitch = texturedata->pitch;
 14.1067 +
 14.1068 +        SetupTextureUpdate(data, texture, pitch);
 14.1069 +        data->glEnable(texturedata->type);
 14.1070 +        data->glBindTexture(texturedata->type, texturedata->texture);
 14.1071 +        for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
 14.1072 +            SDL_Rect *rect = &dirty->rect;
 14.1073 +            pixels =
 14.1074 +                (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch +
 14.1075 +                          rect->x * bpp);
 14.1076 +            data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
 14.1077 +                                  rect->w / texturedata->HACK_RYAN_FIXME,
 14.1078 +                                  rect->h, texturedata->format,
 14.1079 +                                  texturedata->formattype, pixels);
 14.1080 +        }
 14.1081 +        SDL_ClearDirtyRects(&texturedata->dirty);
 14.1082 +    }
 14.1083 +
 14.1084 +    minx = dstrect->x;
 14.1085 +    miny = dstrect->y;
 14.1086 +    maxx = dstrect->x + dstrect->w;
 14.1087 +    maxy = dstrect->y + dstrect->h;
 14.1088 +
 14.1089 +    minu = (GLfloat) srcrect->x / texture->w;
 14.1090 +    minu *= texturedata->texw;
 14.1091 +    maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
 14.1092 +    maxu *= texturedata->texw;
 14.1093 +    minv = (GLfloat) srcrect->y / texture->h;
 14.1094 +    minv *= texturedata->texh;
 14.1095 +    maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
 14.1096 +    maxv *= texturedata->texh;
 14.1097 +
 14.1098 +    data->glEnable(texturedata->type);
 14.1099 +    data->glBindTexture(texturedata->type, texturedata->texture);
 14.1100 +
 14.1101 +    if (texture->modMode) {
 14.1102 +        data->glColor4f((GLfloat) texture->r * inv255f,
 14.1103 +                        (GLfloat) texture->g * inv255f,
 14.1104 +                        (GLfloat) texture->b * inv255f,
 14.1105 +                        (GLfloat) texture->a * inv255f);
 14.1106 +    } else {
 14.1107 +        data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
 14.1108 +    }
 14.1109 +
 14.1110 +    GL_SetBlendMode(data, texture->blendMode);
 14.1111 +
 14.1112 +    /* Set up the shader for the copy, if any */
 14.1113 +    if (texturedata->shader) {
 14.1114 +        data->glEnable(GL_FRAGMENT_PROGRAM_ARB);
 14.1115 +        data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, texturedata->shader);
 14.1116 +    }
 14.1117 +
 14.1118 +    data->glBegin(GL_TRIANGLE_STRIP);
 14.1119 +    data->glTexCoord2f(minu, minv);
 14.1120 +    data->glVertex2f((GLfloat) minx, (GLfloat) miny);
 14.1121 +    data->glTexCoord2f(maxu, minv);
 14.1122 +    data->glVertex2f((GLfloat) maxx, (GLfloat) miny);
 14.1123 +    data->glTexCoord2f(minu, maxv);
 14.1124 +    data->glVertex2f((GLfloat) minx, (GLfloat) maxy);
 14.1125 +    data->glTexCoord2f(maxu, maxv);
 14.1126 +    data->glVertex2f((GLfloat) maxx, (GLfloat) maxy);
 14.1127 +    data->glEnd();
 14.1128 +
 14.1129 +    if (texturedata->shader) {
 14.1130 +        data->glDisable(GL_FRAGMENT_PROGRAM_ARB);
 14.1131 +    }
 14.1132 +
 14.1133 +    data->glDisable(texturedata->type);
 14.1134 +
 14.1135 +    return 0;
 14.1136 +}
 14.1137 +
 14.1138 +static int
 14.1139 +GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
 14.1140 +                    Uint32 pixel_format, void * pixels, int pitch)
 14.1141 +{
 14.1142 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
 14.1143 +    SDL_Window *window = renderer->window;
 14.1144 +    GLint internalFormat;
 14.1145 +    GLenum format, type;
 14.1146 +    Uint8 *src, *dst, *tmp;
 14.1147 +    int w, h, length, rows;
 14.1148 +
 14.1149 +    GL_ActivateRenderer(renderer);
 14.1150 +
 14.1151 +    if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) {
 14.1152 +        /* FIXME: Do a temp copy to a format that is supported */
 14.1153 +        SDL_SetError("Unsupported pixel format");
 14.1154 +        return -1;
 14.1155 +    }
 14.1156 +
 14.1157 +    SDL_GetWindowSize(window, &w, &h);
 14.1158 +
 14.1159 +    data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
 14.1160 +    data->glPixelStorei(GL_PACK_ROW_LENGTH,
 14.1161 +                        (pitch / bytes_per_pixel(pixel_format)));
 14.1162 +
 14.1163 +    data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
 14.1164 +                       format, type, pixels);
 14.1165 +
 14.1166 +    /* Flip the rows to be top-down */
 14.1167 +    length = rect->w * bytes_per_pixel(pixel_format);
 14.1168 +    src = (Uint8*)pixels + (rect->h-1)*pitch;
 14.1169 +    dst = (Uint8*)pixels;
 14.1170 +    tmp = SDL_stack_alloc(Uint8, length);
 14.1171 +    rows = rect->h / 2;
 14.1172 +    while (rows--) {
 14.1173 +        SDL_memcpy(tmp, dst, length);
 14.1174 +        SDL_memcpy(dst, src, length);
 14.1175 +        SDL_memcpy(src, tmp, length);
 14.1176 +        dst += pitch;
 14.1177 +        src -= pitch;
 14.1178 +    }
 14.1179 +    SDL_stack_free(tmp);
 14.1180 +
 14.1181 +    return 0;
 14.1182 +}
 14.1183 +
 14.1184 +static int
 14.1185 +GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
 14.1186 +                     Uint32 pixel_format, const void * pixels, int pitch)
 14.1187 +{
 14.1188 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
 14.1189 +    SDL_Window *window = renderer->window;
 14.1190 +    GLint internalFormat;
 14.1191 +    GLenum format, type;
 14.1192 +    Uint8 *src, *dst, *tmp;
 14.1193 +    int w, h, length, rows;
 14.1194 +
 14.1195 +    GL_ActivateRenderer(renderer);
 14.1196 +
 14.1197 +    if (!convert_format(data, pixel_format, &internalFormat, &format, &type)) {
 14.1198 +        /* FIXME: Do a temp copy to a format that is supported */
 14.1199 +        SDL_SetError("Unsupported pixel format");
 14.1200 +        return -1;
 14.1201 +    }
 14.1202 +
 14.1203 +    SDL_GetWindowSize(window, &w, &h);
 14.1204 +
 14.1205 +    data->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 14.1206 +    data->glPixelStorei(GL_UNPACK_ROW_LENGTH,
 14.1207 +                        (pitch / bytes_per_pixel(pixel_format)));
 14.1208 +
 14.1209 +    /* Flip the rows to be bottom-up */
 14.1210 +    length = rect->h * rect->w * pitch;
 14.1211 +    tmp = SDL_stack_alloc(Uint8, length);
 14.1212 +    src = (Uint8*)pixels + (rect->h-1)*pitch;
 14.1213 +    dst = (Uint8*)tmp;
 14.1214 +    rows = rect->h;
 14.1215 +    while (rows--) {
 14.1216 +        SDL_memcpy(dst, src, pitch);
 14.1217 +        dst += pitch;
 14.1218 +        src -= pitch;
 14.1219 +    }
 14.1220 +
 14.1221 +    data->glRasterPos2i(rect->x, (h-rect->y));
 14.1222 +    data->glDrawPixels(rect->w, rect->h, format, type, tmp);
 14.1223 +    SDL_stack_free(tmp);
 14.1224 +
 14.1225 +    return 0;
 14.1226 +}
 14.1227 +
 14.1228 +static void
 14.1229 +GL_RenderPresent(SDL_Renderer * renderer)
 14.1230 +{
 14.1231 +    GL_ActivateRenderer(renderer);
 14.1232 +
 14.1233 +    SDL_GL_SwapWindow(renderer->window);
 14.1234 +}
 14.1235 +
 14.1236 +static void
 14.1237 +GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
 14.1238 +{
 14.1239 +    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
 14.1240 +    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
 14.1241 +
 14.1242 +    GL_ActivateRenderer(renderer);
 14.1243 +
 14.1244 +    if (!data) {
 14.1245 +        return;
 14.1246 +    }
 14.1247 +    if (data->texture) {
 14.1248 +        renderdata->glDeleteTextures(1, &data->texture);
 14.1249 +    }
 14.1250 +    if (data->palette) {
 14.1251 +        SDL_free(data->palette);
 14.1252 +    }
 14.1253 +    if (data->pixels) {
 14.1254 +        SDL_free(data->pixels);
 14.1255 +    }
 14.1256 +    SDL_FreeDirtyRects(&data->dirty);
 14.1257 +    SDL_free(data);
 14.1258 +    texture->driverdata = NULL;
 14.1259 +}
 14.1260 +
 14.1261 +static void
 14.1262 +GL_DestroyRenderer(SDL_Renderer * renderer)
 14.1263 +{
 14.1264 +    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
 14.1265 +
 14.1266 +    if (data) {
 14.1267 +        if (data->context) {
 14.1268 +            if (data->GL_ARB_fragment_program_supported) {
 14.1269 +                data->glDisable(GL_FRAGMENT_PROGRAM_ARB);
 14.1270 +                data->glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0);
 14.1271 +                if (data->fragment_program_UYVY &&
 14.1272 +                    data->fragment_program_UYVY != ~0) {
 14.1273 +                    data->glDeleteProgramsARB(1,
 14.1274 +                                              &data->fragment_program_UYVY);
 14.1275 +                }
 14.1276 +            }
 14.1277 +
 14.1278 +            /* SDL_GL_MakeCurrent(0, NULL); *//* doesn't do anything */
 14.1279 +            SDL_GL_DeleteContext(data->context);
 14.1280 +        }
 14.1281 +        SDL_free(data);
 14.1282 +    }
 14.1283 +    SDL_free(renderer);
 14.1284 +}
 14.1285 +
 14.1286 +#endif /* SDL_VIDEO_RENDER_OGL */
 14.1287 +
 14.1288 +/* vi: set ts=4 sw=4 expandtab: */
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/render/opengles/SDL_renderer_gles.c	Wed Feb 02 14:34:54 2011 -0800
    15.3 @@ -0,0 +1,842 @@
    15.4 +/*
    15.5 +    SDL - Simple DirectMedia Layer
    15.6 +    Copyright (C) 1997-2010 Sam Lantinga
    15.7 +
    15.8 +    This library is free software; you can redistribute it and/or
    15.9 +    modify it under the terms of the GNU Lesser General Public
   15.10 +    License as published by the Free Software Foundation; either
   15.11 +    version 2.1 of the License, or (at your option) any later version.
   15.12 +
   15.13 +    This library is distributed in the hope that it will be useful,
   15.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   15.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   15.16 +    Lesser General Public License for more details.
   15.17 +
   15.18 +    You should have received a copy of the GNU Lesser General Public
   15.19 +    License along with this library; if not, write to the Free Software
   15.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   15.21 +
   15.22 +    Sam Lantinga
   15.23 +    slouken@libsdl.org
   15.24 +*/
   15.25 +#include "SDL_config.h"
   15.26 +
   15.27 +#if SDL_VIDEO_RENDER_OGL_ES
   15.28 +
   15.29 +#include "SDL_opengles.h"
   15.30 +#include "../SDL_sysrender.h"
   15.31 +
   15.32 +#if defined(SDL_VIDEO_DRIVER_PANDORA)
   15.33 +
   15.34 +/* Empty function stub to get OpenGL ES 1.x support without  */
   15.35 +/* OpenGL ES extension GL_OES_draw_texture supported         */
   15.36 +GL_API void GL_APIENTRY
   15.37 +glDrawTexiOES(GLint x, GLint y, GLint z, GLint width, GLint height)
   15.38 +{
   15.39 +    return;
   15.40 +}
   15.41 +
   15.42 +#endif /* PANDORA */
   15.43 +
   15.44 +/* OpenGL ES 1.1 renderer implementation, based on the OpenGL renderer */
   15.45 +
   15.46 +/* Used to re-create the window with OpenGL capability */
   15.47 +extern int SDL_RecreateWindow(SDL_Window * window, Uint32 flags);
   15.48 +
   15.49 +static const float inv255f = 1.0f / 255.0f;
   15.50 +
   15.51 +static SDL_Renderer *GLES_CreateRenderer(SDL_Window * window, Uint32 flags);
   15.52 +static void GLES_WindowEvent(SDL_Renderer * renderer,
   15.53 +                             const SDL_WindowEvent *event);
   15.54 +static int GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
   15.55 +static int GLES_QueryTexturePixels(SDL_Renderer * renderer,
   15.56 +                                   SDL_Texture * texture, void **pixels,
   15.57 +                                   int *pitch);
   15.58 +static int GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   15.59 +                              const SDL_Rect * rect, const void *pixels,
   15.60 +                              int pitch);
   15.61 +static int GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   15.62 +                            const SDL_Rect * rect, int markDirty,
   15.63 +                            void **pixels, int *pitch);
   15.64 +static void GLES_UnlockTexture(SDL_Renderer * renderer,
   15.65 +                               SDL_Texture * texture);
   15.66 +static void GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   15.67 +                              int numrects, const SDL_Rect * rects);
   15.68 +static int GLES_RenderDrawPoints(SDL_Renderer * renderer,
   15.69 +                                 const SDL_Point * points, int count);
   15.70 +static int GLES_RenderDrawLines(SDL_Renderer * renderer,
   15.71 +                                const SDL_Point * points, int count);
   15.72 +static int GLES_RenderFillRects(SDL_Renderer * renderer,
   15.73 +                                const SDL_Rect ** rects, int count);
   15.74 +static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   15.75 +                           const SDL_Rect * srcrect,
   15.76 +                           const SDL_Rect * dstrect);
   15.77 +static void GLES_RenderPresent(SDL_Renderer * renderer);
   15.78 +static void GLES_DestroyTexture(SDL_Renderer * renderer,
   15.79 +                                SDL_Texture * texture);
   15.80 +static void GLES_DestroyRenderer(SDL_Renderer * renderer);
   15.81 +
   15.82 +
   15.83 +SDL_RenderDriver GL_ES_RenderDriver = {
   15.84 +    GLES_CreateRenderer,
   15.85 +    {
   15.86 +     "opengl_es",
   15.87 +     (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
   15.88 +     6,
   15.89 +     {
   15.90 +      /* OpenGL ES 1.x supported formats list */
   15.91 +      SDL_PIXELFORMAT_RGBA4444,
   15.92 +      SDL_PIXELFORMAT_RGBA5551,
   15.93 +      SDL_PIXELFORMAT_RGB565,
   15.94 +      SDL_PIXELFORMAT_RGB24,
   15.95 +      SDL_PIXELFORMAT_BGR888,
   15.96 +      SDL_PIXELFORMAT_ABGR8888},
   15.97 +     0,
   15.98 +     0}
   15.99 +};
  15.100 +
  15.101 +typedef struct
  15.102 +{
  15.103 +    SDL_GLContext context;
  15.104 +    SDL_bool updateSize;
  15.105 +    int blendMode;
  15.106 +
  15.107 +#ifndef APIENTRY
  15.108 +#define APIENTRY
  15.109 +#endif
  15.110 +
  15.111 +    SDL_bool useDrawTexture;
  15.112 +    SDL_bool GL_OES_draw_texture_supported;
  15.113 +
  15.114 +    /* OpenGL ES functions */
  15.115 +#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
  15.116 +#include "SDL_glesfuncs.h"
  15.117 +#undef SDL_PROC
  15.118 +
  15.119 +} GLES_RenderData;
  15.120 +
  15.121 +typedef struct
  15.122 +{
  15.123 +    GLuint texture;
  15.124 +    GLenum type;
  15.125 +    GLfloat texw;
  15.126 +    GLfloat texh;
  15.127 +    GLenum format;
  15.128 +    GLenum formattype;
  15.129 +    void *pixels;
  15.130 +    int pitch;
  15.131 +    SDL_DirtyRectList dirty;
  15.132 +} GLES_TextureData;
  15.133 +
  15.134 +static void
  15.135 +GLES_SetError(const char *prefix, GLenum result)
  15.136 +{
  15.137 +    const char *error;
  15.138 +
  15.139 +    switch (result) {
  15.140 +    case GL_NO_ERROR:
  15.141 +        error = "GL_NO_ERROR";
  15.142 +        break;
  15.143 +    case GL_INVALID_ENUM:
  15.144 +        error = "GL_INVALID_ENUM";
  15.145 +        break;
  15.146 +    case GL_INVALID_VALUE:
  15.147 +        error = "GL_INVALID_VALUE";
  15.148 +        break;
  15.149 +    case GL_INVALID_OPERATION:
  15.150 +        error = "GL_INVALID_OPERATION";
  15.151 +        break;
  15.152 +    case GL_STACK_OVERFLOW:
  15.153 +        error = "GL_STACK_OVERFLOW";
  15.154 +        break;
  15.155 +    case GL_STACK_UNDERFLOW:
  15.156 +        error = "GL_STACK_UNDERFLOW";
  15.157 +        break;
  15.158 +    case GL_OUT_OF_MEMORY:
  15.159 +        error = "GL_OUT_OF_MEMORY";
  15.160 +        break;
  15.161 +    default:
  15.162 +        error = "UNKNOWN";
  15.163 +        break;
  15.164 +    }
  15.165 +    SDL_SetError("%s: %s", prefix, error);
  15.166 +}
  15.167 +
  15.168 +static int
  15.169 +GLES_LoadFunctions(GLES_RenderData * data)
  15.170 +{
  15.171 +
  15.172 +#define SDL_PROC(ret,func,params) \
  15.173 +    data->func = func;
  15.174 +#include "SDL_glesfuncs.h"
  15.175 +#undef SDL_PROC
  15.176 +
  15.177 +    return 0;
  15.178 +}
  15.179 +
  15.180 +SDL_Renderer *
  15.181 +GLES_CreateRenderer(SDL_Window * window, Uint32 flags)
  15.182 +{
  15.183 +
  15.184 +    SDL_Renderer *renderer;
  15.185 +    GLES_RenderData *data;
  15.186 +    GLint value;
  15.187 +    Uint32 window_flags;
  15.188 +
  15.189 +    window_flags = SDL_GetWindowFlags(window);
  15.190 +    if (!(window_flags & SDL_WINDOW_OPENGL)) {
  15.191 +        if (SDL_RecreateWindow(window, window_flags | SDL_WINDOW_OPENGL) < 0) {
  15.192 +            return NULL;
  15.193 +        }
  15.194 +    }
  15.195 +
  15.196 +    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
  15.197 +    if (!renderer) {
  15.198 +        SDL_OutOfMemory();
  15.199 +        return NULL;
  15.200 +    }
  15.201 +
  15.202 +    data = (GLES_RenderData *) SDL_calloc(1, sizeof(*data));
  15.203 +    if (!data) {
  15.204 +        GLES_DestroyRenderer(renderer);
  15.205 +        SDL_OutOfMemory();
  15.206 +        return NULL;
  15.207 +    }
  15.208 +
  15.209 +    renderer->WindowEvent = GLES_WindowEvent;
  15.210 +    renderer->CreateTexture = GLES_CreateTexture;
  15.211 +    renderer->QueryTexturePixels = GLES_QueryTexturePixels;
  15.212 +    renderer->UpdateTexture = GLES_UpdateTexture;
  15.213 +    renderer->LockTexture = GLES_LockTexture;
  15.214 +    renderer->UnlockTexture = GLES_UnlockTexture;
  15.215 +    renderer->DirtyTexture = GLES_DirtyTexture;
  15.216 +    renderer->RenderDrawPoints = GLES_RenderDrawPoints;
  15.217 +    renderer->RenderDrawLines = GLES_RenderDrawLines;
  15.218 +    renderer->RenderFillRects = GLES_RenderFillRects;
  15.219 +    renderer->RenderCopy = GLES_RenderCopy;
  15.220 +    renderer->RenderPresent = GLES_RenderPresent;
  15.221 +    renderer->DestroyTexture = GLES_DestroyTexture;
  15.222 +    renderer->DestroyRenderer = GLES_DestroyRenderer;
  15.223 +    renderer->info = GL_ES_RenderDriver.info;
  15.224 +    renderer->window = window;
  15.225 +    renderer->driverdata = data;
  15.226 +
  15.227 +    renderer->info.flags = SDL_RENDERER_ACCELERATED;
  15.228 +
  15.229 +    if (GLES_LoadFunctions(data) < 0) {
  15.230 +        GLES_DestroyRenderer(renderer);
  15.231 +        return NULL;
  15.232 +    }
  15.233 +
  15.234 +    data->context = SDL_GL_CreateContext(window);
  15.235 +    if (!data->context) {
  15.236 +        GLES_DestroyRenderer(renderer);
  15.237 +        return NULL;
  15.238 +    }
  15.239 +    if (SDL_GL_MakeCurrent(window, data->context) < 0) {
  15.240 +        GLES_DestroyRenderer(renderer);
  15.241 +        return NULL;
  15.242 +    }
  15.243 +
  15.244 +    if (flags & SDL_RENDERER_PRESENTVSYNC) {
  15.245 +        SDL_GL_SetSwapInterval(1);
  15.246 +    } else {
  15.247 +        SDL_GL_SetSwapInterval(0);
  15.248 +    }
  15.249 +    if (SDL_GL_GetSwapInterval() > 0) {
  15.250 +        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
  15.251 +    }
  15.252 +
  15.253 +#if SDL_VIDEO_DRIVER_PANDORA
  15.254 +    data->GL_OES_draw_texture_supported = SDL_FALSE;
  15.255 +    data->useDrawTexture = SDL_FALSE;
  15.256 +#else
  15.257 +    if (SDL_GL_ExtensionSupported("GL_OES_draw_texture")) {
  15.258 +        data->GL_OES_draw_texture_supported = SDL_TRUE;
  15.259 +        data->useDrawTexture = SDL_TRUE;
  15.260 +    } else {
  15.261 +        data->GL_OES_draw_texture_supported = SDL_FALSE;
  15.262 +        data->useDrawTexture = SDL_FALSE;
  15.263 +    }
  15.264 +#endif
  15.265 +
  15.266 +    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
  15.267 +    renderer->info.max_texture_width = value;
  15.268 +    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
  15.269 +    renderer->info.max_texture_height = value;
  15.270 +
  15.271 +    /* Set up parameters for rendering */
  15.272 +    data->blendMode = -1;
  15.273 +    data->glDisable(GL_DEPTH_TEST);
  15.274 +    data->glDisable(GL_CULL_FACE);
  15.275 +    data->updateSize = SDL_TRUE;
  15.276 +
  15.277 +    data->glEnableClientState(GL_VERTEX_ARRAY);
  15.278 +    data->glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  15.279 +    
  15.280 +    return renderer;
  15.281 +}
  15.282 +
  15.283 +static SDL_GLContext SDL_CurrentContext = NULL;
  15.284 +
  15.285 +static int
  15.286 +GLES_ActivateRenderer(SDL_Renderer * renderer)
  15.287 +{
  15.288 +
  15.289 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
  15.290 +    SDL_Window *window = renderer->window;
  15.291 +
  15.292 +    if (SDL_CurrentContext != data->context) {
  15.293 +        if (SDL_GL_MakeCurrent(window, data->context) < 0) {
  15.294 +            return -1;
  15.295 +        }
  15.296 +        SDL_CurrentContext = data->context;
  15.297 +    }
  15.298 +    if (data->updateSize) {
  15.299 +        int w, h;
  15.300 +
  15.301 +        SDL_GetWindowSize(window, &w, &h);
  15.302 +        data->glMatrixMode(GL_PROJECTION);
  15.303 +        data->glLoadIdentity();
  15.304 +        data->glMatrixMode(GL_MODELVIEW);
  15.305 +        data->glLoadIdentity();
  15.306 +        data->glViewport(0, 0, w, h);
  15.307 +        data->glOrthof(0.0, (GLfloat) w, (GLfloat) h, 0.0, 0.0, 1.0);
  15.308 +        data->updateSize = SDL_FALSE;
  15.309 +    }
  15.310 +    return 0;
  15.311 +}
  15.312 +
  15.313 +static void
  15.314 +GLES_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
  15.315 +{
  15.316 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
  15.317 +
  15.318 +    if (event->event == SDL_WINDOWEVENT_RESIZED) {
  15.319 +        /* Rebind the context to the window area and update matrices */
  15.320 +        SDL_CurrentContext = NULL;
  15.321 +        data->updateSize = SDL_TRUE;
  15.322 +    }
  15.323 +}
  15.324 +
  15.325 +static __inline__ int
  15.326 +power_of_2(int input)
  15.327 +{
  15.328 +    int value = 1;
  15.329 +
  15.330 +    while (value < input) {
  15.331 +        value <<= 1;
  15.332 +    }
  15.333 +    return value;
  15.334 +}
  15.335 +
  15.336 +static int
  15.337 +GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  15.338 +{
  15.339 +    GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
  15.340 +    GLES_TextureData *data;
  15.341 +    GLint internalFormat;
  15.342 +    GLenum format, type;
  15.343 +    int texture_w, texture_h;
  15.344 +    GLenum result;
  15.345 +
  15.346 +    GLES_ActivateRenderer(renderer);
  15.347 +
  15.348 +    switch (texture->format) {
  15.349 +    case SDL_PIXELFORMAT_RGB24:
  15.350 +        internalFormat = GL_RGB;
  15.351 +        format = GL_RGB;
  15.352 +        type = GL_UNSIGNED_BYTE;
  15.353 +        break;
  15.354 +    case SDL_PIXELFORMAT_BGR888:
  15.355 +    case SDL_PIXELFORMAT_ABGR8888:
  15.356 +        internalFormat = GL_RGBA;
  15.357 +        format = GL_RGBA;
  15.358 +        type = GL_UNSIGNED_BYTE;
  15.359 +        break;
  15.360 +    case SDL_PIXELFORMAT_RGB565:
  15.361 +        internalFormat = GL_RGB;
  15.362 +        format = GL_RGB;
  15.363 +        type = GL_UNSIGNED_SHORT_5_6_5;
  15.364 +        break;
  15.365 +    case SDL_PIXELFORMAT_RGBA5551:
  15.366 +        internalFormat = GL_RGBA;
  15.367 +        format = GL_RGBA;
  15.368 +        type = GL_UNSIGNED_SHORT_5_5_5_1;
  15.369 +        break;
  15.370 +    case SDL_PIXELFORMAT_RGBA4444:
  15.371 +        internalFormat = GL_RGBA;
  15.372 +        format = GL_RGBA;
  15.373 +        type = GL_UNSIGNED_SHORT_4_4_4_4;
  15.374 +        break;
  15.375 +    default:
  15.376 +        SDL_SetError("Texture format %s not supported by OpenGL ES",
  15.377 +                     SDL_GetPixelFormatName(texture->format));
  15.378 +        return -1;
  15.379 +    }
  15.380 +
  15.381 +    data = (GLES_TextureData *) SDL_calloc(1, sizeof(*data));
  15.382 +    if (!data) {
  15.383 +        SDL_OutOfMemory();
  15.384 +        return -1;
  15.385 +    }
  15.386 +
  15.387 +    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
  15.388 +        data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
  15.389 +        data->pixels = SDL_malloc(texture->h * data->pitch);
  15.390 +        if (!data->pixels) {
  15.391 +            SDL_OutOfMemory();
  15.392 +            SDL_free(data);
  15.393 +            return -1;
  15.394 +        }
  15.395 +    }
  15.396 +
  15.397 +    texture->driverdata = data;
  15.398 +
  15.399 +    renderdata->glGetError();
  15.400 +    renderdata->glEnable(GL_TEXTURE_2D);
  15.401 +    renderdata->glGenTextures(1, &data->texture);
  15.402 +
  15.403 +    data->type = GL_TEXTURE_2D;
  15.404 +    /* no NPOV textures allowed in OpenGL ES (yet) */
  15.405 +    texture_w = power_of_2(texture->w);
  15.406 +    texture_h = power_of_2(texture->h);
  15.407 +    data->texw = (GLfloat) texture->w / texture_w;
  15.408 +    data->texh = (GLfloat) texture->h / texture_h;
  15.409 +
  15.410 +    data->format = format;
  15.411 +    data->formattype = type;
  15.412 +    renderdata->glBindTexture(data->type, data->texture);
  15.413 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
  15.414 +                                GL_LINEAR);
  15.415 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
  15.416 +                                GL_LINEAR);
  15.417 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
  15.418 +                                GL_CLAMP_TO_EDGE);
  15.419 +    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
  15.420 +                                GL_CLAMP_TO_EDGE);
  15.421 +
  15.422 +    renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
  15.423 +                             texture_h, 0, format, type, NULL);
  15.424 +    renderdata->glDisable(GL_TEXTURE_2D);
  15.425 +
  15.426 +    result = renderdata->glGetError();
  15.427 +    if (result != GL_NO_ERROR) {
  15.428 +        GLES_SetError("glTexImage2D()", result);
  15.429 +        return -1;
  15.430 +    }
  15.431 +    return 0;
  15.432 +}
  15.433 +
  15.434 +static int
  15.435 +GLES_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
  15.436 +                        void **pixels, int *pitch)
  15.437 +{
  15.438 +    GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
  15.439 +
  15.440 +    *pixels = data->pixels;
  15.441 +    *pitch = data->pitch;
  15.442 +    return 0;
  15.443 +}
  15.444 +
  15.445 +static void
  15.446 +SetupTextureUpdate(GLES_RenderData * renderdata, SDL_Texture * texture,
  15.447 +                   int pitch)
  15.448 +{
  15.449 +    GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
  15.450 +    renderdata->glBindTexture(data->type, data->texture);
  15.451 +    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  15.452 +}
  15.453 +
  15.454 +static int
  15.455 +GLES_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  15.456 +                   const SDL_Rect * rect, const void *pixels, int pitch)
  15.457 +{
  15.458 +    GLES_RenderData *renderdata = (GLES_RenderData *) renderer->driverdata;
  15.459 +    GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
  15.460 +    GLenum result;
  15.461 +    int bpp = SDL_BYTESPERPIXEL(texture->format);
  15.462 +    void * temp_buffer;
  15.463 +    void * temp_ptr;
  15.464 +    int i;
  15.465 +
  15.466 +    GLES_ActivateRenderer(renderer);
  15.467 +
  15.468 +    renderdata->glGetError();
  15.469 +    renderdata->glEnable(data->type);
  15.470 +    SetupTextureUpdate(renderdata, texture, pitch);
  15.471 +
  15.472 +    if( rect->w * bpp == pitch ) {
  15.473 +         temp_buffer = (void *)pixels; /* No need to reformat */
  15.474 +    } else {
  15.475 +         /* Reformatting of mem area required */
  15.476 +         temp_buffer = SDL_malloc(rect->w * rect->h * bpp);
  15.477 +         temp_ptr = temp_buffer;
  15.478 +         for (i = 0; i < rect->h; i++) {
  15.479 +             SDL_memcpy(temp_ptr, pixels, rect->w * bpp);
  15.480 +             temp_ptr += rect->w * bpp;
  15.481 +             pixels += pitch;
  15.482 +         }
  15.483 +    }
  15.484 +
  15.485 +    renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
  15.486 +                                rect->h, data->format, data->formattype,
  15.487 +                                temp_buffer);
  15.488 +
  15.489 +    if( temp_buffer != pixels ) {
  15.490 +        SDL_free(temp_buffer);
  15.491 +    }
  15.492 +
  15.493 +    renderdata->glDisable(data->type);
  15.494 +    result = renderdata->glGetError();
  15.495 +    if (result != GL_NO_ERROR) {
  15.496 +        GLES_SetError("glTexSubImage2D()", result);
  15.497 +        return -1;
  15.498 +    }
  15.499 +    return 0;
  15.500 +}
  15.501 +
  15.502 +static int
  15.503 +GLES_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  15.504 +                 const SDL_Rect * rect, int markDirty, void **pixels,
  15.505 +                 int *pitch)
  15.506 +{
  15.507 +    GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
  15.508 +
  15.509 +    if (markDirty) {
  15.510 +        SDL_AddDirtyRect(&data->dirty, rect);
  15.511 +    }
  15.512 +
  15.513 +    *pixels =
  15.514 +        (void *) ((Uint8 *) data->pixels + rect->y * data->pitch +
  15.515 +                  rect->x * SDL_BYTESPERPIXEL(texture->format));
  15.516 +    *pitch = data->pitch;
  15.517 +    return 0;
  15.518 +}
  15.519 +
  15.520 +static void
  15.521 +GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  15.522 +{
  15.523 +}
  15.524 +
  15.525 +static void
  15.526 +GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  15.527 +                  int numrects, const SDL_Rect * rects)
  15.528 +{
  15.529 +    GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
  15.530 +    int i;
  15.531 +
  15.532 +    for (i = 0; i < numrects; ++i) {
  15.533 +        SDL_AddDirtyRect(&data->dirty, &rects[i]);
  15.534 +    }
  15.535 +}
  15.536 +
  15.537 +static void
  15.538 +GLES_SetBlendMode(GLES_RenderData * data, int blendMode)
  15.539 +{
  15.540 +    if (blendMode != data->blendMode) {
  15.541 +        switch (blendMode) {
  15.542 +        case SDL_BLENDMODE_NONE:
  15.543 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  15.544 +            data->glDisable(GL_BLEND);
  15.545 +            break;
  15.546 +        case SDL_BLENDMODE_BLEND:
  15.547 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  15.548 +            data->glEnable(GL_BLEND);
  15.549 +            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  15.550 +            break;
  15.551 +        case SDL_BLENDMODE_ADD:
  15.552 +            data->glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  15.553 +            data->glEnable(GL_BLEND);
  15.554 +            data->glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  15.555 +            break;
  15.556 +        }
  15.557 +        data->blendMode = blendMode;
  15.558 +    }
  15.559 +}
  15.560 +
  15.561 +static int
  15.562 +GLES_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
  15.563 +                      int count)
  15.564 +{
  15.565 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
  15.566 +    int i;
  15.567 +    GLshort *vertices;
  15.568 +
  15.569 +    GLES_ActivateRenderer(renderer);
  15.570 +
  15.571 +    GLES_SetBlendMode(data, renderer->blendMode);
  15.572 +
  15.573 +    data->glColor4f((GLfloat) renderer->r * inv255f,
  15.574 +                    (GLfloat) renderer->g * inv255f,
  15.575 +                    (GLfloat) renderer->b * inv255f,
  15.576 +                    (GLfloat) renderer->a * inv255f);
  15.577 +
  15.578 +    vertices = SDL_stack_alloc(GLshort, count*2);
  15.579 +    for (i = 0; i < count; ++i) {
  15.580 +        vertices[2*i+0] = (GLshort)points[i].x;
  15.581 +        vertices[2*i+1] = (GLshort)points[i].y;
  15.582 +    }
  15.583 +    data->glVertexPointer(2, GL_SHORT, 0, vertices);
  15.584 +    data->glDrawArrays(GL_POINTS, 0, count);
  15.585 +    SDL_stack_free(vertices);
  15.586 +
  15.587 +    return 0;
  15.588 +}
  15.589 +
  15.590 +static int
  15.591 +GLES_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
  15.592 +                     int count)
  15.593 +{
  15.594 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
  15.595 +    int i;
  15.596 +    GLshort *vertices;
  15.597 +
  15.598 +    GLES_ActivateRenderer(renderer);
  15.599 +
  15.600 +    GLES_SetBlendMode(data, renderer->blendMode);
  15.601 +
  15.602 +    data->glColor4f((GLfloat) renderer->r * inv255f,
  15.603 +                    (GLfloat) renderer->g * inv255f,
  15.604 +                    (GLfloat) renderer->b * inv255f,
  15.605 +                    (GLfloat) renderer->a * inv255f);
  15.606 +
  15.607 +    vertices = SDL_stack_alloc(GLshort, count*2);
  15.608 +    for (i = 0; i < count; ++i) {
  15.609 +        vertices[2*i+0] = (GLshort)points[i].x;
  15.610 +        vertices[2*i+1] = (GLshort)points[i].y;
  15.611 +    }
  15.612 +    data->glVertexPointer(2, GL_SHORT, 0, vertices);
  15.613 +    if (count > 2 && 
  15.614 +        points[0].x == points[count-1].x && points[0].y == points[count-1].y) {
  15.615 +        /* GL_LINE_LOOP takes care of the final segment */
  15.616 +        --count;
  15.617 +        data->glDrawArrays(GL_LINE_LOOP, 0, count);
  15.618 +    } else {
  15.619 +        data->glDrawArrays(GL_LINE_STRIP, 0, count);
  15.620 +    }
  15.621 +    SDL_stack_free(vertices);
  15.622 +
  15.623 +    return 0;
  15.624 +}
  15.625 +
  15.626 +static int
  15.627 +GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
  15.628 +                     int count)
  15.629 +{
  15.630 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
  15.631 +    int i;
  15.632 +
  15.633 +    GLES_ActivateRenderer(renderer);
  15.634 +
  15.635 +    GLES_SetBlendMode(data, renderer->blendMode);
  15.636 +
  15.637 +    data->glColor4f((GLfloat) renderer->r * inv255f,
  15.638 +                    (GLfloat) renderer->g * inv255f,
  15.639 +                    (GLfloat) renderer->b * inv255f,
  15.640 +                    (GLfloat) renderer->a * inv255f);
  15.641 +
  15.642 +    for (i = 0; i < count; ++i) {
  15.643 +        const SDL_Rect *rect = rects[i];
  15.644 +        GLshort minx = rect->x;
  15.645 +        GLshort maxx = rect->x + rect->w;
  15.646 +        GLshort miny = rect->y;
  15.647 +        GLshort maxy = rect->y + rect->h;
  15.648 +        GLshort vertices[8];
  15.649 +        vertices[0] = minx;
  15.650 +        vertices[1] = miny;
  15.651 +        vertices[2] = maxx;
  15.652 +        vertices[3] = miny;
  15.653 +        vertices[4] = minx;
  15.654 +        vertices[5] = maxy;
  15.655 +        vertices[6] = maxx;
  15.656 +        vertices[7] = maxy;
  15.657 +
  15.658 +        data->glVertexPointer(2, GL_SHORT, 0, vertices);
  15.659 +        data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  15.660 +    }
  15.661 +
  15.662 +    return 0;
  15.663 +}
  15.664 +
  15.665 +static int
  15.666 +GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
  15.667 +                const SDL_Rect * srcrect, const SDL_Rect * dstrect)
  15.668 +{
  15.669 +
  15.670 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
  15.671 +    GLES_TextureData *texturedata = (GLES_TextureData *) texture->driverdata;
  15.672 +    int minx, miny, maxx, maxy;
  15.673 +    GLfloat minu, maxu, minv, maxv;
  15.674 +    int i;
  15.675 +    void *temp_buffer;          /* used for reformatting dirty rect pixels */
  15.676 +    void *temp_ptr;
  15.677 +
  15.678 +    GLES_ActivateRenderer(renderer);
  15.679 +
  15.680 +    data->glEnable(GL_TEXTURE_2D);
  15.681 +
  15.682 +    if (texturedata->dirty.list) {
  15.683 +        SDL_DirtyRect *dirty;
  15.684 +        void *pixels;
  15.685 +        int bpp = SDL_BYTESPERPIXEL(texture->format);
  15.686 +        int pitch = texturedata->pitch;
  15.687 +
  15.688 +        SetupTextureUpdate(data, texture, pitch);
  15.689 +
  15.690 +        data->glBindTexture(texturedata->type, texturedata->texture);
  15.691 +        for (dirty = texturedata->dirty.list; dirty; dirty = dirty->next) {
  15.692 +            SDL_Rect *rect = &dirty->rect;
  15.693 +            pixels =
  15.694 +                (void *) ((Uint8 *) texturedata->pixels + rect->y * pitch +
  15.695 +                          rect->x * bpp);
  15.696 +            /*      There is no GL_UNPACK_ROW_LENGTH in OpenGLES 
  15.697 +               we must do this reformatting ourselves(!)
  15.698 +
  15.699 +               maybe it'd be a good idea to keep a temp buffer around
  15.700 +               for this purpose rather than allocating it each time
  15.701 +             */
  15.702 +            if( rect->x == 0 && rect->w * bpp == pitch ) {
  15.703 +                temp_buffer = pixels; /* Updating whole texture, no need to reformat */
  15.704 +            } else {
  15.705 +                temp_buffer = SDL_malloc(rect->w * rect->h * bpp);
  15.706 +                temp_ptr = temp_buffer;
  15.707 +                for (i = 0; i < rect->h; i++) {
  15.708 +                    SDL_memcpy(temp_ptr, pixels, rect->w * bpp);
  15.709 +                    temp_ptr += rect->w * bpp;
  15.710 +                    pixels += pitch;
  15.711 +                }
  15.712 +            }
  15.713 +
  15.714 +            data->glTexSubImage2D(texturedata->type, 0, rect->x, rect->y,
  15.715 +                                  rect->w, rect->h, texturedata->format,
  15.716 +                                  texturedata->formattype, temp_buffer);
  15.717 +
  15.718 +            if( temp_buffer != pixels ) {
  15.719 +                SDL_free(temp_buffer);
  15.720 +            }
  15.721 +        }
  15.722 +        SDL_ClearDirtyRects(&texturedata->dirty);
  15.723 +    }
  15.724 +
  15.725 +    data->glBindTexture(texturedata->type, texturedata->texture);
  15.726 +
  15.727 +    if (texture->modMode) {
  15.728 +        data->glColor4f((GLfloat) texture->r * inv255f,
  15.729 +                        (GLfloat) texture->g * inv255f,
  15.730 +                        (GLfloat) texture->b * inv255f,
  15.731 +                        (GLfloat) texture->a * inv255f);
  15.732 +    } else {
  15.733 +        data->glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
  15.734 +    }
  15.735 +
  15.736 +    GLES_SetBlendMode(data, texture->blendMode);
  15.737 +
  15.738 +    if (data->GL_OES_draw_texture_supported && data->useDrawTexture) {
  15.739 +        /* this code is a little funny because the viewport is upside down vs SDL's coordinate system */
  15.740 +        GLint cropRect[4];
  15.741 +        int w, h;
  15.742 +        SDL_Window *window = renderer->window;
  15.743 +
  15.744 +        SDL_GetWindowSize(window, &w, &h);
  15.745 +        cropRect[0] = srcrect->x;
  15.746 +        cropRect[1] = srcrect->y + srcrect->h;
  15.747 +        cropRect[2] = srcrect->w;
  15.748 +        cropRect[3] = -srcrect->h;
  15.749 +        data->glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES,
  15.750 +                               cropRect);
  15.751 +        data->glDrawTexiOES(dstrect->x, h - dstrect->y - dstrect->h, 0,
  15.752 +                            dstrect->w, dstrect->h);
  15.753 +    } else {
  15.754 +
  15.755 +        minx = dstrect->x;
  15.756 +        miny = dstrect->y;
  15.757 +        maxx = dstrect->x + dstrect->w;
  15.758 +        maxy = dstrect->y + dstrect->h;
  15.759 +
  15.760 +        minu = (GLfloat) srcrect->x / texture->w;
  15.761 +        minu *= texturedata->texw;
  15.762 +        maxu = (GLfloat) (srcrect->x + srcrect->w) / texture->w;
  15.763 +        maxu *= texturedata->texw;
  15.764 +        minv = (GLfloat) srcrect->y / texture->h;
  15.765 +        minv *= texturedata->texh;
  15.766 +        maxv = (GLfloat) (srcrect->y + srcrect->h) / texture->h;
  15.767 +        maxv *= texturedata->texh;
  15.768 +
  15.769 +        GLshort vertices[8];
  15.770 +        GLfloat texCoords[8];
  15.771 +
  15.772 +        vertices[0] = minx;
  15.773 +        vertices[1] = miny;
  15.774 +        vertices[2] = maxx;
  15.775 +        vertices[3] = miny;
  15.776 +        vertices[4] = minx;
  15.777 +        vertices[5] = maxy;
  15.778 +        vertices[6] = maxx;
  15.779 +        vertices[7] = maxy;
  15.780 +
  15.781 +        texCoords[0] = minu;
  15.782 +        texCoords[1] = minv;
  15.783 +        texCoords[2] = maxu;
  15.784 +        texCoords[3] = minv;
  15.785 +        texCoords[4] = minu;
  15.786 +        texCoords[5] = maxv;
  15.787 +        texCoords[6] = maxu;
  15.788 +        texCoords[7] = maxv;
  15.789 +
  15.790 +        data->glVertexPointer(2, GL_SHORT, 0, vertices);
  15.791 +        data->glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
  15.792 +        data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  15.793 +    }
  15.794 +
  15.795 +    data->glDisable(GL_TEXTURE_2D);
  15.796 +
  15.797 +    return 0;
  15.798 +}
  15.799 +
  15.800 +static void
  15.801 +GLES_RenderPresent(SDL_Renderer * renderer)
  15.802 +{
  15.803 +    GLES_ActivateRenderer(renderer);
  15.804 +
  15.805 +    SDL_GL_SwapWindow(renderer->window);
  15.806 +}
  15.807 +
  15.808 +static void
  15.809 +GLES_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  15.810 +{
  15.811 +    GLES_TextureData *data = (GLES_TextureData *) texture->driverdata;
  15.812 +
  15.813 +    GLES_ActivateRenderer(renderer);
  15.814 +
  15.815 +    if (!data) {
  15.816 +        return;
  15.817 +    }
  15.818 +    if (data->texture) {
  15.819 +        glDeleteTextures(1, &data->texture);
  15.820 +    }
  15.821 +    if (data->pixels) {
  15.822 +        SDL_free(data->pixels);
  15.823 +    }
  15.824 +    SDL_FreeDirtyRects(&data->dirty);
  15.825 +    SDL_free(data);
  15.826 +    texture->driverdata = NULL;
  15.827 +}
  15.828 +
  15.829 +static void
  15.830 +GLES_DestroyRenderer(SDL_Renderer * renderer)
  15.831 +{
  15.832 +    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
  15.833 +
  15.834 +    if (data) {
  15.835 +        if (data->context) {
  15.836 +            SDL_GL_DeleteContext(data->context);
  15.837 +        }
  15.838 +        SDL_free(data);
  15.839 +    }
  15.840 +    SDL_free(renderer);
  15.841 +}
  15.842 +
  15.843 +#endif /* SDL_VIDEO_RENDER_OGL_ES */
  15.844 +
  15.845 +/* vi: set ts=4 sw=4 expandtab: */
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/render/software/SDL_renderer_sw.c	Wed Feb 02 14:34:54 2011 -0800
    16.3 @@ -0,0 +1,726 @@
    16.4 +/*
    16.5 +    SDL - Simple DirectMedia Layer
    16.6 +    Copyright (C) 1997-2010 Sam Lantinga
    16.7 +
    16.8 +    This library is free software; you can redistribute it and/or
    16.9 +    modify it under the terms of the GNU Lesser General Public
   16.10 +    License as published by the Free Software Foundation; either
   16.11 +    version 2.1 of the License, or (at your option) any later version.
   16.12 +
   16.13 +    This library is distributed in the hope that it will be useful,
   16.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   16.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   16.16 +    Lesser General Public License for more details.
   16.17 +
   16.18 +    You should have received a copy of the GNU Lesser General Public
   16.19 +    License along with this library; if not, write to the Free Software
   16.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   16.21 +
   16.22 +    Sam Lantinga
   16.23 +    slouken@libsdl.org
   16.24 +*/
   16.25 +#include "SDL_config.h"
   16.26 +
   16.27 +#include "../SDL_sysrender.h"
   16.28 +#include "../../video/SDL_pixels_c.h"
   16.29 +#include "../../video/SDL_yuv_sw_c.h"
   16.30 +
   16.31 +
   16.32 +/* SDL surface based renderer implementation */
   16.33 +
   16.34 +static SDL_Renderer *SW_CreateRenderer(SDL_Window * window, Uint32 flags);
   16.35 +static void SW_WindowEvent(SDL_Renderer * renderer,
   16.36 +                           const SDL_WindowEvent *event);
   16.37 +static int SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
   16.38 +static int SW_QueryTexturePixels(SDL_Renderer * renderer,
   16.39 +                                 SDL_Texture * texture, void **pixels,
   16.40 +                                 int *pitch);
   16.41 +static int SW_SetTextureColorMod(SDL_Renderer * renderer,
   16.42 +                                 SDL_Texture * texture);
   16.43 +static int SW_SetTextureAlphaMod(SDL_Renderer * renderer,
   16.44 +                                 SDL_Texture * texture);
   16.45 +static int SW_SetTextureBlendMode(SDL_Renderer * renderer,
   16.46 +                                  SDL_Texture * texture);
   16.47 +static int SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   16.48 +                            const SDL_Rect * rect, const void *pixels,
   16.49 +                            int pitch);
   16.50 +static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   16.51 +                          const SDL_Rect * rect, int markDirty, void **pixels,
   16.52 +                          int *pitch);
   16.53 +static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
   16.54 +static int SW_RenderDrawPoints(SDL_Renderer * renderer,
   16.55 +                               const SDL_Point * points, int count);
   16.56 +static int SW_RenderDrawLines(SDL_Renderer * renderer,
   16.57 +                              const SDL_Point * points, int count);
   16.58 +static int SW_RenderFillRects(SDL_Renderer * renderer,
   16.59 +                              const SDL_Rect ** rects, int count);
   16.60 +static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   16.61 +                         const SDL_Rect * srcrect, const SDL_Rect * dstrect);
   16.62 +static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   16.63 +                               Uint32 format, void * pixels, int pitch);
   16.64 +static int SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   16.65 +                                Uint32 format, const void * pixels, int pitch);
   16.66 +static void SW_RenderPresent(SDL_Renderer * renderer);
   16.67 +static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
   16.68 +static void SW_DestroyRenderer(SDL_Renderer * renderer);
   16.69 +
   16.70 +
   16.71 +SDL_RenderDriver SW_RenderDriver = {
   16.72 +    SW_CreateRenderer,
   16.73 +    {
   16.74 +     "software",
   16.75 +     (SDL_RENDERER_PRESENTVSYNC),
   16.76 +     13,
   16.77 +     {
   16.78 +      SDL_PIXELFORMAT_RGB555,
   16.79 +      SDL_PIXELFORMAT_RGB565,
   16.80 +      SDL_PIXELFORMAT_RGB888,
   16.81 +      SDL_PIXELFORMAT_BGR888,
   16.82 +      SDL_PIXELFORMAT_ARGB8888,
   16.83 +      SDL_PIXELFORMAT_RGBA8888,
   16.84 +      SDL_PIXELFORMAT_ABGR8888,
   16.85 +      SDL_PIXELFORMAT_BGRA8888,
   16.86 +      SDL_PIXELFORMAT_YV12,
   16.87 +      SDL_PIXELFORMAT_IYUV,
   16.88 +      SDL_PIXELFORMAT_YUY2,
   16.89 +      SDL_PIXELFORMAT_UYVY,
   16.90 +      SDL_PIXELFORMAT_YVYU},
   16.91 +     0,
   16.92 +     0}
   16.93 +};
   16.94 +
   16.95 +typedef struct
   16.96 +{
   16.97 +    Uint32 format;
   16.98 +    SDL_bool updateSize;
   16.99 +    SDL_Texture *texture;
  16.100 +    SDL_Surface surface;
  16.101 +    SDL_Renderer *renderer;
  16.102 +    SDL_DirtyRectList dirty;
  16.103 +} SW_RenderData;
  16.104 +
  16.105 +static SDL_Texture *
  16.106 +CreateTexture(SDL_Renderer * renderer, Uint32 format, int w, int h)
  16.107 +{
  16.108 +    SDL_Texture *texture;
  16.109 +
  16.110 +    texture = (SDL_Texture *) SDL_calloc(1, sizeof(*texture));
  16.111 +    if (!texture) {
  16.112 +        SDL_OutOfMemory();
  16.113 +        return NULL;
  16.114 +    }
  16.115 +
  16.116 +    texture->format = format;
  16.117 +    texture->access = SDL_TEXTUREACCESS_STREAMING;
  16.118 +    texture->w = w;
  16.119 +    texture->h = h;
  16.120 +    texture->renderer = renderer;
  16.121 +
  16.122 +    if (renderer->CreateTexture(renderer, texture) < 0) {
  16.123 +        SDL_free(texture);
  16.124 +        return NULL;
  16.125 +    }
  16.126 +    return texture;
  16.127 +}
  16.128 +
  16.129 +static void
  16.130 +DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  16.131 +{
  16.132 +    renderer->DestroyTexture(renderer, texture);
  16.133 +    SDL_free(texture);
  16.134 +}
  16.135 +
  16.136 +SDL_Renderer *
  16.137 +SW_CreateRenderer(SDL_Window * window, Uint32 flags)
  16.138 +{
  16.139 +    SDL_Renderer *renderer;
  16.140 +    SW_RenderData *data;
  16.141 +    int i;
  16.142 +    Uint32 format;
  16.143 +    int bpp;
  16.144 +    Uint32 Rmask, Gmask, Bmask, Amask;
  16.145 +    Uint32 renderer_flags;
  16.146 +    const char *desired_driver;
  16.147 +
  16.148 +    format = SDL_GetWindowPixelFormat(window);
  16.149 +    if (!SDL_PixelFormatEnumToMasks
  16.150 +        (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
  16.151 +        SDL_SetError("Unknown display format");
  16.152 +        return NULL;
  16.153 +    }
  16.154 +
  16.155 +    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
  16.156 +    if (!renderer) {
  16.157 +        SDL_OutOfMemory();
  16.158 +        return NULL;
  16.159 +    }
  16.160 +
  16.161 +    data = (SW_RenderData *) SDL_calloc(1, sizeof(*data));
  16.162 +    if (!data) {
  16.163 +        SW_DestroyRenderer(renderer);
  16.164 +        SDL_OutOfMemory();
  16.165 +        return NULL;
  16.166 +    }
  16.167 +    renderer->WindowEvent = SW_WindowEvent;
  16.168 +    renderer->CreateTexture = SW_CreateTexture;
  16.169 +    renderer->QueryTexturePixels = SW_QueryTexturePixels;
  16.170 +    renderer->SetTextureColorMod = SW_SetTextureColorMod;
  16.171 +    renderer->SetTextureAlphaMod = SW_SetTextureAlphaMod;
  16.172 +    renderer->SetTextureBlendMode = SW_SetTextureBlendMode;
  16.173 +    renderer->UpdateTexture = SW_UpdateTexture;
  16.174 +    renderer->LockTexture = SW_LockTexture;
  16.175 +    renderer->UnlockTexture = SW_UnlockTexture;
  16.176 +    renderer->DestroyTexture = SW_DestroyTexture;
  16.177 +    renderer->RenderDrawPoints = SW_RenderDrawPoints;
  16.178 +    renderer->RenderDrawLines = SW_RenderDrawLines;
  16.179 +    renderer->RenderFillRects = SW_RenderFillRects;
  16.180 +    renderer->RenderCopy = SW_RenderCopy;
  16.181 +    renderer->RenderReadPixels = SW_RenderReadPixels;
  16.182 +    renderer->RenderWritePixels = SW_RenderWritePixels;
  16.183 +    renderer->RenderPresent = SW_RenderPresent;
  16.184 +    renderer->DestroyRenderer = SW_DestroyRenderer;
  16.185 +    renderer->info = SW_RenderDriver.info;
  16.186 +    renderer->info.flags = 0;
  16.187 +    renderer->window = window;
  16.188 +    renderer->driverdata = data;
  16.189 +
  16.190 +    data->format = format;
  16.191 +
  16.192 +    /* Find a render driver that we can use to display data */
  16.193 +    renderer_flags = 0;
  16.194 +    if (flags & SDL_RENDERER_PRESENTVSYNC) {
  16.195 +        renderer_flags |= SDL_RENDERER_PRESENTVSYNC;
  16.196 +    }
  16.197 +    desired_driver = SDL_getenv("SDL_VIDEO_RENDERER_SWDRIVER");
  16.198 +    for (i = 0; i < SDL_GetNumRenderDrivers(); ++i) {
  16.199 +        SDL_RendererInfo info;
  16.200 +        SDL_GetRenderDriverInfo(i, &info);
  16.201 +        if (SDL_strcmp(info.name, SW_RenderDriver.info.name) == 0) {
  16.202 +            continue;
  16.203 +        }
  16.204 +        if (desired_driver
  16.205 +            && SDL_strcasecmp(desired_driver, info.name) != 0) {
  16.206 +            continue;
  16.207 +        }
  16.208 +        data->renderer = SDL_CreateRenderer(window, i, renderer_flags);
  16.209 +        if (data->renderer) {
  16.210 +            break;
  16.211 +        }
  16.212 +    }
  16.213 +    if (i == SDL_GetNumRenderDrivers()) {
  16.214 +        SW_DestroyRenderer(renderer);
  16.215 +        SDL_SetError("Couldn't find display render driver");
  16.216 +        return NULL;
  16.217 +    }
  16.218 +    if (data->renderer->info.flags & SDL_RENDERER_PRESENTVSYNC) {
  16.219 +        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
  16.220 +    }
  16.221 +
  16.222 +    /* Create the textures we'll use for display */
  16.223 +    data->texture =
  16.224 +        CreateTexture(data->renderer, data->format, window->w, window->h);
  16.225 +    if (!data->texture) {
  16.226 +        SW_DestroyRenderer(renderer);
  16.227 +        return NULL;
  16.228 +    }
  16.229 +
  16.230 +    /* Create a surface we'll use for rendering */
  16.231 +    data->surface.flags = SDL_PREALLOC;
  16.232 +    data->surface.format = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
  16.233 +    if (!data->surface.format) {
  16.234 +        SW_DestroyRenderer(renderer);
  16.235 +        return NULL;
  16.236 +    }
  16.237 +
  16.238 +    return renderer;
  16.239 +}
  16.240 +
  16.241 +static SDL_Texture *
  16.242 +SW_ActivateRenderer(SDL_Renderer * renderer)
  16.243 +{
  16.244 +    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
  16.245 +    SDL_Window *window = renderer->window;
  16.246 +
  16.247 +    if (data->updateSize) {
  16.248 +        /* Recreate the textures for the new window size */
  16.249 +        if (data->texture) {
  16.250 +            DestroyTexture(data->renderer, data->texture);
  16.251 +        }
  16.252 +        data->texture = CreateTexture(data->renderer, data->format,
  16.253 +                                      window->w, window->h);
  16.254 +        if (data->texture) {
  16.255 +            data->updateSize = SDL_FALSE;
  16.256 +        }
  16.257 +    }
  16.258 +    return data->texture;
  16.259 +}
  16.260 +
  16.261 +static void
  16.262 +SW_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
  16.263 +{
  16.264 +    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
  16.265 +
  16.266 +    if (event->event == SDL_WINDOWEVENT_RESIZED) {
  16.267 +        data->updateSize = SDL_TRUE;
  16.268 +    }
  16.269 +}
  16.270 +
  16.271 +static int
  16.272 +SW_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  16.273 +{
  16.274 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  16.275 +        texture->driverdata =
  16.276 +            SDL_SW_CreateYUVTexture(texture->format, texture->w, texture->h);
  16.277 +    } else {
  16.278 +        int bpp;
  16.279 +        Uint32 Rmask, Gmask, Bmask, Amask;
  16.280 +
  16.281 +        if (!SDL_PixelFormatEnumToMasks
  16.282 +            (texture->format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
  16.283 +            SDL_SetError("Unknown texture format");
  16.284 +            return -1;
  16.285 +        }
  16.286 +
  16.287 +        texture->driverdata =
  16.288 +            SDL_CreateRGBSurface(0, texture->w, texture->h, bpp, Rmask, Gmask,
  16.289 +                                 Bmask, Amask);
  16.290 +        SDL_SetSurfaceColorMod(texture->driverdata, texture->r, texture->g,
  16.291 +                               texture->b);
  16.292 +        SDL_SetSurfaceAlphaMod(texture->driverdata, texture->a);
  16.293 +        SDL_SetSurfaceBlendMode(texture->driverdata, texture->blendMode);
  16.294 +
  16.295 +        if (texture->access == SDL_TEXTUREACCESS_STATIC) {
  16.296 +            SDL_SetSurfaceRLE(texture->driverdata, 1);
  16.297 +        }
  16.298 +    }
  16.299 +
  16.300 +    if (!texture->driverdata) {
  16.301 +        return -1;
  16.302 +    }
  16.303 +    return 0;
  16.304 +}
  16.305 +
  16.306 +static int
  16.307 +SW_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
  16.308 +                      void **pixels, int *pitch)
  16.309 +{
  16.310 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  16.311 +        return SDL_SW_QueryYUVTexturePixels((SDL_SW_YUVTexture *)
  16.312 +                                            texture->driverdata, pixels,
  16.313 +                                            pitch);
  16.314 +    } else {
  16.315 +        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  16.316 +
  16.317 +        *pixels = surface->pixels;
  16.318 +        *pitch = surface->pitch;
  16.319 +        return 0;
  16.320 +    }
  16.321 +}
  16.322 +
  16.323 +static int
  16.324 +SW_SetTextureColorMod(SDL_Renderer * renderer, SDL_Texture * texture)
  16.325 +{
  16.326 +    SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  16.327 +    return SDL_SetSurfaceColorMod(surface, texture->r, texture->g,
  16.328 +                                  texture->b);
  16.329 +}
  16.330 +
  16.331 +static int
  16.332 +SW_SetTextureAlphaMod(SDL_Renderer * renderer, SDL_Texture * texture)
  16.333 +{
  16.334 +    SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  16.335 +    return SDL_SetSurfaceAlphaMod(surface, texture->a);
  16.336 +}
  16.337 +
  16.338 +static int
  16.339 +SW_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
  16.340 +{
  16.341 +    SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  16.342 +    return SDL_SetSurfaceBlendMode(surface, texture->blendMode);
  16.343 +}
  16.344 +
  16.345 +static int
  16.346 +SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  16.347 +                 const SDL_Rect * rect, const void *pixels, int pitch)
  16.348 +{
  16.349 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  16.350 +        return SDL_SW_UpdateYUVTexture((SDL_SW_YUVTexture *)
  16.351 +                                       texture->driverdata, rect, pixels,
  16.352 +                                       pitch);
  16.353 +    } else {
  16.354 +        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  16.355 +        Uint8 *src, *dst;
  16.356 +        int row;
  16.357 +        size_t length;
  16.358 +
  16.359 +        src = (Uint8 *) pixels;
  16.360 +        dst =
  16.361 +            (Uint8 *) surface->pixels + rect->y * surface->pitch +
  16.362 +            rect->x * surface->format->BytesPerPixel;
  16.363 +        length = rect->w * surface->format->BytesPerPixel;
  16.364 +        for (row = 0; row < rect->h; ++row) {
  16.365 +            SDL_memcpy(dst, src, length);
  16.366 +            src += pitch;
  16.367 +            dst += surface->pitch;
  16.368 +        }
  16.369 +        return 0;
  16.370 +    }
  16.371 +}
  16.372 +
  16.373 +static int
  16.374 +SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  16.375 +               const SDL_Rect * rect, int markDirty, void **pixels,
  16.376 +               int *pitch)
  16.377 +{
  16.378 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  16.379 +        return SDL_SW_LockYUVTexture((SDL_SW_YUVTexture *)
  16.380 +                                     texture->driverdata, rect, markDirty,
  16.381 +                                     pixels, pitch);
  16.382 +    } else {
  16.383 +        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  16.384 +
  16.385 +        *pixels =
  16.386 +            (void *) ((Uint8 *) surface->pixels + rect->y * surface->pitch +
  16.387 +                      rect->x * surface->format->BytesPerPixel);
  16.388 +        *pitch = surface->pitch;
  16.389 +        return 0;
  16.390 +    }
  16.391 +}
  16.392 +
  16.393 +static void
  16.394 +SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  16.395 +{
  16.396 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  16.397 +        SDL_SW_UnlockYUVTexture((SDL_SW_YUVTexture *) texture->driverdata);
  16.398 +    }
  16.399 +}
  16.400 +
  16.401 +static int
  16.402 +SW_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
  16.403 +                    int count)
  16.404 +{
  16.405 +    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
  16.406 +    SDL_Texture *texture = SW_ActivateRenderer(renderer);
  16.407 +    SDL_Rect rect;
  16.408 +    int i;
  16.409 +    int x, y;
  16.410 +    int status = 0;
  16.411 +
  16.412 +    if (!texture) {
  16.413 +        return -1;
  16.414 +    }
  16.415 +
  16.416 +    /* Get the smallest rectangle that contains everything */
  16.417 +    rect.x = 0;
  16.418 +    rect.y = 0;
  16.419 +    rect.w = texture->w;
  16.420 +    rect.h = texture->h;
  16.421 +    if (!SDL_EnclosePoints(points, count, &rect, &rect)) {
  16.422 +        /* Nothing to draw */
  16.423 +        return 0;
  16.424 +    }
  16.425 +
  16.426 +    if (data->renderer->LockTexture(data->renderer, texture, &rect, 1,
  16.427 +                                    &data->surface.pixels,
  16.428 +                                    &data->surface.pitch) < 0) {
  16.429 +        return -1;
  16.430 +    }
  16.431 +
  16.432 +    data->surface.clip_rect.w = data->surface.w = rect.w;
  16.433 +    data->surface.clip_rect.h = data->surface.h = rect.h;
  16.434 +
  16.435 +    /* Draw the points! */
  16.436 +    if (renderer->blendMode == SDL_BLENDMODE_NONE) {
  16.437 +        Uint32 color = SDL_MapRGBA(data->surface.format,
  16.438 +                                   renderer->r, renderer->g, renderer->b,
  16.439 +                                   renderer->a);
  16.440 +
  16.441 +        for (i = 0; i < count; ++i) {
  16.442 +            x = points[i].x - rect.x;
  16.443 +            y = points[i].y - rect.y;
  16.444 +
  16.445 +            status = SDL_DrawPoint(&data->surface, x, y, color);
  16.446 +        }
  16.447 +    } else {
  16.448 +        for (i = 0; i < count; ++i) {
  16.449 +            x = points[i].x - rect.x;
  16.450 +            y = points[i].y - rect.y;
  16.451 +
  16.452 +            status = SDL_BlendPoint(&data->surface, x, y,
  16.453 +                                    renderer->blendMode,
  16.454 +                                    renderer->r, renderer->g, renderer->b,
  16.455 +                                    renderer->a);
  16.456 +        }
  16.457 +    }
  16.458 +
  16.459 +    data->renderer->UnlockTexture(data->renderer, texture);
  16.460 +
  16.461 +    return status;
  16.462 +}
  16.463 +
  16.464 +static int
  16.465 +SW_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
  16.466 +                   int count)
  16.467 +{
  16.468 +    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
  16.469 +    SDL_Texture *texture = SW_ActivateRenderer(renderer);
  16.470 +    SDL_Rect clip, rect;
  16.471 +    int i;
  16.472 +    int x1, y1, x2, y2;
  16.473 +    int status = 0;
  16.474 +
  16.475 +    if (!texture) {
  16.476 +        return -1;
  16.477 +    }
  16.478 +
  16.479 +    /* Get the smallest rectangle that contains everything */
  16.480 +    clip.x = 0;
  16.481 +    clip.y = 0;
  16.482 +    clip.w = texture->w;
  16.483 +    clip.h = texture->h;
  16.484 +    SDL_EnclosePoints(points, count, NULL, &rect);
  16.485 +    if (!SDL_IntersectRect(&rect, &clip, &rect)) {
  16.486 +        /* Nothing to draw */
  16.487 +        return 0;
  16.488 +    }
  16.489 +
  16.490 +    if (data->renderer->LockTexture(data->renderer, texture, &rect, 1,
  16.491 +                                    &data->surface.pixels,
  16.492 +                                    &data->surface.pitch) < 0) {
  16.493 +        return -1;
  16.494 +    }
  16.495 +
  16.496 +    data->surface.clip_rect.w = data->surface.w = rect.w;
  16.497 +    data->surface.clip_rect.h = data->surface.h = rect.h;
  16.498 +
  16.499 +    /* Draw the points! */
  16.500 +    if (renderer->blendMode == SDL_BLENDMODE_NONE) {
  16.501 +        Uint32 color = SDL_MapRGBA(data->surface.format,
  16.502 +                                   renderer->r, renderer->g, renderer->b,
  16.503 +                                   renderer->a);
  16.504 +
  16.505 +        for (i = 1; i < count; ++i) {
  16.506 +            x1 = points[i-1].x - rect.x;
  16.507 +            y1 = points[i-1].y - rect.y;
  16.508 +            x2 = points[i].x - rect.x;
  16.509 +            y2 = points[i].y - rect.y;
  16.510 +
  16.511 +            status = SDL_DrawLine(&data->surface, x1, y1, x2, y2, color);
  16.512 +        }
  16.513 +    } else {
  16.514 +        for (i = 1; i < count; ++i) {
  16.515 +            x1 = points[i-1].x - rect.x;
  16.516 +            y1 = points[i-1].y - rect.y;
  16.517 +            x2 = points[i].x - rect.x;
  16.518 +            y2 = points[i].y - rect.y;
  16.519 +
  16.520 +            status = SDL_BlendLine(&data->surface, x1, y1, x2, y2,
  16.521 +                                   renderer->blendMode,
  16.522 +                                   renderer->r, renderer->g, renderer->b,
  16.523 +                                   renderer->a);
  16.524 +        }
  16.525 +    }
  16.526 +
  16.527 +    data->renderer->UnlockTexture(data->renderer, texture);
  16.528 +
  16.529 +    return status;
  16.530 +}
  16.531 +
  16.532 +static int
  16.533 +SW_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
  16.534 +                   int count)
  16.535 +{
  16.536 +    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
  16.537 +    SDL_Texture *texture = SW_ActivateRenderer(renderer);
  16.538 +    SDL_Rect clip, rect;
  16.539 +    Uint32 color = 0;
  16.540 +    int i;
  16.541 +    int status = 0;
  16.542 +
  16.543 +    if (!texture) {
  16.544 +        return -1;
  16.545 +    }
  16.546 +
  16.547 +    clip.x = 0;
  16.548 +    clip.y = 0;
  16.549 +    clip.w = texture->w;
  16.550 +    clip.h = texture->h;
  16.551 +
  16.552 +    if (renderer->blendMode == SDL_BLENDMODE_NONE) {
  16.553 +        color = SDL_MapRGBA(data->surface.format,
  16.554 +                            renderer->r, renderer->g, renderer->b,
  16.555 +                            renderer->a);
  16.556 +    }
  16.557 +
  16.558 +    for (i = 0; i < count; ++i) {
  16.559 +        if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
  16.560 +            /* Nothing to draw */
  16.561 +            continue;
  16.562 +        }
  16.563 +
  16.564 +        if (data->renderer->LockTexture(data->renderer, texture, &rect, 1,
  16.565 +                                        &data->surface.pixels,
  16.566 +                                        &data->surface.pitch) < 0) {
  16.567 +            return -1;
  16.568 +        }
  16.569 +
  16.570 +        data->surface.clip_rect.w = data->surface.w = rect.w;
  16.571 +        data->surface.clip_rect.h = data->surface.h = rect.h;
  16.572 +
  16.573 +        if (renderer->blendMode == SDL_BLENDMODE_NONE) {
  16.574 +            status = SDL_FillRect(&data->surface, NULL, color);
  16.575 +        } else {
  16.576 +            status = SDL_BlendFillRect(&data->surface, NULL,
  16.577 +                                       renderer->blendMode,
  16.578 +                                       renderer->r, renderer->g, renderer->b,
  16.579 +                                       renderer->a);
  16.580 +        }
  16.581 +
  16.582 +        data->renderer->UnlockTexture(data->renderer, texture);
  16.583 +    }
  16.584 +    return status;
  16.585 +}
  16.586 +
  16.587 +static int
  16.588 +SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
  16.589 +              const SDL_Rect * srcrect, const SDL_Rect * dstrect)
  16.590 +{
  16.591 +    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
  16.592 +    int status;
  16.593 +
  16.594 +    if (!SW_ActivateRenderer(renderer)) {
  16.595 +        return -1;
  16.596 +    }
  16.597 +
  16.598 +    if (data->renderer->LockTexture(data->renderer, data->texture,
  16.599 +                                    dstrect, 1, &data->surface.pixels,
  16.600 +                                    &data->surface.pitch) < 0) {
  16.601 +        return -1;
  16.602 +    }
  16.603 +
  16.604 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  16.605 +        status =
  16.606 +            SDL_SW_CopyYUVToRGB((SDL_SW_YUVTexture *) texture->driverdata,
  16.607 +                                srcrect, data->format, dstrect->w, dstrect->h,
  16.608 +                                data->surface.pixels, data->surface.pitch);
  16.609 +    } else {
  16.610 +        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  16.611 +        SDL_Rect real_srcrect = *srcrect;
  16.612 +        SDL_Rect real_dstrect;
  16.613 +
  16.614 +        data->surface.w = dstrect->w;
  16.615 +        data->surface.h = dstrect->h;
  16.616 +        data->surface.clip_rect.w = dstrect->w;
  16.617 +        data->surface.clip_rect.h = dstrect->h;
  16.618 +        real_dstrect = data->surface.clip_rect;
  16.619 +
  16.620 +        status =
  16.621 +            SDL_LowerBlit(surface, &real_srcrect, &data->surface,
  16.622 +                          &real_dstrect);
  16.623 +    }
  16.624 +    data->renderer->UnlockTexture(data->renderer, data->texture);
  16.625 +    return status;
  16.626 +}
  16.627 +
  16.628 +static int
  16.629 +SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
  16.630 +                    Uint32 format, void * pixels, int pitch)
  16.631 +{
  16.632 +    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
  16.633 +
  16.634 +    if (!SW_ActivateRenderer(renderer)) {
  16.635 +        return -1;
  16.636 +    }
  16.637 +
  16.638 +    if (data->renderer->LockTexture(data->renderer, data->texture,
  16.639 +                                    rect, 0, &data->surface.pixels,
  16.640 +                                    &data->surface.pitch) < 0) {
  16.641 +        return -1;
  16.642 +    }
  16.643 +
  16.644 +    SDL_ConvertPixels(rect->w, rect->h,
  16.645 +                      data->format, data->surface.pixels, data->surface.pitch,
  16.646 +                      format, pixels, pitch);
  16.647 +
  16.648 +    data->renderer->UnlockTexture(data->renderer, data->texture);
  16.649 +    return 0;
  16.650 +}
  16.651 +
  16.652 +static int
  16.653 +SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
  16.654 +                     Uint32 format, const void * pixels, int pitch)
  16.655 +{
  16.656 +    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
  16.657 +
  16.658 +    if (!SW_ActivateRenderer(renderer)) {
  16.659 +        return -1;
  16.660 +    }
  16.661 +
  16.662 +    if (data->renderer->LockTexture(data->renderer, data->texture,
  16.663 +                                    rect, 1, &data->surface.pixels,
  16.664 +                                    &data->surface.pitch) < 0) {
  16.665 +        return -1;
  16.666 +    }
  16.667 +
  16.668 +    SDL_ConvertPixels(rect->w, rect->h, format, pixels, pitch,
  16.669 +                      data->format, data->surface.pixels, data->surface.pitch);
  16.670 +
  16.671 +    data->renderer->UnlockTexture(data->renderer, data->texture);
  16.672 +    return 0;
  16.673 +}
  16.674 +
  16.675 +static void
  16.676 +SW_RenderPresent(SDL_Renderer * renderer)
  16.677 +{
  16.678 +    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
  16.679 +    SDL_Texture *texture = SW_ActivateRenderer(renderer);
  16.680 +    SDL_Rect rect;
  16.681 +
  16.682 +    if (!texture) {
  16.683 +        return;
  16.684 +    }
  16.685 +
  16.686 +    /* Send the data to the display */
  16.687 +    rect.x = 0;
  16.688 +    rect.y = 0;
  16.689 +    rect.w = texture->w;
  16.690 +    rect.h = texture->h;
  16.691 +    data->renderer->RenderCopy(data->renderer, texture, &rect, &rect);
  16.692 +    data->renderer->RenderPresent(data->renderer);
  16.693 +}
  16.694 +
  16.695 +static void
  16.696 +SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  16.697 +{
  16.698 +    if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) {
  16.699 +        SDL_SW_DestroyYUVTexture((SDL_SW_YUVTexture *) texture->driverdata);
  16.700 +    } else {
  16.701 +        SDL_Surface *surface = (SDL_Surface *) texture->driverdata;
  16.702 +
  16.703 +        SDL_FreeSurface(surface);
  16.704 +    }
  16.705 +}
  16.706 +
  16.707 +static void
  16.708 +SW_DestroyRenderer(SDL_Renderer * renderer)
  16.709 +{
  16.710 +    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
  16.711 +    SDL_Window *window = renderer->window;
  16.712 +
  16.713 +    if (data) {
  16.714 +        if (data->texture) {
  16.715 +            DestroyTexture(data->renderer, data->texture);
  16.716 +        }
  16.717 +        if (data->surface.format) {
  16.718 +            SDL_FreeFormat(data->surface.format);
  16.719 +        }
  16.720 +        if (data->renderer) {
  16.721 +            data->renderer->DestroyRenderer(data->renderer);
  16.722 +        }
  16.723 +        SDL_FreeDirtyRects(&data->dirty);
  16.724 +        SDL_free(data);
  16.725 +    }
  16.726 +    SDL_free(renderer);
  16.727 +}
  16.728 +
  16.729 +/* vi: set ts=4 sw=4 expandtab: */
    17.1 --- a/src/video/SDL_pixels_c.h	Wed Feb 02 14:34:24 2011 -0800
    17.2 +++ b/src/video/SDL_pixels_c.h	Wed Feb 02 14:34:54 2011 -0800
    17.3 @@ -47,4 +47,5 @@
    17.4  extern Uint8 SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b);
    17.5  extern void SDL_ApplyGamma(Uint16 * gamma, SDL_Color * colors,
    17.6                             SDL_Color * output, int ncolors);
    17.7 +
    17.8  /* vi: set ts=4 sw=4 expandtab: */
    18.1 --- a/src/video/SDL_rect.c	Wed Feb 02 14:34:24 2011 -0800
    18.2 +++ b/src/video/SDL_rect.c	Wed Feb 02 14:34:54 2011 -0800
    18.3 @@ -21,8 +21,7 @@
    18.4  */
    18.5  #include "SDL_config.h"
    18.6  
    18.7 -#include "SDL_video.h"
    18.8 -#include "SDL_rect_c.h"
    18.9 +#include "SDL_rect.h"
   18.10  
   18.11  SDL_bool
   18.12  SDL_HasIntersection(const SDL_Rect * A, const SDL_Rect * B)
    19.1 --- a/src/video/SDL_rect_c.h	Wed Feb 02 14:34:24 2011 -0800
    19.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.3 @@ -1,40 +0,0 @@
    19.4 -/*
    19.5 -    SDL - Simple DirectMedia Layer
    19.6 -    Copyright (C) 1997-2010 Sam Lantinga
    19.7 -
    19.8 -    This library is free software; you can redistribute it and/or
    19.9 -    modify it under the terms of the GNU Lesser General Public
   19.10 -    License as published by the Free Software Foundation; either
   19.11 -    version 2.1 of the License, or (at your option) any later version.
   19.12 -
   19.13 -    This library is distributed in the hope that it will be useful,
   19.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   19.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   19.16 -    Lesser General Public License for more details.
   19.17 -
   19.18 -    You should have received a copy of the GNU Lesser General Public
   19.19 -    License along with this library; if not, write to the Free Software
   19.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   19.21 -
   19.22 -    Sam Lantinga
   19.23 -    slouken@libsdl.org
   19.24 -*/
   19.25 -#include "SDL_config.h"
   19.26 -
   19.27 -typedef struct SDL_DirtyRect
   19.28 -{
   19.29 -    SDL_Rect rect;
   19.30 -    struct SDL_DirtyRect *next;
   19.31 -} SDL_DirtyRect;
   19.32 -
   19.33 -typedef struct SDL_DirtyRectList
   19.34 -{
   19.35 -    SDL_DirtyRect *list;
   19.36 -    SDL_DirtyRect *free;
   19.37 -} SDL_DirtyRectList;
   19.38 -
   19.39 -extern void SDL_AddDirtyRect(SDL_DirtyRectList * list, const SDL_Rect * rect);
   19.40 -extern void SDL_ClearDirtyRects(SDL_DirtyRectList * list);
   19.41 -extern void SDL_FreeDirtyRects(SDL_DirtyRectList * list);
   19.42 -
   19.43 -/* vi: set ts=4 sw=4 expandtab: */
    20.1 --- a/src/video/SDL_renderer_gl.c	Wed Feb 02 14:34:24 2011 -0800
    20.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.3 @@ -1,1285 +0,0 @@
    20.4 -/*
    20.5 -    SDL - Simple DirectMedia Layer
    20.6 -    Copyright (C) 1997-2010 Sam Lantinga
    20.7 -
    20.8 -    This library is free software; you can redistribute it and/or
    20.9 -    modify it under the terms of the GNU Lesser General Public
   20.10 -    License as published by the Free Software Foundation; either
   20.11 -    version 2.1 of the License, or (at your option) any later version.
   20.12 -
   20.13 -    This library is distributed in the hope that it will be useful,
   20.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
   20.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   20.16 -    Lesser General Public License for more details.
   20.17 -
   20.18 -    You should have received a copy of the GNU Lesser General Public
   20.19 -    License along with this library; if not, write to the Free Software
   20.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
   20.21 -
   20.22 -    Sam Lantinga
   20.23 -    slouken@libsdl.org
   20.24 -*/
   20.25 -#include "SDL_config.h"
   20.26 -
   20.27 -#if SDL_VIDEO_RENDER_OGL
   20.28 -
   20.29 -#include "SDL_video.h"
   20.30 -#include "SDL_opengl.h"
   20.31 -#include "SDL_sysvideo.h"
   20.32 -#include "SDL_pixels_c.h"
   20.33 -#include "SDL_rect_c.h"
   20.34 -#include "SDL_yuv_sw_c.h"
   20.35 -
   20.36 -#ifdef __MACOSX__
   20.37 -#include <OpenGL/OpenGL.h>
   20.38 -#endif
   20.39 -
   20.40 -
   20.41 -/* OpenGL renderer implementation */
   20.42 -
   20.43 -/* Details on optimizing the texture path on Mac OS X:
   20.44 -   http://developer.apple.com/documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/chapter_10_section_2.html
   20.45 -*/
   20.46 -
   20.47 -/* !!! FIXME: this should go in a higher level than the GL renderer. */
   20.48 -static __inline__ int
   20.49 -bytes_per_pixel(const Uint32 format)
   20.50 -{
   20.51 -    if (!SDL_ISPIXELFORMAT_FOURCC(format)) {
   20.52 -        return SDL_BYTESPERPIXEL(format);
   20.53 -    }
   20.54 -
   20.55 -    /* FOURCC format */
   20.56 -    switch (format) {
   20.57 -    case SDL_PIXELFORMAT_YV12:
   20.58 -    case SDL_PIXELFORMAT_IYUV:
   20.59 -    case SDL_PIXELFORMAT_YUY2:
   20.60 -    case SDL_PIXELFORMAT_UYVY:
   20.61 -    case SDL_PIXELFORMAT_YVYU:
   20.62 -        return 2;
   20.63 -    default:
   20.64 -        return 1;               /* shouldn't ever hit this. */
   20.65 -    }
   20.66 -}
   20.67 -
   20.68 -
   20.69 -static const float inv255f = 1.0f / 255.0f;
   20.70 -
   20.71 -static SDL_Renderer *GL_CreateRenderer(SDL_Window * window, Uint32 flags);
   20.72 -static void GL_WindowEvent(SDL_Renderer * renderer,
   20.73 -                           const SDL_WindowEvent *event);
   20.74 -static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture);
   20.75 -static int GL_QueryTexturePixels(SDL_Renderer * renderer,
   20.76 -                                 SDL_Texture * texture, void **pixels,
   20.77 -                                 int *pitch);
   20.78 -static int GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   20.79 -                            const SDL_Rect * rect, const void *pixels,
   20.80 -                            int pitch);
   20.81 -static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   20.82 -                          const SDL_Rect * rect, int markDirty, void **pixels,
   20.83 -                          int *pitch);
   20.84 -static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
   20.85 -static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture,
   20.86 -                            int numrects, const SDL_Rect * rects);
   20.87 -static int GL_RenderClear(SDL_Renderer * renderer);
   20.88 -static int GL_RenderDrawPoints(SDL_Renderer * renderer,
   20.89 -                               const SDL_Point * points, int count);
   20.90 -static int GL_RenderDrawLines(SDL_Renderer * renderer,
   20.91 -                              const SDL_Point * points, int count);
   20.92 -static int GL_RenderFillRects(SDL_Renderer * renderer,
   20.93 -                              const SDL_Rect ** rects, int count);
   20.94 -static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
   20.95 -                         const SDL_Rect * srcrect, const SDL_Rect * dstrect);
   20.96 -static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   20.97 -                               Uint32 pixel_format, void * pixels, int pitch);
   20.98 -static int GL_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
   20.99 -                                Uint32 pixel_format, const void * pixels, int pitch);
  20.100 -static void GL_RenderPresent(SDL_Renderer * renderer);
  20.101 -static void GL_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture);
  20.102 -static void GL_DestroyRenderer(SDL_Renderer * renderer);
  20.103 -
  20.104 -
  20.105 -SDL_RenderDriver GL_RenderDriver = {
  20.106 -    GL_CreateRenderer,
  20.107 -    {
  20.108 -     "opengl",
  20.109 -     (SDL_RENDERER_PRESENTVSYNC | SDL_RENDERER_ACCELERATED),
  20.110 -     13,
  20.111 -     {
  20.112 -      SDL_PIXELFORMAT_RGB332,
  20.113 -      SDL_PIXELFORMAT_RGB444,
  20.114 -      SDL_PIXELFORMAT_RGB555,
  20.115 -      SDL_PIXELFORMAT_ARGB4444,
  20.116 -      SDL_PIXELFORMAT_ARGB1555,
  20.117 -      SDL_PIXELFORMAT_RGB565,
  20.118 -      SDL_PIXELFORMAT_RGB24,
  20.119 -      SDL_PIXELFORMAT_BGR24,
  20.120 -      SDL_PIXELFORMAT_RGB888,
  20.121 -      SDL_PIXELFORMAT_BGR888,
  20.122 -      SDL_PIXELFORMAT_ARGB8888,
  20.123 -      SDL_PIXELFORMAT_ABGR8888,
  20.124 -      SDL_PIXELFORMAT_ARGB2101010},
  20.125 -     0,
  20.126 -     0}
  20.127 -};
  20.128 -
  20.129 -typedef struct
  20.130 -{
  20.131 -    SDL_GLContext context;
  20.132 -    SDL_bool updateSize;
  20.133 -    SDL_bool GL_ARB_texture_rectangle_supported;
  20.134 -    SDL_bool GL_EXT_paletted_texture_supported;
  20.135 -    SDL_bool GL_APPLE_ycbcr_422_supported;
  20.136 -    SDL_bool GL_MESA_ycbcr_texture_supported;
  20.137 -    SDL_bool GL_ARB_fragment_program_supported;
  20.138 -    int blendMode;
  20.139 -
  20.140 -    /* OpenGL functions */
  20.141 -#define SDL_PROC(ret,func,params) ret (APIENTRY *func) params;
  20.142 -#include "SDL_glfuncs.h"
  20.143 -#undef SDL_PROC
  20.144 -
  20.145 -    void (*glTextureRangeAPPLE) (GLenum target, GLsizei length,
  20.146 -                                 const GLvoid * pointer);
  20.147 -
  20.148 -    PFNGLGETPROGRAMIVARBPROC glGetProgramivARB;
  20.149 -    PFNGLGETPROGRAMSTRINGARBPROC glGetProgramStringARB;
  20.150 -    PFNGLPROGRAMLOCALPARAMETER4FVARBPROC glProgramLocalParameter4fvARB;
  20.151 -    PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB;
  20.152 -    PFNGLGENPROGRAMSARBPROC glGenProgramsARB;
  20.153 -    PFNGLBINDPROGRAMARBPROC glBindProgramARB;
  20.154 -    PFNGLPROGRAMSTRINGARBPROC glProgramStringARB;
  20.155 -
  20.156 -    /* (optional) fragment programs */
  20.157 -    GLuint fragment_program_UYVY;
  20.158 -} GL_RenderData;
  20.159 -
  20.160 -typedef struct
  20.161 -{
  20.162 -    GLuint texture;
  20.163 -    GLuint shader;
  20.164 -    GLenum type;
  20.165 -    GLfloat texw;
  20.166 -    GLfloat texh;
  20.167 -    GLenum format;
  20.168 -    GLenum formattype;
  20.169 -    Uint8 *palette;
  20.170 -    void *pixels;
  20.171 -    int pitch;
  20.172 -    SDL_DirtyRectList dirty;
  20.173 -    int HACK_RYAN_FIXME;
  20.174 -} GL_TextureData;
  20.175 -
  20.176 -
  20.177 -static void
  20.178 -GL_SetError(const char *prefix, GLenum result)
  20.179 -{
  20.180 -    const char *error;
  20.181 -
  20.182 -    switch (result) {
  20.183 -    case GL_NO_ERROR:
  20.184 -        error = "GL_NO_ERROR";
  20.185 -        break;
  20.186 -    case GL_INVALID_ENUM:
  20.187 -        error = "GL_INVALID_ENUM";
  20.188 -        break;
  20.189 -    case GL_INVALID_VALUE:
  20.190 -        error = "GL_INVALID_VALUE";
  20.191 -        break;
  20.192 -    case GL_INVALID_OPERATION:
  20.193 -        error = "GL_INVALID_OPERATION";
  20.194 -        break;
  20.195 -    case GL_STACK_OVERFLOW:
  20.196 -        error = "GL_STACK_OVERFLOW";
  20.197 -        break;
  20.198 -    case GL_STACK_UNDERFLOW:
  20.199 -        error = "GL_STACK_UNDERFLOW";
  20.200 -        break;
  20.201 -    case GL_OUT_OF_MEMORY:
  20.202 -        error = "GL_OUT_OF_MEMORY";
  20.203 -        break;
  20.204 -    case GL_TABLE_TOO_LARGE:
  20.205 -        error = "GL_TABLE_TOO_LARGE";
  20.206 -        break;
  20.207 -    default:
  20.208 -        error = "UNKNOWN";
  20.209 -        break;
  20.210 -    }
  20.211 -    SDL_SetError("%s: %s", prefix, error);
  20.212 -}
  20.213 -
  20.214 -static int
  20.215 -GL_LoadFunctions(GL_RenderData * data)
  20.216 -{
  20.217 -#ifdef __SDL_NOGETPROCADDR__
  20.218 -#define SDL_PROC(ret,func,params) data->func=func;
  20.219 -#else
  20.220 -#define SDL_PROC(ret,func,params) \
  20.221 -    do { \
  20.222 -        data->func = SDL_GL_GetProcAddress(#func); \
  20.223 -        if ( ! data->func ) { \
  20.224 -            SDL_SetError("Couldn't load GL function %s: %s\n", #func, SDL_GetError()); \
  20.225 -            return -1; \
  20.226 -        } \
  20.227 -    } while ( 0 );
  20.228 -#endif /* __SDL_NOGETPROCADDR__ */
  20.229 -
  20.230 -#include "SDL_glfuncs.h"
  20.231 -#undef SDL_PROC
  20.232 -    return 0;
  20.233 -}
  20.234 -
  20.235 -SDL_Renderer *
  20.236 -GL_CreateRenderer(SDL_Window * window, Uint32 flags)
  20.237 -{
  20.238 -    SDL_Renderer *renderer;
  20.239 -    GL_RenderData *data;
  20.240 -    GLint value;
  20.241 -
  20.242 -    /* Render directly to the window, unless we're compositing */
  20.243 -#ifndef __MACOSX__
  20.244 -    if (flags & SDL_RENDERER_SINGLEBUFFER) {
  20.245 -        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
  20.246 -    }
  20.247 -#endif
  20.248 -    if (!(window->flags & SDL_WINDOW_OPENGL)) {
  20.249 -        if (SDL_RecreateWindow(window, window->flags | SDL_WINDOW_OPENGL) < 0) {
  20.250 -            return NULL;
  20.251 -        }
  20.252 -    }
  20.253 -
  20.254 -    renderer = (SDL_Renderer *) SDL_calloc(1, sizeof(*renderer));
  20.255 -    if (!renderer) {
  20.256 -        SDL_OutOfMemory();
  20.257 -        return NULL;
  20.258 -    }
  20.259 -
  20.260 -    data = (GL_RenderData *) SDL_calloc(1, sizeof(*data));
  20.261 -    if (!data) {
  20.262 -        GL_DestroyRenderer(renderer);
  20.263 -        SDL_OutOfMemory();
  20.264 -        return NULL;
  20.265 -    }
  20.266 -
  20.267 -    renderer->WindowEvent = GL_WindowEvent;
  20.268 -    renderer->CreateTexture = GL_CreateTexture;
  20.269 -    renderer->QueryTexturePixels = GL_QueryTexturePixels;
  20.270 -    renderer->UpdateTexture = GL_UpdateTexture;
  20.271 -    renderer->LockTexture = GL_LockTexture;
  20.272 -    renderer->UnlockTexture = GL_UnlockTexture;
  20.273 -    renderer->DirtyTexture = GL_DirtyTexture;
  20.274 -    renderer->RenderClear = GL_RenderClear;
  20.275 -    renderer->RenderDrawPoints = GL_RenderDrawPoints;
  20.276 -    renderer->RenderDrawLines = GL_RenderDrawLines;
  20.277 -    renderer->RenderFillRects = GL_RenderFillRects;
  20.278 -    renderer->RenderCopy = GL_RenderCopy;
  20.279 -    renderer->RenderReadPixels = GL_RenderReadPixels;
  20.280 -    renderer->RenderWritePixels = GL_RenderWritePixels;
  20.281 -    renderer->RenderPresent = GL_RenderPresent;
  20.282 -    renderer->DestroyTexture = GL_DestroyTexture;
  20.283 -    renderer->DestroyRenderer = GL_DestroyRenderer;
  20.284 -    renderer->info = GL_RenderDriver.info;
  20.285 -    renderer->window = window;
  20.286 -    renderer->driverdata = data;
  20.287 -
  20.288 -    renderer->info.flags = SDL_RENDERER_ACCELERATED;
  20.289 -
  20.290 -    if (GL_LoadFunctions(data) < 0) {
  20.291 -        GL_DestroyRenderer(renderer);
  20.292 -        return NULL;
  20.293 -    }
  20.294 -
  20.295 -    data->context = SDL_GL_CreateContext(window);
  20.296 -    if (!data->context) {
  20.297 -        GL_DestroyRenderer(renderer);
  20.298 -        return NULL;
  20.299 -    }
  20.300 -    if (SDL_GL_MakeCurrent(window, data->context) < 0) {
  20.301 -        GL_DestroyRenderer(renderer);
  20.302 -        return NULL;
  20.303 -    }
  20.304 -#ifdef __MACOSX__
  20.305 -    /* Enable multi-threaded rendering */
  20.306 -    /* Disabled until Ryan finishes his VBO/PBO code...
  20.307 -       CGLEnable(CGLGetCurrentContext(), kCGLCEMPEngine);
  20.308 -     */
  20.309 -#endif
  20.310 -
  20.311 -    if (flags & SDL_RENDERER_PRESENTVSYNC) {
  20.312 -        SDL_GL_SetSwapInterval(1);
  20.313 -    } else {
  20.314 -        SDL_GL_SetSwapInterval(0);
  20.315 -    }
  20.316 -    if (SDL_GL_GetSwapInterval() > 0) {
  20.317 -        renderer->info.flags |= SDL_RENDERER_PRESENTVSYNC;
  20.318 -    }
  20.319 -
  20.320 -    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
  20.321 -    renderer->info.max_texture_width = value;
  20.322 -    data->glGetIntegerv(GL_MAX_TEXTURE_SIZE, &value);
  20.323 -    renderer->info.max_texture_height = value;
  20.324 -
  20.325 -    if (SDL_GL_ExtensionSupported("GL_ARB_texture_rectangle")
  20.326 -        || SDL_GL_ExtensionSupported("GL_EXT_texture_rectangle")) {
  20.327 -        data->GL_ARB_texture_rectangle_supported = SDL_TRUE;
  20.328 -    }
  20.329 -    if (SDL_GL_ExtensionSupported("GL_APPLE_ycbcr_422")) {
  20.330 -        data->GL_APPLE_ycbcr_422_supported = SDL_TRUE;
  20.331 -    }
  20.332 -    if (SDL_GL_ExtensionSupported("GL_MESA_ycbcr_texture")) {
  20.333 -        data->GL_MESA_ycbcr_texture_supported = SDL_TRUE;
  20.334 -    }
  20.335 -    if (SDL_GL_ExtensionSupported("GL_APPLE_texture_range")) {
  20.336 -        data->glTextureRangeAPPLE =
  20.337 -            (void (*)(GLenum, GLsizei, const GLvoid *))
  20.338 -            SDL_GL_GetProcAddress("glTextureRangeAPPLE");
  20.339 -    }
  20.340 -
  20.341 -    /* we might use fragment programs for YUV data, etc. */
  20.342 -    if (SDL_GL_ExtensionSupported("GL_ARB_fragment_program")) {
  20.343 -        /* !!! FIXME: this doesn't check for errors. */
  20.344 -        /* !!! FIXME: this should really reuse the glfuncs.h stuff. */
  20.345 -        data->glGetProgramivARB = (PFNGLGETPROGRAMIVARBPROC)
  20.346 -            SDL_GL_GetProcAddress("glGetProgramivARB");
  20.347 -        data->glGetProgramStringARB = (PFNGLGETPROGRAMSTRINGARBPROC)
  20.348 -            SDL_GL_GetProcAddress("glGetProgramStringARB");
  20.349 -        data->glProgramLocalParameter4fvARB =
  20.350 -            (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC)
  20.351 -            SDL_GL_GetProcAddress("glProgramLocalParameter4fvARB");
  20.352 -        data->glDeleteProgramsARB = (PFNGLDELETEPROGRAMSARBPROC)
  20.353 -            SDL_GL_GetProcAddress("glDeleteProgramsARB");
  20.354 -        data->glGenProgramsARB = (PFNGLGENPROGRAMSARBPROC)
  20.355 -            SDL_GL_GetProcAddress("glGenProgramsARB");
  20.356 -        data->glBindProgramARB = (PFNGLBINDPROGRAMARBPROC)
  20.357 -            SDL_GL_GetProcAddress("glBindProgramARB");
  20.358 -        data->glProgramStringARB = (PFNGLPROGRAMSTRINGARBPROC)
  20.359 -            SDL_GL_GetProcAddress("glProgramStringARB");
  20.360 -        data->GL_ARB_fragment_program_supported = SDL_TRUE;
  20.361 -    }
  20.362 -
  20.363 -    /* Set up parameters for rendering */
  20.364 -    data->blendMode = -1;
  20.365 -    data->glDisable(GL_DEPTH_TEST);
  20.366 -    data->glDisable(GL_CULL_FACE);
  20.367 -    /* This ended up causing video discrepancies between OpenGL and Direct3D */
  20.368 -    /*data->glEnable(GL_LINE_SMOOTH);*/
  20.369 -    if (data->GL_ARB_texture_rectangle_supported) {
  20.370 -        data->glEnable(GL_TEXTURE_RECTANGLE_ARB);
  20.371 -    } else {
  20.372 -        data->glEnable(GL_TEXTURE_2D);
  20.373 -    }
  20.374 -    data->updateSize = SDL_TRUE;
  20.375 -
  20.376 -    return renderer;
  20.377 -}
  20.378 -
  20.379 -static SDL_GLContext SDL_CurrentContext = NULL;
  20.380 -
  20.381 -static int
  20.382 -GL_ActivateRenderer(SDL_Renderer * renderer)
  20.383 -{
  20.384 -    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
  20.385 -    SDL_Window *window = renderer->window;
  20.386 -
  20.387 -    if (SDL_CurrentContext != data->context) {
  20.388 -        if (SDL_GL_MakeCurrent(window, data->context) < 0) {
  20.389 -            return -1;
  20.390 -        }
  20.391 -        SDL_CurrentContext = data->context;
  20.392 -    }
  20.393 -    if (data->updateSize) {
  20.394 -        data->glMatrixMode(GL_PROJECTION);
  20.395 -        data->glLoadIdentity();
  20.396 -        data->glMatrixMode(GL_MODELVIEW);
  20.397 -        data->glLoadIdentity();
  20.398 -        data->glViewport(0, 0, window->w, window->h);
  20.399 -        data->glOrtho(0.0, (GLdouble) window->w,
  20.400 -                      (GLdouble) window->h, 0.0, 0.0, 1.0);
  20.401 -        data->updateSize = SDL_FALSE;
  20.402 -    }
  20.403 -    return 0;
  20.404 -}
  20.405 -
  20.406 -static void
  20.407 -GL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
  20.408 -{
  20.409 -    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
  20.410 -
  20.411 -    if (event->event == SDL_WINDOWEVENT_RESIZED) {
  20.412 -        /* Rebind the context to the window area and update matrices */
  20.413 -        SDL_CurrentContext = NULL;
  20.414 -        data->updateSize = SDL_TRUE;
  20.415 -    }
  20.416 -}
  20.417 -
  20.418 -static __inline__ int
  20.419 -power_of_2(int input)
  20.420 -{
  20.421 -    int value = 1;
  20.422 -
  20.423 -    while (value < input) {
  20.424 -        value <<= 1;
  20.425 -    }
  20.426 -    return value;
  20.427 -}
  20.428 -
  20.429 -
  20.430 -//#define DEBUG_PROGRAM_COMPILE 1
  20.431 -
  20.432 -static void
  20.433 -set_shader_error(GL_RenderData * data, const char *prefix)
  20.434 -{
  20.435 -    GLint pos = 0;
  20.436 -    const GLubyte *errstr;
  20.437 -    data->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
  20.438 -    errstr = data->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
  20.439 -    SDL_SetError("%s: shader compile error at position %d: %s",
  20.440 -           prefix, (int) pos, (const char *) errstr);
  20.441 -}
  20.442 -
  20.443 -static GLuint
  20.444 -compile_shader(GL_RenderData * data, GLenum shader_type, const char *_code)
  20.445 -{
  20.446 -    const int have_texture_rects = data->GL_ARB_texture_rectangle_supported;
  20.447 -    const char *replacement = have_texture_rects ? "RECT" : "2D";
  20.448 -    const size_t replacementlen = SDL_strlen(replacement);
  20.449 -    const char *token = "%TEXTURETARGET%";
  20.450 -    const size_t tokenlen = SDL_strlen(token);
  20.451 -    char *code = NULL;
  20.452 -    char *ptr = NULL;
  20.453 -    GLuint program = 0;
  20.454 -
  20.455 -    /*
  20.456 -     * The TEX instruction needs a different target depending on what we use.
  20.457 -     *  To handle this, we use "%TEXTURETARGET%" and replace the string before
  20.458 -     *  compiling the shader.
  20.459 -     */
  20.460 -    code = SDL_strdup(_code);
  20.461 -    if (code == NULL)
  20.462 -        return 0;
  20.463 -
  20.464 -    for (ptr = SDL_strstr(code, token); ptr; ptr = SDL_strstr(ptr + 1, token)) {
  20.465 -        SDL_memcpy(ptr, replacement, replacementlen);
  20.466 -        SDL_memmove(ptr + replacementlen, ptr + tokenlen,
  20.467 -                    SDL_strlen(ptr + tokenlen) + 1);
  20.468 -    }
  20.469 -
  20.470 -#if DEBUG_PROGRAM_COMPILE
  20.471 -    printf("compiling shader:\n%s\n\n", code);
  20.472 -#endif
  20.473 -
  20.474 -    data->glGetError();         /* flush any existing error state. */
  20.475 -    data->glGenProgramsARB(1, &program);
  20.476 -    data->glBindProgramARB(shader_type, program);
  20.477 -    data->glProgramStringARB(shader_type, GL_PROGRAM_FORMAT_ASCII_ARB,
  20.478 -                             (GLsizei)SDL_strlen(code), code);
  20.479 -
  20.480 -    SDL_free(code);
  20.481 -
  20.482 -    if (data->glGetError() == GL_INVALID_OPERATION) {
  20.483 -#if DEBUG_PROGRAM_COMPILE
  20.484 -        GLint pos = 0;
  20.485 -        const GLubyte *errstr;
  20.486 -        data->glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
  20.487 -        errstr = data->glGetString(GL_PROGRAM_ERROR_STRING_ARB);
  20.488 -        printf("program compile error at position %d: %s\n\n",
  20.489 -               (int) pos, (const char *) errstr);
  20.490 -#endif
  20.491 -        data->glBindProgramARB(shader_type, 0);
  20.492 -        data->glDeleteProgramsARB(1, &program);
  20.493 -        return 0;
  20.494 -    }
  20.495 -
  20.496 -    return program;
  20.497 -}
  20.498 -
  20.499 -
  20.500 -/*
  20.501 - * Fragment program that renders from UYVY textures.
  20.502 - * The UYVY to RGB equasion is:
  20.503 - *   R = 1.164(Y-16) + 1.596(Cr-128)
  20.504 - *   G = 1.164(Y-16) - 0.813(Cr-128) - 0.391(Cb-128)
  20.505 - *   B = 1.164(Y-16) + 2.018(Cb-128)
  20.506 - * Byte layout is Cb, Y1, Cr, Y2, stored in the R, G, B, A channels.
  20.507 - * 4 bytes == 2 pixels: Y1/Cb/Cr, Y2/Cb/Cr
  20.508 - *
  20.509 - * !!! FIXME: this ignores blendmodes, etc.
  20.510 - * !!! FIXME: this could be more efficient...use a dot product for green, etc.
  20.511 - */
  20.512 -static const char *fragment_program_UYVY_source_code = "!!ARBfp1.0\n"
  20.513 -    /* outputs... */
  20.514 -    "OUTPUT outcolor = result.color;\n"
  20.515 -    /* scratch registers... */
  20.516 -    "TEMP uyvy;\n" "TEMP luminance;\n" "TEMP work;\n"
  20.517 -    /* Halve the coordinates to grab the correct 32 bits for the fragment. */
  20.518 -    "MUL work, fragment.texcoord, { 0.5, 1.0, 1.0, 1.0 };\n"
  20.519 -    /* Sample the YUV texture. Cb, Y1, Cr, Y2, are stored in x, y, z, w. */
  20.520 -    "TEX uyvy, work, texture[0], %TEXTURETARGET%;\n"
  20.521 -    /* Do subtractions (128/255, 16/255, 128/255, 16/255) */
  20.522 -    "SUB uyvy, uyvy, { 0.501960784313726, 0.06274509803922, 0.501960784313726, 0.06274509803922 };\n"
  20.523 -    /* Choose the luminance component by texcoord. */
  20.524 -    /* !!! FIXME: laziness wins out for now... just average Y1 and Y2. */
  20.525 -    "ADD luminance, uyvy.yyyy, uyvy.wwww;\n"
  20.526 -    "MUL luminance, luminance, { 0.5, 0.5, 0.5, 0.5 };\n"
  20.527 -    /* Multiply luminance by its magic value. */
  20.528 -    "MUL luminance, luminance, { 1.164, 1.164, 1.164, 1.164 };\n"
  20.529 -    /* uyvy.xyzw becomes Cr/Cr/Cb/Cb, with multiplications. */
  20.530 -    "MUL uyvy, uyvy.zzxx, { 1.596, -0.813, 2.018, -0.391 };\n"
  20.531 -    /* Add luminance to Cr and Cb, store to RGB channels. */
  20.532 -    "ADD work.rgb, luminance, uyvy;\n"
  20.533 -    /* Do final addition for Green channel.  (!!! FIXME: this should be a DPH?) */
  20.534 -    "ADD work.g, work.g, uyvy.w;\n"
  20.535 -    /* Make sure alpha channel is fully opaque.  (!!! FIXME: blend modes!) */
  20.536 -    "MOV work.a, { 1.0 };\n"
  20.537 -    /* Store out the final fragment color... */
  20.538 -    "MOV outcolor, work;\n"
  20.539 -    /* ...and we're done! */
  20.540 -    "END\n";
  20.541 -
  20.542 -static __inline__ SDL_bool
  20.543 -convert_format(GL_RenderData *renderdata, Uint32 pixel_format,
  20.544 -               GLint* internalFormat, GLenum* format, GLenum* type)
  20.545 -{
  20.546 -    switch (pixel_format) {
  20.547 -    case SDL_PIXELFORMAT_RGB332:
  20.548 -        *internalFormat = GL_R3_G3_B2;
  20.549 -        *format = GL_RGB;
  20.550 -        *type = GL_UNSIGNED_BYTE_3_3_2;
  20.551 -        break;
  20.552 -    case SDL_PIXELFORMAT_RGB444:
  20.553 -        *internalFormat = GL_RGB4;
  20.554 -        *format = GL_RGB;
  20.555 -        *type = GL_UNSIGNED_SHORT_4_4_4_4;
  20.556 -        break;
  20.557 -    case SDL_PIXELFORMAT_RGB555:
  20.558 -        *internalFormat = GL_RGB5;
  20.559 -        *format = GL_RGB;
  20.560 -        *type = GL_UNSIGNED_SHORT_5_5_5_1;
  20.561 -        break;
  20.562 -    case SDL_PIXELFORMAT_ARGB4444:
  20.563 -        *internalFormat = GL_RGBA4;
  20.564 -        *format = GL_BGRA;
  20.565 -        *type = GL_UNSIGNED_SHORT_4_4_4_4_REV;
  20.566 -        break;
  20.567 -    case SDL_PIXELFORMAT_ARGB1555:
  20.568 -        *internalFormat = GL_RGB5_A1;
  20.569 -        *format = GL_BGRA;
  20.570 -        *type = GL_UNSIGNED_SHORT_1_5_5_5_REV;
  20.571 -        break;
  20.572 -    case SDL_PIXELFORMAT_RGB565:
  20.573 -        *internalFormat = GL_RGB8;
  20.574 -        *format = GL_RGB;
  20.575 -        *type = GL_UNSIGNED_SHORT_5_6_5;
  20.576 -        break;
  20.577 -    case SDL_PIXELFORMAT_RGB24:
  20.578 -        *internalFormat = GL_RGB8;
  20.579 -        *format = GL_RGB;
  20.580 -        *type = GL_UNSIGNED_BYTE;
  20.581 -        break;
  20.582 -    case SDL_PIXELFORMAT_RGB888:
  20.583 -        *internalFormat = GL_RGB8;
  20.584 -        *format = GL_BGRA;
  20.585 -        *type = GL_UNSIGNED_BYTE;
  20.586 -        break;
  20.587 -    case SDL_PIXELFORMAT_BGR24:
  20.588 -        *internalFormat = GL_RGB8;
  20.589 -        *format = GL_BGR;
  20.590 -        *type = GL_UNSIGNED_BYTE;
  20.591 -        break;
  20.592 -    case SDL_PIXELFORMAT_BGR888:
  20.593 -        *internalFormat = GL_RGB8;
  20.594 -        *format = GL_RGBA;
  20.595 -        *type = GL_UNSIGNED_BYTE;
  20.596 -        break;
  20.597 -    case SDL_PIXELFORMAT_ARGB8888:
  20.598 -#ifdef __MACOSX__
  20.599 -        *internalFormat = GL_RGBA;
  20.600 -        *format = GL_BGRA;
  20.601 -        *type = GL_UNSIGNED_INT_8_8_8_8_REV;
  20.602 -#else
  20.603 -        *internalFormat = GL_RGBA8;
  20.604 -        *format = GL_BGRA;
  20.605 -        *type = GL_UNSIGNED_BYTE;
  20.606 -#endif
  20.607 -        break;
  20.608 -    case SDL_PIXELFORMAT_ABGR8888:
  20.609 -        *internalFormat = GL_RGBA8;
  20.610 -        *format = GL_RGBA;
  20.611 -        *type = GL_UNSIGNED_BYTE;
  20.612 -        break;
  20.613 -    case SDL_PIXELFORMAT_ARGB2101010:
  20.614 -        *internalFormat = GL_RGB10_A2;
  20.615 -        *format = GL_BGRA;
  20.616 -        *type = GL_UNSIGNED_INT_2_10_10_10_REV;
  20.617 -        break;
  20.618 -    case SDL_PIXELFORMAT_UYVY:
  20.619 -        if (renderdata->GL_APPLE_ycbcr_422_supported) {
  20.620 -            *internalFormat = GL_RGB;
  20.621 -            *format = GL_YCBCR_422_APPLE;
  20.622 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  20.623 -            *type = GL_UNSIGNED_SHORT_8_8_APPLE;
  20.624 -#else
  20.625 -            *type = GL_UNSIGNED_SHORT_8_8_REV_APPLE;
  20.626 -#endif
  20.627 -        } else if (renderdata->GL_MESA_ycbcr_texture_supported) {
  20.628 -            *internalFormat = GL_YCBCR_MESA;
  20.629 -            *format = GL_YCBCR_MESA;
  20.630 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  20.631 -            *type = GL_UNSIGNED_SHORT_8_8_MESA;
  20.632 -#else
  20.633 -            *type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
  20.634 -#endif
  20.635 -        } else if (renderdata->GL_ARB_fragment_program_supported) {
  20.636 -            *internalFormat = GL_RGBA;
  20.637 -            *format = GL_RGBA;
  20.638 -            *type = GL_UNSIGNED_BYTE;
  20.639 -        } else {
  20.640 -            return SDL_FALSE;
  20.641 -        }
  20.642 -        break;
  20.643 -    case SDL_PIXELFORMAT_YUY2:
  20.644 -        if (renderdata->GL_APPLE_ycbcr_422_supported) {
  20.645 -            *internalFormat = GL_RGB;
  20.646 -            *format = GL_YCBCR_422_APPLE;
  20.647 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  20.648 -            *type = GL_UNSIGNED_SHORT_8_8_REV_APPLE;
  20.649 -#else
  20.650 -            *type = GL_UNSIGNED_SHORT_8_8_APPLE;
  20.651 -#endif
  20.652 -        } else if (renderdata->GL_MESA_ycbcr_texture_supported) {
  20.653 -            *internalFormat = GL_YCBCR_MESA;
  20.654 -            *format = GL_YCBCR_MESA;
  20.655 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
  20.656 -            *type = GL_UNSIGNED_SHORT_8_8_REV_MESA;
  20.657 -#else
  20.658 -            *type = GL_UNSIGNED_SHORT_8_8_MESA;
  20.659 -#endif
  20.660 -        } else {
  20.661 -            return SDL_FALSE;
  20.662 -        }
  20.663 -        break;
  20.664 -    default:
  20.665 -        return SDL_FALSE;
  20.666 -    }
  20.667 -    return SDL_TRUE;
  20.668 -}
  20.669 -
  20.670 -static int
  20.671 -GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
  20.672 -{
  20.673 -    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
  20.674 -    GL_TextureData *data;
  20.675 -    GLint internalFormat;
  20.676 -    GLenum format, type;
  20.677 -    int texture_w, texture_h;
  20.678 -    GLuint shader = 0;
  20.679 -    GLenum result;
  20.680 -
  20.681 -    GL_ActivateRenderer(renderer);
  20.682 -
  20.683 -    if (!convert_format(renderdata, texture->format, &internalFormat,
  20.684 -                        &format, &type)) {
  20.685 -        SDL_SetError("Texture format %s not supported by OpenGL",
  20.686 -                     SDL_GetPixelFormatName(texture->format));
  20.687 -        return -1;
  20.688 -    }
  20.689 -    if (texture->format == SDL_PIXELFORMAT_UYVY &&
  20.690 -        !renderdata->GL_APPLE_ycbcr_422_supported &&
  20.691 -        !renderdata->GL_MESA_ycbcr_texture_supported &&
  20.692 -        renderdata->GL_ARB_fragment_program_supported) {
  20.693 -        if (renderdata->fragment_program_UYVY == 0) {
  20.694 -            renderdata->fragment_program_UYVY =
  20.695 -                compile_shader(renderdata, GL_FRAGMENT_PROGRAM_ARB,
  20.696 -                               fragment_program_UYVY_source_code);
  20.697 -            if (renderdata->fragment_program_UYVY == 0) {
  20.698 -                set_shader_error(renderdata, "UYVY");
  20.699 -                return -1;
  20.700 -            }
  20.701 -        }
  20.702 -        shader = renderdata->fragment_program_UYVY;
  20.703 -    }
  20.704 -
  20.705 -    data = (GL_TextureData *) SDL_calloc(1, sizeof(*data));
  20.706 -    if (!data) {
  20.707 -        SDL_OutOfMemory();
  20.708 -        return -1;
  20.709 -    }
  20.710 -
  20.711 -    data->shader = shader;
  20.712 -
  20.713 -    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
  20.714 -        data->pitch = texture->w * bytes_per_pixel(texture->format);
  20.715 -        data->pixels = SDL_malloc(texture->h * data->pitch);
  20.716 -        if (!data->pixels) {
  20.717 -            SDL_OutOfMemory();
  20.718 -            SDL_free(data);
  20.719 -            return -1;
  20.720 -        }
  20.721 -    }
  20.722 -
  20.723 -    texture->driverdata = data;
  20.724 -
  20.725 -    renderdata->glGetError();
  20.726 -    renderdata->glGenTextures(1, &data->texture);
  20.727 -    if (renderdata->GL_ARB_texture_rectangle_supported) {
  20.728 -        data->type = GL_TEXTURE_RECTANGLE_ARB;
  20.729 -        texture_w = texture->w;
  20.730 -        texture_h = texture->h;
  20.731 -        data->texw = (GLfloat) texture_w;
  20.732 -        data->texh = (GLfloat) texture_h;
  20.733 -    } else {
  20.734 -        data->type = GL_TEXTURE_2D;
  20.735 -        texture_w = power_of_2(texture->w);
  20.736 -        texture_h = power_of_2(texture->h);
  20.737 -        data->texw = (GLfloat) (texture->w) / texture_w;
  20.738 -        data->texh = (GLfloat) texture->h / texture_h;
  20.739 -    }
  20.740 -
  20.741 -    /* YUV formats use RGBA but are really two bytes per pixel */
  20.742 -    if (internalFormat == GL_RGBA && bytes_per_pixel(texture->format) < 4) {
  20.743 -        texture_w /= 2;
  20.744 -        if (data->type == GL_TEXTURE_2D) {
  20.745 -            data->texw *= 2.0f;
  20.746 -        }
  20.747 -        data->HACK_RYAN_FIXME = 2;
  20.748 -    } else {
  20.749 -        data->HACK_RYAN_FIXME = 1;
  20.750 -    }
  20.751 -
  20.752 -    data->format = format;
  20.753 -    data->formattype = type;
  20.754 -    renderdata->glEnable(data->type);
  20.755 -    renderdata->glBindTexture(data->type, data->texture);
  20.756 -    renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER,
  20.757 -                                GL_LINEAR);
  20.758 -    renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER,
  20.759 -                                GL_LINEAR);
  20.760 -    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_S,
  20.761 -                                GL_CLAMP_TO_EDGE);
  20.762 -    renderdata->glTexParameteri(data->type, GL_TEXTURE_WRAP_T,
  20.763 -                                GL_CLAMP_TO_EDGE);
  20.764 -#ifdef __MACOSX__
  20.765 -#ifndef GL_TEXTURE_STORAGE_HINT_APPLE
  20.766 -#define GL_TEXTURE_STORAGE_HINT_APPLE       0x85BC
  20.767 -#endif
  20.768 -#ifndef STORAGE_CACHED_APPLE
  20.769 -#define STORAGE_CACHED_APPLE                0x85BE
  20.770 -#endif
  20.771 -#ifndef STORAGE_SHARED_APPLE
  20.772 -#define STORAGE_SHARED_APPLE                0x85BF
  20.773 -#endif
  20.774 -    if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
  20.775 -        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
  20.776 -                                    GL_STORAGE_SHARED_APPLE);
  20.777 -    } else {
  20.778 -        renderdata->glTexParameteri(data->type, GL_TEXTURE_STORAGE_HINT_APPLE,
  20.779 -                                    GL_STORAGE_CACHED_APPLE);
  20.780 -    }
  20.781 -/* This causes a crash in testoverlay for some reason.  Apple bug? */
  20.782 -#if 0
  20.783 -    if (texture->access == SDL_TEXTUREACCESS_STREAMING
  20.784 -        && texture->format == SDL_PIXELFORMAT_ARGB8888) {
  20.785 -        /*
  20.786 -           if (renderdata->glTextureRangeAPPLE) {
  20.787 -           renderdata->glTextureRangeAPPLE(data->type,
  20.788 -           texture->h * data->pitch,
  20.789 -           data->pixels);
  20.790 -           }
  20.791 -         */
  20.792 -        renderdata->glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, GL_TRUE);
  20.793 -        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
  20.794 -                                 texture_h, 0, format, type, data->pixels);
  20.795 -    } else
  20.796 -#endif
  20.797 -#endif
  20.798 -    {
  20.799 -        renderdata->glTexImage2D(data->type, 0, internalFormat, texture_w,
  20.800 -                                 texture_h, 0, format, type, NULL);
  20.801 -    }
  20.802 -    renderdata->glDisable(data->type);
  20.803 -    result = renderdata->glGetError();
  20.804 -    if (result != GL_NO_ERROR) {
  20.805 -        GL_SetError("glTexImage2D()", result);
  20.806 -        return -1;
  20.807 -    }
  20.808 -    return 0;
  20.809 -}
  20.810 -
  20.811 -static int
  20.812 -GL_QueryTexturePixels(SDL_Renderer * renderer, SDL_Texture * texture,
  20.813 -                      void **pixels, int *pitch)
  20.814 -{
  20.815 -    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
  20.816 -
  20.817 -    *pixels = data->pixels;
  20.818 -    *pitch = data->pitch;
  20.819 -    return 0;
  20.820 -}
  20.821 -
  20.822 -static void
  20.823 -SetupTextureUpdate(GL_RenderData * renderdata, SDL_Texture * texture,
  20.824 -                   int pitch)
  20.825 -{
  20.826 -    renderdata->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  20.827 -    renderdata->glPixelStorei(GL_UNPACK_ROW_LENGTH,
  20.828 -                              (pitch / bytes_per_pixel(texture->format)) /
  20.829 -                              ((GL_TextureData *) texture->driverdata)->
  20.830 -                              HACK_RYAN_FIXME);
  20.831 -}
  20.832 -
  20.833 -static int
  20.834 -GL_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
  20.835 -                 const SDL_Rect * rect, const void *pixels, int pitch)
  20.836 -{
  20.837 -    GL_RenderData *renderdata = (GL_RenderData *) renderer->driverdata;
  20.838 -    GL_TextureData *data = (GL_TextureData *) texture->driverdata;
  20.839 -    GLenum result;
  20.840 -
  20.841 -    GL_ActivateRenderer(renderer);
  20.842 -
  20.843 -    renderdata->glGetError();
  20.844 -    SetupTextureUpdate(renderdata, texture, pitch);
  20.845 -    renderdata->glEnable(data->type);
  20.846 -    renderdata->glBindTexture(data->type, data->texture);
  20.847 -    renderdata->glTexSubImage2D(data->type, 0, rect->x, rect->y, rect->w,
  20.848 -                                rect->h, data->format, data->formattype,