Luxophia

Форк
0
/
LUX.GPU.OpenGL.Atom.Framer.pas 
407 строк · 11.2 Кб
1
unit LUX.GPU.OpenGL.Atom.Framer;
2

3
interface //#################################################################### ■
4

5
uses Winapi.OpenGL, Winapi.OpenGLext,
6
     System.Generics.Collections,
7
     LUX, LUX.GPU.OpenGL.Atom, LUX.GPU.OpenGL.Atom.Chaner;
8

9
type //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【型】
10

11
     TGLColors  = class;
12
     TGLFramer  = class;
13
     TGLFramer1 = class;
14
     TGLFramerN = class;
15

16
     //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【レコード】
17

18
     //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【クラス】
19

20
     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLColors
21

22
     TGLColors = class( TDictionary<Integer,IGLChaner> )
23
     private
24
     protected
25
       _Paren :TGLFramer;
26
     public
27
       constructor Create( const Paren_:TGLFramer );
28
       destructor Destroy; override;
29
       ///// メソッド
30
       procedure Attach( const I_:Integer; const Render_:IGLChaner );
31
       procedure Detach( const I_:Integer );
32
     end;
33

34
     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLFramer
35

36
     TGLFramer = class( TGLAtomer )
37
     private
38
     protected
39
       _Depth  :IGLChaner;
40
       _Colors :TGLColors;
41
       _SizeX  :Integer;
42
       _SizeY  :Integer;
43
       ///// アクセス
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;
50
       ///// メソッド
51
       procedure InitDepth( const Depth_:IGLChaner ); virtual; abstract;
52
       procedure InitColor( const Color_:IGLChaner ); virtual; abstract;
53
       procedure InitBuffers;
54
     public
55
       constructor Create;
56
       procedure AfterConstruction; override;
57
       destructor Destroy; override;
58
       ///// プロパティ
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;
63
       ///// メソッド
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 );
70
     end;
71

72
     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLFramer1
73

74
     TGLFramer1 = class( TGLFramer )
75
     private
76
     protected
77
       ///// メソッド
78
       procedure InitDepth( const Depth_:IGLChaner ); override;
79
       procedure InitColor( const Color_:IGLChaner ); override;
80
     public
81
       constructor Create;
82
       destructor Destroy; override;
83
     end;
84

85
     //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLFramerN
86

87
     TGLFramerN = class( TGLFramer )
88
     private
89
     protected
90
       _SampleN :Byte;
91
       ///// アクセス
92
       function GetSampleN :Byte;
93
       procedure SetSampleN( const SampleN_:Byte );
94
       ///// メソッド
95
       procedure InitDepth( const Depth_:IGLChaner ); override;
96
       procedure InitColor( const Color_:IGLChaner ); override;
97
     public
98
       constructor Create;
99
       destructor Destroy; override;
100
       ///// プロパティ
101
       property SampleN :Byte read GetSampleN write SetSampleN;
102
     end;
103

104
//const //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【定数】
105

106
//var //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【変数】
107

108
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【ルーチン】
109

110
implementation //############################################################### ■
111

112
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【レコード】
113

114
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【クラス】
115

116
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLColors
117

118
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
119

120
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
121

122
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
123

124
constructor TGLColors.Create( const Paren_:TGLFramer );
125
begin
126
     inherited Create;
127

128
     _Paren := Paren_;
129
end;
130

131
destructor TGLColors.Destroy;
132
begin
133

134
     inherited;
135
end;
136

137
/////////////////////////////////////////////////////////////////////// メソッド
138

139
procedure TGLColors.Attach( const I_:Integer; const Render_:IGLChaner );
140
begin
141
     inherited AddOrSetValue( I_, Render_ );
142

143
     _Paren.Attach( GL_COLOR_ATTACHMENT0 + I_, Render_ as TGLChaner );
144
end;
145

146
procedure TGLColors.Detach( const I_:Integer );
147
begin
148
     inherited Remove( I_ );
149

150
     _Paren.Detach( GL_COLOR_ATTACHMENT0 + I_ );
151
end;
152

153
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLFramer
154

155
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
156

157
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
158

159
/////////////////////////////////////////////////////////////////////// アクセス
160

161
function TGLFramer.GetDepth :IGLChaner;
162
begin
163
     Result := _Depth;
164
end;
165

166
procedure TGLFramer.SetDepth( const Depth_:IGLChaner );
167
begin
168
     if Assigned( _Depth ) then Detach( GL_DEPTH_ATTACHMENT );
169

170
                  _Depth := Depth_;
171

172
     if Assigned( _Depth ) then Attach( GL_DEPTH_ATTACHMENT, _Depth as TGLChaner );
173
end;
174

175
//------------------------------------------------------------------------------
176

177
function TGLFramer.GetSizeX :Integer;
178
begin
179
     Result := _SizeX;
180
end;
181

182
procedure TGLFramer.SetSizeX( const SizeX_:Integer );
183
begin
184
     _SizeX := SizeX_;  InitBuffers;
185
end;
186

187
function TGLFramer.GetSizeY :Integer;
188
begin
189
     Result := _SizeY;
190
end;
191

192
procedure TGLFramer.SetSizeY( const SizeY_:Integer );
193
begin
194
     _SizeY := SizeY_;  InitBuffers;
195
end;
196

197
/////////////////////////////////////////////////////////////////////// メソッド
198

199
procedure TGLFramer.InitBuffers;
200
var
201
   C :IGLChaner;
202
begin
203
     if Assigned( _Depth ) then InitDepth( _Depth );
204

205
     for C in _Colors.Values do InitColor( C );
206
end;
207

208
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
209

210
constructor TGLFramer.Create;
211
begin
212
     inherited;
213

