hedgewars/uRender.pas
changeset 10326 1748eed62a95
parent 10325 7315870716f2
child 10327 c3770d87311b
equal deleted inserted replaced
10325:7315870716f2 10326:1748eed62a95
   113     shaderMain: GLuint;
   113     shaderMain: GLuint;
   114     shaderWater: GLuint;
   114     shaderWater: GLuint;
   115 {$ENDIF}
   115 {$ENDIF}
   116 
   116 
   117 var LastTint: LongWord = 0;
   117 var LastTint: LongWord = 0;
       
   118     LastColorPointer , LastTexCoordPointer , LastVertexPointer : Pointer;
       
   119 {$IFDEF GL2}
       
   120     LastColorPointerN, LastTexCoordPointerN, LastVertexPointerN: Integer;
       
   121 {$ENDIF}
   118 
   122 
   119 function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline;
   123 function isAreaOffscreen(X, Y, Width, Height: LongInt): boolean; inline;
   120 begin
   124 begin
   121     isAreaOffscreen:= (isDxAreaOffscreen(X, Width) <> 0) or (isDyAreaOffscreen(Y, Height) <> 0);
   125     isAreaOffscreen:= (isDxAreaOffscreen(X, Width) <> 0) or (isDyAreaOffscreen(Y, Height) <> 0);
   122 end;
   126 end;
   544         glEnableVertexAttribArray(aColor);
   548         glEnableVertexAttribArray(aColor);
   545         {$ELSE}
   549         {$ELSE}
   546         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   550         glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   547         glEnableClientState(GL_COLOR_ARRAY);
   551         glEnableClientState(GL_COLOR_ARRAY);
   548         {$ENDIF}
   552         {$ENDIF}
       
   553         LastTexCoordPointer:= nil;
   549         end
   554         end
   550     else
   555     else
   551         begin
   556         begin
   552         {$IFDEF GL2}
   557         {$IFDEF GL2}
   553         glDisableVertexAttribArray(aColor);
   558         glDisableVertexAttribArray(aColor);
   554         glEnableVertexAttribArray(aTexCoord);
   559         glEnableVertexAttribArray(aTexCoord);
   555         {$ELSE}
   560         {$ELSE}
   556         glDisableClientState(GL_COLOR_ARRAY);
   561         glDisableClientState(GL_COLOR_ARRAY);
   557         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   562         glEnableClientState(GL_TEXTURE_COORD_ARRAY);
   558         {$ENDIF}
   563         {$ENDIF}
       
   564         LastColorPointer:= nil;
   559         end;
   565         end;
   560     EnableTexture(not b);
   566     EnableTexture(not b);
   561 end;
   567 end;
   562 
   568 
   563 procedure UpdateModelviewProjection(); inline;
   569 procedure UpdateModelviewProjection(); inline;
   576 end;
   582 end;
   577 
   583 
   578 procedure SetTexCoordPointer(p: Pointer; n: Integer);
   584 procedure SetTexCoordPointer(p: Pointer; n: Integer);
   579 begin
   585 begin
   580 {$IFDEF GL2}
   586 {$IFDEF GL2}
       
   587     if (p = LastTexCoordPointer) and (n = LastTexCoordPointerN) then
       
   588         exit;
   581     glBindBuffer(GL_ARRAY_BUFFER, tBuffer);
   589     glBindBuffer(GL_ARRAY_BUFFER, tBuffer);
   582     glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
   590     glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
   583     glEnableVertexAttribArray(aTexCoord);
   591     glEnableVertexAttribArray(aTexCoord);
   584     glVertexAttribPointer(aTexCoord, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
   592     glVertexAttribPointer(aTexCoord, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
       
   593     LastTexCoordPointer:= n;
   585 {$ELSE}
   594 {$ELSE}
       
   595     if p = LastTexCoordPointer then
       
   596         exit;
   586     n:= n;
   597     n:= n;
   587     glTexCoordPointer(2, GL_FLOAT, 0, p);
   598     glTexCoordPointer(2, GL_FLOAT, 0, p);
   588 {$ENDIF}
   599 {$ENDIF}
       
   600     LastTexCoordPointer:= p;
   589 end;
   601 end;
   590 
   602 
   591 procedure SetVertexPointer(p: Pointer; n: Integer);
   603 procedure SetVertexPointer(p: Pointer; n: Integer);
   592 begin
   604 begin
   593 {$IFDEF GL2}
   605 {$IFDEF GL2}
       
   606     if (p = LastVertexPointer) and (n = LastVertexPointerN) then
       
   607         exit;
   594     glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
   608     glBindBuffer(GL_ARRAY_BUFFER, vBuffer);
   595     glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
   609     glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * n * 2, p, GL_STATIC_DRAW);
   596     glEnableVertexAttribArray(aVertex);
   610     glEnableVertexAttribArray(aVertex);
   597     glVertexAttribPointer(aVertex, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
   611     glVertexAttribPointer(aVertex, 2, GL_FLOAT, GL_FALSE, 0, pointer(0));
       
   612     LastVertexPointer:= n;
   598 {$ELSE}
   613 {$ELSE}
       
   614     if p = LastVertexPointer then
       
   615         exit;
   599     n:= n;
   616     n:= n;
   600     glVertexPointer(2, GL_FLOAT, 0, p);
   617     glVertexPointer(2, GL_FLOAT, 0, p);
   601 {$ENDIF}
   618 {$ENDIF}
       
   619     LastVertexPointer:= p;
   602 end;
   620 end;
   603 
   621 
   604 procedure SetColorPointer(p: Pointer; n: Integer);
   622 procedure SetColorPointer(p: Pointer; n: Integer);
   605 begin
   623 begin
   606 {$IFDEF GL2}
   624 {$IFDEF GL2}
       
   625     if (p = LastColorPointer) and (n = LastColorPointerN) then
       
   626         exit;
   607     glBindBuffer(GL_ARRAY_BUFFER, cBuffer);
   627     glBindBuffer(GL_ARRAY_BUFFER, cBuffer);
   608     glBufferData(GL_ARRAY_BUFFER, n * 4, p, GL_STATIC_DRAW);
   628     glBufferData(GL_ARRAY_BUFFER, n * 4, p, GL_STATIC_DRAW);
   609     glEnableVertexAttribArray(aColor);
   629     glEnableVertexAttribArray(aColor);
   610     glVertexAttribPointer(aColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, pointer(0));
   630     glVertexAttribPointer(aColor, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, pointer(0));
       
   631     LastColorPointer:= n;
   611 {$ELSE}
   632 {$ELSE}
       
   633     if p = LastColorPointer then
       
   634         exit;
   612     n:= n;
   635     n:= n;
   613     glColorPointer(4, GL_UNSIGNED_BYTE, 0, p);
   636     glColorPointer(4, GL_UNSIGNED_BYTE, 0, p);
   614 {$ENDIF}
   637 {$ENDIF}
       
   638     LastColorPointer:= p;
   615 end;
   639 end;
   616 
   640 
   617 procedure EnableTexture(enable:Boolean);
   641 procedure EnableTexture(enable:Boolean);
   618 begin
   642 begin
   619     {$IFDEF GL2}
   643     {$IFDEF GL2}
  1440 var
  1464 var
  1441     nc, tw: Longword;
  1465     nc, tw: Longword;
  1442 begin
  1466 begin
  1443     nc:= (r shl 24) or (g shl 16) or (b shl 8) or a;
  1467     nc:= (r shl 24) or (g shl 16) or (b shl 8) or a;
  1444 
  1468 
  1445     if nc = lastTint then
  1469     if nc = LastTint then
  1446         exit;
  1470         exit;
  1447 
  1471 
  1448     if GrayScale then
  1472     if GrayScale then
  1449         begin
  1473         begin
  1450         tw:= round(r * RGB_LUMINANCE_RED + g * RGB_LUMINANCE_GREEN + b * RGB_LUMINANCE_BLUE);
  1474         tw:= round(r * RGB_LUMINANCE_RED + g * RGB_LUMINANCE_GREEN + b * RGB_LUMINANCE_BLUE);
  1454         g:= tw;
  1478         g:= tw;
  1455         b:= tw
  1479         b:= tw
  1456         end;
  1480         end;
  1457 
  1481 
  1458     openglTint(r, g, b, a);
  1482     openglTint(r, g, b, a);
  1459     lastTint:= nc;
  1483     LastTint:= nc;
  1460 end;
  1484 end;
  1461 
  1485 
  1462 procedure Tint(c: Longword); inline;
  1486 procedure Tint(c: Longword); inline;
  1463 begin
  1487 begin
  1464     if c = lastTint then exit;
  1488     if c = LastTint then exit;
  1465     Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF))
  1489     Tint(((c shr 24) and $FF), ((c shr 16) and $FF), (c shr 8) and $FF, (c and $FF))
  1466 end;
  1490 end;
  1467 
  1491 
  1468 procedure untint(); inline;
  1492 procedure untint(); inline;
  1469 begin
  1493 begin
  1470     if cWhiteColor = lastTint then exit;
  1494     if cWhiteColor = LastTint then exit;
  1471     openglTint($FF, $FF, $FF, $FF);
  1495     openglTint($FF, $FF, $FF, $FF);
  1472     lastTint:= cWhiteColor;
  1496     LastTint:= cWhiteColor;
  1473 end;
  1497 end;
  1474 
  1498 
  1475 procedure setTintAdd(f: boolean); inline;
  1499 procedure setTintAdd(f: boolean); inline;
  1476 begin
  1500 begin
  1477     if f then
  1501     if f then
  1480         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  1504         glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  1481 end;
  1505 end;
  1482 
  1506 
  1483 procedure initModule;
  1507 procedure initModule;
  1484 begin
  1508 begin
       
  1509     LastTint:= cWhiteColor + 1;
       
  1510     LastColorPointer    := nil;
       
  1511     LastTexCoordPointer := nil;
       
  1512     LastVertexPointer   := nil;
       
  1513 {$IFDEF GL2}
       
  1514     LastColorPointerN   :=   0;
       
  1515     LastTexCoordPointerN:=   0;
       
  1516     LastVertexPointerN  :=   0;
       
  1517 {$ENDIF}
  1485 end;
  1518 end;
  1486 
  1519 
  1487 procedure freeModule;
  1520 procedure freeModule;
  1488 begin
  1521 begin
  1489 {$IFDEF GL2}
  1522 {$IFDEF GL2}