1
unit LUX.GPU.OpenGL.Atom.Framer;
3
interface //#################################################################### ■
5
uses Winapi.OpenGL, Winapi.OpenGLext,
6
System.Generics.Collections,
7
LUX, LUX.GPU.OpenGL.Atom, LUX.GPU.OpenGL.Atom.Chaner;
9
type //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【型】
16
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【レコード】
18
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【クラス】
20
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLColors
22
TGLColors = class( TDictionary<Integer,IGLChaner> )
27
constructor Create( const Paren_:TGLFramer );
28
destructor Destroy; override;
30
procedure Attach( const I_:Integer; const Render_:IGLChaner );
31
procedure Detach( const I_:Integer );
34
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLFramer
36
TGLFramer = class( TGLAtomer )
44
function GetDepth :IGLChaner;
45
procedure SetDepth( const Depth_:IGLChaner );
46
function GetSizeX :Integer;
47
procedure SetSizeX( const SizeX_:Integer ); virtual;
48
function GetSizeY :Integer;
49
procedure SetSizeY( const SizeY_:Integer ); virtual;
51
procedure InitDepth( const Depth_:IGLChaner ); virtual; abstract;
52
procedure InitColor( const Color_:IGLChaner ); virtual; abstract;
53
procedure InitBuffers;
56
procedure AfterConstruction; override;
57
destructor Destroy; override;
59
property Depth :IGLChaner read GetDepth write SetDepth;
60
property Colors :TGLColors read _Colors ;
61
property SizeX :Integer read GetSizeX write SetSizeX;
62
property SizeY :Integer read GetSizeY write SetSizeY;
64
procedure Bind( const Mode_:GLenum = GL_FRAMEBUFFER );
65
procedure Unbind( const Mode_:GLenum = GL_FRAMEBUFFER );
66
procedure Attach( const Channel_:GLenum; const Render_:TGLChaner );
67
procedure Detach( const Channel_:GLenum );
68
procedure DrawToView( const ViewX_,ViewY_:Integer );
69
procedure DrawToFramer( const Framer_:TGLFramer );
72
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLFramer1
74
TGLFramer1 = class( TGLFramer )
78
procedure InitDepth( const Depth_:IGLChaner ); override;
79
procedure InitColor( const Color_:IGLChaner ); override;
82
destructor Destroy; override;
85
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLFramerN
87
TGLFramerN = class( TGLFramer )
92
function GetSampleN :Byte;
93
procedure SetSampleN( const SampleN_:Byte );
95
procedure InitDepth( const Depth_:IGLChaner ); override;
96
procedure InitColor( const Color_:IGLChaner ); override;
99
destructor Destroy; override;
101
property SampleN :Byte read GetSampleN write SetSampleN;
104
//const //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【定数】
106
//var //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【変数】
108
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【ルーチン】
110
implementation //############################################################### ■
112
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【レコード】
114
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【クラス】
116
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLColors
118
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
120
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
122
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
124
constructor TGLColors.Create( const Paren_:TGLFramer );
131
destructor TGLColors.Destroy;
137
/////////////////////////////////////////////////////////////////////// メソッド
139
procedure TGLColors.Attach( const I_:Integer; const Render_:IGLChaner );
141
inherited AddOrSetValue( I_, Render_ );
143
_Paren.Attach( GL_COLOR_ATTACHMENT0 + I_, Render_ as TGLChaner );
146
procedure TGLColors.Detach( const I_:Integer );
148
inherited Remove( I_ );
150
_Paren.Detach( GL_COLOR_ATTACHMENT0 + I_ );
153
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLFramer
155
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
157
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
159
/////////////////////////////////////////////////////////////////////// アクセス
161
function TGLFramer.GetDepth :IGLChaner;
166
procedure TGLFramer.SetDepth( const Depth_:IGLChaner );
168
if Assigned( _Depth ) then Detach( GL_DEPTH_ATTACHMENT );
172
if Assigned( _Depth ) then Attach( GL_DEPTH_ATTACHMENT, _Depth as TGLChaner );
175
//------------------------------------------------------------------------------
177
function TGLFramer.GetSizeX :Integer;
182
procedure TGLFramer.SetSizeX( const SizeX_:Integer );
184
_SizeX := SizeX_; InitBuffers;
187
function TGLFramer.GetSizeY :Integer;
192
procedure TGLFramer.SetSizeY( const SizeY_:Integer );
194
_SizeY := SizeY_; InitBuffers;
197
/////////////////////////////////////////////////////////////////////// メソッド
199
procedure TGLFramer.InitBuffers;
203
if Assigned( _Depth ) then InitDepth( _Depth );
205
for C in _Colors.Values do InitColor( C );
208
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
210
constructor TGLFramer.Create;
214
_Colors := TGLColors.Create( Self );
216
glGenFramebuffers( 1, @_ID );
222
procedure TGLFramer.AfterConstruction;
229
destructor TGLFramer.Destroy;
231
glDeleteFramebuffers( 1, @_ID );
238
/////////////////////////////////////////////////////////////////////// メソッド
240
procedure TGLFramer.Bind( const Mode_:GLenum = GL_FRAMEBUFFER );
242
glBindFramebuffer( Mode_, _ID );
245
procedure TGLFramer.Unbind( const Mode_:GLenum = GL_FRAMEBUFFER );
247
glBindFramebuffer( Mode_, 0 );
250
//------------------------------------------------------------------------------
252
procedure TGLFramer.Attach( const Channel_:GLenum; const Render_:TGLChaner );
256
glFramebufferRenderbuffer( GL_FRAMEBUFFER, Channel_, GL_RENDERBUFFER, Render_.ID );
261
procedure TGLFramer.Detach( const Channel_:GLenum );
265
glFramebufferRenderbuffer( GL_FRAMEBUFFER, Channel_, GL_RENDERBUFFER, 0 );
270
//------------------------------------------------------------------------------
272
procedure TGLFramer.DrawToView( const ViewX_,ViewY_:Integer );
274
Bind( GL_READ_FRAMEBUFFER );
276
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
278
glDrawBuffer( GL_BACK );
280
glBlitFramebuffer( 0, 0, _SizeX, _SizeY, 0, 0, ViewX_, ViewY_, GL_COLOR_BUFFER_BIT, GL_NEAREST );
282
Unbind( GL_READ_FRAMEBUFFER );
285
procedure TGLFramer.DrawToFramer( const Framer_:TGLFramer );
287
Bind( GL_READ_FRAMEBUFFER );
288
Framer_.Bind( GL_DRAW_FRAMEBUFFER );
290
glBlitFramebuffer( 0, 0, _SizeX, _SizeY, 0, 0, Framer_.SizeX, Framer_.SizeY, GL_COLOR_BUFFER_BIT, GL_NEAREST );
292
Unbind( GL_READ_FRAMEBUFFER );
293
Framer_.Unbind( GL_DRAW_FRAMEBUFFER );
296
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLFramer1
298
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
300
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
302
/////////////////////////////////////////////////////////////////////// メソッド
304
procedure TGLFramer1.InitDepth( const Depth_:IGLChaner );
306
with Depth_ as IGLChaner1 do
313
procedure TGLFramer1.InitColor( const Color_:IGLChaner );
315
with Color_ as IGLChaner1 do
322
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
324
constructor TGLFramer1.Create;
328
Depth := TGLChaner1.Create( GL_DEPTH_COMPONENT );
329
Colors.Attach( 0, TGLChaner1.Create( GL_RGBA ) );
335
destructor TGLFramer1.Destroy;
341
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLFramerN
343
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
345
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
347
/////////////////////////////////////////////////////////////////////// アクセス
349
function TGLFramerN.GetSampleN :Byte;
354
procedure TGLFramerN.SetSampleN( const SampleN_:Byte );
356
_SampleN := SampleN_; InitBuffers;
359
/////////////////////////////////////////////////////////////////////// メソッド
361
procedure TGLFramerN.InitDepth( const Depth_:IGLChaner );
363
with Depth_ as IGLChanerN do
371
procedure TGLFramerN.InitColor( const Color_:IGLChaner );
373
with Color_ as IGLChanerN do
381
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
383
constructor TGLFramerN.Create;
387
Depth := TGLChanerN.Create( GL_DEPTH_COMPONENT );
388
Colors.Attach( 0, TGLChanerN.Create( GL_RGBA ) );
393
destructor TGLFramerN.Destroy;
399
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【ルーチン】
401
//############################################################################## □
403
initialization //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 初期化
405
finalization //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 最終化
407
end. //######################################################################### ■