Covellite++  Version: 2.3.2 Revision: 2584 Platform: x64 Build: 19:03 05.09.2026
Кроссплатформенный фреймворк для разработки приложений на С++
Загрузка...
Поиск...
Не найдено
OpenGLShader_test.hpp
1
2#pragma once
3#include <gmock/gmock.hpp>
4#include <alicorn/std/vector.hpp>
5#include <alicorn/std/string/encoding.hpp>
6#include <boost/algorithm/string/replace.hpp>
7
8#ifndef OpenGLShader_test
9
10class OpenGLShader_test :
11 public ::testing::Test
12{
13
14};
15
16#endif
17
18namespace
19{
20
21// ************************************************************************** //
22TEST_F(OpenGLShader_test, /*DISABLED_*/Test_State_Sampler_Texture_Mipmapping)
23{
24 using GLProxy_t = ::mock::GLProxy;
25 GLProxy_t GLProxy;
26 GLProxy_t::GetInstance() = &GLProxy;
27
28 const Tested_t Example{ Data_t{} };
29 const ITested_t & IExample = Example;
30
31 auto itStateCreator = IExample.GetCreators().find(uT("State"));
32 ASSERT_NE(IExample.GetCreators().end(), itStateCreator);
33
34 auto itTextureCreator = IExample.GetCreators().find(uT("Texture"));
35 ASSERT_NE(IExample.GetCreators().end(), itTextureCreator);
36
37 auto SamplerRender = itStateCreator->second(Component_t::Make(
38 {
39 { uT("kind"), uT("Sampler") }
40 }));
41 ASSERT_NE(nullptr, SamplerRender);
42
43 auto TextureRender = itTextureCreator->second(Component_t::Make(
44 {
45 { uT("mipmapping"), true }
46 }));
47 ASSERT_NE(nullptr, TextureRender);
48
49 using namespace ::testing;
50
51 EXPECT_CALL(GLProxy, TexParameteri(_, _, _))
52 .Times(0);
53
54 SamplerRender();
55
56 InSequence Dummy;
57
58 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, _))
59 .Times(1);
60
61 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
62 GL_LINEAR_MIPMAP_LINEAR))
63 .Times(1);
64
65 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
66 GL_LINEAR))
67 .Times(1);
68
69 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT))
70 .Times(1);
71
72 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT))
73 .Times(1);
74
75 TextureRender();
76}
77
78// ************************************************************************** //
79TEST_F(OpenGLShader_test, /*DISABLED_*/Test_State_Sampler_TextureArray_Mipmapping)
80{
81 using GLProxy_t = ::mock::GLProxy;
82 GLProxy_t GLProxy;
83 GLProxy_t::GetInstance() = &GLProxy;
84
85 const Tested_t Example{ Data_t{} };
86 const ITested_t & IExample = Example;
87
88 auto itStateCreator = IExample.GetCreators().find(uT("State"));
89 ASSERT_NE(IExample.GetCreators().end(), itStateCreator);
90
91 auto itTextureCreator = IExample.GetCreators().find(uT("TextureArray"));
92 ASSERT_NE(IExample.GetCreators().end(), itTextureCreator);
93
94 auto SamplerRender = itStateCreator->second(Component_t::Make(
95 {
96 { uT("kind"), uT("Sampler") }
97 }));
98 ASSERT_NE(nullptr, SamplerRender);
99
100 auto TextureRender = itTextureCreator->second(Component_t::Make(
101 {
102 { uT("mipmapping"), true }
103 }));
104 ASSERT_NE(nullptr, TextureRender);
105
106 using namespace ::testing;
107
108 EXPECT_CALL(GLProxy, TexParameteri(_, _, _))
109 .Times(0);
110
111 SamplerRender();
112
113 InSequence Dummy;
114
115 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, _))
116 .Times(1);
117
118 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER,
119 GL_LINEAR_MIPMAP_LINEAR))
120 .Times(1);
121
122 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER,
123 GL_LINEAR))
124 .Times(1);
125
126 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT))
127 .Times(1);
128
129 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT))
130 .Times(1);
131
132 TextureRender();
133}
134
135// ************************************************************************** //
136TEST_F(OpenGLShader_test, /*DISABLED_*/Test_BkSurface_Fail)
137{
138 using GLProxy_t = ::mock::GLProxy;
139 GLProxy_t GLProxy;
140 GLProxy_t::GetInstance() = &GLProxy;
141
142 const Tested_t Example{ Data_t{} };
143 const ITested_t & IExample = Example;
144
145 auto itCreator = IExample.GetCreators().find(uT("BkSurface"));
146 ASSERT_NE(IExample.GetCreators().end(), itCreator);
147
148 const ::mock::GLuint FrameBufferId = 1910041904;
149
150 using namespace ::testing;
151
152 InSequence Dummy;
153
154 EXPECT_CALL(GLProxy, GenFramebuffers(1))
155 .Times(1)
156 .WillOnce(Return(FrameBufferId));
157
158 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
159 .Times(1);
160
161 EXPECT_CALL(GLProxy, CheckFramebufferStatus(GL_FRAMEBUFFER))
162 .Times(1)
163 .WillOnce(Return(1910041903));
164
165 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, 0))
166 .Times(1);
167
168 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
169 .Times(1);
170
171 EXPECT_THROW(itCreator->second(Component_t::Make({})), ::std::exception);
172}
173
174// ************************************************************************** //
175TEST_F(OpenGLShader_test, /*DISABLED_*/Test_BkSurface)
176{
177 const auto TestCall = [](
178 const Component_t::ComponentPtr_t & _pBkSurface,
179 const bool _IsUseMapper,
180 const int _Width, const int _Height,
181 const int _ExpectedWidth, const int _ExpectedHeight)
182 {
183 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
184
185 ::mock::GLProxy GLProxy;
186
187 Data_t SettingsData;
188 SettingsData.ClientRect.Top = 34;
189
190 Tested_t Example{ SettingsData };
191 ITested_t & IExample = Example;
192 IExample.PresentFrame();
193
194 auto itCreator = IExample.GetCreators().find(uT("BkSurface"));
195 ASSERT_NE(IExample.GetCreators().end(), itCreator);
196
197 constexpr ::mock::GLint TextureId = 1910041735;
198 constexpr ::mock::GLint FrameBufferId = 1910041803;
199 constexpr ::mock::GLint BindingFrameBufferId = 2006162207;
200
201 const ::std::vector<String_t> Destinations =
202 {
203 uT("depth"),
204 uT("albedo"),
205 uT("metalness"),
206 uT("roughness"),
207 uT("depth"),
208 uT("normal"),
209 uT("occlusion"),
210 uT("depth"),
211 };
212
213 Object_t TextureComponents;
214
215 for (::std::size_t i = 0; i < Destinations.size(); i++)
216 {
217 const auto pTexture = Component_t::Make(
218 {
219 { uT("kind"), uT("Texture") },
220 { uT("destination"), Destinations[i] },
221 });
222
223 if (_IsUseMapper) (*pTexture)[uT("mapper")] = BufferMapper_t{};
224
225 TextureComponents.push_back(pTexture);
226 }
227
228 using namespace ::testing;
229
230 InSequence Dummy;
231
232 const int Viewport[] = { 0, 0, _Width, _Height };
233
234 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
235 .Times(1)
236 .WillOnce(Return(Viewport));
237
238 EXPECT_CALL(GLProxy, GenFramebuffers(1))
239 .Times(1)
240 .WillOnce(Return(FrameBufferId));
241
242 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
243 .Times(1)
244 .WillOnce(Return(&BindingFrameBufferId));
245
246 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
247 .Times(1);
248
249 ::std::vector<::mock::GLenum> AttachmentIndexes;
250
251 for (::std::size_t i = 0; i < Destinations.size(); i++)
252 {
253 auto Format = GL_DEPTH_COMPONENT;
254 auto Attachment = GL_DEPTH_ATTACHMENT;
255
256 if (Destinations[i] != uT("depth"))
257 {
258 Format = GL_RGBA;
259 Attachment = GL_COLOR_ATTACHMENT0 +
260 static_cast<int>(AttachmentIndexes.size());
261 AttachmentIndexes.push_back(Attachment);
262 }
263
264 EXPECT_CALL(GLProxy, GenTextures(1))
265 .Times(1)
266 .WillOnce(Return(TextureId + i));
267
268 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId + i))
269 .Times(1);
270
271 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, _,
272 _ExpectedWidth, _ExpectedHeight, 0, Format, _, ::std::vector<uint8_t>{}))
273 .Times(1);
274
275 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
276 .Times(1);
277
278 EXPECT_CALL(GLProxy, GetError())
279 .Times(1)
280 .WillOnce(Return(GL_NO_ERROR));
281
282 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER, Attachment,
283 GL_TEXTURE_2D, TextureId + i, 0))
284 .Times(1);
285 }
286
287 EXPECT_CALL(GLProxy, CheckFramebufferStatus(GL_FRAMEBUFFER))
288 .Times(1)
289 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
290
291 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, BindingFrameBufferId))
292 .Times(1);
293
294 (*_pBkSurface)[uT("service")] = TextureComponents;
295
296 auto Render = itCreator->second(_pBkSurface);
297 ASSERT_NE(nullptr, Render);
298
299 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
300 .Times(1)
301 .WillOnce(Return(Viewport));
302
303 EXPECT_CALL(GLProxy, TexImage2D(_, _, _, _, _, _, _, _, _))
304 .Times(0);
305
306 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
307 .Times(1)
308 .WillOnce(Return(&BindingFrameBufferId));
309
310 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
311 .Times(1);
312
313 EXPECT_CALL(GLProxy, DrawBuffers(AttachmentIndexes))
314 .Times(1);
315
316 EXPECT_CALL(GLProxy, Viewport(_, _, _, _))
317 .Times(0);
318
319 Render();
320
321 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
322 .Times(1);
323
324 ASSERT_EQ(TextureComponents.size(), Destinations.size());
325
326 EXPECT_EQ(_ExpectedWidth, (int)(*_pBkSurface)[uT("width")]);
327 EXPECT_EQ(_ExpectedHeight, (int)(*_pBkSurface)[uT("height")]);
328
329 for (::std::size_t i = 0; i < TextureComponents.size(); i++)
330 {
331 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
332
333 const auto pTextureComponent = TextureComponents[i];
334 const Texture_t::Ptr_t pTexture =
335 (*pTextureComponent)[uT("entity")].Default(Texture_t::Ptr_t{});
336 ASSERT_NE(nullptr, pTexture);
337 EXPECT_EQ(TextureId + i, pTexture->m_TextureId);
338 EXPECT_EQ(_IsUseMapper ? 4 * _ExpectedWidth * _ExpectedHeight : 0,
339 pTexture->m_ReadCopyData.size());
340 EXPECT_EQ(_ExpectedWidth, (int)(*pTextureComponent)[uT("width")].Default(0));
341 EXPECT_EQ(_ExpectedHeight, (int)(*pTextureComponent)[uT("height")].Default(0));
342 }
343 };
344
345 TestCall(Component_t::Make({ }),
346 false, 12, 45, 12, 45);
347 TestCall(Component_t::Make({ }),
348 true, 45, 12, 45, 12);
349}
350
351// ************************************************************************** //
352TEST_F(OpenGLShader_test, /*DISABLED_*/Test_BkSurface_RenderDepthOnly)
353{
354 using GLProxy_t = ::mock::GLProxy;
355 GLProxy_t GLProxy;
356 GLProxy_t::GetInstance() = &GLProxy;
357
358 const Tested_t Example{ Data_t{} };
359 const ITested_t & IExample = Example;
360
361 auto itCreator = IExample.GetCreators().find(uT("BkSurface"));
362 ASSERT_NE(IExample.GetCreators().end(), itCreator);
363
364 const ::mock::GLuint TextureId = 1910041735;
365 const ::mock::GLuint FrameBufferId = 1910041803;
366
367 using namespace ::testing;
368
369 InSequence Dummy;
370
371 const auto pTexture = Component_t::Make(
372 {
373 { uT("kind"), uT("Texture") },
374 { uT("destination"), uT("depth") },
375 });
376
377 EXPECT_CALL(GLProxy, CheckFramebufferStatus(GL_FRAMEBUFFER))
378 .Times(1)
379 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
380
381 auto Render = itCreator->second(Component_t::Make(
382 {
383 { uT("service"), Object_t{ pTexture } }
384 }));
385 ASSERT_NE(nullptr, Render);
386
387 EXPECT_CALL(GLProxy, DrawBuffers(::std::vector<::mock::GLenum>{}))
388 .Times(1);
389
390 Render();
391}
392
393// ************************************************************************** //
394TEST_F(OpenGLShader_test, /*DISABLED_*/Test_BkSurface_ResizeWindow)
395{
396 const auto TestCall = [](
397 const Component_t::ComponentPtr_t & _pBkSurface,
398 const bool _IsUseMapper,
399 const int _Width, const int _Height,
400 const int _ExpectedWidth, const int _ExpectedHeight,
401 const int _ExpectedWidth2, const int _ExpectedHeight2)
402 {
403 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
404 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
405
406 ::mock::GLProxy GLProxy;
407
408 Data_t SettingsData;
409 SettingsData.ClientRect.Top = 45;
410
411 Tested_t Example{ SettingsData };
412 ITested_t & IExample = Example;
413 IExample.PresentFrame();
414
415 auto itCreator = IExample.GetCreators().find(uT("BkSurface"));
416 ASSERT_NE(IExample.GetCreators().end(), itCreator);
417
418 constexpr ::mock::GLuint TextureId = 1910091302;
419
420 const ::std::vector<String_t> Destinations =
421 {
422 uT("albedo"),
423 uT("metalness"),
424 uT("roughness"),
425 uT("normal"),
426 uT("occlusion"),
427 uT("depth"),
428 };
429
430 Object_t TextureComponents;
431
432 for (::std::size_t i = 0; i < Destinations.size(); i++)
433 {
434 const auto pTexture = Component_t::Make(
435 {
436 { uT("kind"), uT("Texture") },
437 { uT("destination"), Destinations[i] },
438 });
439
440 if (_IsUseMapper) (*pTexture)[uT("mapper")] = BufferMapper_t{};
441
442 TextureComponents.push_back(pTexture);
443 }
444
445 using namespace ::testing;
446
447 InSequence Dummy;
448
449 const int Viewport[] = { 0, 0, _Width, _Height };
450
451 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
452 .Times(1)
453 .WillOnce(Return(Viewport));
454
455 EXPECT_CALL(GLProxy, GetIntegerv(_))
456 .Times(1);
457
458 for (::std::size_t i = 0; i < Destinations.size(); i++)
459 {
460 EXPECT_CALL(GLProxy, GenTextures(1))
461 .Times(1)
462 .WillOnce(Return(TextureId + i));
463
464 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId + i))
465 .Times(1);
466
467 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, _, _,
468 _ExpectedWidth, _ExpectedHeight, _, _, _, ::std::vector<uint8_t>{}))
469 .Times(1);
470
471 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
472 .Times(1);
473
474 EXPECT_CALL(GLProxy, GetError())
475 .Times(1)
476 .WillOnce(Return(GL_NO_ERROR));
477 }
478
479 EXPECT_CALL(GLProxy, CheckFramebufferStatus(GL_FRAMEBUFFER))
480 .Times(1)
481 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
482
483 (*_pBkSurface)[uT("service")] = TextureComponents;
484
485 auto Render = itCreator->second(_pBkSurface);
486 ASSERT_NE(nullptr, Render);
487
488 EXPECT_EQ(_ExpectedWidth, (int)(*_pBkSurface)[uT("width")]);
489 EXPECT_EQ(_ExpectedHeight, (int)(*_pBkSurface)[uT("height")]);
490
491 for (::std::size_t i = 0; i < TextureComponents.size(); i++)
492 {
493 const auto pTextureComponent = TextureComponents[i];
494 EXPECT_EQ(_ExpectedWidth, (int)(*pTextureComponent)[uT("width")].Default(0));
495 EXPECT_EQ(_ExpectedHeight, (int)(*pTextureComponent)[uT("height")].Default(0));
496
497 const Texture_t::Ptr_t pTexture =
498 (*pTextureComponent)[uT("entity")].Default(Texture_t::Ptr_t{});
499 ASSERT_NE(nullptr, pTexture);
500 EXPECT_EQ(_IsUseMapper ? _ExpectedWidth * _ExpectedHeight * 4 : 0,
501 pTexture->m_ReadCopyData.size());
502 }
503
504 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
505 .Times(1);
506
507 EXPECT_CALL(GLProxy, TexImage2D(_, _, _, _, _, _, _, _, _))
508 .Times(0);
509
510 EXPECT_CALL(GLProxy, GetIntegerv(_))
511 .Times(1);
512
513 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, _))
514 .Times(1);
515
516 EXPECT_CALL(GLProxy, Viewport(_, _, _, _))
517 .Times(0);
518
519 Render();
520
521 EXPECT_CALL(GLProxy, GetError())
522 .Times(1)
523 .WillOnce(Return(GL_NO_ERROR));
524
525 IExample.PresentFrame();
526
527 const int Viewport2[] = { 0, 0, _Width * 2, _Height * 2 };
528
529 IExample.ResizeWindow(::covellite::Rect{ 0, 0, _Width * 2, _Height * 2 });
530
531 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
532 .Times(1)
533 .WillOnce(Return(Viewport2));
534
535 for (::std::size_t i = 0; i < Destinations.size(); i++)
536 {
537 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId + i))
538 .Times(1);
539
540 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, _, _,
541 _ExpectedWidth2, _ExpectedHeight2, _, _, _, ::std::vector<uint8_t>{}))
542 .Times(1);
543
544 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
545 .Times(1);
546
547 EXPECT_CALL(GLProxy, GetError())
548 .Times(1)
549 .WillOnce(Return(GL_NO_ERROR));
550 }
551
552 EXPECT_CALL(GLProxy, GetIntegerv(_))
553 .Times(1);
554
555 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, _))
556 .Times(1);
557
558 EXPECT_CALL(GLProxy, Viewport(_, _, _, _))
559 .Times(0);
560
561 Render();
562
563 EXPECT_CALL(GLProxy, GetError())
564 .Times(1)
565 .WillOnce(Return(GL_NO_ERROR));
566
567 IExample.PresentFrame();
568
569 EXPECT_EQ(_ExpectedWidth2, (int)(*_pBkSurface)[uT("width")]);
570 EXPECT_EQ(_ExpectedHeight2, (int)(*_pBkSurface)[uT("height")]);
571
572 for (::std::size_t i = 0; i < TextureComponents.size(); i++)
573 {
574 const auto pTextureComponent = TextureComponents[i];
575 EXPECT_EQ(_ExpectedWidth2, (int)(*pTextureComponent)[uT("width")].Default(0));
576 EXPECT_EQ(_ExpectedHeight2, (int)(*pTextureComponent)[uT("height")].Default(0));
577
578 const Texture_t::Ptr_t pTexture =
579 (*pTextureComponent)[uT("entity")].Default(Texture_t::Ptr_t{});
580 ASSERT_NE(nullptr, pTexture);
581 EXPECT_EQ(_IsUseMapper ? _ExpectedWidth2 * _ExpectedHeight2 * 4 : 0,
582 pTexture->m_ReadCopyData.size());
583 }
584
585 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
586 .Times(1);
587
588 EXPECT_CALL(GLProxy, TexImage2D(_, _, _, _, _, _, _, _, _))
589 .Times(0);
590
591 EXPECT_CALL(GLProxy, GetIntegerv(_))
592 .Times(1);
593
594 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, _))
595 .Times(1);
596
597 EXPECT_CALL(GLProxy, Viewport(_, _, _, _))
598 .Times(0);
599
600 Render();
601
602 EXPECT_CALL(GLProxy, GetError())
603 .Times(1)
604 .WillOnce(Return(GL_NO_ERROR));
605
606 IExample.PresentFrame();
607 };
608
609 TestCall(Component_t::Make({ }),
610 false, 45, 67, 45, 67, 90, 134);
611 TestCall(Component_t::Make({ }),
612 true, 45, 67, 45, 67, 90, 134);
613}
614
615// ************************************************************************** //
616TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_InvalidType)
617{
618 const ::std::string ShaderData =
619 "Pixel vs1(Polygon _Value)\r\n"
620 "Pixel vs2(Polyhedron _Value)\r\n";
621
622 using GLProxy_t = ::mock::GLProxy;
623 GLProxy_t GLProxy;
624 GLProxy_t::GetInstance() = &GLProxy;
625
626 const Tested_t Example{ Data_t{} };
627 const ITested_t & IExample = Example;
628
629 auto itCreator = IExample.GetCreators().find(uT("Shader"));
630 ASSERT_NE(IExample.GetCreators().end(), itCreator);
631
632 const ::mock::GLuint ShaderId = 1908250832;
633
634 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pShader)
635 {
636 using namespace ::testing;
637
638 InSequence Dummy;
639
640 EXPECT_CALL(GLProxy, CreateShader(_))
641 .Times(0);
642
643 auto Render = itCreator->second(_pShader);
644 EXPECT_EQ(nullptr, Render);
645 };
646
647 {
648 const auto pShader = Component_t::Make(
649 {
650 { uT("entry"), uT("vs1") },
651 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
652 });
653
654 TestCall(pShader);
655 }
656
657 {
658 const auto pData = Component_t::Make(
659 {
660 { uT("kind"), uT("Shader") },
661 { uT("entry"), uT("vs2") },
662 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
663 });
664
665 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }));
666 }
667}
668
669// ************************************************************************** //
670TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_NotExistsEntryPoint)
671{
672 using GLProxy_t = ::mock::GLProxy;
673 GLProxy_t GLProxy;
674 GLProxy_t::GetInstance() = &GLProxy;
675
676 const Tested_t Example{ Data_t{} };
677 const ITested_t & IExample = Example;
678
679 auto itCreator = IExample.GetCreators().find(uT("Shader"));
680 ASSERT_NE(IExample.GetCreators().end(), itCreator);
681
682 const ::mock::GLuint ShaderId = 1908250832;
683
684 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pShader)
685 {
686 using namespace ::testing;
687
688 InSequence Dummy;
689
690 EXPECT_CALL(GLProxy, CreateShader(_))
691 .Times(0);
692
693 EXPECT_THROW(itCreator->second(_pShader), ::std::exception);
694 };
695
696 {
697 const auto pShader = Component_t::Make(
698 {
699 { uT("entry"), uT("vsUnknown") },
700 });
701
702 TestCall(pShader);
703 }
704
705 {
706 const auto pData = Component_t::Make(
707 {
708 { uT("kind"), uT("Shader") },
709 { uT("entry"), uT("vsUnknown") },
710 });
711
712 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }));
713 }
714}
715
716// ************************************************************************** //
717TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_CompileFail)
718{
719 using GLProxy_t = ::mock::GLProxy;
720 GLProxy_t GLProxy;
721 GLProxy_t::GetInstance() = &GLProxy;
722
723 const Tested_t Example{ Data_t{} };
724 const ITested_t & IExample = Example;
725
726 auto itCreator = IExample.GetCreators().find(uT("Shader"));
727 ASSERT_NE(IExample.GetCreators().end(), itCreator);
728
729 const ::mock::GLuint ShaderId = 1908251346;
730 const ::std::string ErrorText = "Error1908251350";
731
732 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pShader)
733 {
734 using namespace ::testing;
735
736 InSequence Dummy;
737
738 EXPECT_CALL(GLProxy, CreateShader(_))
739 .Times(1)
740 .WillOnce(Return(ShaderId));
741
742 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, _, _, _))
743 .Times(1);
744
745 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
746 .Times(1);
747
748 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
749 .Times(1)
750 .WillOnce(Return(GL_FALSE));
751
752 EXPECT_CALL(GLProxy, GetShaderInfoLog(ShaderId, 512, nullptr))
753 .Times(1)
754 .WillOnce(Return(ErrorText.c_str()));
755
756 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
757 .Times(1);
758
759 EXPECT_STDEXCEPTION(itCreator->second(_pShader),
760 (".*Compile shader fail \\[header line: 175\\]: " + ErrorText).c_str());
761 };
762
763 {
764 const auto pShader = Component_t::Make(
765 {
766 { uT("entry"), uT("vsFlat") },
767 });
768
769 TestCall(pShader);
770 }
771
772 {
773 const auto pData = Component_t::Make(
774 {
775 { uT("kind"), uT("Shader") },
776 { uT("entry"), uT("vsVolume") },
777 });
778
779 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }));
780 }
781}
782
783::std::string ConvertTextShader(const ::std::vector<uint8_t> & _ShaderText)
784{
785 return ::std::string{ _ShaderText.cbegin(), _ShaderText.cend() };
786}
787
788// ************************************************************************** //
789TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_CreateVertex_Default)
790{
791 using GLProxy_t = ::mock::GLProxy;
792 GLProxy_t GLProxy;
793 GLProxy_t::GetInstance() = &GLProxy;
794
795 const Tested_t Example{ Data_t{} };
796 const ITested_t & IExample = Example;
797
798 auto itCreator = IExample.GetCreators().find(uT("Shader"));
799 ASSERT_NE(IExample.GetCreators().end(), itCreator);
800
801 const ::mock::GLuint ShaderId = 1908250832;
802
803 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pShader,
804 const ::std::string & _Entry)
805 {
806 using namespace ::alicorn::extension::std;
807
808 const auto ExpectedShaderText =
809 ShaderHeader +
810 "#define COVELLITE_SHADER_GLSL\r\n"
811 "#define COVELLITE_SHADER_VERTEX\r\n" +
812 ConvertTextShader(::Predefined + ::Data + ::Input + ::Default) +
813 "out Pixel PixelValue;\r\n"
814 "void main()\r\n"
815 "{\r\n"
816 " Vertex InputData;\r\n"
817 " InputData.Position = Covellite_VertexPosition;\r\n"
818 " InputData.TexCoord = Covellite_VertexTexCoord;\r\n"
819 " InputData.Extra = Covellite_VertexExtra;\r\n"
820 " PixelValue = " + _Entry + "(InputData);\r\n"
821 " gl_Position = PixelValue.ScreenPos;\r\n"
822 "}\r\n";
823
824 using namespace ::testing;
825
826 InSequence Dummy;
827
828 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
829 .Times(1)
830 .WillOnce(Return(ShaderId));
831
832 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText, nullptr))
833 .Times(1);
834
835 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
836 .Times(1);
837
838 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
839 .Times(1)
840 .WillOnce(Return(GL_TRUE));
841
842 auto Render = itCreator->second(_pShader);
843 ASSERT_NE(nullptr, Render);
844
845 Render();
846
847 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
848 .Times(1);
849 };
850
851 {
852 const auto pShader = Component_t::Make(
853 {
854 { uT("entry"), uT("vsFlat") },
855 });
856
857 TestCall(pShader, "vsFlat");
858 }
859
860 {
861 const auto pData = Component_t::Make(
862 {
863 { uT("kind"), uT("Shader") },
864 { uT("entry"), uT("vsVolume") },
865 });
866
867 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }), "vsVolume");
868 }
869}
870
871// ************************************************************************** //
872TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_CreateVertex)
873{
874 const ::std::string ShaderData =
875 "Pixel vs1(Vertex _Value)\r\n"
876 "Pixel vs2_Dummy(Vertex _Value)\r\n"
877 "Pixel vs2(Vertex _Value)\r\n";
878
879 using GLProxy_t = ::mock::GLProxy;
880 GLProxy_t GLProxy;
881 GLProxy_t::GetInstance() = &GLProxy;
882
883 const Tested_t Example{ Data_t{} };
884 const ITested_t & IExample = Example;
885
886 auto itCreator = IExample.GetCreators().find(uT("Shader"));
887 ASSERT_NE(IExample.GetCreators().end(), itCreator);
888
889 const ::mock::GLuint ShaderId = 1908250832;
890
891 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pShader,
892 const ::std::string & _Entry)
893 {
894 using namespace ::alicorn::extension::std;
895
896 const auto ExpectedShaderText =
897 ShaderHeader +
898 "#define COVELLITE_SHADER_GLSL\r\n"
899 "#define COVELLITE_SHADER_VERTEX\r\n" +
900 ConvertTextShader(::Predefined + ::Data + ::Input) + ShaderData +
901 "out Pixel PixelValue;\r\n"
902 "void main()\r\n"
903 "{\r\n"
904 " Vertex InputData;\r\n"
905 " InputData.Position = Covellite_VertexPosition;\r\n"
906 " InputData.TexCoord = Covellite_VertexTexCoord;\r\n"
907 " InputData.Extra = Covellite_VertexExtra;\r\n"
908 " PixelValue = " + _Entry + "(InputData);\r\n"
909 " gl_Position = PixelValue.ScreenPos;\r\n"
910 "}\r\n";
911
912 using namespace ::testing;
913
914 InSequence Dummy;
915
916 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
917 .Times(1)
918 .WillOnce(Return(ShaderId));
919
920 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText, nullptr))
921 .Times(1);
922
923 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
924 .Times(1);
925
926 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
927 .Times(1)
928 .WillOnce(Return(GL_TRUE));
929
930 auto Render = itCreator->second(_pShader);
931 ASSERT_NE(nullptr, Render);
932
933 Render();
934
935 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
936 .Times(1);
937 };
938
939 {
940 const auto pShader = Component_t::Make(
941 {
942 { uT("entry"), uT("vs1") },
943 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
944 });
945
946 TestCall(pShader, "vs1");
947 }
948
949 {
950 const auto pData = Component_t::Make(
951 {
952 { uT("kind"), uT("Shader") },
953 { uT("entry"), uT("vs2") },
954 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
955 });
956
957 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }), "vs2");
958 }
959}
960
961// ************************************************************************** //
962TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_CreateVertex_Instance_InvalidValue)
963{
964 const ::std::string ShaderData =
965 "Pixel vs1(Vertex _Value)\r\n"
966 "Pixel vs2(Vertex _Value)\r\n";
967
968 using GLProxy_t = ::mock::GLProxy;
969 GLProxy_t GLProxy;
970 GLProxy_t::GetInstance() = &GLProxy;
971
972 const Tested_t Example{ Data_t{} };
973 const ITested_t & IExample = Example;
974
975 auto itCreator = IExample.GetCreators().find(uT("Shader"));
976 ASSERT_NE(IExample.GetCreators().end(), itCreator);
977
978 using namespace ::testing;
979
980 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pShader)
981 {
982 EXPECT_CALL(GLProxy, CompileShader(_))
983 .Times(0);
984
985 EXPECT_THROW(itCreator->second(_pShader), ::std::exception);
986 };
987
988 {
989 const auto pShader = Component_t::Make(
990 {
991 { uT("entry"), uT("vs1") },
992 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
993 { uT("instance"), uT("invalid1909231417") },
994 });
995
996 TestCall(pShader);
997 }
998
999 {
1000 const auto pData = Component_t::Make(
1001 {
1002 { uT("kind"), uT("Shader") },
1003 { uT("entry"), uT("vs2") },
1004 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1005 { uT("instance"), uT("invalid1909231418") },
1006 });
1007
1008 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }));
1009 }
1010}
1011
1012// ************************************************************************** //
1013TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_CreateVertex_Instance)
1014{
1015 const ::std::string ShaderData =
1016 "Pixel vs1(Vertex _Value)\r\n"
1017 "Pixel vs2(Vertex _Value)\r\n";
1018
1019 using GLProxy_t = ::mock::GLProxy;
1020 GLProxy_t GLProxy;
1021 GLProxy_t::GetInstance() = &GLProxy;
1022
1023 const Tested_t Example{ Data_t{} };
1024 const ITested_t & IExample = Example;
1025
1026 auto itCreator = IExample.GetCreators().find(uT("Shader"));
1027 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1028
1029 const ::mock::GLuint ShaderId = 1908250832;
1030
1031 auto InputData = ConvertTextShader(::Input);
1032
1033 ::boost::algorithm::replace_first(InputData,
1034 "/* place for instance variables */", ::std::string{} +
1035 "COVELLITE_IN float4 iValue1 COVELLITE_INPUT_SEMANTIC(TEXCOORD1);" + (char)0x5C + "\r\n"
1036 "COVELLITE_IN float4 iValue2 COVELLITE_INPUT_SEMANTIC(TEXCOORD2);" + (char)0x5C + "\r\n"
1037 "COVELLITE_IN int4 iValue3 COVELLITE_INPUT_SEMANTIC(TEXCOORD3);" + (char)0x5C + "\r\n"
1038 "COVELLITE_IN float4 iValue4 COVELLITE_INPUT_SEMANTIC(TEXCOORD4);" + (char)0x5C + "\r\n"
1039 );
1040
1041 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pShader,
1042 const ::std::string & _Entry)
1043 {
1044 using namespace ::alicorn::extension::std;
1045
1046 const auto ExpectedShaderText =
1047 ShaderHeader +
1048 "#define COVELLITE_SHADER_GLSL\r\n"
1049 "#define COVELLITE_SHADER_VERTEX\r\n" +
1050 ConvertTextShader(::Predefined + ::Data) + InputData + ShaderData +
1051 "out Pixel PixelValue;\r\n"
1052 "void main()\r\n"
1053 "{\r\n"
1054 " Vertex InputData;\r\n"
1055 " InputData.Position = Covellite_VertexPosition;\r\n"
1056 " InputData.TexCoord = Covellite_VertexTexCoord;\r\n"
1057 " InputData.Extra = Covellite_VertexExtra;\r\n"
1058 " InputData.iValue1 = iValue1;\r\n"
1059 " InputData.iValue2 = iValue2;\r\n"
1060 " InputData.iValue3 = iValue3;\r\n"
1061 " InputData.iValue4 = iValue4;\r\n"
1062 " PixelValue = " + _Entry + "(InputData);\r\n"
1063 " gl_Position = PixelValue.ScreenPos;\r\n"
1064 "}\r\n";
1065
1066 using namespace ::testing;
1067
1068 InSequence Dummy;
1069
1070 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
1071 .Times(1)
1072 .WillOnce(Return(ShaderId));
1073
1074 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText, nullptr))
1075 .Times(1);
1076
1077 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1078 .Times(1);
1079
1080 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1081 .Times(1)
1082 .WillOnce(Return(GL_TRUE));
1083
1084 auto Render = itCreator->second(_pShader);
1085 ASSERT_NE(nullptr, Render);
1086
1087 Render();
1088
1089 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1090 .Times(1);
1091 };
1092
1093 {
1094 const auto pShader = Component_t::Make(
1095 {
1096 { uT("entry"), uT("vs1") },
1097 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1098 { uT("instance"), uT("f4f4i4f4") },
1099 });
1100
1101 TestCall(pShader, "vs1");
1102 }
1103
1104 {
1105 const auto pData = Component_t::Make(
1106 {
1107 { uT("kind"), uT("Shader") },
1108 { uT("entry"), uT("vs2") },
1109 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1110 { uT("instance"), uT("f4f4i4f4") },
1111 });
1112
1113 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }), "vs2");
1114 }
1115}
1116
1117// ************************************************************************** //
1118TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_CreatePixel_Default)
1119{
1120 using GLProxy_t = ::mock::GLProxy;
1121 GLProxy_t GLProxy;
1122 GLProxy_t::GetInstance() = &GLProxy;
1123
1124 const Tested_t Example{ Data_t{} };
1125 const ITested_t & IExample = Example;
1126
1127 auto itCreator = IExample.GetCreators().find(uT("Shader"));
1128 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1129
1130 const ::mock::GLuint ShaderId = 1908250832;
1131
1132 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pShader,
1133 const ::std::string & _Entry)
1134 {
1135 using namespace ::alicorn::extension::std;
1136
1137 const auto ExpectedShaderText =
1138 ShaderHeader +
1139 "#define COVELLITE_SHADER_GLSL\r\n"
1140 "#define COVELLITE_SHADER_PIXEL\r\n" +
1141 ConvertTextShader(::Predefined + ::Data + ::Input + ::Default) +
1142 "in Pixel PixelValue;\r\n"
1143 "out vec4 Covellite_OutPixelColor;\r\n"
1144 "void main()\r\n"
1145 "{\r\n"
1146 " Covellite_OutPixelColor = " + _Entry + "(PixelValue);\r\n"
1147 "}\r\n";
1148
1149 using namespace ::testing;
1150
1151 InSequence Dummy;
1152
1153 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1154 .Times(1)
1155 .WillOnce(Return(ShaderId));
1156
1157 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText, nullptr))
1158 .Times(1);
1159
1160 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1161 .Times(1);
1162
1163 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1164 .Times(1)
1165 .WillOnce(Return(GL_TRUE));
1166
1167 auto Render = itCreator->second(_pShader);
1168 ASSERT_NE(nullptr, Render);
1169
1170 Render();
1171
1172 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1173 .Times(1);
1174 };
1175
1176 {
1177 const auto pShader = Component_t::Make(
1178 {
1179 { uT("entry"), uT("psColored") },
1180 });
1181
1182 TestCall(pShader, "psColored");
1183 }
1184
1185 {
1186 const auto pData = Component_t::Make(
1187 {
1188 { uT("kind"), uT("Shader") },
1189 { uT("entry"), uT("psTextured") },
1190 });
1191
1192 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }), "psTextured");
1193 }
1194}
1195
1196// ************************************************************************** //
1197TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_CreatePixel_SingleTarget)
1198{
1199 const ::std::string ShaderData =
1200 "float4 ps1(Pixel _Value)\r\n"
1201 "vec4 ps2_Dummy(Pixel _Value)\r\n"
1202 "vec4 ps2(Pixel _Value)\r\n";
1203
1204 using GLProxy_t = ::mock::GLProxy;
1205 GLProxy_t GLProxy;
1206 GLProxy_t::GetInstance() = &GLProxy;
1207
1208 const Tested_t Example{ Data_t{} };
1209 const ITested_t & IExample = Example;
1210
1211 auto itCreator = IExample.GetCreators().find(uT("Shader"));
1212 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1213
1214 const ::mock::GLuint ShaderId = 1908250832;
1215
1216 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pShader,
1217 const ::std::string & _Entry)
1218 {
1219 using namespace ::alicorn::extension::std;
1220
1221 const auto ExpectedShaderText =
1222 ShaderHeader +
1223 "#define COVELLITE_SHADER_GLSL\r\n"
1224 "#define COVELLITE_SHADER_PIXEL\r\n" +
1225 ConvertTextShader(::Predefined + ::Data + ::Input) + ShaderData +
1226 "in Pixel PixelValue;\r\n"
1227 "out vec4 Covellite_OutPixelColor;\r\n"
1228 "void main()\r\n"
1229 "{\r\n"
1230 " Covellite_OutPixelColor = " + _Entry + "(PixelValue);\r\n"
1231 "}\r\n";
1232
1233 using namespace ::testing;
1234
1235 InSequence Dummy;
1236
1237 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1238 .Times(1)
1239 .WillOnce(Return(ShaderId));
1240
1241 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText, nullptr))
1242 .Times(1);
1243
1244 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1245 .Times(1);
1246
1247 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1248 .Times(1)
1249 .WillOnce(Return(GL_TRUE));
1250
1251 auto Render = itCreator->second(_pShader);
1252 ASSERT_NE(nullptr, Render);
1253
1254 Render();
1255
1256 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1257 .Times(1);
1258 };
1259
1260 {
1261 const auto pShader = Component_t::Make(
1262 {
1263 { uT("entry"), uT("ps1") },
1264 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1265 });
1266
1267 TestCall(pShader, "ps1");
1268 }
1269
1270 {
1271 const auto pData = Component_t::Make(
1272 {
1273 { uT("kind"), uT("Shader") },
1274 { uT("entry"), uT("ps2") },
1275 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1276 });
1277
1278 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }), "ps2");
1279 }
1280}
1281
1282// ************************************************************************** //
1283TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_CreatePixel_MultiTarget)
1284{
1285 const ::std::string ShaderData =
1286 "Multi1910031832 ps(Pixel _Value)\r\n";
1287
1288 using GLProxy_t = ::mock::GLProxy;
1289 GLProxy_t GLProxy;
1290 GLProxy_t::GetInstance() = &GLProxy;
1291
1292 const Tested_t Example{ Data_t{} };
1293 const ITested_t & IExample = Example;
1294
1295 auto itCreator = IExample.GetCreators().find(uT("Shader"));
1296 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1297
1298 const ::mock::GLuint ShaderId = 1908250832;
1299
1300 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pShader,
1301 const ::std::string & _Entry)
1302 {
1303 using namespace ::alicorn::extension::std;
1304
1305 const auto ExpectedShaderText =
1306 ShaderHeader +
1307 "#define COVELLITE_SHADER_GLSL\r\n"
1308 "#define COVELLITE_SHADER_PIXEL\r\n" +
1309 ConvertTextShader(::Predefined + ::Data + ::Input) + ShaderData +
1310 "in Pixel PixelValue;\r\n"
1311 "void main()\r\n"
1312 "{\r\n"
1313 " Covellite_MultiOutPixelColor = " + _Entry + "(PixelValue).Target;\r\n"
1314 "}\r\n";
1315
1316 using namespace ::testing;
1317
1318 InSequence Dummy;
1319
1320 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1321 .Times(1)
1322 .WillOnce(Return(ShaderId));
1323
1324 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText, nullptr))
1325 .Times(1);
1326
1327 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1328 .Times(1);
1329
1330 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1331 .Times(1)
1332 .WillOnce(Return(GL_TRUE));
1333
1334 auto Render = itCreator->second(_pShader);
1335 ASSERT_NE(nullptr, Render);
1336
1337 Render();
1338
1339 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1340 .Times(1);
1341 };
1342
1343 {
1344 const auto pShader = Component_t::Make(
1345 {
1346 { uT("entry"), uT("ps") },
1347 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1348 });
1349
1350 TestCall(pShader, "ps");
1351 }
1352
1353 {
1354 const auto pData = Component_t::Make(
1355 {
1356 { uT("kind"), uT("Shader") },
1357 { uT("entry"), uT("ps") },
1358 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1359 });
1360
1361 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }), "ps");
1362 }
1363}
1364
1365// ************************************************************************** //
1366TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_CreatePixel_NoReturn)
1367{
1368 const ::std::string ShaderData =
1369 "void ps(Pixel _Value)\r\n";
1370
1371 using GLProxy_t = ::mock::GLProxy;
1372 GLProxy_t GLProxy;
1373 GLProxy_t::GetInstance() = &GLProxy;
1374
1375 const Tested_t Example{ Data_t{} };
1376 const ITested_t & IExample = Example;
1377
1378 auto itCreator = IExample.GetCreators().find(uT("Shader"));
1379 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1380
1381 const ::mock::GLuint ShaderId = 1908250832;
1382
1383 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pShader,
1384 const ::std::string & _Entry)
1385 {
1386 using namespace ::alicorn::extension::std;
1387
1388 const auto ExpectedShaderText =
1389 ShaderHeader +
1390 "#define COVELLITE_SHADER_GLSL\r\n"
1391 "#define COVELLITE_SHADER_PIXEL\r\n" +
1392 ConvertTextShader(::Predefined + ::Data + ::Input) + ShaderData +
1393 "in Pixel PixelValue;\r\n"
1394 "void main()\r\n"
1395 "{\r\n"
1396 " " + _Entry + "(PixelValue);\r\n"
1397 "}\r\n";
1398
1399 using namespace ::testing;
1400
1401 InSequence Dummy;
1402
1403 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1404 .Times(1)
1405 .WillOnce(Return(ShaderId));
1406
1407 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText, nullptr))
1408 .Times(1);
1409
1410 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1411 .Times(1);
1412
1413 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1414 .Times(1)
1415 .WillOnce(Return(GL_TRUE));
1416
1417 auto Render = itCreator->second(_pShader);
1418 ASSERT_NE(nullptr, Render);
1419
1420 Render();
1421
1422 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1423 .Times(1);
1424 };
1425
1426 {
1427 const auto pShader = Component_t::Make(
1428 {
1429 { uT("entry"), uT("ps") },
1430 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1431 });
1432
1433 TestCall(pShader, "ps");
1434 }
1435
1436 {
1437 const auto pData = Component_t::Make(
1438 {
1439 { uT("kind"), uT("Shader") },
1440 { uT("entry"), uT("ps") },
1441 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1442 });
1443
1444 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }), "ps");
1445 }
1446}
1447
1448// ************************************************************************** //
1449TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_UsingProgram_DeleteVertexShader)
1450{
1451 const ::std::string ShaderData =
1452 "Pixel vs(Vertex _Value)\r\n"
1453 "float4 ps(Pixel _Value)\r\n";
1454
1455 using GLProxy_t = ::mock::GLProxy;
1456 GLProxy_t GLProxy;
1457 GLProxy_t::GetInstance() = &GLProxy;
1458
1459 const Tested_t Example{ Data_t{} };
1460 const ITested_t & IExample = Example;
1461
1462 auto itCreator = IExample.GetCreators().find(uT("Shader"));
1463 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1464
1465 const auto pVertexShader0 = Component_t::Make(
1466 {
1467 { uT("entry"), uT("vs") },
1468 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1469 });
1470
1471 const auto pVertexShader1 = Component_t::Make(
1472 {
1473 { uT("entry"), uT("vs") },
1474 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1475 });
1476
1477 const auto pPixelShader0 = Component_t::Make(
1478 {
1479 { uT("entry"), uT("ps") },
1480 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1481 });
1482
1483 const auto pPixelShader1 = Component_t::Make(
1484 {
1485 { uT("entry"), uT("ps") },
1486 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1487 });
1488
1489 const ::mock::GLuint VertexShader0Id = 1908251613;
1490 const ::mock::GLuint VertexShader1Id = 1908251614;
1491 const ::mock::GLuint PixelShader0Id = 1908251615;
1492 const ::mock::GLuint PixelShader1Id = 1908251616;
1493
1494 const ::mock::GLuint Program00Id = 1908251641;
1495 const ::mock::GLuint Program01Id = 1908251652;
1496 const ::mock::GLuint Program10Id = 1908251653;
1497 const ::mock::GLuint Program11Id = 1908251654;
1498
1499 using namespace ::testing;
1500
1501 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1502 .Times(2)
1503 .WillOnce(Return(PixelShader0Id))
1504 .WillOnce(Return(PixelShader1Id));
1505
1506 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
1507 .Times(2)
1508 .WillOnce(Return(VertexShader0Id))
1509 .WillOnce(Return(VertexShader1Id));
1510
1511 auto PixelShaderRender0 = itCreator->second(pPixelShader0);
1512 ASSERT_NE(nullptr, PixelShaderRender0);
1513
1514 auto PixelShaderRender1 = itCreator->second(pPixelShader1);
1515 ASSERT_NE(nullptr, PixelShaderRender1);
1516
1517 auto VertexShaderRender0 = itCreator->second(pVertexShader0);
1518 ASSERT_NE(nullptr, VertexShaderRender0);
1519
1520 InSequence Dummy;
1521
1522 {
1523 auto VertexShaderRender1 = itCreator->second(pVertexShader1);
1524 ASSERT_NE(nullptr, VertexShaderRender1);
1525
1526 const auto TestCreateProgram = [&](
1527 const ::mock::GLuint _ProgramId,
1528 const ::mock::GLuint _VertexShaderId,
1529 const ::mock::GLuint _PixelShaderId)
1530 {
1531 EXPECT_CALL(GLProxy, CreateProgram())
1532 .Times(1)
1533 .WillOnce(Return(_ProgramId));
1534
1535 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _VertexShaderId))
1536 .Times(1);
1537
1538 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _PixelShaderId))
1539 .Times(1);
1540
1541 EXPECT_CALL(GLProxy, LinkProgram(_ProgramId))
1542 .Times(1);
1543
1544 EXPECT_CALL(GLProxy, GetProgramiv(_ProgramId, GL_LINK_STATUS))
1545 .Times(1)
1546 .WillOnce(Return(GL_TRUE));
1547 };
1548
1549 // **************** Cоздание объектов программ шейдеров ******************* //
1550
1551 EXPECT_CALL(GLProxy, CreateProgram())
1552 .Times(0);
1553
1554 VertexShaderRender0();
1555
1556 TestCreateProgram(Program00Id, VertexShader0Id, PixelShader0Id);
1557
1558 EXPECT_CALL(GLProxy, UseProgram(Program00Id))
1559 .Times(1);
1560
1561 PixelShaderRender0();
1562
1563 TestCreateProgram(Program10Id, VertexShader1Id, PixelShader0Id);
1564
1565 EXPECT_CALL(GLProxy, UseProgram(Program10Id))
1566 .Times(1);
1567
1568 VertexShaderRender1();
1569
1570 TestCreateProgram(Program11Id, VertexShader1Id, PixelShader1Id);
1571
1572 EXPECT_CALL(GLProxy, UseProgram(Program11Id))
1573 .Times(1);
1574
1575 PixelShaderRender1();
1576
1577 TestCreateProgram(Program01Id, VertexShader0Id, PixelShader1Id);
1578
1579 EXPECT_CALL(GLProxy, UseProgram(Program01Id))
1580 .Times(1);
1581
1582 VertexShaderRender0();
1583
1584 // ********* Использование ранее созданных программ шейдеров ************ //
1585
1586 EXPECT_CALL(GLProxy, CreateProgram())
1587 .Times(0);
1588
1589 EXPECT_CALL(GLProxy, UseProgram(Program00Id))
1590 .Times(1);
1591
1592 PixelShaderRender0();
1593
1594 EXPECT_CALL(GLProxy, CreateProgram())
1595 .Times(0);
1596
1597 EXPECT_CALL(GLProxy, UseProgram(Program10Id))
1598 .Times(1);
1599
1600 VertexShaderRender1();
1601
1602 EXPECT_CALL(GLProxy, CreateProgram())
1603 .Times(0);
1604
1605 EXPECT_CALL(GLProxy, UseProgram(Program11Id))
1606 .Times(1);
1607
1608 PixelShaderRender1();
1609
1610 EXPECT_CALL(GLProxy, CreateProgram())
1611 .Times(0);
1612
1613 EXPECT_CALL(GLProxy, UseProgram(Program01Id))
1614 .Times(1);
1615
1616 VertexShaderRender0();
1617
1618 EXPECT_CALL(GLProxy, DeleteProgram(Program10Id))
1619 .Times(1);
1620
1621 EXPECT_CALL(GLProxy, DeleteProgram(Program11Id))
1622 .Times(1);
1623
1624 EXPECT_CALL(GLProxy, DeleteShader(VertexShader1Id))
1625 .Times(1);
1626 }
1627
1628 EXPECT_CALL(GLProxy, DeleteProgram(Program00Id))
1629 .Times(1);
1630
1631 EXPECT_CALL(GLProxy, DeleteProgram(Program01Id))
1632 .Times(1);
1633
1634 EXPECT_CALL(GLProxy, DeleteShader(VertexShader0Id))
1635 .Times(1);
1636
1637 EXPECT_CALL(GLProxy, DeleteShader(PixelShader1Id))
1638 .Times(1);
1639
1640 EXPECT_CALL(GLProxy, DeleteShader(PixelShader0Id))
1641 .Times(1);
1642}
1643
1644// ************************************************************************** //
1645TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_UsingProgram_DeletePixelShader)
1646{
1647 const ::std::string ShaderData =
1648 "Pixel vs(Vertex _Value)\r\n"
1649 "float4 ps(Pixel _Value)\r\n";
1650
1651 using GLProxy_t = ::mock::GLProxy;
1652 GLProxy_t GLProxy;
1653 GLProxy_t::GetInstance() = &GLProxy;
1654
1655 const Tested_t Example{ Data_t{} };
1656 const ITested_t & IExample = Example;
1657
1658 auto itCreator = IExample.GetCreators().find(uT("Shader"));
1659 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1660
1661 const auto pVertexShader0 = Component_t::Make(
1662 {
1663 { uT("entry"), uT("vs") },
1664 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1665 });
1666
1667 const auto pVertexShader1 = Component_t::Make(
1668 {
1669 { uT("entry"), uT("vs") },
1670 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1671 });
1672
1673 const auto pPixelShader0 = Component_t::Make(
1674 {
1675 { uT("entry"), uT("ps") },
1676 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1677 });
1678
1679 const auto pPixelShader1 = Component_t::Make(
1680 {
1681 { uT("entry"), uT("ps") },
1682 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1683 });
1684
1685 const ::mock::GLuint VertexShader0Id = 1908251613;
1686 const ::mock::GLuint VertexShader1Id = 1908251614;
1687 const ::mock::GLuint PixelShader0Id = 1908251615;
1688 const ::mock::GLuint PixelShader1Id = 1908251616;
1689
1690 const ::mock::GLuint Program00Id = 1908251641;
1691 const ::mock::GLuint Program01Id = 1908251652;
1692 const ::mock::GLuint Program10Id = 1908251653;
1693 const ::mock::GLuint Program11Id = 1908251654;
1694
1695 using namespace ::testing;
1696
1697 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
1698 .Times(2)
1699 .WillOnce(Return(VertexShader0Id))
1700 .WillOnce(Return(VertexShader1Id));
1701
1702 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1703 .Times(2)
1704 .WillOnce(Return(PixelShader0Id))
1705 .WillOnce(Return(PixelShader1Id));
1706
1707 auto VertexShaderRender0 = itCreator->second(pVertexShader0);
1708 ASSERT_NE(nullptr, VertexShaderRender0);
1709
1710 auto VertexShaderRender1 = itCreator->second(pVertexShader1);
1711 ASSERT_NE(nullptr, VertexShaderRender1);
1712
1713 auto PixelShaderRender0 = itCreator->second(pPixelShader0);
1714 ASSERT_NE(nullptr, PixelShaderRender0);
1715
1716 InSequence Dummy;
1717
1718 {
1719 auto PixelShaderRender1 = itCreator->second(pPixelShader1);
1720 ASSERT_NE(nullptr, PixelShaderRender1);
1721
1722 const auto TestCreateProgram = [&](
1723 const ::mock::GLuint _ProgramId,
1724 const ::mock::GLuint _VertexShaderId,
1725 const ::mock::GLuint _PixelShaderId)
1726 {
1727 EXPECT_CALL(GLProxy, CreateProgram())
1728 .Times(1)
1729 .WillOnce(Return(_ProgramId));
1730
1731 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _VertexShaderId))
1732 .Times(1);
1733
1734 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _PixelShaderId))
1735 .Times(1);
1736
1737 EXPECT_CALL(GLProxy, LinkProgram(_ProgramId))
1738 .Times(1);
1739
1740 EXPECT_CALL(GLProxy, GetProgramiv(_ProgramId, GL_LINK_STATUS))
1741 .Times(1)
1742 .WillOnce(Return(GL_TRUE));
1743 };
1744
1745 // **************** Cоздание объектов программ шейдеров ******************* //
1746
1747 EXPECT_CALL(GLProxy, CreateProgram())
1748 .Times(0);
1749
1750 VertexShaderRender0();
1751
1752 TestCreateProgram(Program00Id, VertexShader0Id, PixelShader0Id);
1753
1754 EXPECT_CALL(GLProxy, UseProgram(Program00Id))
1755 .Times(1);
1756
1757 PixelShaderRender0();
1758
1759 TestCreateProgram(Program10Id, VertexShader1Id, PixelShader0Id);
1760
1761 EXPECT_CALL(GLProxy, UseProgram(Program10Id))
1762 .Times(1);
1763
1764 VertexShaderRender1();
1765
1766 TestCreateProgram(Program11Id, VertexShader1Id, PixelShader1Id);
1767
1768 EXPECT_CALL(GLProxy, UseProgram(Program11Id))
1769 .Times(1);
1770
1771 PixelShaderRender1();
1772
1773 TestCreateProgram(Program01Id, VertexShader0Id, PixelShader1Id);
1774
1775 EXPECT_CALL(GLProxy, UseProgram(Program01Id))
1776 .Times(1);
1777
1778 VertexShaderRender0();
1779
1780 // ********* Использование ранее созданных программ шейдеров ************ //
1781
1782 EXPECT_CALL(GLProxy, CreateProgram())
1783 .Times(0);
1784
1785 EXPECT_CALL(GLProxy, UseProgram(Program00Id))
1786 .Times(1);
1787
1788 PixelShaderRender0();
1789
1790 EXPECT_CALL(GLProxy, CreateProgram())
1791 .Times(0);
1792
1793 EXPECT_CALL(GLProxy, UseProgram(Program10Id))
1794 .Times(1);
1795
1796 VertexShaderRender1();
1797
1798 EXPECT_CALL(GLProxy, CreateProgram())
1799 .Times(0);
1800
1801 EXPECT_CALL(GLProxy, UseProgram(Program11Id))
1802 .Times(1);
1803
1804 PixelShaderRender1();
1805
1806 EXPECT_CALL(GLProxy, CreateProgram())
1807 .Times(0);
1808
1809 EXPECT_CALL(GLProxy, UseProgram(Program01Id))
1810 .Times(1);
1811
1812 VertexShaderRender0();
1813
1814 EXPECT_CALL(GLProxy, DeleteProgram(Program01Id))
1815 .Times(1);
1816
1817 EXPECT_CALL(GLProxy, DeleteProgram(Program11Id))
1818 .Times(1);
1819
1820 EXPECT_CALL(GLProxy, DeleteShader(PixelShader1Id))
1821 .Times(1);
1822 }
1823
1824 EXPECT_CALL(GLProxy, DeleteProgram(Program00Id))
1825 .Times(1);
1826
1827 EXPECT_CALL(GLProxy, DeleteProgram(Program10Id))
1828 .Times(1);
1829
1830 EXPECT_CALL(GLProxy, DeleteShader(PixelShader0Id))
1831 .Times(1);
1832
1833 EXPECT_CALL(GLProxy, DeleteShader(VertexShader1Id))
1834 .Times(1);
1835
1836 EXPECT_CALL(GLProxy, DeleteShader(VertexShader0Id))
1837 .Times(1);
1838}
1839
1840// ************************************************************************** //
1841TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Shader_UsingProgram_LinkProgramFail)
1842{
1843 using namespace ::alicorn::extension::std;
1844
1845 const ::std::string ShaderData =
1846 "Pixel vs(Vertex _Value)\r\n"
1847 "float4 ps(Pixel _Value)\r\n";
1848
1849 const ::std::string ErrorText = "Error1908291952";
1850 const auto LinkFailLogText = uT("Warning: Link program fail: ") +
1851 string_cast<String, Encoding::UTF8>(ErrorText);
1852
1853 using LoggerProxy_t = ::mock::alicorn::modules::logger::LoggerProxy;
1854 LoggerProxy_t LoggerProxy;
1855 LoggerProxy_t::GetInstance() = &LoggerProxy;
1856
1857 using GLProxy_t = ::mock::GLProxy;
1858 GLProxy_t GLProxy;
1859 GLProxy_t::GetInstance() = &GLProxy;
1860
1861 const Tested_t Example{ Data_t{} };
1862 const ITested_t & IExample = Example;
1863
1864 auto itCreator = IExample.GetCreators().find(uT("Shader"));
1865 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1866
1867 const auto pVertexShader0 = Component_t::Make(
1868 {
1869 { uT("entry"), uT("vs") },
1870 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1871 });
1872
1873 const auto pVertexShader1 = Component_t::Make(
1874 {
1875 { uT("entry"), uT("vs") },
1876 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1877 });
1878
1879 const auto pPixelShader0 = Component_t::Make(
1880 {
1881 { uT("entry"), uT("ps") },
1882 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1883 });
1884
1885 const auto pPixelShader1 = Component_t::Make(
1886 {
1887 { uT("entry"), uT("ps") },
1888 { uT("content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1889 });
1890
1891 const ::mock::GLuint VertexShader0Id = 1908251613;
1892 const ::mock::GLuint VertexShader1Id = 1908251614;
1893 const ::mock::GLuint PixelShader0Id = 1908251615;
1894 const ::mock::GLuint PixelShader1Id = 1908251616;
1895
1896 const ::mock::GLuint Program00Id = 1908251641;
1897 const ::mock::GLuint Program01Id = 1908251652;
1898 const ::mock::GLuint Program10Id = 1908251653;
1899 const ::mock::GLuint Program11Id = 1908251654;
1900
1901 using namespace ::testing;
1902
1903 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
1904 .Times(2)
1905 .WillOnce(Return(VertexShader0Id))
1906 .WillOnce(Return(VertexShader1Id));
1907
1908 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1909 .Times(2)
1910 .WillOnce(Return(PixelShader0Id))
1911 .WillOnce(Return(PixelShader1Id));
1912
1913 auto VertexShaderRender0 = itCreator->second(pVertexShader0);
1914 ASSERT_NE(nullptr, VertexShaderRender0);
1915
1916 auto VertexShaderRender1 = itCreator->second(pVertexShader1);
1917 ASSERT_NE(nullptr, VertexShaderRender1);
1918
1919 auto PixelShaderRender0 = itCreator->second(pPixelShader0);
1920 ASSERT_NE(nullptr, PixelShaderRender0);
1921
1922 InSequence Dummy;
1923
1924 {
1925 auto PixelShaderRender1 = itCreator->second(pPixelShader1);
1926 ASSERT_NE(nullptr, PixelShaderRender1);
1927
1928 const auto TestCreateProgram = [&](
1929 const ::mock::GLuint _ProgramId,
1930 const ::mock::GLuint _VertexShaderId,
1931 const ::mock::GLuint _PixelShaderId,
1932 const Render_t & _Render)
1933 {
1934 EXPECT_CALL(GLProxy, CreateProgram())
1935 .Times(1)
1936 .WillOnce(Return(_ProgramId));
1937
1938 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _VertexShaderId))
1939 .Times(1);
1940
1941 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _PixelShaderId))
1942 .Times(1);
1943
1944 EXPECT_CALL(GLProxy, LinkProgram(_ProgramId))
1945 .Times(1);
1946
1947 EXPECT_CALL(GLProxy, GetProgramiv(_ProgramId, GL_LINK_STATUS))
1948 .Times(1)
1949 .WillOnce(Return(GL_FALSE));
1950
1951 EXPECT_CALL(GLProxy, GetProgramInfoLog(_ProgramId, 512, nullptr))
1952 .Times(1)
1953 .WillOnce(Return(ErrorText.c_str()));
1954
1955 EXPECT_CALL(LoggerProxy, ToLog(Eq(LinkFailLogText)))
1956 .Times(1);
1957
1958 _Render();
1959 };
1960
1961 EXPECT_CALL(GLProxy, CreateProgram())
1962 .Times(0);
1963
1964 EXPECT_CALL(GLProxy, UseProgram(_))
1965 .Times(0);
1966
1967 VertexShaderRender0();
1968
1969 TestCreateProgram(Program00Id, VertexShader0Id, PixelShader0Id,
1970 PixelShaderRender0);
1971
1972 TestCreateProgram(Program10Id, VertexShader1Id, PixelShader0Id,
1973 VertexShaderRender1);
1974
1975 TestCreateProgram(Program11Id, VertexShader1Id, PixelShader1Id,
1976 PixelShaderRender1);
1977
1978 TestCreateProgram(Program01Id, VertexShader0Id, PixelShader1Id,
1979 VertexShaderRender0);
1980
1981 EXPECT_CALL(GLProxy, DeleteProgram(Program01Id))
1982 .Times(1);
1983
1984 EXPECT_CALL(GLProxy, DeleteProgram(Program11Id))
1985 .Times(1);
1986 }
1987
1988 EXPECT_CALL(GLProxy, DeleteProgram(Program00Id))
1989 .Times(1);
1990
1991 EXPECT_CALL(GLProxy, DeleteProgram(Program10Id))
1992 .Times(1);
1993}
1994
1995// ************************************************************************** //
1996TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_Default)
1997{
1998 using GLProxy_t = ::mock::GLProxy;
1999 GLProxy_t GLProxy;
2000 GLProxy_t::GetInstance() = &GLProxy;
2001
2002 const Tested_t Example{ Data_t{} };
2003 const ITested_t & IExample = Example;
2004
2005 auto itCreator = IExample.GetCreators().find(uT("Texture"));
2006 ASSERT_NE(IExample.GetCreators().end(), itCreator);
2007
2008 const ::mock::GLuint TextureId = 1812181809;
2009 const ::mock::GLint ProgramId = 1908221258;
2010 const ::mock::GLint LocationId = 1908221259;
2011
2012 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pTexture,
2013 const ::std::vector<uint8_t> & _Source, const int _Width, const int _Height)
2014 {
2015 using namespace ::testing;
2016
2017 InSequence Dummy;
2018
2019 EXPECT_CALL(GLProxy, GenTextures(1))
2020 .Times(1)
2021 .WillOnce(Return(TextureId));
2022
2023 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2024 .Times(1);
2025
2026 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
2027 _Width, _Height, 0,
2028 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
2029 .Times(1);
2030
2031 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2032 .Times(1);
2033
2034 EXPECT_CALL(GLProxy, GetError())
2035 .Times(1)
2036 .WillOnce(Return(GL_NO_ERROR));
2037
2038 auto Render = itCreator->second(_pTexture);
2039 ASSERT_NE(nullptr, Render);
2040
2041 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0))
2042 .Times(1);
2043
2044 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2045 .Times(1);
2046
2047 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2048 .Times(1)
2049 .WillOnce(Return(&ProgramId));
2050
2051 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("TexDiffuse")))
2052 .Times(1)
2053 .WillOnce(Return(LocationId));
2054
2055 EXPECT_CALL(GLProxy, Uniform1i(LocationId, 0))
2056 .Times(1);
2057
2058 Render();
2059
2060 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
2061 .Times(1);
2062 };
2063
2064 {
2065 ::std::vector<uint8_t> Source =
2066 {
2067 0x20, 0x06, 0x15, 0x12, 0x28,
2068 0x20, 0x06, 0x15, 0x12, 0x28,
2069 0x20, 0x06, 0x15, 0x12, 0x28,
2070 0x20, 0x06, 0x15, 0x12, 0x28,
2071 0x20, 0x06, 0x15, 0x12, 0x28,
2072 0x20, 0x06, 0x15, 0x12, 0x28,
2073 0x20, 0x06, 0x15, 0x12, 0x28,
2074 0x20, 0x06, 0x15, 0x12, 0x28,
2075 };
2076 IntroduceBufferSize(Source);
2077
2078 const int Width = 1812181807;
2079 const int Height = 1812181808;
2080
2081 const auto pTexture = Component_t::Make(
2082 {
2083 { uT("content"), Source },
2084 { uT("width"), Width },
2085 { uT("height"), Height },
2086 });
2087
2088 TestCall(pTexture, Source, Width, Height);
2089 }
2090
2091 {
2092 ::std::vector<uint8_t> Source =
2093 {
2094 0x20, 0x06, 0x15, 0x12, 0x29,
2095 0x20, 0x06, 0x15, 0x12, 0x29,
2096 0x20, 0x06, 0x15, 0x12, 0x29,
2097 0x20, 0x06, 0x15, 0x12, 0x29,
2098 0x20, 0x06, 0x15, 0x12, 0x29,
2099 };
2100 IntroduceBufferSize(Source);
2101
2102 const int Width = 1907251057;
2103 const int Height = 1907251058;
2104
2105 const auto pData = Component_t::Make(
2106 {
2107 { uT("kind"), uT("Texture") },
2108 { uT("content"), Source },
2109 { uT("width"), Width },
2110 { uT("height"), Height },
2111 });
2112
2113 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }), Source, Width, Height);
2114 }
2115}
2116
2117// ************************************************************************** //
2118TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_NameAndIndex)
2119{
2120 using GLProxy_t = ::mock::GLProxy;
2121 GLProxy_t GLProxy;
2122 GLProxy_t::GetInstance() = &GLProxy;
2123
2124 const Tested_t Example{ Data_t{} };
2125 const ITested_t & IExample = Example;
2126
2127 auto itCreator = IExample.GetCreators().find(uT("Texture"));
2128 ASSERT_NE(IExample.GetCreators().end(), itCreator);
2129
2130 const ::mock::GLuint TextureId = 1908221839;
2131 const ::mock::GLint ProgramId = 1908221840;
2132 const ::mock::GLint LocationId = 1908221841;
2133
2134 const auto TestCall = [&](
2135 const Component_t::ComponentPtr_t & _pTexture,
2136 const ::std::vector<uint8_t> & _Source,
2137 const int _Width, const int _Height,
2138 const ::std::size_t _Index,
2139 const ::std::string & _TexName)
2140 {
2141 const auto Index = static_cast<::mock::GLint>(_Index);
2142
2143 using namespace ::testing;
2144
2145 InSequence Dummy;
2146
2147 EXPECT_CALL(GLProxy, GenTextures(1))
2148 .Times(1)
2149 .WillOnce(Return(TextureId));
2150
2151 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2152 .Times(1);
2153
2154 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
2155 _Width, _Height, 0,
2156 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
2157 .Times(1);
2158
2159 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2160 .Times(1);
2161
2162 EXPECT_CALL(GLProxy, GetError())
2163 .Times(1)
2164 .WillOnce(Return(GL_NO_ERROR));
2165
2166 EXPECT_CALL(GLProxy, GenFramebuffers(1))
2167 .Times(0);
2168
2169 auto Render = itCreator->second(_pTexture);
2170 ASSERT_NE(nullptr, Render);
2171
2172 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
2173 .Times(1);
2174
2175 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2176 .Times(1);
2177
2178 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2179 .Times(1)
2180 .WillOnce(Return(&ProgramId));
2181
2182 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
2183 .Times(1)
2184 .WillOnce(Return(LocationId));
2185
2186 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
2187 .Times(0);
2188
2189 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
2190 .Times(1);
2191
2192 Render();
2193
2194 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
2195 .Times(1);
2196 };
2197
2198 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
2199 {
2200 { uT("TexEnvironment"), "TexEnvironment" },
2201 { uT("TexReflection"), "TexReflection" },
2202 { uT("TexBaseColor"), "TexBaseColor" },
2203 };
2204
2205 for (int Index = 0; Index < Names.size(); Index++)
2206 {
2207 ::std::vector<uint8_t> Source =
2208 {
2209 0x20, 0x06, 0x15, 0x12, 0x30,
2210 0x20, 0x06, 0x15, 0x12, 0x30,
2211 0x20, 0x06, 0x15, 0x12, 0x30,
2212 0x20, 0x06, 0x15, 0x12, 0x30,
2213 0x20, 0x06, 0x15, 0x12, 0x30,
2214 };
2215 IntroduceBufferSize(Source);
2216
2217 {
2218 const int Width = 1908221843;
2219 const int Height = 1908221844;
2220
2221 const auto pTexture = Component_t::Make(
2222 {
2223 { uT("content"), Source },
2224 { uT("width"), Width },
2225 { uT("height"), Height },
2226 { uT("name"), Names[Index].first },
2227 { uT("index"), Index },
2228 });
2229
2230 TestCall(pTexture,
2231 Source, Width, Height, Index, Names[Index].second);
2232 }
2233
2234 {
2235 const int Width = 1908221845;
2236 const int Height = 1908221847;
2237
2238 const auto pData = Component_t::Make(
2239 {
2240 { uT("kind"), uT("Texture") },
2241 { uT("content"), Source },
2242 { uT("width"), Width },
2243 { uT("height"), Height },
2244 { uT("name"), Names[Index].first },
2245 { uT("index"), Index },
2246 });
2247
2248 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
2249 Source, Width, Height, Index, Names[Index].second);
2250 }
2251
2252 {
2253 const int Width = 1908221843;
2254 const int Height = 1908221844;
2255
2256 const auto pTexture = Component_t::Make(
2257 {
2258 { uT("content"), Source },
2259 { uT("width"), Width },
2260 { uT("height"), Height },
2261 { uT("name"), Names[Index].first },
2262 { uT("index"), Index },
2263 { uT("mipmapping"), false },
2264 });
2265
2266 TestCall(pTexture,
2267 Source, Width, Height, Index, Names[Index].second);
2268 }
2269
2270 {
2271 const int Width = 1908221845;
2272 const int Height = 1908221847;
2273
2274 const auto pData = Component_t::Make(
2275 {
2276 { uT("kind"), uT("Texture") },
2277 { uT("content"), Source },
2278 { uT("width"), Width },
2279 { uT("height"), Height },
2280 { uT("name"), Names[Index].first },
2281 { uT("index"), Index },
2282 { uT("mipmapping"), false },
2283 });
2284
2285 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
2286 Source, Width, Height, Index, Names[Index].second);
2287 }
2288
2289 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
2290 {
2291 { uT("albedo"), "TexAlbedo" },
2292 { uT("metalness"), "TexMetalness" },
2293 { uT("roughness"), "TexRoughness" },
2294 { uT("normal"), "TexNormal" },
2295 { uT("occlusion"), "TexOcclusion" },
2296 //{ uT("depth"), "TexDepth" }, // другой формат
2297 };
2298
2299 for (::std::size_t i = 0; i < Destinations.size(); i++)
2300 {
2301 {
2302 const int Width = 1908221843;
2303 const int Height = 1908221844;
2304
2305 const auto pTexture = Component_t::Make(
2306 {
2307 { uT("content"), Source },
2308 { uT("width"), Width },
2309 { uT("height"), Height },
2310 { uT("name"), Names[Index].first },
2311 { uT("index"), Index },
2312 { uT("destination"), Destinations[i].first },
2313 });
2314
2315 TestCall(pTexture,
2316 Source, Width, Height, Index, Names[Index].second);
2317 }
2318
2319 {
2320 const int Width = 1908221845;
2321 const int Height = 1908221847;
2322
2323 const auto pData = Component_t::Make(
2324 {
2325 { uT("kind"), uT("Texture") },
2326 { uT("content"), Source },
2327 { uT("width"), Width },
2328 { uT("height"), Height },
2329 { uT("name"), Names[Index].first },
2330 { uT("index"), Index },
2331 { uT("destination"), Destinations[i].first },
2332 });
2333
2334 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
2335 Source, Width, Height, Index, Names[Index].second);
2336 }
2337
2338 {
2339 const int Width = 1908221843;
2340 const int Height = 1908221844;
2341
2342 const auto pTexture = Component_t::Make(
2343 {
2344 { uT("content"), Source },
2345 { uT("width"), Width },
2346 { uT("height"), Height },
2347 { uT("name"), Names[Index].first },
2348 { uT("index"), Index },
2349 { uT("destination"), Destinations[i].first },
2350 { uT("mipmapping"), false },
2351 });
2352
2353 TestCall(pTexture,
2354 Source, Width, Height, Index, Names[Index].second);
2355 }
2356
2357 {
2358 const int Width = 1908221845;
2359 const int Height = 1908221847;
2360
2361 const auto pData = Component_t::Make(
2362 {
2363 { uT("kind"), uT("Texture") },
2364 { uT("content"), Source },
2365 { uT("width"), Width },
2366 { uT("height"), Height },
2367 { uT("name"), Names[Index].first },
2368 { uT("index"), Index },
2369 { uT("destination"), Destinations[i].first },
2370 { uT("mipmapping"), false },
2371 });
2372
2373 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
2374 Source, Width, Height, Index, Names[Index].second);
2375 }
2376 }
2377 }
2378}
2379
2380// ************************************************************************** //
2381TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_NameAndIndex_Capacity16)
2382{
2383 using GLProxy_t = ::mock::GLProxy;
2384 GLProxy_t GLProxy;
2385 GLProxy_t::GetInstance() = &GLProxy;
2386
2387 const Tested_t Example{ Data_t{} };
2388 const ITested_t & IExample = Example;
2389
2390 auto itCreator = IExample.GetCreators().find(uT("Texture"));
2391 ASSERT_NE(IExample.GetCreators().end(), itCreator);
2392
2393 const ::mock::GLuint TextureId = 1908221839;
2394 const ::mock::GLint ProgramId = 1908221840;
2395 const ::mock::GLint LocationId = 1908221841;
2396
2397 const auto TestCall = [&](
2398 const Component_t::ComponentPtr_t & _pTexture,
2399 const ::std::vector<uint8_t> & _Source,
2400 const int _Width, const int _Height,
2401 const ::std::size_t _Index,
2402 const ::std::string & _TexName)
2403 {
2404 const auto Index = static_cast<::mock::GLint>(_Index);
2405
2406 using namespace ::testing;
2407
2408 InSequence Dummy;
2409
2410 EXPECT_CALL(GLProxy, GenTextures(1))
2411 .Times(1)
2412 .WillOnce(Return(TextureId));
2413
2414 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2415 .Times(1);
2416
2417 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
2418 _Width, _Height, 0,
2419 GL_RGBA, GL_HALF_FLOAT, _Source))
2420 .Times(1);
2421
2422 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2423 .Times(1);
2424
2425 EXPECT_CALL(GLProxy, GetError())
2426 .Times(1)
2427 .WillOnce(Return(GL_NO_ERROR));
2428
2429 EXPECT_CALL(GLProxy, GenFramebuffers(1))
2430 .Times(0);
2431
2432 auto Render = itCreator->second(_pTexture);
2433 ASSERT_NE(nullptr, Render);
2434
2435 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
2436 .Times(1);
2437
2438 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2439 .Times(1);
2440
2441 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2442 .Times(1)
2443 .WillOnce(Return(&ProgramId));
2444
2445 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
2446 .Times(1)
2447 .WillOnce(Return(LocationId));
2448
2449 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
2450 .Times(0);
2451
2452 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
2453 .Times(1);
2454
2455 Render();
2456
2457 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
2458 .Times(1);
2459 };
2460
2461 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
2462 {
2463 { uT("TexEnvironment"), "TexEnvironment" },
2464 { uT("TexReflection"), "TexReflection" },
2465 { uT("TexBaseColor"), "TexBaseColor" },
2466 };
2467
2468 for (int Index = 0; Index < Names.size(); Index++)
2469 {
2470 ::std::vector<uint8_t> Source =
2471 {
2472 0x20, 0x06, 0x15, 0x12, 0x30,
2473 0x20, 0x06, 0x15, 0x12, 0x30,
2474 0x20, 0x06, 0x15, 0x12, 0x30,
2475 0x20, 0x06, 0x15, 0x12, 0x30,
2476 0x20, 0x06, 0x15, 0x12, 0x30,
2477 };
2478 IntroduceBufferSize(Source);
2479
2480 {
2481 const int Width = 1908221843;
2482 const int Height = 1908221844;
2483
2484 const auto pTexture = Component_t::Make(
2485 {
2486 { uT("content"), Source },
2487 { uT("width"), Width },
2488 { uT("height"), Height },
2489 { uT("name"), Names[Index].first },
2490 { uT("index"), Index },
2491 { uT("capacity"), 16 },
2492 });
2493
2494 TestCall(pTexture,
2495 Source, Width, Height, Index, Names[Index].second);
2496 }
2497
2498 {
2499 const int Width = 1908221845;
2500 const int Height = 1908221847;
2501
2502 const auto pData = Component_t::Make(
2503 {
2504 { uT("kind"), uT("Texture") },
2505 { uT("content"), Source },
2506 { uT("width"), Width },
2507 { uT("height"), Height },
2508 { uT("name"), Names[Index].first },
2509 { uT("index"), Index },
2510 { uT("capacity"), 16 },
2511 });
2512
2513 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
2514 Source, Width, Height, Index, Names[Index].second);
2515 }
2516
2517 {
2518 const int Width = 1908221843;
2519 const int Height = 1908221844;
2520
2521 const auto pTexture = Component_t::Make(
2522 {
2523 { uT("content"), Source },
2524 { uT("width"), Width },
2525 { uT("height"), Height },
2526 { uT("name"), Names[Index].first },
2527 { uT("index"), Index },
2528 { uT("mipmapping"), false },
2529 { uT("capacity"), 16 },
2530 });
2531
2532 TestCall(pTexture,
2533 Source, Width, Height, Index, Names[Index].second);
2534 }
2535
2536 {
2537 const int Width = 1908221845;
2538 const int Height = 1908221847;
2539
2540 const auto pData = Component_t::Make(
2541 {
2542 { uT("kind"), uT("Texture") },
2543 { uT("content"), Source },
2544 { uT("width"), Width },
2545 { uT("height"), Height },
2546 { uT("name"), Names[Index].first },
2547 { uT("index"), Index },
2548 { uT("mipmapping"), false },
2549 { uT("capacity"), 16 },
2550 });
2551
2552 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
2553 Source, Width, Height, Index, Names[Index].second);
2554 }
2555
2556 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
2557 {
2558 { uT("albedo"), "TexAlbedo" },
2559 { uT("metalness"), "TexMetalness" },
2560 { uT("roughness"), "TexRoughness" },
2561 { uT("normal"), "TexNormal" },
2562 { uT("occlusion"), "TexOcclusion" },
2563 //{ uT("depth"), "TexDepth" }, // другой формат
2564 };
2565
2566 for (::std::size_t i = 0; i < Destinations.size(); i++)
2567 {
2568 {
2569 const int Width = 1908221843;
2570 const int Height = 1908221844;
2571
2572 const auto pTexture = Component_t::Make(
2573 {
2574 { uT("content"), Source },
2575 { uT("width"), Width },
2576 { uT("height"), Height },
2577 { uT("name"), Names[Index].first },
2578 { uT("index"), Index },
2579 { uT("destination"), Destinations[i].first },
2580 { uT("capacity"), 16 },
2581 });
2582
2583 TestCall(pTexture,
2584 Source, Width, Height, Index, Names[Index].second);
2585 }
2586
2587 {
2588 const int Width = 1908221845;
2589 const int Height = 1908221847;
2590
2591 const auto pData = Component_t::Make(
2592 {
2593 { uT("kind"), uT("Texture") },
2594 { uT("content"), Source },
2595 { uT("width"), Width },
2596 { uT("height"), Height },
2597 { uT("name"), Names[Index].first },
2598 { uT("index"), Index },
2599 { uT("destination"), Destinations[i].first },
2600 { uT("capacity"), 16 },
2601 });
2602
2603 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
2604 Source, Width, Height, Index, Names[Index].second);
2605 }
2606
2607 {
2608 const int Width = 1908221843;
2609 const int Height = 1908221844;
2610
2611 const auto pTexture = Component_t::Make(
2612 {
2613 { uT("content"), Source },
2614 { uT("width"), Width },
2615 { uT("height"), Height },
2616 { uT("name"), Names[Index].first },
2617 { uT("index"), Index },
2618 { uT("destination"), Destinations[i].first },
2619 { uT("mipmapping"), false },
2620 { uT("capacity"), 16 },
2621 });
2622
2623 TestCall(pTexture,
2624 Source, Width, Height, Index, Names[Index].second);
2625 }
2626
2627 {
2628 const int Width = 1908221845;
2629 const int Height = 1908221847;
2630
2631 const auto pData = Component_t::Make(
2632 {
2633 { uT("kind"), uT("Texture") },
2634 { uT("content"), Source },
2635 { uT("width"), Width },
2636 { uT("height"), Height },
2637 { uT("name"), Names[Index].first },
2638 { uT("index"), Index },
2639 { uT("destination"), Destinations[i].first },
2640 { uT("mipmapping"), false },
2641 { uT("capacity"), 16 },
2642 });
2643
2644 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
2645 Source, Width, Height, Index, Names[Index].second);
2646 }
2647 }
2648 }
2649}
2650
2651// ************************************************************************** //
2652TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_NameAndIndex_Capacity32)
2653{
2654 using GLProxy_t = ::mock::GLProxy;
2655 GLProxy_t GLProxy;
2656 GLProxy_t::GetInstance() = &GLProxy;
2657
2658 const Tested_t Example{ Data_t{} };
2659 const ITested_t & IExample = Example;
2660
2661 auto itCreator = IExample.GetCreators().find(uT("Texture"));
2662 ASSERT_NE(IExample.GetCreators().end(), itCreator);
2663
2664 const ::mock::GLuint TextureId = 1908221839;
2665 const ::mock::GLint ProgramId = 1908221840;
2666 const ::mock::GLint LocationId = 1908221841;
2667
2668 const auto TestCall = [&](
2669 const Component_t::ComponentPtr_t & _pTexture,
2670 const ::std::vector<uint8_t> & _Source,
2671 const int _Width, const int _Height,
2672 const ::std::size_t _Index,
2673 const ::std::string & _TexName)
2674 {
2675 const auto Index = static_cast<::mock::GLint>(_Index);
2676
2677 using namespace ::testing;
2678
2679 InSequence Dummy;
2680
2681 EXPECT_CALL(GLProxy, GenTextures(1))
2682 .Times(1)
2683 .WillOnce(Return(TextureId));
2684
2685 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2686 .Times(1);
2687
2688 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
2689 _Width, _Height, 0,
2690 GL_RGBA, GL_FLOAT, _Source))
2691 .Times(1);
2692
2693 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2694 .Times(1);
2695
2696 EXPECT_CALL(GLProxy, GetError())
2697 .Times(1)
2698 .WillOnce(Return(GL_NO_ERROR));
2699
2700 EXPECT_CALL(GLProxy, GenFramebuffers(1))
2701 .Times(0);
2702
2703 auto Render = itCreator->second(_pTexture);
2704 ASSERT_NE(nullptr, Render);
2705
2706 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
2707 .Times(1);
2708
2709 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2710 .Times(1);
2711
2712 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2713 .Times(1)
2714 .WillOnce(Return(&ProgramId));
2715
2716 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
2717 .Times(1)
2718 .WillOnce(Return(LocationId));
2719
2720 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
2721 .Times(0);
2722
2723 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
2724 .Times(1);
2725
2726 Render();
2727
2728 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
2729 .Times(1);
2730 };
2731
2732 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
2733 {
2734 { uT("TexEnvironment"), "TexEnvironment" },
2735 { uT("TexReflection"), "TexReflection" },
2736 { uT("TexBaseColor"), "TexBaseColor" },
2737 };
2738
2739 for (int Index = 0; Index < Names.size(); Index++)
2740 {
2741 ::std::vector<uint8_t> Source =
2742 {
2743 0x20, 0x06, 0x15, 0x12, 0x30,
2744 0x20, 0x06, 0x15, 0x12, 0x30,
2745 0x20, 0x06, 0x15, 0x12, 0x30,
2746 0x20, 0x06, 0x15, 0x12, 0x30,
2747 0x20, 0x06, 0x15, 0x12, 0x30,
2748 };
2749 IntroduceBufferSize(Source);
2750
2751 {
2752 const int Width = 1908221843;
2753 const int Height = 1908221844;
2754
2755 const auto pTexture = Component_t::Make(
2756 {
2757 { uT("content"), Source },
2758 { uT("width"), Width },
2759 { uT("height"), Height },
2760 { uT("name"), Names[Index].first },
2761 { uT("index"), Index },
2762 { uT("capacity"), 32 },
2763 });
2764
2765 TestCall(pTexture,
2766 Source, Width, Height, Index, Names[Index].second);
2767 }
2768
2769 {
2770 const int Width = 1908221845;
2771 const int Height = 1908221847;
2772
2773 const auto pData = Component_t::Make(
2774 {
2775 { uT("kind"), uT("Texture") },
2776 { uT("content"), Source },
2777 { uT("width"), Width },
2778 { uT("height"), Height },
2779 { uT("name"), Names[Index].first },
2780 { uT("index"), Index },
2781 { uT("capacity"), 32 },
2782 });
2783
2784 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
2785 Source, Width, Height, Index, Names[Index].second);
2786 }
2787
2788 {
2789 const int Width = 1908221843;
2790 const int Height = 1908221844;
2791
2792 const auto pTexture = Component_t::Make(
2793 {
2794 { uT("content"), Source },
2795 { uT("width"), Width },
2796 { uT("height"), Height },
2797 { uT("name"), Names[Index].first },
2798 { uT("index"), Index },
2799 { uT("mipmapping"), false },
2800 { uT("capacity"), 32 },
2801 });
2802
2803 TestCall(pTexture,
2804 Source, Width, Height, Index, Names[Index].second);
2805 }
2806
2807 {
2808 const int Width = 1908221845;
2809 const int Height = 1908221847;
2810
2811 const auto pData = Component_t::Make(
2812 {
2813 { uT("kind"), uT("Texture") },
2814 { uT("content"), Source },
2815 { uT("width"), Width },
2816 { uT("height"), Height },
2817 { uT("name"), Names[Index].first },
2818 { uT("index"), Index },
2819 { uT("mipmapping"), false },
2820 { uT("capacity"), 32 },
2821 });
2822
2823 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
2824 Source, Width, Height, Index, Names[Index].second);
2825 }
2826
2827 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
2828 {
2829 { uT("albedo"), "TexAlbedo" },
2830 { uT("metalness"), "TexMetalness" },
2831 { uT("roughness"), "TexRoughness" },
2832 { uT("normal"), "TexNormal" },
2833 { uT("occlusion"), "TexOcclusion" },
2834 //{ uT("depth"), "TexDepth" }, // другой формат
2835 };
2836
2837 for (::std::size_t i = 0; i < Destinations.size(); i++)
2838 {
2839 {
2840 const int Width = 1908221843;
2841 const int Height = 1908221844;
2842
2843 const auto pTexture = Component_t::Make(
2844 {
2845 { uT("content"), Source },
2846 { uT("width"), Width },
2847 { uT("height"), Height },
2848 { uT("name"), Names[Index].first },
2849 { uT("index"), Index },
2850 { uT("destination"), Destinations[i].first },
2851 { uT("capacity"), 32 },
2852 });
2853
2854 TestCall(pTexture,
2855 Source, Width, Height, Index, Names[Index].second);
2856 }
2857
2858 {
2859 const int Width = 1908221845;
2860 const int Height = 1908221847;
2861
2862 const auto pData = Component_t::Make(
2863 {
2864 { uT("kind"), uT("Texture") },
2865 { uT("content"), Source },
2866 { uT("width"), Width },
2867 { uT("height"), Height },
2868 { uT("name"), Names[Index].first },
2869 { uT("index"), Index },
2870 { uT("destination"), Destinations[i].first },
2871 { uT("capacity"), 32 },
2872 });
2873
2874 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
2875 Source, Width, Height, Index, Names[Index].second);
2876 }
2877
2878 {
2879 const int Width = 1908221843;
2880 const int Height = 1908221844;
2881
2882 const auto pTexture = Component_t::Make(
2883 {
2884 { uT("content"), Source },
2885 { uT("width"), Width },
2886 { uT("height"), Height },
2887 { uT("name"), Names[Index].first },
2888 { uT("index"), Index },
2889 { uT("destination"), Destinations[i].first },
2890 { uT("mipmapping"), false },
2891 { uT("capacity"), 32 },
2892 });
2893
2894 TestCall(pTexture,
2895 Source, Width, Height, Index, Names[Index].second);
2896 }
2897
2898 {
2899 const int Width = 1908221845;
2900 const int Height = 1908221847;
2901
2902 const auto pData = Component_t::Make(
2903 {
2904 { uT("kind"), uT("Texture") },
2905 { uT("content"), Source },
2906 { uT("width"), Width },
2907 { uT("height"), Height },
2908 { uT("name"), Names[Index].first },
2909 { uT("index"), Index },
2910 { uT("destination"), Destinations[i].first },
2911 { uT("mipmapping"), false },
2912 { uT("capacity"), 32 },
2913 });
2914
2915 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
2916 Source, Width, Height, Index, Names[Index].second);
2917 }
2918 }
2919 }
2920}
2921
2922// ************************************************************************** //
2923TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_Destination)
2924{
2925 using GLProxy_t = ::mock::GLProxy;
2926 GLProxy_t GLProxy;
2927 GLProxy_t::GetInstance() = &GLProxy;
2928
2929 const Tested_t Example{ Data_t{} };
2930 const ITested_t & IExample = Example;
2931
2932 auto itCreator = IExample.GetCreators().find(uT("Texture"));
2933 ASSERT_NE(IExample.GetCreators().end(), itCreator);
2934
2935 const ::mock::GLuint TextureId = 1908221839;
2936 const ::mock::GLint ProgramId = 1908221840;
2937 const ::mock::GLint LocationId = 1908221841;
2938
2939 const auto TestCall = [&](
2940 const Component_t::ComponentPtr_t & _pTexture,
2941 const ::std::vector<uint8_t> & _Source,
2942 const int _Width, const int _Height,
2943 const ::std::size_t _Index,
2944 const ::std::string & _TexName)
2945 {
2946 const auto Index = static_cast<::mock::GLint>(_Index);
2947
2948 using namespace ::testing;
2949
2950 InSequence Dummy;
2951
2952 EXPECT_CALL(GLProxy, GenTextures(1))
2953 .Times(1)
2954 .WillOnce(Return(TextureId));
2955
2956 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2957 .Times(1);
2958
2959 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
2960 _Width, _Height, 0,
2961 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
2962 .Times(1);
2963
2964 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2965 .Times(1);
2966
2967 EXPECT_CALL(GLProxy, GetError())
2968 .Times(1)
2969 .WillOnce(Return(GL_NO_ERROR));
2970
2971 EXPECT_CALL(GLProxy, GenFramebuffers(1))
2972 .Times(0);
2973
2974 auto Render = itCreator->second(_pTexture);
2975 ASSERT_NE(nullptr, Render);
2976
2977 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
2978 .Times(1);
2979
2980 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2981 .Times(1);
2982
2983 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2984 .Times(1)
2985 .WillOnce(Return(&ProgramId));
2986
2987 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
2988 .Times(1)
2989 .WillOnce(Return(LocationId));
2990
2991 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
2992 .Times(0);
2993
2994 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
2995 .Times(1);
2996
2997 Render();
2998
2999 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3000 .Times(1);
3001 };
3002
3003 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3004 {
3005 { uT("albedo"), "TexAlbedo" },
3006 { uT("metalness"), "TexMetalness" },
3007 { uT("roughness"), "TexRoughness" },
3008 { uT("normal"), "TexNormal" },
3009 { uT("occlusion"), "TexOcclusion" },
3010 //{ uT("depth"), "TexDepth" }, // другой формат
3011 };
3012
3013 ::std::vector<uint8_t> Source =
3014 {
3015 0x20, 0x06, 0x15, 0x12, 0x30,
3016 0x20, 0x06, 0x15, 0x12, 0x30,
3017 0x20, 0x06, 0x15, 0x12, 0x30,
3018 0x20, 0x06, 0x15, 0x12, 0x30,
3019 0x20, 0x06, 0x15, 0x12, 0x30,
3020 };
3021 IntroduceBufferSize(Source);
3022
3023 for (::std::size_t i = 0; i < Destinations.size(); i++)
3024 {
3025 {
3026 const int Width = 1908221843;
3027 const int Height = 1908221844;
3028
3029 const auto pTexture = Component_t::Make(
3030 {
3031 { uT("content"), Source },
3032 { uT("width"), Width },
3033 { uT("height"), Height },
3034 { uT("destination"), Destinations[i].first },
3035 });
3036
3037 TestCall(pTexture,
3038 Source, Width, Height, i, Destinations[i].second);
3039 }
3040
3041 {
3042 const int Width = 1908221845;
3043 const int Height = 1908221847;
3044
3045 const auto pData = Component_t::Make(
3046 {
3047 { uT("kind"), uT("Texture") },
3048 { uT("content"), Source },
3049 { uT("width"), Width },
3050 { uT("height"), Height },
3051 { uT("destination"), Destinations[i].first },
3052 });
3053
3054 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
3055 Source, Width, Height, i, Destinations[i].second);
3056 }
3057
3058 {
3059 const int Width = 1908221843;
3060 const int Height = 1908221844;
3061
3062 const auto pTexture = Component_t::Make(
3063 {
3064 { uT("content"), Source },
3065 { uT("width"), Width },
3066 { uT("height"), Height },
3067 { uT("destination"), Destinations[i].first },
3068 { uT("mipmapping"), false },
3069 });
3070
3071 TestCall(pTexture,
3072 Source, Width, Height, i, Destinations[i].second);
3073 }
3074
3075 {
3076 const int Width = 1908221845;
3077 const int Height = 1908221847;
3078
3079 const auto pData = Component_t::Make(
3080 {
3081 { uT("kind"), uT("Texture") },
3082 { uT("content"), Source },
3083 { uT("width"), Width },
3084 { uT("height"), Height },
3085 { uT("destination"), Destinations[i].first },
3086 { uT("mipmapping"), false },
3087 });
3088
3089 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
3090 Source, Width, Height, i, Destinations[i].second);
3091 }
3092 }
3093}
3094
3095// ************************************************************************** //
3096TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_Destination_Capacity16)
3097{
3098 using GLProxy_t = ::mock::GLProxy;
3099 GLProxy_t GLProxy;
3100 GLProxy_t::GetInstance() = &GLProxy;
3101
3102 const Tested_t Example{ Data_t{} };
3103 const ITested_t & IExample = Example;
3104
3105 auto itCreator = IExample.GetCreators().find(uT("Texture"));
3106 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3107
3108 const ::mock::GLuint TextureId = 1908221839;
3109 const ::mock::GLint ProgramId = 1908221840;
3110 const ::mock::GLint LocationId = 1908221841;
3111
3112 const auto TestCall = [&](
3113 const Component_t::ComponentPtr_t & _pTexture,
3114 const ::std::vector<uint8_t> & _Source,
3115 const int _Width, const int _Height,
3116 const ::std::size_t _Index,
3117 const ::std::string & _TexName)
3118 {
3119 const auto Index = static_cast<::mock::GLint>(_Index);
3120
3121 using namespace ::testing;
3122
3123 InSequence Dummy;
3124
3125 EXPECT_CALL(GLProxy, GenTextures(1))
3126 .Times(1)
3127 .WillOnce(Return(TextureId));
3128
3129 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3130 .Times(1);
3131
3132 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
3133 _Width, _Height, 0,
3134 GL_RGBA, GL_HALF_FLOAT, _Source))
3135 .Times(1);
3136
3137 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3138 .Times(1);
3139
3140 EXPECT_CALL(GLProxy, GetError())
3141 .Times(1)
3142 .WillOnce(Return(GL_NO_ERROR));
3143
3144 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3145 .Times(0);
3146
3147 auto Render = itCreator->second(_pTexture);
3148 ASSERT_NE(nullptr, Render);
3149
3150 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3151 .Times(1);
3152
3153 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3154 .Times(1);
3155
3156 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3157 .Times(1)
3158 .WillOnce(Return(&ProgramId));
3159
3160 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3161 .Times(1)
3162 .WillOnce(Return(LocationId));
3163
3164 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
3165 .Times(0);
3166
3167 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3168 .Times(1);
3169
3170 Render();
3171
3172 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3173 .Times(1);
3174 };
3175
3176 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3177 {
3178 { uT("albedo"), "TexAlbedo" },
3179 { uT("metalness"), "TexMetalness" },
3180 { uT("roughness"), "TexRoughness" },
3181 { uT("normal"), "TexNormal" },
3182 { uT("occlusion"), "TexOcclusion" },
3183 //{ uT("depth"), "TexDepth" }, // другой формат
3184 };
3185
3186 ::std::vector<uint8_t> Source =
3187 {
3188 0x20, 0x06, 0x15, 0x12, 0x30,
3189 0x20, 0x06, 0x15, 0x12, 0x30,
3190 0x20, 0x06, 0x15, 0x12, 0x30,
3191 0x20, 0x06, 0x15, 0x12, 0x30,
3192 0x20, 0x06, 0x15, 0x12, 0x30,
3193 };
3194 IntroduceBufferSize(Source);
3195
3196 for (::std::size_t i = 0; i < Destinations.size(); i++)
3197 {
3198 {
3199 const int Width = 1908221843;
3200 const int Height = 1908221844;
3201
3202 const auto pTexture = Component_t::Make(
3203 {
3204 { uT("content"), Source },
3205 { uT("width"), Width },
3206 { uT("height"), Height },
3207 { uT("destination"), Destinations[i].first },
3208 { uT("capacity"), 16 },
3209 });
3210
3211 TestCall(pTexture,
3212 Source, Width, Height, i, Destinations[i].second);
3213 }
3214
3215 {
3216 const int Width = 1908221845;
3217 const int Height = 1908221847;
3218
3219 const auto pData = Component_t::Make(
3220 {
3221 { uT("kind"), uT("Texture") },
3222 { uT("content"), Source },
3223 { uT("width"), Width },
3224 { uT("height"), Height },
3225 { uT("destination"), Destinations[i].first },
3226 { uT("capacity"), 16 },
3227 });
3228
3229 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
3230 Source, Width, Height, i, Destinations[i].second);
3231 }
3232
3233 {
3234 const int Width = 1908221843;
3235 const int Height = 1908221844;
3236
3237 const auto pTexture = Component_t::Make(
3238 {
3239 { uT("content"), Source },
3240 { uT("width"), Width },
3241 { uT("height"), Height },
3242 { uT("destination"), Destinations[i].first },
3243 { uT("mipmapping"), false },
3244 { uT("capacity"), 16 },
3245 });
3246
3247 TestCall(pTexture,
3248 Source, Width, Height, i, Destinations[i].second);
3249 }
3250
3251 {
3252 const int Width = 1908221845;
3253 const int Height = 1908221847;
3254
3255 const auto pData = Component_t::Make(
3256 {
3257 { uT("kind"), uT("Texture") },
3258 { uT("content"), Source },
3259 { uT("width"), Width },
3260 { uT("height"), Height },
3261 { uT("destination"), Destinations[i].first },
3262 { uT("mipmapping"), false },
3263 { uT("capacity"), 16 },
3264 });
3265
3266 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
3267 Source, Width, Height, i, Destinations[i].second);
3268 }
3269 }
3270}
3271
3272// ************************************************************************** //
3273TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_Destination_Capacity32)
3274{
3275 using GLProxy_t = ::mock::GLProxy;
3276 GLProxy_t GLProxy;
3277 GLProxy_t::GetInstance() = &GLProxy;
3278
3279 const Tested_t Example{ Data_t{} };
3280 const ITested_t & IExample = Example;
3281
3282 auto itCreator = IExample.GetCreators().find(uT("Texture"));
3283 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3284
3285 const ::mock::GLuint TextureId = 1908221839;
3286 const ::mock::GLint ProgramId = 1908221840;
3287 const ::mock::GLint LocationId = 1908221841;
3288
3289 const auto TestCall = [&](
3290 const Component_t::ComponentPtr_t & _pTexture,
3291 const ::std::vector<uint8_t> & _Source,
3292 const int _Width, const int _Height,
3293 const ::std::size_t _Index,
3294 const ::std::string & _TexName)
3295 {
3296 const auto Index = static_cast<::mock::GLint>(_Index);
3297
3298 using namespace ::testing;
3299
3300 InSequence Dummy;
3301
3302 EXPECT_CALL(GLProxy, GenTextures(1))
3303 .Times(1)
3304 .WillOnce(Return(TextureId));
3305
3306 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3307 .Times(1);
3308
3309 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
3310 _Width, _Height, 0,
3311 GL_RGBA, GL_FLOAT, _Source))
3312 .Times(1);
3313
3314 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3315 .Times(1);
3316
3317 EXPECT_CALL(GLProxy, GetError())
3318 .Times(1)
3319 .WillOnce(Return(GL_NO_ERROR));
3320
3321 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3322 .Times(0);
3323
3324 auto Render = itCreator->second(_pTexture);
3325 ASSERT_NE(nullptr, Render);
3326
3327 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3328 .Times(1);
3329
3330 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3331 .Times(1);
3332
3333 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3334 .Times(1)
3335 .WillOnce(Return(&ProgramId));
3336
3337 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3338 .Times(1)
3339 .WillOnce(Return(LocationId));
3340
3341 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
3342 .Times(0);
3343
3344 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3345 .Times(1);
3346
3347 Render();
3348
3349 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3350 .Times(1);
3351 };
3352
3353 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3354 {
3355 { uT("albedo"), "TexAlbedo" },
3356 { uT("metalness"), "TexMetalness" },
3357 { uT("roughness"), "TexRoughness" },
3358 { uT("normal"), "TexNormal" },
3359 { uT("occlusion"), "TexOcclusion" },
3360 //{ uT("depth"), "TexDepth" }, // другой формат
3361 };
3362
3363 ::std::vector<uint8_t> Source =
3364 {
3365 0x20, 0x06, 0x15, 0x12, 0x30,
3366 0x20, 0x06, 0x15, 0x12, 0x30,
3367 0x20, 0x06, 0x15, 0x12, 0x30,
3368 0x20, 0x06, 0x15, 0x12, 0x30,
3369 0x20, 0x06, 0x15, 0x12, 0x30,
3370 };
3371 IntroduceBufferSize(Source);
3372
3373 for (::std::size_t i = 0; i < Destinations.size(); i++)
3374 {
3375 {
3376 const int Width = 1908221843;
3377 const int Height = 1908221844;
3378
3379 const auto pTexture = Component_t::Make(
3380 {
3381 { uT("content"), Source },
3382 { uT("width"), Width },
3383 { uT("height"), Height },
3384 { uT("destination"), Destinations[i].first },
3385 { uT("capacity"), 32 },
3386 });
3387
3388 TestCall(pTexture,
3389 Source, Width, Height, i, Destinations[i].second);
3390 }
3391
3392 {
3393 const int Width = 1908221845;
3394 const int Height = 1908221847;
3395
3396 const auto pData = Component_t::Make(
3397 {
3398 { uT("kind"), uT("Texture") },
3399 { uT("content"), Source },
3400 { uT("width"), Width },
3401 { uT("height"), Height },
3402 { uT("destination"), Destinations[i].first },
3403 { uT("capacity"), 32 },
3404 });
3405
3406 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
3407 Source, Width, Height, i, Destinations[i].second);
3408 }
3409
3410 {
3411 const int Width = 1908221843;
3412 const int Height = 1908221844;
3413
3414 const auto pTexture = Component_t::Make(
3415 {
3416 { uT("content"), Source },
3417 { uT("width"), Width },
3418 { uT("height"), Height },
3419 { uT("destination"), Destinations[i].first },
3420 { uT("mipmapping"), false },
3421 { uT("capacity"), 32 },
3422 });
3423
3424 TestCall(pTexture,
3425 Source, Width, Height, i, Destinations[i].second);
3426 }
3427
3428 {
3429 const int Width = 1908221845;
3430 const int Height = 1908221847;
3431
3432 const auto pData = Component_t::Make(
3433 {
3434 { uT("kind"), uT("Texture") },
3435 { uT("content"), Source },
3436 { uT("width"), Width },
3437 { uT("height"), Height },
3438 { uT("destination"), Destinations[i].first },
3439 { uT("mipmapping"), false },
3440 { uT("capacity"), 32 },
3441 });
3442
3443 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
3444 Source, Width, Height, i, Destinations[i].second);
3445 }
3446 }
3447}
3448
3449// ************************************************************************** //
3450TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_Mipmapping_NameAndIndex)
3451{
3452 using GLProxy_t = ::mock::GLProxy;
3453 GLProxy_t GLProxy;
3454 GLProxy_t::GetInstance() = &GLProxy;
3455
3456 const Tested_t Example{ Data_t{} };
3457 const ITested_t & IExample = Example;
3458
3459 auto itCreator = IExample.GetCreators().find(uT("Texture"));
3460 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3461
3462 const ::mock::GLuint TextureId = 1908221839;
3463 const ::mock::GLint ProgramId = 1908221840;
3464 const ::mock::GLint LocationId = 1908221841;
3465
3466 const auto TestCall = [&](
3467 const Component_t::ComponentPtr_t & _pTexture,
3468 const ::std::vector<uint8_t> & _Source,
3469 const int _Width, const int _Height,
3470 const ::std::size_t _Index,
3471 const ::std::string & _TexName)
3472 {
3473 const auto Index = static_cast<::mock::GLint>(_Index);
3474
3475 using namespace ::testing;
3476
3477 InSequence Dummy;
3478
3479 EXPECT_CALL(GLProxy, GenTextures(1))
3480 .Times(1)
3481 .WillOnce(Return(TextureId));
3482
3483 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3484 .Times(1);
3485
3486 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
3487 _Width, _Height, 0,
3488 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
3489 .Times(1);
3490
3491 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3492 .Times(1);
3493
3494 EXPECT_CALL(GLProxy, GetError())
3495 .Times(1)
3496 .WillOnce(Return(GL_NO_ERROR));
3497
3498 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3499 .Times(1);
3500
3501 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
3502 .Times(1);
3503
3504 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3505 .Times(1);
3506
3507 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3508 .Times(0);
3509
3510 auto Render = itCreator->second(_pTexture);
3511 ASSERT_NE(nullptr, Render);
3512
3513 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3514 .Times(1);
3515
3516 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3517 .Times(1);
3518
3519 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3520 .Times(1)
3521 .WillOnce(Return(&ProgramId));
3522
3523 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3524 .Times(1)
3525 .WillOnce(Return(LocationId));
3526
3527 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
3528 .Times(0);
3529
3530 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3531 .Times(1);
3532
3533 Render();
3534
3535 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3536 .Times(1);
3537 };
3538
3539 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
3540 {
3541 { uT("TexEnvironment"), "TexEnvironment" },
3542 { uT("TexReflection"), "TexReflection" },
3543 { uT("TexBaseColor"), "TexBaseColor" },
3544 };
3545
3546 for (int Index = 0; Index < Names.size(); Index++)
3547 {
3548 ::std::vector<uint8_t> Source =
3549 {
3550 0x20, 0x06, 0x15, 0x12, 0x31,
3551 0x20, 0x06, 0x15, 0x12, 0x31,
3552 0x20, 0x06, 0x15, 0x12, 0x31,
3553 0x20, 0x06, 0x15, 0x12, 0x31,
3554 0x20, 0x06, 0x15, 0x12, 0x31,
3555 };
3556 IntroduceBufferSize(Source);
3557
3558 {
3559 const int Width = 1908221843;
3560 const int Height = 1908221844;
3561
3562 const auto pTexture = Component_t::Make(
3563 {
3564 { uT("content"), Source },
3565 { uT("width"), Width },
3566 { uT("height"), Height },
3567 { uT("name"), Names[Index].first },
3568 { uT("index"), Index },
3569 { uT("mipmapping"), true },
3570 });
3571
3572 TestCall(pTexture,
3573 Source, Width, Height, Index, Names[Index].second);
3574 }
3575
3576 {
3577 const int Width = 1908221845;
3578 const int Height = 1908221847;
3579
3580 const auto pData = Component_t::Make(
3581 {
3582 { uT("kind"), uT("Texture") },
3583 { uT("content"), Source },
3584 { uT("width"), Width },
3585 { uT("height"), Height },
3586 { uT("name"), Names[Index].first },
3587 { uT("index"), Index },
3588 { uT("mipmapping"), true },
3589 });
3590
3591 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
3592 Source, Width, Height, Index, Names[Index].second);
3593 }
3594
3595 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3596 {
3597 { uT("albedo"), "TexAlbedo" },
3598 { uT("metalness"), "TexMetalness" },
3599 { uT("roughness"), "TexRoughness" },
3600 { uT("normal"), "TexNormal" },
3601 { uT("occlusion"), "TexOcclusion" },
3602 };
3603
3604 for (::std::size_t i = 0; i < Destinations.size(); i++)
3605 {
3606 {
3607 const int Width = 1908221843;
3608 const int Height = 1908221844;
3609
3610 const auto pTexture = Component_t::Make(
3611 {
3612 { uT("content"), Source },
3613 { uT("width"), Width },
3614 { uT("height"), Height },
3615 { uT("name"), Names[Index].first },
3616 { uT("index"), Index },
3617 { uT("destination"), Destinations[i].first },
3618 { uT("mipmapping"), true },
3619 });
3620
3621 TestCall(pTexture,
3622 Source, Width, Height, Index, Names[Index].second);
3623 }
3624
3625 {
3626 const int Width = 1908221845;
3627 const int Height = 1908221847;
3628
3629 const auto pData = Component_t::Make(
3630 {
3631 { uT("kind"), uT("Texture") },
3632 { uT("content"), Source },
3633 { uT("width"), Width },
3634 { uT("height"), Height },
3635 { uT("name"), Names[Index].first },
3636 { uT("index"), Index },
3637 { uT("destination"), Destinations[i].first },
3638 { uT("mipmapping"), true },
3639 });
3640
3641 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
3642 Source, Width, Height, Index, Names[Index].second);
3643 }
3644 }
3645 }
3646}
3647
3648// ************************************************************************** //
3649TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_Mipmapping_NameAndIndex_Capacity16)
3650{
3651 using GLProxy_t = ::mock::GLProxy;
3652 GLProxy_t GLProxy;
3653 GLProxy_t::GetInstance() = &GLProxy;
3654
3655 const Tested_t Example{ Data_t{} };
3656 const ITested_t & IExample = Example;
3657
3658 auto itCreator = IExample.GetCreators().find(uT("Texture"));
3659 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3660
3661 const ::mock::GLuint TextureId = 1908221839;
3662 const ::mock::GLint ProgramId = 1908221840;
3663 const ::mock::GLint LocationId = 1908221841;
3664
3665 const auto TestCall = [&](
3666 const Component_t::ComponentPtr_t & _pTexture,
3667 const ::std::vector<uint8_t> & _Source,
3668 const int _Width, const int _Height,
3669 const ::std::size_t _Index,
3670 const ::std::string & _TexName)
3671 {
3672 const auto Index = static_cast<::mock::GLint>(_Index);
3673
3674 using namespace ::testing;
3675
3676 InSequence Dummy;
3677
3678 EXPECT_CALL(GLProxy, GenTextures(1))
3679 .Times(1)
3680 .WillOnce(Return(TextureId));
3681
3682 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3683 .Times(1);
3684
3685 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
3686 _Width, _Height, 0,
3687 GL_RGBA, GL_HALF_FLOAT, _Source))
3688 .Times(1);
3689
3690 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3691 .Times(1);
3692
3693 EXPECT_CALL(GLProxy, GetError())
3694 .Times(1)
3695 .WillOnce(Return(GL_NO_ERROR));
3696
3697 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3698 .Times(1);
3699
3700 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
3701 .Times(1);
3702
3703 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3704 .Times(1);
3705
3706 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3707 .Times(0);
3708
3709 auto Render = itCreator->second(_pTexture);
3710 ASSERT_NE(nullptr, Render);
3711
3712 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3713 .Times(1);
3714
3715 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3716 .Times(1);
3717
3718 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3719 .Times(1)
3720 .WillOnce(Return(&ProgramId));
3721
3722 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3723 .Times(1)
3724 .WillOnce(Return(LocationId));
3725
3726 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
3727 .Times(0);
3728
3729 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3730 .Times(1);
3731
3732 Render();
3733
3734 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3735 .Times(1);
3736 };
3737
3738 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
3739 {
3740 { uT("TexEnvironment"), "TexEnvironment" },
3741 { uT("TexReflection"), "TexReflection" },
3742 { uT("TexBaseColor"), "TexBaseColor" },
3743 };
3744
3745 for (int Index = 0; Index < Names.size(); Index++)
3746 {
3747 ::std::vector<uint8_t> Source =
3748 {
3749 0x20, 0x06, 0x15, 0x12, 0x31,
3750 0x20, 0x06, 0x15, 0x12, 0x31,
3751 0x20, 0x06, 0x15, 0x12, 0x31,
3752 0x20, 0x06, 0x15, 0x12, 0x31,
3753 0x20, 0x06, 0x15, 0x12, 0x31,
3754 };
3755 IntroduceBufferSize(Source);
3756
3757 {
3758 const int Width = 1908221843;
3759 const int Height = 1908221844;
3760
3761 const auto pTexture = Component_t::Make(
3762 {
3763 { uT("content"), Source },
3764 { uT("width"), Width },
3765 { uT("height"), Height },
3766 { uT("name"), Names[Index].first },
3767 { uT("index"), Index },
3768 { uT("mipmapping"), true },
3769 { uT("capacity"), 16 },
3770 });
3771
3772 TestCall(pTexture,
3773 Source, Width, Height, Index, Names[Index].second);
3774 }
3775
3776 {
3777 const int Width = 1908221845;
3778 const int Height = 1908221847;
3779
3780 const auto pData = Component_t::Make(
3781 {
3782 { uT("kind"), uT("Texture") },
3783 { uT("content"), Source },
3784 { uT("width"), Width },
3785 { uT("height"), Height },
3786 { uT("name"), Names[Index].first },
3787 { uT("index"), Index },
3788 { uT("mipmapping"), true },
3789 { uT("capacity"), 16 },
3790 });
3791
3792 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
3793 Source, Width, Height, Index, Names[Index].second);
3794 }
3795
3796 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3797 {
3798 { uT("albedo"), "TexAlbedo" },
3799 { uT("metalness"), "TexMetalness" },
3800 { uT("roughness"), "TexRoughness" },
3801 { uT("normal"), "TexNormal" },
3802 { uT("occlusion"), "TexOcclusion" },
3803 };
3804
3805 for (::std::size_t i = 0; i < Destinations.size(); i++)
3806 {
3807 {
3808 const int Width = 1908221843;
3809 const int Height = 1908221844;
3810
3811 const auto pTexture = Component_t::Make(
3812 {
3813 { uT("content"), Source },
3814 { uT("width"), Width },
3815 { uT("height"), Height },
3816 { uT("name"), Names[Index].first },
3817 { uT("index"), Index },
3818 { uT("destination"), Destinations[i].first },
3819 { uT("mipmapping"), true },
3820 { uT("capacity"), 16 },
3821 });
3822
3823 TestCall(pTexture,
3824 Source, Width, Height, Index, Names[Index].second);
3825 }
3826
3827 {
3828 const int Width = 1908221845;
3829 const int Height = 1908221847;
3830
3831 const auto pData = Component_t::Make(
3832 {
3833 { uT("kind"), uT("Texture") },
3834 { uT("content"), Source },
3835 { uT("width"), Width },
3836 { uT("height"), Height },
3837 { uT("name"), Names[Index].first },
3838 { uT("index"), Index },
3839 { uT("destination"), Destinations[i].first },
3840 { uT("mipmapping"), true },
3841 { uT("capacity"), 16 },
3842 });
3843
3844 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
3845 Source, Width, Height, Index, Names[Index].second);
3846 }
3847 }
3848 }
3849}
3850
3851// ************************************************************************** //
3852TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_Mipmapping_NameAndIndex_Capacity32)
3853{
3854 using GLProxy_t = ::mock::GLProxy;
3855 GLProxy_t GLProxy;
3856 GLProxy_t::GetInstance() = &GLProxy;
3857
3858 const Tested_t Example{ Data_t{} };
3859 const ITested_t & IExample = Example;
3860
3861 auto itCreator = IExample.GetCreators().find(uT("Texture"));
3862 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3863
3864 const ::mock::GLuint TextureId = 1908221839;
3865 const ::mock::GLint ProgramId = 1908221840;
3866 const ::mock::GLint LocationId = 1908221841;
3867
3868 const auto TestCall = [&](
3869 const Component_t::ComponentPtr_t & _pTexture,
3870 const ::std::vector<uint8_t> & _Source,
3871 const int _Width, const int _Height,
3872 const ::std::size_t _Index,
3873 const ::std::string & _TexName)
3874 {
3875 const auto Index = static_cast<::mock::GLint>(_Index);
3876
3877 using namespace ::testing;
3878
3879 InSequence Dummy;
3880
3881 EXPECT_CALL(GLProxy, GenTextures(1))
3882 .Times(1)
3883 .WillOnce(Return(TextureId));
3884
3885 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3886 .Times(1);
3887
3888 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
3889 _Width, _Height, 0,
3890 GL_RGBA, GL_FLOAT, _Source))
3891 .Times(1);
3892
3893 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3894 .Times(1);
3895
3896 EXPECT_CALL(GLProxy, GetError())
3897 .Times(1)
3898 .WillOnce(Return(GL_NO_ERROR));
3899
3900 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3901 .Times(1);
3902
3903 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
3904 .Times(1);
3905
3906 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3907 .Times(1);
3908
3909 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3910 .Times(0);
3911
3912 auto Render = itCreator->second(_pTexture);
3913 ASSERT_NE(nullptr, Render);
3914
3915 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3916 .Times(1);
3917
3918 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3919 .Times(1);
3920
3921 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3922 .Times(1)
3923 .WillOnce(Return(&ProgramId));
3924
3925 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3926 .Times(1)
3927 .WillOnce(Return(LocationId));
3928
3929 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
3930 .Times(0);
3931
3932 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3933 .Times(1);
3934
3935 Render();
3936
3937 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3938 .Times(1);
3939 };
3940
3941 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
3942 {
3943 { uT("TexEnvironment"), "TexEnvironment" },
3944 { uT("TexReflection"), "TexReflection" },
3945 { uT("TexBaseColor"), "TexBaseColor" },
3946 };
3947
3948 for (int Index = 0; Index < Names.size(); Index++)
3949 {
3950 ::std::vector<uint8_t> Source =
3951 {
3952 0x20, 0x06, 0x15, 0x12, 0x31,
3953 0x20, 0x06, 0x15, 0x12, 0x31,
3954 0x20, 0x06, 0x15, 0x12, 0x31,
3955 0x20, 0x06, 0x15, 0x12, 0x31,
3956 0x20, 0x06, 0x15, 0x12, 0x31,
3957 };
3958 IntroduceBufferSize(Source);
3959
3960 {
3961 const int Width = 1908221843;
3962 const int Height = 1908221844;
3963
3964 const auto pTexture = Component_t::Make(
3965 {
3966 { uT("content"), Source },
3967 { uT("width"), Width },
3968 { uT("height"), Height },
3969 { uT("name"), Names[Index].first },
3970 { uT("index"), Index },
3971 { uT("mipmapping"), true },
3972 { uT("capacity"), 32 },
3973 });
3974
3975 TestCall(pTexture,
3976 Source, Width, Height, Index, Names[Index].second);
3977 }
3978
3979 {
3980 const int Width = 1908221845;
3981 const int Height = 1908221847;
3982
3983 const auto pData = Component_t::Make(
3984 {
3985 { uT("kind"), uT("Texture") },
3986 { uT("content"), Source },
3987 { uT("width"), Width },
3988 { uT("height"), Height },
3989 { uT("name"), Names[Index].first },
3990 { uT("index"), Index },
3991 { uT("mipmapping"), true },
3992 { uT("capacity"), 32 },
3993 });
3994
3995 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
3996 Source, Width, Height, Index, Names[Index].second);
3997 }
3998
3999 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4000 {
4001 { uT("albedo"), "TexAlbedo" },
4002 { uT("metalness"), "TexMetalness" },
4003 { uT("roughness"), "TexRoughness" },
4004 { uT("normal"), "TexNormal" },
4005 { uT("occlusion"), "TexOcclusion" },
4006 };
4007
4008 for (::std::size_t i = 0; i < Destinations.size(); i++)
4009 {
4010 {
4011 const int Width = 1908221843;
4012 const int Height = 1908221844;
4013
4014 const auto pTexture = Component_t::Make(
4015 {
4016 { uT("content"), Source },
4017 { uT("width"), Width },
4018 { uT("height"), Height },
4019 { uT("name"), Names[Index].first },
4020 { uT("index"), Index },
4021 { uT("destination"), Destinations[i].first },
4022 { uT("mipmapping"), true },
4023 { uT("capacity"), 32 },
4024 });
4025
4026 TestCall(pTexture,
4027 Source, Width, Height, Index, Names[Index].second);
4028 }
4029
4030 {
4031 const int Width = 1908221845;
4032 const int Height = 1908221847;
4033
4034 const auto pData = Component_t::Make(
4035 {
4036 { uT("kind"), uT("Texture") },
4037 { uT("content"), Source },
4038 { uT("width"), Width },
4039 { uT("height"), Height },
4040 { uT("name"), Names[Index].first },
4041 { uT("index"), Index },
4042 { uT("destination"), Destinations[i].first },
4043 { uT("mipmapping"), true },
4044 { uT("capacity"), 32 },
4045 });
4046
4047 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
4048 Source, Width, Height, Index, Names[Index].second);
4049 }
4050 }
4051 }
4052}
4053
4054// ************************************************************************** //
4055TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_Mipmapping_Destination)
4056{
4057 using GLProxy_t = ::mock::GLProxy;
4058 GLProxy_t GLProxy;
4059 GLProxy_t::GetInstance() = &GLProxy;
4060
4061 const Tested_t Example{ Data_t{} };
4062 const ITested_t & IExample = Example;
4063
4064 auto itCreator = IExample.GetCreators().find(uT("Texture"));
4065 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4066
4067 const ::mock::GLuint TextureId = 1908221839;
4068 const ::mock::GLint ProgramId = 1908221840;
4069 const ::mock::GLint LocationId = 1908221841;
4070
4071 const auto TestCall = [&](
4072 const Component_t::ComponentPtr_t & _pTexture,
4073 const ::std::vector<uint8_t> & _Source,
4074 const int _Width, const int _Height,
4075 const ::std::size_t _Index,
4076 const ::std::string & _TexName)
4077 {
4078 const auto Index = static_cast<::mock::GLint>(_Index);
4079
4080 using namespace ::testing;
4081
4082 InSequence Dummy;
4083
4084 EXPECT_CALL(GLProxy, GenTextures(1))
4085 .Times(1)
4086 .WillOnce(Return(TextureId));
4087
4088 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4089 .Times(1);
4090
4091 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
4092 _Width, _Height, 0,
4093 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
4094 .Times(1);
4095
4096 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4097 .Times(1);
4098
4099 EXPECT_CALL(GLProxy, GetError())
4100 .Times(1)
4101 .WillOnce(Return(GL_NO_ERROR));
4102
4103 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4104 .Times(1);
4105
4106 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
4107 .Times(1);
4108
4109 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4110 .Times(1);
4111
4112 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4113 .Times(0);
4114
4115 auto Render = itCreator->second(_pTexture);
4116 ASSERT_NE(nullptr, Render);
4117
4118 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4119 .Times(1);
4120
4121 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4122 .Times(1);
4123
4124 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4125 .Times(1)
4126 .WillOnce(Return(&ProgramId));
4127
4128 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4129 .Times(1)
4130 .WillOnce(Return(LocationId));
4131
4132 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
4133 .Times(0);
4134
4135 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4136 .Times(1);
4137
4138 Render();
4139
4140 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4141 .Times(1);
4142 };
4143
4144 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4145 {
4146 { uT("albedo"), "TexAlbedo" },
4147 { uT("metalness"), "TexMetalness" },
4148 { uT("roughness"), "TexRoughness" },
4149 { uT("normal"), "TexNormal" },
4150 { uT("occlusion"), "TexOcclusion" },
4151 };
4152
4153 ::std::vector<uint8_t> Source =
4154 {
4155 0x20, 0x06, 0x15, 0x12, 0x31,
4156 0x20, 0x06, 0x15, 0x12, 0x31,
4157 0x20, 0x06, 0x15, 0x12, 0x31,
4158 0x20, 0x06, 0x15, 0x12, 0x31,
4159 0x20, 0x06, 0x15, 0x12, 0x31,
4160 };
4161 IntroduceBufferSize(Source);
4162
4163 for (::std::size_t i = 0; i < Destinations.size(); i++)
4164 {
4165 {
4166 const int Width = 1908221843;
4167 const int Height = 1908221844;
4168
4169 const auto pTexture = Component_t::Make(
4170 {
4171 { uT("content"), Source },
4172 { uT("width"), Width },
4173 { uT("height"), Height },
4174 { uT("destination"), Destinations[i].first },
4175 { uT("mipmapping"), true },
4176 });
4177
4178 TestCall(pTexture,
4179 Source, Width, Height, i, Destinations[i].second);
4180 }
4181
4182 {
4183 const int Width = 1908221845;
4184 const int Height = 1908221847;
4185
4186 const auto pData = Component_t::Make(
4187 {
4188 { uT("kind"), uT("Texture") },
4189 { uT("content"), Source },
4190 { uT("width"), Width },
4191 { uT("height"), Height },
4192 { uT("destination"), Destinations[i].first },
4193 { uT("mipmapping"), true },
4194 });
4195
4196 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
4197 Source, Width, Height, i, Destinations[i].second);
4198 }
4199 }
4200}
4201
4202// ************************************************************************** //
4203TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_Mipmapping_Destination_Capacity16)
4204{
4205 using GLProxy_t = ::mock::GLProxy;
4206 GLProxy_t GLProxy;
4207 GLProxy_t::GetInstance() = &GLProxy;
4208
4209 const Tested_t Example{ Data_t{} };
4210 const ITested_t & IExample = Example;
4211
4212 auto itCreator = IExample.GetCreators().find(uT("Texture"));
4213 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4214
4215 const ::mock::GLuint TextureId = 1908221839;
4216 const ::mock::GLint ProgramId = 1908221840;
4217 const ::mock::GLint LocationId = 1908221841;
4218
4219 const auto TestCall = [&](
4220 const Component_t::ComponentPtr_t & _pTexture,
4221 const ::std::vector<uint8_t> & _Source,
4222 const int _Width, const int _Height,
4223 const ::std::size_t _Index,
4224 const ::std::string & _TexName)
4225 {
4226 const auto Index = static_cast<::mock::GLint>(_Index);
4227
4228 using namespace ::testing;
4229
4230 InSequence Dummy;
4231
4232 EXPECT_CALL(GLProxy, GenTextures(1))
4233 .Times(1)
4234 .WillOnce(Return(TextureId));
4235
4236 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4237 .Times(1);
4238
4239 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
4240 _Width, _Height, 0,
4241 GL_RGBA, GL_HALF_FLOAT, _Source))
4242 .Times(1);
4243
4244 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4245 .Times(1);
4246
4247 EXPECT_CALL(GLProxy, GetError())
4248 .Times(1)
4249 .WillOnce(Return(GL_NO_ERROR));
4250
4251 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4252 .Times(1);
4253
4254 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
4255 .Times(1);
4256
4257 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4258 .Times(1);
4259
4260 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4261 .Times(0);
4262
4263 auto Render = itCreator->second(_pTexture);
4264 ASSERT_NE(nullptr, Render);
4265
4266 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4267 .Times(1);
4268
4269 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4270 .Times(1);
4271
4272 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4273 .Times(1)
4274 .WillOnce(Return(&ProgramId));
4275
4276 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4277 .Times(1)
4278 .WillOnce(Return(LocationId));
4279
4280 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
4281 .Times(0);
4282
4283 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4284 .Times(1);
4285
4286 Render();
4287
4288 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4289 .Times(1);
4290 };
4291
4292 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4293 {
4294 { uT("albedo"), "TexAlbedo" },
4295 { uT("metalness"), "TexMetalness" },
4296 { uT("roughness"), "TexRoughness" },
4297 { uT("normal"), "TexNormal" },
4298 { uT("occlusion"), "TexOcclusion" },
4299 };
4300
4301 ::std::vector<uint8_t> Source =
4302 {
4303 0x20, 0x06, 0x15, 0x12, 0x31,
4304 0x20, 0x06, 0x15, 0x12, 0x31,
4305 0x20, 0x06, 0x15, 0x12, 0x31,
4306 0x20, 0x06, 0x15, 0x12, 0x31,
4307 0x20, 0x06, 0x15, 0x12, 0x31,
4308 };
4309 IntroduceBufferSize(Source);
4310
4311 for (::std::size_t i = 0; i < Destinations.size(); i++)
4312 {
4313 {
4314 const int Width = 1908221843;
4315 const int Height = 1908221844;
4316
4317 const auto pTexture = Component_t::Make(
4318 {
4319 { uT("content"), Source },
4320 { uT("width"), Width },
4321 { uT("height"), Height },
4322 { uT("destination"), Destinations[i].first },
4323 { uT("mipmapping"), true },
4324 { uT("capacity"), 16 },
4325 });
4326
4327 TestCall(pTexture,
4328 Source, Width, Height, i, Destinations[i].second);
4329 }
4330
4331 {
4332 const int Width = 1908221845;
4333 const int Height = 1908221847;
4334
4335 const auto pData = Component_t::Make(
4336 {
4337 { uT("kind"), uT("Texture") },
4338 { uT("content"), Source },
4339 { uT("width"), Width },
4340 { uT("height"), Height },
4341 { uT("destination"), Destinations[i].first },
4342 { uT("mipmapping"), true },
4343 { uT("capacity"), 16 },
4344 });
4345
4346 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
4347 Source, Width, Height, i, Destinations[i].second);
4348 }
4349 }
4350}
4351
4352// ************************************************************************** //
4353TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_Mipmapping_Destination_Capacity32)
4354{
4355 using GLProxy_t = ::mock::GLProxy;
4356 GLProxy_t GLProxy;
4357 GLProxy_t::GetInstance() = &GLProxy;
4358
4359 const Tested_t Example{ Data_t{} };
4360 const ITested_t & IExample = Example;
4361
4362 auto itCreator = IExample.GetCreators().find(uT("Texture"));
4363 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4364
4365 const ::mock::GLuint TextureId = 1908221839;
4366 const ::mock::GLint ProgramId = 1908221840;
4367 const ::mock::GLint LocationId = 1908221841;
4368
4369 const auto TestCall = [&](
4370 const Component_t::ComponentPtr_t & _pTexture,
4371 const ::std::vector<uint8_t> & _Source,
4372 const int _Width, const int _Height,
4373 const ::std::size_t _Index,
4374 const ::std::string & _TexName)
4375 {
4376 const auto Index = static_cast<::mock::GLint>(_Index);
4377
4378 using namespace ::testing;
4379
4380 InSequence Dummy;
4381
4382 EXPECT_CALL(GLProxy, GenTextures(1))
4383 .Times(1)
4384 .WillOnce(Return(TextureId));
4385
4386 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4387 .Times(1);
4388
4389 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
4390 _Width, _Height, 0,
4391 GL_RGBA, GL_FLOAT, _Source))
4392 .Times(1);
4393
4394 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4395 .Times(1);
4396
4397 EXPECT_CALL(GLProxy, GetError())
4398 .Times(1)
4399 .WillOnce(Return(GL_NO_ERROR));
4400
4401 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4402 .Times(1);
4403
4404 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
4405 .Times(1);
4406
4407 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4408 .Times(1);
4409
4410 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4411 .Times(0);
4412
4413 auto Render = itCreator->second(_pTexture);
4414 ASSERT_NE(nullptr, Render);
4415
4416 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4417 .Times(1);
4418
4419 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4420 .Times(1);
4421
4422 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4423 .Times(1)
4424 .WillOnce(Return(&ProgramId));
4425
4426 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4427 .Times(1)
4428 .WillOnce(Return(LocationId));
4429
4430 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
4431 .Times(0);
4432
4433 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4434 .Times(1);
4435
4436 Render();
4437
4438 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4439 .Times(1);
4440 };
4441
4442 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4443 {
4444 { uT("albedo"), "TexAlbedo" },
4445 { uT("metalness"), "TexMetalness" },
4446 { uT("roughness"), "TexRoughness" },
4447 { uT("normal"), "TexNormal" },
4448 { uT("occlusion"), "TexOcclusion" },
4449 };
4450
4451 ::std::vector<uint8_t> Source =
4452 {
4453 0x20, 0x06, 0x15, 0x12, 0x31,
4454 0x20, 0x06, 0x15, 0x12, 0x31,
4455 0x20, 0x06, 0x15, 0x12, 0x31,
4456 0x20, 0x06, 0x15, 0x12, 0x31,
4457 0x20, 0x06, 0x15, 0x12, 0x31,
4458 };
4459 IntroduceBufferSize(Source);
4460
4461 for (::std::size_t i = 0; i < Destinations.size(); i++)
4462 {
4463 {
4464 const int Width = 1908221843;
4465 const int Height = 1908221844;
4466
4467 const auto pTexture = Component_t::Make(
4468 {
4469 { uT("content"), Source },
4470 { uT("width"), Width },
4471 { uT("height"), Height },
4472 { uT("destination"), Destinations[i].first },
4473 { uT("mipmapping"), true },
4474 { uT("capacity"), 32 },
4475 });
4476
4477 TestCall(pTexture,
4478 Source, Width, Height, i, Destinations[i].second);
4479 }
4480
4481 {
4482 const int Width = 1908221845;
4483 const int Height = 1908221847;
4484
4485 const auto pData = Component_t::Make(
4486 {
4487 { uT("kind"), uT("Texture") },
4488 { uT("content"), Source },
4489 { uT("width"), Width },
4490 { uT("height"), Height },
4491 { uT("destination"), Destinations[i].first },
4492 { uT("mipmapping"), true },
4493 { uT("capacity"), 32 },
4494 });
4495
4496 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
4497 Source, Width, Height, i, Destinations[i].second);
4498 }
4499 }
4500}
4501
4502// ************************************************************************** //
4503TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_ReadData_NameAndIndex)
4504{
4505 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
4506 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
4507
4508 using GLProxy_t = ::mock::GLProxy;
4509 GLProxy_t GLProxy;
4510 GLProxy_t::GetInstance() = &GLProxy;
4511
4512 class MapperProxy :
4513 public ::alicorn::extension::testing::Proxy<MapperProxy>
4514 {
4515 public:
4516 MOCK_METHOD1(Map, bool(const void *));
4517 MOCK_METHOD1(CheckData, void(::std::vector<uint32_t>));
4518 };
4519
4520 MapperProxy oMapperProxy;
4521 MapperProxy::GetInstance() = &oMapperProxy;
4522
4523 const int Width = 3;
4524 const int Height = 4;
4525
4526 const BufferMapper_t Mapper = [&](const void * _pData)
4527 {
4528 if (_pData != nullptr)
4529 {
4530 ::std::vector<uint32_t> Data(Width * Height);
4531 memcpy(Data.data(), _pData, Width * Height * 4);
4532 oMapperProxy.CheckData(Data);
4533 }
4534
4535 return oMapperProxy.Map(_pData);
4536 };
4537
4538 const Tested_t Example{ Data_t{} };
4539 const ITested_t & IExample = Example;
4540
4541 auto itCreator = IExample.GetCreators().find(uT("Texture"));
4542 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4543
4544 const ::mock::GLint TextureId = 1910221154;
4545 const ::mock::GLint ProgramId = 1910221155;
4546 const ::mock::GLint LocationId = 1910221156;
4547 const ::mock::GLint FrameBufferId = 1910221209;
4548 const ::mock::GLint DefaultFrameBufferId = 1910221236;
4549
4550 const auto TestCall = [&](
4551 const Component_t::ComponentPtr_t & _pDataTexture,
4552 const ::std::size_t _Index,
4553 const ::std::string & _TexName,
4554 const ::std::vector<uint32_t> & _RawData,
4555 const ::std::vector<uint32_t> & _ExpectData)
4556 {
4557 const auto Index = static_cast<::mock::GLint>(_Index);
4558
4559 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT("") };
4560
4561 using namespace ::testing;
4562
4563 InSequence Dummy;
4564
4565 EXPECT_CALL(GLProxy, GenTextures(1))
4566 .Times(1)
4567 .WillOnce(Return(TextureId));
4568
4569 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4570 .Times(1);
4571
4572 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
4573 Width, Height, 0,
4574 GL_RGBA, GL_UNSIGNED_BYTE, ::std::vector<uint8_t>{}))
4575 .Times(1);
4576
4577 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4578 .Times(1);
4579
4580 EXPECT_CALL(GLProxy, GetError())
4581 .Times(1)
4582 .WillOnce(Return(GL_NO_ERROR));
4583
4584 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
4585 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
4586
4587 (*_pDataTexture)[uT("entity")] = pTexture;
4588
4589 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4590 .Times(1)
4591 .WillOnce(Return(FrameBufferId));
4592
4593 EXPECT_CALL(GLProxy, GenTextures(1))
4594 .Times(0);
4595
4596 auto Render = itCreator->second(Component_t::Make(
4597 {
4598 { uT("service"), Object_t{ _pDataTexture } }
4599 }));
4600 ASSERT_NE(nullptr, Render);
4601
4602 const auto TestCallActivateTexture = [&](void)
4603 {
4604 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4605 .Times(1);
4606
4607 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4608 .Times(1);
4609
4610 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4611 .Times(1)
4612 .WillOnce(Return(&ProgramId));
4613
4614 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4615 .Times(1)
4616 .WillOnce(Return(LocationId));
4617
4618 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
4619 .Times(0);
4620
4621 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4622 .Times(1);
4623 };
4624
4626
4627 EXPECT_CALL(oMapperProxy, Map(nullptr))
4628 .Times(1)
4629 .WillOnce(Return(false));
4630
4631 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
4632 .Times(0);
4633
4634 TestCallActivateTexture();
4635 Render();
4636
4638
4639 EXPECT_CALL(oMapperProxy, Map(nullptr))
4640 .Times(1)
4641 .WillOnce(Return(true));
4642
4643 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
4644 .Times(1)
4645 .WillOnce(Return(&DefaultFrameBufferId));
4646
4647 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
4648 .Times(1);
4649
4650 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
4651 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
4652 .Times(1);
4653
4654 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
4655 .Times(1)
4656 .WillOnce(Return(_RawData));
4657
4658 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
4659 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
4660 .Times(1);
4661
4662 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
4663 .Times(1);
4664
4665 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
4666 .Times(1);
4667
4668 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
4669 .Times(1);
4670
4671 TestCallActivateTexture();
4672 Render();
4673
4675
4676 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
4677 .Times(1);
4678
4679 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4680 .Times(1);
4681 };
4682
4683 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
4684 {
4685 { uT("TexEnvironment"), "TexEnvironment" },
4686 { uT("TexReflection"), "TexReflection" },
4687 { uT("TexBaseColor"), "TexBaseColor" },
4688 };
4689
4690 for (int Index = 0; Index < Names.size(); Index++)
4691 {
4692 const ::std::vector<uint32_t> RawData =
4693 {
4694 0x10221334, 0x10221335, 0x10221336,
4695 0x10221337, 0x10221338, 0x10221339,
4696 0x10221340, 0x10221341, 0x10221342,
4697 0x10221343, 0x10221344, 0x10221345,
4698 };
4699
4700 const ::std::vector<uint32_t> ExpectData =
4701 {
4702 0x10221343, 0x10221344, 0x10221345,
4703 0x10221340, 0x10221341, 0x10221342,
4704 0x10221337, 0x10221338, 0x10221339,
4705 0x10221334, 0x10221335, 0x10221336,
4706 };
4707
4708 const auto pData = Component_t::Make(
4709 {
4710 { uT("kind"), uT("Texture") },
4711 { uT("width"), Width },
4712 { uT("height"), Height },
4713 { uT("mapper"), Mapper },
4714 { uT("name"), Names[Index].first },
4715 { uT("index"), Index },
4716 });
4717
4718 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
4719
4720 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4721 {
4722 { uT("albedo"), "TexAlbedo" },
4723 { uT("metalness"), "TexMetalness" },
4724 { uT("roughness"), "TexRoughness" },
4725 { uT("normal"), "TexNormal" },
4726 { uT("occlusion"), "TexOcclusion" },
4727 };
4728
4729 for (::std::size_t i = 0; i < Destinations.size(); i++)
4730 {
4731 const auto pData = Component_t::Make(
4732 {
4733 { uT("kind"), uT("Texture") },
4734 { uT("width"), Width },
4735 { uT("height"), Height },
4736 { uT("mapper"), Mapper },
4737 { uT("name"), Names[Index].first },
4738 { uT("index"), Index },
4739 { uT("destination"), Destinations[i].first },
4740 });
4741
4742 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
4743 }
4744 }
4745}
4746
4747// ************************************************************************** //
4748TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_ReadData_NameAndIndex_Capacity16)
4749{
4750 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
4751 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
4752
4753 using GLProxy_t = ::mock::GLProxy;
4754 GLProxy_t GLProxy;
4755 GLProxy_t::GetInstance() = &GLProxy;
4756
4757 class MapperProxy :
4758 public ::alicorn::extension::testing::Proxy<MapperProxy>
4759 {
4760 public:
4761 MOCK_METHOD1(Map, bool(const void *));
4762 MOCK_METHOD1(CheckData, void(::std::vector<uint32_t>));
4763 };
4764
4765 MapperProxy oMapperProxy;
4766 MapperProxy::GetInstance() = &oMapperProxy;
4767
4768 const int Width = 3;
4769 const int Height = 4;
4770
4771 const BufferMapper_t Mapper = [&](const void * _pData)
4772 {
4773 if (_pData != nullptr)
4774 {
4775 ::std::vector<uint32_t> Data(Width * Height);
4776 memcpy(Data.data(), _pData, Width * Height * 4);
4777 oMapperProxy.CheckData(Data);
4778 }
4779
4780 return oMapperProxy.Map(_pData);
4781 };
4782
4783 const Tested_t Example{ Data_t{} };
4784 const ITested_t & IExample = Example;
4785
4786 auto itCreator = IExample.GetCreators().find(uT("Texture"));
4787 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4788
4789 const ::mock::GLint TextureId = 1910221154;
4790 const ::mock::GLint ProgramId = 1910221155;
4791 const ::mock::GLint LocationId = 1910221156;
4792 const ::mock::GLint FrameBufferId = 1910221209;
4793 const ::mock::GLint DefaultFrameBufferId = 1910221236;
4794
4795 const auto TestCall = [&](
4796 const Component_t::ComponentPtr_t & _pDataTexture,
4797 const ::std::size_t _Index,
4798 const ::std::string & _TexName,
4799 const ::std::vector<uint32_t> & _RawData,
4800 const ::std::vector<uint32_t> & _ExpectData)
4801 {
4802 const auto Index = static_cast<::mock::GLint>(_Index);
4803
4804 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT("") };
4805
4806 using namespace ::testing;
4807
4808 InSequence Dummy;
4809
4810 EXPECT_CALL(GLProxy, GenTextures(1))
4811 .Times(1)
4812 .WillOnce(Return(TextureId));
4813
4814 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4815 .Times(1);
4816
4817 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
4818 Width, Height, 0,
4819 GL_RGBA, GL_HALF_FLOAT, ::std::vector<uint8_t>{}))
4820 .Times(1);
4821
4822 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4823 .Times(1);
4824
4825 EXPECT_CALL(GLProxy, GetError())
4826 .Times(1)
4827 .WillOnce(Return(GL_NO_ERROR));
4828
4829 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
4830 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
4831
4832 (*_pDataTexture)[uT("entity")] = pTexture;
4833
4834 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4835 .Times(1)
4836 .WillOnce(Return(FrameBufferId));
4837
4838 EXPECT_CALL(GLProxy, GenTextures(1))
4839 .Times(0);
4840
4841 auto Render = itCreator->second(Component_t::Make(
4842 {
4843 { uT("service"), Object_t{ _pDataTexture } }
4844 }));
4845 ASSERT_NE(nullptr, Render);
4846
4847 const auto TestCallActivateTexture = [&](void)
4848 {
4849 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4850 .Times(1);
4851
4852 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4853 .Times(1);
4854
4855 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4856 .Times(1)
4857 .WillOnce(Return(&ProgramId));
4858
4859 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4860 .Times(1)
4861 .WillOnce(Return(LocationId));
4862
4863 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
4864 .Times(0);
4865
4866 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4867 .Times(1);
4868 };
4869
4871
4872 EXPECT_CALL(oMapperProxy, Map(nullptr))
4873 .Times(1)
4874 .WillOnce(Return(false));
4875
4876 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
4877 .Times(0);
4878
4879 TestCallActivateTexture();
4880 Render();
4881
4883
4884 EXPECT_CALL(oMapperProxy, Map(nullptr))
4885 .Times(1)
4886 .WillOnce(Return(true));
4887
4888 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
4889 .Times(1)
4890 .WillOnce(Return(&DefaultFrameBufferId));
4891
4892 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
4893 .Times(1);
4894
4895 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
4896 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
4897 .Times(1);
4898
4899 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
4900 .Times(1)
4901 .WillOnce(Return(_RawData));
4902
4903 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
4904 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
4905 .Times(1);
4906
4907 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
4908 .Times(1);
4909
4910 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
4911 .Times(1);
4912
4913 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
4914 .Times(1);
4915
4916 TestCallActivateTexture();
4917 Render();
4918
4920
4921 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
4922 .Times(1);
4923
4924 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4925 .Times(1);
4926 };
4927
4928 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
4929 {
4930 { uT("TexEnvironment"), "TexEnvironment" },
4931 { uT("TexReflection"), "TexReflection" },
4932 { uT("TexBaseColor"), "TexBaseColor" },
4933 };
4934
4935 for (int Index = 0; Index < Names.size(); Index++)
4936 {
4937 const ::std::vector<uint32_t> RawData =
4938 {
4939 0x10221334, 0x10221335, 0x10221336,
4940 0x10221337, 0x10221338, 0x10221339,
4941 0x10221340, 0x10221341, 0x10221342,
4942 0x10221343, 0x10221344, 0x10221345,
4943 };
4944
4945 const ::std::vector<uint32_t> ExpectData =
4946 {
4947 0x10221343, 0x10221344, 0x10221345,
4948 0x10221340, 0x10221341, 0x10221342,
4949 0x10221337, 0x10221338, 0x10221339,
4950 0x10221334, 0x10221335, 0x10221336,
4951 };
4952
4953 const auto pData = Component_t::Make(
4954 {
4955 { uT("kind"), uT("Texture") },
4956 { uT("width"), Width },
4957 { uT("height"), Height },
4958 { uT("mapper"), Mapper },
4959 { uT("name"), Names[Index].first },
4960 { uT("index"), Index },
4961 { uT("capacity"), 16 },
4962 });
4963
4964 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
4965
4966 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4967 {
4968 { uT("albedo"), "TexAlbedo" },
4969 { uT("metalness"), "TexMetalness" },
4970 { uT("roughness"), "TexRoughness" },
4971 { uT("normal"), "TexNormal" },
4972 { uT("occlusion"), "TexOcclusion" },
4973 };
4974
4975 for (::std::size_t i = 0; i < Destinations.size(); i++)
4976 {
4977 const auto pData = Component_t::Make(
4978 {
4979 { uT("kind"), uT("Texture") },
4980 { uT("width"), Width },
4981 { uT("height"), Height },
4982 { uT("mapper"), Mapper },
4983 { uT("name"), Names[Index].first },
4984 { uT("index"), Index },
4985 { uT("destination"), Destinations[i].first },
4986 { uT("capacity"), 16 },
4987 });
4988
4989 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
4990 }
4991 }
4992}
4993
4994// ************************************************************************** //
4995TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_ReadData_NameAndIndex_Capacity32)
4996{
4997 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
4998 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
4999
5000 using GLProxy_t = ::mock::GLProxy;
5001 GLProxy_t GLProxy;
5002 GLProxy_t::GetInstance() = &GLProxy;
5003
5004 class MapperProxy :
5005 public ::alicorn::extension::testing::Proxy<MapperProxy>
5006 {
5007 public:
5008 MOCK_METHOD1(Map, bool(const void *));
5009 MOCK_METHOD1(CheckData, void(::std::vector<uint32_t>));
5010 };
5011
5012 MapperProxy oMapperProxy;
5013 MapperProxy::GetInstance() = &oMapperProxy;
5014
5015 const int Width = 3;
5016 const int Height = 4;
5017
5018 const BufferMapper_t Mapper = [&](const void * _pData)
5019 {
5020 if (_pData != nullptr)
5021 {
5022 ::std::vector<uint32_t> Data(Width * Height);
5023 memcpy(Data.data(), _pData, Width * Height * 4);
5024 oMapperProxy.CheckData(Data);
5025 }
5026
5027 return oMapperProxy.Map(_pData);
5028 };
5029
5030 const Tested_t Example{ Data_t{} };
5031 const ITested_t & IExample = Example;
5032
5033 auto itCreator = IExample.GetCreators().find(uT("Texture"));
5034 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5035
5036 const ::mock::GLint TextureId = 1910221154;
5037 const ::mock::GLint ProgramId = 1910221155;
5038 const ::mock::GLint LocationId = 1910221156;
5039 const ::mock::GLint FrameBufferId = 1910221209;
5040 const ::mock::GLint DefaultFrameBufferId = 1910221236;
5041
5042 const auto TestCall = [&](
5043 const Component_t::ComponentPtr_t & _pDataTexture,
5044 const ::std::size_t _Index,
5045 const ::std::string & _TexName,
5046 const ::std::vector<uint32_t> & _RawData,
5047 const ::std::vector<uint32_t> & _ExpectData)
5048 {
5049 const auto Index = static_cast<::mock::GLint>(_Index);
5050
5051 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT("") };
5052
5053 using namespace ::testing;
5054
5055 InSequence Dummy;
5056
5057 EXPECT_CALL(GLProxy, GenTextures(1))
5058 .Times(1)
5059 .WillOnce(Return(TextureId));
5060
5061 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5062 .Times(1);
5063
5064 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
5065 Width, Height, 0,
5066 GL_RGBA, GL_FLOAT, ::std::vector<uint8_t>{}))
5067 .Times(1);
5068
5069 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5070 .Times(1);
5071
5072 EXPECT_CALL(GLProxy, GetError())
5073 .Times(1)
5074 .WillOnce(Return(GL_NO_ERROR));
5075
5076 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
5077 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
5078
5079 (*_pDataTexture)[uT("entity")] = pTexture;
5080
5081 EXPECT_CALL(GLProxy, GenFramebuffers(1))
5082 .Times(1)
5083 .WillOnce(Return(FrameBufferId));
5084
5085 EXPECT_CALL(GLProxy, GenTextures(1))
5086 .Times(0);
5087
5088 auto Render = itCreator->second(Component_t::Make(
5089 {
5090 { uT("service"), Object_t{ _pDataTexture } }
5091 }));
5092 ASSERT_NE(nullptr, Render);
5093
5094 const auto TestCallActivateTexture = [&](void)
5095 {
5096 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5097 .Times(1);
5098
5099 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5100 .Times(1);
5101
5102 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5103 .Times(1)
5104 .WillOnce(Return(&ProgramId));
5105
5106 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5107 .Times(1)
5108 .WillOnce(Return(LocationId));
5109
5110 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
5111 .Times(0);
5112
5113 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5114 .Times(1);
5115 };
5116
5118
5119 EXPECT_CALL(oMapperProxy, Map(nullptr))
5120 .Times(1)
5121 .WillOnce(Return(false));
5122
5123 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
5124 .Times(0);
5125
5126 TestCallActivateTexture();
5127 Render();
5128
5130
5131 EXPECT_CALL(oMapperProxy, Map(nullptr))
5132 .Times(1)
5133 .WillOnce(Return(true));
5134
5135 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
5136 .Times(1)
5137 .WillOnce(Return(&DefaultFrameBufferId));
5138
5139 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
5140 .Times(1);
5141
5142 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
5143 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
5144 .Times(1);
5145
5146 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
5147 .Times(1)
5148 .WillOnce(Return(_RawData));
5149
5150 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
5151 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
5152 .Times(1);
5153
5154 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
5155 .Times(1);
5156
5157 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
5158 .Times(1);
5159
5160 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
5161 .Times(1);
5162
5163 TestCallActivateTexture();
5164 Render();
5165
5167
5168 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
5169 .Times(1);
5170
5171 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5172 .Times(1);
5173 };
5174
5175 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
5176 {
5177 { uT("TexEnvironment"), "TexEnvironment" },
5178 { uT("TexReflection"), "TexReflection" },
5179 { uT("TexBaseColor"), "TexBaseColor" },
5180 };
5181
5182 for (int Index = 0; Index < Names.size(); Index++)
5183 {
5184 const ::std::vector<uint32_t> RawData =
5185 {
5186 0x10221334, 0x10221335, 0x10221336,
5187 0x10221337, 0x10221338, 0x10221339,
5188 0x10221340, 0x10221341, 0x10221342,
5189 0x10221343, 0x10221344, 0x10221345,
5190 };
5191
5192 const ::std::vector<uint32_t> ExpectData =
5193 {
5194 0x10221343, 0x10221344, 0x10221345,
5195 0x10221340, 0x10221341, 0x10221342,
5196 0x10221337, 0x10221338, 0x10221339,
5197 0x10221334, 0x10221335, 0x10221336,
5198 };
5199
5200 const auto pData = Component_t::Make(
5201 {
5202 { uT("kind"), uT("Texture") },
5203 { uT("width"), Width },
5204 { uT("height"), Height },
5205 { uT("mapper"), Mapper },
5206 { uT("name"), Names[Index].first },
5207 { uT("index"), Index },
5208 { uT("capacity"), 32 },
5209 });
5210
5211 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
5212
5213 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
5214 {
5215 { uT("albedo"), "TexAlbedo" },
5216 { uT("metalness"), "TexMetalness" },
5217 { uT("roughness"), "TexRoughness" },
5218 { uT("normal"), "TexNormal" },
5219 { uT("occlusion"), "TexOcclusion" },
5220 };
5221
5222 for (::std::size_t i = 0; i < Destinations.size(); i++)
5223 {
5224 const auto pData = Component_t::Make(
5225 {
5226 { uT("kind"), uT("Texture") },
5227 { uT("width"), Width },
5228 { uT("height"), Height },
5229 { uT("mapper"), Mapper },
5230 { uT("name"), Names[Index].first },
5231 { uT("index"), Index },
5232 { uT("destination"), Destinations[i].first },
5233 { uT("capacity"), 32 },
5234 });
5235
5236 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
5237 }
5238 }
5239}
5240
5241// ************************************************************************** //
5242TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_ReadData_Destination)
5243{
5244 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
5245 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
5246
5247 using GLProxy_t = ::mock::GLProxy;
5248 GLProxy_t GLProxy;
5249 GLProxy_t::GetInstance() = &GLProxy;
5250
5251 class MapperProxy :
5252 public ::alicorn::extension::testing::Proxy<MapperProxy>
5253 {
5254 public:
5255 MOCK_METHOD1(Map, bool(const void *));
5256 MOCK_METHOD1(CheckData, void(::std::vector<uint32_t>));
5257 };
5258
5259 MapperProxy oMapperProxy;
5260 MapperProxy::GetInstance() = &oMapperProxy;
5261
5262 const int Width = 3;
5263 const int Height = 4;
5264
5265 const BufferMapper_t Mapper = [&](const void * _pData)
5266 {
5267 if (_pData != nullptr)
5268 {
5269 ::std::vector<uint32_t> Data(Width * Height);
5270 memcpy(Data.data(), _pData, Width * Height * 4);
5271 oMapperProxy.CheckData(Data);
5272 }
5273
5274 return oMapperProxy.Map(_pData);
5275 };
5276
5277 const Tested_t Example{ Data_t{} };
5278 const ITested_t & IExample = Example;
5279
5280 auto itCreator = IExample.GetCreators().find(uT("Texture"));
5281 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5282
5283 const ::mock::GLint TextureId = 1910221154;
5284 const ::mock::GLint ProgramId = 1910221155;
5285 const ::mock::GLint LocationId = 1910221156;
5286 const ::mock::GLint FrameBufferId = 1910221209;
5287 const ::mock::GLint DefaultFrameBufferId = 1910221236;
5288
5289 const auto TestCall = [&](
5290 const Component_t::ComponentPtr_t & _pDataTexture,
5291 const ::std::size_t _Index,
5292 const ::std::string & _TexName,
5293 const ::std::vector<uint32_t> & _RawData,
5294 const ::std::vector<uint32_t> & _ExpectData)
5295 {
5296 const auto Index = static_cast<::mock::GLint>(_Index);
5297
5298 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT("") };
5299
5300 using namespace ::testing;
5301
5302 InSequence Dummy;
5303
5304 EXPECT_CALL(GLProxy, GenTextures(1))
5305 .Times(1)
5306 .WillOnce(Return(TextureId));
5307
5308 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5309 .Times(1);
5310
5311 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
5312 Width, Height, 0,
5313 GL_RGBA, GL_UNSIGNED_BYTE, ::std::vector<uint8_t>{}))
5314 .Times(1);
5315
5316 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5317 .Times(1);
5318
5319 EXPECT_CALL(GLProxy, GetError())
5320 .Times(1)
5321 .WillOnce(Return(GL_NO_ERROR));
5322
5323 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
5324 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
5325
5326 (*_pDataTexture)[uT("entity")] = pTexture;
5327
5328 EXPECT_CALL(GLProxy, GenFramebuffers(1))
5329 .Times(1)
5330 .WillOnce(Return(FrameBufferId));
5331
5332 EXPECT_CALL(GLProxy, GenTextures(1))
5333 .Times(0);
5334
5335 auto Render = itCreator->second(Component_t::Make(
5336 {
5337 { uT("service"), Object_t{ _pDataTexture } }
5338 }));
5339 ASSERT_NE(nullptr, Render);
5340
5341 const auto TestCallActivateTexture = [&](void)
5342 {
5343 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5344 .Times(1);
5345
5346 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5347 .Times(1);
5348
5349 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5350 .Times(1)
5351 .WillOnce(Return(&ProgramId));
5352
5353 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5354 .Times(1)
5355 .WillOnce(Return(LocationId));
5356
5357 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
5358 .Times(0);
5359
5360 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5361 .Times(1);
5362 };
5363
5365
5366 EXPECT_CALL(oMapperProxy, Map(nullptr))
5367 .Times(1)
5368 .WillOnce(Return(false));
5369
5370 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
5371 .Times(0);
5372
5373 TestCallActivateTexture();
5374 Render();
5375
5377
5378 EXPECT_CALL(oMapperProxy, Map(nullptr))
5379 .Times(1)
5380 .WillOnce(Return(true));
5381
5382 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
5383 .Times(1)
5384 .WillOnce(Return(&DefaultFrameBufferId));
5385
5386 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
5387 .Times(1);
5388
5389 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
5390 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
5391 .Times(1);
5392
5393 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
5394 .Times(1)
5395 .WillOnce(Return(_RawData));
5396
5397 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
5398 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
5399 .Times(1);
5400
5401 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
5402 .Times(1);
5403
5404 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
5405 .Times(1);
5406
5407 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
5408 .Times(1);
5409
5410 TestCallActivateTexture();
5411 Render();
5412
5414
5415 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
5416 .Times(1);
5417
5418 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5419 .Times(1);
5420 };
5421
5422 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
5423 {
5424 { uT("albedo"), "TexAlbedo" },
5425 { uT("metalness"), "TexMetalness" },
5426 { uT("roughness"), "TexRoughness" },
5427 { uT("normal"), "TexNormal" },
5428 { uT("occlusion"), "TexOcclusion" },
5429 };
5430
5431 for (::std::size_t i = 0; i < Destinations.size(); i++)
5432 {
5433 const ::std::vector<uint32_t> RawData =
5434 {
5435 0x10221334, 0x10221335, 0x10221336,
5436 0x10221337, 0x10221338, 0x10221339,
5437 0x10221340, 0x10221341, 0x10221342,
5438 0x10221343, 0x10221344, 0x10221345,
5439 };
5440
5441 const ::std::vector<uint32_t> ExpectData =
5442 {
5443 0x10221343, 0x10221344, 0x10221345,
5444 0x10221340, 0x10221341, 0x10221342,
5445 0x10221337, 0x10221338, 0x10221339,
5446 0x10221334, 0x10221335, 0x10221336,
5447 };
5448
5449 const auto pData = Component_t::Make(
5450 {
5451 { uT("kind"), uT("Texture") },
5452 { uT("width"), Width },
5453 { uT("height"), Height },
5454 { uT("mapper"), Mapper },
5455 { uT("destination"), Destinations[i].first },
5456 });
5457
5458 TestCall(pData, i, Destinations[i].second, RawData, ExpectData);
5459 }
5460}
5461
5462// ************************************************************************** //
5463TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_ReadData_Destination_Capacity16)
5464{
5465 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
5466 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
5467
5468 using GLProxy_t = ::mock::GLProxy;
5469 GLProxy_t GLProxy;
5470 GLProxy_t::GetInstance() = &GLProxy;
5471
5472 class MapperProxy :
5473 public ::alicorn::extension::testing::Proxy<MapperProxy>
5474 {
5475 public:
5476 MOCK_METHOD1(Map, bool(const void *));
5477 MOCK_METHOD1(CheckData, void(::std::vector<uint32_t>));
5478 };
5479
5480 MapperProxy oMapperProxy;
5481 MapperProxy::GetInstance() = &oMapperProxy;
5482
5483 const int Width = 3;
5484 const int Height = 4;
5485
5486 const BufferMapper_t Mapper = [&](const void * _pData)
5487 {
5488 if (_pData != nullptr)
5489 {
5490 ::std::vector<uint32_t> Data(Width * Height);
5491 memcpy(Data.data(), _pData, Width * Height * 4);
5492 oMapperProxy.CheckData(Data);
5493 }
5494
5495 return oMapperProxy.Map(_pData);
5496 };
5497
5498 const Tested_t Example{ Data_t{} };
5499 const ITested_t & IExample = Example;
5500
5501 auto itCreator = IExample.GetCreators().find(uT("Texture"));
5502 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5503
5504 const ::mock::GLint TextureId = 1910221154;
5505 const ::mock::GLint ProgramId = 1910221155;
5506 const ::mock::GLint LocationId = 1910221156;
5507 const ::mock::GLint FrameBufferId = 1910221209;
5508 const ::mock::GLint DefaultFrameBufferId = 1910221236;
5509
5510 const auto TestCall = [&](
5511 const Component_t::ComponentPtr_t & _pDataTexture,
5512 const ::std::size_t _Index,
5513 const ::std::string & _TexName,
5514 const ::std::vector<uint32_t> & _RawData,
5515 const ::std::vector<uint32_t> & _ExpectData)
5516 {
5517 const auto Index = static_cast<::mock::GLint>(_Index);
5518
5519 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT("") };
5520
5521 using namespace ::testing;
5522
5523 InSequence Dummy;
5524
5525 EXPECT_CALL(GLProxy, GenTextures(1))
5526 .Times(1)
5527 .WillOnce(Return(TextureId));
5528
5529 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5530 .Times(1);
5531
5532 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
5533 Width, Height, 0,
5534 GL_RGBA, GL_HALF_FLOAT, ::std::vector<uint8_t>{}))
5535 .Times(1);
5536
5537 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5538 .Times(1);
5539
5540 EXPECT_CALL(GLProxy, GetError())
5541 .Times(1)
5542 .WillOnce(Return(GL_NO_ERROR));
5543
5544 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
5545 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
5546
5547 (*_pDataTexture)[uT("entity")] = pTexture;
5548
5549 EXPECT_CALL(GLProxy, GenFramebuffers(1))
5550 .Times(1)
5551 .WillOnce(Return(FrameBufferId));
5552
5553 EXPECT_CALL(GLProxy, GenTextures(1))
5554 .Times(0);
5555
5556 auto Render = itCreator->second(Component_t::Make(
5557 {
5558 { uT("service"), Object_t{ _pDataTexture } }
5559 }));
5560 ASSERT_NE(nullptr, Render);
5561
5562 const auto TestCallActivateTexture = [&](void)
5563 {
5564 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5565 .Times(1);
5566
5567 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5568 .Times(1);
5569
5570 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5571 .Times(1)
5572 .WillOnce(Return(&ProgramId));
5573
5574 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5575 .Times(1)
5576 .WillOnce(Return(LocationId));
5577
5578 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
5579 .Times(0);
5580
5581 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5582 .Times(1);
5583 };
5584
5586
5587 EXPECT_CALL(oMapperProxy, Map(nullptr))
5588 .Times(1)
5589 .WillOnce(Return(false));
5590
5591 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
5592 .Times(0);
5593
5594 TestCallActivateTexture();
5595 Render();
5596
5598
5599 EXPECT_CALL(oMapperProxy, Map(nullptr))
5600 .Times(1)
5601 .WillOnce(Return(true));
5602
5603 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
5604 .Times(1)
5605 .WillOnce(Return(&DefaultFrameBufferId));
5606
5607 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
5608 .Times(1);
5609
5610 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
5611 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
5612 .Times(1);
5613
5614 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
5615 .Times(1)
5616 .WillOnce(Return(_RawData));
5617
5618 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
5619 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
5620 .Times(1);
5621
5622 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
5623 .Times(1);
5624
5625 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
5626 .Times(1);
5627
5628 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
5629 .Times(1);
5630
5631 TestCallActivateTexture();
5632 Render();
5633
5635
5636 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
5637 .Times(1);
5638
5639 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5640 .Times(1);
5641 };
5642
5643 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
5644 {
5645 { uT("albedo"), "TexAlbedo" },
5646 { uT("metalness"), "TexMetalness" },
5647 { uT("roughness"), "TexRoughness" },
5648 { uT("normal"), "TexNormal" },
5649 { uT("occlusion"), "TexOcclusion" },
5650 };
5651
5652 for (::std::size_t i = 0; i < Destinations.size(); i++)
5653 {
5654 const ::std::vector<uint32_t> RawData =
5655 {
5656 0x10221334, 0x10221335, 0x10221336,
5657 0x10221337, 0x10221338, 0x10221339,
5658 0x10221340, 0x10221341, 0x10221342,
5659 0x10221343, 0x10221344, 0x10221345,
5660 };
5661
5662 const ::std::vector<uint32_t> ExpectData =
5663 {
5664 0x10221343, 0x10221344, 0x10221345,
5665 0x10221340, 0x10221341, 0x10221342,
5666 0x10221337, 0x10221338, 0x10221339,
5667 0x10221334, 0x10221335, 0x10221336,
5668 };
5669
5670 const auto pData = Component_t::Make(
5671 {
5672 { uT("kind"), uT("Texture") },
5673 { uT("width"), Width },
5674 { uT("height"), Height },
5675 { uT("mapper"), Mapper },
5676 { uT("destination"), Destinations[i].first },
5677 { uT("capacity"), 16 },
5678 });
5679
5680 TestCall(pData, i, Destinations[i].second, RawData, ExpectData);
5681 }
5682}
5683
5684// ************************************************************************** //
5685TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_ReadData_Destination_Capacity32)
5686{
5687 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
5688 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
5689
5690 using GLProxy_t = ::mock::GLProxy;
5691 GLProxy_t GLProxy;
5692 GLProxy_t::GetInstance() = &GLProxy;
5693
5694 class MapperProxy :
5695 public ::alicorn::extension::testing::Proxy<MapperProxy>
5696 {
5697 public:
5698 MOCK_METHOD1(Map, bool(const void *));
5699 MOCK_METHOD1(CheckData, void(::std::vector<uint32_t>));
5700 };
5701
5702 MapperProxy oMapperProxy;
5703 MapperProxy::GetInstance() = &oMapperProxy;
5704
5705 const int Width = 3;
5706 const int Height = 4;
5707
5708 const BufferMapper_t Mapper = [&](const void * _pData)
5709 {
5710 if (_pData != nullptr)
5711 {
5712 ::std::vector<uint32_t> Data(Width * Height);
5713 memcpy(Data.data(), _pData, Width * Height * 4);
5714 oMapperProxy.CheckData(Data);
5715 }
5716
5717 return oMapperProxy.Map(_pData);
5718 };
5719
5720 const Tested_t Example{ Data_t{} };
5721 const ITested_t & IExample = Example;
5722
5723 auto itCreator = IExample.GetCreators().find(uT("Texture"));
5724 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5725
5726 const ::mock::GLint TextureId = 1910221154;
5727 const ::mock::GLint ProgramId = 1910221155;
5728 const ::mock::GLint LocationId = 1910221156;
5729 const ::mock::GLint FrameBufferId = 1910221209;
5730 const ::mock::GLint DefaultFrameBufferId = 1910221236;
5731
5732 const auto TestCall = [&](
5733 const Component_t::ComponentPtr_t & _pDataTexture,
5734 const ::std::size_t _Index,
5735 const ::std::string & _TexName,
5736 const ::std::vector<uint32_t> & _RawData,
5737 const ::std::vector<uint32_t> & _ExpectData)
5738 {
5739 const auto Index = static_cast<::mock::GLint>(_Index);
5740
5741 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT("") };
5742
5743 using namespace ::testing;
5744
5745 InSequence Dummy;
5746
5747 EXPECT_CALL(GLProxy, GenTextures(1))
5748 .Times(1)
5749 .WillOnce(Return(TextureId));
5750
5751 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5752 .Times(1);
5753
5754 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
5755 Width, Height, 0,
5756 GL_RGBA, GL_FLOAT, ::std::vector<uint8_t>{}))
5757 .Times(1);
5758
5759 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5760 .Times(1);
5761
5762 EXPECT_CALL(GLProxy, GetError())
5763 .Times(1)
5764 .WillOnce(Return(GL_NO_ERROR));
5765
5766 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
5767 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
5768
5769 (*_pDataTexture)[uT("entity")] = pTexture;
5770
5771 EXPECT_CALL(GLProxy, GenFramebuffers(1))
5772 .Times(1)
5773 .WillOnce(Return(FrameBufferId));
5774
5775 EXPECT_CALL(GLProxy, GenTextures(1))
5776 .Times(0);
5777
5778 auto Render = itCreator->second(Component_t::Make(
5779 {
5780 { uT("service"), Object_t{ _pDataTexture } }
5781 }));
5782 ASSERT_NE(nullptr, Render);
5783
5784 const auto TestCallActivateTexture = [&](void)
5785 {
5786 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5787 .Times(1);
5788
5789 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5790 .Times(1);
5791
5792 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5793 .Times(1)
5794 .WillOnce(Return(&ProgramId));
5795
5796 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5797 .Times(1)
5798 .WillOnce(Return(LocationId));
5799
5800 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
5801 .Times(0);
5802
5803 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5804 .Times(1);
5805 };
5806
5808
5809 EXPECT_CALL(oMapperProxy, Map(nullptr))
5810 .Times(1)
5811 .WillOnce(Return(false));
5812
5813 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
5814 .Times(0);
5815
5816 TestCallActivateTexture();
5817 Render();
5818
5820
5821 EXPECT_CALL(oMapperProxy, Map(nullptr))
5822 .Times(1)
5823 .WillOnce(Return(true));
5824
5825 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
5826 .Times(1)
5827 .WillOnce(Return(&DefaultFrameBufferId));
5828
5829 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
5830 .Times(1);
5831
5832 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
5833 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
5834 .Times(1);
5835
5836 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
5837 .Times(1)
5838 .WillOnce(Return(_RawData));
5839
5840 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
5841 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
5842 .Times(1);
5843
5844 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
5845 .Times(1);
5846
5847 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
5848 .Times(1);
5849
5850 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
5851 .Times(1);
5852
5853 TestCallActivateTexture();
5854 Render();
5855
5857
5858 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
5859 .Times(1);
5860
5861 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5862 .Times(1);
5863 };
5864
5865 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
5866 {
5867 { uT("albedo"), "TexAlbedo" },
5868 { uT("metalness"), "TexMetalness" },
5869 { uT("roughness"), "TexRoughness" },
5870 { uT("normal"), "TexNormal" },
5871 { uT("occlusion"), "TexOcclusion" },
5872 };
5873
5874 for (::std::size_t i = 0; i < Destinations.size(); i++)
5875 {
5876 const ::std::vector<uint32_t> RawData =
5877 {
5878 0x10221334, 0x10221335, 0x10221336,
5879 0x10221337, 0x10221338, 0x10221339,
5880 0x10221340, 0x10221341, 0x10221342,
5881 0x10221343, 0x10221344, 0x10221345,
5882 };
5883
5884 const ::std::vector<uint32_t> ExpectData =
5885 {
5886 0x10221343, 0x10221344, 0x10221345,
5887 0x10221340, 0x10221341, 0x10221342,
5888 0x10221337, 0x10221338, 0x10221339,
5889 0x10221334, 0x10221335, 0x10221336,
5890 };
5891
5892 const auto pData = Component_t::Make(
5893 {
5894 { uT("kind"), uT("Texture") },
5895 { uT("width"), Width },
5896 { uT("height"), Height },
5897 { uT("mapper"), Mapper },
5898 { uT("destination"), Destinations[i].first },
5899 { uT("capacity"), 32 },
5900 });
5901
5902 TestCall(pData, i, Destinations[i].second, RawData, ExpectData);
5903 }
5904}
5905
5906// ************************************************************************** //
5907TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_Depth_NameAndIndex)
5908{
5909 using GLProxy_t = ::mock::GLProxy;
5910 GLProxy_t GLProxy;
5911 GLProxy_t::GetInstance() = &GLProxy;
5912
5913 const Tested_t Example{ Data_t{} };
5914 const ITested_t & IExample = Example;
5915
5916 auto itCreator = IExample.GetCreators().find(uT("Texture"));
5917 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5918
5919 const ::mock::GLuint TextureId = 1910041336;
5920 const ::mock::GLint ProgramId = 1910041337;
5921 const ::mock::GLint LocationId = 1910041338;
5922
5923 const auto TestCall = [&](
5924 const Component_t::ComponentPtr_t & _pTexture,
5925 const ::std::vector<uint8_t> & _Source,
5926 const int _Width, const int _Height,
5927 const ::std::size_t _Index,
5928 const ::std::string & _TexName)
5929 {
5930 const auto Index = static_cast<::mock::GLint>(_Index);
5931
5932 using namespace ::testing;
5933
5934 InSequence Dummy;
5935
5936 EXPECT_CALL(GLProxy, GenTextures(1))
5937 .Times(1)
5938 .WillOnce(Return(TextureId));
5939
5940 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5941 .Times(1);
5942
5943 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
5944 _Width, _Height, 0,
5945 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, _Source))
5946 .Times(1);
5947
5948 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5949 .Times(1);
5950
5951 EXPECT_CALL(GLProxy, GetError())
5952 .Times(1)
5953 .WillOnce(Return(GL_NO_ERROR));
5954
5955 auto Render = itCreator->second(_pTexture);
5956 ASSERT_NE(nullptr, Render);
5957
5958 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5959 .Times(1);
5960
5961 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5962 .Times(1);
5963
5964 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5965 .Times(1)
5966 .WillOnce(Return(&ProgramId));
5967
5968 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5969 .Times(1)
5970 .WillOnce(Return(LocationId));
5971
5972 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
5973 .Times(0);
5974
5975 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5976 .Times(1);
5977
5978 Render();
5979
5980 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5981 .Times(1);
5982 };
5983
5984 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
5985 {
5986 { uT("TexEnvironment"), "TexEnvironment" },
5987 { uT("TexReflection"), "TexReflection" },
5988 { uT("TexBaseColor"), "TexBaseColor" },
5989 };
5990
5991 for (int Index = 0; Index < Names.size(); Index++)
5992 {
5993 ::std::vector<uint8_t> Source =
5994 {
5995 0x20, 0x06, 0x15, 0x12, 0x32,
5996 0x20, 0x06, 0x15, 0x12, 0x32,
5997 0x20, 0x06, 0x15, 0x12, 0x32,
5998 0x20, 0x06, 0x15, 0x12, 0x32,
5999 0x20, 0x06, 0x15, 0x12, 0x32,
6000 };
6001 IntroduceBufferSize(Source);
6002
6003 {
6004 const int Width = 1910041343;
6005 const int Height = 1910041344;
6006
6007 const auto pTexture = Component_t::Make(
6008 {
6009 { uT("content"), Source },
6010 { uT("width"), Width },
6011 { uT("height"), Height },
6012 { uT("name"), Names[Index].first },
6013 { uT("index"), Index },
6014 { uT("destination"), uT("depth") },
6015 });
6016
6017 TestCall(pTexture, Source, Width, Height, Index, Names[Index].second);
6018 }
6019
6020 {
6021 const int Width = 1910041346;
6022 const int Height = 1910041347;
6023
6024 const auto pData = Component_t::Make(
6025 {
6026 { uT("kind"), uT("Texture") },
6027 { uT("content"), Source },
6028 { uT("width"), Width },
6029 { uT("height"), Height },
6030 { uT("name"), Names[Index].first },
6031 { uT("index"), Index },
6032 { uT("destination"), uT("depth") },
6033 });
6034
6035 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
6036 Source, Width, Height, Index, Names[Index].second);
6037 }
6038 }
6039}
6040
6041// ************************************************************************** //
6042TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_Depth_Destination)
6043{
6044 using GLProxy_t = ::mock::GLProxy;
6045 GLProxy_t GLProxy;
6046 GLProxy_t::GetInstance() = &GLProxy;
6047
6048 const Tested_t Example{ Data_t{} };
6049 const ITested_t & IExample = Example;
6050
6051 auto itCreator = IExample.GetCreators().find(uT("Texture"));
6052 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6053
6054 const ::mock::GLuint TextureId = 1910041336;
6055 const ::mock::GLint ProgramId = 1910041337;
6056 const ::mock::GLint LocationId = 1910041338;
6057
6058 const auto TestCall = [&](
6059 const Component_t::ComponentPtr_t & _pTexture,
6060 const ::std::vector<uint8_t> & _Source,
6061 const int _Width, const int _Height,
6062 const ::std::size_t _Index,
6063 const ::std::string & _TexName)
6064 {
6065 const auto Index = static_cast<::mock::GLint>(_Index);
6066
6067 using namespace ::testing;
6068
6069 InSequence Dummy;
6070
6071 EXPECT_CALL(GLProxy, GenTextures(1))
6072 .Times(1)
6073 .WillOnce(Return(TextureId));
6074
6075 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6076 .Times(1);
6077
6078 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
6079 _Width, _Height, 0,
6080 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, _Source))
6081 .Times(1);
6082
6083 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
6084 .Times(1);
6085
6086 EXPECT_CALL(GLProxy, GetError())
6087 .Times(1)
6088 .WillOnce(Return(GL_NO_ERROR));
6089
6090 auto Render = itCreator->second(_pTexture);
6091 ASSERT_NE(nullptr, Render);
6092
6093 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
6094 .Times(1);
6095
6096 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6097 .Times(1);
6098
6099 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6100 .Times(1)
6101 .WillOnce(Return(&ProgramId));
6102
6103 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
6104 .Times(1)
6105 .WillOnce(Return(LocationId));
6106
6107 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
6108 .Times(0);
6109
6110 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
6111 .Times(1);
6112
6113 Render();
6114
6115 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6116 .Times(1);
6117 };
6118
6119 ::std::vector<uint8_t> Source =
6120 {
6121 0x20, 0x06, 0x15, 0x12, 0x32,
6122 0x20, 0x06, 0x15, 0x12, 0x32,
6123 0x20, 0x06, 0x15, 0x12, 0x32,
6124 0x20, 0x06, 0x15, 0x12, 0x32,
6125 0x20, 0x06, 0x15, 0x12, 0x32,
6126 };
6127 IntroduceBufferSize(Source);
6128
6129 {
6130 const int Width = 1910041343;
6131 const int Height = 1910041344;
6132
6133 const auto pTexture = Component_t::Make(
6134 {
6135 { uT("content"), Source },
6136 { uT("width"), Width },
6137 { uT("height"), Height },
6138 { uT("destination"), uT("depth") },
6139 });
6140
6141 TestCall(pTexture, Source, Width, Height, 5, "TexDepth");
6142 }
6143
6144 {
6145 const int Width = 1910041346;
6146 const int Height = 1910041347;
6147
6148 const auto pData = Component_t::Make(
6149 {
6150 { uT("kind"), uT("Texture") },
6151 { uT("content"), Source },
6152 { uT("width"), Width },
6153 { uT("height"), Height },
6154 { uT("destination"), uT("depth") },
6155 });
6156
6157 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
6158 Source, Width, Height, 5, "TexDepth");
6159 }
6160}
6161
6162// ************************************************************************** //
6163TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_UsingExists_NameAndIndex)
6164{
6165 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
6166
6167 using GLProxy_t = ::mock::GLProxy;
6168 GLProxy_t GLProxy;
6169 GLProxy_t::GetInstance() = &GLProxy;
6170
6171 const Tested_t Example{ Data_t{} };
6172 const ITested_t & IExample = Example;
6173
6174 auto itCreator = IExample.GetCreators().find(uT("Texture"));
6175 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6176
6177 const ::mock::GLuint TextureId = 1908221839;
6178 const ::mock::GLint ProgramId = 1908221840;
6179 const ::mock::GLint LocationId = 1908221841;
6180
6181 const auto TestCall = [&](
6182 const Component_t::ComponentPtr_t & _pData,
6183 const Component_t::ComponentPtr_t & _pTexture,
6184 const ::std::vector<uint8_t> & _Source,
6185 const int _Width, const int _Height,
6186 const ::std::size_t _Index,
6187 const ::std::string & _TexName)
6188 {
6189 const ::covellite::api::renderer::Component::Texture TextureData{ *_pData, uT("") };
6190 const auto Index = static_cast<::mock::GLint>(_Index);
6191
6192 using namespace ::testing;
6193
6194 InSequence Dummy;
6195
6196 EXPECT_CALL(GLProxy, GenTextures(1))
6197 .Times(1)
6198 .WillOnce(Return(TextureId));
6199
6200 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6201 .Times(1);
6202
6203 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, _,
6204 _Width, _Height, 0, _, _, _Source))
6205 .Times(1);
6206
6207 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
6208 .Times(1);
6209
6210 EXPECT_CALL(GLProxy, GetError())
6211 .Times(1)
6212 .WillOnce(Return(GL_NO_ERROR));
6213
6214 (*_pData)[uT("entity")] = ::std::make_shared<Texture_t>(TextureData);
6215
6216 EXPECT_CALL(GLProxy, GenTextures(_))
6217 .Times(0);
6218
6219 auto Render = itCreator->second(_pTexture);
6220 ASSERT_NE(nullptr, Render);
6221
6222 const Texture_t::Ptr_t pEntity = (*_pData)[uT("entity")].Default(Texture_t::Ptr_t{});
6223 EXPECT_EQ(nullptr, pEntity);
6224
6225 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
6226 .Times(1);
6227
6228 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6229 .Times(1);
6230
6231 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6232 .Times(1)
6233 .WillOnce(Return(&ProgramId));
6234
6235 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
6236 .Times(1)
6237 .WillOnce(Return(LocationId));
6238
6239 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
6240 .Times(1);
6241
6242 Render();
6243
6244 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6245 .Times(1);
6246 };
6247
6248 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
6249 {
6250 { uT("TexEnvironment"), "TexEnvironment" },
6251 { uT("TexReflection"), "TexReflection" },
6252 { uT("TexBaseColor"), "TexBaseColor" },
6253 };
6254
6255 for (int Index = 0; Index < Names.size(); Index++)
6256 {
6257 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
6258 {
6259 { uT("albedo"), "TexAlbedo" },
6260 { uT("metalness"), "TexMetalness" },
6261 { uT("roughness"), "TexRoughness" },
6262 { uT("normal"), "TexNormal" },
6263 { uT("occlusion"), "TexOcclusion" },
6264 { uT("depth"), "TexDepth" },
6265 };
6266
6267 ::std::vector<uint8_t> Source =
6268 {
6269 0x20, 0x06, 0x15, 0x12, 0x33,
6270 0x20, 0x06, 0x15, 0x12, 0x33,
6271 0x20, 0x06, 0x15, 0x12, 0x33,
6272 0x20, 0x06, 0x15, 0x12, 0x33,
6273 0x20, 0x06, 0x15, 0x12, 0x33,
6274 };
6275 IntroduceBufferSize(Source);
6276
6277 for (::std::size_t i = 0; i < Destinations.size(); i++)
6278 {
6279 const int Width = 1908221845;
6280 const int Height = 1908221847;
6281
6282 const auto pData = Component_t::Make(
6283 {
6284 { uT("kind"), uT("Texture") },
6285 { uT("content"), Source },
6286 { uT("width"), Width },
6287 { uT("height"), Height },
6288 { uT("name"), Names[Index].first },
6289 { uT("index"), Index },
6290 { uT("destination"), Destinations[i].first },
6291 });
6292
6293 TestCall(pData, Component_t::Make({ { uT("service"), Object_t{ pData } } }),
6294 Source, Width, Height, Index, Names[Index].second);
6295 }
6296 }
6297}
6298
6299// ************************************************************************** //
6300TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_UsingExists_Destination)
6301{
6302 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
6303
6304 using GLProxy_t = ::mock::GLProxy;
6305 GLProxy_t GLProxy;
6306 GLProxy_t::GetInstance() = &GLProxy;
6307
6308 const Tested_t Example{ Data_t{} };
6309 const ITested_t & IExample = Example;
6310
6311 auto itCreator = IExample.GetCreators().find(uT("Texture"));
6312 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6313
6314 const ::mock::GLuint TextureId = 1908221839;
6315 const ::mock::GLint ProgramId = 1908221840;
6316 const ::mock::GLint LocationId = 1908221841;
6317
6318 const auto TestCall = [&](
6319 const Component_t::ComponentPtr_t & _pData,
6320 const Component_t::ComponentPtr_t & _pTexture,
6321 const ::std::vector<uint8_t> & _Source,
6322 const int _Width, const int _Height,
6323 const ::std::size_t _Index,
6324 const ::std::string & _TexName)
6325 {
6326 const ::covellite::api::renderer::Component::Texture TextureData{ *_pData, uT("") };
6327 const auto Index = static_cast<::mock::GLint>(_Index);
6328
6329 using namespace ::testing;
6330
6331 InSequence Dummy;
6332
6333 EXPECT_CALL(GLProxy, GenTextures(1))
6334 .Times(1)
6335 .WillOnce(Return(TextureId));
6336
6337 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6338 .Times(1);
6339
6340 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, _,
6341 _Width, _Height, 0, _, _, _Source))
6342 .Times(1);
6343
6344 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
6345 .Times(1);
6346
6347 EXPECT_CALL(GLProxy, GetError())
6348 .Times(1)
6349 .WillOnce(Return(GL_NO_ERROR));
6350
6351 (*_pData)[uT("entity")] = ::std::make_shared<Texture_t>(TextureData);
6352
6353 EXPECT_CALL(GLProxy, GenTextures(_))
6354 .Times(0);
6355
6356 auto Render = itCreator->second(_pTexture);
6357 ASSERT_NE(nullptr, Render);
6358
6359 const Texture_t::Ptr_t pEntity = (*_pData)[uT("entity")].Default(Texture_t::Ptr_t{});
6360 EXPECT_EQ(nullptr, pEntity);
6361
6362 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
6363 .Times(1);
6364
6365 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6366 .Times(1);
6367
6368 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6369 .Times(1)
6370 .WillOnce(Return(&ProgramId));
6371
6372 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
6373 .Times(1)
6374 .WillOnce(Return(LocationId));
6375
6376 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
6377 .Times(1);
6378
6379 Render();
6380
6381 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6382 .Times(1);
6383 };
6384
6385 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
6386 {
6387 { uT("albedo"), "TexAlbedo" },
6388 { uT("metalness"), "TexMetalness" },
6389 { uT("roughness"), "TexRoughness" },
6390 { uT("normal"), "TexNormal" },
6391 { uT("occlusion"), "TexOcclusion" },
6392 { uT("depth"), "TexDepth" },
6393 };
6394
6395 ::std::vector<uint8_t> Source =
6396 {
6397 0x20, 0x06, 0x15, 0x12, 0x33,
6398 0x20, 0x06, 0x15, 0x12, 0x33,
6399 0x20, 0x06, 0x15, 0x12, 0x33,
6400 0x20, 0x06, 0x15, 0x12, 0x33,
6401 0x20, 0x06, 0x15, 0x12, 0x33,
6402 };
6403 IntroduceBufferSize(Source);
6404
6405 for (::std::size_t i = 0; i < Destinations.size(); i++)
6406 {
6407 const int Width = 1908221845;
6408 const int Height = 1908221847;
6409
6410 const auto pData = Component_t::Make(
6411 {
6412 { uT("kind"), uT("Texture") },
6413 { uT("content"), Source },
6414 { uT("width"), Width },
6415 { uT("height"), Height },
6416 { uT("destination"), Destinations[i].first },
6417 });
6418
6419 TestCall(pData, Component_t::Make({ { uT("service"), Object_t{ pData } } }),
6420 Source, Width, Height, i, Destinations[i].second);
6421 }
6422}
6423
6424// ************************************************************************** //
6425TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Texture_NoDeclaredInShader)
6426{
6427 using GLProxy_t = ::mock::GLProxy;
6428 GLProxy_t GLProxy;
6429 GLProxy_t::GetInstance() = &GLProxy;
6430
6431 const Tested_t Example{ Data_t{} };
6432 const ITested_t & IExample = Example;
6433
6434 auto itCreator = IExample.GetCreators().find(uT("Texture"));
6435 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6436
6437 const ::mock::GLuint TextureId = 1908221839;
6438
6439 const auto TestCall = [&](
6440 const Component_t::ComponentPtr_t & _pTexture,
6441 const ::std::vector<uint8_t> & /*_Source*/,
6442 const int /*_Width*/, const int /*_Height*/,
6443 const ::std::size_t _Index,
6444 const ::std::string & _TexName)
6445 {
6446 const auto Index = static_cast<::mock::GLint>(_Index);
6447
6448 using namespace ::testing;
6449
6450 InSequence Dummy;
6451
6452 EXPECT_CALL(GLProxy, GenTextures(1))
6453 .Times(1)
6454 .WillOnce(Return(TextureId));
6455
6456 auto Render = itCreator->second(_pTexture);
6457 ASSERT_NE(nullptr, Render);
6458
6459 EXPECT_CALL(GLProxy, GetUniformLocation(_, _TexName))
6460 .Times(1)
6461 .WillOnce(Return(-1));
6462
6463 EXPECT_CALL(GLProxy, Uniform1i(_, _))
6464 .Times(0);
6465
6466 Render();
6467
6468 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6469 .Times(1);
6470 };
6471
6472 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
6473 {
6474 { uT("albedo"), "TexAlbedo" },
6475 { uT("metalness"), "TexMetalness" },
6476 { uT("roughness"), "TexRoughness" },
6477 { uT("normal"), "TexNormal" },
6478 { uT("occlusion"), "TexOcclusion" },
6479 { uT("depth"), "TexDepth" },
6480 };
6481
6482 ::std::vector<uint8_t> Source =
6483 {
6484 0x20, 0x06, 0x15, 0x12, 0x34,
6485 0x20, 0x06, 0x15, 0x12, 0x34,
6486 0x20, 0x06, 0x15, 0x12, 0x34,
6487 0x20, 0x06, 0x15, 0x12, 0x34,
6488 0x20, 0x06, 0x15, 0x12, 0x34,
6489 };
6490 IntroduceBufferSize(Source);
6491
6492 for (::std::size_t i = 0; i < Destinations.size(); i++)
6493 {
6494 {
6495 const uint8_t * pSource = (uint8_t *)1908221842;
6496 const int Width = 1908221843;
6497 const int Height = 1908221844;
6498
6499 const auto pTexture = Component_t::Make(
6500 {
6501 { uT("content"), Source },
6502 { uT("width"), Width },
6503 { uT("height"), Height },
6504 { uT("destination"), Destinations[i].first },
6505 });
6506
6507 TestCall(pTexture,
6508 Source, Width, Height, i, Destinations[i].second);
6509 }
6510
6511 {
6512 const uint8_t * pSource = (uint8_t *)1908221846;
6513 const int Width = 1908221845;
6514 const int Height = 1908221847;
6515
6516 const auto pData = Component_t::Make(
6517 {
6518 { uT("kind"), uT("Texture") },
6519 { uT("content"), Source },
6520 { uT("width"), Width },
6521 { uT("height"), Height },
6522 { uT("destination"), Destinations[i].first },
6523 });
6524
6525 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
6526 Source, Width, Height, i, Destinations[i].second);
6527 }
6528 }
6529}
6530
6531// ************************************************************************** //
6532TEST_F(OpenGLShader_test, /*DISABLED_*/Test_TextureArray_Default)
6533{
6534 using GLProxy_t = ::mock::GLProxy;
6535 GLProxy_t GLProxy;
6536 GLProxy_t::GetInstance() = &GLProxy;
6537
6538 const Tested_t Example{ Data_t{} };
6539 const ITested_t & IExample = Example;
6540
6541 auto itCreator = IExample.GetCreators().find(uT("TextureArray"));
6542 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6543
6544 const ::mock::GLuint TextureId = 1812181809;
6545 const ::mock::GLint ProgramId = 1908221258;
6546 const ::mock::GLint LocationId = 1908221259;
6547
6548 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pTexture,
6549 const ::std::vector<uint8_t> & _Source, const int _Width, const int _Height)
6550 {
6551 using namespace ::testing;
6552
6553 InSequence Dummy;
6554
6555 EXPECT_CALL(GLProxy, GenTextures(1))
6556 .Times(1)
6557 .WillOnce(Return(TextureId));
6558
6559 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
6560 .Times(1);
6561
6562 EXPECT_CALL(GLProxy, TexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8,
6563 _Width, _Height, 1))
6564 .Times(1);
6565
6566 EXPECT_CALL(GLProxy, TexSubImage3D_1(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0,
6567 _Width, _Height))
6568 .Times(1);
6569
6570 EXPECT_CALL(GLProxy, TexSubImage3D_2(1, GL_RGBA,
6571 GL_UNSIGNED_BYTE, _Source))
6572 .Times(1);
6573
6574 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, 0))
6575 .Times(1);
6576
6577 EXPECT_CALL(GLProxy, GetError())
6578 .Times(1)
6579 .WillOnce(Return(GL_NO_ERROR));
6580
6581 auto Render = itCreator->second(_pTexture);
6582 ASSERT_NE(nullptr, Render);
6583
6584 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0))
6585 .Times(1);
6586
6587 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
6588 .Times(1);
6589
6590 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6591 .Times(1)
6592 .WillOnce(Return(&ProgramId));
6593
6594 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("TexDiffuse")))
6595 .Times(1)
6596 .WillOnce(Return(LocationId));
6597
6598 EXPECT_CALL(GLProxy, Uniform1i(LocationId, 0))
6599 .Times(1);
6600
6601 Render();
6602
6603 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6604 .Times(1);
6605 };
6606
6607 {
6608 ::std::vector<uint8_t> Source =
6609 {
6610 0x20, 0x06, 0x15, 0x12, 0x28,
6611 0x20, 0x06, 0x15, 0x12, 0x28,
6612 0x20, 0x06, 0x15, 0x12, 0x28,
6613 0x20, 0x06, 0x15, 0x12, 0x28,
6614 0x20, 0x06, 0x15, 0x12, 0x28,
6615 0x20, 0x06, 0x15, 0x12, 0x28,
6616 0x20, 0x06, 0x15, 0x12, 0x28,
6617 0x20, 0x06, 0x15, 0x12, 0x28,
6618 };
6619 IntroduceBufferSize(Source);
6620
6621 const int Width = 1812181807;
6622 const int Height = 1812181808;
6623
6624 const auto pTexture = Component_t::Make(
6625 {
6626 { uT("content"), ::std::vector{ Source } },
6627 { uT("width"), Width },
6628 { uT("height"), Height },
6629 });
6630
6631 TestCall(pTexture, Source, Width, Height);
6632 }
6633
6634 {
6635 ::std::vector<uint8_t> Source =
6636 {
6637 0x20, 0x06, 0x15, 0x12, 0x29,
6638 0x20, 0x06, 0x15, 0x12, 0x29,
6639 0x20, 0x06, 0x15, 0x12, 0x29,
6640 0x25, 0x04, 0x07, 0x21, 0x03,
6641 0x25, 0x04, 0x07, 0x21, 0x04,
6642 0x25, 0x04, 0x07, 0x21, 0x05,
6643 0x25, 0x04, 0x07, 0x21, 0x06
6644 };
6645 IntroduceBufferSize(Source);
6646
6647 const int Width = 1907251057;
6648 const int Height = 1907251058;
6649
6650 const auto pData = Component_t::Make(
6651 {
6652 { uT("kind"), uT("TextureArray") },
6653 { uT("content"), ::std::vector{ Source } },
6654 { uT("width"), Width },
6655 { uT("height"), Height },
6656 });
6657
6658 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
6659 Source, Width, Height);
6660 }
6661}
6662
6663// ************************************************************************** //
6664TEST_F(OpenGLShader_test, /*DISABLED_*/Test_TextureArray_NameAndIndex)
6665{
6666 using GLProxy_t = ::mock::GLProxy;
6667 GLProxy_t GLProxy;
6668 GLProxy_t::GetInstance() = &GLProxy;
6669
6670 const Tested_t Example{ Data_t{} };
6671 const ITested_t & IExample = Example;
6672
6673 auto itCreator = IExample.GetCreators().find(uT("TextureArray"));
6674 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6675
6676 const ::mock::GLuint TextureId = 1908221839;
6677 const ::mock::GLint ProgramId = 1908221840;
6678 const ::mock::GLint LocationId = 1908221841;
6679
6680 const auto TestCall = [&](
6681 const Component_t::ComponentPtr_t & _pTexture,
6682 const ::std::vector<uint8_t> & _Source,
6683 const int _Width, const int _Height,
6684 const ::std::size_t _Index,
6685 const ::std::string & _TexName)
6686 {
6687 const auto Index = static_cast<::mock::GLint>(_Index);
6688
6689 using namespace ::testing;
6690
6691 InSequence Dummy;
6692
6693 EXPECT_CALL(GLProxy, GenTextures(1))
6694 .Times(1)
6695 .WillOnce(Return(TextureId));
6696
6697 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
6698 .Times(1);
6699
6700 EXPECT_CALL(GLProxy, TexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8,
6701 _Width, _Height, 1))
6702 .Times(1);
6703
6704 EXPECT_CALL(GLProxy, TexSubImage3D_1(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0,
6705 _Width, _Height))
6706 .Times(1);
6707
6708 EXPECT_CALL(GLProxy, TexSubImage3D_2(1, GL_RGBA,
6709 GL_UNSIGNED_BYTE, _Source))
6710 .Times(1);
6711
6712 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, 0))
6713 .Times(1);
6714
6715 EXPECT_CALL(GLProxy, GetError())
6716 .Times(1)
6717 .WillOnce(Return(GL_NO_ERROR));
6718
6719 auto Render = itCreator->second(_pTexture);
6720 ASSERT_NE(nullptr, Render);
6721
6722 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
6723 .Times(1);
6724
6725 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
6726 .Times(1);
6727
6728 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6729 .Times(1)
6730 .WillOnce(Return(&ProgramId));
6731
6732 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
6733 .Times(1)
6734 .WillOnce(Return(LocationId));
6735
6736 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
6737 .Times(0);
6738
6739 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
6740 .Times(1);
6741
6742 Render();
6743
6744 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6745 .Times(1);
6746 };
6747
6748 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
6749 {
6750 { uT("TexEnvironment"), "TexEnvironment" },
6751 { uT("TexReflection"), "TexReflection" },
6752 { uT("TexBaseColor"), "TexBaseColor" },
6753 };
6754
6755 for (int Index = 0; Index < Names.size(); Index++)
6756 {
6757 ::std::vector<uint8_t> Source =
6758 {
6759 0x20, 0x06, 0x15, 0x12, 0x30,
6760 0x20, 0x06, 0x15, 0x12, 0x30,
6761 0x20, 0x06, 0x15, 0x12, 0x30,
6762 0x20, 0x06, 0x15, 0x12, 0x30,
6763 0x20, 0x06, 0x15, 0x12, 0x30,
6764 };
6765 IntroduceBufferSize(Source);
6766
6767 {
6768 const int Width = 1908221843;
6769 const int Height = 1908221844;
6770
6771 const auto pTexture = Component_t::Make(
6772 {
6773 { uT("content"), ::std::vector{ Source } },
6774 { uT("width"), Width },
6775 { uT("height"), Height },
6776 { uT("name"), Names[Index].first },
6777 { uT("index"), Index },
6778 });
6779
6780 TestCall(pTexture,
6781 Source, Width, Height, Index, Names[Index].second);
6782 }
6783
6784 {
6785 const int Width = 1908221845;
6786 const int Height = 1908221847;
6787
6788 const auto pData = Component_t::Make(
6789 {
6790 { uT("kind"), uT("TextureArray") },
6791 { uT("content"), ::std::vector{ Source } },
6792 { uT("width"), Width },
6793 { uT("height"), Height },
6794 { uT("name"), Names[Index].first },
6795 { uT("index"), Index },
6796 });
6797
6798 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
6799 Source, Width, Height, Index, Names[Index].second);
6800 }
6801
6802 {
6803 const int Width = 1908221843;
6804 const int Height = 1908221844;
6805
6806 const auto pTexture = Component_t::Make(
6807 {
6808 { uT("content"), ::std::vector{ Source } },
6809 { uT("width"), Width },
6810 { uT("height"), Height },
6811 { uT("name"), Names[Index].first },
6812 { uT("index"), Index },
6813 { uT("mipmapping"), false },
6814 });
6815
6816 TestCall(pTexture,
6817 Source, Width, Height, Index, Names[Index].second);
6818 }
6819
6820 {
6821 const int Width = 1908221845;
6822 const int Height = 1908221847;
6823
6824 const auto pData = Component_t::Make(
6825 {
6826 { uT("kind"), uT("TextureArray") },
6827 { uT("content"), ::std::vector{ Source } },
6828 { uT("width"), Width },
6829 { uT("height"), Height },
6830 { uT("name"), Names[Index].first },
6831 { uT("index"), Index },
6832 { uT("mipmapping"), false },
6833 });
6834
6835 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
6836 Source, Width, Height, Index, Names[Index].second);
6837 }
6838
6839 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
6840 {
6841 { uT("albedo"), "TexAlbedo" },
6842 { uT("metalness"), "TexMetalness" },
6843 { uT("roughness"), "TexRoughness" },
6844 { uT("normal"), "TexNormal" },
6845 { uT("occlusion"), "TexOcclusion" },
6846 //{ uT("depth"), "TexDepth" }, // другой формат
6847 };
6848
6849 for (::std::size_t i = 0; i < Destinations.size(); i++)
6850 {
6851 {
6852 const int Width = 1908221843;
6853 const int Height = 1908221844;
6854
6855 const auto pTexture = Component_t::Make(
6856 {
6857 { uT("content"), ::std::vector{ Source } },
6858 { uT("width"), Width },
6859 { uT("height"), Height },
6860 { uT("name"), Names[Index].first },
6861 { uT("index"), Index },
6862 { uT("destination"), Destinations[i].first },
6863 });
6864
6865 TestCall(pTexture,
6866 Source, Width, Height, Index, Names[Index].second);
6867 }
6868
6869 {
6870 const int Width = 1908221845;
6871 const int Height = 1908221847;
6872
6873 const auto pData = Component_t::Make(
6874 {
6875 { uT("kind"), uT("TextureArray") },
6876 { uT("content"), ::std::vector{ Source } },
6877 { uT("width"), Width },
6878 { uT("height"), Height },
6879 { uT("name"), Names[Index].first },
6880 { uT("index"), Index },
6881 { uT("destination"), Destinations[i].first },
6882 });
6883
6884 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
6885 Source, Width, Height, Index, Names[Index].second);
6886 }
6887
6888 {
6889 const int Width = 1908221843;
6890 const int Height = 1908221844;
6891
6892 const auto pTexture = Component_t::Make(
6893 {
6894 { uT("content"), ::std::vector{ Source } },
6895 { uT("width"), Width },
6896 { uT("height"), Height },
6897 { uT("name"), Names[Index].first },
6898 { uT("index"), Index },
6899 { uT("destination"), Destinations[i].first },
6900 { uT("mipmapping"), false },
6901 });
6902
6903 TestCall(pTexture,
6904 Source, Width, Height, Index, Names[Index].second);
6905 }
6906
6907 {
6908 const int Width = 1908221845;
6909 const int Height = 1908221847;
6910
6911 const auto pData = Component_t::Make(
6912 {
6913 { uT("kind"), uT("TextureArray") },
6914 { uT("content"), ::std::vector{ Source } },
6915 { uT("width"), Width },
6916 { uT("height"), Height },
6917 { uT("name"), Names[Index].first },
6918 { uT("index"), Index },
6919 { uT("destination"), Destinations[i].first },
6920 { uT("mipmapping"), false },
6921 });
6922
6923 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
6924 Source, Width, Height, Index, Names[Index].second);
6925 }
6926 }
6927 }
6928}
6929
6930// ************************************************************************** //
6931TEST_F(OpenGLShader_test, /*DISABLED_*/Test_TextureArray_Destination)
6932{
6933 using GLProxy_t = ::mock::GLProxy;
6934 GLProxy_t GLProxy;
6935 GLProxy_t::GetInstance() = &GLProxy;
6936
6937 const Tested_t Example{ Data_t{} };
6938 const ITested_t & IExample = Example;
6939
6940 auto itCreator = IExample.GetCreators().find(uT("TextureArray"));
6941 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6942
6943 const ::mock::GLuint TextureId = 1908221839;
6944 const ::mock::GLint ProgramId = 1908221840;
6945 const ::mock::GLint LocationId = 1908221841;
6946
6947 const auto TestCall = [&](
6948 const Component_t::ComponentPtr_t & _pTexture,
6949 const ::std::vector<uint8_t> & _Source,
6950 const int _Width, const int _Height,
6951 const ::std::size_t _Index,
6952 const ::std::string & _TexName)
6953 {
6954 const auto Index = static_cast<::mock::GLint>(_Index);
6955
6956 using namespace ::testing;
6957
6958 InSequence Dummy;
6959
6960 EXPECT_CALL(GLProxy, GenTextures(1))
6961 .Times(1)
6962 .WillOnce(Return(TextureId));
6963
6964 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
6965 .Times(1);
6966
6967 EXPECT_CALL(GLProxy, TexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8,
6968 _Width, _Height, 1))
6969 .Times(1);
6970
6971 EXPECT_CALL(GLProxy, TexSubImage3D_1(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0,
6972 _Width, _Height))
6973 .Times(1);
6974
6975 EXPECT_CALL(GLProxy, TexSubImage3D_2(1, GL_RGBA,
6976 GL_UNSIGNED_BYTE, _Source))
6977 .Times(1);
6978
6979 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, 0))
6980 .Times(1);
6981
6982 EXPECT_CALL(GLProxy, GetError())
6983 .Times(1)
6984 .WillOnce(Return(GL_NO_ERROR));
6985
6986 auto Render = itCreator->second(_pTexture);
6987 ASSERT_NE(nullptr, Render);
6988
6989 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
6990 .Times(1);
6991
6992 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
6993 .Times(1);
6994
6995 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6996 .Times(1)
6997 .WillOnce(Return(&ProgramId));
6998
6999 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
7000 .Times(1)
7001 .WillOnce(Return(LocationId));
7002
7003 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
7004 .Times(0);
7005
7006 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
7007 .Times(1);
7008
7009 Render();
7010
7011 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
7012 .Times(1);
7013 };
7014
7015 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
7016 {
7017 { uT("albedo"), "TexAlbedo" },
7018 { uT("metalness"), "TexMetalness" },
7019 { uT("roughness"), "TexRoughness" },
7020 { uT("normal"), "TexNormal" },
7021 { uT("occlusion"), "TexOcclusion" },
7022 //{ uT("depth"), "TexDepth" }, // другой формат
7023 };
7024
7025 ::std::vector<uint8_t> Source =
7026 {
7027 0x20, 0x06, 0x15, 0x12, 0x30,
7028 0x20, 0x06, 0x15, 0x12, 0x30,
7029 0x20, 0x06, 0x15, 0x12, 0x30,
7030 0x20, 0x06, 0x15, 0x12, 0x30,
7031 0x20, 0x06, 0x15, 0x12, 0x30,
7032 };
7033 IntroduceBufferSize(Source);
7034
7035 for (::std::size_t i = 0; i < Destinations.size(); i++)
7036 {
7037 {
7038 const int Width = 1908221843;
7039 const int Height = 1908221844;
7040
7041 const auto pTexture = Component_t::Make(
7042 {
7043 { uT("content"), ::std::vector{ Source } },
7044 { uT("width"), Width },
7045 { uT("height"), Height },
7046 { uT("destination"), Destinations[i].first },
7047 });
7048
7049 TestCall(pTexture,
7050 Source, Width, Height, i, Destinations[i].second);
7051 }
7052
7053 {
7054 const int Width = 1908221845;
7055 const int Height = 1908221847;
7056
7057 const auto pData = Component_t::Make(
7058 {
7059 { uT("kind"), uT("TextureArray") },
7060 { uT("content"), ::std::vector{ Source } },
7061 { uT("width"), Width },
7062 { uT("height"), Height },
7063 { uT("destination"), Destinations[i].first },
7064 });
7065
7066 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
7067 Source, Width, Height, i, Destinations[i].second);
7068 }
7069
7070 {
7071 const int Width = 1908221843;
7072 const int Height = 1908221844;
7073
7074 const auto pTexture = Component_t::Make(
7075 {
7076 { uT("content"), ::std::vector{ Source } },
7077 { uT("width"), Width },
7078 { uT("height"), Height },
7079 { uT("destination"), Destinations[i].first },
7080 { uT("mipmapping"), false },
7081 });
7082
7083 TestCall(pTexture,
7084 Source, Width, Height, i, Destinations[i].second);
7085 }
7086
7087 {
7088 const int Width = 1908221845;
7089 const int Height = 1908221847;
7090
7091 const auto pData = Component_t::Make(
7092 {
7093 { uT("kind"), uT("TextureArray") },
7094 { uT("content"), ::std::vector{ Source } },
7095 { uT("width"), Width },
7096 { uT("height"), Height },
7097 { uT("destination"), Destinations[i].first },
7098 { uT("mipmapping"), false },
7099 });
7100
7101 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
7102 Source, Width, Height, i, Destinations[i].second);
7103 }
7104 }
7105}
7106
7107// ************************************************************************** //
7108TEST_F(OpenGLShader_test, /*DISABLED_*/Test_TextureArray_Mipmapping_NameAndIndex)
7109{
7110 using GLProxy_t = ::mock::GLProxy;
7111 GLProxy_t GLProxy;
7112 GLProxy_t::GetInstance() = &GLProxy;
7113
7114 const Tested_t Example{ Data_t{} };
7115 const ITested_t & IExample = Example;
7116
7117 auto itCreator = IExample.GetCreators().find(uT("TextureArray"));
7118 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7119
7120 const ::mock::GLuint TextureId = 1908221839;
7121 const ::mock::GLint ProgramId = 1908221840;
7122 const ::mock::GLint LocationId = 1908221841;
7123
7124 const auto TestCall = [&](
7125 const Component_t::ComponentPtr_t & _pTexture,
7126 const ::std::vector<uint8_t> & _Source,
7127 const int _Width, const int _Height,
7128 const ::std::size_t _Index,
7129 const ::std::string & _TexName)
7130 {
7131 const auto Index = static_cast<::mock::GLint>(_Index);
7132
7133 using namespace ::testing;
7134
7135 InSequence Dummy;
7136
7137 EXPECT_CALL(GLProxy, GenTextures(1))
7138 .Times(1)
7139 .WillOnce(Return(TextureId));
7140
7141 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
7142 .Times(1);
7143
7144 EXPECT_CALL(GLProxy, TexStorage3D(GL_TEXTURE_2D_ARRAY, 8, GL_RGBA8,
7145 _Width, _Height, 1))
7146 .Times(1);
7147
7148 EXPECT_CALL(GLProxy, TexSubImage3D_1(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0,
7149 _Width, _Height))
7150 .Times(1);
7151
7152 EXPECT_CALL(GLProxy, TexSubImage3D_2(1, GL_RGBA,
7153 GL_UNSIGNED_BYTE, _Source))
7154 .Times(1);
7155
7156 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D_ARRAY))
7157 .Times(1);
7158
7159 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, 0))
7160 .Times(1);
7161
7162 EXPECT_CALL(GLProxy, GetError())
7163 .Times(1)
7164 .WillOnce(Return(GL_NO_ERROR));
7165
7166 auto Render = itCreator->second(_pTexture);
7167 ASSERT_NE(nullptr, Render);
7168
7169 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
7170 .Times(1);
7171
7172 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
7173 .Times(1);
7174
7175 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
7176 .Times(1)
7177 .WillOnce(Return(&ProgramId));
7178
7179 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
7180 .Times(1)
7181 .WillOnce(Return(LocationId));
7182
7183 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
7184 .Times(0);
7185
7186 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
7187 .Times(1);
7188
7189 Render();
7190
7191 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
7192 .Times(1);
7193 };
7194
7195 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
7196 {
7197 { uT("TexEnvironment"), "TexEnvironment" },
7198 { uT("TexReflection"), "TexReflection" },
7199 { uT("TexBaseColor"), "TexBaseColor" },
7200 };
7201
7202 for (int Index = 0; Index < Names.size(); Index++)
7203 {
7204 ::std::vector<uint8_t> Source =
7205 {
7206 0x20, 0x06, 0x15, 0x12, 0x31,
7207 0x20, 0x06, 0x15, 0x12, 0x31,
7208 0x20, 0x06, 0x15, 0x12, 0x31,
7209 0x20, 0x06, 0x15, 0x12, 0x31,
7210 0x20, 0x06, 0x15, 0x12, 0x31,
7211 };
7212 IntroduceBufferSize(Source);
7213
7214 {
7215 const int Width = 1908221843;
7216 const int Height = 1908221844;
7217
7218 const auto pTexture = Component_t::Make(
7219 {
7220 { uT("content"), ::std::vector{ Source } },
7221 { uT("width"), Width },
7222 { uT("height"), Height },
7223 { uT("name"), Names[Index].first },
7224 { uT("index"), Index },
7225 { uT("mipmapping"), true },
7226 });
7227
7228 TestCall(pTexture,
7229 Source, Width, Height, Index, Names[Index].second);
7230 }
7231
7232 {
7233 const int Width = 1908221845;
7234 const int Height = 1908221847;
7235
7236 const auto pData = Component_t::Make(
7237 {
7238 { uT("kind"), uT("TextureArray") },
7239 { uT("content"), ::std::vector{ Source } },
7240 { uT("width"), Width },
7241 { uT("height"), Height },
7242 { uT("name"), Names[Index].first },
7243 { uT("index"), Index },
7244 { uT("mipmapping"), true },
7245 });
7246
7247 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
7248 Source, Width, Height, Index, Names[Index].second);
7249 }
7250
7251 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
7252 {
7253 { uT("albedo"), "TexAlbedo" },
7254 { uT("metalness"), "TexMetalness" },
7255 { uT("roughness"), "TexRoughness" },
7256 { uT("normal"), "TexNormal" },
7257 { uT("occlusion"), "TexOcclusion" },
7258 };
7259
7260 for (::std::size_t i = 0; i < Destinations.size(); i++)
7261 {
7262 {
7263 const int Width = 1908221843;
7264 const int Height = 1908221844;
7265
7266 const auto pTexture = Component_t::Make(
7267 {
7268 { uT("content"), ::std::vector{ Source } },
7269 { uT("width"), Width },
7270 { uT("height"), Height },
7271 { uT("name"), Names[Index].first },
7272 { uT("index"), Index },
7273 { uT("destination"), Destinations[i].first },
7274 { uT("mipmapping"), true },
7275 });
7276
7277 TestCall(pTexture,
7278 Source, Width, Height, Index, Names[Index].second);
7279 }
7280
7281 {
7282 const int Width = 1908221845;
7283 const int Height = 1908221847;
7284
7285 const auto pData = Component_t::Make(
7286 {
7287 { uT("kind"), uT("TextureArray") },
7288 { uT("content"), ::std::vector{ Source } },
7289 { uT("width"), Width },
7290 { uT("height"), Height },
7291 { uT("name"), Names[Index].first },
7292 { uT("index"), Index },
7293 { uT("destination"), Destinations[i].first },
7294 { uT("mipmapping"), true },
7295 });
7296
7297 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
7298 Source, Width, Height, Index, Names[Index].second);
7299 }
7300 }
7301 }
7302}
7303
7304// ************************************************************************** //
7305TEST_F(OpenGLShader_test, /*DISABLED_*/Test_TextureArray_Mipmapping_Destination)
7306{
7307 using GLProxy_t = ::mock::GLProxy;
7308 GLProxy_t GLProxy;
7309 GLProxy_t::GetInstance() = &GLProxy;
7310
7311 const Tested_t Example{ Data_t{} };
7312 const ITested_t & IExample = Example;
7313
7314 auto itCreator = IExample.GetCreators().find(uT("TextureArray"));
7315 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7316
7317 const ::mock::GLuint TextureId = 1908221839;
7318 const ::mock::GLint ProgramId = 1908221840;
7319 const ::mock::GLint LocationId = 1908221841;
7320
7321 const auto TestCall = [&](
7322 const Component_t::ComponentPtr_t & _pTexture,
7323 const ::std::vector<uint8_t> & _Source,
7324 const int _Width, const int _Height,
7325 const ::std::size_t _Index,
7326 const ::std::string & _TexName)
7327 {
7328 const auto Index = static_cast<::mock::GLint>(_Index);
7329
7330 using namespace ::testing;
7331
7332 InSequence Dummy;
7333
7334 EXPECT_CALL(GLProxy, GenTextures(1))
7335 .Times(1)
7336 .WillOnce(Return(TextureId));
7337
7338 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
7339 .Times(1);
7340
7341 EXPECT_CALL(GLProxy, TexStorage3D(GL_TEXTURE_2D_ARRAY, 8, GL_RGBA8,
7342 _Width, _Height, 1))
7343 .Times(1);
7344
7345 EXPECT_CALL(GLProxy, TexSubImage3D_1(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0,
7346 _Width, _Height))
7347 .Times(1);
7348
7349 EXPECT_CALL(GLProxy, TexSubImage3D_2(1, GL_RGBA,
7350 GL_UNSIGNED_BYTE, _Source))
7351 .Times(1);
7352
7353 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D_ARRAY))
7354 .Times(1);
7355
7356 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, 0))
7357 .Times(1);
7358
7359 EXPECT_CALL(GLProxy, GetError())
7360 .Times(1)
7361 .WillOnce(Return(GL_NO_ERROR));
7362
7363 auto Render = itCreator->second(_pTexture);
7364 ASSERT_NE(nullptr, Render);
7365
7366 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
7367 .Times(1);
7368
7369 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
7370 .Times(1);
7371
7372 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
7373 .Times(1)
7374 .WillOnce(Return(&ProgramId));
7375
7376 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
7377 .Times(1)
7378 .WillOnce(Return(LocationId));
7379
7380 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq("TexDiffuse")))
7381 .Times(0);
7382
7383 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
7384 .Times(1);
7385
7386 Render();
7387
7388 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
7389 .Times(1);
7390 };
7391
7392 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
7393 {
7394 { uT("albedo"), "TexAlbedo" },
7395 { uT("metalness"), "TexMetalness" },
7396 { uT("roughness"), "TexRoughness" },
7397 { uT("normal"), "TexNormal" },
7398 { uT("occlusion"), "TexOcclusion" },
7399 };
7400
7401 ::std::vector<uint8_t> Source =
7402 {
7403 0x20, 0x06, 0x15, 0x12, 0x31,
7404 0x20, 0x06, 0x15, 0x12, 0x31,
7405 0x20, 0x06, 0x15, 0x12, 0x31,
7406 0x20, 0x06, 0x15, 0x12, 0x31,
7407 0x20, 0x06, 0x15, 0x12, 0x31,
7408 };
7409 IntroduceBufferSize(Source);
7410
7411 for (::std::size_t i = 0; i < Destinations.size(); i++)
7412 {
7413 {
7414 const int Width = 1908221843;
7415 const int Height = 1908221844;
7416
7417 const auto pTexture = Component_t::Make(
7418 {
7419 { uT("content"), ::std::vector{ Source } },
7420 { uT("width"), Width },
7421 { uT("height"), Height },
7422 { uT("destination"), Destinations[i].first },
7423 { uT("mipmapping"), true },
7424 });
7425
7426 TestCall(pTexture,
7427 Source, Width, Height, i, Destinations[i].second);
7428 }
7429
7430 {
7431 const int Width = 1908221845;
7432 const int Height = 1908221847;
7433
7434 const auto pData = Component_t::Make(
7435 {
7436 { uT("kind"), uT("TextureArray") },
7437 { uT("content"), ::std::vector{ Source } },
7438 { uT("width"), Width },
7439 { uT("height"), Height },
7440 { uT("destination"), Destinations[i].first },
7441 { uT("mipmapping"), true },
7442 });
7443
7444 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
7445 Source, Width, Height, i, Destinations[i].second);
7446 }
7447 }
7448}
7449
7450// ************************************************************************** //
7451TEST_F(OpenGLShader_test, /*DISABLED_*/Test_TextureArray_NoDeclaredInShader)
7452{
7453 using GLProxy_t = ::mock::GLProxy;
7454 GLProxy_t GLProxy;
7455 GLProxy_t::GetInstance() = &GLProxy;
7456
7457 const Tested_t Example{ Data_t{} };
7458 const ITested_t & IExample = Example;
7459
7460 auto itCreator = IExample.GetCreators().find(uT("TextureArray"));
7461 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7462
7463 const ::mock::GLuint TextureId = 1908221839;
7464
7465 const auto TestCall = [&](
7466 const Component_t::ComponentPtr_t & _pTexture,
7467 const ::std::vector<uint8_t> & /*_Source*/,
7468 const int /*_Width*/, const int /*_Height*/,
7469 const ::std::size_t _Index,
7470 const ::std::string & _TexName)
7471 {
7472 const auto Index = static_cast<::mock::GLint>(_Index);
7473
7474 using namespace ::testing;
7475
7476 InSequence Dummy;
7477
7478 EXPECT_CALL(GLProxy, GenTextures(1))
7479 .Times(1)
7480 .WillOnce(Return(TextureId));
7481
7482 auto Render = itCreator->second(_pTexture);
7483 ASSERT_NE(nullptr, Render);
7484
7485 EXPECT_CALL(GLProxy, GetUniformLocation(_, _TexName))
7486 .Times(1)
7487 .WillOnce(Return(-1));
7488
7489 EXPECT_CALL(GLProxy, Uniform1i(_, _))
7490 .Times(0);
7491
7492 Render();
7493
7494 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
7495 .Times(1);
7496 };
7497
7498 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
7499 {
7500 { uT("albedo"), "TexAlbedo" },
7501 { uT("metalness"), "TexMetalness" },
7502 { uT("roughness"), "TexRoughness" },
7503 { uT("normal"), "TexNormal" },
7504 { uT("occlusion"), "TexOcclusion" },
7505 { uT("depth"), "TexDepth" },
7506 };
7507
7508 ::std::vector<uint8_t> Source =
7509 {
7510 0x20, 0x06, 0x15, 0x12, 0x34,
7511 0x20, 0x06, 0x15, 0x12, 0x34,
7512 0x20, 0x06, 0x15, 0x12, 0x34,
7513 0x20, 0x06, 0x15, 0x12, 0x34,
7514 0x20, 0x06, 0x15, 0x12, 0x34,
7515 };
7516 IntroduceBufferSize(Source);
7517
7518 for (::std::size_t i = 0; i < Destinations.size(); i++)
7519 {
7520 {
7521 const uint8_t * pSource = (uint8_t *)1908221842;
7522 const int Width = 1908221843;
7523 const int Height = 1908221844;
7524
7525 const auto pTexture = Component_t::Make(
7526 {
7527 { uT("content"), ::std::vector{ Source } },
7528 { uT("width"), Width },
7529 { uT("height"), Height },
7530 { uT("destination"), Destinations[i].first },
7531 });
7532
7533 TestCall(pTexture,
7534 Source, Width, Height, i, Destinations[i].second);
7535 }
7536
7537 {
7538 const uint8_t * pSource = (uint8_t *)1908221846;
7539 const int Width = 1908221845;
7540 const int Height = 1908221847;
7541
7542 const auto pData = Component_t::Make(
7543 {
7544 { uT("kind"), uT("TextureArray") },
7545 { uT("content"), ::std::vector{ Source } },
7546 { uT("width"), Width },
7547 { uT("height"), Height },
7548 { uT("destination"), Destinations[i].first },
7549 });
7550
7551 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
7552 Source, Width, Height, i, Destinations[i].second);
7553 }
7554 }
7555}
7556
7557// ************************************************************************** //
7558TEST_F(OpenGLShader_test, /*DISABLED_*/Test_TextureArray_MultiTextureData)
7559{
7560 using namespace ::alicorn::extension::std;
7561
7562 using GLProxy_t = ::mock::GLProxy;
7563 GLProxy_t GLProxy;
7564 GLProxy_t::GetInstance() = &GLProxy;
7565
7566 const Tested_t Example{ Data_t{} };
7567 const ITested_t & IExample = Example;
7568
7569 auto itCreator = IExample.GetCreators().find(uT("TextureArray"));
7570 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7571
7572 const ::mock::GLuint TextureId = 1812181809;
7573 const ::mock::GLint ProgramId = 1908221258;
7574 const ::mock::GLint LocationId = 1908221259;
7575
7576 const auto TestCall = [&](const Component_t::ComponentPtr_t & _pTexture,
7577 const ::std::vector<uint8_t> & _Source, const size_t _ArrayCount,
7578 const int _Width, const int _Height)
7579 {
7580 using namespace ::testing;
7581
7582 InSequence Dummy;
7583
7584 EXPECT_CALL(GLProxy, GenTextures(1))
7585 .Times(1)
7586 .WillOnce(Return(TextureId));
7587
7588 EXPECT_CALL(GLProxy, BindTexture(_, _))
7589 .Times(1);
7590
7591 EXPECT_CALL(GLProxy, TexStorage3D(_, _, _, _, _, _ArrayCount))
7592 .Times(1);
7593
7594 EXPECT_CALL(GLProxy, TexSubImage3D_1(_, 0, 0, 0, 0, _, _))
7595 .Times(1);
7596
7597 EXPECT_CALL(GLProxy, TexSubImage3D_2(_ArrayCount, _, _, _Source))
7598 .Times(1);
7599
7600 EXPECT_CALL(GLProxy, BindTexture(_, 0))
7601 .Times(1);
7602
7603 EXPECT_CALL(GLProxy, GetError())
7604 .Times(1)
7605 .WillOnce(Return(GL_NO_ERROR));
7606
7607 auto Render = itCreator->second(_pTexture);
7608 ASSERT_NE(nullptr, Render);
7609 };
7610
7611 {
7612 ::std::vector<uint8_t> Source1 =
7613 {
7614 0x20, 0x06, 0x15, 0x12, 0x28,
7615 0x20, 0x06, 0x15, 0x12, 0x28,
7616 0x20, 0x06, 0x15, 0x12, 0x28,
7617 0x20, 0x06, 0x15, 0x12, 0x28,
7618 0x20, 0x06, 0x15, 0x12, 0x28,
7619 };
7620 IntroduceBufferSize(Source1, false);
7621
7622 ::std::vector<uint8_t> Source2 =
7623 {
7624 0x20, 0x06, 0x15, 0x12, 0x28,
7625 0x20, 0x06, 0x15, 0x12, 0x28,
7626 0x20, 0x06, 0x15, 0x12, 0x28,
7627 0x20, 0x06, 0x15, 0x12, 0x28,
7628 0x20, 0x06, 0x15, 0x12, 0x28,
7629 0x20, 0x06, 0x15, 0x12, 0x28,
7630 };
7631 IntroduceBufferSize(Source2, false);
7632
7633 ::std::vector<uint8_t> Source3 =
7634 {
7635 0x20, 0x06, 0x15, 0x12, 0x28,
7636 0x20, 0x06, 0x15, 0x12, 0x28,
7637 0x20, 0x06, 0x15, 0x12, 0x28,
7638 0x20, 0x06, 0x15, 0x12, 0x28,
7639 0x20, 0x06, 0x15, 0x12, 0x28,
7640 0x20, 0x06, 0x15, 0x12, 0x28,
7641 0x20, 0x06, 0x15, 0x12, 0x28,
7642 0x20, 0x06, 0x15, 0x12, 0x28,
7643 };
7644 IntroduceBufferSize(Source3);
7645
7646 const int Width = 1812181807;
7647 const int Height = 1812181808;
7648
7649 const auto pTexture = Component_t::Make(
7650 {
7651 { uT("content"), ::std::vector{ Source1, Source2, Source3 } },
7652 { uT("width"), Width },
7653 { uT("height"), Height },
7654 });
7655
7656 TestCall(pTexture, Source1 + Source2 + Source3, 3, Width, Height);
7657 }
7658
7659 {
7660 ::std::vector<uint8_t> Source1 =
7661 {
7662 0x20, 0x06, 0x15, 0x12, 0x29,
7663 0x20, 0x06, 0x15, 0x12, 0x29,
7664 0x20, 0x06, 0x15, 0x12, 0x29,
7665 };
7666 IntroduceBufferSize(Source1, false);
7667
7668 ::std::vector<uint8_t> Source2 =
7669 {
7670 0x25, 0x04, 0x07, 0x21, 0x03,
7671 0x25, 0x04, 0x07, 0x21, 0x04,
7672 0x25, 0x04, 0x07, 0x21, 0x05,
7673 0x25, 0x04, 0x07, 0x21, 0x06
7674 };
7675 IntroduceBufferSize(Source2, true);
7676
7677 const int Width = 1907251057;
7678 const int Height = 1907251058;
7679
7680 const auto pData = Component_t::Make(
7681 {
7682 { uT("kind"), uT("TextureArray") },
7683 { uT("content"), ::std::vector{ Source1, Source2 } },
7684 { uT("width"), Width },
7685 { uT("height"), Height },
7686 });
7687
7688 TestCall(Component_t::Make({ { uT("service"), Object_t{ pData } } }),
7689 Source1 + Source2, 2, Width, Height);
7690 }
7691}
7692
7693// ************************************************************************** //
7694TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Buffer_Fail)
7695{
7696 using GLProxy_t = ::mock::GLProxy;
7697 GLProxy_t GLProxy;
7698 GLProxy_t::GetInstance() = &GLProxy;
7699
7700 const Tested_t Example{ Data_t{} };
7701 const ITested_t & IExample = Example;
7702
7703 auto itCreator = IExample.GetCreators().find(uT("Buffer"));
7704 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7705
7706 auto TestCallRender = [&](const Component_t::ComponentPtr_t & _pComponent)
7707 {
7708 using namespace ::testing;
7709
7710 InSequence Dummy;
7711
7712 EXPECT_CALL(GLProxy, GenBuffers(_))
7713 .Times(1);
7714
7715 EXPECT_CALL(GLProxy, GetError())
7716 .Times(1)
7717 .WillOnce(Return(1908232144));
7718
7719 EXPECT_THROW(itCreator->second(_pComponent), ::std::exception);
7720 };
7721
7722 {
7723 const ::std::vector<::covellite::api::Vertex> Source;
7724
7725 const auto pBuffer = Component_t::Make(
7726 {
7727 { uT("content"), Source },
7728 });
7729
7730 TestCallRender(pBuffer);
7731
7732 const auto pData = Component_t::Make(
7733 {
7734 { uT("kind"), uT("Buffer") },
7735 { uT("content"), Source },
7736 });
7737
7738 TestCallRender(Component_t::Make({ { uT("service"), Object_t{ pData } } }));
7739 }
7740
7741 {
7742 using BufferMapper_t =
7743 ::covellite::api::cbBufferMap_t<::covellite::api::Vertex>;
7744 const ::std::vector<::covellite::api::Vertex> Source;
7745
7746 BufferMapper_t Mapper = [](::covellite::api::Vertex *) { return false; };
7747
7748 const auto pBuffer = Component_t::Make(
7749 {
7750 { uT("content"), Source },
7751 { uT("mapper"), Mapper },
7752 });
7753
7754 TestCallRender(pBuffer);
7755
7756 const auto pData = Component_t::Make(
7757 {
7758 { uT("kind"), uT("Buffer") },
7759 { uT("content"), Source },
7760 { uT("mapper"), Mapper },
7761 });
7762
7763 TestCallRender(Component_t::Make({ { uT("service"), Object_t{ pData } } }));
7764 }
7765}
7766
7767// ************************************************************************** //
7768TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Buffer_Vertex_Static)
7769{
7770 using Vertex_t = ::covellite::api::Vertex;
7771
7772 using GLProxy_t = ::mock::GLProxy;
7773 GLProxy_t GLProxy;
7774 GLProxy_t::GetInstance() = &GLProxy;
7775
7776 const ::mock::GLuint BufferId = 1908231206;
7777 const ::mock::GLint ProgramId = 1908231246;
7778 const ::mock::GLint PositionId = 1908231301;
7779 const ::mock::GLint TexCoordId = 1908231302;
7780 const ::mock::GLint ExtraId = 1908231304;
7781
7782 ::std::vector<Vertex_t> Source =
7783 {
7784 {
7785 1808261932.0f, 1808261933.0f, 1812161256.0f, 1808261934.0f,
7786 1812161257.0f, 1808261935.0f,
7787 1808261936.0f, 1812161258.0f, 1908201939.0f, 1908201940.0f
7788 },
7789 {
7790 1808261932.0f, 1808261933.0f, 1812161259.0f, 1808261934.0f,
7791 1812161300.0f, 1808261935.0f,
7792 1808261936.0f, 1812161301.0f, 1908201941.0f, 1908201942.0f
7793 },
7794 { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, // Маркер конца данных
7795 };
7796
7797 IntroduceBufferSize(Source);
7798
7799 const ::mock::GLProxy::Floats_t ExpectedVertexData =
7800 {
7801 Source[0].px, Source[0].py, Source[0].pz,
7802 Source[1].px, Source[1].py, Source[1].pz,
7803 };
7804
7805 const ::mock::GLProxy::Floats_t ExpectedTexCoordData =
7806 {
7807 Source[0].tu, Source[0].tv,
7808 Source[1].tu, Source[1].tv,
7809 };
7810
7811 const ::mock::GLProxy::Floats_t ExpectedNormalData =
7812 {
7813 Source[0].ex, Source[0].ey, Source[0].ez,
7814 Source[1].ex, Source[1].ey, Source[1].ez,
7815 };
7816
7817 const Tested_t Example{ Data_t{} };
7818 const ITested_t & IExample = Example;
7819
7820 auto itCreator = IExample.GetCreators().find(uT("Buffer"));
7821 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7822
7823 auto TestCallRender = [&](const Component_t::ComponentPtr_t & _pComponent)
7824 {
7825 using namespace ::testing;
7826
7827 InSequence Dummy;
7828
7829 EXPECT_CALL(GLProxy, GenBuffers(1))
7830 .Times(1)
7831 .WillOnce(Return(BufferId));
7832
7833 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
7834 .Times(1);
7835
7836 const auto Size =
7837 static_cast<::mock::GLsizeiptr>(Source.size() * sizeof(Vertex_t));
7838
7839 EXPECT_CALL(GLProxy, BufferData(GL_ARRAY_BUFFER, Size,
7840 GetExpected(Source), GL_STATIC_DRAW))
7841 .Times(1);
7842
7843 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
7844 .Times(1);
7845
7846 EXPECT_CALL(GLProxy, GetError())
7847 .Times(1)
7848 .WillOnce(Return(GL_NO_ERROR));
7849
7850 const auto Render = itCreator->second(_pComponent);
7851 ASSERT_NE(nullptr, Render);
7852
7853 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
7854 .Times(1);
7855
7856 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
7857 .Times(1)
7858 .WillOnce(Return(&ProgramId));
7859
7860 EXPECT_CALL(GLProxy,
7861 GetAttribLocation(ProgramId, Eq("Covellite_VertexPosition")))
7862 .Times(1)
7863 .WillOnce(Return(PositionId));
7864
7865 EXPECT_CALL(GLProxy, EnableVertexAttribArray(PositionId))
7866 .Times(1);
7867
7868 EXPECT_CALL(GLProxy, VertexAttribPointer(PositionId, 4, GL_FLOAT, GL_FALSE,
7869 sizeof(Vertex_t), (void*)0))
7870 .Times(1);
7871
7872 EXPECT_CALL(GLProxy, VertexAttribDivisor(PositionId, 0))
7873 .Times(1);
7874
7875 EXPECT_CALL(GLProxy,
7876 GetAttribLocation(ProgramId, Eq("Covellite_VertexTexCoord")))
7877 .Times(1)
7878 .WillOnce(Return(TexCoordId));
7879
7880 EXPECT_CALL(GLProxy, EnableVertexAttribArray(TexCoordId))
7881 .Times(1);
7882
7883 EXPECT_CALL(GLProxy, VertexAttribPointer(TexCoordId, 2, GL_FLOAT, GL_FALSE,
7884 sizeof(Vertex_t), (void*)(sizeof(float) * 4)))
7885 .Times(1);
7886
7887 EXPECT_CALL(GLProxy, VertexAttribDivisor(TexCoordId, 0))
7888 .Times(1);
7889
7890 EXPECT_CALL(GLProxy,
7891 GetAttribLocation(ProgramId, Eq("Covellite_VertexExtra")))
7892 .Times(1)
7893 .WillOnce(Return(ExtraId));
7894
7895 EXPECT_CALL(GLProxy, EnableVertexAttribArray(ExtraId))
7896 .Times(1);
7897
7898 EXPECT_CALL(GLProxy, VertexAttribPointer(ExtraId, 4, GL_FLOAT, GL_FALSE,
7899 sizeof(Vertex_t), (void*)(sizeof(float) * 6)))
7900 .Times(1);
7901
7902 EXPECT_CALL(GLProxy, VertexAttribDivisor(ExtraId, 0))
7903 .Times(1);
7904
7905 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
7906 .Times(1);
7907
7908 Render();
7909
7910 EXPECT_CALL(GLProxy, DeleteBuffers(1, BufferId))
7911 .Times(1);
7912 };
7913
7914 // ***************** Передача данных в объекте компонента ***************** //
7915
7916 {
7917 const auto pBuffer = Component_t::Make(
7918 {
7919 { uT("content"), Source },
7920 });
7921
7922 TestCallRender(pBuffer);
7923 }
7924
7925 // ************** Передача данных в объекте компонента Data *************** //
7926
7927 {
7928 const auto pData = Component_t::Make(
7929 {
7930 { uT("kind"), uT("Buffer") },
7931 { uT("content"), Source },
7932 });
7933
7934 TestCallRender(Component_t::Make({ { uT("service"), Object_t{ pData } } }));
7935 }
7936}
7937
7938// ************************************************************************** //
7939TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Buffer_Vertex_Dynamic)
7940{
7941 using Vertex_t = ::covellite::api::Vertex;
7942 using BufferMapper_t = ::covellite::api::cbBufferMap_t<Vertex_t>;
7943
7944 class Proxy :
7945 public ::alicorn::extension::testing::Proxy<Proxy>
7946 {
7947 public:
7948 MOCK_METHOD1(Mapper, bool(Vertex_t *));
7949 };
7950
7951 Proxy oProxy;
7952 Proxy::GetInstance() = &oProxy;
7953
7954 using GLProxy_t = ::mock::GLProxy;
7955 GLProxy_t GLProxy;
7956 GLProxy_t::GetInstance() = &GLProxy;
7957
7958 const ::mock::GLuint BufferId = 1908232202;
7959 const ::mock::GLint ProgramId = 1908232203;
7960 const ::mock::GLint PositionId = 1908232204;
7961 const ::mock::GLint TexCoordId = 1908232205;
7962 const ::mock::GLint ExtraId = 1908232206;
7963
7964 ::std::vector<Vertex_t> Source1 =
7965 {
7966 {
7967 1808261932.0f, 1808261933.0f, 1812161256.0f, 1808261934.0f,
7968 1812161257.0f, 1808261935.0f,
7969 1808261936.0f, 1812161258.0f, 1908201945.0f, 1908201946.0f
7970 },
7971 {
7972 1808261932.0f, 1808261933.0f, 1812161259.0f, 1808261934.0f,
7973 1812161300.0f, 1808261935.0f,
7974 1808261936.0f, 1812161301.0f, 1908201947.0f, 1908201948.0f
7975 },
7976 { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, // Маркер конца данных
7977 };
7978
7979 IntroduceBufferSize(Source1);
7980
7981 const ::std::vector<::mock::GLfloat> Source2 =
7982 {
7983 1908011341.0f, 1908261933.0f, 1912161256.0f, 1908261934.0f,
7984 1912161257.0f, 1908261935.0f,
7985 1908261936.0f, 1912161258.0f, 1908201949.0f, 1908201950.0f,
7986 1908261932.0f, 1908261933.0f, 1912161259.0f, 1908261934.0f,
7987 1912161300.0f, 1908261935.0f,
7988 1908261936.0f, 1912161301.0f, 1908201951.0f, 1908201952.0f,
7989 };
7990
7991 const BufferMapper_t Mapper = [&](Vertex_t * _pData)
7992 {
7993 if (_pData != nullptr)
7994 {
7995 memcpy(_pData, Source2.data(), sizeof(::mock::GLfloat) * Source2.size());
7996 }
7997
7998 return oProxy.Mapper(_pData);
7999 };
8000
8001 const Tested_t Example{ Data_t{} };
8002 const ITested_t & IExample = Example;
8003
8004 auto itCreator = IExample.GetCreators().find(uT("Buffer"));
8005 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8006
8007 auto TestCallRender = [&](const Component_t::ComponentPtr_t & _pComponent)
8008 {
8009 using namespace ::testing;
8010
8011 InSequence Dummy;
8012
8013 EXPECT_CALL(GLProxy, GenBuffers(1))
8014 .Times(1)
8015 .WillOnce(Return(BufferId));
8016
8017 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
8018 .Times(1);
8019
8020 const auto Size =
8021 static_cast<::mock::GLsizeiptr>(Source1.size() * sizeof(Vertex_t));
8022
8023 EXPECT_CALL(GLProxy, BufferData(GL_ARRAY_BUFFER, Size,
8024 GetExpected(Source1), GL_DYNAMIC_DRAW))
8025 .Times(1);
8026
8027 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
8028 .Times(1);
8029
8030 EXPECT_CALL(GLProxy, GetError())
8031 .Times(1)
8032 .WillOnce(Return(GL_NO_ERROR));
8033
8034 const auto Render = itCreator->second(_pComponent);
8035 ASSERT_NE(nullptr, Render);
8036
8037 {
8038 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
8039 .Times(1);
8040
8041 EXPECT_CALL(oProxy, Mapper(nullptr))
8042 .Times(1)
8043 .WillOnce(Return(false));
8044
8045 EXPECT_CALL(oProxy, Mapper(_))
8046 .Times(0);
8047
8048 EXPECT_CALL(GLProxy, BufferSubData(_, _, _, _))
8049 .Times(0);
8050
8051 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8052 .Times(1)
8053 .WillOnce(Return(&ProgramId));
8054
8055 EXPECT_CALL(GLProxy,
8056 GetAttribLocation(ProgramId, Eq("Covellite_VertexPosition")))
8057 .Times(1)
8058 .WillOnce(Return(PositionId));
8059
8060 EXPECT_CALL(GLProxy, EnableVertexAttribArray(PositionId))
8061 .Times(1);
8062
8063 EXPECT_CALL(GLProxy, VertexAttribPointer(PositionId, 4, GL_FLOAT, GL_FALSE,
8064 sizeof(Vertex_t), (void*)0))
8065 .Times(1);
8066
8067 EXPECT_CALL(GLProxy, VertexAttribDivisor(PositionId, 0))
8068 .Times(1);
8069
8070 EXPECT_CALL(GLProxy,
8071 GetAttribLocation(ProgramId, Eq("Covellite_VertexTexCoord")))
8072 .Times(1)
8073 .WillOnce(Return(TexCoordId));
8074
8075 EXPECT_CALL(GLProxy, EnableVertexAttribArray(TexCoordId))
8076 .Times(1);
8077
8078 EXPECT_CALL(GLProxy, VertexAttribPointer(TexCoordId, 2, GL_FLOAT, GL_FALSE,
8079 sizeof(Vertex_t), (void*)(sizeof(float) * 4)))
8080 .Times(1);
8081
8082 EXPECT_CALL(GLProxy, VertexAttribDivisor(TexCoordId, 0))
8083 .Times(1);
8084
8085 EXPECT_CALL(GLProxy,
8086 GetAttribLocation(ProgramId, Eq("Covellite_VertexExtra")))
8087 .Times(1)
8088 .WillOnce(Return(ExtraId));
8089
8090 EXPECT_CALL(GLProxy, EnableVertexAttribArray(ExtraId))
8091 .Times(1);
8092
8093 EXPECT_CALL(GLProxy, VertexAttribPointer(ExtraId, 4, GL_FLOAT, GL_FALSE,
8094 sizeof(Vertex_t), (void*)(sizeof(float) * 6)))
8095 .Times(1);
8096
8097 EXPECT_CALL(GLProxy, VertexAttribDivisor(ExtraId, 0))
8098 .Times(1);
8099
8100 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
8101 .Times(1);
8102
8103 Render();
8104 }
8105
8106 {
8107 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
8108 .Times(1);
8109
8110 EXPECT_CALL(oProxy, Mapper(nullptr))
8111 .Times(1)
8112 .WillOnce(Return(true));
8113
8114 EXPECT_CALL(oProxy, Mapper(_))
8115 .Times(1);
8116
8117 EXPECT_CALL(GLProxy, BufferSubData(GL_ARRAY_BUFFER, 0, Size, Source2))
8118 .Times(1);
8119
8120 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8121 .Times(1)
8122 .WillOnce(Return(&ProgramId));
8123
8124 EXPECT_CALL(GLProxy,
8125 GetAttribLocation(ProgramId, Eq("Covellite_VertexPosition")))
8126 .Times(1)
8127 .WillOnce(Return(PositionId));
8128
8129 EXPECT_CALL(GLProxy, EnableVertexAttribArray(PositionId))
8130 .Times(1);
8131
8132 EXPECT_CALL(GLProxy, VertexAttribPointer(PositionId, 4, GL_FLOAT, GL_FALSE,
8133 sizeof(Vertex_t), (void*)0))
8134 .Times(1);
8135
8136 EXPECT_CALL(GLProxy, VertexAttribDivisor(PositionId, 0))
8137 .Times(1);
8138
8139 EXPECT_CALL(GLProxy,
8140 GetAttribLocation(ProgramId, Eq("Covellite_VertexTexCoord")))
8141 .Times(1)
8142 .WillOnce(Return(TexCoordId));
8143
8144 EXPECT_CALL(GLProxy, EnableVertexAttribArray(TexCoordId))
8145 .Times(1);
8146
8147 EXPECT_CALL(GLProxy, VertexAttribPointer(TexCoordId, 2, GL_FLOAT, GL_FALSE,
8148 sizeof(Vertex_t), (void*)(sizeof(float) * 4)))
8149 .Times(1);
8150
8151 EXPECT_CALL(GLProxy, VertexAttribDivisor(TexCoordId, 0))
8152 .Times(1);
8153
8154 EXPECT_CALL(GLProxy,
8155 GetAttribLocation(ProgramId, Eq("Covellite_VertexExtra")))
8156 .Times(1)
8157 .WillOnce(Return(ExtraId));
8158
8159 EXPECT_CALL(GLProxy, EnableVertexAttribArray(ExtraId))
8160 .Times(1);
8161
8162 EXPECT_CALL(GLProxy, VertexAttribPointer(ExtraId, 4, GL_FLOAT, GL_FALSE,
8163 sizeof(Vertex_t), (void*)(sizeof(float) * 6)))
8164 .Times(1);
8165
8166 EXPECT_CALL(GLProxy, VertexAttribDivisor(ExtraId, 0))
8167 .Times(1);
8168
8169 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
8170 .Times(1);
8171
8172 Render();
8173 }
8174
8175 EXPECT_CALL(GLProxy, DeleteBuffers(1, BufferId))
8176 .Times(1);
8177 };
8178
8179 // ***************** Передача данных в объекте компонента ***************** //
8180
8181 {
8182 const auto pBuffer = Component_t::Make(
8183 {
8184 { uT("content"), Source1 },
8185 { uT("mapper"), Mapper },
8186 });
8187
8188 TestCallRender(pBuffer);
8189 }
8190
8191 // ************** Передача данных в объекте компонента Data *************** //
8192
8193 {
8194 const auto pData = Component_t::Make(
8195 {
8196 { uT("kind"), uT("Buffer") },
8197 { uT("content"), Source1 },
8198 });
8199
8200 const auto pBuffer = Component_t::Make(
8201 {
8202 { uT("mapper"), Mapper },
8203 { uT("service"), Object_t{ pData } }
8204 });
8205
8206 TestCallRender(pBuffer);
8207 }
8208}
8209
8210// ************************************************************************** //
8211TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Buffer_Vertex_IgnoreNotExistsVariables)
8212{
8213 using Vertex_t = ::covellite::api::Vertex;
8214 using BufferMapper_t = ::covellite::api::cbBufferMap_t<Vertex_t>;
8215
8216 using GLProxy_t = ::mock::GLProxy;
8217 GLProxy_t GLProxy;
8218 GLProxy_t::GetInstance() = &GLProxy;
8219
8220 const ::mock::GLuint BufferId = 1908231206;
8221 const ::mock::GLint ProgramId = 1908231246;
8222
8223 ::std::vector<Vertex_t> Source =
8224 {
8225 {
8226 1808261932.0f, 1808261933.0f, 1812161256.0f, 1808261934.0f,
8227 1812161257.0f, 1808261935.0f,
8228 1808261936.0f, 1812161258.0f, 1908201939.0f, 1908201940.0f
8229 },
8230 {
8231 1808261932.0f, 1808261933.0f, 1812161259.0f, 1808261934.0f,
8232 1812161300.0f, 1808261935.0f,
8233 1808261936.0f, 1812161301.0f, 1908201941.0f, 1908201942.0f
8234 },
8235 { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, // Маркер конца данных
8236 };
8237
8238 IntroduceBufferSize(Source);
8239
8240 const Tested_t Example{ Data_t{} };
8241 const ITested_t & IExample = Example;
8242
8243 auto itCreator = IExample.GetCreators().find(uT("Buffer"));
8244 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8245
8246 auto TestCallRender = [&](const Component_t::ComponentPtr_t & _pComponent)
8247 {
8248 using namespace ::testing;
8249
8250 InSequence Dummy;
8251
8252 EXPECT_CALL(GLProxy, GenBuffers(1))
8253 .Times(1)
8254 .WillOnce(Return(BufferId));
8255
8256 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
8257 .Times(1);
8258
8259 EXPECT_CALL(GLProxy, BufferData(GL_ARRAY_BUFFER, _, _, _))
8260 .Times(1);
8261
8262 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
8263 .Times(1);
8264
8265 EXPECT_CALL(GLProxy, GetError())
8266 .Times(1)
8267 .WillOnce(Return(GL_NO_ERROR));
8268
8269 const auto Render = itCreator->second(_pComponent);
8270 ASSERT_NE(nullptr, Render);
8271
8272 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
8273 .Times(1);
8274
8275 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8276 .Times(1)
8277 .WillOnce(Return(&ProgramId));
8278
8279 EXPECT_CALL(GLProxy,
8280 GetAttribLocation(ProgramId, Eq("Covellite_VertexPosition")))
8281 .Times(1)
8282 .WillOnce(Return(-1));
8283
8284 EXPECT_CALL(GLProxy, EnableVertexAttribArray(_))
8285 .Times(0);
8286
8287 EXPECT_CALL(GLProxy, VertexAttribPointer(_, _, _, _, _, _))
8288 .Times(0);
8289
8290 EXPECT_CALL(GLProxy, VertexAttribDivisor(_, _))
8291 .Times(0);
8292
8293 EXPECT_CALL(GLProxy,
8294 GetAttribLocation(ProgramId, Eq("Covellite_VertexTexCoord")))
8295 .Times(1)
8296 .WillOnce(Return(-1));
8297
8298 EXPECT_CALL(GLProxy, EnableVertexAttribArray(_))
8299 .Times(0);
8300
8301 EXPECT_CALL(GLProxy, VertexAttribPointer(_, _, _, _, _, _))
8302 .Times(0);
8303
8304 EXPECT_CALL(GLProxy, VertexAttribDivisor(_, _))
8305 .Times(0);
8306
8307 EXPECT_CALL(GLProxy,
8308 GetAttribLocation(ProgramId, Eq("Covellite_VertexExtra")))
8309 .Times(1)
8310 .WillOnce(Return(-1));
8311
8312 EXPECT_CALL(GLProxy, EnableVertexAttribArray(_))
8313 .Times(0);
8314
8315 EXPECT_CALL(GLProxy, VertexAttribPointer(_, _, _, _, _, _))
8316 .Times(0);
8317
8318 EXPECT_CALL(GLProxy, VertexAttribDivisor(_, _))
8319 .Times(0);
8320
8321 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
8322 .Times(1);
8323
8324 Render();
8325
8326 EXPECT_CALL(GLProxy, DeleteBuffers(1, BufferId))
8327 .Times(1);
8328 };
8329
8330 // ***************** Передача данных в объекте компонента ***************** //
8331
8332 {
8333 const auto pBuffer = Component_t::Make(
8334 {
8335 { uT("content"), Source },
8336 });
8337
8338 TestCallRender(pBuffer);
8339 }
8340
8341 // ************** Передача данных в объекте компонента Data *************** //
8342
8343 {
8344 const auto pData = Component_t::Make(
8345 {
8346 { uT("kind"), uT("Buffer") },
8347 { uT("content"), Source },
8348 });
8349
8350 TestCallRender(Component_t::Make({ { uT("service"), Object_t{ pData } } }));
8351 }
8352
8354
8355 // ***************** Передача данных в объекте компонента ***************** //
8356
8357 {
8358 const auto pBuffer = Component_t::Make(
8359 {
8360 { uT("content"), Source },
8361 { uT("mapper"), BufferMapper_t{} },
8362 });
8363
8364 TestCallRender(pBuffer);
8365 }
8366
8367 // ************** Передача данных в объекте компонента Data *************** //
8368
8369 {
8370 const auto pData = Component_t::Make(
8371 {
8372 { uT("kind"), uT("Buffer") },
8373 { uT("content"), Source },
8374 });
8375
8376 const auto pBuffer = Component_t::Make(
8377 {
8378 { uT("mapper"), BufferMapper_t{} },
8379 { uT("service"), Object_t{ pData } }
8380 });
8381
8382 TestCallRender(pBuffer);
8383 }
8384}
8385
8386// ************************************************************************** //
8387TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Transform_Default)
8388{
8389 using GLProxy_t = ::mock::GLProxy;
8390 GLProxy_t GLProxy;
8391 GLProxy_t::GetInstance() = &GLProxy;
8392
8393 const Tested_t Example{ Data_t{} };
8394 const ITested_t & IExample = Example;
8395
8396 const ::mock::GLint ProgramId = 1908241203;
8397 const ::mock::GLint MatrixWorldLocationId = 1908241207;
8398 const ::mock::GLint ExtraLocationId = 2608311427;
8399
8400 auto itCreator = IExample.GetCreators().find(uT("Transform"));
8401 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8402
8403 auto pPosition = Component_t::Make({ { uT("kind"), uT("Position") } });
8404 auto pRotation = Component_t::Make({ { uT("kind"), uT("Rotation") } });
8405 auto pScale = Component_t::Make({ { uT("kind"), uT("Scale") } });
8406 auto pTransform = Component_t::Make(
8407 {
8408 { uT("service"), Object_t{ pPosition, pRotation, pScale } }
8409 });
8410
8411 const auto Render = itCreator->second(pTransform);
8412 ASSERT_NE(nullptr, Render);
8413
8414 auto WorldMatrix = ::glm::identity<::glm::mat4>();
8415
8416 auto TestCallRender = [&](
8417 float _X, float _Y, float _Z,
8418 float _A, float _B, float _C,
8419 float _Sx, float _Sy, float _Sz,
8420 const ::glm::vec4 & _Extra)
8421 {
8422 (*pPosition)[uT("x")] = _X;
8423 (*pPosition)[uT("y")] = _Y;
8424 (*pPosition)[uT("z")] = _Z;
8425
8426 (*pRotation)[uT("x")] = _A;
8427 (*pRotation)[uT("y")] = _B;
8428 (*pRotation)[uT("z")] = _C;
8429
8430 (*pScale)[uT("x")] = _Sx;
8431 (*pScale)[uT("y")] = _Sy;
8432 (*pScale)[uT("z")] = _Sz;
8433
8434 WorldMatrix = ::glm::identity<::glm::mat4>();
8435 WorldMatrix = ::glm::scale(WorldMatrix, { _Sx, _Sy, _Sz });
8436 WorldMatrix = ::glm::rotate(WorldMatrix, _C, { 0.0f, 0.0f, 1.0f });
8437 WorldMatrix = ::glm::rotate(WorldMatrix, _B, { 0.0f, 1.0f, 0.0f });
8438 WorldMatrix = ::glm::rotate(WorldMatrix, _A, { 1.0f, 0.0f, 0.0f });
8439 WorldMatrix = ::glm::translate(WorldMatrix, { _X, _Y, _Z });
8440 WorldMatrix = ::glm::transpose(WorldMatrix);
8441
8442 using namespace ::testing;
8443
8444 InSequence Dummy;
8445
8446 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8447 .Times(1)
8448 .WillOnce(Return(&ProgramId));
8449
8450 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("ObjectData.World")))
8451 .Times(1)
8452 .WillOnce(Return(MatrixWorldLocationId));
8453
8454 EXPECT_CALL(GLProxy,
8455 UniformMatrix4fv(MatrixWorldLocationId, 1, GL_FALSE, WorldMatrix))
8456 .Times(1);
8457
8458 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("ObjectData.Extra")))
8459 .Times(1)
8460 .WillOnce(Return(ExtraLocationId));
8461
8462 EXPECT_CALL(GLProxy,
8463 Uniform4fv(ExtraLocationId, 1, _Extra))
8464 .Times(1);
8465
8466 Render();
8467 };
8468
8469 // Два вызова, чтобы убедиться, что изменение исходных данных приводит
8470 // к изменению результата рендеринга.
8471
8472 TestCallRender(
8473 1956.0f, 1957.0f, 1958.0f,
8474 1204.0f, 1205.0f, 1206.0f,
8475 1152.0f, 1153.0f, 1154.0f,
8476 ::glm::vec4());
8477
8478 const auto Extra = ::glm::vec4(1959.0f, 1960.0f, 1961.0f, 1962.0f);
8479 (*pTransform)[uT("extra")] = Extra;
8480
8481 TestCallRender(
8482 1959.0f, 1960.0f, 1961.0f,
8483 1145.0f, 1146.0f, 1147.0f,
8484 1155.0f, 1157.0f, 1158.0f,
8485 Extra);
8486}
8487
8488// ************************************************************************** //
8489TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Transform_Static)
8490{
8491 using GLProxy_t = ::mock::GLProxy;
8492 GLProxy_t GLProxy;
8493 GLProxy_t::GetInstance() = &GLProxy;
8494
8495 const Tested_t Example{ Data_t{} };
8496 const ITested_t & IExample = Example;
8497
8498 const ::mock::GLint ProgramId = 1908241203;
8499 const ::mock::GLint MatrixWorldLocationId = 1908241207;
8500 const ::mock::GLint ExtraLocationId = 2608311426;
8501
8502 auto itCreator = IExample.GetCreators().find(uT("Transform"));
8503 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8504
8505 auto pPosition = Component_t::Make({ { uT("kind"), uT("Position") } });
8506 auto pRotation = Component_t::Make({ { uT("kind"), uT("Rotation") } });
8507 auto pScale = Component_t::Make({ { uT("kind"), uT("Scale") } });
8508
8509 auto TestCallRender = [&](const Component_t::ComponentPtr_t & _pTransform)
8510 {
8511 auto WorldMatrix = ::glm::identity<::glm::mat4>();
8512
8513 auto SetValues = [&](const bool _IsBuildMatrix,
8514 float _X, float _Y, float _Z,
8515 float _A, float _B, float _C,
8516 float _Sx, float _Sy, float _Sz)
8517 {
8518 (*pPosition)[uT("x")] = _X;
8519 (*pPosition)[uT("y")] = _Y;
8520 (*pPosition)[uT("z")] = _Z;
8521
8522 (*pRotation)[uT("x")] = _A;
8523 (*pRotation)[uT("y")] = _B;
8524 (*pRotation)[uT("z")] = _C;
8525
8526 (*pScale)[uT("x")] = _Sx;
8527 (*pScale)[uT("y")] = _Sy;
8528 (*pScale)[uT("z")] = _Sz;
8529
8530 if (_IsBuildMatrix)
8531 {
8532 WorldMatrix = ::glm::identity<::glm::mat4>();
8533 WorldMatrix = ::glm::scale(WorldMatrix, { _Sx, _Sy, _Sz });
8534 WorldMatrix = ::glm::rotate(WorldMatrix, _C, { 0.0f, 0.0f, 1.0f });
8535 WorldMatrix = ::glm::rotate(WorldMatrix, _B, { 0.0f, 1.0f, 0.0f });
8536 WorldMatrix = ::glm::rotate(WorldMatrix, _A, { 1.0f, 0.0f, 0.0f });
8537 WorldMatrix = ::glm::translate(WorldMatrix, { _X, _Y, _Z });
8538 WorldMatrix = ::glm::transpose(WorldMatrix);
8539 }
8540 };
8541
8542 SetValues(true,
8543 1956.0f, 1957.0f, 1958.0f,
8544 1204.0f, 1205.0f, 1206.0f,
8545 1152.0f, 1153.0f, 1154.0f);
8546
8547 const auto Render = itCreator->second(_pTransform);
8548 ASSERT_NE(nullptr, Render);
8549
8550 auto TestCallRender = [&](void)
8551 {
8552 using namespace ::testing;
8553
8554 InSequence Dummy;
8555
8556 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8557 .Times(1)
8558 .WillOnce(Return(&ProgramId));
8559
8560 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("ObjectData.World")))
8561 .Times(1)
8562 .WillOnce(Return(MatrixWorldLocationId));
8563
8564 EXPECT_CALL(GLProxy,
8565 UniformMatrix4fv(MatrixWorldLocationId, 1, GL_FALSE, WorldMatrix))
8566 .Times(1);
8567
8568 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("ObjectData.Extra")))
8569 .Times(1)
8570 .WillOnce(Return(ExtraLocationId));
8571
8572 EXPECT_CALL(GLProxy,
8573 Uniform4fv(ExtraLocationId, 1, ::glm::vec4()))
8574 .Times(1);
8575
8576 Render();
8577 };
8578
8579 // Два вызова, чтобы убедиться, что изменение исходных данных не приводит
8580 // к изменению результата рендеринга.
8581
8582 TestCallRender();
8583
8584 SetValues(false,
8585 1959.0f, 1960.0f, 1961.0f,
8586 1145.0f, 1146.0f, 1147.0f,
8587 1155.0f, 1157.0f, 1158.0f);
8588
8589 TestCallRender();
8590 };
8591
8592 const auto pTransform = Component_t::Make(
8593 {
8594 { uT("kind"), uT("Static") },
8595 { uT("service"), Object_t{ pPosition, pRotation, pScale } }
8596 });
8597
8598 TestCallRender(pTransform);
8599}
8600
8601// ************************************************************************** //
8602TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Transform_Billboard)
8603{
8604 using GLProxy_t = ::mock::GLProxy;
8605 GLProxy_t GLProxy;
8606 GLProxy_t::GetInstance() = &GLProxy;
8607
8608 Tested_t Example{ Data_t{} };
8609 const ITested_t & IExample = Example;
8610
8611 const ::mock::GLint ProgramId = 1908241203;
8612 const ::mock::GLint MatrixWorldLocationId = 1908241207;
8613 const ::mock::GLint ExtraLocationId = 2608311425;
8614
8615 auto itCreator = IExample.GetCreators().find(uT("Transform"));
8616 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8617
8618 auto pPosition = Component_t::Make({ { uT("kind"), uT("Position") } });
8619
8620 auto TestCallRender = [&](const Component_t::ComponentPtr_t & _pTransform)
8621 {
8622 const auto Render = itCreator->second(_pTransform);
8623 ASSERT_NE(nullptr, Render);
8624
8625 auto WorldMatrix = ::glm::identity<::glm::mat4>();
8626
8627 auto TestCallRender = [&](float _X, float _Y, float _Z)
8628 {
8629 (*pPosition)[uT("x")] = _X;
8630 (*pPosition)[uT("y")] = _Y;
8631 (*pPosition)[uT("z")] = _Z;
8632
8633 WorldMatrix = ::glm::identity<::glm::mat4>();
8634 WorldMatrix = ::glm::translate(WorldMatrix, { _X, _Y, _Z });
8635
8636 const auto ViewMatrix = ::glm::mat4
8637 {
8638 { 1.0f, 2.0f, 3.0f, 4.0f },
8639 { 5.0f, 6.0f, 7.0f, 8.0f },
8640 { 9.0f, 10.0f, 11.0f, 12.0f },
8641 { 13.0f, 14.0f, 15.0f, 16.0f },
8642 };
8643
8644 GetCameraMartix(Example).View = ViewMatrix;
8645
8646 auto TransposeViewMatrix = ViewMatrix;
8647 TransposeViewMatrix[0][3] = 0.0f;
8648 TransposeViewMatrix[1][3] = 0.0f;
8649 TransposeViewMatrix[2][3] = 0.0f;
8650 TransposeViewMatrix[3][0] = 0.0f;
8651 TransposeViewMatrix[3][1] = 0.0f;
8652 TransposeViewMatrix[3][2] = 0.0f;
8653 TransposeViewMatrix[3][3] = 1.0f;
8654
8655 WorldMatrix = TransposeViewMatrix *
8656 ::glm::translate(::glm::identity<::glm::mat4>(), { _X, _Y, _Z });
8657 WorldMatrix = ::glm::transpose(WorldMatrix);
8658
8659 using namespace ::testing;
8660
8661 InSequence Dummy;
8662
8663 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8664 .Times(1)
8665 .WillOnce(Return(&ProgramId));
8666
8667 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("ObjectData.World")))
8668 .Times(1)
8669 .WillOnce(Return(MatrixWorldLocationId));
8670
8671 EXPECT_CALL(GLProxy,
8672 UniformMatrix4fv(MatrixWorldLocationId, 1, GL_FALSE, WorldMatrix))
8673 .Times(1);
8674
8675 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("ObjectData.Extra")))
8676 .Times(1)
8677 .WillOnce(Return(ExtraLocationId));
8678
8679 EXPECT_CALL(GLProxy,
8680 Uniform4fv(ExtraLocationId, 1, ::glm::vec4()))
8681 .Times(1);
8682
8683 Render();
8684 };
8685
8686 // Два вызова, чтобы убедиться, что изменение исходных данных приводит
8687 // к изменению результата рендеринга.
8688
8689 TestCallRender(1956.0f, 1957.0f, 1958.0f);
8690 TestCallRender(1959.0f, 1960.0f, 1961.0f);
8691 };
8692
8693 const auto pTransform = Component_t::Make(
8694 {
8695 { uT("kind"), uT("Billboard") },
8696 { uT("service"), Object_t{ pPosition } }
8697 });
8698
8699 TestCallRender(pTransform);
8700}
8701
8702// ************************************************************************** //
8703TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Transform_DefaultValues)
8704{
8705 using GLProxy_t = ::mock::GLProxy;
8706 GLProxy_t GLProxy;
8707 GLProxy_t::GetInstance() = &GLProxy;
8708
8709 Tested_t Example{ Data_t{} };
8710 const ITested_t & IExample = Example;
8711
8712 auto itCreator = IExample.GetCreators().find(uT("Transform"));
8713 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8714
8715 auto pPosition = Component_t::Make({ { uT("kind"), uT("Position") } });
8716 auto pRotation = Component_t::Make({ { uT("kind"), uT("Rotation") } });
8717 auto pScale = Component_t::Make({ { uT("kind"), uT("Scale") } });
8718
8719 auto TestCallRender = [&](const Component_t::ComponentPtr_t & _pComponent,
8720 const bool _IsFullTransform = true)
8721 {
8722 const auto Render = itCreator->second(_pComponent);
8723 ASSERT_NE(nullptr, Render);
8724
8725 const auto ViewMatrix = ::glm::mat4
8726 {
8727 { 1.0f, 2.0f, 3.0f, 4.0f },
8728 { 5.0f, 6.0f, 7.0f, 8.0f },
8729 { 9.0f, 10.0f, 11.0f, 12.0f },
8730 { 13.0f, 14.0f, 15.0f, 16.0f },
8731 };
8732
8733 GetCameraMartix(Example).View = ViewMatrix;
8734
8735 auto WorldMatrix = ::glm::identity<::glm::mat4>();
8736
8737 if (_IsFullTransform)
8738 {
8739 WorldMatrix = ::glm::scale(WorldMatrix, { 1.0f, 1.0f, 1.0f });
8740 WorldMatrix = ::glm::transpose(WorldMatrix);
8741 }
8742 else
8743 {
8744 auto TransposeViewMatrix = ViewMatrix;
8745 TransposeViewMatrix[0][3] = 0.0f;
8746 TransposeViewMatrix[1][3] = 0.0f;
8747 TransposeViewMatrix[2][3] = 0.0f;
8748 TransposeViewMatrix[3][0] = 0.0f;
8749 TransposeViewMatrix[3][1] = 0.0f;
8750 TransposeViewMatrix[3][2] = 0.0f;
8751 TransposeViewMatrix[3][3] = 1.0f;
8752
8753 WorldMatrix = TransposeViewMatrix;
8754 WorldMatrix = ::glm::transpose(WorldMatrix);
8755 }
8756
8757 using namespace ::testing;
8758
8759 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, WorldMatrix))
8760 .Times(1);
8761
8762 Render();
8763 };
8764
8765 TestCallRender(Component_t::Make(
8766 {
8767 { uT("service"), Object_t{ pPosition, pRotation, pScale } }
8768 }));
8769
8770 TestCallRender(Component_t::Make(
8771 {
8772 { uT("kind"), uT("Static") },
8773 { uT("service"), Object_t{ pPosition, pRotation, pScale } }
8774 }));
8775
8776 TestCallRender(Component_t::Make(
8777 {
8778 { uT("kind"), uT("Billboard") },
8779 { uT("service"), Object_t{ pPosition, pRotation, pScale } }
8780 }), false);
8781}
8782
8783// ************************************************************************** //
8784TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Transform_Combine)
8785{
8786 using GLProxy_t = ::mock::GLProxy;
8787 GLProxy_t GLProxy;
8788 GLProxy_t::GetInstance() = &GLProxy;
8789
8790 Tested_t Example{ Data_t{} };
8791 const ITested_t & IExample = Example;
8792
8793 auto itCreator = IExample.GetCreators().find(uT("Transform"));
8794 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8795
8796 auto MatrixIdentity = ::glm::identity<::glm::mat4>();
8797
8798 ::std::deque<Component_t::ComponentPtr_t> Components;
8799
8800 const auto SetPosition = [&](float _X, float _Y, float _Z)
8801 {
8802 Components.push_front(Component_t::Make(
8803 {
8804 { uT("kind"), uT("Position") },
8805 { uT("x"), _X },
8806 { uT("y"), _Y },
8807 { uT("z"), _Z },
8808 }));
8809
8810 MatrixIdentity = ::glm::translate(MatrixIdentity, { _X, _Y, _Z });
8811 };
8812
8813 const auto SetRotation = [&](float _X, float _Y, float _Z)
8814 {
8815 Components.push_front(Component_t::Make(
8816 {
8817 { uT("kind"), uT("Rotation") },
8818 { uT("x"), _X },
8819 { uT("y"), _Y },
8820 { uT("z"), _Z },
8821 }));
8822
8823 MatrixIdentity = ::glm::rotate(MatrixIdentity, _Z, { 0.0f, 0.0f, 1.0f });
8824 MatrixIdentity = ::glm::rotate(MatrixIdentity, _Y, { 0.0f, 1.0f, 0.0f });
8825 MatrixIdentity = ::glm::rotate(MatrixIdentity, _X, { 1.0f, 0.0f, 0.0f });
8826 };
8827
8828 const auto SetScale = [&](float _X, float _Y, float _Z)
8829 {
8830 Components.push_front(Component_t::Make(
8831 {
8832 { uT("kind"), uT("Scale") },
8833 { uT("x"), _X },
8834 { uT("y"), _Y },
8835 { uT("z"), _Z },
8836 }));
8837
8838 MatrixIdentity = ::glm::scale(MatrixIdentity, { _X, _Y, _Z });
8839 };
8840
8841 {
8842 MatrixIdentity = ::glm::identity<::glm::mat4>();
8843 Components.clear();
8844
8845 SetPosition(1.0f, 2.0f, 3.0f);
8846 SetRotation(4.0f, 5.0f, 6.0f);
8847 SetScale(7.0f, 8.0f, 9.0f);
8848
8849 SetPosition(11.0f, 22.0f, 33.0f);
8850 SetRotation(44.0f, 55.0f, 66.0f);
8851 SetScale(77.0f, 88.0f, 99.0f);
8852
8853 MatrixIdentity = ::glm::transpose(MatrixIdentity);
8854
8855 auto Render = itCreator->second(Component_t::Make(
8856 {
8857 { uT("service"), Object_t{ Components.begin(), Components.end() } }
8858 }));
8859 ASSERT_NE(nullptr, Render);
8860
8861 using namespace ::testing;
8862
8863 InSequence Dummy;
8864
8865 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, MatrixIdentity))
8866 .Times(1);
8867
8868 Render();
8869 }
8870
8871 {
8872 MatrixIdentity = ::glm::identity<::glm::mat4>();
8873 Components.clear();
8874
8875 SetPosition(1.0f, 2.0f, 3.0f);
8876 SetRotation(4.0f, 5.0f, 6.0f);
8877 SetScale(7.0f, 8.0f, 9.0f);
8878
8879 SetPosition(11.0f, 22.0f, 33.0f);
8880 SetRotation(44.0f, 55.0f, 66.0f);
8881 SetScale(77.0f, 88.0f, 99.0f);
8882
8883 MatrixIdentity = ::glm::transpose(MatrixIdentity);
8884
8885 auto Render = itCreator->second(Component_t::Make(
8886 {
8887 { uT("kind"), uT("Static") },
8888 { uT("service"), Object_t{ Components.begin(), Components.end() } }
8889 }));
8890 ASSERT_NE(nullptr, Render);
8891
8892 using namespace ::testing;
8893
8894 InSequence Dummy;
8895
8896 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, MatrixIdentity))
8897 .Times(1);
8898
8899 Render();
8900 }
8901
8902 {
8903 const auto ViewMatrix = ::glm::mat4
8904 {
8905 { 1.0f, 2.0f, 3.0f, 4.0f },
8906 { 5.0f, 6.0f, 7.0f, 8.0f },
8907 { 9.0f, 10.0f, 11.0f, 12.0f },
8908 { 13.0f, 14.0f, 15.0f, 16.0f },
8909 };
8910
8911 GetCameraMartix(Example).View = ViewMatrix;
8912
8913 auto TransposeViewMatrix = ViewMatrix;
8914 TransposeViewMatrix[0][3] = 0.0f;
8915 TransposeViewMatrix[1][3] = 0.0f;
8916 TransposeViewMatrix[2][3] = 0.0f;
8917 TransposeViewMatrix[3][0] = 0.0f;
8918 TransposeViewMatrix[3][1] = 0.0f;
8919 TransposeViewMatrix[3][2] = 0.0f;
8920 TransposeViewMatrix[3][3] = 1.0f;
8921
8922 MatrixIdentity = TransposeViewMatrix;
8923 Components.clear();
8924
8925 SetPosition(1.0f, 2.0f, 3.0f);
8926 SetPosition(11.0f, 22.0f, 33.0f);
8927 SetPosition(111.0f, 222.0f, 333.0f);
8928
8929 MatrixIdentity = ::glm::transpose(MatrixIdentity);
8930
8931 auto Render = itCreator->second(Component_t::Make(
8932 {
8933 { uT("kind"), uT("Billboard") },
8934 { uT("service"), Object_t{ Components.begin(), Components.end() } }
8935 }));
8936 ASSERT_NE(nullptr, Render);
8937
8938 using namespace ::testing;
8939
8940 InSequence Dummy;
8941
8942 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, MatrixIdentity))
8943 .Times(1);
8944
8945 Render();
8946 }
8947}
8948
8949// ************************************************************************** //
8950TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Buffer_Constant_User_CreateBuffer_Error)
8951{
8952 using BufferMapper_t = ::covellite::api::cbBufferMap_t<void>;
8953
8954 using GLProxy_t = ::mock::GLProxy;
8955 GLProxy_t GLProxy;
8956 GLProxy_t::GetInstance() = &GLProxy;
8957
8958 struct Data { };
8959 const BufferMapper_t BufferMapper = [&](void *) { return false; };
8960
8961 const Tested_t oExample{ Data_t{} };
8962 const ITested_t & IExample = oExample;
8963
8964 auto itConstBufferCreator = IExample.GetCreators().find(uT("Buffer"));
8965 ASSERT_NE(IExample.GetCreators().end(), itConstBufferCreator);
8966
8967 auto TestCallRender = [&](const Component_t::ComponentPtr_t & _pComponent)
8968 {
8969 using namespace ::testing;
8970
8971 InSequence Dummy;
8972
8973 EXPECT_CALL(GLProxy, GenBuffers(_))
8974 .Times(1);
8975
8976 EXPECT_CALL(GLProxy, GetError())
8977 .Times(1)
8978 .WillOnce(Return(1909211243));
8979
8980 EXPECT_THROW(itConstBufferCreator->second(_pComponent), ::std::exception);
8981 };
8982
8983 const auto pBuffer = Component_t::Make(
8984 {
8985 { uT("mapper"), BufferMapper },
8986 { uT("size"), sizeof(Data) },
8987 });
8988 TestCallRender(pBuffer);
8989}
8990
8991// ************************************************************************** //
8992TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Buffer_Constant_User_UpdateBuffer_NotExistsName)
8993{
8994 using BufferMapper_t = ::covellite::api::cbBufferMap_t<void>;
8995
8996 using GLProxy_t = ::mock::GLProxy;
8997 GLProxy_t GLProxy;
8998 GLProxy_t::GetInstance() = &GLProxy;
8999
9000 const BufferMapper_t BufferMapper = [&](void *) { return false; };
9001
9002 using namespace ::testing;
9003
9004 const Tested_t oExample{ Data_t{} };
9005 const ITested_t & IExample = oExample;
9006
9007 auto itConstBufferCreator = IExample.GetCreators().find(uT("Buffer"));
9008 ASSERT_NE(IExample.GetCreators().end(), itConstBufferCreator);
9009
9010 auto TestCallRender = [&](const Component_t::ComponentPtr_t & _pComponent)
9011 {
9012 using namespace ::testing;
9013
9014 const auto Render = itConstBufferCreator->second(_pComponent);
9015 ASSERT_NE(nullptr, Render);
9016
9017 InSequence Dummy;
9018
9019 EXPECT_CALL(GLProxy, GetUniformBlockIndex(_, _))
9020 .Times(1)
9021 .WillOnce(Return(GL_INVALID_INDEX));
9022
9023 EXPECT_CALL(GLProxy, BindBuffer(_, _))
9024 .Times(0);
9025
9026 EXPECT_CALL(GLProxy, UniformBufferSubData(_, _, _))
9027 .Times(0);
9028
9029 EXPECT_CALL(GLProxy, BindBufferBase(_, _, _))
9030 .Times(0);
9031
9032 EXPECT_CALL(GLProxy, UniformBlockBinding(_, _, _))
9033 .Times(0);
9034
9035 Render();
9036 };
9037
9038 const auto pBuffer = Component_t::Make(
9039 {
9040 { uT("mapper"), BufferMapper },
9041 { uT("size"), ::std::size_t{ 4 } },
9042 });
9043
9044 TestCallRender(pBuffer);
9045}
9046
9047// ************************************************************************** //
9048TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Buffer_Constant_User)
9049{
9050 using BufferMapper_t = ::covellite::api::cbBufferMap_t<void>;
9051
9052 using GLProxy_t = ::mock::GLProxy;
9053 GLProxy_t GLProxy;
9054 GLProxy_t::GetInstance() = &GLProxy;
9055
9056 class MapperProxy :
9057 public ::alicorn::extension::testing::Proxy<MapperProxy>
9058 {
9059 public:
9060 MOCK_METHOD1(DoMapper, void(const void *));
9061 };
9062
9063 MapperProxy oMapperProxy;
9064 MapperProxy::GetInstance() = &oMapperProxy;
9065
9066 const ::mock::GLuint BufferId = 1909211301;
9067 const ::mock::GLint ProgramId = 1909211302;
9068 const ::mock::GLint BlockIndex = 1909211332;
9069 const ::std::size_t Size = 313;
9070
9071 void * pData = nullptr;
9072
9073 const BufferMapper_t BufferMapper = [&](void * _pData)
9074 {
9075 pData = _pData;
9076 oMapperProxy.DoMapper(_pData);
9077 return false;
9078 };
9079
9080 const Tested_t oExample{ Data_t{} };
9081 const ITested_t & IExample = oExample;
9082
9083 auto itConstBufferCreator = IExample.GetCreators().find(uT("Buffer"));
9084 ASSERT_NE(IExample.GetCreators().end(), itConstBufferCreator);
9085
9086 auto TestCallRender = [&](const Component_t::ComponentPtr_t & _pComponent,
9087 const ::std::string & _Name)
9088 {
9089 using namespace ::testing;
9090
9091 InSequence Dummy;
9092
9093 EXPECT_CALL(GLProxy, GenBuffers(1))
9094 .Times(1)
9095 .WillOnce(Return(BufferId));
9096
9097 EXPECT_CALL(GLProxy, BindBuffer(GL_UNIFORM_BUFFER, BufferId))
9098 .Times(1);
9099
9100 EXPECT_CALL(GLProxy,
9101 BufferData(GL_UNIFORM_BUFFER, Size, _, GL_DYNAMIC_DRAW))
9102 .Times(1);
9103
9104 EXPECT_CALL(GLProxy, BindBuffer(GL_UNIFORM_BUFFER, 0))
9105 .Times(1);
9106
9107 EXPECT_CALL(GLProxy, GetError())
9108 .Times(1)
9109 .WillOnce(Return(GL_NO_ERROR));
9110
9111 const auto Render = itConstBufferCreator->second(_pComponent);
9112 ASSERT_NE(nullptr, Render);
9113
9114 EXPECT_CALL(oMapperProxy, DoMapper(_))
9115 .Times(1);
9116
9117 EXPECT_CALL(GLProxy, GetIntegerv(_))
9118 .Times(1);
9119
9120 EXPECT_CALL(GLProxy, GetUniformBlockIndex(_, _))
9121 .Times(1)
9122 .WillOnce(Return(BlockIndex));
9123
9124 EXPECT_CALL(GLProxy, BindBuffer(_, _))
9125 .Times(1);
9126
9127 EXPECT_CALL(GLProxy, UniformBufferSubData(_, _, _))
9128 .Times(1);
9129
9130 EXPECT_CALL(GLProxy, BindBuffer(_, _))
9131 .Times(1);
9132
9133 EXPECT_CALL(GLProxy, BindBufferBase(_, _, _))
9134 .Times(1);
9135
9136 EXPECT_CALL(GLProxy, UniformBlockBinding(_, _, _))
9137 .Times(1);
9138
9139 Render(); // Первый вызов, чтобы запомнить указатель на локальный буфер данных
9140
9141 EXPECT_CALL(oMapperProxy, DoMapper(pData))
9142 .Times(1);
9143
9144 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
9145 .Times(1)
9146 .WillOnce(Return(&ProgramId));
9147
9148 EXPECT_CALL(GLProxy, GetUniformBlockIndex(ProgramId, _Name))
9149 .Times(1)
9150 .WillOnce(Return(BlockIndex));
9151
9152 EXPECT_CALL(GLProxy, BindBuffer(GL_UNIFORM_BUFFER, BufferId))
9153 .Times(1);
9154
9155 EXPECT_CALL(GLProxy, UniformBufferSubData(0, Size, pData))
9156 .Times(1);
9157
9158 EXPECT_CALL(GLProxy, BindBuffer(GL_UNIFORM_BUFFER, 0))
9159 .Times(1);
9160
9161 EXPECT_CALL(GLProxy,
9162 BindBufferBase(GL_UNIFORM_BUFFER, COVELLITE_BUFFER_INDEX_USER, BufferId))
9163 .Times(1);
9164
9165 EXPECT_CALL(GLProxy,
9166 UniformBlockBinding(ProgramId, BlockIndex, COVELLITE_BUFFER_INDEX_USER))
9167 .Times(1);
9168
9169 Render();
9170
9171 EXPECT_CALL(GLProxy, DeleteBuffers(1, BufferId))
9172 .Times(1);
9173 };
9174
9175 // Default constant buffer name
9176 {
9177 const auto pBuffer = Component_t::Make(
9178 {
9179 { uT("mapper"), BufferMapper },
9180 { uT("size"), Size },
9181 });
9182
9183 TestCallRender(pBuffer, "cbUserData");
9184 }
9185
9186 {
9187 const ::std::string Name = "Name1909211251";
9188
9189 const auto pBuffer = Component_t::Make(
9190 {
9191 { uT("mapper"), BufferMapper },
9192 { uT("size"), Size },
9193 { uT("name"), Name },
9194 });
9195
9196 TestCallRender(pBuffer, Name);
9197 }
9198}
9199
9200// ************************************************************************** //
9201TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Camera_Orthographic_DefaultPosition)
9202{
9203 Tested::GetValue() = 1;
9204
9205 ::mock::GLProxy GLProxy;
9206
9207 const Tested_t Example{ Data_t{} };
9208 const ITested_t & IExample = Example;
9209
9210 auto itCreator = IExample.GetCreators().find(uT("Camera"));
9211 ASSERT_NE(IExample.GetCreators().end(), itCreator);
9212
9213 auto Render = itCreator->second(Component_t::Make(
9214 {
9215 { uT("kind"), uT("Orthographic") },
9216 }));
9217 ASSERT_NE(nullptr, Render);
9218
9219 auto itShaderCreator = IExample.GetCreators().find(uT("Shader"));
9220 ASSERT_NE(IExample.GetCreators().end(), itShaderCreator);
9221
9222 auto VsRender = itShaderCreator->second(Component_t::Make(
9223 {
9224 { uT("entry"), uT("vsFlat") },
9225 }));
9226 ASSERT_NE(nullptr, VsRender);
9227
9228 auto PsRender = itShaderCreator->second(Component_t::Make(
9229 {
9230 { uT("entry"), uT("psColored") },
9231 }));
9232 ASSERT_NE(nullptr, PsRender);
9233
9234 const float Viewport[] =
9235 {
9236 1812271148.0f, 1812271149.0f, 1812181722.0f, 1812181723.0f
9237 };
9238
9239 using namespace ::testing;
9240
9241 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, 0))
9242 .Times(1);
9243
9244 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
9245 .Times(1);
9246
9247 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
9248 .Times(0);
9249
9250 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
9251 .Times(0);
9252
9253 EXPECT_CALL(GLProxy, Disable(GL_BLEND))
9254 .Times(1);
9255
9256 EXPECT_CALL(GLProxy, Disable(GL_DITHER))
9257 .Times(1);
9258
9259 EXPECT_CALL(GLProxy, Enable(GL_CULL_FACE))
9260 .Times(1);
9261
9262 EXPECT_CALL(GLProxy, CullFace(GL_BACK))
9263 .Times(1);
9264
9265 EXPECT_CALL(GLProxy, FrontFace(GL_CCW))
9266 .Times(1);
9267
9268 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
9269 .Times(1);
9270
9271 EXPECT_CALL(GLProxy, GetFloatv(GL_VIEWPORT))
9272 .Times(1)
9273 .WillOnce(Return(Viewport));
9274
9275 Render(); // Формирует матрицы вида и проекции
9276
9277 VsRender(); // Нужно, чтобы сформировалась шейдерная программа, иначе
9278 // не будет вызывана функция glUseProgram().
9279
9280 const ::mock::GLint ProgramId = 1908251932;
9281 const ::mock::GLint ProjectionLocationId = 1908251933;
9282 const ::mock::GLint ViewLocationId = 1908252005;
9283 const ::mock::GLint ViewInverseLocationId = 1908252013;
9284
9285 const auto Projection = ::glm::transpose(::glm::ortho(
9286 Viewport[0], Viewport[0] + Viewport[2],
9287 Viewport[1] + Viewport[3], Viewport[1],
9288 1.0f, -1.0f));
9289 auto View = ::glm::identity<::glm::mat4>();
9290 const auto ViewInverse = ::glm::transpose(::glm::inverse(View));
9291 View = ::glm::transpose(View);
9292
9293 InSequence Dummy;
9294
9295 EXPECT_CALL(GLProxy, GetProgramiv(_, _))
9296 .Times(1)
9297 .WillOnce(Return(GL_TRUE));
9298
9299 EXPECT_CALL(GLProxy, UseProgram(_))
9300 .Times(1);
9301
9302 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
9303 .Times(1)
9304 .WillOnce(Return(&ProgramId));
9305
9306 // *************** Передача других данных шейдеру ********************* //
9307
9308 EXPECT_CALL(GLProxy, GetUniformLocation(_, _))
9309 .Times(AtLeast(1));
9310
9311 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, _))
9312 .Times(AtLeast(1));
9313
9314 // ******************************************************************** //
9315
9316 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("CameraData.Projection")))
9317 .Times(1)
9318 .WillOnce(Return(ProjectionLocationId));
9319
9320 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("CameraData.View")))
9321 .Times(1)
9322 .WillOnce(Return(ViewLocationId));
9323
9324 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("CameraData.ViewInverse")))
9325 .Times(1)
9326 .WillOnce(Return(ViewInverseLocationId));
9327
9328 EXPECT_CALL(GLProxy,
9329 UniformMatrix4fv(ProjectionLocationId, 1, GL_FALSE, Projection))
9330 .Times(1);
9331
9332 EXPECT_CALL(GLProxy,
9333 UniformMatrix4fv(ViewLocationId, 1, GL_FALSE, View))
9334 .Times(1);
9335
9336 EXPECT_CALL(GLProxy,
9337 UniformMatrix4fv(ViewInverseLocationId, 1, GL_FALSE, ViewInverse))
9338 .Times(1);
9339
9340 PsRender(); // Передача матриц вида и проекции шейдеру
9341}
9342
9343// ************************************************************************** //
9344TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Camera_Orthographic)
9345{
9346 Tested::GetValue() = 1;
9347
9348 using GLProxy_t = ::mock::GLProxy;
9349 GLProxy_t GLProxy;
9350 GLProxy_t::GetInstance() = &GLProxy;
9351
9352 const auto X = 11111.0f;
9353 const auto Y = 22222.0f;
9354
9355 const float SourceViewport[] =
9356 {
9357 19022.82014f, 19022.82015f, 19022.82016f, 19022.82017f
9358 };
9359
9360 const Tested_t Example{ Data_t{} };
9361 const ITested_t & IExample = Example;
9362
9363 auto itCreator = IExample.GetCreators().find(uT("Camera"));
9364 ASSERT_NE(IExample.GetCreators().end(), itCreator);
9365
9366 auto itShaderCreator = IExample.GetCreators().find(uT("Shader"));
9367 ASSERT_NE(IExample.GetCreators().end(), itShaderCreator);
9368
9369 auto VsRender = itShaderCreator->second(Component_t::Make(
9370 {
9371 { uT("entry"), uT("vsFlat") },
9372 }));
9373 ASSERT_NE(nullptr, VsRender);
9374
9375 auto PsRender = itShaderCreator->second(Component_t::Make(
9376 {
9377 { uT("entry"), uT("psColored") },
9378 }));
9379 ASSERT_NE(nullptr, PsRender);
9380
9381 using namespace ::testing;
9382
9383 const auto pPosition = Component_t::Make(
9384 {
9385 { uT("kind"), uT("Position") },
9386 { uT("x"), X },
9387 { uT("y"), Y },
9388 });
9389
9390 const auto pCameraComponent = Component_t::Make(
9391 {
9392 { uT("kind"), uT("Orthographic") },
9393 { uT("service"), Object_t{ pPosition } },
9394 });
9395
9396 auto Render = itCreator->second(pCameraComponent);
9397 ASSERT_NE(nullptr, Render);
9398
9399 InSequence Dummy;
9400
9401 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, 0))
9402 .Times(1);
9403
9404 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
9405 .Times(1);
9406
9407 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
9408 .Times(0);
9409
9410 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
9411 .Times(0);
9412
9413 EXPECT_CALL(GLProxy, Disable(GL_BLEND))
9414 .Times(1);
9415
9416 EXPECT_CALL(GLProxy, Disable(GL_DITHER))
9417 .Times(1);
9418
9419 EXPECT_CALL(GLProxy, Enable(GL_CULL_FACE))
9420 .Times(1);
9421
9422 EXPECT_CALL(GLProxy, CullFace(GL_BACK))
9423 .Times(1);
9424
9425 EXPECT_CALL(GLProxy, FrontFace(GL_CCW))
9426 .Times(1);
9427
9428 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
9429 .Times(1);
9430
9431 EXPECT_CALL(GLProxy, GetFloatv(GL_VIEWPORT))
9432 .Times(1)
9433 .WillOnce(Return(SourceViewport));
9434
9435 Render(); // Формирует матрицы вида и проекции
9436
9437 const auto Projection = ::glm::transpose(::glm::ortho(
9438 SourceViewport[0] + X,
9439 SourceViewport[0] + SourceViewport[2] + X,
9440 SourceViewport[1] + SourceViewport[3] + Y,
9441 SourceViewport[1] + Y,
9442 1.0f, -1.0f));
9443
9444 auto View = ::glm::identity<::glm::mat4>();
9445 const auto ViewInverse = ::glm::transpose(::glm::inverse(View));
9446 View = ::glm::transpose(View);
9447
9448 EXPECT_EQ(View, (::glm::mat4)(*pCameraComponent)[uT("view")].Default(::glm::mat4{ 1.0f }));
9449 EXPECT_EQ(Projection, (::glm::mat4)(*pCameraComponent)[uT("projection")].Default(::glm::mat4{ 1.0f }));
9450
9451 VsRender(); // Нужно, чтобы сформировалась шейдерная программа, иначе
9452 // не будет вызывана функция glUseProgram().
9453
9454 EXPECT_CALL(GLProxy, GetProgramiv(_, _))
9455 .Times(1)
9456 .WillOnce(Return(GL_TRUE));
9457
9458 EXPECT_CALL(GLProxy, UseProgram(_))
9459 .Times(1);
9460
9461 const ::mock::GLint ProgramId = 1908251932;
9462 const ::mock::GLint ProjectionLocationId = 1908251933;
9463 const ::mock::GLint ViewLocationId = 1908252005;
9464 const ::mock::GLint ViewInverseLocationId = 1908252013;
9465
9466 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
9467 .Times(1)
9468 .WillRepeatedly(Return(&ProgramId));
9469
9470 // *************** Передача других данных шейдеру ********************* //
9471
9472 EXPECT_CALL(GLProxy, GetUniformLocation(_, _))
9473 .Times(AtLeast(1));
9474
9475 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, _))
9476 .Times(AtLeast(1));
9477
9478 // ******************************************************************** //
9479
9480 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("CameraData.Projection")))
9481 .Times(1)
9482 .WillOnce(Return(ProjectionLocationId));
9483
9484 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("CameraData.View")))
9485 .Times(1)
9486 .WillOnce(Return(ViewLocationId));
9487
9488 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("CameraData.ViewInverse")))
9489 .Times(1)
9490 .WillOnce(Return(ViewInverseLocationId));
9491
9492 EXPECT_CALL(GLProxy,
9493 UniformMatrix4fv(ProjectionLocationId, 1, GL_FALSE, Projection))
9494 .Times(1);
9495
9496 EXPECT_CALL(GLProxy,
9497 UniformMatrix4fv(ViewLocationId, 1, GL_FALSE, View))
9498 .Times(1);
9499
9500 EXPECT_CALL(GLProxy,
9501 UniformMatrix4fv(ViewInverseLocationId, 1, GL_FALSE, ViewInverse))
9502 .Times(1);
9503
9504 PsRender(); // Передача матриц вида и проекции шейдеру
9505}
9506
9507// ************************************************************************** //
9508TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Camera_Perspective)
9509{
9510 ::testing::DefaultValue<int>::Set(GL_TRUE);
9511
9512 Tested::GetValue() = 1;
9513
9514 using GLProxy_t = ::mock::GLProxy;
9515 GLProxy_t GLProxy;
9516 GLProxy_t::GetInstance() = &GLProxy;
9517
9518 const float Width = 1024.0f;
9519 const float Height = 768.0f;
9520
9521 const Tested_t Example{ Data_t{} };
9522 const ITested_t & IExample = Example;
9523
9524 auto itShaderCreator = IExample.GetCreators().find(uT("Shader"));
9525 ASSERT_NE(IExample.GetCreators().end(), itShaderCreator);
9526
9527 auto VsRender = itShaderCreator->second(Component_t::Make(
9528 {
9529 { uT("entry"), uT("vsFlat") },
9530 }));
9531 ASSERT_NE(nullptr, VsRender);
9532
9533 auto PsRender = itShaderCreator->second(Component_t::Make(
9534 {
9535 { uT("entry"), uT("psColored") },
9536 }));
9537 ASSERT_NE(nullptr, PsRender);
9538
9539 using namespace ::testing;
9540
9541 auto TestCallRender = [&](
9542 const Component_t::ComponentPtr_t & _pCameraComponent,
9543 Render_t & _Render,
9544 float _AngleY, float _zNear, float _zFar,
9545 float _X, float _Y, float _Z,
9546 float _A, float _B, float _C,
9547 float _Distance)
9548 {
9549 ASSERT_NE(nullptr, _Render);
9550
9551 const float AngleYRadians = _AngleY *
9552 ::alicorn::extension::cpp::math::Constant<float>::DegreeToRadian;
9553
9554 InSequence Dummy;
9555
9556 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, 0))
9557 .Times(1);
9558
9559 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
9560 .Times(1);
9561
9562 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
9563 .Times(0);
9564
9565 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
9566 .Times(0);
9567
9568 EXPECT_CALL(GLProxy, Disable(GL_BLEND))
9569 .Times(1);
9570
9571 EXPECT_CALL(GLProxy, Disable(GL_DITHER))
9572 .Times(1);
9573
9574 EXPECT_CALL(GLProxy, Enable(GL_CULL_FACE))
9575 .Times(1);
9576
9577 EXPECT_CALL(GLProxy, CullFace(GL_BACK))
9578 .Times(1);
9579
9580 EXPECT_CALL(GLProxy, FrontFace(GL_CCW))
9581 .Times(1);
9582
9583 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
9584 .Times(1);
9585
9586 const float Viewport[] = { 0, 0, Width, Height };
9587
9588 EXPECT_CALL(GLProxy, GetFloatv(GL_VIEWPORT))
9589 .Times(1)
9590 .WillOnce(Return(Viewport));
9591
9592 _Render(); // Формирует матрицы вида и проекции
9593
9594 const auto Projection = ::glm::transpose(::glm::perspectiveFovRH(
9595 AngleYRadians, Viewport[2], Viewport[3], _zFar, _zNear));
9596
9597 auto GetEye = [&](void) -> ::glm::vec3
9598 {
9599 const auto Distance = _Distance + 0.1f;
9600
9601 ::glm::mat4 Transform = ::glm::identity<::glm::mat4>();
9602
9603 Transform = ::glm::translate(Transform,
9604 ::glm::vec3{ _X, _Y, _Z });
9605 Transform = ::glm::rotate(Transform,
9606 _C, ::glm::vec3{ 0.0f, 0.0f, 1.0f });
9607 Transform = ::glm::rotate(Transform,
9608 _B, ::glm::vec3{ 0.0f, 1.0f, 0.0f });
9609 Transform = ::glm::rotate(Transform,
9610 _A, ::glm::vec3{ 1.0f, 0.0f, 0.0f });
9611
9612 return Transform * ::glm::vec4{ Distance, 0.0f, 0.0f, 1.0f };
9613 };
9614
9615 auto View = ::glm::lookAtRH(
9616 GetEye(),
9617 ::glm::vec3{ _X, _Y, _Z },
9618 ::glm::vec3{ 0.0f, 0.0f, 1.0f });
9619 const auto ViewInverse = ::glm::transpose(::glm::inverse(View));
9620 View = ::glm::transpose(View);
9621
9622 EXPECT_EQ(View, (::glm::mat4)(*_pCameraComponent)[uT("view")].Default(::glm::mat4{ 1.0f }));
9623 EXPECT_EQ(Projection, (::glm::mat4)(*_pCameraComponent)[uT("projection")].Default(::glm::mat4{ 1.0f }));
9624
9625 EXPECT_CALL(GLProxy, UseProgram(_))
9626 .Times(AtLeast(1));
9627
9628 VsRender(); // Нужно, чтобы сформировалась шейдерная программа, иначе
9629 // не будет вызывана функция glUseProgram().
9630
9631 const ::mock::GLint ProgramId = 1908251932;
9632 const ::mock::GLint ProjectionLocationId = 1908251933;
9633 const ::mock::GLint ViewLocationId = 1908252005;
9634 const ::mock::GLint ViewInverseLocationId = 1908252013;
9635
9636 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
9637 .Times(1)
9638 .WillRepeatedly(Return(&ProgramId));
9639
9640 // *************** Передача других данных шейдеру ********************* //
9641
9642 EXPECT_CALL(GLProxy, GetUniformLocation(_, _))
9643 .Times(AtLeast(1));
9644
9645 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, _))
9646 .Times(AtLeast(1));
9647
9648 // ******************************************************************** //
9649
9650 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("CameraData.Projection")))
9651 .Times(1)
9652 .WillOnce(Return(ProjectionLocationId));
9653
9654 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("CameraData.View")))
9655 .Times(1)
9656 .WillOnce(Return(ViewLocationId));
9657
9658 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq("CameraData.ViewInverse")))
9659 .Times(1)
9660 .WillOnce(Return(ViewInverseLocationId));
9661
9662 EXPECT_CALL(GLProxy,
9663 UniformMatrix4fv(ProjectionLocationId, 1, GL_FALSE, Projection))
9664 .Times(1);
9665
9666 EXPECT_CALL(GLProxy,
9667 UniformMatrix4fv(ViewLocationId, 1, GL_FALSE, View))
9668 .Times(1);
9669
9670 EXPECT_CALL(GLProxy,
9671 UniformMatrix4fv(ViewInverseLocationId, 1, GL_FALSE, ViewInverse))
9672 .Times(1);
9673
9674 PsRender(); // Передача матриц вида и проекции шейдеру
9675
9676 ::testing::DefaultValue<int>::Clear();
9677 };
9678
9679 auto itCreator = IExample.GetCreators().find(uT("Camera"));
9680 ASSERT_NE(IExample.GetCreators().end(), itCreator);
9681
9682 class CameraInfo
9683 {
9684 public:
9685 float AngleY;
9686 float zNear, zFar;
9687 float X, Y, Z;
9688 float A, B, C;
9689 float Distance;
9690 };
9691
9692 const ::std::vector<CameraInfo> CameraInfos =
9693 {
9694 { 90.0f, 0.01f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f }, // Default values
9695 { 91.0f, 1.11f, 10.1f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f },
9696 { 92.0f, 2.22f, 20.2f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f },
9697 };
9698
9699 {
9700 // Default values + not using Position & Rotation
9701
9702 const auto pCamera = Component_t::Make(
9703 {
9704 { uT("kind"), uT("Perspective") },
9705 });
9706
9707 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
9708 .Times(1);
9709
9710 auto Render = itCreator->second(pCamera);
9711
9712 auto Info = CameraInfos[0];
9713
9714 TestCallRender(
9715 pCamera, Render,
9716 Info.AngleY, Info.zNear, Info.zFar,
9717 Info.X, Info.Y, Info.Z,
9718 Info.A, Info.B, Info.C,
9719 Info.Distance);
9720 }
9721
9722 const auto pPosition = Component_t::Make(
9723 {
9724 { uT("kind"), uT("Position") },
9725 });
9726
9727 const auto pRotation = Component_t::Make(
9728 {
9729 { uT("kind"), uT("Rotation") },
9730 });
9731
9732 {
9733 // Default values from Position & Rotation
9734
9735 const auto pCamera = Component_t::Make(
9736 {
9737 { uT("kind"), uT("Perspective") },
9738 { uT("service"), Object_t{ pPosition, pRotation } },
9739 });
9740
9741 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
9742 .Times(1);
9743
9744 auto Render = itCreator->second(pCamera);
9745
9746 auto Info = CameraInfos[0];
9747
9748 TestCallRender(
9749 pCamera, Render,
9750 Info.AngleY, Info.zNear, Info.zFar,
9751 Info.X, Info.Y, Info.Z,
9752 Info.A, Info.B, Info.C,
9753 Info.Distance);
9754 }
9755
9756 {
9757 // Change values from Position & Rotation
9758
9759 const auto pCamera = Component_t::Make(
9760 {
9761 { uT("kind"), uT("Perspective") },
9762 { uT("service"), Object_t{ pPosition, pRotation } },
9763 });
9764
9765 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
9766 .Times(1);
9767
9768 auto Render = itCreator->second(pCamera);
9769
9770 for (size_t i = 1; i < CameraInfos.size(); i++)
9771 {
9772 auto Info = CameraInfos[i];
9773
9774 (*pPosition)[uT("x")] = Info.X;
9775 (*pPosition)[uT("y")] = Info.Y;
9776 (*pPosition)[uT("z")] = Info.Z;
9777
9778 (*pRotation)[uT("x")] = Info.A;
9779 (*pRotation)[uT("y")] = Info.B;
9780 (*pRotation)[uT("z")] = Info.C;
9781
9782 (*pCamera)[uT("fov")] = Info.AngleY;
9783 (*pCamera)[uT("znear")] = Info.zNear;
9784 (*pCamera)[uT("zfar")] = Info.zFar;
9785 (*pCamera)[uT("distance")] = Info.Distance;
9786
9787 TestCallRender(
9788 pCamera, Render,
9789 Info.AngleY, Info.zNear, Info.zFar,
9790 Info.X, Info.Y, Info.Z,
9791 Info.A, Info.B, Info.C,
9792 Info.Distance);
9793 }
9794 }
9795}
9796
9797// ************************************************************************** //
9798TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Camera_SetWindowViewport)
9799{
9800 const auto TestCall = [](const Component_t::ComponentPtr_t & _pCamera)
9801 {
9802 ::mock::WindowsProxy WindowsProxy;
9803 ::mock::GLProxy GLProxy;
9804
9805 Data_t Data;
9806 Data.ClientRect.Top = 12345;
9807 Data.ClientRect.Width = 2008131258;
9808 Data.ClientRect.Height = 2008131259;
9809
9810 using namespace ::testing;
9811
9812 Tested_t Example{ Data };
9813 ITested_t & IExample = Example;
9814
9815 auto itCreator = IExample.GetCreators().find(uT("Camera"));
9816 ASSERT_NE(IExample.GetCreators().end(), itCreator);
9817
9818 EXPECT_CALL(GLProxy, Viewport(0, 0, Data.ClientRect.Width, Data.ClientRect.Height - Data.ClientRect.Top))
9819 .Times(1);
9820
9821 auto Render = itCreator->second(_pCamera);
9822 ASSERT_NE(nullptr, Render);
9823
9824 EXPECT_CALL(GLProxy, Viewport(0, 0, Data.ClientRect.Width, Data.ClientRect.Height - Data.ClientRect.Top))
9825 .Times(1);
9826
9827 Render();
9828
9829 IExample.ResizeWindow(::covellite::Rect{ 0, 54321, 2008131300, 2008131301 });
9830
9831 EXPECT_CALL(GLProxy, Viewport(0, 0, 2008131300, 2008131301 - 54321))
9832 .Times(1);
9833
9834 Render();
9835 };
9836
9837 TestCall(Component_t::Make(
9838 {
9839 { uT("kind"), uT("Orthographic") },
9840 }));
9841
9842 TestCall(Component_t::Make(
9843 {
9844 { uT("kind"), uT("Perspective") },
9845 }));
9846}
9847
9848// ************************************************************************** //
9849TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Camera_SetScaleViewport)
9850{
9851 const auto TestCall = [](const float _Scale,
9852 const Component_t::ComponentPtr_t & _pCamera)
9853 {
9854 ::mock::WindowsProxy WindowsProxy;
9855 ::mock::GLProxy GLProxy;
9856
9857 Data_t Data;
9858 Data.ClientRect.Top = 123;
9859 Data.ClientRect.Width = 1024;
9860 Data.ClientRect.Height = 2048;
9861
9862 const auto ExpectedWidth = static_cast<int>(_Scale * Data.ClientRect.Width);
9863 const auto ExpectedHeight = static_cast<int>(_Scale * (Data.ClientRect.Height - Data.ClientRect.Top));
9864
9865 using namespace ::testing;
9866
9867 Tested_t Example{ Data };
9868 ITested_t & IExample = Example;
9869
9870 auto itCreator = IExample.GetCreators().find(uT("Camera"));
9871 ASSERT_NE(IExample.GetCreators().end(), itCreator);
9872
9873 EXPECT_CALL(GLProxy, Viewport(0, 0, ExpectedWidth, ExpectedHeight))
9874 .Times(1);
9875
9876 auto Render = itCreator->second(_pCamera);
9877 ASSERT_NE(nullptr, Render);
9878
9879 EXPECT_CALL(GLProxy, Viewport(0, 0, ExpectedWidth, ExpectedHeight))
9880 .Times(1);
9881
9882 Render();
9883
9884 IExample.ResizeWindow(::covellite::Rect{ 0, 321, 2048, 4096 });
9885
9886 const auto ExpectedWidth2 = static_cast<int>(_Scale * 2048);
9887 const auto ExpectedHeight2 = static_cast<int>(_Scale * (4096 - 321));
9888
9889 EXPECT_CALL(GLProxy, Viewport(0, 0, ExpectedWidth2, ExpectedHeight2))
9890 .Times(1);
9891
9892 Render();
9893 };
9894
9895 TestCall(0.5f, Component_t::Make(
9896 {
9897 { uT("kind"), uT("Orthographic") },
9898 { uT("scale"), 0.5f },
9899 }));
9900
9901 TestCall(2.0f, Component_t::Make(
9902 {
9903 { uT("kind"), uT("Perspective") },
9904 { uT("scale"), 2.0f },
9905 }));
9906
9907 TestCall(0.25f, Component_t::Make(
9908 {
9909 { uT("kind"), uT("Orthographic") },
9910 { uT("scale"), 0.25f },
9911 { uT("width"), 2009081959 },
9912 { uT("height"), 2009082000 },
9913 }));
9914
9915 TestCall(4.0f, Component_t::Make(
9916 {
9917 { uT("kind"), uT("Perspective") },
9918 { uT("scale"), 4.0f },
9919 { uT("width"), 2009081959 },
9920 { uT("height"), 2009082000 },
9921 }));
9922}
9923
9924// ************************************************************************** //
9925TEST_F(OpenGLShader_test, /*DISABLED_*/Test_Camera_SetUserViewport)
9926{
9927 const auto TestCall = [](const int _Width, const int _Height,
9928 const Component_t::ComponentPtr_t & _pCamera)
9929 {
9930 ::mock::WindowsProxy WindowsProxy;
9931 ::mock::GLProxy GLProxy;
9932
9933 Data_t Data;
9934 Data.ClientRect.Top = 345;
9935 Data.ClientRect.Width = 2009082008;
9936 Data.ClientRect.Height = 2009082009;
9937
9938 using namespace ::testing;
9939
9940 Tested_t Example{ Data };
9941 ITested_t & IExample = Example;
9942
9943 auto itCreator = IExample.GetCreators().find(uT("Camera"));
9944 ASSERT_NE(IExample.GetCreators().end(), itCreator);
9945
9946 EXPECT_CALL(GLProxy, Viewport(0, 0, _Width, _Height))
9947 .Times(1);
9948
9949 auto Render = itCreator->second(_pCamera);
9950 ASSERT_NE(nullptr, Render);
9951
9952 EXPECT_CALL(GLProxy, Viewport(0, 0, _Width, _Height))
9953 .Times(1);
9954
9955 Render();
9956
9957 IExample.ResizeWindow(::covellite::Rect{ 0, 543, 2008131300, 2008131301 });
9958
9959 EXPECT_CALL(GLProxy, Viewport(0, 0, _Width, _Height))
9960 .Times(1);
9961
9962 Render();
9963 };
9964
9965 TestCall(1024, 2048, Component_t::Make(
9966 {
9967 { uT("kind"), uT("Orthographic") },
9968 { uT("width"), 1024 },
9969 { uT("height"), 2048 },
9970 }));
9971
9972 TestCall(2048, 4096, Component_t::Make(
9973 {
9974 { uT("kind"), uT("Perspective") },
9975 { uT("width"), 2048 },
9976 { uT("height"), 4096 },
9977 }));
9978}
9979
9980} // unnamed namespace
Класс входит в проект Covellite.Api Класс формата вертексного буфера.
Определения Vertex.hpp:34