code cleanup and opengles optimizations
authorkoda
Sat, 16 Jan 2010 06:48:56 +0000
changeset 2697 75880595a9f1
parent 2696 41aa7b56c17b
child 2698 90585aba87ad
code cleanup and opengles optimizations
cocoaTouch/GameSetup.m
cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m
cocoaTouch/SDLOverrides/SDL_uikitview.h
cocoaTouch/otherSrc/PascalImports.h
hedgewars/CCHandlers.inc
hedgewars/SDLh.pas
hedgewars/hwengine.pas
hedgewars/uConsts.pas
hedgewars/uMisc.pas
hedgewars/uStore.pas
--- a/cocoaTouch/GameSetup.m	Fri Jan 15 10:03:31 2010 +0000
+++ b/cocoaTouch/GameSetup.m	Sat Jan 16 06:48:56 2010 +0000
@@ -27,7 +27,7 @@
 }
 
 -(void) dealloc {
-	[self.systemSettings release];
+	if (systemSettings) [self.systemSettings release];
 	[self.localeString autorelease];
 	[super dealloc];
 }
@@ -84,7 +84,8 @@
 		
 		/* This check the sd if there is a pending connection.
 		 * If there is one, accept that, and open a new socket for communicating */
-		if ((csd = SDLNet_TCP_Accept(sd))) {
+		csd = SDLNet_TCP_Accept(sd);
+		if (NULL != csd) {
 			
 			NSLog(@"engineProtocol - Client found");
 			
@@ -175,7 +176,7 @@
 				
 				clientQuit = NO;
 			} else {
-				NSLog(@"engineProtocolThread - wrong message, closing connection");
+				NSLog(@"engineProtocolThread - wrong message or client closed connection");
 				clientQuit = YES;
 			}
 			
@@ -226,12 +227,15 @@
 						// empty packet or just statistics
 						break;
 					// missing case for exiting right away
-				} 
+				}
 			}
+			NSLog(@"Client Exited");
+			// wait a little to let the client close cleanly
+			sleep(5);
+			// Close the client socket
+			SDLNet_TCP_Close(csd);
 		}
-		
-		/* Close the client socket */
-		SDLNet_TCP_Close(csd);
+
 	}
 
 	SDLNet_TCP_Close(sd);
