hedgewars/uStore.pas
changeset 5660 1647244b3ffe
parent 5654 1cb68f420aa6
child 5662 99083392cd4f
equal deleted inserted replaced
5658:76220933369f 5660:1647244b3ffe
    42 procedure MakeCrossHairs;
    42 procedure MakeCrossHairs;
    43 
    43 
    44 implementation
    44 implementation
    45 uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands, uDebug;
    45 uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands, uDebug;
    46 
    46 
    47 type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    47 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    48 
    48 
    49 var MaxTextureSize: LongInt;
    49 var MaxTextureSize: LongInt;
    50     cGPUVendor: TGPUVendor;
    50 //    cGPUVendor: TGPUVendor;
    51 
    51 
    52 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
    52 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
    53 var w, h: LongInt;
    53 var w, h: LongInt;
    54     tmpsurf: PSDL_Surface;
    54     tmpsurf: PSDL_Surface;
    55     clr: TSDL_Color;
    55     clr: TSDL_Color;
   561     else
   561     else
   562         AddFileLog('OpenGL - "' + extension + '" failed to load');
   562         AddFileLog('OpenGL - "' + extension + '" failed to load');
   563 {$ENDIF}
   563 {$ENDIF}
   564 end;
   564 end;
   565 
   565 
   566 procedure SetupOpenGL;
   566 procedure SetupOpenGLAttributes;
   567 var vendor: shortstring = '';
   567 begin
   568 {$IFDEF DARWIN}
       
   569 const one : LongInt = 1;
       
   570 {$ENDIF}
       
   571 begin
       
   572 {$IFDEF SDL13}
       
   573     // this function creates an opengles1.1 context by default on mobile devices
       
   574     // use SDL_GL_SetAttribute to change this behaviour
       
   575     SDLGLcontext:=SDL_GL_CreateContext(SDLwindow);
       
   576     SDLTry(SDLGLcontext <> nil, true);
       
   577     SDL_GL_SetSwapInterval(1);
       
   578 {$ENDIF}
       
   579 
       
   580 {$IFDEF IPHONEOS}
   568 {$IFDEF IPHONEOS}
   581     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
   569     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
   582     SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
   570     SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
   583     vendor:= vendor; // avoid hint
       
   584     one:= one; // avoid hint
       
   585 {$ELSE}
   571 {$ELSE}
   586     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
   572     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
   587     vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR))));
   573 {$IFNDEF SDL13} // vsync is default in 1.3
   588 {$IFNDEF SDL13}
       
   589 // this attribute is default in 1.3 and must be enabled in MacOSX
       
   590     SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, LongInt((cReducedQuality and rqDesyncVBlank) = 0));
   574     SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, LongInt((cReducedQuality and rqDesyncVBlank) = 0));
   591 
       
   592 {$IFDEF DARWIN}
       
   593 // fixes vsync in Snow Leopard
       
   594     CGLSetParameter(CGLGetCurrentContext(), 222, @one);
       
   595 {$ENDIF}
       
   596 {$ENDIF}
   575 {$ENDIF}
   597 {$ENDIF}
   576 {$ENDIF}
   598     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); // no depth buffer
   577     SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); // no depth buffer
   599     SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
   578     SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
   600     SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
   579     SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
   601     SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
   580     SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
   602     SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); // no alpha channel required
   581     SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); // no alpha channel required
   603     SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); // buffer has to be 16 bit only
   582     SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 16); // buffer has to be 16 bit only
   604     SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // try to prefer hardware rendering
   583     SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); // try to prefer hardware rendering
   605 
   584 end;
       
   585 
       
   586 procedure SetupOpenGL;
       
   587 //var vendor: shortstring = '';
       
   588 begin
       
   589 {$IFDEF SDL13}
       
   590     // this function creates an opengles1.1 context by default on mobile devices
       
   591     // use SDL_GL_SetAttribute to change this behaviour
       
   592     SDLGLcontext:=SDL_GL_CreateContext(SDLwindow);
       
   593     SDLTry(SDLGLcontext <> nil, true);
       
   594     SDL_GL_SetSwapInterval(1);
       
   595 {$ENDIF}
       
   596 
       
   597     // get the max (horizontal and vertical) size for textures that the gpu can support
   606     glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
   598     glGetIntegerv(GL_MAX_TEXTURE_SIZE, @MaxTextureSize);
   607 
       
   608     AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER))));
       
   609     AddFileLog('  |----- Vendor: ' + shortstring(pchar(glGetString(GL_VENDOR))));
       
   610     AddFileLog('  |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION))));
       
   611     AddFileLog('  \----- GL_MAX_TEXTURE_SIZE: ' + inttostr(MaxTextureSize));
       
   612 
       
   613     if MaxTextureSize <= 0 then
   599     if MaxTextureSize <= 0 then
   614         begin
   600         begin
   615         MaxTextureSize:= 1024;
   601         MaxTextureSize:= 1024;
   616         AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024');
   602         AddFileLog('OpenGL Warning - driver didn''t provide any valid max texture size; assuming 1024');
   617         end
   603         end
   619         begin
   605         begin
   620         cReducedQuality := cReducedQuality or rqNoBackground;  
   606         cReducedQuality := cReducedQuality or rqNoBackground;  
   621         AddFileLog('Texture size too small for backgrounds, disabling.');
   607         AddFileLog('Texture size too small for backgrounds, disabling.');
   622         end;
   608         end;
   623 
   609 
       
   610 (*  // find out which gpu we are using (for extension compatibility maybe?)
   624 {$IFDEF IPHONEOS}
   611 {$IFDEF IPHONEOS}
       
   612     vendor:= vendor; // avoid hint
   625     cGPUVendor:= gvApple;
   613     cGPUVendor:= gvApple;
   626 {$ELSE}
   614 {$ELSE}
       
   615     vendor:= LowerCase(shortstring(pchar(glGetString(GL_VENDOR))));
   627     if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then
   616     if StrPos(Str2PChar(vendor), Str2PChar('nvidia')) <> nil then
   628         cGPUVendor:= gvNVIDIA
   617         cGPUVendor:= gvNVIDIA
   629     else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then
   618     else if StrPos(Str2PChar(vendor), Str2PChar('intel')) <> nil then
   630         cGPUVendor:= gvATI
   619         cGPUVendor:= gvATI
   631     else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then
   620     else if StrPos(Str2PChar(vendor), Str2PChar('ati')) <> nil then
   632         cGPUVendor:= gvIntel;
   621         cGPUVendor:= gvIntel
       
   622     else
       
   623         AddFileLog('OpenGL Warning - unknown hardware vendor; please report');
   633 {$ENDIF}
   624 {$ENDIF}
   634 //SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two');
   625 //SupportNPOTT:= glLoadExtension('GL_ARB_texture_non_power_of_two');
       
   626 *)
       
   627 
       
   628     // everyone love debugging
       
   629     AddFileLog('OpenGL-- Renderer: ' + shortstring(pchar(glGetString(GL_RENDERER))));
       
   630     AddFileLog('  |----- Vendor: ' + shortstring(pchar(glGetString(GL_VENDOR))));
       
   631     AddFileLog('  |----- Version: ' + shortstring(pchar(glGetString(GL_VERSION))));
       
   632     AddFileLog('  \----- Texture Size: ' + inttostr(MaxTextureSize));
       
   633 
   635 {$IFNDEF S3D_DISABLED}
   634 {$IFNDEF S3D_DISABLED}
   636     if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then
   635     if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then
   637     begin
   636     begin
   638         // prepare left and right frame buffers and associated textures
   637         // prepare left and right frame buffers and associated textures
   639         if glLoadExtension('GL_EXT_framebuffer_object') then
   638         if glLoadExtension('GL_EXT_framebuffer_object') then
   672         else
   671         else
   673             cStereoMode:= smNone;
   672             cStereoMode:= smNone;
   674     end;
   673     end;
   675 {$ENDIF}
   674 {$ENDIF}
   676 
   675 
   677     if cGPUVendor = gvUnknown then
       
   678         AddFileLog('OpenGL Warning - unknown hardware vendor; please report');
       
   679 
       
   680     // set view port to whole window
   676     // set view port to whole window
   681     if (rotationQt = 0) or (rotationQt = 180) then
   677     if (rotationQt = 0) or (rotationQt = 180) then
   682         glViewport(0, 0, cScreenWidth, cScreenHeight)
   678         glViewport(0, 0, cScreenWidth, cScreenHeight)
   683     else
   679     else
   684         glViewport(0, 0, cScreenHeight, cScreenWidth);
   680         glViewport(0, 0, cScreenHeight, cScreenWidth);
   955     s:= s; // avoid compiler hint
   951     s:= s; // avoid compiler hint
   956     if Length(s) = 0 then cFullScreen:= not cFullScreen
   952     if Length(s) = 0 then cFullScreen:= not cFullScreen
   957     else cFullScreen:= s = '1';
   953     else cFullScreen:= s = '1';
   958 
   954 
   959     buf[0]:= char(0); // avoid compiler hint
   955     buf[0]:= char(0); // avoid compiler hint
   960     AddFileLog('Prepare to change video parameters...');
   956     AddFileLog('Preparing to change video parameters...');
   961 
   957 
   962     flags:= SDL_OPENGL;// or SDL_RESIZABLE;
   958     reinit:= false;
   963 
   959     if SDLPrimSurface = nil then
   964     if cFullScreen then
   960         begin
   965         flags:= flags or SDL_FULLSCREEN;
   961         // set window title
   966 
   962         SDL_WM_SetCaption('Hedgewars', nil);
   967 {$IFDEF SDL_IMAGE_NEWER}
   963 {$IFDEF SDL_IMAGE_NEWER}
   968     WriteToConsole('Init SDL_image... ');
   964         WriteToConsole('Init SDL_image... ');
   969     SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
   965         SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
   970     WriteLnToConsole(msgOK);
   966         WriteLnToConsole(msgOK);
   971 {$ENDIF}
   967 {$ENDIF}
   972     // load engine icon
   968         // load engine icon
   973 {$IFDEF DARWIN}
   969 {$IFDEF DARWIN}
   974     ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine_mac', ifIgnoreCaps);
   970         ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine_mac', ifIgnoreCaps);
   975     if ico = nil then ico:= LoadImage(Pathz[ptGraphics] + '/hwengine_mac', ifIgnoreCaps);
   971         if ico = nil then ico:= LoadImage(Pathz[ptGraphics] + '/hwengine_mac', ifIgnoreCaps);
   976 {$ELSE}
   972 {$ELSE}
   977     ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
   973         ico:= LoadImage(UserPathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
   978     if ico = nil then ico:= LoadImage(Pathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
   974         if ico = nil then ico:= LoadImage(Pathz[ptGraphics] + '/hwengine', ifIgnoreCaps);
   979 {$ENDIF}
   975 {$ENDIF}
   980     if ico <> nil then
   976         if ico <> nil then
   981     begin
   977             begin
   982         SDL_WM_SetIcon(ico, 0);
   978             SDL_WM_SetIcon(ico, 0);
   983         SDL_FreeSurface(ico)
   979             SDL_FreeSurface(ico)
   984     end;
   980             end;
   985 
   981         end
   986     // set window title
   982     else
   987     SDL_WM_SetCaption('Hedgewars', nil);
   983         begin
   988     reinit:= false;
       
   989     if SDLPrimSurface <> nil then
       
   990     begin
       
   991 {$IFDEF DARWIN | WIN32}
   984 {$IFDEF DARWIN | WIN32}
   992         reinit:= true;
   985         reinit:= true;
   993 {$ENDIF}
   986 {$ENDIF}
   994         AddFileLog('Freeing old primary surface...');
   987         AddFileLog('Freeing old primary surface...');
   995         SDL_FreeSurface(SDLPrimSurface);
   988         SDL_FreeSurface(SDLPrimSurface);
   996         SDLPrimSurface:= nil;
   989         SDLPrimSurface:= nil;
   997     end;
   990         end;
   998 
   991 
       
   992     // these attributes must be set up before creating the sdl window
       
   993     SetupOpenGLAttributes();
   999 {$IFDEF SDL13}
   994 {$IFDEF SDL13}
  1000     // these values in x and y make the window appear in the center
   995     // these values in x and y make the window appear in the center
  1001     x:= SDL_WINDOWPOS_CENTERED_MASK;
   996     x:= SDL_WINDOWPOS_CENTERED_MASK;
  1002     y:= SDL_WINDOWPOS_CENTERED_MASK;
   997     y:= SDL_WINDOWPOS_CENTERED_MASK;
  1003     flags:= SDL_WINDOW_OPENGL or SDL_WINDOW_SHOWN;
   998     flags:= SDL_WINDOW_OPENGL or SDL_WINDOW_SHOWN;
  1011 {$ENDIF}
  1006 {$ENDIF}
  1012 
  1007 
  1013     SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags);
  1008     SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags);
  1014     SDLTry(SDLwindow <> nil, true);
  1009     SDLTry(SDLwindow <> nil, true);
  1015 {$ELSE}
  1010 {$ELSE}
       
  1011     flags:= SDL_OPENGL;// or SDL_RESIZABLE;
       
  1012     if cFullScreen then
       
  1013         flags:= flags or SDL_FULLSCREEN;
       
  1014 
  1016     if not cOnlyStats then
  1015     if not cOnlyStats then
  1017         begin
  1016         begin
  1018 {$IFDEF WIN32}
  1017 {$IFDEF WIN32}
  1019         s:= SDL_getenv('SDL_VIDEO_CENTERED');
  1018         s:= SDL_getenv('SDL_VIDEO_CENTERED');
  1020         SDL_putenv('SDL_VIDEO_CENTERED=1');
  1019         SDL_putenv('SDL_VIDEO_CENTERED=1');
  1045 begin
  1044 begin
  1046     RegisterVariable('fullscr', vtCommand, @chFullScr, true);
  1045     RegisterVariable('fullscr', vtCommand, @chFullScr, true);
  1047 
  1046 
  1048     SDLPrimSurface:= nil;
  1047     SDLPrimSurface:= nil;
  1049 
  1048 
  1050 {$IFNDEF IPHONEOS}
       
  1051     rotationQt:= 0;
  1049     rotationQt:= 0;
  1052     cGPUVendor:= gvUnknown;
       
  1053 {$ENDIF}
       
  1054 
       
  1055     cScaleFactor:= 2.0;
  1050     cScaleFactor:= 2.0;
  1056     SupportNPOTT:= false;
       
  1057     Step:= 0;
  1051     Step:= 0;
  1058     ProgrTex:= nil;
  1052     ProgrTex:= nil;
       
  1053     SupportNPOTT:= false;
       
  1054 //    cGPUVendor:= gvUnknown;
  1059 
  1055 
  1060     // init all ammo name texture pointers
  1056     // init all ammo name texture pointers
  1061     for ai:= Low(TAmmoType) to High(TAmmoType) do
  1057     for ai:= Low(TAmmoType) to High(TAmmoType) do
  1062     begin
  1058     begin
  1063         Ammoz[ai].NameTex := nil;
  1059         Ammoz[ai].NameTex := nil;