| 1 |
{%MainUnit castleglimages.pas} |
| 2 |
{ |
| 3 |
Copyright 2001-2023 Michalis Kamburelis. |
| 4 |
|
| 5 |
This file is part of "Castle Game Engine". |
| 6 |
|
| 7 |
"Castle Game Engine" is free software; see the file COPYING.txt, |
| 8 |
included in this distribution, for details about the copyright. |
| 9 |
|
| 10 |
"Castle Game Engine" is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 |
|
| 14 |
---------------------------------------------------------------------------- |
| 15 |
} |
| 16 |
|
| 17 |
{ Part of CastleGLImages unit: texture filtering (TTextureFilter and friends). } |
| 18 |
|
| 19 |
{$ifdef read_interface} |
| 20 |
|
| 21 |
{$ifdef read_interface_type} |
| 22 |
// type - don't add type Delphi can't parse that correctly |
| 23 |
{ We recommend using CastleRenderOptions unit to get these types. |
| 24 |
But for backward compatibility, they are also available here. } |
| 25 |
TMinificationFilter = CastleRenderOptions.TMinificationFilter; |
| 26 |
TMagnificationFilter = CastleRenderOptions.TMagnificationFilter; |
| 27 |
|
| 28 |
TTextureFilter = record |
| 29 |
public |
| 30 |
Magnification: TMagnificationFilter; |
| 31 |
Minification: TMinificationFilter; |
| 32 |
function NeedsMipmaps: boolean; |
| 33 |
procedure DisableMipmaps; |
| 34 |
class operator {$ifdef FPC}={$else}Equal{$endif} (const V1, V2: TTextureFilter): boolean; |
| 35 |
end; |
| 36 |
{$endif read_interface_type} |
| 37 |
|
| 38 |
{$ifdef read_interface_func} |
| 39 |
function TextureFilter(const Minification: TMinificationFilter; |
| 40 |
const Magnification: TMagnificationFilter): TTextureFilter; |
| 41 |
|
| 42 |
{ Set current texture minification and magnification filter. |
| 43 |
|
| 44 |
This is just a thin wrapper for calling |
| 45 |
@longCode(# |
| 46 |
glTexParameteri(Target, GL_TEXTURE_MIN_FILTER, ...); |
| 47 |
glTexParameteri(Target, GL_TEXTURE_MAG_FILTER, ...); |
| 48 |
#) } |
| 49 |
procedure SetTextureFilter(const Target: TGLenum; const Filter: TTextureFilter); |
| 50 |
{$endif read_interface_func} |
| 51 |
|
| 52 |
{$ifdef read_interface_const} |
| 53 |
const |
| 54 |
{ We recommend using CastleRenderOptions unit to get these constants. |
| 55 |
But for backward compatibility, they are also available here. } |
| 56 |
minNearest = CastleRenderOptions.minNearest; |
| 57 |
minLinear = CastleRenderOptions.minLinear; |
| 58 |
minNearestMipmapNearest = CastleRenderOptions.minNearestMipmapNearest; |
| 59 |
minNearestMipmapLinear = CastleRenderOptions.minNearestMipmapLinear; |
| 60 |
minLinearMipmapNearest = CastleRenderOptions.minLinearMipmapNearest; |
| 61 |
minLinearMipmapLinear = CastleRenderOptions.minLinearMipmapLinear; |
| 62 |
magNearest = CastleRenderOptions.magNearest; |
| 63 |
magLinear = CastleRenderOptions.magLinear; |
| 64 |
{$endif read_interface_const} |
| 65 |
|
| 66 |
{$endif read_interface} |
| 67 |
|
| 68 |
{$ifdef read_implementation} |
| 69 |
|
| 70 |
procedure SetTextureFilter(const Target: TGLenum; const Filter: TTextureFilter); |
| 71 |
const |
| 72 |
MinFilterGL: array [TMinificationFilter] of TGLint = |
| 73 |
( GL_NEAREST, |
| 74 |
GL_LINEAR, |
| 75 |
GL_NEAREST_MIPMAP_NEAREST, |
| 76 |
GL_NEAREST_MIPMAP_LINEAR, |
| 77 |
GL_LINEAR_MIPMAP_NEAREST, |
| 78 |
GL_LINEAR_MIPMAP_LINEAR ); |
| 79 |
MagFilterGL: array [TMagnificationFilter] of TGLint = |
| 80 |
( GL_NEAREST, |
| 81 |
GL_LINEAR ); |
| 82 |
begin |
| 83 |
glTexParameteri(Target, GL_TEXTURE_MIN_FILTER, MinFilterGL[Filter.Minification]); |
| 84 |
glTexParameteri(Target, GL_TEXTURE_MAG_FILTER, MagFilterGL[Filter.Magnification]); |
| 85 |
end; |
| 86 |
|
| 87 |
function TTextureFilter.NeedsMipmaps: boolean; |
| 88 |
begin |
| 89 |
Result := Minification in |
| 90 |
[ minNearestMipmapNearest, |
| 91 |
minNearestMipmapLinear, |
| 92 |
minLinearMipmapNearest, |
| 93 |
minLinearMipmapLinear ]; |
| 94 |
end; |
| 95 |
|
| 96 |
procedure TTextureFilter.DisableMipmaps; |
| 97 |
begin |
| 98 |
if NeedsMipmaps then |
| 99 |
begin |
| 100 |
Minification := minLinear; |
| 101 |
Assert(not NeedsMipmaps); |
| 102 |
end; |
| 103 |
end; |
| 104 |
|
| 105 |
class operator TTextureFilter.{$ifdef FPC}={$else}Equal{$endif} |
| 106 |
(const V1, V2: TTextureFilter): boolean; |
| 107 |
begin |
| 108 |
Result := |
| 109 |
(V1.Minification = V2.Minification ) and |
| 110 |
(V1.Magnification = V2.Magnification); |
| 111 |
end; |
| 112 |
|
| 113 |
function TextureFilter(const Minification: TMinificationFilter; |
| 114 |
const Magnification: TMagnificationFilter): TTextureFilter; |
| 115 |
begin |
| 116 |
Result.Minification := Minification; |
| 117 |
Result.Magnification := Magnification; |
| 118 |
end; |
| 119 |
|
| 120 |
{$endif read_implementation} |