-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathGfx.cc
698 lines (634 loc) · 25.2 KB
/
Gfx.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
//------------------------------------------------------------------------------
// Gfx.cc
//------------------------------------------------------------------------------
#include "Pre.h"
#include "Gfx.h"
#include "Core/Core.h"
#include "Core/Trace.h"
#include "Gfx/private/gfxPointers.h"
#include "Gfx/private/displayMgr.h"
#include "Gfx/private/gfxResourceContainer.h"
#include "Gfx/private/renderer.h"
namespace Oryol {
using namespace _priv;
namespace {
struct _state {
class GfxSetup gfxSetup;
GfxFrameInfo gfxFrameInfo;
RunLoop::Id runLoopId = RunLoop::InvalidId;
_priv::displayMgr displayManager;
class _priv::renderer renderer;
_priv::gfxResourceContainer resourceContainer;
bool inPass = false;
};
_state* state = nullptr;
}
//------------------------------------------------------------------------------
void
Gfx::Setup(const class GfxSetup& setup) {
o_assert_dbg(!IsValid());
state = Memory::New<_state>();
state->gfxSetup = setup;
gfxPointers pointers;
pointers.displayMgr = &state->displayManager;
pointers.renderer = &state->renderer;
pointers.resContainer = &state->resourceContainer;
pointers.meshPool = &state->resourceContainer.meshPool;
pointers.shaderPool = &state->resourceContainer.shaderPool;
pointers.texturePool = &state->resourceContainer.texturePool;
pointers.pipelinePool = &state->resourceContainer.pipelinePool;
pointers.renderPassPool = &state->resourceContainer.renderPassPool;
state->displayManager.SetupDisplay(setup, pointers);
state->renderer.setup(setup, pointers);
state->resourceContainer.setup(setup, pointers);
state->runLoopId = Core::PreRunLoop()->Add([] {
state->displayManager.ProcessSystemEvents();
});
state->gfxFrameInfo = GfxFrameInfo();
}
//------------------------------------------------------------------------------
void
Gfx::Discard() {
o_assert_dbg(IsValid());
o_assert_dbg(!state->inPass);
state->resourceContainer.GarbageCollect();
state->resourceContainer.Destroy(ResourceLabel::All);
Core::PreRunLoop()->Remove(state->runLoopId);
state->renderer.discard();
state->resourceContainer.discard();
state->displayManager.DiscardDisplay();
Memory::Delete(state);
state = nullptr;
}
//------------------------------------------------------------------------------
bool
Gfx::IsValid() {
return nullptr != state;
}
//------------------------------------------------------------------------------
bool
Gfx::QuitRequested() {
o_assert_dbg(IsValid());
return state->displayManager.QuitRequested();
}
//------------------------------------------------------------------------------
Gfx::EventHandlerId
Gfx::Subscribe(EventHandler handler) {
o_assert_dbg(IsValid());
return state->displayManager.Subscribe(handler);
}
//------------------------------------------------------------------------------
void
Gfx::Unsubscribe(EventHandlerId id) {
o_assert_dbg(IsValid());
state->displayManager.Unsubscribe(id);
}
//------------------------------------------------------------------------------
const GfxSetup&
Gfx::GfxSetup() {
o_assert_dbg(IsValid());
return state->gfxSetup;
}
//------------------------------------------------------------------------------
const DisplayAttrs&
Gfx::DisplayAttrs() {
o_assert_dbg(IsValid());
return state->displayManager.GetDisplayAttrs();
}
//------------------------------------------------------------------------------
const DisplayAttrs&
Gfx::PassAttrs() {
o_assert_dbg(IsValid());
return state->renderer.renderPassAttrs();
}
//------------------------------------------------------------------------------
const GfxFrameInfo&
Gfx::FrameInfo() {
o_assert_dbg(IsValid());
return state->gfxFrameInfo;
}
//------------------------------------------------------------------------------
void
Gfx::BeginPass() {
o_assert_dbg(IsValid());
o_assert_dbg(!state->inPass);
state->inPass = true;
state->gfxFrameInfo.NumPasses++;
state->renderer.beginPass(nullptr, &state->gfxSetup.DefaultPassAction);
}
//------------------------------------------------------------------------------
void
Gfx::BeginPass(const PassAction& action) {
o_assert_dbg(IsValid());
o_assert_dbg(!state->inPass);
state->inPass = true;
state->gfxFrameInfo.NumPasses++;
state->renderer.beginPass(nullptr, &action);
}
//------------------------------------------------------------------------------
void
Gfx::BeginPass(const Id& id) {
o_assert_dbg(IsValid());
o_assert_dbg(!state->inPass);
state->inPass = true;
state->gfxFrameInfo.NumPasses++;
renderPass* pass = state->resourceContainer.lookupRenderPass(id);
o_assert_dbg(pass);
state->renderer.beginPass(pass, &pass->Setup.DefaultAction);
}
//------------------------------------------------------------------------------
void
Gfx::BeginPass(const Id& id, const PassAction& passAction) {
o_assert_dbg(IsValid());
o_assert_dbg(!state->inPass);
state->inPass = true;
state->gfxFrameInfo.NumPasses++;
renderPass* pass = state->resourceContainer.lookupRenderPass(id);
o_assert_dbg(pass);
state->renderer.beginPass(pass, &passAction);
}
//------------------------------------------------------------------------------
void
Gfx::EndPass() {
o_assert_dbg(IsValid());
o_assert_dbg(state->inPass);
state->inPass = false;
state->renderer.endPass();
}
//------------------------------------------------------------------------------
void
Gfx::ApplyDrawState(const DrawState& drawState) {
o_trace_scoped(Gfx_ApplyDrawState);
o_assert_dbg(IsValid());
o_assert_dbg(state->inPass);
o_assert_dbg(drawState.Pipeline.Type == GfxResourceType::Pipeline);
state->gfxFrameInfo.NumApplyDrawState++;
// apply pipeline and meshes
pipeline* pip = state->resourceContainer.lookupPipeline(drawState.Pipeline);
o_assert_dbg(pip);
mesh* meshes[GfxConfig::MaxNumInputMeshes] = { };
int numMeshes = 0;
for (; numMeshes < GfxConfig::MaxNumInputMeshes; numMeshes++) {
if (drawState.Mesh[numMeshes].IsValid()) {
meshes[numMeshes] = state->resourceContainer.lookupMesh(drawState.Mesh[numMeshes]);
}
else {
break;
}
}
#if ORYOL_DEBUG
validateMeshes(pip, meshes, numMeshes);
#endif
state->renderer.applyDrawState(pip, meshes, numMeshes);
// apply vertex textures if any
texture* vsTextures[GfxConfig::MaxNumVertexTextures] = { };
int numVSTextures = 0;
for (; numVSTextures < GfxConfig::MaxNumVertexTextures; numVSTextures++) {
const Id& texId = drawState.VSTexture[numVSTextures];
if (texId.IsValid()) {
vsTextures[numVSTextures] = state->resourceContainer.lookupTexture(texId);
}
else {
break;
}
}
if (numVSTextures > 0) {
#if ORYOL_DEBUG
validateTextures(ShaderStage::VS, pip, vsTextures, numVSTextures);
#endif
state->renderer.applyTextures(ShaderStage::VS, vsTextures, numVSTextures);
}
// apply fragment textures if any
texture* fsTextures[GfxConfig::MaxNumFragmentTextures] = { };
int numFSTextures = 0;
for (; numFSTextures < GfxConfig::MaxNumFragmentTextures; numFSTextures++) {
const Id& texId = drawState.FSTexture[numFSTextures];
if (texId.IsValid()) {
fsTextures[numFSTextures] = state->resourceContainer.lookupTexture(texId);
}
else {
break;
}
}
if (numFSTextures > 0) {
#if ORYOL_DEBUG
validateTextures(ShaderStage::FS, pip, fsTextures, numFSTextures);
#endif
state->renderer.applyTextures(ShaderStage::FS, fsTextures, numFSTextures);
}
}
//------------------------------------------------------------------------------
bool
Gfx::QueryFeature(GfxFeature::Code feat) {
o_assert_dbg(IsValid());
return state->renderer.queryFeature(feat);
}
//------------------------------------------------------------------------------
ResourceLabel
Gfx::PushResourceLabel() {
o_assert_dbg(IsValid());
return state->resourceContainer.PushLabel();
}
//------------------------------------------------------------------------------
void
Gfx::PushResourceLabel(ResourceLabel label) {
o_assert_dbg(IsValid());
state->resourceContainer.PushLabel(label);
}
//------------------------------------------------------------------------------
ResourceLabel
Gfx::PopResourceLabel() {
o_assert_dbg(IsValid());
return state->resourceContainer.PopLabel();
}
//------------------------------------------------------------------------------
Id
Gfx::LoadResource(const Ptr<ResourceLoader>& loader) {
o_assert_dbg(IsValid());
return state->resourceContainer.Load(loader);
}
//------------------------------------------------------------------------------
Id
Gfx::LookupResource(const Locator& locator) {
o_assert_dbg(IsValid());
return state->resourceContainer.Lookup(locator);
}
//------------------------------------------------------------------------------
int
Gfx::QueryFreeResourceSlots(GfxResourceType::Code resourceType) {
o_assert_dbg(IsValid());
return state->resourceContainer.QueryFreeSlots(resourceType);
}
//------------------------------------------------------------------------------
ResourceInfo
Gfx::QueryResourceInfo(const Id& id) {
o_assert_dbg(IsValid());
return state->resourceContainer.QueryResourceInfo(id);
}
//------------------------------------------------------------------------------
ResourcePoolInfo
Gfx::QueryResourcePoolInfo(GfxResourceType::Code resType) {
o_assert_dbg(IsValid());
return state->resourceContainer.QueryPoolInfo(resType);
}
//------------------------------------------------------------------------------
void
Gfx::DestroyResources(ResourceLabel label) {
o_assert_dbg(IsValid());
return state->resourceContainer.DestroyDeferred(label);
}
//------------------------------------------------------------------------------
_priv::gfxResourceContainer*
Gfx::resource() {
o_assert_dbg(IsValid());
return &(state->resourceContainer);
}
//------------------------------------------------------------------------------
void
Gfx::ApplyViewPort(int x, int y, int width, int height, bool originTopLeft) {
o_assert_dbg(IsValid());
o_assert_dbg(state->inPass);
state->gfxFrameInfo.NumApplyViewPort++;
state->renderer.applyViewPort(x, y, width, height, originTopLeft);
}
//------------------------------------------------------------------------------
void
Gfx::ApplyScissorRect(int x, int y, int width, int height, bool originTopLeft) {
o_assert_dbg(IsValid());
o_assert_dbg(state->inPass);
state->gfxFrameInfo.NumApplyScissorRect++;
state->renderer.applyScissorRect(x, y, width, height, originTopLeft);
}
//------------------------------------------------------------------------------
void
Gfx::CommitFrame() {
o_trace_scoped(Gfx_CommitFrame);
o_assert_dbg(IsValid());
o_assert_dbg(!state->inPass);
state->renderer.commitFrame();
state->displayManager.Present();
state->resourceContainer.GarbageCollect();
state->gfxFrameInfo = GfxFrameInfo();
}
//------------------------------------------------------------------------------
void
Gfx::ResetStateCache() {
o_trace_scoped(Gfx_ResetStateCache);
o_assert_dbg(IsValid());
state->renderer.resetStateCache();
}
//------------------------------------------------------------------------------
void
Gfx::UpdateVertices(const Id& id, const void* data, int numBytes) {
o_trace_scoped(Gfx_UpdateVertices);
o_assert_dbg(IsValid());
state->gfxFrameInfo.NumUpdateVertices++;
mesh* msh = state->resourceContainer.lookupMesh(id);
state->renderer.updateVertices(msh, data, numBytes);
}
//------------------------------------------------------------------------------
void
Gfx::UpdateIndices(const Id& id, const void* data, int numBytes) {
o_trace_scoped(Gfx_UpdateIndices);
o_assert_dbg(IsValid());
state->gfxFrameInfo.NumUpdateIndices++;
mesh* msh = state->resourceContainer.lookupMesh(id);
state->renderer.updateIndices(msh, data, numBytes);
}
//------------------------------------------------------------------------------
void
Gfx::UpdateTexture(const Id& id, const void* data, const ImageDataAttrs& offsetsAndSizes) {
o_trace_scoped(Gfx_UpdateTexture);
o_assert_dbg(IsValid());
state->gfxFrameInfo.NumUpdateTextures++;
texture* tex = state->resourceContainer.lookupTexture(id);
state->renderer.updateTexture(tex, data, offsetsAndSizes);
}
//------------------------------------------------------------------------------
void
Gfx::Draw(int primGroupIndex, int numInstances) {
o_trace_scoped(Gfx_Draw);
o_assert_dbg(IsValid());
o_assert_dbg(state->inPass);
state->gfxFrameInfo.NumDraw++;
state->renderer.draw(primGroupIndex, numInstances);
}
//------------------------------------------------------------------------------
void
Gfx::Draw(const PrimitiveGroup& primGroup, int numInstances) {
o_trace_scoped(Gfx_Draw);
o_assert_dbg(IsValid());
o_assert_dbg(state->inPass);
state->gfxFrameInfo.NumDraw++;
state->renderer.draw(primGroup.BaseElement, primGroup.NumElements, numInstances);
}
//------------------------------------------------------------------------------
#if ORYOL_DEBUG
void
Gfx::validateMeshes(pipeline* pip, mesh** meshes, int num) {
// checks that:
// - at least one input mesh must be attached, and it must be in slot 0
// - all attached input meshes must be valid
// - PrimitivesGroups may only be attached to the mesh in slot 0
// - if indexed rendering is used, the mesh in slot 0 must have an index buffer
// - the mesh in slot 0 cannot contain per-instance-data
// - no colliding vertex attributes across all input meshes
//
// this method should only be called in debug mode
// FIXME FIXME FIXME: check for matching vertex layout!!!
o_assert_dbg(meshes && (num > 0) && (num < GfxConfig::MaxNumInputMeshes));
if (nullptr == meshes[0]) {
o_error("invalid mesh block: at least one input mesh must be provided, in slot 0!\n");
}
if ((meshes[0]->indexBufferAttrs.Type != IndexType::None) &&
(meshes[0]->indexBufferAttrs.NumIndices == 0)) {
o_error("invalid mesh block: the input mesh at slot 0 uses indexed rendering, but has no indices!\n");
}
StaticArray<int, VertexAttr::NumVertexAttrs> vertexAttrCounts;
vertexAttrCounts.Fill(0);
for (int mshIndex = 0; mshIndex < GfxConfig::MaxNumInputMeshes; mshIndex++) {
const meshBase* msh = meshes[mshIndex];
if (msh) {
if (ResourceState::Valid != msh->State) {
o_error("invalid mesh block: input mesh at slot '%d' not valid!\n", mshIndex);
}
if ((mshIndex > 0) && (msh->indexBufferAttrs.Type != IndexType::None)) {
o_error("invalid drawState: input mesh at slot '%d' has indices, only allowed for slot 0!\n", mshIndex);
}
if ((mshIndex > 0) && (msh->numPrimGroups > 0)) {
o_error("invalid mesh block: input mesh at slot '%d' has primitive groups, only allowed for slot 0!\n", mshIndex);
}
const int numComps = msh->vertexBufferAttrs.Layout.NumComponents();
for (int compIndex = 0; compIndex < numComps; compIndex++) {
const auto& comp = msh->vertexBufferAttrs.Layout.ComponentAt(compIndex);
vertexAttrCounts[comp.Attr]++;
if (vertexAttrCounts[comp.Attr] > 1) {
o_error("invalid mesh block: same vertex attribute declared in multiple input meshes!\n");
}
}
}
}
}
#endif
//------------------------------------------------------------------------------
#if ORYOL_DEBUG
void
Gfx::validateTextures(ShaderStage::Code stage, pipeline* pip, texture** textures, int numTextures) {
o_assert_dbg(pip);
// check if provided texture types are compatible with the expections shader
const shader* shd = pip->shd;
o_assert_dbg(shd);
for (int slot = 0; slot < numTextures; slot++) {
int index = shd->Setup.TextureIndexByStageAndSlot(stage, slot);
if ((InvalidIndex != index) && textures[slot]) {
if (textures[slot]->textureAttrs.Type != shd->Setup.TexType(index)) {
o_error("Texture type mismatch at slot '%d'!\n", slot);
}
}
else if ((InvalidIndex == index) && textures[slot]) {
o_warn("Texture applied at slot '%d' which isn't expected by shader.\n", slot);
}
else if ((InvalidIndex != index) && !textures[slot]) {
o_error("No texture applied at slot '%d', but shader expects one!\n", slot);
}
}
}
#endif
//------------------------------------------------------------------------------
#if ORYOL_DEBUG
void
Gfx::validateTextureSetup(const TextureSetup& setup, const void* data, int size) {
o_assert((setup.NumMipMaps > 0) && (setup.NumMipMaps <= GfxConfig::MaxNumTextureMipMaps));
o_assert((setup.Width >= 1) && (setup.Height >= 1) && (setup.Depth >= 1));
if (data) {
o_assert(size > 0);
o_assert(setup.TextureUsage == Usage::Immutable);
o_assert(setup.ImageData.NumMipMaps == setup.NumMipMaps);
if (setup.Type == TextureType::TextureCube) {
o_assert(setup.ImageData.NumFaces == 6);
}
else {
o_assert(setup.ImageData.NumFaces == 1);
}
}
if (setup.Type == TextureType::Texture2D) {
o_assert(setup.Depth == 1);
}
if (setup.Type == TextureType::TextureArray) {
o_assert(setup.Depth <= GfxConfig::MaxNumTextureArraySlices);
}
if (setup.Type == TextureType::Texture3D) {
o_assert(!setup.IsRenderTarget);
}
if (setup.IsRenderTarget) {
o_assert(setup.TextureUsage == Usage::Immutable);
o_assert(PixelFormat::IsValidRenderTargetColorFormat(setup.ColorFormat));
if (setup.DepthFormat != PixelFormat::InvalidPixelFormat) {
o_assert(PixelFormat::IsValidRenderTargetDepthFormat(setup.DepthFormat));
}
}
else {
o_assert(setup.SampleCount == 1);
o_assert(setup.DepthFormat == PixelFormat::InvalidPixelFormat);
}
}
#endif
//------------------------------------------------------------------------------
#if ORYOL_DEBUG
void
Gfx::validateMeshSetup(const MeshSetup& setup, const void* data, int size) {
o_assert(setup.ShouldSetupFullScreenQuad() || (setup.VertexUsage != Usage::InvalidUsage) || (setup.IndexUsage != Usage::InvalidUsage));
if (setup.NumVertices > 0) {
o_assert(!setup.Layout.Empty());
if (setup.VertexUsage == Usage::Immutable) {
o_assert(data && (size > 0));
o_assert((setup.VertexDataOffset >= 0) && (setup.VertexDataOffset < size));
}
}
if (setup.NumIndices > 0) {
o_assert((setup.IndicesType == IndexType::Index16) || (setup.IndicesType == IndexType::Index32));
if (setup.IndexUsage == Usage::Immutable) {
o_assert(data && (size > 0));
o_assert((setup.IndexDataOffset >= 0) && (setup.IndexDataOffset < size));
}
}
}
#endif
//------------------------------------------------------------------------------
#if ORYOL_DEBUG
void
Gfx::validatePipelineSetup(const PipelineSetup& setup) {
o_assert(setup.PrimType != PrimitiveType::InvalidPrimitiveType);
o_assert(setup.Shader.IsValid());
bool anyLayoutValid = false;
for (const auto& layout : setup.Layouts) {
if (!layout.Empty()) {
anyLayoutValid = true;
break;
}
}
o_assert(anyLayoutValid);
}
#endif
//------------------------------------------------------------------------------
#if ORYOL_DEBUG
void
Gfx::validatePassSetup(const PassSetup& setup) {
// check that at least one color attachment texture is defined
// and that there are no 'holes' if there are multiple attachments
bool continuous = true;
for (int i = 0; i < GfxConfig::MaxNumColorAttachments; i++) {
if (setup.ColorAttachments[i].Texture.IsValid()) {
if (!continuous) {
o_error("invalid render pass: must have continuous color attachments!\n");
}
}
else {
if (0 == i) {
o_error("invalid render pass: must have color attachment at slot 0!\n");
}
continuous = false;
}
}
// check that all render targets have the required params
const texture* t0 = state->resourceContainer.lookupTexture(setup.ColorAttachments[0].Texture);
o_assert(t0);
const int w = t0->textureAttrs.Width;
const int h = t0->textureAttrs.Height;
const int sampleCount = t0->textureAttrs.SampleCount;
for (int i = 0; i < GfxConfig::MaxNumColorAttachments; i++) {
const texture* tex = state->resourceContainer.lookupTexture(setup.ColorAttachments[i].Texture);
if (tex) {
const auto& attrs = tex->textureAttrs;
if ((attrs.Width != w) || (attrs.Height != h)) {
o_error("invalid render pass: all color attachments must have the same size!\n");
}
if (attrs.SampleCount != sampleCount) {
o_error("invalid render pass: all color attachments must have same sample-count!\n");
}
if (attrs.TextureUsage != Usage::Immutable) {
o_error("invalid render pass: color attachments must have immutable usage!\n");
}
if (!tex->Setup.IsRenderTarget) {
o_error("invalid render pass: color attachment must have been setup as render target!\n");
}
}
}
const texture* dsTex = state->resourceContainer.lookupTexture(setup.DepthStencilTexture);
if (dsTex) {
const auto& attrs = dsTex->textureAttrs;
if ((attrs.Width != w) || (attrs.Height != h)) {
o_error("invalid render pass: depth-stencil attachment must have same size as color attachments!\n");
}
if (attrs.SampleCount != sampleCount) {
o_error("invalid render pass: depth-stencil attachment must have sample sample-count as color attachments!\n");
}
if (attrs.TextureUsage != Usage::Immutable) {
o_error("invalid render pass: depth attachment must have immutable usage!\n");
}
if (!dsTex->Setup.IsRenderTarget) {
o_error("invalid render pass: depth attachment must have been setup as render target!\n");
}
}
}
#endif
//------------------------------------------------------------------------------
#if ORYOL_DEBUG
void
Gfx::validateShaderSetup(const ShaderSetup& setup) {
// hmm, FIXME
}
#endif
//------------------------------------------------------------------------------
template<> Id
Gfx::CreateResource(const TextureSetup& setup, const void* data, int size) {
o_assert_dbg(IsValid());
#if ORYOL_DEBUG
validateTextureSetup(setup, data, size);
#endif
return state->resourceContainer.Create(setup, data, size);
}
//------------------------------------------------------------------------------
template<> Id
Gfx::CreateResource(const MeshSetup& setup, const void* data, int size) {
o_assert_dbg(IsValid());
#if ORYOL_DEBUG
validateMeshSetup(setup, data, size);
#endif
return state->resourceContainer.Create(setup, data, size);
}
//------------------------------------------------------------------------------
template<> Id
Gfx::CreateResource(const ShaderSetup& setup, const void* data, int size) {
o_assert_dbg(IsValid());
#if ORYOL_DEBUG
validateShaderSetup(setup);
#endif
return state->resourceContainer.Create(setup, nullptr, 0);
}
//------------------------------------------------------------------------------
template<> Id
Gfx::CreateResource(const PipelineSetup& setup, const void* data, int size) {
o_assert_dbg(IsValid());
#if ORYOL_DEBUG
validatePipelineSetup(setup);
#endif
return state->resourceContainer.Create(setup, nullptr, 0);
}
//------------------------------------------------------------------------------
template<> Id
Gfx::CreateResource(const PassSetup& setup, const void* data, int size) {
o_assert_dbg(IsValid());
#if ORYOL_DEBUG
validatePassSetup(setup);
#endif
return state->resourceContainer.Create(setup, nullptr, 0);
}
//------------------------------------------------------------------------------
void
Gfx::applyUniformBlock(ShaderStage::Code bindStage, int bindSlot, uint32_t layoutHash, const uint8_t* ptr, int byteSize) {
o_assert_dbg(IsValid());
state->gfxFrameInfo.NumApplyUniformBlock++;
state->renderer.applyUniformBlock(bindStage, bindSlot, layoutHash, ptr, byteSize);
}
} // namespace Oryol