hedgewars/uStore.pas
changeset 2575 d06e0e829828
parent 2568 e654cbfb23ba
child 2578 ec8e69b23097
equal deleted inserted replaced
2574:2f3e5c57359c 2575:d06e0e829828
   899 end;
   899 end;
   900 
   900 
   901 function  LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface;
   901 function  LoadImage(const filename: string; imageFlags: Integer): PSDL_Surface;
   902 var tmpsurf: PSDL_Surface;
   902 var tmpsurf: PSDL_Surface;
   903     s: shortstring;
   903     s: shortstring;
   904 {$IFDEF IPHONEOS}
   904 {$IFDEF DARWIN}
   905     convertedSurf: PSDL_Surface;
   905     convertedSurf: PSDL_Surface;
   906 const TestFormat: TSDL_PixelFormat = (
       
   907             palette: nil;
       
   908             BitsPerPixel : 32;
       
   909             BytesPerPixel: 4;
       
   910             Rloss : 0;
       
   911             Gloss : 0;
       
   912             Bloss : 0;
       
   913             Aloss : 0;
       
   914 			Rshift: 0;
       
   915             Gshift: 8;
       
   916             Bshift: 16;
       
   917             Ashift: 24;
       
   918             RMask : $000000FF;
       
   919             GMask : $0000FF00;
       
   920             BMask : $00FF0000;
       
   921             AMask : $FF000000;
       
   922             colorkey: 0;
       
   923             alpha : 255);
       
   924 {$ENDIF}
   906 {$ENDIF}
   925 begin
   907 begin
   926 WriteToConsole(msgLoading + filename + '... ');
   908 WriteToConsole(msgLoading + filename + '... ');
   927 
   909 
   928 s:= filename + '.png';
   910 s:= filename + '.png';
   959 		OutError(msgFailedSize, (imageFlags and ifCritical) <> 0);
   941 		OutError(msgFailedSize, (imageFlags and ifCritical) <> 0);
   960 		//dummy surface to replace non-critical textures that failed to load due to their size
   942 		//dummy surface to replace non-critical textures that failed to load due to their size
   961 		exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask));
   943 		exit(SDL_CreateRGBSurface(SDL_SWSURFACE, 32, 32, 32, RMask, GMask, BMask, AMask));
   962 	end;
   944 	end;
   963 
   945 
       
   946 {$IFDEF DARWIN}
       
   947 //for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7
       
   948 if (tmpsurf^.format^.bitsperpixel = 24) or ((tmpsurf^.format^.bitsperpixel = 32) and (tmpsurf^.format^.rshift > tmpsurf^.format^.bshift)) then
       
   949 begin
       
   950 	convertedSurf:= SDL_ConvertSurface(tmpsurf, @convFormat, SDL_SWSURFACE);
       
   951 	SDL_FreeSurface(tmpsurf);	
       
   952 	tmpsurf:= convertedSurf;
       
   953 end;
       
   954 {$ENDIF}
       
   955 
   964 if (imageFlags and ifTransparent) <> 0 then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
   956 if (imageFlags and ifTransparent) <> 0 then TryDo(SDL_SetColorKey(tmpsurf, SDL_SRCCOLORKEY, 0) = 0, errmsgTransparentSet, true);
   965 //if (imageFlags and ifAlpha) <> 0 then Result:= SDL_DisplayFormatAlpha(tmpsurf) else Result:= SDL_DisplayFormat(tmpsurf);
   957 //if (imageFlags and ifAlpha) <> 0 then Result:= SDL_DisplayFormatAlpha(tmpsurf) else Result:= SDL_DisplayFormat(tmpsurf);
   966 WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');
   958 WriteLnToConsole('(' + inttostr(tmpsurf^.w) + ',' + inttostr(tmpsurf^.h) + ') ');
   967 WriteLnToConsole(msgOK);
   959 WriteLnToConsole(msgOK);
   968 
   960 
   969 {$IFDEF IPHONEOS}
       
   970 //for more information http://www.idevgames.com/forum/showpost.php?p=85864&postcount=7
       
   971 convertedSurf:= SDL_ConvertSurface(tmpsurf, @TestFormat, SDL_SWSURFACE);
       
   972 tmpsurf:= convertedSurf;
       
   973 {$ENDIF}
       
   974 
       
   975 LoadImage:= tmpsurf //Result
   961 LoadImage:= tmpsurf //Result
   976 end;
   962 end;
   977 
   963 
   978 function glLoadExtension(extension : string) : boolean;
   964 function glLoadExtension(extension : string) : boolean;
   979 begin
   965 begin
   980 {$IFNDEF IPHONEOS}
   966 {$IFNDEF IPHONEOS}
   981 	glLoadExtension:= glext_LoadExtension(extension);
   967 	glLoadExtension:= glext_LoadExtension(extension);
   982 {$ELSE}
   968 {$ELSE}
   983     glLoadExtension:= false;
   969 	glLoadExtension:= false;
   984 {$ENDIF}
   970 {$ENDIF}
   985 {$IFDEF DEBUGFILE}
   971 {$IFDEF DEBUGFILE}
   986 	if not glLoadExtension then
   972 	if not glLoadExtension then
   987 		AddFileLog('OpenGL: "' + extension + '" failed to load')
   973 		AddFileLog('OpenGL - "' + extension + '" failed to load')
   988 	else
   974 	else
   989 		AddFileLog('OpenGL: "' + extension + '" loaded');
   975 		AddFileLog('OpenGL - "' + extension + '" loaded');
   990 {$ENDIF}
   976 {$ENDIF}
   991 end;
   977 end;
   992 
   978 
   993 procedure SetupOpenGL;
   979 procedure SetupOpenGL;
   994 var vendor: shortstring;
   980 var vendor: shortstring;
   995 begin
   981 begin
   996 glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
   982 glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
   997 
   983 
   998 {$IFDEF DEBUGFILE}
   984 {$IFDEF DEBUGFILE}
   999 AddFileLog('OpenGL: Renderer: ' + glGetString(GL_RENDERER));
   985 AddFileLog('OpenGL - Renderer: ' + string(pchar(glGetString(GL_RENDERER))));
  1000 AddFileLog('OpenGL: Vendor: ' + glGetString(GL_VENDOR));
   986 AddFileLog('OpenGL - Vendor: ' + string(pchar(glGetString(GL_VENDOR))));
  1001 AddFileLog('OpenGL: Version: ' + glGetString(GL_VERSION));
   987 AddFileLog('OpenGL - Version: ' + string(pchar(glGetString(GL_VERSION))));
  1002 AddFileLog('OpenGL: GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize));
   988 AddFileLog('OpenGL - GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize));
  1003 {$ENDIF}
   989 {$ENDIF}
  1004 
   990 
  1005 if MaxTextureSize = 0 then
   991 if MaxTextureSize = 0 then
  1006 	begin
   992 	begin
       
   993 {$IFDEF DARWIN}
       
   994 	MaxTextureSize:= 2048;
       
   995 {$ELSE}
  1007 	MaxTextureSize:= 1024;
   996 	MaxTextureSize:= 1024;
       
   997 {$ENDIF}
  1008 {$IFDEF DEBUGFILE}
   998 {$IFDEF DEBUGFILE}
  1009 	AddFileLog('OpenGL: Warning - driver didn''t provide any valid max texture size; assuming 1024');
   999 	AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024');
  1010 {$ENDIF}
  1000 {$ENDIF}
  1011 	end;
  1001 	end;
  1012 
  1002 
  1013 vendor:= LowerCase(glGetString(GL_VENDOR));
  1003 vendor:= LowerCase(string(pchar(glGetString(GL_VENDOR))));
  1014 if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then
  1004 if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then
  1015 	cGPUVendor:= gvNVIDIA
  1005 	cGPUVendor:= gvNVIDIA
  1016 else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then
  1006 else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then
  1017 	cGPUVendor:= gvATI
  1007 	cGPUVendor:= gvATI
  1018 else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then
  1008 else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then
  1019 	cGPUVendor:= gvIntel;
  1009 	cGPUVendor:= gvIntel;
  1020 
  1010 
  1021 	
  1011 	
  1022 	
       
  1023 {$IFNDEF IPHONEOS}
  1012 {$IFNDEF IPHONEOS}
  1024 // since ATI seems to be unable to provide proper texture filtering/quality,
  1013 // since ATI seems to be unable to provide proper texture filtering/quality,
  1025 // don't even try to load the extension on ATI cards
  1014 // do not even try to load the extension on ATI cards
       
  1015 
       
  1016 {$IFDEF DARWIN}
       
  1017 if true then
       
  1018 {$ELSE}
  1026 if cGPUVendor <> gvATI then
  1019 if cGPUVendor <> gvATI then
       
  1020 {$ENDIF}
  1027 	SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two')
  1021 	SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two')
  1028 {$IFDEF DEBUGFILE}
  1022 {$IFDEF DEBUGFILE}
  1029 else
  1023 else
  1030 	AddFileLog('OpenGL: Skipped extension GL_ARB_texture_non_power_of_two due to ATI card')
  1024 	AddFileLog('OpenGL: Skipped extension GL_ARB_texture_non_power_of_two due to ATI card')
  1031 {$ENDIF}
  1025 {$ENDIF}
  1032 ; // don't touch this line! :)
  1026 ; // do not touch this line! :)
  1033 {$ENDIF}
  1027 {$ENDIF}
  1034 
  1028 
  1035 // set view port to whole window
  1029 // set view port to whole window
  1036 glViewport(0, 0, cScreenWidth, cScreenHeight);
  1030 glViewport(0, 0, cScreenWidth, cScreenHeight);
  1037 
  1031