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