From: Bergmann89 Date: Sun, 21 Sep 2014 15:34:53 +0000 (+0200) Subject: * added function to get FormatDescriptor from internal OpenGL Format X-Git-Tag: v3.1.2~12 X-Git-Url: https://git.delphigl.com/?p=glBitmap.git;a=commitdiff_plain;h=401bba6efa010fd58c8bd2f5d5e6067b3a7aaf97 * added function to get FormatDescriptor from internal OpenGL Format * fixed some hints / warnings --- diff --git a/glBitmap.pas b/glBitmap.pas index c13d85c..1be10f8 100644 --- a/glBitmap.pas +++ b/glBitmap.pas @@ -907,6 +907,8 @@ type property glFormat: GLenum read GetglFormat; property glInternalFormat: GLenum read GetglInternalFormat; property glDataFormat: GLenum read GetglDataFormat; + public + class function GetByFormat(const aInternalFormat: GLenum): TglBitmapFormatDescriptor; end; //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -3720,6 +3722,21 @@ begin end; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TglBitmapFormatDescriptor/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +class function TglBitmapFormatDescriptor.GetByFormat(const aInternalFormat: GLenum): TglBitmapFormatDescriptor; +var + f: TglBitmapFormat; +begin + for f := Low(TglBitmapFormat) to High(TglBitmapFormat) do begin + result := TFormatDescriptor.Get(f); + if (result.glInternalFormat = aInternalFormat) then + exit; + end; + result := TFormatDescriptor.Get(tfEmpty); +end; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //TFormatDescriptor/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class procedure TFormatDescriptor.Init; @@ -5002,7 +5019,7 @@ var bfFormat: TbmpBitfieldFormat; pSourceLine, pDestLine: PByte; pSourceMD, pDestMD: Pointer; - x, y: Cardinal; + x, y: Integer; pixel: TglBitmapPixelData; begin bfFormat := TbmpBitfieldFormat.Create; @@ -5017,7 +5034,7 @@ var pDestMD := FormatDesc.CreateMappingData; try for y := 0 to aImage.Height-1 do begin - pSourceLine := aImage.PixelData + y * aImage.DataDescription.BytesPerLine; + pSourceLine := aImage.PixelData + y {%H-}* aImage.DataDescription.BytesPerLine; pDestLine := ImageData + y * Round(FormatDesc.PixelSize * aImage.Width); for x := 0 to aImage.Width-1 do begin bfFormat.Unmap(pSourceLine, pixel, pSourceMD); @@ -5386,6 +5403,7 @@ var TempPtr: PByte; Size: Integer; begin + result := nil; Temp := (ClassType.Create as TglBitmap); try // copy texture data if assigned @@ -8051,9 +8069,9 @@ end; procedure TglBitmap2D.GetDataFromTexture; var Temp: PByte; - TempWidth, TempHeight: GLint; - TempIntFormat: GLenum; - IntFormat, f: TglBitmapFormat; + TempWidth, TempHeight: Integer; + TempIntFormat: GLint; + IntFormat: TglBitmapFormat; FormatDesc: TFormatDescriptor; begin Bind; @@ -8061,16 +8079,11 @@ begin // Request Data glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_WIDTH, @TempWidth); glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_HEIGHT, @TempHeight); - glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_INTERNAL_FORMAT, PGLint(@TempIntFormat)); + glGetTexLevelParameteriv(Target, 0, GL_TEXTURE_INTERNAL_FORMAT, @TempIntFormat); - IntFormat := tfEmpty; - for f := Low(TglBitmapFormat) to High(TglBitmapFormat) do begin - FormatDesc := TFormatDescriptor.Get(f); - if (FormatDesc.glInternalFormat = TempIntFormat) then begin - IntFormat := FormatDesc.Format; - break; - end; - end; + IntFormat := tfEmpty; + FormatDesc := (TglBitmapFormatDescriptor.GetByFormat(TempIntFormat) as TFormatDescriptor); + IntFormat := FormatDesc.Format; // Getting data from OpenGL FormatDesc := TFormatDescriptor.Get(IntFormat);