+//TglBitmap1D/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap1D.SetDataPointer(var aData: PByte; const aFormat: TglBitmapFormat;
+ const aWidth: Integer; const aHeight: Integer);
+var
+ pTemp: pByte;
+ Size: Integer;
+begin
+ if (aHeight > 1) then begin
+ Size := TFormatDescriptor.Get(aFormat).GetSize(aWidth, 1);
+ GetMem(pTemp, Size);
+ try
+ Move(aData^, pTemp^, Size);
+ FreeMem(aData);
+ aData := nil;
+ except
+ FreeMem(pTemp);
+ raise;
+ end;
+ end else
+ pTemp := aData;
+ inherited SetDataPointer(pTemp, aFormat, aWidth);
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+function TglBitmap1D.FlipHorz: Boolean;
+var
+ Col: Integer;
+ pTempDest, pDest, pSource: PByte;
+begin
+ result := inherited FlipHorz;
+ if Assigned(Data) and not TFormatDescriptor.Get(Format).IsCompressed then begin
+ pSource := Data;
+ GetMem(pDest, fRowSize);
+ try
+ pTempDest := pDest;
+ Inc(pTempDest, fRowSize);
+ for Col := 0 to Width-1 do begin
+ dec(pTempDest, fPixelSize); //dec before, because ptr is behind last byte of data
+ Move(pSource^, pTempDest^, fPixelSize);
+ Inc(pSource, fPixelSize);
+ end;
+ SetDataPointer(pDest, Format, Width); //be careful, Data could be freed by this method
+ result := true;
+ except
+ if Assigned(pDest) then
+ FreeMem(pDest);
+ raise;
+ end;
+ end;
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap1D.UploadData(const aBuildWithGlu: Boolean);
+var
+ FormatDesc: TFormatDescriptor;
+begin
+ // Upload data
+ FormatDesc := TFormatDescriptor.Get(Format);
+ if FormatDesc.IsCompressed then
+ glCompressedTexImage1D(Target, 0, FormatDesc.glInternalFormat, Width, 0, FormatDesc.GetSize(Width, 1), Data)
+ else if aBuildWithGlu then
+ gluBuild1DMipmaps(Target, FormatDesc.glInternalFormat, Width, FormatDesc.glFormat, FormatDesc.glDataFormat, Data)
+ else
+ glTexImage1D(Target, 0, FormatDesc.glInternalFormat, Width, 0, FormatDesc.glFormat, FormatDesc.glDataFormat, Data);
+
+ // Free Data
+ if (FreeDataAfterGenTexture) then
+ FreeData;
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap1D.GenTexture(const aTestTextureSize: Boolean);
+var
+ BuildWithGlu, TexRec: Boolean;
+ TexSize: Integer;
+begin
+ if Assigned(Data) then begin
+ // Check Texture Size
+ if (aTestTextureSize) then begin
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE, @TexSize);
+
+ if (Width > TexSize) then
+ raise EglBitmapSizeToLargeException.Create('TglBitmap1D.GenTexture - The size for the texture is to large. It''s may be not conform with the Hardware.');
+
+ TexRec := (GL_ARB_texture_rectangle or GL_EXT_texture_rectangle or GL_NV_texture_rectangle) and
+ (Target = GL_TEXTURE_RECTANGLE_ARB);
+ if not (IsPowerOfTwo(Width) or GL_ARB_texture_non_power_of_two or GL_VERSION_2_0 or TexRec) then
+ raise EglBitmapNonPowerOfTwoException.Create('TglBitmap1D.GenTexture - Rendercontex dosn''t support non power of two texture.');
+ end;
+
+ CreateId;
+ SetupParameters(BuildWithGlu);
+ UploadData(BuildWithGlu);
+ glAreTexturesResident(1, @fID, @fIsResident);
+ end;
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+procedure TglBitmap1D.AfterConstruction;
+begin
+ inherited;
+ Target := GL_TEXTURE_1D;
+end;
+
+//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////