--- a/hedgewars/uStore.pas Tue Sep 08 19:20:58 2015 +0300
+++ b/hedgewars/uStore.pas Mon Nov 16 22:57:24 2015 +0300
@@ -55,25 +55,20 @@
procedure InitOffscreenOpenGL;
{$ENDIF}
-{$IFDEF SDL2}
procedure WarpMouse(x, y: Word); inline;
-{$ENDIF}
procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
procedure SetSkyColor(r, g, b: real);
implementation
uses uMisc, uConsole, uVariables, uUtils, uTextures, uRender, uRenderUtils,
uCommands, uPhysFSLayer, uDebug
- {$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF}
- {$IF NOT DEFINED(SDL2) AND DEFINED(USE_VIDEO_RECORDING)}, glut {$ENDIF};
+ {$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF};
-var
-{$IFDEF SDL2}
+//type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
+
+var
SDLwindow: PSDL_Window;
SDLGLcontext: PSDL_GLContext;
-{$ELSE}
- SDLPrimSurface: PSDL_Surface;
-{$ENDIF}
squaresize : LongInt;
numsquares : LongInt;
ProgrTex: PTexture;
@@ -117,9 +112,9 @@
clr.g:= (Color shr 8) and $FF;
clr.b:= Color and $FF;
tmpsurf:= TTF_RenderUTF8_Blended(Fontz[Font].Handle, s, clr);
-SDLTry(tmpsurf <> nil, true);
+SDLTry(tmpsurf <> nil, 'TTF_RenderUTF8_Blended', true);
tmpsurf:= doSurfaceConversion(tmpsurf);
-SDLTry(tmpsurf <> nil, true);
+SDLTry(tmpsurf <> nil, 'TTF_RenderUTF8_Blended, doSurfaceConversion', true);
SDL_UpperBlit(tmpsurf, nil, Surface, @finalRect);
SDL_FreeSurface(tmpsurf);
finalRect.x:= X;
@@ -361,7 +356,7 @@
s:= cPathz[ptFonts] + '/' + Name;
WriteToConsole(msgLoading + s + ' (' + inttostr(Height) + 'pt)... ');
Handle:= TTF_OpenFontRW(rwopsOpenRead(s), true, Height);
- SDLTry(Handle <> nil, true);
+ SDLTry(Handle <> nil, 'TTF_OpenFontRW', true);
TTF_SetFontStyle(Handle, style);
WriteLnToConsole(msgOK)
end;
@@ -370,7 +365,11 @@
begin
MakeCrossHairs;
LoadGraves;
+{$IFDEF IPHONEOS}
+ tmpHatSurf:= LoadDataImage(ptHats, 'chef', ifNone);
+{$ELSE}
tmpHatSurf:= LoadDataImage(ptHats, 'Reserved/chef', ifNone);
+{$ENDIF}
ChefHatTexture:= Surface2Tex(tmpHatSurf, true);
freeTmpHatSurf();
end;
@@ -606,7 +605,7 @@
// anounce that loading failed
OutError(msgFailed, false);
- SDLTry(false, (imageFlags and ifCritical) <> 0);
+ SDLTry(false, 'LoadImage', (imageFlags and ifCritical) <> 0);
// rwops was already freed by IMG_Load_RW
rwops:= nil;
end else
@@ -719,12 +718,12 @@
{$IFDEF IPHONEOS}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 0);
SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, 1);
+
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
{$ELSE}
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
{$ENDIF}
-{$IFNDEF SDL2} // vsync is default in SDL2
- SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, LongInt((cReducedQuality and rqDesyncVBlank) = 0));
-{$ENDIF}
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
@@ -737,38 +736,22 @@
procedure SetupOpenGL;
var buf: array[byte] of char;
begin
+ AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_GetCurrentVideoDriver()) + ')');
-{$IFDEF SDL2}
- AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_GetCurrentVideoDriver()) + ')');
-{$ELSE}
- buf[0]:= char(0); // avoid compiler hint
- AddFileLog('Setting up OpenGL (using driver: ' + shortstring(SDL_VideoDriverName(buf, sizeof(buf))) + ')');
-{$ENDIF}
+ // TODO: this function creates an opengles1.1 context
+ // un-comment below and add proper logic to support opengles2.0
+ //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+ //SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+ if SDLGLcontext = nil then
+ SDLGLcontext:= SDL_GL_CreateContext(SDLwindow);
+ SDLTry(SDLGLcontext <> nil, 'SDLGLcontext', true);
+ SDLTry(SDL_GL_SetSwapInterval(1) = 0, 'SDL_GL_SetSwapInterval', true);
RendererSetup();
+
+// gl2 init/matrix code was here, but removed
end;
-(*
-procedure UpdateProjection;
-var
- s: GLfloat;
-begin
- s:=cScaleFactor;
- mProjection[0,0]:= s/cScreenWidth; mProjection[0,1]:= 0.0; mProjection[0,2]:=0.0; mProjection[0,3]:= 0.0;
- mProjection[1,0]:= 0.0; mProjection[1,1]:= -s/cScreenHeight; mProjection[1,2]:=0.0; mProjection[1,3]:= 0.0;
- mProjection[2,0]:= 0.0; mProjection[2,1]:= 0.0; mProjection[2,2]:=1.0; mProjection[2,3]:= 0.0;
- mProjection[3,0]:= cStereoDepth; mProjection[3,1]:= s/2; mProjection[3,2]:=0.0; mProjection[3,3]:= 1.0;
-
-{$IFDEF GL2}
- UpdateModelviewProjection;
-{$ELSE}
- glMatrixMode(GL_PROJECTION);
- glLoadMatrixf(@mProjection[0, 0]);
- glMatrixMode(GL_MODELVIEW);
-{$ENDIF}
-end;
-*)
-
////////////////////////////////////////////////////////////////////////////////
procedure AddProgress;
var r: TSDL_Rect;
@@ -998,41 +981,23 @@
end;
{$IFDEF USE_VIDEO_RECORDING}
-{$IFDEF SDL2}
procedure InitOffscreenOpenGL;
begin
// create hidden window
- SDLwindow:= SDL_CreateWindow('hedgewars video rendering (SDL2 hidden window)',
+ SDLwindow:= SDL_CreateWindow(PChar('hedgewars video rendering (SDL2 hidden window)'),
SDL_WINDOWPOS_CENTERED_MASK, SDL_WINDOWPOS_CENTERED_MASK,
cScreenWidth, cScreenHeight,
SDL_WINDOW_HIDDEN or SDL_WINDOW_OPENGL);
- SDLTry(SDLwindow <> nil, true);
+ SDLTry(SDLwindow <> nil, 'SDL_CreateWindow', true);
SetupOpenGL();
end;
-{$ELSE}
-procedure InitOffscreenOpenGL;
-var ArgCount: LongInt;
- PrgName: pchar;
-begin
- ArgCount:= 1;
- PrgName:= 'hwengine';
- glutInit(@ArgCount, @PrgName);
- glutInitWindowSize(cScreenWidth, cScreenHeight);
- // we do not need a window, but without this call OpenGL will not initialize
- glutCreateWindow('hedgewars video rendering (glut hidden window)');
- glutHideWindow();
- // we do not need to set this callback, but it is required for GLUT3 compat
- glutDisplayFunc(@SwapBuffers);
- RendererSetup();
-end;
-{$ENDIF} // SDL2
{$ENDIF} // USE_VIDEO_RECORDING
procedure chFullScr(var s: shortstring);
var flags: Longword = 0;
reinit: boolean = false;
{$IFNDEF DARWIN}ico: PSDL_Surface;{$ENDIF}
- {$IFDEF SDL2}x, y: LongInt;{$ENDIF}
+ x, y: LongInt;
begin
if cOnlyStats then
begin
@@ -1055,28 +1020,12 @@
end;
AddFileLog('Preparing to change video parameters...');
-{$IFDEF SDL2}
if SDLwindow = nil then
-{$ELSE}
- if SDLPrimSurface = nil then
-{$ENDIF}
begin
// set window title
- {$IFNDEF SDL2}
- SDL_WM_SetCaption(_P'Hedgewars', nil);
- {$ENDIF}
WriteToConsole('Init SDL_image... ');
- SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, true);
+ SDLTry(IMG_Init(IMG_INIT_PNG) <> 0, 'IMG_Init', true);
WriteLnToConsole(msgOK);
- // load engine icon
- {$IFNDEF DARWIN}
- ico:= LoadDataImage(ptGraphics, 'hwengine', ifIgnoreCaps);
- if ico <> nil then
- begin
- SDL_WM_SetIcon(ico, 0);
- SDL_FreeSurface(ico)
- end;
- {$ENDIF}
end
else
begin
@@ -1101,10 +1050,6 @@
//uTextures.freeModule; //DEBUG ONLY
{$ENDIF}
AddFileLog('Freeing old primary surface...');
- {$IFNDEF SDL2}
- SDL_FreeSurface(SDLPrimSurface);
- SDLPrimSurface:= nil;
- {$ENDIF}
{$ENDIF}
end;
@@ -1118,7 +1063,6 @@
*)
SetupOpenGLAttributes();
{$ENDIF}
-{$IFDEF SDL2}
// these values in x and y make the window appear in the center
x:= SDL_WINDOWPOS_CENTERED_MASK;
y:= SDL_WINDOWPOS_CENTERED_MASK;
@@ -1137,26 +1081,18 @@
flags:= flags or SDL_WINDOW_FULLSCREEN;
if SDLwindow = nil then
- SDLwindow:= SDL_CreateWindow('Hedgewars', x, y, cScreenWidth, cScreenHeight, flags);
- SDLTry(SDLwindow <> nil, true);
-{$ELSE}
- flags:= SDL_OPENGL or SDL_RESIZABLE;
- if cFullScreen then
- flags:= flags or SDL_FULLSCREEN;
- if not cOnlyStats then
+ SDLwindow:= SDL_CreateWindow(PChar('Hedgewars'), x, y, cScreenWidth, cScreenHeight, flags);
+ SDLTry(SDLwindow <> nil, 'SDL_CreateWindow', true);
+
+ // load engine ico
+ {$IFNDEF DARWIN}
+ ico:= LoadDataImage(ptGraphics, 'hwengine', ifIgnoreCaps);
+ if ico <> nil then
begin
- {$IFDEF WIN32}
- s:= SDL_getenv('SDL_VIDEO_CENTERED');
- SDL_putenv('SDL_VIDEO_CENTERED=1');
+ SDL_SetWindowIcon(SDLwindow, ico);
+ SDL_FreeSurface(ico);
+ end;
{$ENDIF}
- SDLPrimSurface:= SDL_SetVideoMode(cScreenWidth, cScreenHeight, 0, flags);
- SDLTry(SDLPrimSurface <> nil, true);
- {$IFDEF WIN32}
- SDL_putenv(str2pchar('SDL_VIDEO_CENTERED=' + s));
- {$ENDIF}
- end;
-{$ENDIF}
-
SetupOpenGL();
if reinit then
@@ -1179,7 +1115,6 @@
end;
end;
-{$IFDEF SDL2}
// for sdl1.2 we directly call SDL_WarpMouse()
// for sdl2 we provide a SDL_WarpMouse() which just calls this function
// this has the advantage of reducing 'uses' and 'ifdef' statements
@@ -1188,17 +1123,12 @@
begin
SDL_WarpMouseInWindow(SDLwindow, x, y);
end;
-{$ENDIF}
procedure SwapBuffers; {$IFDEF USE_VIDEO_RECORDING}cdecl{$ELSE}inline{$ENDIF};
begin
if GameType = gmtRecord then
exit;
-{$IFDEF SDL2}
SDL_GL_SwapWindow(SDLwindow);
-{$ELSE}
- SDL_GL_SwapBuffers();
-{$ENDIF}
end;
procedure SetSkyColor(r, g, b: real);
@@ -1226,12 +1156,8 @@
// init all count texture pointers
for i:= Low(CountTexz) to High(CountTexz) do
CountTexz[i] := nil;
-{$IFDEF SDL2}
SDLwindow:= nil;
SDLGLcontext:= nil;
-{$ELSE}
- SDLPrimSurface:= nil;
-{$ENDIF}
prevHat:= 'NoHat';
tmpHatSurf:= nil;
@@ -1253,10 +1179,8 @@
end;
TTF_Quit();
-{$IFDEF SDL2}
SDL_GL_DeleteContext(SDLGLcontext);
SDL_DestroyWindow(SDLwindow);
-{$ENDIF}
SDL_Quit();
end;
end.