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