-procedure TglBitmap2D.GenTexture(const aTestTextureSize: Boolean);
-var
- {$IFNDEF OPENGL_ES}
- BuildWithGlu, TexRec: Boolean;
- {$ENDIF}
- PotTex: Boolean;
- TexSize: Integer;
-begin
- if Assigned(Data) then begin
- // Check Texture Size
- if (aTestTextureSize) then begin
- glGetIntegerv(GL_MAX_TEXTURE_SIZE, @TexSize);
-
- if ((Height > TexSize) or (Width > TexSize)) then
- raise EglBitmapSizeToLarge.Create('TglBitmap2D.GenTexture - The size for the texture is to large. It''s may be not conform with the Hardware.');
-
- PotTex := IsPowerOfTwo(Height) and IsPowerOfTwo(Width);
-{$IF NOT DEFINED(OPENGL_ES)}
- TexRec := (GL_ARB_texture_rectangle or GL_EXT_texture_rectangle or GL_NV_texture_rectangle) and (Target = GL_TEXTURE_RECTANGLE);
- if not (PotTex or GL_ARB_texture_non_power_of_two or GL_VERSION_2_0 or TexRec) then
- raise EglBitmapNonPowerOfTwo.Create('TglBitmap2D.GenTexture - Rendercontex dosn''t support non power of two texture.');
-{$ELSEIF DEFINED(OPENGL_ES_EXT)}
- if not PotTex and not GL_OES_texture_npot then
- raise EglBitmapNonPowerOfTwo.Create('TglBitmap2D.GenTexture - Rendercontex dosn''t support non power of two texture.');
-{$ELSE}
- if not PotTex then
- raise EglBitmapNonPowerOfTwo.Create('TglBitmap2D.GenTexture - Rendercontex dosn''t support non power of two texture.');
-{$IFEND}
- end;
-
- CreateId;
- SetupParameters({$IFNDEF OPENGL_ES}BuildWithGlu{$ENDIF});
- UploadData(Target{$IFNDEF OPENGL_ES}, BuildWithGlu{$ENDIF});
-{$IFNDEF OPENGL_ES}
- glAreTexturesResident(1, @fID, @fIsResident);
-{$ENDIF}
- end;
-end;
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TglBitmap2D.FlipHorz: Boolean;
-var
- Col, Row: Integer;
- TempDestData, DestData, SourceData: PByte;
- ImgSize: Integer;
-begin
- result := inherited FlipHorz;
- if Assigned(Data) then begin
- SourceData := Data;
- ImgSize := Height * fRowSize;
- GetMem(DestData, ImgSize);
- try
- TempDestData := DestData;
- Dec(TempDestData, fRowSize + fPixelSize);
- for Row := 0 to Height -1 do begin
- Inc(TempDestData, fRowSize * 2);
- for Col := 0 to Width -1 do begin
- Move(SourceData^, TempDestData^, fPixelSize);
- Inc(SourceData, fPixelSize);
- Dec(TempDestData, fPixelSize);
- end;
- end;
- SetDataPointer(DestData, Format, Width, Height); //be careful, Data could be freed by this method
- result := true;
- except
- if Assigned(DestData) then
- FreeMem(DestData);
- raise;
- end;
- end;
-end;
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-function TglBitmap2D.FlipVert: Boolean;
-var
- Row: Integer;
- TempDestData, DestData, SourceData: PByte;
-begin
- result := inherited FlipVert;
- if Assigned(Data) then begin
- SourceData := Data;
- GetMem(DestData, Height * fRowSize);
- try
- TempDestData := DestData;
- Inc(TempDestData, Width * (Height -1) * fPixelSize);
- for Row := 0 to Height -1 do begin
- Move(SourceData^, TempDestData^, fRowSize);
- Dec(TempDestData, fRowSize);
- Inc(SourceData, fRowSize);
- end;
- SetDataPointer(DestData, Format, Width, Height); //be careful, Data could be freed by this method
- result := true;
- except
- if Assigned(DestData) then
- FreeMem(DestData);
- raise;
- end;
- end;
-end;
-
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//TglBitmap2D - ToNormalMap///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-type
- TMatrixItem = record
- X, Y: Integer;
- W: Single;
- end;
-
- PglBitmapToNormalMapRec = ^TglBitmapToNormalMapRec;
- TglBitmapToNormalMapRec = Record
- Scale: Single;
- Heights: array of Single;
- MatrixU : array of TMatrixItem;
- MatrixV : array of TMatrixItem;
- end;
-
-const
- ONE_OVER_255 = 1 / 255;
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-procedure glBitmapToNormalMapPrepareFunc(var FuncRec: TglBitmapFunctionRec);
-var
- Val: Single;
-begin
- with FuncRec do begin
- Val :=
- Source.Data.r * LUMINANCE_WEIGHT_R +
- Source.Data.g * LUMINANCE_WEIGHT_G +
- Source.Data.b * LUMINANCE_WEIGHT_B;
- PglBitmapToNormalMapRec(Args)^.Heights[Position.Y * Size.X + Position.X] := Val * ONE_OVER_255;
- end;