hedgewars/uStore.pas
changeset 7138 f8248bcba8f1
parent 7129 0ce4f478ea6c
child 7186 013deb83086b
equal deleted inserted replaced
7136:6f3c9ec79338 7138:f8248bcba8f1
    43 
    43 
    44 procedure WarpMouse(x, y: Word); inline;
    44 procedure WarpMouse(x, y: Word); inline;
    45 procedure SwapBuffers; inline;
    45 procedure SwapBuffers; inline;
    46 procedure UpdateProjection;
    46 procedure UpdateProjection;
    47 
    47 
       
    48 {$IFDEF GL2}
       
    49 procedure UpdateModelviewProjection;
       
    50 {$ENDIF}
       
    51 
    48 implementation
    52 implementation
    49 uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands,
    53 uses uMisc, uConsole, uMobile, uVariables, uUtils, uTextures, uRender, uRenderUtils, uCommands,
    50      uDebug{$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF};
    54      uDebug{$IFDEF USE_CONTEXT_RESTORE}, uWorld{$ENDIF}, uMatrix;
    51 
    55 
    52 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    56 //type TGPUVendor = (gvUnknown, gvNVIDIA, gvATI, gvIntel, gvApple);
    53 
    57 
    54 var MaxTextureSize: LongInt;
    58 var MaxTextureSize: LongInt;
    55 {$IFDEF SDL13}
    59 {$IFDEF SDL13}
    58 {$ELSE}
    62 {$ELSE}
    59     SDLPrimSurface: PSDL_Surface;
    63     SDLPrimSurface: PSDL_Surface;
    60 {$ENDIF}
    64 {$ENDIF}
    61 {$IFDEF GL2}
    65 {$IFDEF GL2}
    62     Shader: GLuint;
    66     Shader: GLuint;
       
    67     uMVPLocation: GLint;
    63 {$ENDIF}
    68 {$ENDIF}
    64 
    69 
    65 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
    70 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: ansistring): TSDL_Rect;
    66 var w, h: LongInt;
    71 var w, h: LongInt;
    67     tmpsurf: PSDL_Surface;
    72     tmpsurf: PSDL_Surface;
   789 {$IFDEF GL2}
   794 {$IFDEF GL2}
   790     Load_GL_VERSION_2_0;
   795     Load_GL_VERSION_2_0;
   791     Shader:= CompileProgram('default');
   796     Shader:= CompileProgram('default');
   792     glUseProgram(Shader);
   797     glUseProgram(Shader);
   793     glUniform1i(glGetUniformLocation(Shader, 'tex'), 0);
   798     glUniform1i(glGetUniformLocation(Shader, 'tex'), 0);
       
   799     uMVPLocation:= glGetUniformLocation(Shader, 'mvp');
       
   800 
   794 {$ENDIF}
   801 {$ENDIF}
   795 
   802 
   796 {$IFNDEF S3D_DISABLED}
   803 {$IFNDEF S3D_DISABLED}
   797     if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then
   804     if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) or (cStereoMode = smAFR) then
   798     begin
   805     begin
   853     glEnable(GL_TEXTURE_2D);
   860     glEnable(GL_TEXTURE_2D);
   854     glEnableClientState(GL_VERTEX_ARRAY);
   861     glEnableClientState(GL_VERTEX_ARRAY);
   855     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   862     glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   856 end;
   863 end;
   857 
   864 
       
   865 {$IFDEF GL2}
       
   866 procedure UpdateModelviewProjection;
       
   867 var
       
   868     mvp: TMatrix4x4f;
       
   869 begin
       
   870     MatrixMultiply(mvp, mProjection, mModelview);
       
   871     glUniformMatrix4fv(uMVPLocation, 1, GL_FALSE, @mvp[0, 0]);
       
   872 end;
       
   873 {$ENDIF GL2}
       
   874 
   858 procedure UpdateProjection;
   875 procedure UpdateProjection;
   859 var mat: array[0..15] of GLfloat;
   876 var
   860     s: GLfloat;
   877     s: GLfloat;
   861 begin
   878 begin
   862     s:=cScaleFactor;
   879     s:=cScaleFactor;
       
   880     mProjection[0,0]:= s/cScreenWidth; mProjection[0,1]:=  0.0;             mProjection[0,2]:=0.0; mProjection[0,3]:=  0.0;
       
   881     mProjection[1,0]:= 0.0;            mProjection[1,1]:= -s/cScreenHeight; mProjection[1,2]:=0.0; mProjection[1,3]:=  0.0;
       
   882     mProjection[2,0]:= 0.0;            mProjection[2,1]:=  0.0;             mProjection[2,2]:=1.0; mProjection[2,3]:=  0.0;
       
   883     mProjection[3,0]:= cStereoDepth;   mProjection[3,1]:=  s/2;             mProjection[3,2]:=0.0; mProjection[3,3]:=  1.0;
       
   884 
       
   885     {$IFDEF GL2}
       
   886     UpdateModelviewProjection;
       
   887     {$ELSE}
   863     glMatrixMode(GL_PROJECTION);
   888     glMatrixMode(GL_PROJECTION);
   864     mat[ 0]:= s/cScreenWidth; mat[ 1]:=  0.0;             mat[ 2]:=0.0; mat[ 3]:=  0.0;
   889     glLoadMatrixf(@mProjection[0, 0]);
   865     mat[ 4]:= 0.0;            mat[ 5]:= -s/cScreenHeight; mat[ 6]:=0.0; mat[ 7]:=  0.0;
       
   866     mat[ 8]:= 0.0;            mat[ 9]:=  0.0;             mat[10]:=1.0; mat[11]:=  0.0;
       
   867     mat[12]:= cStereoDepth;   mat[13]:=  s/2;             mat[14]:=0.0; mat[15]:=  1.0;
       
   868     glLoadMatrixf(@mat);
       
   869     glMatrixMode(GL_MODELVIEW);
   890     glMatrixMode(GL_MODELVIEW);
       
   891     {$ENDIF}    
   870 end;
   892 end;
   871 
   893 
   872 procedure SetScale(f: GLfloat);
   894 procedure SetScale(f: GLfloat);
   873 begin
   895 begin
   874     // This lazy update conflicts with R7103 at the moment, missing the initial SetScale(2.0)
   896     // This lazy update conflicts with R7103 at the moment, missing the initial SetScale(2.0)