2
// This unit is part of the GLScene Engine https://github.com/glscene
5
This unit provides support for two new types of "multisample
6
textures" - two-dimensional and two-dimensional array - as well as
7
mechanisms to fetch a specific sample from such a texture in a shader,
8
and to attach such textures to FBOs for rendering.
11
04/11/10- DaStr - Added $I GLScene.inc
12
23/08/10 - Yar - Added OpenGLTokens to uses, replaced OpenGL1x functions to OpenGLAdapter
13
16/05/10 - Yar - Creation (thanks to C4)
16
unit GLMultisampleImage;
32
// TGLMultisampleImage
34
TGLMultisampleImage = class(TGLTextureImage)
38
FSamplesCount: Integer;
39
FWidth, FHeight, FDepth: Integer;
40
FFixedSamplesLocation: Boolean;
41
procedure SetWidth(val: Integer);
42
procedure SetHeight(val: Integer);
43
procedure SetDepth(val: Integer);
44
procedure SetSamplesCount(val: Integer);
45
procedure SetFixedSamplesLocation(val: Boolean);
48
function GetWidth: Integer; override;
49
function GetHeight: Integer; override;
50
function GetDepth: Integer; override;
51
function GetTextureTarget: TGLTextureTarget; override;
54
constructor Create(AOwner: TPersistent); override;
55
destructor Destroy; override;
57
procedure Assign(Source: TPersistent); override;
59
class function IsSelfLoading: Boolean; override;
60
procedure LoadTexture(AInternalFormat: TGLInternalFormat); override;
61
function GetBitmap32: TGLBitmap32; override;
62
procedure ReleaseBitmap32; override;
64
procedure SaveToFile(const fileName: string); override;
65
procedure LoadFromFile(const fileName: string); override;
66
class function FriendlyName: string; override;
67
class function FriendlyDescription: string; override;
69
property NativeTextureTarget;
73
{ Width of the blank image (for memory allocation). }
74
property Width: Integer read GetWidth write SetWidth default 256;
75
{ Width of the blank image (for memory allocation). }
76
property Height: Integer read GetHeight write SetHeight default 256;
77
property Depth: Integer read GetDepth write SetDepth default 0;
78
property SamplesCount: Integer read FSamplesCount write SetSamplesCount
80
property FixedSamplesLocation: Boolean read FFixedSamplesLocation write
81
SetFixedSamplesLocation;
87
// ------------------ TGLMultisampleImage ------------------
90
{$IFDEF GLS_REGIONS}{$REGION 'TGLMultisampleImage'}{$ENDIF}
95
constructor TGLMultisampleImage.Create(AOwner: TPersistent);
107
destructor TGLMultisampleImage.Destroy;
116
procedure TGLMultisampleImage.Assign(Source: TPersistent);
118
if Assigned(Source) then
120
if (Source is TGLMultisampleImage) then
122
FWidth := TGLMultisampleImage(Source).FWidth;
123
FHeight := TGLMultisampleImage(Source).FHeight;
124
FDepth := TGLMultisampleImage(Source).FDepth;
125
FSamplesCount := TGLMultisampleImage(Source).FSamplesCount;
138
procedure TGLMultisampleImage.SetWidth(val: Integer);
140
if val <> FWidth then
152
function TGLMultisampleImage.GetWidth: Integer;
160
procedure TGLMultisampleImage.SetHeight(val: Integer);
162
if val <> FHeight then
174
function TGLMultisampleImage.GetHeight: Integer;
182
function TGLMultisampleImage.GetDepth: Integer;
190
procedure TGLMultisampleImage.SetDepth(val: Integer);
192
if val <> FDepth then
204
procedure TGLMultisampleImage.SetSamplesCount(val: Integer);
209
if val <> FSamplesCount then
211
FSamplesCount := val;
216
// SetFixedSamplesLocation
219
procedure TGLMultisampleImage.SetFixedSamplesLocation(val: Boolean);
221
if val <> FFixedSamplesLocation then
223
FFixedSamplesLocation := val;
231
function TGLMultisampleImage.GetBitmap32: TGLBitmap32;
233
if not Assigned(FBitmap) then
235
FBitmap := TGLBitmap32.Create;
236
FBitmap.Blank := true;
237
FBitmap.Width := FWidth;
238
FBitmap.Height := FHeight;
246
procedure TGLMultisampleImage.ReleaseBitmap32;
255
procedure TGLMultisampleImage.SaveToFile(const fileName: string);
262
procedure TGLMultisampleImage.LoadFromFile(const fileName: string);
269
class function TGLMultisampleImage.FriendlyName: string;
271
Result := 'Multisample Image';
274
// FriendlyDescription
277
class function TGLMultisampleImage.FriendlyDescription: string;
279
Result := 'Image for rendering to texture with antialiasing';
285
function TGLMultisampleImage.GetTextureTarget: TGLTextureTarget;
288
Result := ttTexture2DMultisampleArray
290
Result := ttTexture2DMultisample;
293
class function TGLMultisampleImage.IsSelfLoading: Boolean;
298
procedure TGLMultisampleImage.LoadTexture(AInternalFormat: TGLInternalFormat);
300
target: TGLTextureTarget;
301
maxSamples, maxSize: TGLint;
303
// Check smaples count range
304
GL.GetIntegerv(GL_MAX_SAMPLES, @maxSamples);
305
if FSamplesCount > maxSamples then
306
FSamplesCount := maxSamples;
307
if IsDepthFormat(AInternalFormat) then
309
GL.GetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES, @maxSamples);
310
if FSamplesCount > maxSamples then
311
FSamplesCount := maxSamples;
315
GL.GetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, @maxSamples);
316
if FSamplesCount > maxSamples then
317
FSamplesCount := maxSamples;
319
// Check texture size
320
GL.GetIntegerv(GL_MAX_TEXTURE_SIZE, @maxSize);
321
if FWidth > maxSize then
323
if FHeight > maxSize then
326
target := NativeTextureTarget;
329
ttTexture2DMultisample:
330
GL.TexImage2DMultisample(
331
DecodeGLTextureTarget(target),
333
InternalFormatToOpenGLFormat(AInternalFormat),
336
FFixedSamplesLocation);
338
ttTexture2DMultisampleArray:
339
GL.TexImage3DMultisample(
340
DecodeGLTextureTarget(target),
342
InternalFormatToOpenGLFormat(AInternalFormat),
346
FFixedSamplesLocation);
350
{$IFDEF GLS_REGIONS}{$ENDREGION}{$ENDIF}
353
RegisterGLTextureImageClass(TGLMultisampleImage);