hedgewars/uRender.pas
branchqmlfrontend
changeset 11071 3851ce4f2061
parent 10886 99273b7afbff
parent 11046 47a8c19ecb60
child 11403 b894922d58cc
equal deleted inserted replaced
11050:9b7c8c5a94e0 11071:3851ce4f2061
     1 (*
     1 (*
     2  * Hedgewars, a free turn based strategy game
     2  * Hedgewars, a free turn based strategy game
     3  * Copyright (c) 2004-2014 Andrey Korotaev <unC0Rr@gmail.com>
     3  * Copyright (c) 2004-2015 Andrey Korotaev <unC0Rr@gmail.com>
     4  *
     4  *
     5  * This program is free software; you can redistribute it and/or modify
     5  * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7  * the Free Software Foundation; version 2 of the License
     8  *
     8  *
    58 procedure DrawScreenWidget      (widget: POnScreenWidget);
    58 procedure DrawScreenWidget      (widget: POnScreenWidget);
    59 procedure DrawWater             (Alpha: byte; OffsetY, OffsetX: LongInt);
    59 procedure DrawWater             (Alpha: byte; OffsetY, OffsetX: LongInt);
    60 procedure DrawWaves             (Dir, dX, dY, oX: LongInt; tnt: Byte);
    60 procedure DrawWaves             (Dir, dX, dY, oX: LongInt; tnt: Byte);
    61 
    61 
    62 procedure RenderClear           ();
    62 procedure RenderClear           ();
       
    63 {$IFDEF USE_S3D_RENDERING}
    63 procedure RenderClear           (mode: TRenderMode);
    64 procedure RenderClear           (mode: TRenderMode);
       
    65 {$ENDIF}
    64 procedure RenderSetClearColor   (r, g, b, a: real);
    66 procedure RenderSetClearColor   (r, g, b, a: real);
    65 procedure Tint                  (r, g, b, a: Byte); inline;
    67 procedure Tint                  (r, g, b, a: Byte); inline;
    66 procedure Tint                  (c: Longword); inline;
    68 procedure Tint                  (c: Longword); inline;
    67 procedure untint(); inline;
    69 procedure untint(); inline;
    68 procedure setTintAdd            (f: boolean); inline;
    70 procedure setTintAdd            (f: boolean); inline;
   133 procedure openglTranslProjMatrix(X, Y, Z: GLFloat); forward;
   135 procedure openglTranslProjMatrix(X, Y, Z: GLFloat); forward;
   134 procedure openglScalef          (ScaleX, ScaleY, ScaleZ: GLfloat); forward;
   136 procedure openglScalef          (ScaleX, ScaleY, ScaleZ: GLfloat); forward;
   135 procedure openglRotatef         (RotX, RotY, RotZ: GLfloat; dir: LongInt); forward;
   137 procedure openglRotatef         (RotX, RotY, RotZ: GLfloat; dir: LongInt); forward;
   136 procedure openglTint            (r, g, b, a: Byte); forward;
   138 procedure openglTint            (r, g, b, a: Byte); forward;
   137 
   139 
       
   140 {$IFDEF USE_S3D_RENDERING OR USE_VIDEO_RECORDING}
   138 procedure CreateFramebuffer(var frame, depth, tex: GLuint); forward;
   141 procedure CreateFramebuffer(var frame, depth, tex: GLuint); forward;
   139 procedure DeleteFramebuffer(var frame, depth, tex: GLuint); forward;
   142 procedure DeleteFramebuffer(var frame, depth, tex: GLuint); forward;
       
   143 {$ENDIF}
   140 
   144 
   141 function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline;
   145 function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline;
   142 begin
   146 begin
   143     isAreaOffscreen:= (isDxAreaOffscreen(X, Width) <> 0) or (isDyAreaOffscreen(Y, Height) <> 0);
   147     isAreaOffscreen:= (isDxAreaOffscreen(X, Width) <> 0) or (isDyAreaOffscreen(Y, Height) <> 0);
   144 end;
   148 end;
   466     tmpstr := StrPas(PChar(glGetString(GL_EXTENSIONS)));
   470     tmpstr := StrPas(PChar(glGetString(GL_EXTENSIONS)));
   467     tmpn := WordCount(tmpstr, [' ']);
   471     tmpn := WordCount(tmpstr, [' ']);
   468     tmpint := 1;
   472     tmpint := 1;
   469 
   473 
   470     repeat
   474     repeat
   471     begin
   475         begin
   472         // print up to 3 extentions per row
   476         // print up to 3 extentions per row
   473         // ExtractWord will return empty string if index out of range
   477         // ExtractWord will return empty string if index out of range
   474         AddFileLog(TrimRight(
   478         AddFileLog(TrimRight(
   475             ExtractWord(tmpint, tmpstr, [' ']) + ' ' +
   479             ExtractWord(tmpint, tmpstr, [' ']) + ' ' +
   476             ExtractWord(tmpint+1, tmpstr, [' ']) + ' ' +
   480             ExtractWord(tmpint+1, tmpstr, [' ']) + ' ' +
   477             ExtractWord(tmpint+2, tmpstr, [' '])
   481             ExtractWord(tmpint+2, tmpstr, [' '])
   478         ));
   482         ));
   479         tmpint := tmpint + 3;
   483         tmpint := tmpint + 3;
   480     end;
   484         end;
   481     until (tmpint > tmpn);
   485     until (tmpint > tmpn);
   482 {$ENDIF}
   486 {$ENDIF}
   483     AddFileLog('');
   487     AddFileLog('');
   484 
   488 
   485     defaultFrame:= 0;
   489     defaultFrame:= 0;
   486 
   490 
   487 {$IFDEF USE_VIDEO_RECORDING}
   491 {$IFDEF USE_VIDEO_RECORDING}
   488     if GameType = gmtRecord then
   492     if GameType = gmtRecord then
   489     begin
   493         begin
   490         if glLoadExtension('GL_EXT_framebuffer_object') then
   494         if glLoadExtension('GL_EXT_framebuffer_object') then
   491         begin
   495             begin
   492             CreateFramebuffer(defaultFrame, depthv, texv);
   496             CreateFramebuffer(defaultFrame, depthv, texv);
   493             glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, defaultFrame);
   497             glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, defaultFrame);
   494             AddFileLog('Using framebuffer for video recording.');
   498             AddFileLog('Using framebuffer for video recording.');
   495         end
   499             end
   496         else if AuxBufNum > 0 then
   500         else if AuxBufNum > 0 then
   497         begin
   501             begin
   498             glDrawBuffer(GL_AUX0);
   502             glDrawBuffer(GL_AUX0);
   499             glReadBuffer(GL_AUX0);
   503             glReadBuffer(GL_AUX0);
   500             AddFileLog('Using auxiliary buffer for video recording.');
   504             AddFileLog('Using auxiliary buffer for video recording.');
   501         end
   505             end
   502         else
   506         else
   503         begin
   507             begin
   504             glDrawBuffer(GL_BACK);
   508             glDrawBuffer(GL_BACK);
   505             glReadBuffer(GL_BACK);
   509             glReadBuffer(GL_BACK);
   506             AddFileLog('Warning: off-screen rendering is not supported; using back buffer but it may not work.');
   510             AddFileLog('Warning: off-screen rendering is not supported; using back buffer but it may not work.');
       
   511             end;
   507         end;
   512         end;
   508     end;
       
   509 {$ENDIF}
   513 {$ENDIF}
   510 
   514 
   511 {$IFDEF GL2}
   515 {$IFDEF GL2}
   512 
   516 
   513 {$IFDEF PAS2C}
   517 {$IFDEF PAS2C}
   514     err := glewInit();
   518     err := glewInit();
   515     if err <> GLEW_OK then
   519     if err <> GLEW_OK then
   516     begin
   520         begin
   517         WriteLnToConsole('Failed to initialize GLEW.');
   521         WriteLnToConsole('Failed to initialize GLEW.');
   518         halt(HaltStartupError);
   522         halt(HaltStartupError);
   519     end;
   523         end;
   520 {$ENDIF}
   524 {$ENDIF}
   521 
   525 
   522 {$IFNDEF PAS2C}
   526 {$IFNDEF PAS2C}
   523     if not Load_GL_VERSION_2_0 then
   527     if not Load_GL_VERSION_2_0 then
   524         halt;
   528         halt;
   541     UpdateModelviewProjection;
   545     UpdateModelviewProjection;
   542 {$ENDIF}
   546 {$ENDIF}
   543 
   547 
   544 {$IFDEF USE_S3D_RENDERING}
   548 {$IFDEF USE_S3D_RENDERING}
   545     if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
   549     if (cStereoMode = smHorizontal) or (cStereoMode = smVertical) then
   546     begin
   550         begin
   547         // prepare left and right frame buffers and associated textures
   551         // prepare left and right frame buffers and associated textures
   548         if glLoadExtension('GL_EXT_framebuffer_object') then
   552         if glLoadExtension('GL_EXT_framebuffer_object') then
   549             begin
   553             begin
   550             CreateFramebuffer(framel, depthl, texl);
   554             CreateFramebuffer(framel, depthl, texl);
   551             CreateFramebuffer(framer, depthr, texr);
   555             CreateFramebuffer(framer, depthr, texr);
   556             // reset
   560             // reset
   557             glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, defaultFrame)
   561             glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, defaultFrame)
   558             end
   562             end
   559         else
   563         else
   560             cStereoMode:= smNone;
   564             cStereoMode:= smNone;
   561     end;
   565         end;
   562 
   566 
   563     // set up vertex/texture buffers for frame textures
   567     // set up vertex/texture buffers for frame textures
   564     texLRDtb[0].X:= 0.0;
   568     texLRDtb[0].X:= 0.0;
   565     texLRDtb[0].Y:= 0.0;
   569     texLRDtb[0].Y:= 0.0;
   566     texLRDtb[1].X:= 1.0;
   570     texLRDtb[1].X:= 1.0;