@@ -258,10 +262,7 @@
 }
 
 -(void) unloadSettings {
-	for (id obj in self)
-		if ([obj isKindOfClass:[NSDictionary class]]) {
-			[obj release];
-		}
+	[systemSettings dealloc];
 }
 
 -(void) setArgsForLocalPlay {
--- a/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m	Fri Jan 15 10:03:31 2010 +0000
+++ b/cocoaTouch/SDLOverrides/SDL_uikitappdelegate.m	Sat Jan 16 06:48:56 2010 +0000
@@ -91,12 +91,12 @@
 	[setup loadSettingsFromFile:@"settings.plist" forKey:@"systemSettings"];
 
 	// remove the current view to free resources
-	[UIView beginAnimations:nil context:NULL];
+/*	[UIView beginAnimations:nil context:NULL];
 	[UIView setAnimationDuration:1.5];
-	controller.view.alpha = 0;
+	controller.view.alpha = 1;
 	[UIView commitAnimations];
 	[controller.view performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:1.5];
-
+*/
 	NSLog(@"Game is launching...");
 
 	[NSThread detachNewThreadSelector:@selector(launchSDL_main) toTarget:self withObject:nil];
--- a/cocoaTouch/SDLOverrides/SDL_uikitview.h	Fri Jan 15 10:03:31 2010 +0000
+++ b/cocoaTouch/SDLOverrides/SDL_uikitview.h	Sat Jan 16 06:48:56 2010 +0000
@@ -36,7 +36,7 @@
 
 // constants for telling which input has been received
 #define kMinimumPinchDelta		100
-#define kMinimumGestureLength	20
+#define kMinimumGestureLength	10
 #define kMaximumVariance		4
 
 /* *INDENT-OFF* */
--- a/cocoaTouch/otherSrc/PascalImports.h	Fri Jan 15 10:03:31 2010 +0000
+++ b/cocoaTouch/otherSrc/PascalImports.h	Sat Jan 16 06:48:56 2010 +0000
@@ -20,6 +20,8 @@
 	
 	int HW_protoVer(void);
 	
+	void Game(void);
+	
 	void HW_click(void);
 	void HW_zoomIn(void);
 	void HW_zoomOut(void);
--- a/hedgewars/CCHandlers.inc	Fri Jan 15 10:03:31 2010 +0000
+++ b/hedgewars/CCHandlers.inc	Sat Jan 16 06:48:56 2010 +0000
@@ -598,67 +598,59 @@
 {$IFDEF DEBUGFILE}
     buf: array[byte] of char;
 {$ENDIF}
+{$IFDEF SDL13}
+	windowID: TSDL_WindowID;
+{$ENDIF}
 begin
-if Length(s) = 0 then cFullScreen:= not cFullScreen
+	if Length(s) = 0 then cFullScreen:= not cFullScreen
 	else cFullScreen:= s = '1';
 
 {$IFDEF DEBUGFILE}
-AddFileLog('Prepare to change video parameters...');
+	AddFileLog('Prepare to change video parameters...');
 {$ENDIF}
 
+	flags:= SDL_OPENGL;// or SDL_RESIZABLE;
 {$IFDEF IPHONEOS}
-SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
-SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
-SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
-SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
-SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
-SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
-SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
-SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
-{$ELSE}
-SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-{$ENDIF}
-
-{$IFNDEF SDL13}
-// this attribute is default in 1.3 and must be enabled in MacOSX
-{$IFNDEF DARWIN}
-if cVSyncInUse then
-{$ENDIF}
-	SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
+	// remove the topbar from the iPhone
+	flags:= flags or SDL_NOFRAME;
 {$ENDIF}
 
-flags:= SDL_OPENGL;// or SDL_RESIZABLE;
-{$IFDEF IPHONEOS}
-// remove the topbar from the iPhone
-flags:= flags or SDL_NOFRAME;
-{$ENDIF}
-
-if cFullScreen then
+	if cFullScreen then
 	begin
-	flags:= flags or SDL_FULLSCREEN;
-	cScreenWidth:= cInitWidth;
-	cScreenHeight:= cInitHeight
+		flags:= flags or SDL_FULLSCREEN;
+		cScreenWidth:= cInitWidth;
+		cScreenHeight:= cInitHeight
 	end;
 
-SDL_WM_SetCaption('Hedgewars', nil);
-if SDLPrimSurface <> nil then
+	SDL_WM_SetCaption('Hedgewars', nil);
+	if SDLPrimSurface <> nil then
 	begin
-	{$IFDEF DEBUGFILE}
-	AddFileLog('Freeing old primary surface...');
-	{$ENDIF}
-	SDL_FreeSurface(SDLPrimSurface);
+{$IFDEF DEBUGFILE}
+		AddFileLog('Freeing old primary surface...');
+{$ENDIF}
+		SDL_FreeSurface(SDLPrimSurface);
 	end;
-
-SDLPrimSurface:= SDL_SetVideoMode(cScreenWidth, cScreenHeight, cBits, flags);
-SDLTry(SDLPrimSurface <> nil, true);
-PixelFormat:= SDLPrimSurface^.format;
+	
+{$IFDEF SDL13}
+	windowID:= SDL_CreateWindow(nil, 0, 0, cScreenWidth, cScreenHeight,	SDL_WINDOW_OPENGL or SDL_WINDOW_SHOWN 
+				{$IFDEF IPHONEOS} or SDL_WINDOW_BORDERLESS{$ENDIF});
+    SDL_CreateRenderer(windowID, 0, 0);
+	PixelFormat:=nil;// SDLPrimSurface^.format;
+	
+	SDL_SetRenderDrawColor(0, 0, 0, 255);
+    SDL_RenderFill(nil);
+    SDL_RenderPresent();
+{$ELSE}
+	SDLPrimSurface:= SDL_SetVideoMode(cScreenWidth, cScreenHeight, cBits, flags);
+	SDLTry(SDLPrimSurface <> nil, true);
+	PixelFormat:= SDLPrimSurface^.format;
+{$ENDIF}
 
 {$IFDEF DEBUGFILE}
-AddFileLog('Setting up OpenGL...');
-AddFileLog('SDL video driver: ' + string(SDL_VideoDriverName(buf, sizeof(buf))));
+	AddFileLog('Setting up OpenGL...');
+	AddFileLog('SDL video driver: ' + string(SDL_VideoDriverName(buf, sizeof(buf))));
 {$ENDIF}
-SetupOpenGL();
-
+	SetupOpenGL();
 end;
 
 procedure chVol_p(var s: shortstring);
--- a/hedgewars/SDLh.pas	Fri Jan 15 10:03:31 2010 +0000
+++ b/hedgewars/SDLh.pas	Sat Jan 16 06:48:56 2010 +0000
@@ -175,6 +175,21 @@
 	AMask = $000000FF;
 {$ENDIF}
 
+{$IFDEF SDL13}
+// SDL_WindowFlags (enum)
+    SDL_WINDOW_FULLSCREEN = $00000001;         //*< fullscreen window, implies borderless */
+    SDL_WINDOW_OPENGL = $00000002;             //*< window usable with OpenGL context */
+    SDL_WINDOW_SHOWN = $00000004;              //*< window is visible */
+    SDL_WINDOW_BORDERLESS = $00000008;         //*< no window decoration */
+    SDL_WINDOW_RESIZABLE = $00000010;          //*< window can be resized */
+    SDL_WINDOW_MINIMIZED = $00000020;          //*< window is minimized */
+    SDL_WINDOW_MAXIMIZED = $00000040;          //*< window is maximized */
+    SDL_WINDOW_INPUT_GRABBED = $00000100;      //*< window has grabbed input focus */
+    SDL_WINDOW_INPUT_FOCUS = $00000200;        //*< window has input focus */
+    SDL_WINDOW_MOUSE_FOCUS = $00000400;        //*< window has mouse focus */
+    SDL_WINDOW_FOREIGN = $00000800;            //*< window not created by SDL */
+{$ENDIF}
+
 	{* SDL_mixer *}
 	MIX_MAX_VOLUME = 128;
 	MIX_INIT_FLAC = $00000001;
@@ -313,7 +328,8 @@
 
 {$IFDEF SDL13}
 	TSDL_WindowID = LongInt;
-
+	TSDL_TextureID = LongInt;
+	
 	TSDL_WindowEvent = record
 		type_: byte;
 		gain: byte;
@@ -610,9 +626,21 @@
 function  SDL_SaveBMP_RW(surface: PSDL_Surface; dst: PSDL_RWops; freedst: LongInt): LongInt; cdecl; external SDLLibName;
 
 {$IFDEF SDL13}
+function  SDL_CreateWindow(title: PChar; x,y,w,h, flags: LongInt): TSDL_WindowID; cdecl; external SDLLibName;
+function  SDL_CreateRenderer(windowID: TSDL_WindowID; index, flags: LongInt): LongInt; cdecl; external SDLLibName;
+function  SDL_SetRenderDrawColor(r,g,b,a: byte): LongInt; cdecl; external SDLLibName;
+function  SDL_RenderFill(rect: PSDL_Rect): LongInt;
+function  SDL_RenderFillRect(rect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
+function  SDL_RenderClear: LongInt; cdecl; external SDLLibName;
+procedure SDL_RenderPresent; cdecl; external SDLLibName;
+function  SDL_RenderCopy(textureID: TSDL_TextureID; srcrect, dstrect: PSDL_Rect): LongInt; cdecl; external SDLLibName;
+
+function  SDL_CreateTextureFromSurface(format: LongInt; surface: PSDL_Surface): TSDL_TextureID; cdecl; external SDLLibName;
+procedure SDL_DestroyTexture(textureID: TSDL_TextureID); cdecl; external SDLLibName;
+
 function  SDL_GetKeyboardState(numkeys: PLongInt): PByteArray; cdecl; external SDLLibName;
 function  SDL_SelectMouse(index: LongInt): LongInt; cdecl; external SDLLibName;
-function  SDL_GetRelativeMouseState(index: LongInt; x, y: PLongInt): Byte; cdecl; external SDLLibName;
+function  SDL_GetRelativeMouseState(x, y: PLongInt): Byte; cdecl; external SDLLibName;
 function  SDL_GetNumMice: LongInt; cdecl; external SDLLibName;
 function  SDL_PixelFormatEnumToMasks(format: TSDL_ArrayByteOrder; bpp: PLongInt; Rmask, Gmask, Bmask, Amask: PLongInt): boolean; cdecl; external SDLLibName;
 {$ELSE}
@@ -767,5 +795,15 @@
                   (PByteArray(buf)^[0] shl 24)
 end;
 
+{$IFDEF SDL13}
+function SDL_RenderFill(rect: PSDL_Rect): LongInt;
+var res: LongInt;
+begin
+	if (rect <> nil) then res:= SDL_RenderFillRect(rect)
+	else res:= SDL_RenderClear();
+	exit(res);
+end;
+{$ENDIF}
+
 end.
 
--- a/hedgewars/hwengine.pas	Fri Jan 15 10:03:31 2010 +0000
+++ b/hedgewars/hwengine.pas	Sat Jan 16 06:48:56 2010 +0000
@@ -480,7 +480,6 @@
 TryDo(InitStepsFlags = cifAllInited, 'Some parameters not set (flags = ' + inttostr(InitStepsFlags) + ')', true);
 
 MainLoop;
-ControllerClose();
 end;
 
 /////////////////////////
--- a/hedgewars/uConsts.pas	Fri Jan 15 10:03:31 2010 +0000
+++ b/hedgewars/uConsts.pas	Sat Jan 16 06:48:56 2010 +0000
@@ -32,6 +32,9 @@
 
 {$INCLUDE "proto.inc"}
 
+// typed const is a variable despite const qualifier
+// in freepascal you may actually use var for the same purpose
+
 type
 
 	TGameState = (gsLandGen, gsStart, gsGame, gsChat, gsConfirm, gsExit);
@@ -162,7 +165,7 @@
 	errmsgIncorrectUse    = 'Incorrect use';
 	errmsgShouldntRun     = 'This program shouldn''t be run manually';
 	errmsgWrongNumber     = 'Wrong parameters number';
-        errmsgSlotsOverflow   = 'CurSlot overflowed';
+	errmsgSlotsOverflow   = 'CurSlot overflowed';
 
 	msgLoading           = 'Loading ';
 	msgOK                = 'ok';
@@ -408,7 +411,28 @@
 			'Sounds/voices',                 // ptVoices
 			'Graphics/Hats'                  // ptHats
 			);
-
+		(*
+	PathzBackup: array[TPathType] of String = (
+			'',                              // ptNone
+			'',                              // ptData
+			'Graphics',                      // ptGraphics
+			'Themes',                        // ptThemes
+			'Themes/avematan',               // ptCurrTheme
+			'Teams',                         // ptTeams
+			'Maps',                          // ptMaps
+			'',                              // ptMapCurrent
+			'Demos',                         // ptDemos
+			'Sounds',                        // ptSounds
+			'Graphics/Graves',               // ptGraves
+			'Fonts',                         // ptFonts
+			'Forts',                         // ptForts
+			'Locale',                        // ptLocale
+			'Graphics/AmmoMenu',             // ptAmmoMenu
+			'Graphics/Hedgehog',             // ptHedgehog
+			'Sounds/voices',                 // ptVoices
+			'Graphics/Hats'                  // ptHats
+			);
+		*)	
 	SpritesData: array[TSprite] of record
 			FileName: String[14];
 			Path, AltPath: TPathType;
--- a/hedgewars/uMisc.pas	Fri Jan 15 10:03:31 2010 +0000
+++ b/hedgewars/uMisc.pas	Sat Jan 16 06:48:56 2010 +0000
@@ -33,6 +33,10 @@
 {$ENDIF}
 	;
 
+type HwColor4f = record
+	r, g, b, a: byte
+	end;
+
 var
 	isCursorVisible : boolean = false;
 	isTerminated    : boolean = false;
@@ -64,7 +68,7 @@
 	cScreenHeight    : LongInt = 768;
 	cInitWidth       : LongInt = 1024;
 	cInitHeight      : LongInt = 768;
-	cVSyncInUse	 : boolean = true;	
+	cVSyncInUse		 : boolean = true;	
 	cBits            : LongInt = 32;
 	cBitsStr         : string[2] = '32';
 	cTagsMaskIndex   : byte = Low(cTagsMasks);
@@ -138,14 +142,12 @@
 	AttackBar: LongInt = 0; // 0 - none, 1 - just bar at the right-down corner, 2 - like in WWP
 
 	i: LongInt;
+	
+	cWaterOpacity: byte = $80;
+	WaterColorArray: array[0..3] of HwColor4f;
 
-type HwColor4f = record
-	r, g, b, a: byte
-	end;
-
-var cWaterOpacity: byte = $80;
-
-var WaterColorArray: array[0..3] of HwColor4f;
+	CursorPoint: TPoint;
+    TargetPoint: TPoint = (X: NoPointX; Y: 0);
 
 procedure movecursor(dx, dy: Integer);
 function hwSign(r: hwFloat): LongInt;
@@ -179,11 +181,8 @@
 {$IFNDEF IPHONEOS}
 procedure MakeScreenshot(s: shortstring);
 {$ENDIF}
-
 function modifyDamage(dmg: Longword): Longword;
 
-var CursorPoint: TPoint;
-    TargetPoint: TPoint = (X: NoPointX; Y: 0);
 
 implementation
 uses uConsole, uStore, uIO, Math, uRandom, uSound;
--- a/hedgewars/uStore.pas	Fri Jan 15 10:03:31 2010 +0000
+++ b/hedgewars/uStore.pas	Sat Jan 16 06:48:56 2010 +0000
@@ -1004,11 +1004,6 @@
 function  LoadImage(const filename: string; imageFlags: LongInt): PSDL_Surface;
 var tmpsurf: PSDL_Surface;
     s: shortstring;
-{$IFDEF DONTUSE}
-    tmpP: PLongWordArray;
-    tmpA, tmpR, tmpG, tmpB: LongWord;
-    i: LongInt;
-{$ENDIF}
 begin
 	WriteToConsole(msgLoading + filename + ' [flags: ' + inttostr(imageFlags) + ']... ');
 
@@ -1054,52 +1049,6 @@
 
 	tmpsurf:= doSurfaceConversion(tmpsurf);
 
-{$IFDEF DONTUSE}   // way too slow
-{* http://bugzilla.libsdl.org/show_bug.cgi?id=868 but patched library doesn't work on ipod, so implementing workaround here *}
-	if imageFlags and (ifAlpha or ifTransparent) > 0 then
-	begin
-		tmpP := tmpsurf^.pixels;
-		for i:= 0 to (tmpsurf^.pitch shr 2) * tmpsurf^.h - 1 do 
-		begin
-{$IFDEF ENDIAN_LITTLE}
-			tmpA:= tmpP^[i] shr 24 and $FF;
-			tmpR:= tmpP^[i] shr 16 and $FF;
-			tmpG:= tmpP^[i] shr 8 and $FF;
-			tmpB:= tmpP^[i] and $FF;
-{$ELSE}
-			tmpA:= tmpP^[i] and $FF;
-			tmpR:= tmpP^[i] shr 8 and $FF;
-			tmpG:= tmpP^[i] shr 16 and $FF;
-			tmpB:= tmpP^[i] shr 24 and $FF;
-{$ENDIF}
-			if tmpA <> 0 then
-			begin
-				tmpR:= round(tmpR * 255 / tmpA);
-				tmpG:= round(tmpG * 255 / tmpA);
-				tmpB:= round(tmpB * 255 / tmpA);
-			end;
-
-			if tmpR > 255 then tmpR:= 255;
-			if tmpG > 255 then tmpG:= 255;
-			if tmpB > 255 then tmpB:= 255;
-
-{$IFDEF ENDIAN_LITTLE}
-			tmpP^[i]:= (tmpA shl 24) or (tmpR shl 16) or (tmpG shl 8) or tmpB;
-{$ELSE}
-			tmpP^[i]:= (tmpA) or (tmpR shl 8) or (tmpG shl 16) or (tmpB shl 24);
-{$ENDIF}
-		end;
-(*		for i:= 0 to (tmpsurf^.pitch shr 2) * tmpsurf^.h - 1 do
-		begin
-			tmpA:= tmpP^[i] shr 24 and $FF;
-			tmpR:= tmpP^[i] shr 16 and $FF;
-			tmpG:= tmpP^[i] shr 8 and $FF;
-			tmpB:= tmpP^[i] and $FF;
-			writeln(stdout, inttostr(tmpA) + ' | ' + inttostr(tmpR) + ' | ' + inttostr(tmpG)+ ' | ' + inttostr(tmpB));
-		end; *)
-	end;
-{$ENDIF}
-
 	if (imageFlags and ifTransparent) <> 0 then
 		TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
 
@@ -1125,19 +1074,45 @@
 end;
 
 procedure SetupOpenGL;
+{$IFDEF DEBUGFILE}
 var vendor: shortstring;
+{$ENDIF}
 begin
+{$IFDEF IPHONEOS}
+//these are good performance savers, perhaps we could enable them by default
+	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
+	SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
+	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
+	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
+	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
+	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
+	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
+	SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
+	//SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
+{$ELSE}
+	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+{$ENDIF}
+
+{$IFNDEF SDL13}
+// this attribute is default in 1.3 and must be enabled in MacOSX
+{$IFNDEF DARWIN}
+	if cVSyncInUse then
+{$ENDIF}
+		SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1);
+{$ENDIF}
+
 	glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
+
+{$IFDEF DEBUGFILE}
 	vendor:= LowerCase(string(pchar(glGetString(GL_VENDOR))));
 
-{$IFDEF DEBUGFILE}
 	AddFileLog('OpenGL - Renderer: ' + string(pchar(glGetString(GL_RENDERER))));
 	AddFileLog('  |----- Vendor: ' + vendor);
 	AddFileLog('  |----- Version: ' + string(pchar(glGetString(GL_VERSION))));
 	AddFileLog('  \----- GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize));
 {$ENDIF}
 
-	if MaxTextureSize = 0 then
+	if MaxTextureSize <= 0 then
 	begin
 		MaxTextureSize:= 1024;
 {$IFDEF DEBUGFILE}
@@ -1146,59 +1121,61 @@
 	end;
 
 {$IFNDEF IPHONEOS}
-if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then
-	cGPUVendor:= gvNVIDIA
-else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then
-	cGPUVendor:= gvATI
-else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then
-	cGPUVendor:= gvIntel;
-
+	if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then
+		cGPUVendor:= gvNVIDIA
+	else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then
+		cGPUVendor:= gvATI
+	else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then
+		cGPUVendor:= gvIntel;
 //SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two');
 {$ENDIF}
 
-// set view port to whole window
-glViewport(0, 0, cScreenWidth, cScreenHeight);
+	// set view port to whole window
+	glViewport(0, 0, cScreenWidth, cScreenHeight);
 
-glMatrixMode(GL_MODELVIEW);
-// prepare default translation/scaling
-glLoadIdentity();
-glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
+	glMatrixMode(GL_MODELVIEW);
+	// prepare default translation/scaling
+	glLoadIdentity();
+	glScalef(2.0 / cScreenWidth, -2.0 / cScreenHeight, 1.0);
 {$IFDEF IPHONEOS}
-//glRotatef(90, 0, 0, 1);
+	//glRotatef(90, 0, 0, 1);
 {$ENDIF}
-glTranslatef(0, -cScreenHeight / 2, 0);
+	glTranslatef(0, -cScreenHeight / 2, 0);
 
-// enable alpha blending
-glEnable(GL_BLEND);
-glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+	// enable alpha blending
+	glEnable(GL_BLEND);
+	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
 end;
 
 procedure SetScale(f: GLfloat);
 begin
-// leave immediately if scale factor did not change
-if f = cScaleFactor then exit;
+	// leave immediately if scale factor did not change
+	if f = cScaleFactor then exit;
 
-if f = 2.0 then // default scaling
-	glPopMatrix // "return" to default scaling
-else // other scaling
+	if f = 2.0 then glPopMatrix // "return" to default scaling
+	else // other scaling
 	begin
-	glPushMatrix; // save default scaling
-	glLoadIdentity;
-	glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
+		glPushMatrix; // save default scaling
+		glLoadIdentity;
+		glScalef(f / cScreenWidth, -f / cScreenHeight, 1.0);
 {$IFDEF IPHONEOS}
-//	glRotatef(90, 0, 0, 1);
+		//glRotatef(90, 0, 0, 1);
 {$ENDIF}
-	glTranslatef(0, -cScreenHeight / 2, 0);
+		glTranslatef(0, -cScreenHeight / 2, 0);
 	end;
 
-cScaleFactor:= f;
+	cScaleFactor:= f;
 end;
 
 ////////////////////////////////////////////////////////////////////////////////
-var ProgrTex: PTexture = nil;
-    Step: integer = 0;
+var Step: LongInt = 0;
 	squaresize : LongInt;
-	numsquares : integer;
+	numsquares : LongInt;
+{$IFDEF SDL13notworking}
+	ProgrTex: TSDL_TextureID = 0;
+{$ELSE}
+	ProgrTex: PTexture = nil;
+{$ENDIF}
 
 procedure AddProgress;
 var r: TSDL_Rect;
@@ -1206,47 +1183,63 @@
 begin
 	if Step = 0 then
 	begin
-	{$IFDEF SDL_IMAGE_NEWER}
+{$IFDEF SDL_IMAGE_NEWER}
 		WriteToConsole('Init SDL_image... ');
 		SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
 		WriteLnToConsole(msgOK);
-	{$ENDIF}
+{$ENDIF}
 	
 		WriteToConsole(msgLoading + 'progress sprite: ');
 		texsurf:= LoadImage(Pathz[ptGraphics] + '/Progress', ifCritical or ifTransparent);
+{$IFDEF SDL13notworking}
+		ProgrTex:= SDL_CreateTextureFromSurface(0, texsurf);
+{$ELSE}
 		ProgrTex:= Surface2Tex(texsurf, false);
+{$ENDIF}
+		squaresize:= texsurf^.w shr 1;
+		numsquares:= texsurf^.h div squaresize;
 		SDL_FreeSurface(texsurf);
-		squaresize:= ProgrTex^.w shr 1;
-		numsquares:= ProgrTex^.h div squaresize;
 	end;
 
-TryDo(ProgrTex <> nil, 'ProgrTex = nil!', true);
+{$IFDEF SDL13notworking}
+	TryDo(ProgrTex <> 0, 'Error - Progress Texure is 0!', true);
+{$ELSE}
+	TryDo(ProgrTex <> nil, 'Error - Progress Texure is nil!', true);
+{$ENDIF}
 
-glClear(GL_COLOR_BUFFER_BIT);
-glEnable(GL_TEXTURE_2D);
-if Step < numsquares then r.x:= 0
-else r.x:= squaresize;
-r.y:= (Step mod numsquares) * squaresize;
-r.w:= squaresize;
-r.h:= squaresize;
-DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex);
-glDisable(GL_TEXTURE_2D);
-SDL_GL_SwapBuffers();
-inc(Step);
+	glClear(GL_COLOR_BUFFER_BIT);
+	glEnable(GL_TEXTURE_2D);
+	if Step < numsquares then r.x:= 0
+	else r.x:= squaresize;
+	
+	r.y:= (Step mod numsquares) * squaresize;
+	r.w:= squaresize;
+	r.h:= squaresize;
+	
+{$IFDEF SDL13notworking}
+	SDL_RenderCopy(ProgrTex, nil, @r);
+{$ELSE}	
+	DrawFromRect( -squaresize div 2, (cScreenHeight - squaresize) shr 1, @r, ProgrTex);
+{$ENDIF}
+	glDisable(GL_TEXTURE_2D);
+	SDL_GL_SwapBuffers();
+	inc(Step);
 end;
 
 
 procedure FinishProgress;
 begin
-WriteLnToConsole('Freeing progress surface... ');
-FreeTexture(ProgrTex);
-ProgrTex:= nil;
+	WriteLnToConsole('Freeing progress surface... ');
+{$IFDEF SDL13notworking}
+	SDL_DestroyTexture(ProgrTex);
+{$ELSE}
+	FreeTexture(ProgrTex);
+{$ENDIF}
 
 {$IFDEF IPHONEOS}
-// show overlay buttons
-IPH_showControls;
+	// show overlay buttons
+	IPH_showControls;
 {$ENDIF}
-
 end;
 
 procedure flipSurface(Surface: PSDL_Surface; Vertical: Boolean);