214
     _Colors := TGLColors.Create( Self );
215

216
     glGenFramebuffers( 1, @_ID );
217

218
     _SizeX := 1920;
219
     _SizeY := 1080;
220
end;
221

222
procedure TGLFramer.AfterConstruction;
223
begin
224
     inherited;
225

226
     InitBuffers;
227
end;
228

229
destructor TGLFramer.Destroy;
230
begin
231
     glDeleteFramebuffers( 1, @_ID );
232

233
     _Colors.Free;
234

235
     inherited;
236
end;
237

238
/////////////////////////////////////////////////////////////////////// メソッド
239

240
procedure TGLFramer.Bind( const Mode_:GLenum = GL_FRAMEBUFFER );
241
begin
242
     glBindFramebuffer( Mode_, _ID );
243
end;
244

245
procedure TGLFramer.Unbind( const Mode_:GLenum = GL_FRAMEBUFFER );
246
begin
247
     glBindFramebuffer( Mode_, 0 );
248
end;
249

250
//------------------------------------------------------------------------------
251

252
procedure TGLFramer.Attach( const Channel_:GLenum; const Render_:TGLChaner );
253
begin
254
     Bind;
255

256
       glFramebufferRenderbuffer( GL_FRAMEBUFFER, Channel_, GL_RENDERBUFFER, Render_.ID );
257

258
     Unbind;
259
end;
260

261
procedure TGLFramer.Detach( const Channel_:GLenum );
262
begin
263
     Bind;
264

265
       glFramebufferRenderbuffer( GL_FRAMEBUFFER, Channel_, GL_RENDERBUFFER, 0 );
266

267
     Unbind;
268
end;
269

270
//------------------------------------------------------------------------------
271

272
procedure TGLFramer.DrawToView( const ViewX_,ViewY_:Integer );
273
begin
274
     Bind( GL_READ_FRAMEBUFFER );
275

276
     glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 );
277

278
     glDrawBuffer( GL_BACK );
279

280
     glBlitFramebuffer( 0, 0, _SizeX, _SizeY, 0, 0, ViewX_, ViewY_, GL_COLOR_BUFFER_BIT, GL_NEAREST );
281

282
     Unbind( GL_READ_FRAMEBUFFER );
283
end;
284

285
procedure TGLFramer.DrawToFramer( const Framer_:TGLFramer );
286
begin
287
             Bind( GL_READ_FRAMEBUFFER );
288
     Framer_.Bind( GL_DRAW_FRAMEBUFFER );
289

290
     glBlitFramebuffer( 0, 0, _SizeX, _SizeY, 0, 0, Framer_.SizeX, Framer_.SizeY, GL_COLOR_BUFFER_BIT, GL_NEAREST );
291

292
             Unbind( GL_READ_FRAMEBUFFER );
293
     Framer_.Unbind( GL_DRAW_FRAMEBUFFER );
294
end;
295

296
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLFramer1
297

298
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
299

300
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
301

302
/////////////////////////////////////////////////////////////////////// メソッド
303

304
procedure TGLFramer1.InitDepth( const Depth_:IGLChaner );
305
begin
306
     with Depth_ as IGLChaner1 do
307
     begin
308
          SizeX := _SizeX;
309
          SizeY := _SizeY;
310
     end;
311
end;
312

313
procedure TGLFramer1.InitColor( const Color_:IGLChaner );
314
begin
315
     with Color_ as IGLChaner1 do
316
     begin
317
          SizeX := _SizeX;
318
          SizeY := _SizeY;
319
     end;
320
end;
321

322
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
323

324
constructor TGLFramer1.Create;
325
begin
326
     inherited;
327

328
     Depth :=          TGLChaner1.Create( GL_DEPTH_COMPONENT );
329
     Colors.Attach( 0, TGLChaner1.Create( GL_RGBA            ) );
330

331
     _SizeX := 1920;
332
     _SizeY := 1080;
333
end;
334

335
destructor TGLFramer1.Destroy;
336
begin
337

338
     inherited;
339
end;
340

341
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TGLFramerN
342

343
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& private
344

345
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& protected
346

347
/////////////////////////////////////////////////////////////////////// アクセス
348

349
function TGLFramerN.GetSampleN :Byte;
350
begin
351
     Result := _SampleN;
352
end;
353

354
procedure TGLFramerN.SetSampleN( const SampleN_:Byte );
355
begin
356
     _SampleN := SampleN_;  InitBuffers;
357
end;
358

359
/////////////////////////////////////////////////////////////////////// メソッド
360

361
procedure TGLFramerN.InitDepth( const Depth_:IGLChaner );
362
begin
363
     with Depth_ as IGLChanerN do
364
     begin
365
          SizeX   := _SizeX;
366
          SizeY   := _SizeY;
367
          SampleN := _SampleN;
368
     end;
369
end;
370

371
procedure TGLFramerN.InitColor( const Color_:IGLChaner );
372
begin
373
     with Color_ as IGLChanerN do
374
     begin
375
          SizeX   := _SizeX;
376
          SizeY   := _SizeY;
377
          SampleN := _SampleN;
378
     end;
379
end;
380

381
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& public
382

383
constructor TGLFramerN.Create;
384
begin
385
     inherited;
386

387
     Depth :=          TGLChanerN.Create( GL_DEPTH_COMPONENT );
388
     Colors.Attach( 0, TGLChanerN.Create( GL_RGBA            ) );
389

390
     _SampleN := 8;
391
end;
392

393
destructor TGLFramerN.Destroy;
394
begin
395

396
     inherited;
397
end;
398

399
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$【ルーチン】
400

401
//############################################################################## □
402

403
initialization //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 初期化
404

405
finalization //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 最終化
406

407
end. //######################################################################### ■

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.