| @@ -304,7 +304,7 @@ type | |||||
| { possible mipmap types } | { possible mipmap types } | ||||
| TglBitmapMipMap = ( | TglBitmapMipMap = ( | ||||
| mmNone, //< no mipmaps | mmNone, //< no mipmaps | ||||
| mmMipmap, //< normal mipmaps | |||||
| mmMipmap, //< normal mipmaps, glGenerateMipmap for 3.0+ or GL_GENERATE_MIPMAP for legacy | |||||
| mmMipmapGlu); //< mipmaps generated with glu functions | mmMipmapGlu); //< mipmaps generated with glu functions | ||||
| { possible normal map functions } | { possible normal map functions } | ||||
| @@ -1009,7 +1009,7 @@ type | |||||
| procedure CreateID; | procedure CreateID; | ||||
| { setup texture parameters } | { setup texture parameters } | ||||
| procedure SetupParameters({$IFNDEF OPENGL_ES}out aBuildWithGlu: Boolean{$ENDIF}); | |||||
| procedure SetupParameters({$IFNDEF OPENGL_ES}out aRealMipMapMode: TglBitmapMipMap{$ENDIF}); | |||||
| protected | protected | ||||
| property Width: Integer read GetWidth; //< the actual width of the texture | property Width: Integer read GetWidth; //< the actual width of the texture | ||||
| @@ -1108,7 +1108,7 @@ type | |||||
| { upload the texture data to video card | { upload the texture data to video card | ||||
| @param aDataObj texture data object that contains the actual data | @param aDataObj texture data object that contains the actual data | ||||
| @param aBuildWithGlu use glu functions to build mipmaps } | @param aBuildWithGlu use glu functions to build mipmaps } | ||||
| procedure UploadDataIntern(const aDataObj: TglBitmapData; const aBuildWithGlu: Boolean); | |||||
| procedure UploadDataIntern(const aDataObj: TglBitmapData; const aRealMipMapMode: TglBitmapMipMap); | |||||
| public | public | ||||
| property Width; //< actual with of the texture | property Width; //< actual with of the texture | ||||
| @@ -1134,7 +1134,7 @@ type | |||||
| @param aTarget target o upload data to (e.g. GL_TEXTURE_2D) | @param aTarget target o upload data to (e.g. GL_TEXTURE_2D) | ||||
| @param aBuildWithGlu use glu functions to build mipmaps } | @param aBuildWithGlu use glu functions to build mipmaps } | ||||
| procedure UploadDataIntern(const aDataObj: TglBitmapData; const aTarget: GLenum | procedure UploadDataIntern(const aDataObj: TglBitmapData; const aTarget: GLenum | ||||
| {$IFNDEF OPENGL_ES}; const aBuildWithGlu: Boolean{$ENDIF}); | |||||
| {$IFNDEF OPENGL_ES}; const aRealMipMap: TglBitmapMipMap{$ENDIF}); | |||||
| public | public | ||||
| property Width; //< actual width of the texture | property Width; //< actual width of the texture | ||||
| @@ -8188,7 +8188,7 @@ begin | |||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TglBitmap.SetupParameters({$IFNDEF OPENGL_ES}out aBuildWithGlu: Boolean{$ENDIF}); | |||||
| procedure TglBitmap.SetupParameters({$IFNDEF OPENGL_ES}out aRealMipMapMode: TglBitmapMipMap{$ENDIF}); | |||||
| begin | begin | ||||
| // Set Up Parameters | // Set Up Parameters | ||||
| SetWrap(fWrapS, fWrapT, fWrapR); | SetWrap(fWrapS, fWrapT, fWrapR); | ||||
| @@ -8203,17 +8203,26 @@ begin | |||||
| {$IFNDEF OPENGL_ES} | {$IFNDEF OPENGL_ES} | ||||
| // Mip Maps Generation Mode | // Mip Maps Generation Mode | ||||
| aBuildWithGlu := false; | |||||
| if (MipMap = mmMipmap) then begin | |||||
| if (GL_VERSION_1_4 or GL_SGIS_generate_mipmap) then | |||||
| glTexParameteri(Target, GL_GENERATE_MIPMAP, GLint(GL_TRUE)) | |||||
| else | |||||
| aBuildWithGlu := true; | |||||
| end else if (MipMap = mmMipmapGlu) then | |||||
| aBuildWithGlu := true; | |||||
| aRealMipMapMode:= mmNone; | |||||
| case MipMap of | |||||
| mmNone: begin | |||||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0); | |||||
| glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0); | |||||
| end; | |||||
| mmMipmap: begin | |||||
| if GL_VERSION_3_0 or GL_ARB_framebuffer_object then | |||||
| aRealMipMapMode:= mmMipmap | |||||
| else if GL_VERSION_1_4 or GL_SGIS_generate_mipmap then begin | |||||
| glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GLint(GL_TRUE)); | |||||
| aRealMipMapMode:= mmNone; | |||||
| end else | |||||
| aRealMipMapMode:= mmMipmapGlu; | |||||
| end; | |||||
| mmMipmapGlu: aRealMipMapMode:= mmMipmapGlu; | |||||
| end; | |||||
| {$ELSE} | {$ELSE} | ||||
| if (MipMap = mmMipmap) then | |||||
| glGenerateMipmap(Target); | |||||
| if MipMap <> mmNone then | |||||
| aRealMipMapMode:= mmMipmap; | |||||
| {$ENDIF} | {$ENDIF} | ||||
| end; | end; | ||||
| @@ -8502,7 +8511,7 @@ begin | |||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TglBitmap1D.UploadDataIntern(const aDataObj: TglBitmapData; const aBuildWithGlu: Boolean); | |||||
| procedure TglBitmap1D.UploadDataIntern(const aDataObj: TglBitmapData; const aRealMipMapMode: TglBitmapMipMap); | |||||
| var | var | ||||
| fd: TglBitmapFormatDescriptor; | fd: TglBitmapFormatDescriptor; | ||||
| begin | begin | ||||
| @@ -8514,18 +8523,24 @@ begin | |||||
| if fd.IsCompressed then begin | if fd.IsCompressed then begin | ||||
| if not Assigned(glCompressedTexImage1D) then | if not Assigned(glCompressedTexImage1D) then | ||||
| raise EglBitmap.Create('compressed formats not supported by video adapter'); | raise EglBitmap.Create('compressed formats not supported by video adapter'); | ||||
| glCompressedTexImage1D(Target, 0, fd.glInternalFormat, aDataObj.Width, 0, fd.GetSize(aDataObj.Width, 1), aDataObj.Data) | |||||
| end else if aBuildWithGlu then | |||||
| glCompressedTexImage1D(Target, 0, fd.glInternalFormat, aDataObj.Width, 0, fd.GetSize(aDataObj.Width, 1), aDataObj.Data); | |||||
| if aRealMipMapMode = mmMipmap then | |||||
| glGenerateMipmap(Target); | |||||
| end else if aRealMipMapMode = mmMipmapGlu then | |||||
| gluBuild1DMipmaps(Target, fd.glInternalFormat, aDataObj.Width, fd.glFormat, fd.glDataFormat, aDataObj.Data) | gluBuild1DMipmaps(Target, fd.glInternalFormat, aDataObj.Width, fd.glFormat, fd.glDataFormat, aDataObj.Data) | ||||
| else | |||||
| else begin | |||||
| glTexImage1D(Target, 0, fd.glInternalFormat, aDataObj.Width, 0, fd.glFormat, fd.glDataFormat, aDataObj.Data); | glTexImage1D(Target, 0, fd.glInternalFormat, aDataObj.Width, 0, fd.glFormat, fd.glDataFormat, aDataObj.Data); | ||||
| if aRealMipMapMode = mmMipmap then | |||||
| glGenerateMipmap(Target); | |||||
| end; | |||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TglBitmap1D.UploadData(const aDataObj: TglBitmapData; const aCheckSize: Boolean); | procedure TglBitmap1D.UploadData(const aDataObj: TglBitmapData; const aCheckSize: Boolean); | ||||
| var | var | ||||
| BuildWithGlu, TexRec: Boolean; | |||||
| TexRec: Boolean; | |||||
| TexSize: Integer; | TexSize: Integer; | ||||
| realMM: TglBitmapMipMap; | |||||
| begin | begin | ||||
| if not Assigned(aDataObj) then | if not Assigned(aDataObj) then | ||||
| exit; | exit; | ||||
| @@ -8547,8 +8562,8 @@ begin | |||||
| if (fID = 0) then | if (fID = 0) then | ||||
| CreateID; | CreateID; | ||||
| SetupParameters(BuildWithGlu); | |||||
| UploadDataIntern(aDataObj, BuildWithGlu); | |||||
| SetupParameters(realMM); | |||||
| UploadDataIntern(aDataObj, realMM); | |||||
| glAreTexturesResident(1, @fID, @fIsResident); | glAreTexturesResident(1, @fID, @fIsResident); | ||||
| end; | end; | ||||
| {$ENDIF} | {$ENDIF} | ||||
| @@ -8563,7 +8578,7 @@ begin | |||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||
| procedure TglBitmap2D.UploadDataIntern(const aDataObj: TglBitmapData; const aTarget: GLenum{$IFNDEF OPENGL_ES}; const aBuildWithGlu: Boolean{$ENDIF}); | |||||
| procedure TglBitmap2D.UploadDataIntern(const aDataObj: TglBitmapData; const aTarget: GLenum{$IFNDEF OPENGL_ES}; const aRealMipMap: TglBitmapMipMap{$ENDIF}); | |||||
| var | var | ||||
| fd: TglBitmapFormatDescriptor; | fd: TglBitmapFormatDescriptor; | ||||
| begin | begin | ||||
| @@ -8576,13 +8591,17 @@ begin | |||||
| if fd.IsCompressed then begin | if fd.IsCompressed then begin | ||||
| if not Assigned(glCompressedTexImage2D) then | if not Assigned(glCompressedTexImage2D) then | ||||
| raise EglBitmap.Create('compressed formats not supported by video adapter'); | raise EglBitmap.Create('compressed formats not supported by video adapter'); | ||||
| glCompressedTexImage2D(aTarget, 0, fd.glInternalFormat, aDataObj.Width, aDataObj.Height, 0, fd.GetSize(fDimension), aDataObj.Data) | |||||
| glCompressedTexImage2D(aTarget, 0, fd.glInternalFormat, aDataObj.Width, aDataObj.Height, 0, fd.GetSize(fDimension), aDataObj.Data); | |||||
| if aRealMipMap = mmMipmap then | |||||
| glGenerateMipmap(aTarget); | |||||
| {$IFNDEF OPENGL_ES} | {$IFNDEF OPENGL_ES} | ||||
| end else if aBuildWithGlu then begin | |||||
| end else if aRealMipMap = mmMipmapGlu then begin | |||||
| gluBuild2DMipmaps(aTarget, fd.ChannelCount, aDataObj.Width, aDataObj.Height, fd.glFormat, fd.glDataFormat, aDataObj.Data) | gluBuild2DMipmaps(aTarget, fd.ChannelCount, aDataObj.Width, aDataObj.Height, fd.glFormat, fd.glDataFormat, aDataObj.Data) | ||||
| {$ENDIF} | {$ENDIF} | ||||
| end else begin | end else begin | ||||
| glTexImage2D(aTarget, 0, fd.glInternalFormat, aDataObj.Width, aDataObj.Height, 0, fd.glFormat, fd.glDataFormat, aDataObj.Data); | glTexImage2D(aTarget, 0, fd.glInternalFormat, aDataObj.Width, aDataObj.Height, 0, fd.glFormat, fd.glDataFormat, aDataObj.Data); | ||||
| if aRealMipMap = mmMipmap then | |||||
| glGenerateMipmap(aTarget); | |||||
| end; | end; | ||||
| end; | end; | ||||
| @@ -8590,7 +8609,8 @@ end; | |||||
| procedure TglBitmap2D.UploadData(const aDataObj: TglBitmapData; const aCheckSize: Boolean); | procedure TglBitmap2D.UploadData(const aDataObj: TglBitmapData; const aCheckSize: Boolean); | ||||
| var | var | ||||
| {$IFNDEF OPENGL_ES} | {$IFNDEF OPENGL_ES} | ||||
| BuildWithGlu, TexRec: Boolean; | |||||
| TexRec: Boolean; | |||||
| realMM: TglBitmapMipMap; | |||||
| {$ENDIF} | {$ENDIF} | ||||
| PotTex: Boolean; | PotTex: Boolean; | ||||
| TexSize: Integer; | TexSize: Integer; | ||||
| @@ -8623,8 +8643,8 @@ begin | |||||
| if (fID = 0) then | if (fID = 0) then | ||||
| CreateID; | CreateID; | ||||
| SetupParameters({$IFNDEF OPENGL_ES}BuildWithGlu{$ENDIF}); | |||||
| UploadDataIntern(aDataObj, Target{$IFNDEF OPENGL_ES}, BuildWithGlu{$ENDIF}); | |||||
| SetupParameters({$IFNDEF OPENGL_ES}realMM{$ENDIF}); | |||||
| UploadDataIntern(aDataObj, Target{$IFNDEF OPENGL_ES}, realMM{$ENDIF}); | |||||
| {$IFNDEF OPENGL_ES} | {$IFNDEF OPENGL_ES} | ||||
| glAreTexturesResident(1, @fID, @fIsResident); | glAreTexturesResident(1, @fID, @fIsResident); | ||||
| {$ENDIF} | {$ENDIF} | ||||
| @@ -8690,7 +8710,7 @@ end; | |||||
| procedure TglBitmapCubeMap.UploadCubeMap(const aDataObj: TglBitmapData; const aCubeTarget: Cardinal; const aCheckSize: Boolean); | procedure TglBitmapCubeMap.UploadCubeMap(const aDataObj: TglBitmapData; const aCubeTarget: Cardinal; const aCheckSize: Boolean); | ||||
| var | var | ||||
| {$IFNDEF OPENGL_ES} | {$IFNDEF OPENGL_ES} | ||||
| BuildWithGlu: Boolean; | |||||
| realMM: TglBitmapMipMap; | |||||
| {$ENDIF} | {$ENDIF} | ||||
| TexSize: Integer; | TexSize: Integer; | ||||
| begin | begin | ||||
| @@ -8716,8 +8736,8 @@ begin | |||||
| if (fID = 0) then | if (fID = 0) then | ||||
| CreateID; | CreateID; | ||||
| SetupParameters({$IFNDEF OPENGL_ES}BuildWithGlu{$ENDIF}); | |||||
| UploadDataIntern(aDataObj, aCubeTarget{$IFNDEF OPENGL_ES}, BuildWithGlu{$ENDIF}); | |||||
| SetupParameters({$IFNDEF OPENGL_ES}realMM{$ENDIF}); | |||||
| UploadDataIntern(aDataObj, aCubeTarget{$IFNDEF OPENGL_ES}, realMM{$ENDIF}); | |||||
| end; | end; | ||||
| ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||||