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>
8#ifndef OpenGLShader_test
10class OpenGLShader_test :
11 public ::testing::Test
22TEST_F(OpenGLShader_test, Test_State_Sampler_Texture_Mipmapping)
24 using GLProxy_t = ::mock::GLProxy;
26 GLProxy_t::GetInstance() = &GLProxy;
28 const Tested_t Example{ Data_t{} };
29 const ITested_t & IExample = Example;
31 auto itStateCreator = IExample.GetCreators().find(uT(
"State"));
32 ASSERT_NE(IExample.GetCreators().end(), itStateCreator);
34 auto itTextureCreator = IExample.GetCreators().find(uT(
"Texture"));
35 ASSERT_NE(IExample.GetCreators().end(), itTextureCreator);
37 auto SamplerRender = itStateCreator->second(Component_t::Make(
39 { uT(
"kind"), uT(
"Sampler") }
41 ASSERT_NE(
nullptr, SamplerRender);
43 auto TextureRender = itTextureCreator->second(Component_t::Make(
45 { uT(
"mipmapping"),
true }
47 ASSERT_NE(
nullptr, TextureRender);
49 using namespace ::testing;
51 EXPECT_CALL(GLProxy, TexParameteri(_, _, _))
58 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, _))
61 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
62 GL_LINEAR_MIPMAP_LINEAR))
65 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
69 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT))
72 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT))
79TEST_F(OpenGLShader_test, Test_State_Sampler_TextureArray_Mipmapping)
81 using GLProxy_t = ::mock::GLProxy;
83 GLProxy_t::GetInstance() = &GLProxy;
85 const Tested_t Example{ Data_t{} };
86 const ITested_t & IExample = Example;
88 auto itStateCreator = IExample.GetCreators().find(uT(
"State"));
89 ASSERT_NE(IExample.GetCreators().end(), itStateCreator);
91 auto itTextureCreator = IExample.GetCreators().find(uT(
"TextureArray"));
92 ASSERT_NE(IExample.GetCreators().end(), itTextureCreator);
94 auto SamplerRender = itStateCreator->second(Component_t::Make(
96 { uT(
"kind"), uT(
"Sampler") }
98 ASSERT_NE(
nullptr, SamplerRender);
100 auto TextureRender = itTextureCreator->second(Component_t::Make(
102 { uT(
"mipmapping"),
true }
104 ASSERT_NE(
nullptr, TextureRender);
106 using namespace ::testing;
108 EXPECT_CALL(GLProxy, TexParameteri(_, _, _))
115 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, _))
118 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MIN_FILTER,
119 GL_LINEAR_MIPMAP_LINEAR))
122 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_MAG_FILTER,
126 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_S, GL_REPEAT))
129 EXPECT_CALL(GLProxy, TexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_REPEAT))
136TEST_F(OpenGLShader_test, Test_BkSurface_Fail)
138 using GLProxy_t = ::mock::GLProxy;
140 GLProxy_t::GetInstance() = &GLProxy;
142 const Tested_t Example{ Data_t{} };
143 const ITested_t & IExample = Example;
145 auto itCreator = IExample.GetCreators().find(uT(
"BkSurface"));
146 ASSERT_NE(IExample.GetCreators().end(), itCreator);
148 const ::mock::GLuint FrameBufferId = 1910041904;
150 using namespace ::testing;
154 EXPECT_CALL(GLProxy, GenFramebuffers(1))
156 .WillOnce(Return(FrameBufferId));
158 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
161 EXPECT_CALL(GLProxy, CheckFramebufferStatus(GL_FRAMEBUFFER))
163 .WillOnce(Return(1910041903));
165 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, 0))
168 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
171 EXPECT_THROW(itCreator->second(Component_t::Make({})), ::std::exception);
175TEST_F(OpenGLShader_test, Test_BkSurface)
177 const auto TestCall = [](
178 const Component_t::ComponentPtr_t & _pBkSurface,
179 const bool _IsUseMapper,
180 const int _Width,
const int _Height,
181 const int _ExpectedWidth,
const int _ExpectedHeight)
183 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
185 ::mock::GLProxy GLProxy;
188 SettingsData.ClientRect.Top = 34;
190 Tested_t Example{ SettingsData };
191 ITested_t & IExample = Example;
192 IExample.PresentFrame();
194 auto itCreator = IExample.GetCreators().find(uT(
"BkSurface"));
195 ASSERT_NE(IExample.GetCreators().end(), itCreator);
197 constexpr ::mock::GLint TextureId = 1910041735;
198 constexpr ::mock::GLint FrameBufferId = 1910041803;
199 constexpr ::mock::GLint BindingFrameBufferId = 2006162207;
201 const ::std::vector<String_t> Destinations =
213 Object_t TextureComponents;
215 for (::std::size_t i = 0; i < Destinations.size(); i++)
217 const auto pTexture = Component_t::Make(
219 { uT(
"kind"), uT(
"Texture") },
220 { uT(
"destination"), Destinations[i] },
223 if (_IsUseMapper) (*pTexture)[uT(
"mapper")] = BufferMapper_t{};
225 TextureComponents.push_back(pTexture);
228 using namespace ::testing;
232 const int Viewport[] = { 0, 0, _Width, _Height };
234 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
236 .WillOnce(Return(Viewport));
238 EXPECT_CALL(GLProxy, GenFramebuffers(1))
240 .WillOnce(Return(FrameBufferId));
242 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
244 .WillOnce(Return(&BindingFrameBufferId));
246 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
249 ::std::vector<::mock::GLenum> AttachmentIndexes;
251 for (::std::size_t i = 0; i < Destinations.size(); i++)
253 auto Format = GL_DEPTH_COMPONENT;
254 auto Attachment = GL_DEPTH_ATTACHMENT;
256 if (Destinations[i] != uT(
"depth"))
259 Attachment = GL_COLOR_ATTACHMENT0 +
260 static_cast<int>(AttachmentIndexes.size());
261 AttachmentIndexes.push_back(Attachment);
264 EXPECT_CALL(GLProxy, GenTextures(1))
266 .WillOnce(Return(TextureId + i));
268 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId + i))
271 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, _,
272 _ExpectedWidth, _ExpectedHeight, 0, Format, _, ::std::vector<uint8_t>{}))
275 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
278 EXPECT_CALL(GLProxy, GetError())
280 .WillOnce(Return(GL_NO_ERROR));
282 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER, Attachment,
283 GL_TEXTURE_2D, TextureId + i, 0))
287 EXPECT_CALL(GLProxy, CheckFramebufferStatus(GL_FRAMEBUFFER))
289 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
291 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, BindingFrameBufferId))
294 (*_pBkSurface)[uT(
"service")] = TextureComponents;
296 auto Render = itCreator->second(_pBkSurface);
297 ASSERT_NE(
nullptr, Render);
299 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
301 .WillOnce(Return(Viewport));
303 EXPECT_CALL(GLProxy, TexImage2D(_, _, _, _, _, _, _, _, _))
306 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
308 .WillOnce(Return(&BindingFrameBufferId));
310 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
313 EXPECT_CALL(GLProxy, DrawBuffers(AttachmentIndexes))
316 EXPECT_CALL(GLProxy, Viewport(_, _, _, _))
321 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
324 ASSERT_EQ(TextureComponents.size(), Destinations.size());
326 EXPECT_EQ(_ExpectedWidth, (
int)(*_pBkSurface)[uT(
"width")]);
327 EXPECT_EQ(_ExpectedHeight, (
int)(*_pBkSurface)[uT(
"height")]);
329 for (::std::size_t i = 0; i < TextureComponents.size(); i++)
331 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
333 const auto pTextureComponent = TextureComponents[i];
334 const Texture_t::Ptr_t pTexture =
335 (*pTextureComponent)[uT(
"entity")].Default(Texture_t::Ptr_t{});
336 ASSERT_NE(
nullptr, pTexture);
337 EXPECT_EQ(TextureId + i, pTexture->m_TextureId);
338 EXPECT_EQ(_IsUseMapper ? 4 * _ExpectedWidth * _ExpectedHeight : 0,
339 pTexture->m_ReadCopyData.size());
340 EXPECT_EQ(_ExpectedWidth, (
int)(*pTextureComponent)[uT(
"width")].Default(0));
341 EXPECT_EQ(_ExpectedHeight, (
int)(*pTextureComponent)[uT(
"height")].Default(0));
345 TestCall(Component_t::Make({ }),
346 false, 12, 45, 12, 45);
347 TestCall(Component_t::Make({ }),
348 true, 45, 12, 45, 12);
352TEST_F(OpenGLShader_test, Test_BkSurface_RenderDepthOnly)
354 using GLProxy_t = ::mock::GLProxy;
356 GLProxy_t::GetInstance() = &GLProxy;
358 const Tested_t Example{ Data_t{} };
359 const ITested_t & IExample = Example;
361 auto itCreator = IExample.GetCreators().find(uT(
"BkSurface"));
362 ASSERT_NE(IExample.GetCreators().end(), itCreator);
364 const ::mock::GLuint TextureId = 1910041735;
365 const ::mock::GLuint FrameBufferId = 1910041803;
367 using namespace ::testing;
371 const auto pTexture = Component_t::Make(
373 { uT(
"kind"), uT(
"Texture") },
374 { uT(
"destination"), uT(
"depth") },
377 EXPECT_CALL(GLProxy, CheckFramebufferStatus(GL_FRAMEBUFFER))
379 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
381 auto Render = itCreator->second(Component_t::Make(
383 { uT(
"service"), Object_t{ pTexture } }
385 ASSERT_NE(
nullptr, Render);
387 EXPECT_CALL(GLProxy, DrawBuffers(::std::vector<::mock::GLenum>{}))
394TEST_F(OpenGLShader_test, Test_BkSurface_ResizeWindow)
396 const auto TestCall = [](
397 const Component_t::ComponentPtr_t & _pBkSurface,
398 const bool _IsUseMapper,
399 const int _Width,
const int _Height,
400 const int _ExpectedWidth,
const int _ExpectedHeight,
401 const int _ExpectedWidth2,
const int _ExpectedHeight2)
403 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
404 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
406 ::mock::GLProxy GLProxy;
409 SettingsData.ClientRect.Top = 45;
411 Tested_t Example{ SettingsData };
412 ITested_t & IExample = Example;
413 IExample.PresentFrame();
415 auto itCreator = IExample.GetCreators().find(uT(
"BkSurface"));
416 ASSERT_NE(IExample.GetCreators().end(), itCreator);
418 constexpr ::mock::GLuint TextureId = 1910091302;
420 const ::std::vector<String_t> Destinations =
430 Object_t TextureComponents;
432 for (::std::size_t i = 0; i < Destinations.size(); i++)
434 const auto pTexture = Component_t::Make(
436 { uT(
"kind"), uT(
"Texture") },
437 { uT(
"destination"), Destinations[i] },
440 if (_IsUseMapper) (*pTexture)[uT(
"mapper")] = BufferMapper_t{};
442 TextureComponents.push_back(pTexture);
445 using namespace ::testing;
449 const int Viewport[] = { 0, 0, _Width, _Height };
451 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
453 .WillOnce(Return(Viewport));
455 EXPECT_CALL(GLProxy, GetIntegerv(_))
458 for (::std::size_t i = 0; i < Destinations.size(); i++)
460 EXPECT_CALL(GLProxy, GenTextures(1))
462 .WillOnce(Return(TextureId + i));
464 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId + i))
467 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, _, _,
468 _ExpectedWidth, _ExpectedHeight, _, _, _, ::std::vector<uint8_t>{}))
471 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
474 EXPECT_CALL(GLProxy, GetError())
476 .WillOnce(Return(GL_NO_ERROR));
479 EXPECT_CALL(GLProxy, CheckFramebufferStatus(GL_FRAMEBUFFER))
481 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
483 (*_pBkSurface)[uT(
"service")] = TextureComponents;
485 auto Render = itCreator->second(_pBkSurface);
486 ASSERT_NE(
nullptr, Render);
488 EXPECT_EQ(_ExpectedWidth, (
int)(*_pBkSurface)[uT(
"width")]);
489 EXPECT_EQ(_ExpectedHeight, (
int)(*_pBkSurface)[uT(
"height")]);
491 for (::std::size_t i = 0; i < TextureComponents.size(); i++)
493 const auto pTextureComponent = TextureComponents[i];
494 EXPECT_EQ(_ExpectedWidth, (
int)(*pTextureComponent)[uT(
"width")].Default(0));
495 EXPECT_EQ(_ExpectedHeight, (
int)(*pTextureComponent)[uT(
"height")].Default(0));
497 const Texture_t::Ptr_t pTexture =
498 (*pTextureComponent)[uT(
"entity")].Default(Texture_t::Ptr_t{});
499 ASSERT_NE(
nullptr, pTexture);
500 EXPECT_EQ(_IsUseMapper ? _ExpectedWidth * _ExpectedHeight * 4 : 0,
501 pTexture->m_ReadCopyData.size());
504 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
507 EXPECT_CALL(GLProxy, TexImage2D(_, _, _, _, _, _, _, _, _))
510 EXPECT_CALL(GLProxy, GetIntegerv(_))
513 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, _))
516 EXPECT_CALL(GLProxy, Viewport(_, _, _, _))
521 IExample.PresentFrame();
523 const int Viewport2[] = { 0, 0, _Width * 2, _Height * 2 };
525 IExample.ResizeWindow(::covellite::Rect{ 0, 0, _Width * 2, _Height * 2 });
527 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
529 .WillOnce(Return(Viewport2));
531 for (::std::size_t i = 0; i < Destinations.size(); i++)
533 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId + i))
536 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, _, _,
537 _ExpectedWidth2, _ExpectedHeight2, _, _, _, ::std::vector<uint8_t>{}))
540 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
543 EXPECT_CALL(GLProxy, GetError())
545 .WillOnce(Return(GL_NO_ERROR));
548 EXPECT_CALL(GLProxy, GetIntegerv(_))
551 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, _))
554 EXPECT_CALL(GLProxy, Viewport(_, _, _, _))
559 IExample.PresentFrame();
561 EXPECT_EQ(_ExpectedWidth2, (
int)(*_pBkSurface)[uT(
"width")]);
562 EXPECT_EQ(_ExpectedHeight2, (
int)(*_pBkSurface)[uT(
"height")]);
564 for (::std::size_t i = 0; i < TextureComponents.size(); i++)
566 const auto pTextureComponent = TextureComponents[i];
567 EXPECT_EQ(_ExpectedWidth2, (
int)(*pTextureComponent)[uT(
"width")].Default(0));
568 EXPECT_EQ(_ExpectedHeight2, (
int)(*pTextureComponent)[uT(
"height")].Default(0));
570 const Texture_t::Ptr_t pTexture =
571 (*pTextureComponent)[uT(
"entity")].Default(Texture_t::Ptr_t{});
572 ASSERT_NE(
nullptr, pTexture);
573 EXPECT_EQ(_IsUseMapper ? _ExpectedWidth2 * _ExpectedHeight2 * 4 : 0,
574 pTexture->m_ReadCopyData.size());
577 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
580 EXPECT_CALL(GLProxy, TexImage2D(_, _, _, _, _, _, _, _, _))
583 EXPECT_CALL(GLProxy, GetIntegerv(_))
586 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, _))
589 EXPECT_CALL(GLProxy, Viewport(_, _, _, _))
594 IExample.PresentFrame();
597 TestCall(Component_t::Make({ }),
598 false, 45, 67, 45, 67, 90, 134);
599 TestCall(Component_t::Make({ }),
600 true, 45, 67, 45, 67, 90, 134);
604TEST_F(OpenGLShader_test, Test_Shader_InvalidType)
606 const ::std::string ShaderData =
607 "Pixel vs1(Polygon _Value)\r\n"
608 "Pixel vs2(Polyhedron _Value)\r\n";
610 using GLProxy_t = ::mock::GLProxy;
612 GLProxy_t::GetInstance() = &GLProxy;
614 const Tested_t Example{ Data_t{} };
615 const ITested_t & IExample = Example;
617 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
618 ASSERT_NE(IExample.GetCreators().end(), itCreator);
620 const ::mock::GLuint ShaderId = 1908250832;
622 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader)
624 using namespace ::testing;
628 EXPECT_CALL(GLProxy, CreateShader(_))
631 auto Render = itCreator->second(_pShader);
632 EXPECT_EQ(
nullptr, Render);
636 const auto pShader = Component_t::Make(
638 { uT(
"entry"), uT(
"vs1") },
639 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
646 const auto pData = Component_t::Make(
648 { uT(
"kind"), uT(
"Shader") },
649 { uT(
"entry"), uT(
"vs2") },
650 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
653 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
658TEST_F(OpenGLShader_test, Test_Shader_NotExistsEntryPoint)
660 using GLProxy_t = ::mock::GLProxy;
662 GLProxy_t::GetInstance() = &GLProxy;
664 const Tested_t Example{ Data_t{} };
665 const ITested_t & IExample = Example;
667 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
668 ASSERT_NE(IExample.GetCreators().end(), itCreator);
670 const ::mock::GLuint ShaderId = 1908250832;
672 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader)
674 using namespace ::testing;
678 EXPECT_CALL(GLProxy, CreateShader(_))
681 EXPECT_THROW(itCreator->second(_pShader), ::std::exception);
685 const auto pShader = Component_t::Make(
687 { uT(
"entry"), uT(
"vsUnknown") },
694 const auto pData = Component_t::Make(
696 { uT(
"kind"), uT(
"Shader") },
697 { uT(
"entry"), uT(
"vsUnknown") },
700 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
705TEST_F(OpenGLShader_test, Test_Shader_CompileFail)
707 using GLProxy_t = ::mock::GLProxy;
709 GLProxy_t::GetInstance() = &GLProxy;
711 const Tested_t Example{ Data_t{} };
712 const ITested_t & IExample = Example;
714 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
715 ASSERT_NE(IExample.GetCreators().end(), itCreator);
717 const ::mock::GLuint ShaderId = 1908251346;
718 const ::std::string ErrorText =
"Error1908251350";
720 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader)
722 using namespace ::testing;
726 EXPECT_CALL(GLProxy, CreateShader(_))
728 .WillOnce(Return(ShaderId));
730 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, _, _, _))
733 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
736 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
738 .WillOnce(Return(GL_FALSE));
740 EXPECT_CALL(GLProxy, GetShaderInfoLog(ShaderId, 512,
nullptr))
742 .WillOnce(Return(ErrorText.c_str()));
744 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
747 EXPECT_STDEXCEPTION(itCreator->second(_pShader),
748 (
".*Compile shader fail \\[header line: 173\\]: " + ErrorText).c_str());
752 const auto pShader = Component_t::Make(
754 { uT(
"entry"), uT(
"vsFlat") },
761 const auto pData = Component_t::Make(
763 { uT(
"kind"), uT(
"Shader") },
764 { uT(
"entry"), uT(
"vsVolume") },
767 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
771::std::string ConvertTextShader(const ::std::vector<uint8_t> & _ShaderText)
773 return ::std::string{ _ShaderText.cbegin(), _ShaderText.cend() };
777TEST_F(OpenGLShader_test, Test_Shader_CreateVertex_Default)
779 using GLProxy_t = ::mock::GLProxy;
781 GLProxy_t::GetInstance() = &GLProxy;
783 const Tested_t Example{ Data_t{} };
784 const ITested_t & IExample = Example;
786 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
787 ASSERT_NE(IExample.GetCreators().end(), itCreator);
789 const ::mock::GLuint ShaderId = 1908250832;
791 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
792 const ::std::string & _Entry)
794 using namespace ::alicorn::extension::std;
796 const auto ExpectedShaderText =
798 "#define COVELLITE_SHADER_GLSL\r\n"
799 "#define COVELLITE_SHADER_VERTEX\r\n" +
800 ConvertTextShader(::Predefined + ::Data + ::Input + ::Default) +
801 "out Pixel PixelValue;\r\n"
804 " Vertex InputData;\r\n"
805 " InputData.Position = Covellite_VertexPosition;\r\n"
806 " InputData.TexCoord = Covellite_VertexTexCoord;\r\n"
807 " InputData.Extra = Covellite_VertexExtra;\r\n"
808 " PixelValue = " + _Entry +
"(InputData);\r\n"
809 " gl_Position = PixelValue.ScreenPos;\r\n"
812 using namespace ::testing;
816 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
818 .WillOnce(Return(ShaderId));
820 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
823 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
826 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
828 .WillOnce(Return(GL_TRUE));
830 auto Render = itCreator->second(_pShader);
831 ASSERT_NE(
nullptr, Render);
835 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
840 const auto pShader = Component_t::Make(
842 { uT(
"entry"), uT(
"vsFlat") },
845 TestCall(pShader,
"vsFlat");
849 const auto pData = Component_t::Make(
851 { uT(
"kind"), uT(
"Shader") },
852 { uT(
"entry"), uT(
"vsVolume") },
855 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"vsVolume");
860TEST_F(OpenGLShader_test, Test_Shader_CreateVertex)
862 const ::std::string ShaderData =
863 "Pixel vs1(Vertex _Value)\r\n"
864 "Pixel vs2_Dummy(Vertex _Value)\r\n"
865 "Pixel vs2(Vertex _Value)\r\n";
867 using GLProxy_t = ::mock::GLProxy;
869 GLProxy_t::GetInstance() = &GLProxy;
871 const Tested_t Example{ Data_t{} };
872 const ITested_t & IExample = Example;
874 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
875 ASSERT_NE(IExample.GetCreators().end(), itCreator);
877 const ::mock::GLuint ShaderId = 1908250832;
879 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
880 const ::std::string & _Entry)
882 using namespace ::alicorn::extension::std;
884 const auto ExpectedShaderText =
886 "#define COVELLITE_SHADER_GLSL\r\n"
887 "#define COVELLITE_SHADER_VERTEX\r\n" +
888 ConvertTextShader(::Predefined + ::Data + ::Input) + ShaderData +
889 "out Pixel PixelValue;\r\n"
892 " Vertex InputData;\r\n"
893 " InputData.Position = Covellite_VertexPosition;\r\n"
894 " InputData.TexCoord = Covellite_VertexTexCoord;\r\n"
895 " InputData.Extra = Covellite_VertexExtra;\r\n"
896 " PixelValue = " + _Entry +
"(InputData);\r\n"
897 " gl_Position = PixelValue.ScreenPos;\r\n"
900 using namespace ::testing;
904 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
906 .WillOnce(Return(ShaderId));
908 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
911 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
914 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
916 .WillOnce(Return(GL_TRUE));
918 auto Render = itCreator->second(_pShader);
919 ASSERT_NE(
nullptr, Render);
923 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
928 const auto pShader = Component_t::Make(
930 { uT(
"entry"), uT(
"vs1") },
931 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
934 TestCall(pShader,
"vs1");
938 const auto pData = Component_t::Make(
940 { uT(
"kind"), uT(
"Shader") },
941 { uT(
"entry"), uT(
"vs2") },
942 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
945 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"vs2");
950TEST_F(OpenGLShader_test, Test_Shader_CreateVertex_Instance_InvalidValue)
952 const ::std::string ShaderData =
953 "Pixel vs1(Vertex _Value)\r\n"
954 "Pixel vs2(Vertex _Value)\r\n";
956 using GLProxy_t = ::mock::GLProxy;
958 GLProxy_t::GetInstance() = &GLProxy;
960 const Tested_t Example{ Data_t{} };
961 const ITested_t & IExample = Example;
963 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
964 ASSERT_NE(IExample.GetCreators().end(), itCreator);
966 using namespace ::testing;
968 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader)
970 EXPECT_CALL(GLProxy, CompileShader(_))
973 EXPECT_THROW(itCreator->second(_pShader), ::std::exception);
977 const auto pShader = Component_t::Make(
979 { uT(
"entry"), uT(
"vs1") },
980 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
981 { uT(
"instance"), uT(
"invalid1909231417") },
988 const auto pData = Component_t::Make(
990 { uT(
"kind"), uT(
"Shader") },
991 { uT(
"entry"), uT(
"vs2") },
992 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
993 { uT(
"instance"), uT(
"invalid1909231418") },
996 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
1001TEST_F(OpenGLShader_test, Test_Shader_CreateVertex_Instance)
1003 const ::std::string ShaderData =
1004 "Pixel vs1(Vertex _Value)\r\n"
1005 "Pixel vs2(Vertex _Value)\r\n";
1007 using GLProxy_t = ::mock::GLProxy;
1009 GLProxy_t::GetInstance() = &GLProxy;
1011 const Tested_t Example{ Data_t{} };
1012 const ITested_t & IExample = Example;
1014 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1015 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1017 const ::mock::GLuint ShaderId = 1908250832;
1019 auto InputData = ConvertTextShader(::Input);
1021 ::boost::algorithm::replace_first(InputData,
1022 "/* place for instance variables */", ::std::string{} +
1023 "COVELLITE_IN float4 iValue1 COVELLITE_INPUT_SEMANTIC(TEXCOORD1);" + (char)0x5C +
"\r\n"
1024 "COVELLITE_IN float4 iValue2 COVELLITE_INPUT_SEMANTIC(TEXCOORD2);" + (char)0x5C +
"\r\n"
1025 "COVELLITE_IN int4 iValue3 COVELLITE_INPUT_SEMANTIC(TEXCOORD3);" + (char)0x5C +
"\r\n"
1026 "COVELLITE_IN float4 iValue4 COVELLITE_INPUT_SEMANTIC(TEXCOORD4);" + (char)0x5C +
"\r\n"
1029 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
1030 const ::std::string & _Entry)
1032 using namespace ::alicorn::extension::std;
1034 const auto ExpectedShaderText =
1036 "#define COVELLITE_SHADER_GLSL\r\n"
1037 "#define COVELLITE_SHADER_VERTEX\r\n" +
1038 ConvertTextShader(::Predefined + ::Data) + InputData + ShaderData +
1039 "out Pixel PixelValue;\r\n"
1042 " Vertex InputData;\r\n"
1043 " InputData.Position = Covellite_VertexPosition;\r\n"
1044 " InputData.TexCoord = Covellite_VertexTexCoord;\r\n"
1045 " InputData.Extra = Covellite_VertexExtra;\r\n"
1046 " InputData.iValue1 = iValue1;\r\n"
1047 " InputData.iValue2 = iValue2;\r\n"
1048 " InputData.iValue3 = iValue3;\r\n"
1049 " InputData.iValue4 = iValue4;\r\n"
1050 " PixelValue = " + _Entry +
"(InputData);\r\n"
1051 " gl_Position = PixelValue.ScreenPos;\r\n"
1054 using namespace ::testing;
1058 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
1060 .WillOnce(Return(ShaderId));
1062 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
1065 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1068 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1070 .WillOnce(Return(GL_TRUE));
1072 auto Render = itCreator->second(_pShader);
1073 ASSERT_NE(
nullptr, Render);
1077 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1082 const auto pShader = Component_t::Make(
1084 { uT(
"entry"), uT(
"vs1") },
1085 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1086 { uT(
"instance"), uT(
"f4f4i4f4") },
1089 TestCall(pShader,
"vs1");
1093 const auto pData = Component_t::Make(
1095 { uT(
"kind"), uT(
"Shader") },
1096 { uT(
"entry"), uT(
"vs2") },
1097 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1098 { uT(
"instance"), uT(
"f4f4i4f4") },
1101 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"vs2");
1106TEST_F(OpenGLShader_test, Test_Shader_CreatePixel_Default)
1108 using GLProxy_t = ::mock::GLProxy;
1110 GLProxy_t::GetInstance() = &GLProxy;
1112 const Tested_t Example{ Data_t{} };
1113 const ITested_t & IExample = Example;
1115 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1116 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1118 const ::mock::GLuint ShaderId = 1908250832;
1120 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
1121 const ::std::string & _Entry)
1123 using namespace ::alicorn::extension::std;
1125 const auto ExpectedShaderText =
1127 "#define COVELLITE_SHADER_GLSL\r\n"
1128 "#define COVELLITE_SHADER_PIXEL\r\n" +
1129 ConvertTextShader(::Predefined + ::Data + ::Input + ::Default) +
1130 "in Pixel PixelValue;\r\n"
1131 "out vec4 Covellite_OutPixelColor;\r\n"
1134 " Covellite_OutPixelColor = " + _Entry +
"(PixelValue);\r\n"
1137 using namespace ::testing;
1141 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1143 .WillOnce(Return(ShaderId));
1145 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
1148 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1151 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1153 .WillOnce(Return(GL_TRUE));
1155 auto Render = itCreator->second(_pShader);
1156 ASSERT_NE(
nullptr, Render);
1160 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1165 const auto pShader = Component_t::Make(
1167 { uT(
"entry"), uT(
"psColored") },
1170 TestCall(pShader,
"psColored");
1174 const auto pData = Component_t::Make(
1176 { uT(
"kind"), uT(
"Shader") },
1177 { uT(
"entry"), uT(
"psTextured") },
1180 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"psTextured");
1185TEST_F(OpenGLShader_test, Test_Shader_CreatePixel_SingleTarget)
1187 const ::std::string ShaderData =
1188 "float4 ps1(Pixel _Value)\r\n"
1189 "vec4 ps2_Dummy(Pixel _Value)\r\n"
1190 "vec4 ps2(Pixel _Value)\r\n";
1192 using GLProxy_t = ::mock::GLProxy;
1194 GLProxy_t::GetInstance() = &GLProxy;
1196 const Tested_t Example{ Data_t{} };
1197 const ITested_t & IExample = Example;
1199 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1200 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1202 const ::mock::GLuint ShaderId = 1908250832;
1204 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
1205 const ::std::string & _Entry)
1207 using namespace ::alicorn::extension::std;
1209 const auto ExpectedShaderText =
1211 "#define COVELLITE_SHADER_GLSL\r\n"
1212 "#define COVELLITE_SHADER_PIXEL\r\n" +
1213 ConvertTextShader(::Predefined + ::Data + ::Input) + ShaderData +
1214 "in Pixel PixelValue;\r\n"
1215 "out vec4 Covellite_OutPixelColor;\r\n"
1218 " Covellite_OutPixelColor = " + _Entry +
"(PixelValue);\r\n"
1221 using namespace ::testing;
1225 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1227 .WillOnce(Return(ShaderId));
1229 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
1232 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1235 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1237 .WillOnce(Return(GL_TRUE));
1239 auto Render = itCreator->second(_pShader);
1240 ASSERT_NE(
nullptr, Render);
1244 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1249 const auto pShader = Component_t::Make(
1251 { uT(
"entry"), uT(
"ps1") },
1252 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1255 TestCall(pShader,
"ps1");
1259 const auto pData = Component_t::Make(
1261 { uT(
"kind"), uT(
"Shader") },
1262 { uT(
"entry"), uT(
"ps2") },
1263 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1266 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"ps2");
1271TEST_F(OpenGLShader_test, Test_Shader_CreatePixel_MultiTarget)
1273 const ::std::string ShaderData =
1274 "Multi1910031832 ps(Pixel _Value)\r\n";
1276 using GLProxy_t = ::mock::GLProxy;
1278 GLProxy_t::GetInstance() = &GLProxy;
1280 const Tested_t Example{ Data_t{} };
1281 const ITested_t & IExample = Example;
1283 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1284 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1286 const ::mock::GLuint ShaderId = 1908250832;
1288 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
1289 const ::std::string & _Entry)
1291 using namespace ::alicorn::extension::std;
1293 const auto ExpectedShaderText =
1295 "#define COVELLITE_SHADER_GLSL\r\n"
1296 "#define COVELLITE_SHADER_PIXEL\r\n" +
1297 ConvertTextShader(::Predefined + ::Data + ::Input) + ShaderData +
1298 "in Pixel PixelValue;\r\n"
1301 " Covellite_MultiOutPixelColor = " + _Entry +
"(PixelValue).Target;\r\n"
1304 using namespace ::testing;
1308 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1310 .WillOnce(Return(ShaderId));
1312 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
1315 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1318 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1320 .WillOnce(Return(GL_TRUE));
1322 auto Render = itCreator->second(_pShader);
1323 ASSERT_NE(
nullptr, Render);
1327 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1332 const auto pShader = Component_t::Make(
1334 { uT(
"entry"), uT(
"ps") },
1335 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1338 TestCall(pShader,
"ps");
1342 const auto pData = Component_t::Make(
1344 { uT(
"kind"), uT(
"Shader") },
1345 { uT(
"entry"), uT(
"ps") },
1346 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1349 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"ps");
1354TEST_F(OpenGLShader_test, Test_Shader_CreatePixel_NoReturn)
1356 const ::std::string ShaderData =
1357 "void ps(Pixel _Value)\r\n";
1359 using GLProxy_t = ::mock::GLProxy;
1361 GLProxy_t::GetInstance() = &GLProxy;
1363 const Tested_t Example{ Data_t{} };
1364 const ITested_t & IExample = Example;
1366 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1367 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1369 const ::mock::GLuint ShaderId = 1908250832;
1371 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
1372 const ::std::string & _Entry)
1374 using namespace ::alicorn::extension::std;
1376 const auto ExpectedShaderText =
1378 "#define COVELLITE_SHADER_GLSL\r\n"
1379 "#define COVELLITE_SHADER_PIXEL\r\n" +
1380 ConvertTextShader(::Predefined + ::Data + ::Input) + ShaderData +
1381 "in Pixel PixelValue;\r\n"
1384 " " + _Entry +
"(PixelValue);\r\n"
1387 using namespace ::testing;
1391 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1393 .WillOnce(Return(ShaderId));
1395 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
1398 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1401 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1403 .WillOnce(Return(GL_TRUE));
1405 auto Render = itCreator->second(_pShader);
1406 ASSERT_NE(
nullptr, Render);
1410 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1415 const auto pShader = Component_t::Make(
1417 { uT(
"entry"), uT(
"ps") },
1418 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1421 TestCall(pShader,
"ps");
1425 const auto pData = Component_t::Make(
1427 { uT(
"kind"), uT(
"Shader") },
1428 { uT(
"entry"), uT(
"ps") },
1429 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1432 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"ps");
1437TEST_F(OpenGLShader_test, Test_Shader_UsingProgram_DeleteVertexShader)
1439 const ::std::string ShaderData =
1440 "Pixel vs(Vertex _Value)\r\n"
1441 "float4 ps(Pixel _Value)\r\n";
1443 using GLProxy_t = ::mock::GLProxy;
1445 GLProxy_t::GetInstance() = &GLProxy;
1447 const Tested_t Example{ Data_t{} };
1448 const ITested_t & IExample = Example;
1450 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1451 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1453 const auto pVertexShader0 = Component_t::Make(
1455 { uT(
"entry"), uT(
"vs") },
1456 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1459 const auto pVertexShader1 = Component_t::Make(
1461 { uT(
"entry"), uT(
"vs") },
1462 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1465 const auto pPixelShader0 = Component_t::Make(
1467 { uT(
"entry"), uT(
"ps") },
1468 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1471 const auto pPixelShader1 = Component_t::Make(
1473 { uT(
"entry"), uT(
"ps") },
1474 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1477 const ::mock::GLuint VertexShader0Id = 1908251613;
1478 const ::mock::GLuint VertexShader1Id = 1908251614;
1479 const ::mock::GLuint PixelShader0Id = 1908251615;
1480 const ::mock::GLuint PixelShader1Id = 1908251616;
1482 const ::mock::GLuint Program00Id = 1908251641;
1483 const ::mock::GLuint Program01Id = 1908251652;
1484 const ::mock::GLuint Program10Id = 1908251653;
1485 const ::mock::GLuint Program11Id = 1908251654;
1487 using namespace ::testing;
1489 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1491 .WillOnce(Return(PixelShader0Id))
1492 .WillOnce(Return(PixelShader1Id));
1494 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
1496 .WillOnce(Return(VertexShader0Id))
1497 .WillOnce(Return(VertexShader1Id));
1499 auto PixelShaderRender0 = itCreator->second(pPixelShader0);
1500 ASSERT_NE(
nullptr, PixelShaderRender0);
1502 auto PixelShaderRender1 = itCreator->second(pPixelShader1);
1503 ASSERT_NE(
nullptr, PixelShaderRender1);
1505 auto VertexShaderRender0 = itCreator->second(pVertexShader0);
1506 ASSERT_NE(
nullptr, VertexShaderRender0);
1511 auto VertexShaderRender1 = itCreator->second(pVertexShader1);
1512 ASSERT_NE(
nullptr, VertexShaderRender1);
1514 const auto TestCreateProgram = [&](
1515 const ::mock::GLuint _ProgramId,
1516 const ::mock::GLuint _VertexShaderId,
1517 const ::mock::GLuint _PixelShaderId)
1519 EXPECT_CALL(GLProxy, CreateProgram())
1521 .WillOnce(Return(_ProgramId));
1523 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _VertexShaderId))
1526 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _PixelShaderId))
1529 EXPECT_CALL(GLProxy, LinkProgram(_ProgramId))
1532 EXPECT_CALL(GLProxy, GetProgramiv(_ProgramId, GL_LINK_STATUS))
1534 .WillOnce(Return(GL_TRUE));
1539 EXPECT_CALL(GLProxy, CreateProgram())
1542 VertexShaderRender0();
1544 TestCreateProgram(Program00Id, VertexShader0Id, PixelShader0Id);
1546 EXPECT_CALL(GLProxy, UseProgram(Program00Id))
1549 PixelShaderRender0();
1551 TestCreateProgram(Program10Id, VertexShader1Id, PixelShader0Id);
1553 EXPECT_CALL(GLProxy, UseProgram(Program10Id))
1556 VertexShaderRender1();
1558 TestCreateProgram(Program11Id, VertexShader1Id, PixelShader1Id);
1560 EXPECT_CALL(GLProxy, UseProgram(Program11Id))
1563 PixelShaderRender1();
1565 TestCreateProgram(Program01Id, VertexShader0Id, PixelShader1Id);
1567 EXPECT_CALL(GLProxy, UseProgram(Program01Id))
1570 VertexShaderRender0();
1574 EXPECT_CALL(GLProxy, CreateProgram())
1577 EXPECT_CALL(GLProxy, UseProgram(Program00Id))
1580 PixelShaderRender0();
1582 EXPECT_CALL(GLProxy, CreateProgram())
1585 EXPECT_CALL(GLProxy, UseProgram(Program10Id))
1588 VertexShaderRender1();
1590 EXPECT_CALL(GLProxy, CreateProgram())
1593 EXPECT_CALL(GLProxy, UseProgram(Program11Id))
1596 PixelShaderRender1();
1598 EXPECT_CALL(GLProxy, CreateProgram())
1601 EXPECT_CALL(GLProxy, UseProgram(Program01Id))
1604 VertexShaderRender0();
1606 EXPECT_CALL(GLProxy, DeleteProgram(Program10Id))
1609 EXPECT_CALL(GLProxy, DeleteProgram(Program11Id))
1612 EXPECT_CALL(GLProxy, DeleteShader(VertexShader1Id))
1616 EXPECT_CALL(GLProxy, DeleteProgram(Program00Id))
1619 EXPECT_CALL(GLProxy, DeleteProgram(Program01Id))
1622 EXPECT_CALL(GLProxy, DeleteShader(VertexShader0Id))
1625 EXPECT_CALL(GLProxy, DeleteShader(PixelShader1Id))
1628 EXPECT_CALL(GLProxy, DeleteShader(PixelShader0Id))
1633TEST_F(OpenGLShader_test, Test_Shader_UsingProgram_DeletePixelShader)
1635 const ::std::string ShaderData =
1636 "Pixel vs(Vertex _Value)\r\n"
1637 "float4 ps(Pixel _Value)\r\n";
1639 using GLProxy_t = ::mock::GLProxy;
1641 GLProxy_t::GetInstance() = &GLProxy;
1643 const Tested_t Example{ Data_t{} };
1644 const ITested_t & IExample = Example;
1646 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1647 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1649 const auto pVertexShader0 = Component_t::Make(
1651 { uT(
"entry"), uT(
"vs") },
1652 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1655 const auto pVertexShader1 = Component_t::Make(
1657 { uT(
"entry"), uT(
"vs") },
1658 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1661 const auto pPixelShader0 = Component_t::Make(
1663 { uT(
"entry"), uT(
"ps") },
1664 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1667 const auto pPixelShader1 = Component_t::Make(
1669 { uT(
"entry"), uT(
"ps") },
1670 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1673 const ::mock::GLuint VertexShader0Id = 1908251613;
1674 const ::mock::GLuint VertexShader1Id = 1908251614;
1675 const ::mock::GLuint PixelShader0Id = 1908251615;
1676 const ::mock::GLuint PixelShader1Id = 1908251616;
1678 const ::mock::GLuint Program00Id = 1908251641;
1679 const ::mock::GLuint Program01Id = 1908251652;
1680 const ::mock::GLuint Program10Id = 1908251653;
1681 const ::mock::GLuint Program11Id = 1908251654;
1683 using namespace ::testing;
1685 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
1687 .WillOnce(Return(VertexShader0Id))
1688 .WillOnce(Return(VertexShader1Id));
1690 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1692 .WillOnce(Return(PixelShader0Id))
1693 .WillOnce(Return(PixelShader1Id));
1695 auto VertexShaderRender0 = itCreator->second(pVertexShader0);
1696 ASSERT_NE(
nullptr, VertexShaderRender0);
1698 auto VertexShaderRender1 = itCreator->second(pVertexShader1);
1699 ASSERT_NE(
nullptr, VertexShaderRender1);
1701 auto PixelShaderRender0 = itCreator->second(pPixelShader0);
1702 ASSERT_NE(
nullptr, PixelShaderRender0);
1707 auto PixelShaderRender1 = itCreator->second(pPixelShader1);
1708 ASSERT_NE(
nullptr, PixelShaderRender1);
1710 const auto TestCreateProgram = [&](
1711 const ::mock::GLuint _ProgramId,
1712 const ::mock::GLuint _VertexShaderId,
1713 const ::mock::GLuint _PixelShaderId)
1715 EXPECT_CALL(GLProxy, CreateProgram())
1717 .WillOnce(Return(_ProgramId));
1719 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _VertexShaderId))
1722 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _PixelShaderId))
1725 EXPECT_CALL(GLProxy, LinkProgram(_ProgramId))
1728 EXPECT_CALL(GLProxy, GetProgramiv(_ProgramId, GL_LINK_STATUS))
1730 .WillOnce(Return(GL_TRUE));
1735 EXPECT_CALL(GLProxy, CreateProgram())
1738 VertexShaderRender0();
1740 TestCreateProgram(Program00Id, VertexShader0Id, PixelShader0Id);
1742 EXPECT_CALL(GLProxy, UseProgram(Program00Id))
1745 PixelShaderRender0();
1747 TestCreateProgram(Program10Id, VertexShader1Id, PixelShader0Id);
1749 EXPECT_CALL(GLProxy, UseProgram(Program10Id))
1752 VertexShaderRender1();
1754 TestCreateProgram(Program11Id, VertexShader1Id, PixelShader1Id);
1756 EXPECT_CALL(GLProxy, UseProgram(Program11Id))
1759 PixelShaderRender1();
1761 TestCreateProgram(Program01Id, VertexShader0Id, PixelShader1Id);
1763 EXPECT_CALL(GLProxy, UseProgram(Program01Id))
1766 VertexShaderRender0();
1770 EXPECT_CALL(GLProxy, CreateProgram())
1773 EXPECT_CALL(GLProxy, UseProgram(Program00Id))
1776 PixelShaderRender0();
1778 EXPECT_CALL(GLProxy, CreateProgram())
1781 EXPECT_CALL(GLProxy, UseProgram(Program10Id))
1784 VertexShaderRender1();
1786 EXPECT_CALL(GLProxy, CreateProgram())
1789 EXPECT_CALL(GLProxy, UseProgram(Program11Id))
1792 PixelShaderRender1();
1794 EXPECT_CALL(GLProxy, CreateProgram())
1797 EXPECT_CALL(GLProxy, UseProgram(Program01Id))
1800 VertexShaderRender0();
1802 EXPECT_CALL(GLProxy, DeleteProgram(Program01Id))
1805 EXPECT_CALL(GLProxy, DeleteProgram(Program11Id))
1808 EXPECT_CALL(GLProxy, DeleteShader(PixelShader1Id))
1812 EXPECT_CALL(GLProxy, DeleteProgram(Program00Id))
1815 EXPECT_CALL(GLProxy, DeleteProgram(Program10Id))
1818 EXPECT_CALL(GLProxy, DeleteShader(PixelShader0Id))
1821 EXPECT_CALL(GLProxy, DeleteShader(VertexShader1Id))
1824 EXPECT_CALL(GLProxy, DeleteShader(VertexShader0Id))
1829TEST_F(OpenGLShader_test, Test_Shader_UsingProgram_LinkProgramFail)
1831 using namespace ::alicorn::extension::std;
1833 const ::std::string ShaderData =
1834 "Pixel vs(Vertex _Value)\r\n"
1835 "float4 ps(Pixel _Value)\r\n";
1837 const ::std::string ErrorText =
"Error1908291952";
1838 const auto LinkFailLogText = uT(
"Warning: Link program fail: ") +
1839 string_cast<String, Encoding::UTF8>(ErrorText);
1841 using LoggerProxy_t = ::mock::alicorn::modules::logger::LoggerProxy;
1842 LoggerProxy_t LoggerProxy;
1843 LoggerProxy_t::GetInstance() = &LoggerProxy;
1845 using GLProxy_t = ::mock::GLProxy;
1847 GLProxy_t::GetInstance() = &GLProxy;
1849 const Tested_t Example{ Data_t{} };
1850 const ITested_t & IExample = Example;
1852 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1853 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1855 const auto pVertexShader0 = Component_t::Make(
1857 { uT(
"entry"), uT(
"vs") },
1858 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1861 const auto pVertexShader1 = Component_t::Make(
1863 { uT(
"entry"), uT(
"vs") },
1864 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1867 const auto pPixelShader0 = Component_t::Make(
1869 { uT(
"entry"), uT(
"ps") },
1870 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1873 const auto pPixelShader1 = Component_t::Make(
1875 { uT(
"entry"), uT(
"ps") },
1876 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1879 const ::mock::GLuint VertexShader0Id = 1908251613;
1880 const ::mock::GLuint VertexShader1Id = 1908251614;
1881 const ::mock::GLuint PixelShader0Id = 1908251615;
1882 const ::mock::GLuint PixelShader1Id = 1908251616;
1884 const ::mock::GLuint Program00Id = 1908251641;
1885 const ::mock::GLuint Program01Id = 1908251652;
1886 const ::mock::GLuint Program10Id = 1908251653;
1887 const ::mock::GLuint Program11Id = 1908251654;
1889 using namespace ::testing;
1891 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
1893 .WillOnce(Return(VertexShader0Id))
1894 .WillOnce(Return(VertexShader1Id));
1896 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1898 .WillOnce(Return(PixelShader0Id))
1899 .WillOnce(Return(PixelShader1Id));
1901 auto VertexShaderRender0 = itCreator->second(pVertexShader0);
1902 ASSERT_NE(
nullptr, VertexShaderRender0);
1904 auto VertexShaderRender1 = itCreator->second(pVertexShader1);
1905 ASSERT_NE(
nullptr, VertexShaderRender1);
1907 auto PixelShaderRender0 = itCreator->second(pPixelShader0);
1908 ASSERT_NE(
nullptr, PixelShaderRender0);
1913 auto PixelShaderRender1 = itCreator->second(pPixelShader1);
1914 ASSERT_NE(
nullptr, PixelShaderRender1);
1916 const auto TestCreateProgram = [&](
1917 const ::mock::GLuint _ProgramId,
1918 const ::mock::GLuint _VertexShaderId,
1919 const ::mock::GLuint _PixelShaderId,
1920 const Render_t & _Render)
1922 EXPECT_CALL(GLProxy, CreateProgram())
1924 .WillOnce(Return(_ProgramId));
1926 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _VertexShaderId))
1929 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _PixelShaderId))
1932 EXPECT_CALL(GLProxy, LinkProgram(_ProgramId))
1935 EXPECT_CALL(GLProxy, GetProgramiv(_ProgramId, GL_LINK_STATUS))
1937 .WillOnce(Return(GL_FALSE));
1939 EXPECT_CALL(GLProxy, GetProgramInfoLog(_ProgramId, 512,
nullptr))
1941 .WillOnce(Return(ErrorText.c_str()));
1943 EXPECT_CALL(LoggerProxy, ToLog(Eq(LinkFailLogText)))
1949 EXPECT_CALL(GLProxy, CreateProgram())
1952 EXPECT_CALL(GLProxy, UseProgram(_))
1955 VertexShaderRender0();
1957 TestCreateProgram(Program00Id, VertexShader0Id, PixelShader0Id,
1958 PixelShaderRender0);
1960 TestCreateProgram(Program10Id, VertexShader1Id, PixelShader0Id,
1961 VertexShaderRender1);
1963 TestCreateProgram(Program11Id, VertexShader1Id, PixelShader1Id,
1964 PixelShaderRender1);
1966 TestCreateProgram(Program01Id, VertexShader0Id, PixelShader1Id,
1967 VertexShaderRender0);
1969 EXPECT_CALL(GLProxy, DeleteProgram(Program01Id))
1972 EXPECT_CALL(GLProxy, DeleteProgram(Program11Id))
1976 EXPECT_CALL(GLProxy, DeleteProgram(Program00Id))
1979 EXPECT_CALL(GLProxy, DeleteProgram(Program10Id))
1984TEST_F(OpenGLShader_test, Test_Texture_Default)
1986 using GLProxy_t = ::mock::GLProxy;
1988 GLProxy_t::GetInstance() = &GLProxy;
1990 const Tested_t Example{ Data_t{} };
1991 const ITested_t & IExample = Example;
1993 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
1994 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1996 const ::mock::GLuint TextureId = 1812181809;
1997 const ::mock::GLint ProgramId = 1908221258;
1998 const ::mock::GLint LocationId = 1908221259;
2000 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pTexture,
2001 const ::std::vector<uint8_t> & _Source,
const int _Width,
const int _Height)
2003 using namespace ::testing;
2007 EXPECT_CALL(GLProxy, GenTextures(1))
2009 .WillOnce(Return(TextureId));
2011 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2014 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
2016 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
2019 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2022 EXPECT_CALL(GLProxy, GetError())
2024 .WillOnce(Return(GL_NO_ERROR));
2026 auto Render = itCreator->second(_pTexture);
2027 ASSERT_NE(
nullptr, Render);
2029 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0))
2032 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2035 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2037 .WillOnce(Return(&ProgramId));
2039 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"TexDiffuse")))
2041 .WillOnce(Return(LocationId));
2043 EXPECT_CALL(GLProxy, Uniform1i(LocationId, 0))
2048 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
2053 ::std::vector<uint8_t> Source =
2055 0x20, 0x06, 0x15, 0x12, 0x28,
2056 0x20, 0x06, 0x15, 0x12, 0x28,
2057 0x20, 0x06, 0x15, 0x12, 0x28,
2058 0x20, 0x06, 0x15, 0x12, 0x28,
2059 0x20, 0x06, 0x15, 0x12, 0x28,
2060 0x20, 0x06, 0x15, 0x12, 0x28,
2061 0x20, 0x06, 0x15, 0x12, 0x28,
2062 0x20, 0x06, 0x15, 0x12, 0x28,
2064 IntroduceBufferSize(Source);
2066 const int Width = 1812181807;
2067 const int Height = 1812181808;
2069 const auto pTexture = Component_t::Make(
2071 { uT(
"content"), Source },
2072 { uT(
"width"), Width },
2073 { uT(
"height"), Height },
2076 TestCall(pTexture, Source, Width, Height);
2080 ::std::vector<uint8_t> Source =
2082 0x20, 0x06, 0x15, 0x12, 0x29,
2083 0x20, 0x06, 0x15, 0x12, 0x29,
2084 0x20, 0x06, 0x15, 0x12, 0x29,
2085 0x20, 0x06, 0x15, 0x12, 0x29,
2086 0x20, 0x06, 0x15, 0x12, 0x29,
2088 IntroduceBufferSize(Source);
2090 const int Width = 1907251057;
2091 const int Height = 1907251058;
2093 const auto pData = Component_t::Make(
2095 { uT(
"kind"), uT(
"Texture") },
2096 { uT(
"content"), Source },
2097 { uT(
"width"), Width },
2098 { uT(
"height"), Height },
2101 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }), Source, Width, Height);
2106TEST_F(OpenGLShader_test, Test_Texture_NameAndIndex)
2108 using GLProxy_t = ::mock::GLProxy;
2110 GLProxy_t::GetInstance() = &GLProxy;
2112 const Tested_t Example{ Data_t{} };
2113 const ITested_t & IExample = Example;
2115 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
2116 ASSERT_NE(IExample.GetCreators().end(), itCreator);
2118 const ::mock::GLuint TextureId = 1908221839;
2119 const ::mock::GLint ProgramId = 1908221840;
2120 const ::mock::GLint LocationId = 1908221841;
2122 const auto TestCall = [&](
2123 const Component_t::ComponentPtr_t & _pTexture,
2124 const ::std::vector<uint8_t> & _Source,
2125 const int _Width,
const int _Height,
2126 const ::std::size_t _Index,
2127 const ::std::string & _TexName)
2129 const auto Index =
static_cast<::mock::GLint
>(_Index);
2131 using namespace ::testing;
2135 EXPECT_CALL(GLProxy, GenTextures(1))
2137 .WillOnce(Return(TextureId));
2139 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2142 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
2144 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
2147 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2150 EXPECT_CALL(GLProxy, GetError())
2152 .WillOnce(Return(GL_NO_ERROR));
2154 EXPECT_CALL(GLProxy, GenFramebuffers(1))
2157 auto Render = itCreator->second(_pTexture);
2158 ASSERT_NE(
nullptr, Render);
2160 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
2163 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2166 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2168 .WillOnce(Return(&ProgramId));
2170 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
2172 .WillOnce(Return(LocationId));
2174 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
2177 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
2182 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
2186 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
2188 { uT(
"TexEnvironment"),
"TexEnvironment" },
2189 { uT(
"TexReflection"),
"TexReflection" },
2190 { uT(
"TexBaseColor"),
"TexBaseColor" },
2193 for (
int Index = 0; Index < Names.size(); Index++)
2195 ::std::vector<uint8_t> Source =
2197 0x20, 0x06, 0x15, 0x12, 0x30,
2198 0x20, 0x06, 0x15, 0x12, 0x30,
2199 0x20, 0x06, 0x15, 0x12, 0x30,
2200 0x20, 0x06, 0x15, 0x12, 0x30,
2201 0x20, 0x06, 0x15, 0x12, 0x30,
2203 IntroduceBufferSize(Source);
2206 const int Width = 1908221843;
2207 const int Height = 1908221844;
2209 const auto pTexture = Component_t::Make(
2211 { uT(
"content"), Source },
2212 { uT(
"width"), Width },
2213 { uT(
"height"), Height },
2214 { uT(
"name"), Names[Index].first },
2215 { uT(
"index"), Index },
2219 Source, Width, Height, Index, Names[Index].second);
2223 const int Width = 1908221845;
2224 const int Height = 1908221847;
2226 const auto pData = Component_t::Make(
2228 { uT(
"kind"), uT(
"Texture") },
2229 { uT(
"content"), Source },
2230 { uT(
"width"), Width },
2231 { uT(
"height"), Height },
2232 { uT(
"name"), Names[Index].first },
2233 { uT(
"index"), Index },
2236 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2237 Source, Width, Height, Index, Names[Index].second);
2241 const int Width = 1908221843;
2242 const int Height = 1908221844;
2244 const auto pTexture = Component_t::Make(
2246 { uT(
"content"), Source },
2247 { uT(
"width"), Width },
2248 { uT(
"height"), Height },
2249 { uT(
"name"), Names[Index].first },
2250 { uT(
"index"), Index },
2251 { uT(
"mipmapping"),
false },
2255 Source, Width, Height, Index, Names[Index].second);
2259 const int Width = 1908221845;
2260 const int Height = 1908221847;
2262 const auto pData = Component_t::Make(
2264 { uT(
"kind"), uT(
"Texture") },
2265 { uT(
"content"), Source },
2266 { uT(
"width"), Width },
2267 { uT(
"height"), Height },
2268 { uT(
"name"), Names[Index].first },
2269 { uT(
"index"), Index },
2270 { uT(
"mipmapping"),
false },
2273 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2274 Source, Width, Height, Index, Names[Index].second);
2277 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
2279 { uT(
"albedo"),
"TexAlbedo" },
2280 { uT(
"metalness"),
"TexMetalness" },
2281 { uT(
"roughness"),
"TexRoughness" },
2282 { uT(
"normal"),
"TexNormal" },
2283 { uT(
"occlusion"),
"TexOcclusion" },
2287 for (::std::size_t i = 0; i < Destinations.size(); i++)
2290 const int Width = 1908221843;
2291 const int Height = 1908221844;
2293 const auto pTexture = Component_t::Make(
2295 { uT(
"content"), Source },
2296 { uT(
"width"), Width },
2297 { uT(
"height"), Height },
2298 { uT(
"name"), Names[Index].first },
2299 { uT(
"index"), Index },
2300 { uT(
"destination"), Destinations[i].first },
2304 Source, Width, Height, Index, Names[Index].second);
2308 const int Width = 1908221845;
2309 const int Height = 1908221847;
2311 const auto pData = Component_t::Make(
2313 { uT(
"kind"), uT(
"Texture") },
2314 { uT(
"content"), Source },
2315 { uT(
"width"), Width },
2316 { uT(
"height"), Height },
2317 { uT(
"name"), Names[Index].first },
2318 { uT(
"index"), Index },
2319 { uT(
"destination"), Destinations[i].first },
2322 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2323 Source, Width, Height, Index, Names[Index].second);
2327 const int Width = 1908221843;
2328 const int Height = 1908221844;
2330 const auto pTexture = Component_t::Make(
2332 { uT(
"content"), Source },
2333 { uT(
"width"), Width },
2334 { uT(
"height"), Height },
2335 { uT(
"name"), Names[Index].first },
2336 { uT(
"index"), Index },
2337 { uT(
"destination"), Destinations[i].first },
2338 { uT(
"mipmapping"),
false },
2342 Source, Width, Height, Index, Names[Index].second);
2346 const int Width = 1908221845;
2347 const int Height = 1908221847;
2349 const auto pData = Component_t::Make(
2351 { uT(
"kind"), uT(
"Texture") },
2352 { uT(
"content"), Source },
2353 { uT(
"width"), Width },
2354 { uT(
"height"), Height },
2355 { uT(
"name"), Names[Index].first },
2356 { uT(
"index"), Index },
2357 { uT(
"destination"), Destinations[i].first },
2358 { uT(
"mipmapping"),
false },
2361 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2362 Source, Width, Height, Index, Names[Index].second);
2369TEST_F(OpenGLShader_test, Test_Texture_NameAndIndex_Capacity16)
2371 using GLProxy_t = ::mock::GLProxy;
2373 GLProxy_t::GetInstance() = &GLProxy;
2375 const Tested_t Example{ Data_t{} };
2376 const ITested_t & IExample = Example;
2378 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
2379 ASSERT_NE(IExample.GetCreators().end(), itCreator);
2381 const ::mock::GLuint TextureId = 1908221839;
2382 const ::mock::GLint ProgramId = 1908221840;
2383 const ::mock::GLint LocationId = 1908221841;
2385 const auto TestCall = [&](
2386 const Component_t::ComponentPtr_t & _pTexture,
2387 const ::std::vector<uint8_t> & _Source,
2388 const int _Width,
const int _Height,
2389 const ::std::size_t _Index,
2390 const ::std::string & _TexName)
2392 const auto Index =
static_cast<::mock::GLint
>(_Index);
2394 using namespace ::testing;
2398 EXPECT_CALL(GLProxy, GenTextures(1))
2400 .WillOnce(Return(TextureId));
2402 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2405 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
2407 GL_RGBA, GL_HALF_FLOAT, _Source))
2410 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2413 EXPECT_CALL(GLProxy, GetError())
2415 .WillOnce(Return(GL_NO_ERROR));
2417 EXPECT_CALL(GLProxy, GenFramebuffers(1))
2420 auto Render = itCreator->second(_pTexture);
2421 ASSERT_NE(
nullptr, Render);
2423 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
2426 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2429 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2431 .WillOnce(Return(&ProgramId));
2433 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
2435 .WillOnce(Return(LocationId));
2437 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
2440 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
2445 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
2449 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
2451 { uT(
"TexEnvironment"),
"TexEnvironment" },
2452 { uT(
"TexReflection"),
"TexReflection" },
2453 { uT(
"TexBaseColor"),
"TexBaseColor" },
2456 for (
int Index = 0; Index < Names.size(); Index++)
2458 ::std::vector<uint8_t> Source =
2460 0x20, 0x06, 0x15, 0x12, 0x30,
2461 0x20, 0x06, 0x15, 0x12, 0x30,
2462 0x20, 0x06, 0x15, 0x12, 0x30,
2463 0x20, 0x06, 0x15, 0x12, 0x30,
2464 0x20, 0x06, 0x15, 0x12, 0x30,
2466 IntroduceBufferSize(Source);
2469 const int Width = 1908221843;
2470 const int Height = 1908221844;
2472 const auto pTexture = Component_t::Make(
2474 { uT(
"content"), Source },
2475 { uT(
"width"), Width },
2476 { uT(
"height"), Height },
2477 { uT(
"name"), Names[Index].first },
2478 { uT(
"index"), Index },
2479 { uT(
"capacity"), 16 },
2483 Source, Width, Height, Index, Names[Index].second);
2487 const int Width = 1908221845;
2488 const int Height = 1908221847;
2490 const auto pData = Component_t::Make(
2492 { uT(
"kind"), uT(
"Texture") },
2493 { uT(
"content"), Source },
2494 { uT(
"width"), Width },
2495 { uT(
"height"), Height },
2496 { uT(
"name"), Names[Index].first },
2497 { uT(
"index"), Index },
2498 { uT(
"capacity"), 16 },
2501 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2502 Source, Width, Height, Index, Names[Index].second);
2506 const int Width = 1908221843;
2507 const int Height = 1908221844;
2509 const auto pTexture = Component_t::Make(
2511 { uT(
"content"), Source },
2512 { uT(
"width"), Width },
2513 { uT(
"height"), Height },
2514 { uT(
"name"), Names[Index].first },
2515 { uT(
"index"), Index },
2516 { uT(
"mipmapping"),
false },
2517 { uT(
"capacity"), 16 },
2521 Source, Width, Height, Index, Names[Index].second);
2525 const int Width = 1908221845;
2526 const int Height = 1908221847;
2528 const auto pData = Component_t::Make(
2530 { uT(
"kind"), uT(
"Texture") },
2531 { uT(
"content"), Source },
2532 { uT(
"width"), Width },
2533 { uT(
"height"), Height },
2534 { uT(
"name"), Names[Index].first },
2535 { uT(
"index"), Index },
2536 { uT(
"mipmapping"),
false },
2537 { uT(
"capacity"), 16 },
2540 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2541 Source, Width, Height, Index, Names[Index].second);
2544 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
2546 { uT(
"albedo"),
"TexAlbedo" },
2547 { uT(
"metalness"),
"TexMetalness" },
2548 { uT(
"roughness"),
"TexRoughness" },
2549 { uT(
"normal"),
"TexNormal" },
2550 { uT(
"occlusion"),
"TexOcclusion" },
2554 for (::std::size_t i = 0; i < Destinations.size(); i++)
2557 const int Width = 1908221843;
2558 const int Height = 1908221844;
2560 const auto pTexture = Component_t::Make(
2562 { uT(
"content"), Source },
2563 { uT(
"width"), Width },
2564 { uT(
"height"), Height },
2565 { uT(
"name"), Names[Index].first },
2566 { uT(
"index"), Index },
2567 { uT(
"destination"), Destinations[i].first },
2568 { uT(
"capacity"), 16 },
2572 Source, Width, Height, Index, Names[Index].second);
2576 const int Width = 1908221845;
2577 const int Height = 1908221847;
2579 const auto pData = Component_t::Make(
2581 { uT(
"kind"), uT(
"Texture") },
2582 { uT(
"content"), Source },
2583 { uT(
"width"), Width },
2584 { uT(
"height"), Height },
2585 { uT(
"name"), Names[Index].first },
2586 { uT(
"index"), Index },
2587 { uT(
"destination"), Destinations[i].first },
2588 { uT(
"capacity"), 16 },
2591 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2592 Source, Width, Height, Index, Names[Index].second);
2596 const int Width = 1908221843;
2597 const int Height = 1908221844;
2599 const auto pTexture = Component_t::Make(
2601 { uT(
"content"), Source },
2602 { uT(
"width"), Width },
2603 { uT(
"height"), Height },
2604 { uT(
"name"), Names[Index].first },
2605 { uT(
"index"), Index },
2606 { uT(
"destination"), Destinations[i].first },
2607 { uT(
"mipmapping"),
false },
2608 { uT(
"capacity"), 16 },
2612 Source, Width, Height, Index, Names[Index].second);
2616 const int Width = 1908221845;
2617 const int Height = 1908221847;
2619 const auto pData = Component_t::Make(
2621 { uT(
"kind"), uT(
"Texture") },
2622 { uT(
"content"), Source },
2623 { uT(
"width"), Width },
2624 { uT(
"height"), Height },
2625 { uT(
"name"), Names[Index].first },
2626 { uT(
"index"), Index },
2627 { uT(
"destination"), Destinations[i].first },
2628 { uT(
"mipmapping"),
false },
2629 { uT(
"capacity"), 16 },
2632 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2633 Source, Width, Height, Index, Names[Index].second);
2640TEST_F(OpenGLShader_test, Test_Texture_NameAndIndex_Capacity32)
2642 using GLProxy_t = ::mock::GLProxy;
2644 GLProxy_t::GetInstance() = &GLProxy;
2646 const Tested_t Example{ Data_t{} };
2647 const ITested_t & IExample = Example;
2649 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
2650 ASSERT_NE(IExample.GetCreators().end(), itCreator);
2652 const ::mock::GLuint TextureId = 1908221839;
2653 const ::mock::GLint ProgramId = 1908221840;
2654 const ::mock::GLint LocationId = 1908221841;
2656 const auto TestCall = [&](
2657 const Component_t::ComponentPtr_t & _pTexture,
2658 const ::std::vector<uint8_t> & _Source,
2659 const int _Width,
const int _Height,
2660 const ::std::size_t _Index,
2661 const ::std::string & _TexName)
2663 const auto Index =
static_cast<::mock::GLint
>(_Index);
2665 using namespace ::testing;
2669 EXPECT_CALL(GLProxy, GenTextures(1))
2671 .WillOnce(Return(TextureId));
2673 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2676 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
2678 GL_RGBA, GL_FLOAT, _Source))
2681 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2684 EXPECT_CALL(GLProxy, GetError())
2686 .WillOnce(Return(GL_NO_ERROR));
2688 EXPECT_CALL(GLProxy, GenFramebuffers(1))
2691 auto Render = itCreator->second(_pTexture);
2692 ASSERT_NE(
nullptr, Render);
2694 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
2697 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2700 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2702 .WillOnce(Return(&ProgramId));
2704 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
2706 .WillOnce(Return(LocationId));
2708 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
2711 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
2716 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
2720 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
2722 { uT(
"TexEnvironment"),
"TexEnvironment" },
2723 { uT(
"TexReflection"),
"TexReflection" },
2724 { uT(
"TexBaseColor"),
"TexBaseColor" },
2727 for (
int Index = 0; Index < Names.size(); Index++)
2729 ::std::vector<uint8_t> Source =
2731 0x20, 0x06, 0x15, 0x12, 0x30,
2732 0x20, 0x06, 0x15, 0x12, 0x30,
2733 0x20, 0x06, 0x15, 0x12, 0x30,
2734 0x20, 0x06, 0x15, 0x12, 0x30,
2735 0x20, 0x06, 0x15, 0x12, 0x30,
2737 IntroduceBufferSize(Source);
2740 const int Width = 1908221843;
2741 const int Height = 1908221844;
2743 const auto pTexture = Component_t::Make(
2745 { uT(
"content"), Source },
2746 { uT(
"width"), Width },
2747 { uT(
"height"), Height },
2748 { uT(
"name"), Names[Index].first },
2749 { uT(
"index"), Index },
2750 { uT(
"capacity"), 32 },
2754 Source, Width, Height, Index, Names[Index].second);
2758 const int Width = 1908221845;
2759 const int Height = 1908221847;
2761 const auto pData = Component_t::Make(
2763 { uT(
"kind"), uT(
"Texture") },
2764 { uT(
"content"), Source },
2765 { uT(
"width"), Width },
2766 { uT(
"height"), Height },
2767 { uT(
"name"), Names[Index].first },
2768 { uT(
"index"), Index },
2769 { uT(
"capacity"), 32 },
2772 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2773 Source, Width, Height, Index, Names[Index].second);
2777 const int Width = 1908221843;
2778 const int Height = 1908221844;
2780 const auto pTexture = Component_t::Make(
2782 { uT(
"content"), Source },
2783 { uT(
"width"), Width },
2784 { uT(
"height"), Height },
2785 { uT(
"name"), Names[Index].first },
2786 { uT(
"index"), Index },
2787 { uT(
"mipmapping"),
false },
2788 { uT(
"capacity"), 32 },
2792 Source, Width, Height, Index, Names[Index].second);
2796 const int Width = 1908221845;
2797 const int Height = 1908221847;
2799 const auto pData = Component_t::Make(
2801 { uT(
"kind"), uT(
"Texture") },
2802 { uT(
"content"), Source },
2803 { uT(
"width"), Width },
2804 { uT(
"height"), Height },
2805 { uT(
"name"), Names[Index].first },
2806 { uT(
"index"), Index },
2807 { uT(
"mipmapping"),
false },
2808 { uT(
"capacity"), 32 },
2811 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2812 Source, Width, Height, Index, Names[Index].second);
2815 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
2817 { uT(
"albedo"),
"TexAlbedo" },
2818 { uT(
"metalness"),
"TexMetalness" },
2819 { uT(
"roughness"),
"TexRoughness" },
2820 { uT(
"normal"),
"TexNormal" },
2821 { uT(
"occlusion"),
"TexOcclusion" },
2825 for (::std::size_t i = 0; i < Destinations.size(); i++)
2828 const int Width = 1908221843;
2829 const int Height = 1908221844;
2831 const auto pTexture = Component_t::Make(
2833 { uT(
"content"), Source },
2834 { uT(
"width"), Width },
2835 { uT(
"height"), Height },
2836 { uT(
"name"), Names[Index].first },
2837 { uT(
"index"), Index },
2838 { uT(
"destination"), Destinations[i].first },
2839 { uT(
"capacity"), 32 },
2843 Source, Width, Height, Index, Names[Index].second);
2847 const int Width = 1908221845;
2848 const int Height = 1908221847;
2850 const auto pData = Component_t::Make(
2852 { uT(
"kind"), uT(
"Texture") },
2853 { uT(
"content"), Source },
2854 { uT(
"width"), Width },
2855 { uT(
"height"), Height },
2856 { uT(
"name"), Names[Index].first },
2857 { uT(
"index"), Index },
2858 { uT(
"destination"), Destinations[i].first },
2859 { uT(
"capacity"), 32 },
2862 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2863 Source, Width, Height, Index, Names[Index].second);
2867 const int Width = 1908221843;
2868 const int Height = 1908221844;
2870 const auto pTexture = Component_t::Make(
2872 { uT(
"content"), Source },
2873 { uT(
"width"), Width },
2874 { uT(
"height"), Height },
2875 { uT(
"name"), Names[Index].first },
2876 { uT(
"index"), Index },
2877 { uT(
"destination"), Destinations[i].first },
2878 { uT(
"mipmapping"),
false },
2879 { uT(
"capacity"), 32 },
2883 Source, Width, Height, Index, Names[Index].second);
2887 const int Width = 1908221845;
2888 const int Height = 1908221847;
2890 const auto pData = Component_t::Make(
2892 { uT(
"kind"), uT(
"Texture") },
2893 { uT(
"content"), Source },
2894 { uT(
"width"), Width },
2895 { uT(
"height"), Height },
2896 { uT(
"name"), Names[Index].first },
2897 { uT(
"index"), Index },
2898 { uT(
"destination"), Destinations[i].first },
2899 { uT(
"mipmapping"),
false },
2900 { uT(
"capacity"), 32 },
2903 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2904 Source, Width, Height, Index, Names[Index].second);
2911TEST_F(OpenGLShader_test, Test_Texture_Destination)
2913 using GLProxy_t = ::mock::GLProxy;
2915 GLProxy_t::GetInstance() = &GLProxy;
2917 const Tested_t Example{ Data_t{} };
2918 const ITested_t & IExample = Example;
2920 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
2921 ASSERT_NE(IExample.GetCreators().end(), itCreator);
2923 const ::mock::GLuint TextureId = 1908221839;
2924 const ::mock::GLint ProgramId = 1908221840;
2925 const ::mock::GLint LocationId = 1908221841;
2927 const auto TestCall = [&](
2928 const Component_t::ComponentPtr_t & _pTexture,
2929 const ::std::vector<uint8_t> & _Source,
2930 const int _Width,
const int _Height,
2931 const ::std::size_t _Index,
2932 const ::std::string & _TexName)
2934 const auto Index =
static_cast<::mock::GLint
>(_Index);
2936 using namespace ::testing;
2940 EXPECT_CALL(GLProxy, GenTextures(1))
2942 .WillOnce(Return(TextureId));
2944 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2947 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
2949 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
2952 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2955 EXPECT_CALL(GLProxy, GetError())
2957 .WillOnce(Return(GL_NO_ERROR));
2959 EXPECT_CALL(GLProxy, GenFramebuffers(1))
2962 auto Render = itCreator->second(_pTexture);
2963 ASSERT_NE(
nullptr, Render);
2965 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
2968 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2971 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2973 .WillOnce(Return(&ProgramId));
2975 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
2977 .WillOnce(Return(LocationId));
2979 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
2982 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
2987 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
2991 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
2993 { uT(
"albedo"),
"TexAlbedo" },
2994 { uT(
"metalness"),
"TexMetalness" },
2995 { uT(
"roughness"),
"TexRoughness" },
2996 { uT(
"normal"),
"TexNormal" },
2997 { uT(
"occlusion"),
"TexOcclusion" },
3001 ::std::vector<uint8_t> Source =
3003 0x20, 0x06, 0x15, 0x12, 0x30,
3004 0x20, 0x06, 0x15, 0x12, 0x30,
3005 0x20, 0x06, 0x15, 0x12, 0x30,
3006 0x20, 0x06, 0x15, 0x12, 0x30,
3007 0x20, 0x06, 0x15, 0x12, 0x30,
3009 IntroduceBufferSize(Source);
3011 for (::std::size_t i = 0; i < Destinations.size(); i++)
3014 const int Width = 1908221843;
3015 const int Height = 1908221844;
3017 const auto pTexture = Component_t::Make(
3019 { uT(
"content"), Source },
3020 { uT(
"width"), Width },
3021 { uT(
"height"), Height },
3022 { uT(
"destination"), Destinations[i].first },
3026 Source, Width, Height, i, Destinations[i].second);
3030 const int Width = 1908221845;
3031 const int Height = 1908221847;
3033 const auto pData = Component_t::Make(
3035 { uT(
"kind"), uT(
"Texture") },
3036 { uT(
"content"), Source },
3037 { uT(
"width"), Width },
3038 { uT(
"height"), Height },
3039 { uT(
"destination"), Destinations[i].first },
3042 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3043 Source, Width, Height, i, Destinations[i].second);
3047 const int Width = 1908221843;
3048 const int Height = 1908221844;
3050 const auto pTexture = Component_t::Make(
3052 { uT(
"content"), Source },
3053 { uT(
"width"), Width },
3054 { uT(
"height"), Height },
3055 { uT(
"destination"), Destinations[i].first },
3056 { uT(
"mipmapping"),
false },
3060 Source, Width, Height, i, Destinations[i].second);
3064 const int Width = 1908221845;
3065 const int Height = 1908221847;
3067 const auto pData = Component_t::Make(
3069 { uT(
"kind"), uT(
"Texture") },
3070 { uT(
"content"), Source },
3071 { uT(
"width"), Width },
3072 { uT(
"height"), Height },
3073 { uT(
"destination"), Destinations[i].first },
3074 { uT(
"mipmapping"),
false },
3077 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3078 Source, Width, Height, i, Destinations[i].second);
3084TEST_F(OpenGLShader_test, Test_Texture_Destination_Capacity16)
3086 using GLProxy_t = ::mock::GLProxy;
3088 GLProxy_t::GetInstance() = &GLProxy;
3090 const Tested_t Example{ Data_t{} };
3091 const ITested_t & IExample = Example;
3093 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
3094 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3096 const ::mock::GLuint TextureId = 1908221839;
3097 const ::mock::GLint ProgramId = 1908221840;
3098 const ::mock::GLint LocationId = 1908221841;
3100 const auto TestCall = [&](
3101 const Component_t::ComponentPtr_t & _pTexture,
3102 const ::std::vector<uint8_t> & _Source,
3103 const int _Width,
const int _Height,
3104 const ::std::size_t _Index,
3105 const ::std::string & _TexName)
3107 const auto Index =
static_cast<::mock::GLint
>(_Index);
3109 using namespace ::testing;
3113 EXPECT_CALL(GLProxy, GenTextures(1))
3115 .WillOnce(Return(TextureId));
3117 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3120 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
3122 GL_RGBA, GL_HALF_FLOAT, _Source))
3125 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3128 EXPECT_CALL(GLProxy, GetError())
3130 .WillOnce(Return(GL_NO_ERROR));
3132 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3135 auto Render = itCreator->second(_pTexture);
3136 ASSERT_NE(
nullptr, Render);
3138 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3141 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3144 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3146 .WillOnce(Return(&ProgramId));
3148 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3150 .WillOnce(Return(LocationId));
3152 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
3155 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3160 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3164 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3166 { uT(
"albedo"),
"TexAlbedo" },
3167 { uT(
"metalness"),
"TexMetalness" },
3168 { uT(
"roughness"),
"TexRoughness" },
3169 { uT(
"normal"),
"TexNormal" },
3170 { uT(
"occlusion"),
"TexOcclusion" },
3174 ::std::vector<uint8_t> Source =
3176 0x20, 0x06, 0x15, 0x12, 0x30,
3177 0x20, 0x06, 0x15, 0x12, 0x30,
3178 0x20, 0x06, 0x15, 0x12, 0x30,
3179 0x20, 0x06, 0x15, 0x12, 0x30,
3180 0x20, 0x06, 0x15, 0x12, 0x30,
3182 IntroduceBufferSize(Source);
3184 for (::std::size_t i = 0; i < Destinations.size(); i++)
3187 const int Width = 1908221843;
3188 const int Height = 1908221844;
3190 const auto pTexture = Component_t::Make(
3192 { uT(
"content"), Source },
3193 { uT(
"width"), Width },
3194 { uT(
"height"), Height },
3195 { uT(
"destination"), Destinations[i].first },
3196 { uT(
"capacity"), 16 },
3200 Source, Width, Height, i, Destinations[i].second);
3204 const int Width = 1908221845;
3205 const int Height = 1908221847;
3207 const auto pData = Component_t::Make(
3209 { uT(
"kind"), uT(
"Texture") },
3210 { uT(
"content"), Source },
3211 { uT(
"width"), Width },
3212 { uT(
"height"), Height },
3213 { uT(
"destination"), Destinations[i].first },
3214 { uT(
"capacity"), 16 },
3217 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3218 Source, Width, Height, i, Destinations[i].second);
3222 const int Width = 1908221843;
3223 const int Height = 1908221844;
3225 const auto pTexture = Component_t::Make(
3227 { uT(
"content"), Source },
3228 { uT(
"width"), Width },
3229 { uT(
"height"), Height },
3230 { uT(
"destination"), Destinations[i].first },
3231 { uT(
"mipmapping"),
false },
3232 { uT(
"capacity"), 16 },
3236 Source, Width, Height, i, Destinations[i].second);
3240 const int Width = 1908221845;
3241 const int Height = 1908221847;
3243 const auto pData = Component_t::Make(
3245 { uT(
"kind"), uT(
"Texture") },
3246 { uT(
"content"), Source },
3247 { uT(
"width"), Width },
3248 { uT(
"height"), Height },
3249 { uT(
"destination"), Destinations[i].first },
3250 { uT(
"mipmapping"),
false },
3251 { uT(
"capacity"), 16 },
3254 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3255 Source, Width, Height, i, Destinations[i].second);
3261TEST_F(OpenGLShader_test, Test_Texture_Destination_Capacity32)
3263 using GLProxy_t = ::mock::GLProxy;
3265 GLProxy_t::GetInstance() = &GLProxy;
3267 const Tested_t Example{ Data_t{} };
3268 const ITested_t & IExample = Example;
3270 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
3271 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3273 const ::mock::GLuint TextureId = 1908221839;
3274 const ::mock::GLint ProgramId = 1908221840;
3275 const ::mock::GLint LocationId = 1908221841;
3277 const auto TestCall = [&](
3278 const Component_t::ComponentPtr_t & _pTexture,
3279 const ::std::vector<uint8_t> & _Source,
3280 const int _Width,
const int _Height,
3281 const ::std::size_t _Index,
3282 const ::std::string & _TexName)
3284 const auto Index =
static_cast<::mock::GLint
>(_Index);
3286 using namespace ::testing;
3290 EXPECT_CALL(GLProxy, GenTextures(1))
3292 .WillOnce(Return(TextureId));
3294 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3297 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
3299 GL_RGBA, GL_FLOAT, _Source))
3302 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3305 EXPECT_CALL(GLProxy, GetError())
3307 .WillOnce(Return(GL_NO_ERROR));
3309 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3312 auto Render = itCreator->second(_pTexture);
3313 ASSERT_NE(
nullptr, Render);
3315 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3318 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3321 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3323 .WillOnce(Return(&ProgramId));
3325 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3327 .WillOnce(Return(LocationId));
3329 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
3332 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3337 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3341 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3343 { uT(
"albedo"),
"TexAlbedo" },
3344 { uT(
"metalness"),
"TexMetalness" },
3345 { uT(
"roughness"),
"TexRoughness" },
3346 { uT(
"normal"),
"TexNormal" },
3347 { uT(
"occlusion"),
"TexOcclusion" },
3351 ::std::vector<uint8_t> Source =
3353 0x20, 0x06, 0x15, 0x12, 0x30,
3354 0x20, 0x06, 0x15, 0x12, 0x30,
3355 0x20, 0x06, 0x15, 0x12, 0x30,
3356 0x20, 0x06, 0x15, 0x12, 0x30,
3357 0x20, 0x06, 0x15, 0x12, 0x30,
3359 IntroduceBufferSize(Source);
3361 for (::std::size_t i = 0; i < Destinations.size(); i++)
3364 const int Width = 1908221843;
3365 const int Height = 1908221844;
3367 const auto pTexture = Component_t::Make(
3369 { uT(
"content"), Source },
3370 { uT(
"width"), Width },
3371 { uT(
"height"), Height },
3372 { uT(
"destination"), Destinations[i].first },
3373 { uT(
"capacity"), 32 },
3377 Source, Width, Height, i, Destinations[i].second);
3381 const int Width = 1908221845;
3382 const int Height = 1908221847;
3384 const auto pData = Component_t::Make(
3386 { uT(
"kind"), uT(
"Texture") },
3387 { uT(
"content"), Source },
3388 { uT(
"width"), Width },
3389 { uT(
"height"), Height },
3390 { uT(
"destination"), Destinations[i].first },
3391 { uT(
"capacity"), 32 },
3394 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3395 Source, Width, Height, i, Destinations[i].second);
3399 const int Width = 1908221843;
3400 const int Height = 1908221844;
3402 const auto pTexture = Component_t::Make(
3404 { uT(
"content"), Source },
3405 { uT(
"width"), Width },
3406 { uT(
"height"), Height },
3407 { uT(
"destination"), Destinations[i].first },
3408 { uT(
"mipmapping"),
false },
3409 { uT(
"capacity"), 32 },
3413 Source, Width, Height, i, Destinations[i].second);
3417 const int Width = 1908221845;
3418 const int Height = 1908221847;
3420 const auto pData = Component_t::Make(
3422 { uT(
"kind"), uT(
"Texture") },
3423 { uT(
"content"), Source },
3424 { uT(
"width"), Width },
3425 { uT(
"height"), Height },
3426 { uT(
"destination"), Destinations[i].first },
3427 { uT(
"mipmapping"),
false },
3428 { uT(
"capacity"), 32 },
3431 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3432 Source, Width, Height, i, Destinations[i].second);
3438TEST_F(OpenGLShader_test, Test_Texture_Mipmapping_NameAndIndex)
3440 using GLProxy_t = ::mock::GLProxy;
3442 GLProxy_t::GetInstance() = &GLProxy;
3444 const Tested_t Example{ Data_t{} };
3445 const ITested_t & IExample = Example;
3447 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
3448 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3450 const ::mock::GLuint TextureId = 1908221839;
3451 const ::mock::GLint ProgramId = 1908221840;
3452 const ::mock::GLint LocationId = 1908221841;
3454 const auto TestCall = [&](
3455 const Component_t::ComponentPtr_t & _pTexture,
3456 const ::std::vector<uint8_t> & _Source,
3457 const int _Width,
const int _Height,
3458 const ::std::size_t _Index,
3459 const ::std::string & _TexName)
3461 const auto Index =
static_cast<::mock::GLint
>(_Index);
3463 using namespace ::testing;
3467 EXPECT_CALL(GLProxy, GenTextures(1))
3469 .WillOnce(Return(TextureId));
3471 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3474 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
3476 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
3479 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3482 EXPECT_CALL(GLProxy, GetError())
3484 .WillOnce(Return(GL_NO_ERROR));
3486 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3489 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
3492 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3495 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3498 auto Render = itCreator->second(_pTexture);
3499 ASSERT_NE(
nullptr, Render);
3501 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3504 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3507 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3509 .WillOnce(Return(&ProgramId));
3511 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3513 .WillOnce(Return(LocationId));
3515 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
3518 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3523 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3527 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
3529 { uT(
"TexEnvironment"),
"TexEnvironment" },
3530 { uT(
"TexReflection"),
"TexReflection" },
3531 { uT(
"TexBaseColor"),
"TexBaseColor" },
3534 for (
int Index = 0; Index < Names.size(); Index++)
3536 ::std::vector<uint8_t> Source =
3538 0x20, 0x06, 0x15, 0x12, 0x31,
3539 0x20, 0x06, 0x15, 0x12, 0x31,
3540 0x20, 0x06, 0x15, 0x12, 0x31,
3541 0x20, 0x06, 0x15, 0x12, 0x31,
3542 0x20, 0x06, 0x15, 0x12, 0x31,
3544 IntroduceBufferSize(Source);
3547 const int Width = 1908221843;
3548 const int Height = 1908221844;
3550 const auto pTexture = Component_t::Make(
3552 { uT(
"content"), Source },
3553 { uT(
"width"), Width },
3554 { uT(
"height"), Height },
3555 { uT(
"name"), Names[Index].first },
3556 { uT(
"index"), Index },
3557 { uT(
"mipmapping"),
true },
3561 Source, Width, Height, Index, Names[Index].second);
3565 const int Width = 1908221845;
3566 const int Height = 1908221847;
3568 const auto pData = Component_t::Make(
3570 { uT(
"kind"), uT(
"Texture") },
3571 { uT(
"content"), Source },
3572 { uT(
"width"), Width },
3573 { uT(
"height"), Height },
3574 { uT(
"name"), Names[Index].first },
3575 { uT(
"index"), Index },
3576 { uT(
"mipmapping"),
true },
3579 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3580 Source, Width, Height, Index, Names[Index].second);
3583 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3585 { uT(
"albedo"),
"TexAlbedo" },
3586 { uT(
"metalness"),
"TexMetalness" },
3587 { uT(
"roughness"),
"TexRoughness" },
3588 { uT(
"normal"),
"TexNormal" },
3589 { uT(
"occlusion"),
"TexOcclusion" },
3592 for (::std::size_t i = 0; i < Destinations.size(); i++)
3595 const int Width = 1908221843;
3596 const int Height = 1908221844;
3598 const auto pTexture = Component_t::Make(
3600 { uT(
"content"), Source },
3601 { uT(
"width"), Width },
3602 { uT(
"height"), Height },
3603 { uT(
"name"), Names[Index].first },
3604 { uT(
"index"), Index },
3605 { uT(
"destination"), Destinations[i].first },
3606 { uT(
"mipmapping"),
true },
3610 Source, Width, Height, Index, Names[Index].second);
3614 const int Width = 1908221845;
3615 const int Height = 1908221847;
3617 const auto pData = Component_t::Make(
3619 { uT(
"kind"), uT(
"Texture") },
3620 { uT(
"content"), Source },
3621 { uT(
"width"), Width },
3622 { uT(
"height"), Height },
3623 { uT(
"name"), Names[Index].first },
3624 { uT(
"index"), Index },
3625 { uT(
"destination"), Destinations[i].first },
3626 { uT(
"mipmapping"),
true },
3629 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3630 Source, Width, Height, Index, Names[Index].second);
3637TEST_F(OpenGLShader_test, Test_Texture_Mipmapping_NameAndIndex_Capacity16)
3639 using GLProxy_t = ::mock::GLProxy;
3641 GLProxy_t::GetInstance() = &GLProxy;
3643 const Tested_t Example{ Data_t{} };
3644 const ITested_t & IExample = Example;
3646 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
3647 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3649 const ::mock::GLuint TextureId = 1908221839;
3650 const ::mock::GLint ProgramId = 1908221840;
3651 const ::mock::GLint LocationId = 1908221841;
3653 const auto TestCall = [&](
3654 const Component_t::ComponentPtr_t & _pTexture,
3655 const ::std::vector<uint8_t> & _Source,
3656 const int _Width,
const int _Height,
3657 const ::std::size_t _Index,
3658 const ::std::string & _TexName)
3660 const auto Index =
static_cast<::mock::GLint
>(_Index);
3662 using namespace ::testing;
3666 EXPECT_CALL(GLProxy, GenTextures(1))
3668 .WillOnce(Return(TextureId));
3670 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3673 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
3675 GL_RGBA, GL_HALF_FLOAT, _Source))
3678 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3681 EXPECT_CALL(GLProxy, GetError())
3683 .WillOnce(Return(GL_NO_ERROR));
3685 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3688 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
3691 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3694 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3697 auto Render = itCreator->second(_pTexture);
3698 ASSERT_NE(
nullptr, Render);
3700 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3703 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3706 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3708 .WillOnce(Return(&ProgramId));
3710 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3712 .WillOnce(Return(LocationId));
3714 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
3717 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3722 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3726 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
3728 { uT(
"TexEnvironment"),
"TexEnvironment" },
3729 { uT(
"TexReflection"),
"TexReflection" },
3730 { uT(
"TexBaseColor"),
"TexBaseColor" },
3733 for (
int Index = 0; Index < Names.size(); Index++)
3735 ::std::vector<uint8_t> Source =
3737 0x20, 0x06, 0x15, 0x12, 0x31,
3738 0x20, 0x06, 0x15, 0x12, 0x31,
3739 0x20, 0x06, 0x15, 0x12, 0x31,
3740 0x20, 0x06, 0x15, 0x12, 0x31,
3741 0x20, 0x06, 0x15, 0x12, 0x31,
3743 IntroduceBufferSize(Source);
3746 const int Width = 1908221843;
3747 const int Height = 1908221844;
3749 const auto pTexture = Component_t::Make(
3751 { uT(
"content"), Source },
3752 { uT(
"width"), Width },
3753 { uT(
"height"), Height },
3754 { uT(
"name"), Names[Index].first },
3755 { uT(
"index"), Index },
3756 { uT(
"mipmapping"),
true },
3757 { uT(
"capacity"), 16 },
3761 Source, Width, Height, Index, Names[Index].second);
3765 const int Width = 1908221845;
3766 const int Height = 1908221847;
3768 const auto pData = Component_t::Make(
3770 { uT(
"kind"), uT(
"Texture") },
3771 { uT(
"content"), Source },
3772 { uT(
"width"), Width },
3773 { uT(
"height"), Height },
3774 { uT(
"name"), Names[Index].first },
3775 { uT(
"index"), Index },
3776 { uT(
"mipmapping"),
true },
3777 { uT(
"capacity"), 16 },
3780 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3781 Source, Width, Height, Index, Names[Index].second);
3784 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3786 { uT(
"albedo"),
"TexAlbedo" },
3787 { uT(
"metalness"),
"TexMetalness" },
3788 { uT(
"roughness"),
"TexRoughness" },
3789 { uT(
"normal"),
"TexNormal" },
3790 { uT(
"occlusion"),
"TexOcclusion" },
3793 for (::std::size_t i = 0; i < Destinations.size(); i++)
3796 const int Width = 1908221843;
3797 const int Height = 1908221844;
3799 const auto pTexture = Component_t::Make(
3801 { uT(
"content"), Source },
3802 { uT(
"width"), Width },
3803 { uT(
"height"), Height },
3804 { uT(
"name"), Names[Index].first },
3805 { uT(
"index"), Index },
3806 { uT(
"destination"), Destinations[i].first },
3807 { uT(
"mipmapping"),
true },
3808 { uT(
"capacity"), 16 },
3812 Source, Width, Height, Index, Names[Index].second);
3816 const int Width = 1908221845;
3817 const int Height = 1908221847;
3819 const auto pData = Component_t::Make(
3821 { uT(
"kind"), uT(
"Texture") },
3822 { uT(
"content"), Source },
3823 { uT(
"width"), Width },
3824 { uT(
"height"), Height },
3825 { uT(
"name"), Names[Index].first },
3826 { uT(
"index"), Index },
3827 { uT(
"destination"), Destinations[i].first },
3828 { uT(
"mipmapping"),
true },
3829 { uT(
"capacity"), 16 },
3832 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3833 Source, Width, Height, Index, Names[Index].second);
3840TEST_F(OpenGLShader_test, Test_Texture_Mipmapping_NameAndIndex_Capacity32)
3842 using GLProxy_t = ::mock::GLProxy;
3844 GLProxy_t::GetInstance() = &GLProxy;
3846 const Tested_t Example{ Data_t{} };
3847 const ITested_t & IExample = Example;
3849 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
3850 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3852 const ::mock::GLuint TextureId = 1908221839;
3853 const ::mock::GLint ProgramId = 1908221840;
3854 const ::mock::GLint LocationId = 1908221841;
3856 const auto TestCall = [&](
3857 const Component_t::ComponentPtr_t & _pTexture,
3858 const ::std::vector<uint8_t> & _Source,
3859 const int _Width,
const int _Height,
3860 const ::std::size_t _Index,
3861 const ::std::string & _TexName)
3863 const auto Index =
static_cast<::mock::GLint
>(_Index);
3865 using namespace ::testing;
3869 EXPECT_CALL(GLProxy, GenTextures(1))
3871 .WillOnce(Return(TextureId));
3873 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3876 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
3878 GL_RGBA, GL_FLOAT, _Source))
3881 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3884 EXPECT_CALL(GLProxy, GetError())
3886 .WillOnce(Return(GL_NO_ERROR));
3888 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3891 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
3894 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3897 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3900 auto Render = itCreator->second(_pTexture);
3901 ASSERT_NE(
nullptr, Render);
3903 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3906 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3909 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3911 .WillOnce(Return(&ProgramId));
3913 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3915 .WillOnce(Return(LocationId));
3917 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
3920 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3925 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3929 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
3931 { uT(
"TexEnvironment"),
"TexEnvironment" },
3932 { uT(
"TexReflection"),
"TexReflection" },
3933 { uT(
"TexBaseColor"),
"TexBaseColor" },
3936 for (
int Index = 0; Index < Names.size(); Index++)
3938 ::std::vector<uint8_t> Source =
3940 0x20, 0x06, 0x15, 0x12, 0x31,
3941 0x20, 0x06, 0x15, 0x12, 0x31,
3942 0x20, 0x06, 0x15, 0x12, 0x31,
3943 0x20, 0x06, 0x15, 0x12, 0x31,
3944 0x20, 0x06, 0x15, 0x12, 0x31,
3946 IntroduceBufferSize(Source);
3949 const int Width = 1908221843;
3950 const int Height = 1908221844;
3952 const auto pTexture = Component_t::Make(
3954 { uT(
"content"), Source },
3955 { uT(
"width"), Width },
3956 { uT(
"height"), Height },
3957 { uT(
"name"), Names[Index].first },
3958 { uT(
"index"), Index },
3959 { uT(
"mipmapping"),
true },
3960 { uT(
"capacity"), 32 },
3964 Source, Width, Height, Index, Names[Index].second);
3968 const int Width = 1908221845;
3969 const int Height = 1908221847;
3971 const auto pData = Component_t::Make(
3973 { uT(
"kind"), uT(
"Texture") },
3974 { uT(
"content"), Source },
3975 { uT(
"width"), Width },
3976 { uT(
"height"), Height },
3977 { uT(
"name"), Names[Index].first },
3978 { uT(
"index"), Index },
3979 { uT(
"mipmapping"),
true },
3980 { uT(
"capacity"), 32 },
3983 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3984 Source, Width, Height, Index, Names[Index].second);
3987 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3989 { uT(
"albedo"),
"TexAlbedo" },
3990 { uT(
"metalness"),
"TexMetalness" },
3991 { uT(
"roughness"),
"TexRoughness" },
3992 { uT(
"normal"),
"TexNormal" },
3993 { uT(
"occlusion"),
"TexOcclusion" },
3996 for (::std::size_t i = 0; i < Destinations.size(); i++)
3999 const int Width = 1908221843;
4000 const int Height = 1908221844;
4002 const auto pTexture = Component_t::Make(
4004 { uT(
"content"), Source },
4005 { uT(
"width"), Width },
4006 { uT(
"height"), Height },
4007 { uT(
"name"), Names[Index].first },
4008 { uT(
"index"), Index },
4009 { uT(
"destination"), Destinations[i].first },
4010 { uT(
"mipmapping"),
true },
4011 { uT(
"capacity"), 32 },
4015 Source, Width, Height, Index, Names[Index].second);
4019 const int Width = 1908221845;
4020 const int Height = 1908221847;
4022 const auto pData = Component_t::Make(
4024 { uT(
"kind"), uT(
"Texture") },
4025 { uT(
"content"), Source },
4026 { uT(
"width"), Width },
4027 { uT(
"height"), Height },
4028 { uT(
"name"), Names[Index].first },
4029 { uT(
"index"), Index },
4030 { uT(
"destination"), Destinations[i].first },
4031 { uT(
"mipmapping"),
true },
4032 { uT(
"capacity"), 32 },
4035 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
4036 Source, Width, Height, Index, Names[Index].second);
4043TEST_F(OpenGLShader_test, Test_Texture_Mipmapping_Destination)
4045 using GLProxy_t = ::mock::GLProxy;
4047 GLProxy_t::GetInstance() = &GLProxy;
4049 const Tested_t Example{ Data_t{} };
4050 const ITested_t & IExample = Example;
4052 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
4053 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4055 const ::mock::GLuint TextureId = 1908221839;
4056 const ::mock::GLint ProgramId = 1908221840;
4057 const ::mock::GLint LocationId = 1908221841;
4059 const auto TestCall = [&](
4060 const Component_t::ComponentPtr_t & _pTexture,
4061 const ::std::vector<uint8_t> & _Source,
4062 const int _Width,
const int _Height,
4063 const ::std::size_t _Index,
4064 const ::std::string & _TexName)
4066 const auto Index =
static_cast<::mock::GLint
>(_Index);
4068 using namespace ::testing;
4072 EXPECT_CALL(GLProxy, GenTextures(1))
4074 .WillOnce(Return(TextureId));
4076 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4079 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
4081 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
4084 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4087 EXPECT_CALL(GLProxy, GetError())
4089 .WillOnce(Return(GL_NO_ERROR));
4091 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4094 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
4097 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4100 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4103 auto Render = itCreator->second(_pTexture);
4104 ASSERT_NE(
nullptr, Render);
4106 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4109 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4112 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4114 .WillOnce(Return(&ProgramId));
4116 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4118 .WillOnce(Return(LocationId));
4120 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
4123 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4128 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4132 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4134 { uT(
"albedo"),
"TexAlbedo" },
4135 { uT(
"metalness"),
"TexMetalness" },
4136 { uT(
"roughness"),
"TexRoughness" },
4137 { uT(
"normal"),
"TexNormal" },
4138 { uT(
"occlusion"),
"TexOcclusion" },
4141 ::std::vector<uint8_t> Source =
4143 0x20, 0x06, 0x15, 0x12, 0x31,
4144 0x20, 0x06, 0x15, 0x12, 0x31,
4145 0x20, 0x06, 0x15, 0x12, 0x31,
4146 0x20, 0x06, 0x15, 0x12, 0x31,
4147 0x20, 0x06, 0x15, 0x12, 0x31,
4149 IntroduceBufferSize(Source);
4151 for (::std::size_t i = 0; i < Destinations.size(); i++)
4154 const int Width = 1908221843;
4155 const int Height = 1908221844;
4157 const auto pTexture = Component_t::Make(
4159 { uT(
"content"), Source },
4160 { uT(
"width"), Width },
4161 { uT(
"height"), Height },
4162 { uT(
"destination"), Destinations[i].first },
4163 { uT(
"mipmapping"),
true },
4167 Source, Width, Height, i, Destinations[i].second);
4171 const int Width = 1908221845;
4172 const int Height = 1908221847;
4174 const auto pData = Component_t::Make(
4176 { uT(
"kind"), uT(
"Texture") },
4177 { uT(
"content"), Source },
4178 { uT(
"width"), Width },
4179 { uT(
"height"), Height },
4180 { uT(
"destination"), Destinations[i].first },
4181 { uT(
"mipmapping"),
true },
4184 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
4185 Source, Width, Height, i, Destinations[i].second);
4191TEST_F(OpenGLShader_test, Test_Texture_Mipmapping_Destination_Capacity16)
4193 using GLProxy_t = ::mock::GLProxy;
4195 GLProxy_t::GetInstance() = &GLProxy;
4197 const Tested_t Example{ Data_t{} };
4198 const ITested_t & IExample = Example;
4200 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
4201 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4203 const ::mock::GLuint TextureId = 1908221839;
4204 const ::mock::GLint ProgramId = 1908221840;
4205 const ::mock::GLint LocationId = 1908221841;
4207 const auto TestCall = [&](
4208 const Component_t::ComponentPtr_t & _pTexture,
4209 const ::std::vector<uint8_t> & _Source,
4210 const int _Width,
const int _Height,
4211 const ::std::size_t _Index,
4212 const ::std::string & _TexName)
4214 const auto Index =
static_cast<::mock::GLint
>(_Index);
4216 using namespace ::testing;
4220 EXPECT_CALL(GLProxy, GenTextures(1))
4222 .WillOnce(Return(TextureId));
4224 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4227 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
4229 GL_RGBA, GL_HALF_FLOAT, _Source))
4232 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4235 EXPECT_CALL(GLProxy, GetError())
4237 .WillOnce(Return(GL_NO_ERROR));
4239 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4242 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
4245 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4248 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4251 auto Render = itCreator->second(_pTexture);
4252 ASSERT_NE(
nullptr, Render);
4254 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4257 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4260 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4262 .WillOnce(Return(&ProgramId));
4264 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4266 .WillOnce(Return(LocationId));
4268 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
4271 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4276 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4280 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4282 { uT(
"albedo"),
"TexAlbedo" },
4283 { uT(
"metalness"),
"TexMetalness" },
4284 { uT(
"roughness"),
"TexRoughness" },
4285 { uT(
"normal"),
"TexNormal" },
4286 { uT(
"occlusion"),
"TexOcclusion" },
4289 ::std::vector<uint8_t> Source =
4291 0x20, 0x06, 0x15, 0x12, 0x31,
4292 0x20, 0x06, 0x15, 0x12, 0x31,
4293 0x20, 0x06, 0x15, 0x12, 0x31,
4294 0x20, 0x06, 0x15, 0x12, 0x31,
4295 0x20, 0x06, 0x15, 0x12, 0x31,
4297 IntroduceBufferSize(Source);
4299 for (::std::size_t i = 0; i < Destinations.size(); i++)
4302 const int Width = 1908221843;
4303 const int Height = 1908221844;
4305 const auto pTexture = Component_t::Make(
4307 { uT(
"content"), Source },
4308 { uT(
"width"), Width },
4309 { uT(
"height"), Height },
4310 { uT(
"destination"), Destinations[i].first },
4311 { uT(
"mipmapping"),
true },
4312 { uT(
"capacity"), 16 },
4316 Source, Width, Height, i, Destinations[i].second);
4320 const int Width = 1908221845;
4321 const int Height = 1908221847;
4323 const auto pData = Component_t::Make(
4325 { uT(
"kind"), uT(
"Texture") },
4326 { uT(
"content"), Source },
4327 { uT(
"width"), Width },
4328 { uT(
"height"), Height },
4329 { uT(
"destination"), Destinations[i].first },
4330 { uT(
"mipmapping"),
true },
4331 { uT(
"capacity"), 16 },
4334 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
4335 Source, Width, Height, i, Destinations[i].second);
4341TEST_F(OpenGLShader_test, Test_Texture_Mipmapping_Destination_Capacity32)
4343 using GLProxy_t = ::mock::GLProxy;
4345 GLProxy_t::GetInstance() = &GLProxy;
4347 const Tested_t Example{ Data_t{} };
4348 const ITested_t & IExample = Example;
4350 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
4351 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4353 const ::mock::GLuint TextureId = 1908221839;
4354 const ::mock::GLint ProgramId = 1908221840;
4355 const ::mock::GLint LocationId = 1908221841;
4357 const auto TestCall = [&](
4358 const Component_t::ComponentPtr_t & _pTexture,
4359 const ::std::vector<uint8_t> & _Source,
4360 const int _Width,
const int _Height,
4361 const ::std::size_t _Index,
4362 const ::std::string & _TexName)
4364 const auto Index =
static_cast<::mock::GLint
>(_Index);
4366 using namespace ::testing;
4370 EXPECT_CALL(GLProxy, GenTextures(1))
4372 .WillOnce(Return(TextureId));
4374 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4377 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
4379 GL_RGBA, GL_FLOAT, _Source))
4382 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4385 EXPECT_CALL(GLProxy, GetError())
4387 .WillOnce(Return(GL_NO_ERROR));
4389 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4392 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
4395 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4398 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4401 auto Render = itCreator->second(_pTexture);
4402 ASSERT_NE(
nullptr, Render);
4404 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4407 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4410 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4412 .WillOnce(Return(&ProgramId));
4414 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4416 .WillOnce(Return(LocationId));
4418 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
4421 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4426 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4430 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4432 { uT(
"albedo"),
"TexAlbedo" },
4433 { uT(
"metalness"),
"TexMetalness" },
4434 { uT(
"roughness"),
"TexRoughness" },
4435 { uT(
"normal"),
"TexNormal" },
4436 { uT(
"occlusion"),
"TexOcclusion" },
4439 ::std::vector<uint8_t> Source =
4441 0x20, 0x06, 0x15, 0x12, 0x31,
4442 0x20, 0x06, 0x15, 0x12, 0x31,
4443 0x20, 0x06, 0x15, 0x12, 0x31,
4444 0x20, 0x06, 0x15, 0x12, 0x31,
4445 0x20, 0x06, 0x15, 0x12, 0x31,
4447 IntroduceBufferSize(Source);
4449 for (::std::size_t i = 0; i < Destinations.size(); i++)
4452 const int Width = 1908221843;
4453 const int Height = 1908221844;
4455 const auto pTexture = Component_t::Make(
4457 { uT(
"content"), Source },
4458 { uT(
"width"), Width },
4459 { uT(
"height"), Height },
4460 { uT(
"destination"), Destinations[i].first },
4461 { uT(
"mipmapping"),
true },
4462 { uT(
"capacity"), 32 },
4466 Source, Width, Height, i, Destinations[i].second);
4470 const int Width = 1908221845;
4471 const int Height = 1908221847;
4473 const auto pData = Component_t::Make(
4475 { uT(
"kind"), uT(
"Texture") },
4476 { uT(
"content"), Source },
4477 { uT(
"width"), Width },
4478 { uT(
"height"), Height },
4479 { uT(
"destination"), Destinations[i].first },
4480 { uT(
"mipmapping"),
true },
4481 { uT(
"capacity"), 32 },
4484 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
4485 Source, Width, Height, i, Destinations[i].second);
4491TEST_F(OpenGLShader_test, Test_Texture_ReadData_NameAndIndex)
4493 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
4494 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
4496 using GLProxy_t = ::mock::GLProxy;
4498 GLProxy_t::GetInstance() = &GLProxy;
4501 public ::alicorn::extension::testing::Proxy<MapperProxy>
4504 MOCK_METHOD1(Map,
bool(
const void *));
4505 MOCK_METHOD1(CheckData,
void(::std::vector<uint32_t>));
4508 MapperProxy oMapperProxy;
4509 MapperProxy::GetInstance() = &oMapperProxy;
4511 const int Width = 3;
4512 const int Height = 4;
4514 const BufferMapper_t Mapper = [&](
const void * _pData)
4516 if (_pData !=
nullptr)
4518 ::std::vector<uint32_t> Data(Width * Height);
4519 memcpy(Data.data(), _pData, Width * Height * 4);
4520 oMapperProxy.CheckData(Data);
4523 return oMapperProxy.Map(_pData);
4526 const Tested_t Example{ Data_t{} };
4527 const ITested_t & IExample = Example;
4529 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
4530 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4532 const ::mock::GLint TextureId = 1910221154;
4533 const ::mock::GLint ProgramId = 1910221155;
4534 const ::mock::GLint LocationId = 1910221156;
4535 const ::mock::GLint FrameBufferId = 1910221209;
4536 const ::mock::GLint DefaultFrameBufferId = 1910221236;
4538 const auto TestCall = [&](
4539 const Component_t::ComponentPtr_t & _pDataTexture,
4540 const ::std::size_t _Index,
4541 const ::std::string & _TexName,
4542 const ::std::vector<uint32_t> & _RawData,
4543 const ::std::vector<uint32_t> & _ExpectData)
4545 const auto Index =
static_cast<::mock::GLint
>(_Index);
4547 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT(
"") };
4549 using namespace ::testing;
4553 EXPECT_CALL(GLProxy, GenTextures(1))
4555 .WillOnce(Return(TextureId));
4557 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4560 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
4562 GL_RGBA, GL_UNSIGNED_BYTE, ::std::vector<uint8_t>{}))
4565 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4568 EXPECT_CALL(GLProxy, GetError())
4570 .WillOnce(Return(GL_NO_ERROR));
4572 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
4573 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
4575 (*_pDataTexture)[uT(
"entity")] = pTexture;
4577 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4579 .WillOnce(Return(FrameBufferId));
4581 EXPECT_CALL(GLProxy, GenTextures(1))
4584 auto Render = itCreator->second(Component_t::Make(
4586 { uT(
"service"), Object_t{ _pDataTexture } }
4588 ASSERT_NE(
nullptr, Render);
4590 const auto TestCallActivateTexture = [&](void)
4592 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4595 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4598 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4600 .WillOnce(Return(&ProgramId));
4602 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4604 .WillOnce(Return(LocationId));
4606 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
4609 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4615 EXPECT_CALL(oMapperProxy, Map(
nullptr))
4617 .WillOnce(Return(
false));
4619 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
4622 TestCallActivateTexture();
4627 EXPECT_CALL(oMapperProxy, Map(
nullptr))
4629 .WillOnce(Return(
true));
4631 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
4633 .WillOnce(Return(&DefaultFrameBufferId));
4635 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
4638 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
4639 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
4642 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
4644 .WillOnce(Return(_RawData));
4646 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
4647 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
4650 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
4653 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
4656 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
4659 TestCallActivateTexture();
4664 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
4667 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4671 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
4673 { uT(
"TexEnvironment"),
"TexEnvironment" },
4674 { uT(
"TexReflection"),
"TexReflection" },
4675 { uT(
"TexBaseColor"),
"TexBaseColor" },
4678 for (
int Index = 0; Index < Names.size(); Index++)
4680 const ::std::vector<uint32_t> RawData =
4682 0x10221334, 0x10221335, 0x10221336,
4683 0x10221337, 0x10221338, 0x10221339,
4684 0x10221340, 0x10221341, 0x10221342,
4685 0x10221343, 0x10221344, 0x10221345,
4688 const ::std::vector<uint32_t> ExpectData =
4690 0x10221343, 0x10221344, 0x10221345,
4691 0x10221340, 0x10221341, 0x10221342,
4692 0x10221337, 0x10221338, 0x10221339,
4693 0x10221334, 0x10221335, 0x10221336,
4696 const auto pData = Component_t::Make(
4698 { uT(
"kind"), uT(
"Texture") },
4699 { uT(
"width"), Width },
4700 { uT(
"height"), Height },
4701 { uT(
"mapper"), Mapper },
4702 { uT(
"name"), Names[Index].first },
4703 { uT(
"index"), Index },
4706 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
4708 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4710 { uT(
"albedo"),
"TexAlbedo" },
4711 { uT(
"metalness"),
"TexMetalness" },
4712 { uT(
"roughness"),
"TexRoughness" },
4713 { uT(
"normal"),
"TexNormal" },
4714 { uT(
"occlusion"),
"TexOcclusion" },
4717 for (::std::size_t i = 0; i < Destinations.size(); i++)
4719 const auto pData = Component_t::Make(
4721 { uT(
"kind"), uT(
"Texture") },
4722 { uT(
"width"), Width },
4723 { uT(
"height"), Height },
4724 { uT(
"mapper"), Mapper },
4725 { uT(
"name"), Names[Index].first },
4726 { uT(
"index"), Index },
4727 { uT(
"destination"), Destinations[i].first },
4730 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
4736TEST_F(OpenGLShader_test, Test_Texture_ReadData_NameAndIndex_Capacity16)
4738 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
4739 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
4741 using GLProxy_t = ::mock::GLProxy;
4743 GLProxy_t::GetInstance() = &GLProxy;
4746 public ::alicorn::extension::testing::Proxy<MapperProxy>
4749 MOCK_METHOD1(Map,
bool(
const void *));
4750 MOCK_METHOD1(CheckData,
void(::std::vector<uint32_t>));
4753 MapperProxy oMapperProxy;
4754 MapperProxy::GetInstance() = &oMapperProxy;
4756 const int Width = 3;
4757 const int Height = 4;
4759 const BufferMapper_t Mapper = [&](
const void * _pData)
4761 if (_pData !=
nullptr)
4763 ::std::vector<uint32_t> Data(Width * Height);
4764 memcpy(Data.data(), _pData, Width * Height * 4);
4765 oMapperProxy.CheckData(Data);
4768 return oMapperProxy.Map(_pData);
4771 const Tested_t Example{ Data_t{} };
4772 const ITested_t & IExample = Example;
4774 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
4775 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4777 const ::mock::GLint TextureId = 1910221154;
4778 const ::mock::GLint ProgramId = 1910221155;
4779 const ::mock::GLint LocationId = 1910221156;
4780 const ::mock::GLint FrameBufferId = 1910221209;
4781 const ::mock::GLint DefaultFrameBufferId = 1910221236;
4783 const auto TestCall = [&](
4784 const Component_t::ComponentPtr_t & _pDataTexture,
4785 const ::std::size_t _Index,
4786 const ::std::string & _TexName,
4787 const ::std::vector<uint32_t> & _RawData,
4788 const ::std::vector<uint32_t> & _ExpectData)
4790 const auto Index =
static_cast<::mock::GLint
>(_Index);
4792 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT(
"") };
4794 using namespace ::testing;
4798 EXPECT_CALL(GLProxy, GenTextures(1))
4800 .WillOnce(Return(TextureId));
4802 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4805 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
4807 GL_RGBA, GL_HALF_FLOAT, ::std::vector<uint8_t>{}))
4810 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4813 EXPECT_CALL(GLProxy, GetError())
4815 .WillOnce(Return(GL_NO_ERROR));
4817 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
4818 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
4820 (*_pDataTexture)[uT(
"entity")] = pTexture;
4822 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4824 .WillOnce(Return(FrameBufferId));
4826 EXPECT_CALL(GLProxy, GenTextures(1))
4829 auto Render = itCreator->second(Component_t::Make(
4831 { uT(
"service"), Object_t{ _pDataTexture } }
4833 ASSERT_NE(
nullptr, Render);
4835 const auto TestCallActivateTexture = [&](void)
4837 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4840 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4843 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4845 .WillOnce(Return(&ProgramId));
4847 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4849 .WillOnce(Return(LocationId));
4851 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
4854 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4860 EXPECT_CALL(oMapperProxy, Map(
nullptr))
4862 .WillOnce(Return(
false));
4864 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
4867 TestCallActivateTexture();
4872 EXPECT_CALL(oMapperProxy, Map(
nullptr))
4874 .WillOnce(Return(
true));
4876 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
4878 .WillOnce(Return(&DefaultFrameBufferId));
4880 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
4883 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
4884 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
4887 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
4889 .WillOnce(Return(_RawData));
4891 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
4892 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
4895 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
4898 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
4901 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
4904 TestCallActivateTexture();
4909 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
4912 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4916 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
4918 { uT(
"TexEnvironment"),
"TexEnvironment" },
4919 { uT(
"TexReflection"),
"TexReflection" },
4920 { uT(
"TexBaseColor"),
"TexBaseColor" },
4923 for (
int Index = 0; Index < Names.size(); Index++)
4925 const ::std::vector<uint32_t> RawData =
4927 0x10221334, 0x10221335, 0x10221336,
4928 0x10221337, 0x10221338, 0x10221339,
4929 0x10221340, 0x10221341, 0x10221342,
4930 0x10221343, 0x10221344, 0x10221345,
4933 const ::std::vector<uint32_t> ExpectData =
4935 0x10221343, 0x10221344, 0x10221345,
4936 0x10221340, 0x10221341, 0x10221342,
4937 0x10221337, 0x10221338, 0x10221339,
4938 0x10221334, 0x10221335, 0x10221336,
4941 const auto pData = Component_t::Make(
4943 { uT(
"kind"), uT(
"Texture") },
4944 { uT(
"width"), Width },
4945 { uT(
"height"), Height },
4946 { uT(
"mapper"), Mapper },
4947 { uT(
"name"), Names[Index].first },
4948 { uT(
"index"), Index },
4949 { uT(
"capacity"), 16 },
4952 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
4954 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4956 { uT(
"albedo"),
"TexAlbedo" },
4957 { uT(
"metalness"),
"TexMetalness" },
4958 { uT(
"roughness"),
"TexRoughness" },
4959 { uT(
"normal"),
"TexNormal" },
4960 { uT(
"occlusion"),
"TexOcclusion" },
4963 for (::std::size_t i = 0; i < Destinations.size(); i++)
4965 const auto pData = Component_t::Make(
4967 { uT(
"kind"), uT(
"Texture") },
4968 { uT(
"width"), Width },
4969 { uT(
"height"), Height },
4970 { uT(
"mapper"), Mapper },
4971 { uT(
"name"), Names[Index].first },
4972 { uT(
"index"), Index },
4973 { uT(
"destination"), Destinations[i].first },
4974 { uT(
"capacity"), 16 },
4977 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
4983TEST_F(OpenGLShader_test, Test_Texture_ReadData_NameAndIndex_Capacity32)
4985 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
4986 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
4988 using GLProxy_t = ::mock::GLProxy;
4990 GLProxy_t::GetInstance() = &GLProxy;
4993 public ::alicorn::extension::testing::Proxy<MapperProxy>
4996 MOCK_METHOD1(Map,
bool(
const void *));
4997 MOCK_METHOD1(CheckData,
void(::std::vector<uint32_t>));
5000 MapperProxy oMapperProxy;
5001 MapperProxy::GetInstance() = &oMapperProxy;
5003 const int Width = 3;
5004 const int Height = 4;
5006 const BufferMapper_t Mapper = [&](
const void * _pData)
5008 if (_pData !=
nullptr)
5010 ::std::vector<uint32_t> Data(Width * Height);
5011 memcpy(Data.data(), _pData, Width * Height * 4);
5012 oMapperProxy.CheckData(Data);
5015 return oMapperProxy.Map(_pData);
5018 const Tested_t Example{ Data_t{} };
5019 const ITested_t & IExample = Example;
5021 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
5022 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5024 const ::mock::GLint TextureId = 1910221154;
5025 const ::mock::GLint ProgramId = 1910221155;
5026 const ::mock::GLint LocationId = 1910221156;
5027 const ::mock::GLint FrameBufferId = 1910221209;
5028 const ::mock::GLint DefaultFrameBufferId = 1910221236;
5030 const auto TestCall = [&](
5031 const Component_t::ComponentPtr_t & _pDataTexture,
5032 const ::std::size_t _Index,
5033 const ::std::string & _TexName,
5034 const ::std::vector<uint32_t> & _RawData,
5035 const ::std::vector<uint32_t> & _ExpectData)
5037 const auto Index =
static_cast<::mock::GLint
>(_Index);
5039 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT(
"") };
5041 using namespace ::testing;
5045 EXPECT_CALL(GLProxy, GenTextures(1))
5047 .WillOnce(Return(TextureId));
5049 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5052 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
5054 GL_RGBA, GL_FLOAT, ::std::vector<uint8_t>{}))
5057 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5060 EXPECT_CALL(GLProxy, GetError())
5062 .WillOnce(Return(GL_NO_ERROR));
5064 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
5065 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
5067 (*_pDataTexture)[uT(
"entity")] = pTexture;
5069 EXPECT_CALL(GLProxy, GenFramebuffers(1))
5071 .WillOnce(Return(FrameBufferId));
5073 EXPECT_CALL(GLProxy, GenTextures(1))
5076 auto Render = itCreator->second(Component_t::Make(
5078 { uT(
"service"), Object_t{ _pDataTexture } }
5080 ASSERT_NE(
nullptr, Render);
5082 const auto TestCallActivateTexture = [&](void)
5084 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5087 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5090 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5092 .WillOnce(Return(&ProgramId));
5094 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5096 .WillOnce(Return(LocationId));
5098 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
5101 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5107 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5109 .WillOnce(Return(
false));
5111 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
5114 TestCallActivateTexture();
5119 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5121 .WillOnce(Return(
true));
5123 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
5125 .WillOnce(Return(&DefaultFrameBufferId));
5127 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
5130 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
5131 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
5134 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
5136 .WillOnce(Return(_RawData));
5138 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
5139 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
5142 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
5145 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
5148 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
5151 TestCallActivateTexture();
5156 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
5159 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5163 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
5165 { uT(
"TexEnvironment"),
"TexEnvironment" },
5166 { uT(
"TexReflection"),
"TexReflection" },
5167 { uT(
"TexBaseColor"),
"TexBaseColor" },
5170 for (
int Index = 0; Index < Names.size(); Index++)
5172 const ::std::vector<uint32_t> RawData =
5174 0x10221334, 0x10221335, 0x10221336,
5175 0x10221337, 0x10221338, 0x10221339,
5176 0x10221340, 0x10221341, 0x10221342,
5177 0x10221343, 0x10221344, 0x10221345,
5180 const ::std::vector<uint32_t> ExpectData =
5182 0x10221343, 0x10221344, 0x10221345,
5183 0x10221340, 0x10221341, 0x10221342,
5184 0x10221337, 0x10221338, 0x10221339,
5185 0x10221334, 0x10221335, 0x10221336,
5188 const auto pData = Component_t::Make(
5190 { uT(
"kind"), uT(
"Texture") },
5191 { uT(
"width"), Width },
5192 { uT(
"height"), Height },
5193 { uT(
"mapper"), Mapper },
5194 { uT(
"name"), Names[Index].first },
5195 { uT(
"index"), Index },
5196 { uT(
"capacity"), 32 },
5199 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
5201 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
5203 { uT(
"albedo"),
"TexAlbedo" },
5204 { uT(
"metalness"),
"TexMetalness" },
5205 { uT(
"roughness"),
"TexRoughness" },
5206 { uT(
"normal"),
"TexNormal" },
5207 { uT(
"occlusion"),
"TexOcclusion" },
5210 for (::std::size_t i = 0; i < Destinations.size(); i++)
5212 const auto pData = Component_t::Make(
5214 { uT(
"kind"), uT(
"Texture") },
5215 { uT(
"width"), Width },
5216 { uT(
"height"), Height },
5217 { uT(
"mapper"), Mapper },
5218 { uT(
"name"), Names[Index].first },
5219 { uT(
"index"), Index },
5220 { uT(
"destination"), Destinations[i].first },
5221 { uT(
"capacity"), 32 },
5224 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
5230TEST_F(OpenGLShader_test, Test_Texture_ReadData_Destination)
5232 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
5233 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
5235 using GLProxy_t = ::mock::GLProxy;
5237 GLProxy_t::GetInstance() = &GLProxy;
5240 public ::alicorn::extension::testing::Proxy<MapperProxy>
5243 MOCK_METHOD1(Map,
bool(
const void *));
5244 MOCK_METHOD1(CheckData,
void(::std::vector<uint32_t>));
5247 MapperProxy oMapperProxy;
5248 MapperProxy::GetInstance() = &oMapperProxy;
5250 const int Width = 3;
5251 const int Height = 4;
5253 const BufferMapper_t Mapper = [&](
const void * _pData)
5255 if (_pData !=
nullptr)
5257 ::std::vector<uint32_t> Data(Width * Height);
5258 memcpy(Data.data(), _pData, Width * Height * 4);
5259 oMapperProxy.CheckData(Data);
5262 return oMapperProxy.Map(_pData);
5265 const Tested_t Example{ Data_t{} };
5266 const ITested_t & IExample = Example;
5268 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
5269 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5271 const ::mock::GLint TextureId = 1910221154;
5272 const ::mock::GLint ProgramId = 1910221155;
5273 const ::mock::GLint LocationId = 1910221156;
5274 const ::mock::GLint FrameBufferId = 1910221209;
5275 const ::mock::GLint DefaultFrameBufferId = 1910221236;
5277 const auto TestCall = [&](
5278 const Component_t::ComponentPtr_t & _pDataTexture,
5279 const ::std::size_t _Index,
5280 const ::std::string & _TexName,
5281 const ::std::vector<uint32_t> & _RawData,
5282 const ::std::vector<uint32_t> & _ExpectData)
5284 const auto Index =
static_cast<::mock::GLint
>(_Index);
5286 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT(
"") };
5288 using namespace ::testing;
5292 EXPECT_CALL(GLProxy, GenTextures(1))
5294 .WillOnce(Return(TextureId));
5296 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5299 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
5301 GL_RGBA, GL_UNSIGNED_BYTE, ::std::vector<uint8_t>{}))
5304 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5307 EXPECT_CALL(GLProxy, GetError())
5309 .WillOnce(Return(GL_NO_ERROR));
5311 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
5312 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
5314 (*_pDataTexture)[uT(
"entity")] = pTexture;
5316 EXPECT_CALL(GLProxy, GenFramebuffers(1))
5318 .WillOnce(Return(FrameBufferId));
5320 EXPECT_CALL(GLProxy, GenTextures(1))
5323 auto Render = itCreator->second(Component_t::Make(
5325 { uT(
"service"), Object_t{ _pDataTexture } }
5327 ASSERT_NE(
nullptr, Render);
5329 const auto TestCallActivateTexture = [&](void)
5331 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5334 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5337 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5339 .WillOnce(Return(&ProgramId));
5341 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5343 .WillOnce(Return(LocationId));
5345 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
5348 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5354 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5356 .WillOnce(Return(
false));
5358 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
5361 TestCallActivateTexture();
5366 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5368 .WillOnce(Return(
true));
5370 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
5372 .WillOnce(Return(&DefaultFrameBufferId));
5374 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
5377 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
5378 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
5381 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
5383 .WillOnce(Return(_RawData));
5385 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
5386 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
5389 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
5392 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
5395 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
5398 TestCallActivateTexture();
5403 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
5406 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5410 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
5412 { uT(
"albedo"),
"TexAlbedo" },
5413 { uT(
"metalness"),
"TexMetalness" },
5414 { uT(
"roughness"),
"TexRoughness" },
5415 { uT(
"normal"),
"TexNormal" },
5416 { uT(
"occlusion"),
"TexOcclusion" },
5419 for (::std::size_t i = 0; i < Destinations.size(); i++)
5421 const ::std::vector<uint32_t> RawData =
5423 0x10221334, 0x10221335, 0x10221336,
5424 0x10221337, 0x10221338, 0x10221339,
5425 0x10221340, 0x10221341, 0x10221342,
5426 0x10221343, 0x10221344, 0x10221345,
5429 const ::std::vector<uint32_t> ExpectData =
5431 0x10221343, 0x10221344, 0x10221345,
5432 0x10221340, 0x10221341, 0x10221342,
5433 0x10221337, 0x10221338, 0x10221339,
5434 0x10221334, 0x10221335, 0x10221336,
5437 const auto pData = Component_t::Make(
5439 { uT(
"kind"), uT(
"Texture") },
5440 { uT(
"width"), Width },
5441 { uT(
"height"), Height },
5442 { uT(
"mapper"), Mapper },
5443 { uT(
"destination"), Destinations[i].first },
5446 TestCall(pData, i, Destinations[i].second, RawData, ExpectData);
5451TEST_F(OpenGLShader_test, Test_Texture_ReadData_Destination_Capacity16)
5453 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
5454 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
5456 using GLProxy_t = ::mock::GLProxy;
5458 GLProxy_t::GetInstance() = &GLProxy;
5461 public ::alicorn::extension::testing::Proxy<MapperProxy>
5464 MOCK_METHOD1(Map,
bool(
const void *));
5465 MOCK_METHOD1(CheckData,
void(::std::vector<uint32_t>));
5468 MapperProxy oMapperProxy;
5469 MapperProxy::GetInstance() = &oMapperProxy;
5471 const int Width = 3;
5472 const int Height = 4;
5474 const BufferMapper_t Mapper = [&](
const void * _pData)
5476 if (_pData !=
nullptr)
5478 ::std::vector<uint32_t> Data(Width * Height);
5479 memcpy(Data.data(), _pData, Width * Height * 4);
5480 oMapperProxy.CheckData(Data);
5483 return oMapperProxy.Map(_pData);
5486 const Tested_t Example{ Data_t{} };
5487 const ITested_t & IExample = Example;
5489 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
5490 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5492 const ::mock::GLint TextureId = 1910221154;
5493 const ::mock::GLint ProgramId = 1910221155;
5494 const ::mock::GLint LocationId = 1910221156;
5495 const ::mock::GLint FrameBufferId = 1910221209;
5496 const ::mock::GLint DefaultFrameBufferId = 1910221236;
5498 const auto TestCall = [&](
5499 const Component_t::ComponentPtr_t & _pDataTexture,
5500 const ::std::size_t _Index,
5501 const ::std::string & _TexName,
5502 const ::std::vector<uint32_t> & _RawData,
5503 const ::std::vector<uint32_t> & _ExpectData)
5505 const auto Index =
static_cast<::mock::GLint
>(_Index);
5507 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT(
"") };
5509 using namespace ::testing;
5513 EXPECT_CALL(GLProxy, GenTextures(1))
5515 .WillOnce(Return(TextureId));
5517 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5520 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
5522 GL_RGBA, GL_HALF_FLOAT, ::std::vector<uint8_t>{}))
5525 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5528 EXPECT_CALL(GLProxy, GetError())
5530 .WillOnce(Return(GL_NO_ERROR));
5532 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
5533 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
5535 (*_pDataTexture)[uT(
"entity")] = pTexture;
5537 EXPECT_CALL(GLProxy, GenFramebuffers(1))
5539 .WillOnce(Return(FrameBufferId));
5541 EXPECT_CALL(GLProxy, GenTextures(1))
5544 auto Render = itCreator->second(Component_t::Make(
5546 { uT(
"service"), Object_t{ _pDataTexture } }
5548 ASSERT_NE(
nullptr, Render);
5550 const auto TestCallActivateTexture = [&](void)
5552 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5555 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5558 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5560 .WillOnce(Return(&ProgramId));
5562 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5564 .WillOnce(Return(LocationId));
5566 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
5569 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5575 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5577 .WillOnce(Return(
false));
5579 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
5582 TestCallActivateTexture();
5587 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5589 .WillOnce(Return(
true));
5591 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
5593 .WillOnce(Return(&DefaultFrameBufferId));
5595 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
5598 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
5599 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
5602 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
5604 .WillOnce(Return(_RawData));
5606 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
5607 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
5610 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
5613 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
5616 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
5619 TestCallActivateTexture();
5624 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
5627 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5631 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
5633 { uT(
"albedo"),
"TexAlbedo" },
5634 { uT(
"metalness"),
"TexMetalness" },
5635 { uT(
"roughness"),
"TexRoughness" },
5636 { uT(
"normal"),
"TexNormal" },
5637 { uT(
"occlusion"),
"TexOcclusion" },
5640 for (::std::size_t i = 0; i < Destinations.size(); i++)
5642 const ::std::vector<uint32_t> RawData =
5644 0x10221334, 0x10221335, 0x10221336,
5645 0x10221337, 0x10221338, 0x10221339,
5646 0x10221340, 0x10221341, 0x10221342,
5647 0x10221343, 0x10221344, 0x10221345,
5650 const ::std::vector<uint32_t> ExpectData =
5652 0x10221343, 0x10221344, 0x10221345,
5653 0x10221340, 0x10221341, 0x10221342,
5654 0x10221337, 0x10221338, 0x10221339,
5655 0x10221334, 0x10221335, 0x10221336,
5658 const auto pData = Component_t::Make(
5660 { uT(
"kind"), uT(
"Texture") },
5661 { uT(
"width"), Width },
5662 { uT(
"height"), Height },
5663 { uT(
"mapper"), Mapper },
5664 { uT(
"destination"), Destinations[i].first },
5665 { uT(
"capacity"), 16 },
5668 TestCall(pData, i, Destinations[i].second, RawData, ExpectData);
5673TEST_F(OpenGLShader_test, Test_Texture_ReadData_Destination_Capacity32)
5675 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
5676 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
5678 using GLProxy_t = ::mock::GLProxy;
5680 GLProxy_t::GetInstance() = &GLProxy;
5683 public ::alicorn::extension::testing::Proxy<MapperProxy>
5686 MOCK_METHOD1(Map,
bool(
const void *));
5687 MOCK_METHOD1(CheckData,
void(::std::vector<uint32_t>));
5690 MapperProxy oMapperProxy;
5691 MapperProxy::GetInstance() = &oMapperProxy;
5693 const int Width = 3;
5694 const int Height = 4;
5696 const BufferMapper_t Mapper = [&](
const void * _pData)
5698 if (_pData !=
nullptr)
5700 ::std::vector<uint32_t> Data(Width * Height);
5701 memcpy(Data.data(), _pData, Width * Height * 4);
5702 oMapperProxy.CheckData(Data);
5705 return oMapperProxy.Map(_pData);
5708 const Tested_t Example{ Data_t{} };
5709 const ITested_t & IExample = Example;
5711 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
5712 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5714 const ::mock::GLint TextureId = 1910221154;
5715 const ::mock::GLint ProgramId = 1910221155;
5716 const ::mock::GLint LocationId = 1910221156;
5717 const ::mock::GLint FrameBufferId = 1910221209;
5718 const ::mock::GLint DefaultFrameBufferId = 1910221236;
5720 const auto TestCall = [&](
5721 const Component_t::ComponentPtr_t & _pDataTexture,
5722 const ::std::size_t _Index,
5723 const ::std::string & _TexName,
5724 const ::std::vector<uint32_t> & _RawData,
5725 const ::std::vector<uint32_t> & _ExpectData)
5727 const auto Index =
static_cast<::mock::GLint
>(_Index);
5729 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT(
"") };
5731 using namespace ::testing;
5735 EXPECT_CALL(GLProxy, GenTextures(1))
5737 .WillOnce(Return(TextureId));
5739 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5742 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
5744 GL_RGBA, GL_FLOAT, ::std::vector<uint8_t>{}))
5747 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5750 EXPECT_CALL(GLProxy, GetError())
5752 .WillOnce(Return(GL_NO_ERROR));
5754 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
5755 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
5757 (*_pDataTexture)[uT(
"entity")] = pTexture;
5759 EXPECT_CALL(GLProxy, GenFramebuffers(1))
5761 .WillOnce(Return(FrameBufferId));
5763 EXPECT_CALL(GLProxy, GenTextures(1))
5766 auto Render = itCreator->second(Component_t::Make(
5768 { uT(
"service"), Object_t{ _pDataTexture } }
5770 ASSERT_NE(
nullptr, Render);
5772 const auto TestCallActivateTexture = [&](void)
5774 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5777 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5780 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5782 .WillOnce(Return(&ProgramId));
5784 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5786 .WillOnce(Return(LocationId));
5788 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
5791 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5797 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5799 .WillOnce(Return(
false));
5801 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
5804 TestCallActivateTexture();
5809 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5811 .WillOnce(Return(
true));
5813 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
5815 .WillOnce(Return(&DefaultFrameBufferId));
5817 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
5820 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
5821 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
5824 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
5826 .WillOnce(Return(_RawData));
5828 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
5829 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
5832 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
5835 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
5838 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
5841 TestCallActivateTexture();
5846 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
5849 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5853 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
5855 { uT(
"albedo"),
"TexAlbedo" },
5856 { uT(
"metalness"),
"TexMetalness" },
5857 { uT(
"roughness"),
"TexRoughness" },
5858 { uT(
"normal"),
"TexNormal" },
5859 { uT(
"occlusion"),
"TexOcclusion" },
5862 for (::std::size_t i = 0; i < Destinations.size(); i++)
5864 const ::std::vector<uint32_t> RawData =
5866 0x10221334, 0x10221335, 0x10221336,
5867 0x10221337, 0x10221338, 0x10221339,
5868 0x10221340, 0x10221341, 0x10221342,
5869 0x10221343, 0x10221344, 0x10221345,
5872 const ::std::vector<uint32_t> ExpectData =
5874 0x10221343, 0x10221344, 0x10221345,
5875 0x10221340, 0x10221341, 0x10221342,
5876 0x10221337, 0x10221338, 0x10221339,
5877 0x10221334, 0x10221335, 0x10221336,
5880 const auto pData = Component_t::Make(
5882 { uT(
"kind"), uT(
"Texture") },
5883 { uT(
"width"), Width },
5884 { uT(
"height"), Height },
5885 { uT(
"mapper"), Mapper },
5886 { uT(
"destination"), Destinations[i].first },
5887 { uT(
"capacity"), 32 },
5890 TestCall(pData, i, Destinations[i].second, RawData, ExpectData);
5895TEST_F(OpenGLShader_test, Test_Texture_Depth_NameAndIndex)
5897 using GLProxy_t = ::mock::GLProxy;
5899 GLProxy_t::GetInstance() = &GLProxy;
5901 const Tested_t Example{ Data_t{} };
5902 const ITested_t & IExample = Example;
5904 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
5905 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5907 const ::mock::GLuint TextureId = 1910041336;
5908 const ::mock::GLint ProgramId = 1910041337;
5909 const ::mock::GLint LocationId = 1910041338;
5911 const auto TestCall = [&](
5912 const Component_t::ComponentPtr_t & _pTexture,
5913 const ::std::vector<uint8_t> & _Source,
5914 const int _Width,
const int _Height,
5915 const ::std::size_t _Index,
5916 const ::std::string & _TexName)
5918 const auto Index =
static_cast<::mock::GLint
>(_Index);
5920 using namespace ::testing;
5924 EXPECT_CALL(GLProxy, GenTextures(1))
5926 .WillOnce(Return(TextureId));
5928 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5931 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
5933 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, _Source))
5936 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5939 EXPECT_CALL(GLProxy, GetError())
5941 .WillOnce(Return(GL_NO_ERROR));
5943 auto Render = itCreator->second(_pTexture);
5944 ASSERT_NE(
nullptr, Render);
5946 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5949 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5952 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5954 .WillOnce(Return(&ProgramId));
5956 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5958 .WillOnce(Return(LocationId));
5960 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
5963 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5968 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5972 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
5974 { uT(
"TexEnvironment"),
"TexEnvironment" },
5975 { uT(
"TexReflection"),
"TexReflection" },
5976 { uT(
"TexBaseColor"),
"TexBaseColor" },
5979 for (
int Index = 0; Index < Names.size(); Index++)
5981 ::std::vector<uint8_t> Source =
5983 0x20, 0x06, 0x15, 0x12, 0x32,
5984 0x20, 0x06, 0x15, 0x12, 0x32,
5985 0x20, 0x06, 0x15, 0x12, 0x32,
5986 0x20, 0x06, 0x15, 0x12, 0x32,
5987 0x20, 0x06, 0x15, 0x12, 0x32,
5989 IntroduceBufferSize(Source);
5992 const int Width = 1910041343;
5993 const int Height = 1910041344;
5995 const auto pTexture = Component_t::Make(
5997 { uT(
"content"), Source },
5998 { uT(
"width"), Width },
5999 { uT(
"height"), Height },
6000 { uT(
"name"), Names[Index].first },
6001 { uT(
"index"), Index },
6002 { uT(
"destination"), uT(
"depth") },
6005 TestCall(pTexture, Source, Width, Height, Index, Names[Index].second);
6009 const int Width = 1910041346;
6010 const int Height = 1910041347;
6012 const auto pData = Component_t::Make(
6014 { uT(
"kind"), uT(
"Texture") },
6015 { uT(
"content"), Source },
6016 { uT(
"width"), Width },
6017 { uT(
"height"), Height },
6018 { uT(
"name"), Names[Index].first },
6019 { uT(
"index"), Index },
6020 { uT(
"destination"), uT(
"depth") },
6023 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6024 Source, Width, Height, Index, Names[Index].second);
6030TEST_F(OpenGLShader_test, Test_Texture_Depth_Destination)
6032 using GLProxy_t = ::mock::GLProxy;
6034 GLProxy_t::GetInstance() = &GLProxy;
6036 const Tested_t Example{ Data_t{} };
6037 const ITested_t & IExample = Example;
6039 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
6040 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6042 const ::mock::GLuint TextureId = 1910041336;
6043 const ::mock::GLint ProgramId = 1910041337;
6044 const ::mock::GLint LocationId = 1910041338;
6046 const auto TestCall = [&](
6047 const Component_t::ComponentPtr_t & _pTexture,
6048 const ::std::vector<uint8_t> & _Source,
6049 const int _Width,
const int _Height,
6050 const ::std::size_t _Index,
6051 const ::std::string & _TexName)
6053 const auto Index =
static_cast<::mock::GLint
>(_Index);
6055 using namespace ::testing;
6059 EXPECT_CALL(GLProxy, GenTextures(1))
6061 .WillOnce(Return(TextureId));
6063 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6066 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
6068 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, _Source))
6071 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
6074 EXPECT_CALL(GLProxy, GetError())
6076 .WillOnce(Return(GL_NO_ERROR));
6078 auto Render = itCreator->second(_pTexture);
6079 ASSERT_NE(
nullptr, Render);
6081 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
6084 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6087 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6089 .WillOnce(Return(&ProgramId));
6091 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
6093 .WillOnce(Return(LocationId));
6095 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
6098 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
6103 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6107 ::std::vector<uint8_t> Source =
6109 0x20, 0x06, 0x15, 0x12, 0x32,
6110 0x20, 0x06, 0x15, 0x12, 0x32,
6111 0x20, 0x06, 0x15, 0x12, 0x32,
6112 0x20, 0x06, 0x15, 0x12, 0x32,
6113 0x20, 0x06, 0x15, 0x12, 0x32,
6115 IntroduceBufferSize(Source);
6118 const int Width = 1910041343;
6119 const int Height = 1910041344;
6121 const auto pTexture = Component_t::Make(
6123 { uT(
"content"), Source },
6124 { uT(
"width"), Width },
6125 { uT(
"height"), Height },
6126 { uT(
"destination"), uT(
"depth") },
6129 TestCall(pTexture, Source, Width, Height, 5,
"TexDepth");
6133 const int Width = 1910041346;
6134 const int Height = 1910041347;
6136 const auto pData = Component_t::Make(
6138 { uT(
"kind"), uT(
"Texture") },
6139 { uT(
"content"), Source },
6140 { uT(
"width"), Width },
6141 { uT(
"height"), Height },
6142 { uT(
"destination"), uT(
"depth") },
6145 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6146 Source, Width, Height, 5,
"TexDepth");
6151TEST_F(OpenGLShader_test, Test_Texture_UsingExists_NameAndIndex)
6153 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
6155 using GLProxy_t = ::mock::GLProxy;
6157 GLProxy_t::GetInstance() = &GLProxy;
6159 const Tested_t Example{ Data_t{} };
6160 const ITested_t & IExample = Example;
6162 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
6163 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6165 const ::mock::GLuint TextureId = 1908221839;
6166 const ::mock::GLint ProgramId = 1908221840;
6167 const ::mock::GLint LocationId = 1908221841;
6169 const auto TestCall = [&](
6170 const Component_t::ComponentPtr_t & _pData,
6171 const Component_t::ComponentPtr_t & _pTexture,
6172 const ::std::vector<uint8_t> & _Source,
6173 const int _Width,
const int _Height,
6174 const ::std::size_t _Index,
6175 const ::std::string & _TexName)
6177 const ::covellite::api::renderer::Component::Texture TextureData{ *_pData, uT(
"") };
6178 const auto Index =
static_cast<::mock::GLint
>(_Index);
6180 using namespace ::testing;
6184 EXPECT_CALL(GLProxy, GenTextures(1))
6186 .WillOnce(Return(TextureId));
6188 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6191 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, _,
6192 _Width, _Height, 0, _, _, _Source))
6195 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
6198 EXPECT_CALL(GLProxy, GetError())
6200 .WillOnce(Return(GL_NO_ERROR));
6202 (*_pData)[uT(
"entity")] = ::std::make_shared<Texture_t>(TextureData);
6204 EXPECT_CALL(GLProxy, GenTextures(_))
6207 auto Render = itCreator->second(_pTexture);
6208 ASSERT_NE(
nullptr, Render);
6210 const Texture_t::Ptr_t pEntity = (*_pData)[uT(
"entity")].Default(Texture_t::Ptr_t{});
6211 EXPECT_EQ(
nullptr, pEntity);
6213 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
6216 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6219 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6221 .WillOnce(Return(&ProgramId));
6223 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
6225 .WillOnce(Return(LocationId));
6227 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
6232 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6236 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
6238 { uT(
"TexEnvironment"),
"TexEnvironment" },
6239 { uT(
"TexReflection"),
"TexReflection" },
6240 { uT(
"TexBaseColor"),
"TexBaseColor" },
6243 for (
int Index = 0; Index < Names.size(); Index++)
6245 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
6247 { uT(
"albedo"),
"TexAlbedo" },
6248 { uT(
"metalness"),
"TexMetalness" },
6249 { uT(
"roughness"),
"TexRoughness" },
6250 { uT(
"normal"),
"TexNormal" },
6251 { uT(
"occlusion"),
"TexOcclusion" },
6252 { uT(
"depth"),
"TexDepth" },
6255 ::std::vector<uint8_t> Source =
6257 0x20, 0x06, 0x15, 0x12, 0x33,
6258 0x20, 0x06, 0x15, 0x12, 0x33,
6259 0x20, 0x06, 0x15, 0x12, 0x33,
6260 0x20, 0x06, 0x15, 0x12, 0x33,
6261 0x20, 0x06, 0x15, 0x12, 0x33,
6263 IntroduceBufferSize(Source);
6265 for (::std::size_t i = 0; i < Destinations.size(); i++)
6267 const int Width = 1908221845;
6268 const int Height = 1908221847;
6270 const auto pData = Component_t::Make(
6272 { uT(
"kind"), uT(
"Texture") },
6273 { uT(
"content"), Source },
6274 { uT(
"width"), Width },
6275 { uT(
"height"), Height },
6276 { uT(
"name"), Names[Index].first },
6277 { uT(
"index"), Index },
6278 { uT(
"destination"), Destinations[i].first },
6281 TestCall(pData, Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6282 Source, Width, Height, Index, Names[Index].second);
6288TEST_F(OpenGLShader_test, Test_Texture_UsingExists_Destination)
6290 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
6292 using GLProxy_t = ::mock::GLProxy;
6294 GLProxy_t::GetInstance() = &GLProxy;
6296 const Tested_t Example{ Data_t{} };
6297 const ITested_t & IExample = Example;
6299 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
6300 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6302 const ::mock::GLuint TextureId = 1908221839;
6303 const ::mock::GLint ProgramId = 1908221840;
6304 const ::mock::GLint LocationId = 1908221841;
6306 const auto TestCall = [&](
6307 const Component_t::ComponentPtr_t & _pData,
6308 const Component_t::ComponentPtr_t & _pTexture,
6309 const ::std::vector<uint8_t> & _Source,
6310 const int _Width,
const int _Height,
6311 const ::std::size_t _Index,
6312 const ::std::string & _TexName)
6314 const ::covellite::api::renderer::Component::Texture TextureData{ *_pData, uT(
"") };
6315 const auto Index =
static_cast<::mock::GLint
>(_Index);
6317 using namespace ::testing;
6321 EXPECT_CALL(GLProxy, GenTextures(1))
6323 .WillOnce(Return(TextureId));
6325 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6328 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, _,
6329 _Width, _Height, 0, _, _, _Source))
6332 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
6335 EXPECT_CALL(GLProxy, GetError())
6337 .WillOnce(Return(GL_NO_ERROR));
6339 (*_pData)[uT(
"entity")] = ::std::make_shared<Texture_t>(TextureData);
6341 EXPECT_CALL(GLProxy, GenTextures(_))
6344 auto Render = itCreator->second(_pTexture);
6345 ASSERT_NE(
nullptr, Render);
6347 const Texture_t::Ptr_t pEntity = (*_pData)[uT(
"entity")].Default(Texture_t::Ptr_t{});
6348 EXPECT_EQ(
nullptr, pEntity);
6350 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
6353 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6356 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6358 .WillOnce(Return(&ProgramId));
6360 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
6362 .WillOnce(Return(LocationId));
6364 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
6369 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6373 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
6375 { uT(
"albedo"),
"TexAlbedo" },
6376 { uT(
"metalness"),
"TexMetalness" },
6377 { uT(
"roughness"),
"TexRoughness" },
6378 { uT(
"normal"),
"TexNormal" },
6379 { uT(
"occlusion"),
"TexOcclusion" },
6380 { uT(
"depth"),
"TexDepth" },
6383 ::std::vector<uint8_t> Source =
6385 0x20, 0x06, 0x15, 0x12, 0x33,
6386 0x20, 0x06, 0x15, 0x12, 0x33,
6387 0x20, 0x06, 0x15, 0x12, 0x33,
6388 0x20, 0x06, 0x15, 0x12, 0x33,
6389 0x20, 0x06, 0x15, 0x12, 0x33,
6391 IntroduceBufferSize(Source);
6393 for (::std::size_t i = 0; i < Destinations.size(); i++)
6395 const int Width = 1908221845;
6396 const int Height = 1908221847;
6398 const auto pData = Component_t::Make(
6400 { uT(
"kind"), uT(
"Texture") },
6401 { uT(
"content"), Source },
6402 { uT(
"width"), Width },
6403 { uT(
"height"), Height },
6404 { uT(
"destination"), Destinations[i].first },
6407 TestCall(pData, Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6408 Source, Width, Height, i, Destinations[i].second);
6413TEST_F(OpenGLShader_test, Test_Texture_NoDeclaredInShader)
6415 using GLProxy_t = ::mock::GLProxy;
6417 GLProxy_t::GetInstance() = &GLProxy;
6419 const Tested_t Example{ Data_t{} };
6420 const ITested_t & IExample = Example;
6422 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
6423 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6425 const ::mock::GLuint TextureId = 1908221839;
6427 const auto TestCall = [&](
6428 const Component_t::ComponentPtr_t & _pTexture,
6429 const ::std::vector<uint8_t> & ,
6430 const int ,
const int ,
6431 const ::std::size_t _Index,
6432 const ::std::string & _TexName)
6434 const auto Index =
static_cast<::mock::GLint
>(_Index);
6436 using namespace ::testing;
6440 EXPECT_CALL(GLProxy, GenTextures(1))
6442 .WillOnce(Return(TextureId));
6444 auto Render = itCreator->second(_pTexture);
6445 ASSERT_NE(
nullptr, Render);
6447 EXPECT_CALL(GLProxy, GetUniformLocation(_, _TexName))
6449 .WillOnce(Return(-1));
6451 EXPECT_CALL(GLProxy, Uniform1i(_, _))
6456 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6460 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
6462 { uT(
"albedo"),
"TexAlbedo" },
6463 { uT(
"metalness"),
"TexMetalness" },
6464 { uT(
"roughness"),
"TexRoughness" },
6465 { uT(
"normal"),
"TexNormal" },
6466 { uT(
"occlusion"),
"TexOcclusion" },
6467 { uT(
"depth"),
"TexDepth" },
6470 ::std::vector<uint8_t> Source =
6472 0x20, 0x06, 0x15, 0x12, 0x34,
6473 0x20, 0x06, 0x15, 0x12, 0x34,
6474 0x20, 0x06, 0x15, 0x12, 0x34,
6475 0x20, 0x06, 0x15, 0x12, 0x34,
6476 0x20, 0x06, 0x15, 0x12, 0x34,
6478 IntroduceBufferSize(Source);
6480 for (::std::size_t i = 0; i < Destinations.size(); i++)
6483 const uint8_t * pSource = (uint8_t *)1908221842;
6484 const int Width = 1908221843;
6485 const int Height = 1908221844;
6487 const auto pTexture = Component_t::Make(
6489 { uT(
"content"), Source },
6490 { uT(
"width"), Width },
6491 { uT(
"height"), Height },
6492 { uT(
"destination"), Destinations[i].first },
6496 Source, Width, Height, i, Destinations[i].second);
6500 const uint8_t * pSource = (uint8_t *)1908221846;
6501 const int Width = 1908221845;
6502 const int Height = 1908221847;
6504 const auto pData = Component_t::Make(
6506 { uT(
"kind"), uT(
"Texture") },
6507 { uT(
"content"), Source },
6508 { uT(
"width"), Width },
6509 { uT(
"height"), Height },
6510 { uT(
"destination"), Destinations[i].first },
6513 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6514 Source, Width, Height, i, Destinations[i].second);
6520TEST_F(OpenGLShader_test, Test_TextureArray_Default)
6522 using GLProxy_t = ::mock::GLProxy;
6524 GLProxy_t::GetInstance() = &GLProxy;
6526 const Tested_t Example{ Data_t{} };
6527 const ITested_t & IExample = Example;
6529 auto itCreator = IExample.GetCreators().find(uT(
"TextureArray"));
6530 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6532 const ::mock::GLuint TextureId = 1812181809;
6533 const ::mock::GLint ProgramId = 1908221258;
6534 const ::mock::GLint LocationId = 1908221259;
6536 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pTexture,
6537 const ::std::vector<uint8_t> & _Source,
const int _Width,
const int _Height)
6539 using namespace ::testing;
6543 EXPECT_CALL(GLProxy, GenTextures(1))
6545 .WillOnce(Return(TextureId));
6547 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
6550 EXPECT_CALL(GLProxy, TexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8,
6551 _Width, _Height, 1))
6554 EXPECT_CALL(GLProxy, TexSubImage3D_1(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0,
6558 EXPECT_CALL(GLProxy, TexSubImage3D_2(1, GL_RGBA,
6559 GL_UNSIGNED_BYTE, _Source))
6562 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, 0))
6565 EXPECT_CALL(GLProxy, GetError())
6567 .WillOnce(Return(GL_NO_ERROR));
6569 auto Render = itCreator->second(_pTexture);
6570 ASSERT_NE(
nullptr, Render);
6572 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0))
6575 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
6578 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6580 .WillOnce(Return(&ProgramId));
6582 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"TexDiffuse")))
6584 .WillOnce(Return(LocationId));
6586 EXPECT_CALL(GLProxy, Uniform1i(LocationId, 0))
6591 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6596 ::std::vector<uint8_t> Source =
6598 0x20, 0x06, 0x15, 0x12, 0x28,
6599 0x20, 0x06, 0x15, 0x12, 0x28,
6600 0x20, 0x06, 0x15, 0x12, 0x28,
6601 0x20, 0x06, 0x15, 0x12, 0x28,
6602 0x20, 0x06, 0x15, 0x12, 0x28,
6603 0x20, 0x06, 0x15, 0x12, 0x28,
6604 0x20, 0x06, 0x15, 0x12, 0x28,
6605 0x20, 0x06, 0x15, 0x12, 0x28,
6607 IntroduceBufferSize(Source);
6609 const int Width = 1812181807;
6610 const int Height = 1812181808;
6612 const auto pTexture = Component_t::Make(
6614 { uT(
"content"), ::std::vector{ Source } },
6615 { uT(
"width"), Width },
6616 { uT(
"height"), Height },
6619 TestCall(pTexture, Source, Width, Height);
6623 ::std::vector<uint8_t> Source =
6625 0x20, 0x06, 0x15, 0x12, 0x29,
6626 0x20, 0x06, 0x15, 0x12, 0x29,
6627 0x20, 0x06, 0x15, 0x12, 0x29,
6628 0x25, 0x04, 0x07, 0x21, 0x03,
6629 0x25, 0x04, 0x07, 0x21, 0x04,
6630 0x25, 0x04, 0x07, 0x21, 0x05,
6631 0x25, 0x04, 0x07, 0x21, 0x06
6633 IntroduceBufferSize(Source);
6635 const int Width = 1907251057;
6636 const int Height = 1907251058;
6638 const auto pData = Component_t::Make(
6640 { uT(
"kind"), uT(
"TextureArray") },
6641 { uT(
"content"), ::std::vector{ Source } },
6642 { uT(
"width"), Width },
6643 { uT(
"height"), Height },
6646 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6647 Source, Width, Height);
6652TEST_F(OpenGLShader_test, Test_TextureArray_NameAndIndex)
6654 using GLProxy_t = ::mock::GLProxy;
6656 GLProxy_t::GetInstance() = &GLProxy;
6658 const Tested_t Example{ Data_t{} };
6659 const ITested_t & IExample = Example;
6661 auto itCreator = IExample.GetCreators().find(uT(
"TextureArray"));
6662 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6664 const ::mock::GLuint TextureId = 1908221839;
6665 const ::mock::GLint ProgramId = 1908221840;
6666 const ::mock::GLint LocationId = 1908221841;
6668 const auto TestCall = [&](
6669 const Component_t::ComponentPtr_t & _pTexture,
6670 const ::std::vector<uint8_t> & _Source,
6671 const int _Width,
const int _Height,
6672 const ::std::size_t _Index,
6673 const ::std::string & _TexName)
6675 const auto Index =
static_cast<::mock::GLint
>(_Index);
6677 using namespace ::testing;
6681 EXPECT_CALL(GLProxy, GenTextures(1))
6683 .WillOnce(Return(TextureId));
6685 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
6688 EXPECT_CALL(GLProxy, TexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8,
6689 _Width, _Height, 1))
6692 EXPECT_CALL(GLProxy, TexSubImage3D_1(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0,
6696 EXPECT_CALL(GLProxy, TexSubImage3D_2(1, GL_RGBA,
6697 GL_UNSIGNED_BYTE, _Source))
6700 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, 0))
6703 EXPECT_CALL(GLProxy, GetError())
6705 .WillOnce(Return(GL_NO_ERROR));
6707 auto Render = itCreator->second(_pTexture);
6708 ASSERT_NE(
nullptr, Render);
6710 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
6713 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
6716 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6718 .WillOnce(Return(&ProgramId));
6720 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
6722 .WillOnce(Return(LocationId));
6724 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
6727 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
6732 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6736 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
6738 { uT(
"TexEnvironment"),
"TexEnvironment" },
6739 { uT(
"TexReflection"),
"TexReflection" },
6740 { uT(
"TexBaseColor"),
"TexBaseColor" },
6743 for (
int Index = 0; Index < Names.size(); Index++)
6745 ::std::vector<uint8_t> Source =
6747 0x20, 0x06, 0x15, 0x12, 0x30,
6748 0x20, 0x06, 0x15, 0x12, 0x30,
6749 0x20, 0x06, 0x15, 0x12, 0x30,
6750 0x20, 0x06, 0x15, 0x12, 0x30,
6751 0x20, 0x06, 0x15, 0x12, 0x30,
6753 IntroduceBufferSize(Source);
6756 const int Width = 1908221843;
6757 const int Height = 1908221844;
6759 const auto pTexture = Component_t::Make(
6761 { uT(
"content"), ::std::vector{ Source } },
6762 { uT(
"width"), Width },
6763 { uT(
"height"), Height },
6764 { uT(
"name"), Names[Index].first },
6765 { uT(
"index"), Index },
6769 Source, Width, Height, Index, Names[Index].second);
6773 const int Width = 1908221845;
6774 const int Height = 1908221847;
6776 const auto pData = Component_t::Make(
6778 { uT(
"kind"), uT(
"TextureArray") },
6779 { uT(
"content"), ::std::vector{ Source } },
6780 { uT(
"width"), Width },
6781 { uT(
"height"), Height },
6782 { uT(
"name"), Names[Index].first },
6783 { uT(
"index"), Index },
6786 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6787 Source, Width, Height, Index, Names[Index].second);
6791 const int Width = 1908221843;
6792 const int Height = 1908221844;
6794 const auto pTexture = Component_t::Make(
6796 { uT(
"content"), ::std::vector{ Source } },
6797 { uT(
"width"), Width },
6798 { uT(
"height"), Height },
6799 { uT(
"name"), Names[Index].first },
6800 { uT(
"index"), Index },
6801 { uT(
"mipmapping"),
false },
6805 Source, Width, Height, Index, Names[Index].second);
6809 const int Width = 1908221845;
6810 const int Height = 1908221847;
6812 const auto pData = Component_t::Make(
6814 { uT(
"kind"), uT(
"TextureArray") },
6815 { uT(
"content"), ::std::vector{ Source } },
6816 { uT(
"width"), Width },
6817 { uT(
"height"), Height },
6818 { uT(
"name"), Names[Index].first },
6819 { uT(
"index"), Index },
6820 { uT(
"mipmapping"),
false },
6823 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6824 Source, Width, Height, Index, Names[Index].second);
6827 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
6829 { uT(
"albedo"),
"TexAlbedo" },
6830 { uT(
"metalness"),
"TexMetalness" },
6831 { uT(
"roughness"),
"TexRoughness" },
6832 { uT(
"normal"),
"TexNormal" },
6833 { uT(
"occlusion"),
"TexOcclusion" },
6837 for (::std::size_t i = 0; i < Destinations.size(); i++)
6840 const int Width = 1908221843;
6841 const int Height = 1908221844;
6843 const auto pTexture = Component_t::Make(
6845 { uT(
"content"), ::std::vector{ Source } },
6846 { uT(
"width"), Width },
6847 { uT(
"height"), Height },
6848 { uT(
"name"), Names[Index].first },
6849 { uT(
"index"), Index },
6850 { uT(
"destination"), Destinations[i].first },
6854 Source, Width, Height, Index, Names[Index].second);
6858 const int Width = 1908221845;
6859 const int Height = 1908221847;
6861 const auto pData = Component_t::Make(
6863 { uT(
"kind"), uT(
"TextureArray") },
6864 { uT(
"content"), ::std::vector{ Source } },
6865 { uT(
"width"), Width },
6866 { uT(
"height"), Height },
6867 { uT(
"name"), Names[Index].first },
6868 { uT(
"index"), Index },
6869 { uT(
"destination"), Destinations[i].first },
6872 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6873 Source, Width, Height, Index, Names[Index].second);
6877 const int Width = 1908221843;
6878 const int Height = 1908221844;
6880 const auto pTexture = Component_t::Make(
6882 { uT(
"content"), ::std::vector{ Source } },
6883 { uT(
"width"), Width },
6884 { uT(
"height"), Height },
6885 { uT(
"name"), Names[Index].first },
6886 { uT(
"index"), Index },
6887 { uT(
"destination"), Destinations[i].first },
6888 { uT(
"mipmapping"),
false },
6892 Source, Width, Height, Index, Names[Index].second);
6896 const int Width = 1908221845;
6897 const int Height = 1908221847;
6899 const auto pData = Component_t::Make(
6901 { uT(
"kind"), uT(
"TextureArray") },
6902 { uT(
"content"), ::std::vector{ Source } },
6903 { uT(
"width"), Width },
6904 { uT(
"height"), Height },
6905 { uT(
"name"), Names[Index].first },
6906 { uT(
"index"), Index },
6907 { uT(
"destination"), Destinations[i].first },
6908 { uT(
"mipmapping"),
false },
6911 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6912 Source, Width, Height, Index, Names[Index].second);
6919TEST_F(OpenGLShader_test, Test_TextureArray_Destination)
6921 using GLProxy_t = ::mock::GLProxy;
6923 GLProxy_t::GetInstance() = &GLProxy;
6925 const Tested_t Example{ Data_t{} };
6926 const ITested_t & IExample = Example;
6928 auto itCreator = IExample.GetCreators().find(uT(
"TextureArray"));
6929 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6931 const ::mock::GLuint TextureId = 1908221839;
6932 const ::mock::GLint ProgramId = 1908221840;
6933 const ::mock::GLint LocationId = 1908221841;
6935 const auto TestCall = [&](
6936 const Component_t::ComponentPtr_t & _pTexture,
6937 const ::std::vector<uint8_t> & _Source,
6938 const int _Width,
const int _Height,
6939 const ::std::size_t _Index,
6940 const ::std::string & _TexName)
6942 const auto Index =
static_cast<::mock::GLint
>(_Index);
6944 using namespace ::testing;
6948 EXPECT_CALL(GLProxy, GenTextures(1))
6950 .WillOnce(Return(TextureId));
6952 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
6955 EXPECT_CALL(GLProxy, TexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA8,
6956 _Width, _Height, 1))
6959 EXPECT_CALL(GLProxy, TexSubImage3D_1(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0,
6963 EXPECT_CALL(GLProxy, TexSubImage3D_2(1, GL_RGBA,
6964 GL_UNSIGNED_BYTE, _Source))
6967 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, 0))
6970 EXPECT_CALL(GLProxy, GetError())
6972 .WillOnce(Return(GL_NO_ERROR));
6974 auto Render = itCreator->second(_pTexture);
6975 ASSERT_NE(
nullptr, Render);
6977 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
6980 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
6983 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6985 .WillOnce(Return(&ProgramId));
6987 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
6989 .WillOnce(Return(LocationId));
6991 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
6994 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
6999 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
7003 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
7005 { uT(
"albedo"),
"TexAlbedo" },
7006 { uT(
"metalness"),
"TexMetalness" },
7007 { uT(
"roughness"),
"TexRoughness" },
7008 { uT(
"normal"),
"TexNormal" },
7009 { uT(
"occlusion"),
"TexOcclusion" },
7013 ::std::vector<uint8_t> Source =
7015 0x20, 0x06, 0x15, 0x12, 0x30,
7016 0x20, 0x06, 0x15, 0x12, 0x30,
7017 0x20, 0x06, 0x15, 0x12, 0x30,
7018 0x20, 0x06, 0x15, 0x12, 0x30,
7019 0x20, 0x06, 0x15, 0x12, 0x30,
7021 IntroduceBufferSize(Source);
7023 for (::std::size_t i = 0; i < Destinations.size(); i++)
7026 const int Width = 1908221843;
7027 const int Height = 1908221844;
7029 const auto pTexture = Component_t::Make(
7031 { uT(
"content"), ::std::vector{ Source } },
7032 { uT(
"width"), Width },
7033 { uT(
"height"), Height },
7034 { uT(
"destination"), Destinations[i].first },
7038 Source, Width, Height, i, Destinations[i].second);
7042 const int Width = 1908221845;
7043 const int Height = 1908221847;
7045 const auto pData = Component_t::Make(
7047 { uT(
"kind"), uT(
"TextureArray") },
7048 { uT(
"content"), ::std::vector{ Source } },
7049 { uT(
"width"), Width },
7050 { uT(
"height"), Height },
7051 { uT(
"destination"), Destinations[i].first },
7054 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
7055 Source, Width, Height, i, Destinations[i].second);
7059 const int Width = 1908221843;
7060 const int Height = 1908221844;
7062 const auto pTexture = Component_t::Make(
7064 { uT(
"content"), ::std::vector{ Source } },
7065 { uT(
"width"), Width },
7066 { uT(
"height"), Height },
7067 { uT(
"destination"), Destinations[i].first },
7068 { uT(
"mipmapping"),
false },
7072 Source, Width, Height, i, Destinations[i].second);
7076 const int Width = 1908221845;
7077 const int Height = 1908221847;
7079 const auto pData = Component_t::Make(
7081 { uT(
"kind"), uT(
"TextureArray") },
7082 { uT(
"content"), ::std::vector{ Source } },
7083 { uT(
"width"), Width },
7084 { uT(
"height"), Height },
7085 { uT(
"destination"), Destinations[i].first },
7086 { uT(
"mipmapping"),
false },
7089 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
7090 Source, Width, Height, i, Destinations[i].second);
7096TEST_F(OpenGLShader_test, Test_TextureArray_Mipmapping_NameAndIndex)
7098 using GLProxy_t = ::mock::GLProxy;
7100 GLProxy_t::GetInstance() = &GLProxy;
7102 const Tested_t Example{ Data_t{} };
7103 const ITested_t & IExample = Example;
7105 auto itCreator = IExample.GetCreators().find(uT(
"TextureArray"));
7106 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7108 const ::mock::GLuint TextureId = 1908221839;
7109 const ::mock::GLint ProgramId = 1908221840;
7110 const ::mock::GLint LocationId = 1908221841;
7112 const auto TestCall = [&](
7113 const Component_t::ComponentPtr_t & _pTexture,
7114 const ::std::vector<uint8_t> & _Source,
7115 const int _Width,
const int _Height,
7116 const ::std::size_t _Index,
7117 const ::std::string & _TexName)
7119 const auto Index =
static_cast<::mock::GLint
>(_Index);
7121 using namespace ::testing;
7125 EXPECT_CALL(GLProxy, GenTextures(1))
7127 .WillOnce(Return(TextureId));
7129 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
7132 EXPECT_CALL(GLProxy, TexStorage3D(GL_TEXTURE_2D_ARRAY, 8, GL_RGBA8,
7133 _Width, _Height, 1))
7136 EXPECT_CALL(GLProxy, TexSubImage3D_1(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0,
7140 EXPECT_CALL(GLProxy, TexSubImage3D_2(1, GL_RGBA,
7141 GL_UNSIGNED_BYTE, _Source))
7144 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D_ARRAY))
7147 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, 0))
7150 EXPECT_CALL(GLProxy, GetError())
7152 .WillOnce(Return(GL_NO_ERROR));
7154 auto Render = itCreator->second(_pTexture);
7155 ASSERT_NE(
nullptr, Render);
7157 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
7160 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
7163 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
7165 .WillOnce(Return(&ProgramId));
7167 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
7169 .WillOnce(Return(LocationId));
7171 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
7174 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
7179 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
7183 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
7185 { uT(
"TexEnvironment"),
"TexEnvironment" },
7186 { uT(
"TexReflection"),
"TexReflection" },
7187 { uT(
"TexBaseColor"),
"TexBaseColor" },
7190 for (
int Index = 0; Index < Names.size(); Index++)
7192 ::std::vector<uint8_t> Source =
7194 0x20, 0x06, 0x15, 0x12, 0x31,
7195 0x20, 0x06, 0x15, 0x12, 0x31,
7196 0x20, 0x06, 0x15, 0x12, 0x31,
7197 0x20, 0x06, 0x15, 0x12, 0x31,
7198 0x20, 0x06, 0x15, 0x12, 0x31,
7200 IntroduceBufferSize(Source);
7203 const int Width = 1908221843;
7204 const int Height = 1908221844;
7206 const auto pTexture = Component_t::Make(
7208 { uT(
"content"), ::std::vector{ Source } },
7209 { uT(
"width"), Width },
7210 { uT(
"height"), Height },
7211 { uT(
"name"), Names[Index].first },
7212 { uT(
"index"), Index },
7213 { uT(
"mipmapping"),
true },
7217 Source, Width, Height, Index, Names[Index].second);
7221 const int Width = 1908221845;
7222 const int Height = 1908221847;
7224 const auto pData = Component_t::Make(
7226 { uT(
"kind"), uT(
"TextureArray") },
7227 { uT(
"content"), ::std::vector{ Source } },
7228 { uT(
"width"), Width },
7229 { uT(
"height"), Height },
7230 { uT(
"name"), Names[Index].first },
7231 { uT(
"index"), Index },
7232 { uT(
"mipmapping"),
true },
7235 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
7236 Source, Width, Height, Index, Names[Index].second);
7239 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
7241 { uT(
"albedo"),
"TexAlbedo" },
7242 { uT(
"metalness"),
"TexMetalness" },
7243 { uT(
"roughness"),
"TexRoughness" },
7244 { uT(
"normal"),
"TexNormal" },
7245 { uT(
"occlusion"),
"TexOcclusion" },
7248 for (::std::size_t i = 0; i < Destinations.size(); i++)
7251 const int Width = 1908221843;
7252 const int Height = 1908221844;
7254 const auto pTexture = Component_t::Make(
7256 { uT(
"content"), ::std::vector{ Source } },
7257 { uT(
"width"), Width },
7258 { uT(
"height"), Height },
7259 { uT(
"name"), Names[Index].first },
7260 { uT(
"index"), Index },
7261 { uT(
"destination"), Destinations[i].first },
7262 { uT(
"mipmapping"),
true },
7266 Source, Width, Height, Index, Names[Index].second);
7270 const int Width = 1908221845;
7271 const int Height = 1908221847;
7273 const auto pData = Component_t::Make(
7275 { uT(
"kind"), uT(
"TextureArray") },
7276 { uT(
"content"), ::std::vector{ Source } },
7277 { uT(
"width"), Width },
7278 { uT(
"height"), Height },
7279 { uT(
"name"), Names[Index].first },
7280 { uT(
"index"), Index },
7281 { uT(
"destination"), Destinations[i].first },
7282 { uT(
"mipmapping"),
true },
7285 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
7286 Source, Width, Height, Index, Names[Index].second);
7293TEST_F(OpenGLShader_test, Test_TextureArray_Mipmapping_Destination)
7295 using GLProxy_t = ::mock::GLProxy;
7297 GLProxy_t::GetInstance() = &GLProxy;
7299 const Tested_t Example{ Data_t{} };
7300 const ITested_t & IExample = Example;
7302 auto itCreator = IExample.GetCreators().find(uT(
"TextureArray"));
7303 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7305 const ::mock::GLuint TextureId = 1908221839;
7306 const ::mock::GLint ProgramId = 1908221840;
7307 const ::mock::GLint LocationId = 1908221841;
7309 const auto TestCall = [&](
7310 const Component_t::ComponentPtr_t & _pTexture,
7311 const ::std::vector<uint8_t> & _Source,
7312 const int _Width,
const int _Height,
7313 const ::std::size_t _Index,
7314 const ::std::string & _TexName)
7316 const auto Index =
static_cast<::mock::GLint
>(_Index);
7318 using namespace ::testing;
7322 EXPECT_CALL(GLProxy, GenTextures(1))
7324 .WillOnce(Return(TextureId));
7326 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
7329 EXPECT_CALL(GLProxy, TexStorage3D(GL_TEXTURE_2D_ARRAY, 8, GL_RGBA8,
7330 _Width, _Height, 1))
7333 EXPECT_CALL(GLProxy, TexSubImage3D_1(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0,
7337 EXPECT_CALL(GLProxy, TexSubImage3D_2(1, GL_RGBA,
7338 GL_UNSIGNED_BYTE, _Source))
7341 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D_ARRAY))
7344 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, 0))
7347 EXPECT_CALL(GLProxy, GetError())
7349 .WillOnce(Return(GL_NO_ERROR));
7351 auto Render = itCreator->second(_pTexture);
7352 ASSERT_NE(
nullptr, Render);
7354 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
7357 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D_ARRAY, TextureId))
7360 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
7362 .WillOnce(Return(&ProgramId));
7364 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
7366 .WillOnce(Return(LocationId));
7368 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
7371 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
7376 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
7380 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
7382 { uT(
"albedo"),
"TexAlbedo" },
7383 { uT(
"metalness"),
"TexMetalness" },
7384 { uT(
"roughness"),
"TexRoughness" },
7385 { uT(
"normal"),
"TexNormal" },
7386 { uT(
"occlusion"),
"TexOcclusion" },
7389 ::std::vector<uint8_t> Source =
7391 0x20, 0x06, 0x15, 0x12, 0x31,
7392 0x20, 0x06, 0x15, 0x12, 0x31,
7393 0x20, 0x06, 0x15, 0x12, 0x31,
7394 0x20, 0x06, 0x15, 0x12, 0x31,
7395 0x20, 0x06, 0x15, 0x12, 0x31,
7397 IntroduceBufferSize(Source);
7399 for (::std::size_t i = 0; i < Destinations.size(); i++)
7402 const int Width = 1908221843;
7403 const int Height = 1908221844;
7405 const auto pTexture = Component_t::Make(
7407 { uT(
"content"), ::std::vector{ Source } },
7408 { uT(
"width"), Width },
7409 { uT(
"height"), Height },
7410 { uT(
"destination"), Destinations[i].first },
7411 { uT(
"mipmapping"),
true },
7415 Source, Width, Height, i, Destinations[i].second);
7419 const int Width = 1908221845;
7420 const int Height = 1908221847;
7422 const auto pData = Component_t::Make(
7424 { uT(
"kind"), uT(
"TextureArray") },
7425 { uT(
"content"), ::std::vector{ Source } },
7426 { uT(
"width"), Width },
7427 { uT(
"height"), Height },
7428 { uT(
"destination"), Destinations[i].first },
7429 { uT(
"mipmapping"),
true },
7432 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
7433 Source, Width, Height, i, Destinations[i].second);
7439TEST_F(OpenGLShader_test, Test_TextureArray_NoDeclaredInShader)
7441 using GLProxy_t = ::mock::GLProxy;
7443 GLProxy_t::GetInstance() = &GLProxy;
7445 const Tested_t Example{ Data_t{} };
7446 const ITested_t & IExample = Example;
7448 auto itCreator = IExample.GetCreators().find(uT(
"TextureArray"));
7449 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7451 const ::mock::GLuint TextureId = 1908221839;
7453 const auto TestCall = [&](
7454 const Component_t::ComponentPtr_t & _pTexture,
7455 const ::std::vector<uint8_t> & ,
7456 const int ,
const int ,
7457 const ::std::size_t _Index,
7458 const ::std::string & _TexName)
7460 const auto Index =
static_cast<::mock::GLint
>(_Index);
7462 using namespace ::testing;
7466 EXPECT_CALL(GLProxy, GenTextures(1))
7468 .WillOnce(Return(TextureId));
7470 auto Render = itCreator->second(_pTexture);
7471 ASSERT_NE(
nullptr, Render);
7473 EXPECT_CALL(GLProxy, GetUniformLocation(_, _TexName))
7475 .WillOnce(Return(-1));
7477 EXPECT_CALL(GLProxy, Uniform1i(_, _))
7482 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
7486 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
7488 { uT(
"albedo"),
"TexAlbedo" },
7489 { uT(
"metalness"),
"TexMetalness" },
7490 { uT(
"roughness"),
"TexRoughness" },
7491 { uT(
"normal"),
"TexNormal" },
7492 { uT(
"occlusion"),
"TexOcclusion" },
7493 { uT(
"depth"),
"TexDepth" },
7496 ::std::vector<uint8_t> Source =
7498 0x20, 0x06, 0x15, 0x12, 0x34,
7499 0x20, 0x06, 0x15, 0x12, 0x34,
7500 0x20, 0x06, 0x15, 0x12, 0x34,
7501 0x20, 0x06, 0x15, 0x12, 0x34,
7502 0x20, 0x06, 0x15, 0x12, 0x34,
7504 IntroduceBufferSize(Source);
7506 for (::std::size_t i = 0; i < Destinations.size(); i++)
7509 const uint8_t * pSource = (uint8_t *)1908221842;
7510 const int Width = 1908221843;
7511 const int Height = 1908221844;
7513 const auto pTexture = Component_t::Make(
7515 { uT(
"content"), ::std::vector{ Source } },
7516 { uT(
"width"), Width },
7517 { uT(
"height"), Height },
7518 { uT(
"destination"), Destinations[i].first },
7522 Source, Width, Height, i, Destinations[i].second);
7526 const uint8_t * pSource = (uint8_t *)1908221846;
7527 const int Width = 1908221845;
7528 const int Height = 1908221847;
7530 const auto pData = Component_t::Make(
7532 { uT(
"kind"), uT(
"TextureArray") },
7533 { uT(
"content"), ::std::vector{ Source } },
7534 { uT(
"width"), Width },
7535 { uT(
"height"), Height },
7536 { uT(
"destination"), Destinations[i].first },
7539 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
7540 Source, Width, Height, i, Destinations[i].second);
7546TEST_F(OpenGLShader_test, Test_TextureArray_MultiTextureData)
7548 using namespace ::alicorn::extension::std;
7550 using GLProxy_t = ::mock::GLProxy;
7552 GLProxy_t::GetInstance() = &GLProxy;
7554 const Tested_t Example{ Data_t{} };
7555 const ITested_t & IExample = Example;
7557 auto itCreator = IExample.GetCreators().find(uT(
"TextureArray"));
7558 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7560 const ::mock::GLuint TextureId = 1812181809;
7561 const ::mock::GLint ProgramId = 1908221258;
7562 const ::mock::GLint LocationId = 1908221259;
7564 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pTexture,
7565 const ::std::vector<uint8_t> & _Source,
const size_t _ArrayCount,
7566 const int _Width,
const int _Height)
7568 using namespace ::testing;
7572 EXPECT_CALL(GLProxy, GenTextures(1))
7574 .WillOnce(Return(TextureId));
7576 EXPECT_CALL(GLProxy, BindTexture(_, _))
7579 EXPECT_CALL(GLProxy, TexStorage3D(_, _, _, _, _, _ArrayCount))
7582 EXPECT_CALL(GLProxy, TexSubImage3D_1(_, 0, 0, 0, 0, _, _))
7585 EXPECT_CALL(GLProxy, TexSubImage3D_2(_ArrayCount, _, _, _Source))
7588 EXPECT_CALL(GLProxy, BindTexture(_, 0))
7591 EXPECT_CALL(GLProxy, GetError())
7593 .WillOnce(Return(GL_NO_ERROR));
7595 auto Render = itCreator->second(_pTexture);
7596 ASSERT_NE(
nullptr, Render);
7600 ::std::vector<uint8_t> Source1 =
7602 0x20, 0x06, 0x15, 0x12, 0x28,
7603 0x20, 0x06, 0x15, 0x12, 0x28,
7604 0x20, 0x06, 0x15, 0x12, 0x28,
7605 0x20, 0x06, 0x15, 0x12, 0x28,
7606 0x20, 0x06, 0x15, 0x12, 0x28,
7608 IntroduceBufferSize(Source1,
false);
7610 ::std::vector<uint8_t> Source2 =
7612 0x20, 0x06, 0x15, 0x12, 0x28,
7613 0x20, 0x06, 0x15, 0x12, 0x28,
7614 0x20, 0x06, 0x15, 0x12, 0x28,
7615 0x20, 0x06, 0x15, 0x12, 0x28,
7616 0x20, 0x06, 0x15, 0x12, 0x28,
7617 0x20, 0x06, 0x15, 0x12, 0x28,
7619 IntroduceBufferSize(Source2,
false);
7621 ::std::vector<uint8_t> Source3 =
7623 0x20, 0x06, 0x15, 0x12, 0x28,
7624 0x20, 0x06, 0x15, 0x12, 0x28,
7625 0x20, 0x06, 0x15, 0x12, 0x28,
7626 0x20, 0x06, 0x15, 0x12, 0x28,
7627 0x20, 0x06, 0x15, 0x12, 0x28,
7628 0x20, 0x06, 0x15, 0x12, 0x28,
7629 0x20, 0x06, 0x15, 0x12, 0x28,
7630 0x20, 0x06, 0x15, 0x12, 0x28,
7632 IntroduceBufferSize(Source3);
7634 const int Width = 1812181807;
7635 const int Height = 1812181808;
7637 const auto pTexture = Component_t::Make(
7639 { uT(
"content"), ::std::vector{ Source1, Source2, Source3 } },
7640 { uT(
"width"), Width },
7641 { uT(
"height"), Height },
7644 TestCall(pTexture, Source1 + Source2 + Source3, 3, Width, Height);
7648 ::std::vector<uint8_t> Source1 =
7650 0x20, 0x06, 0x15, 0x12, 0x29,
7651 0x20, 0x06, 0x15, 0x12, 0x29,
7652 0x20, 0x06, 0x15, 0x12, 0x29,
7654 IntroduceBufferSize(Source1,
false);
7656 ::std::vector<uint8_t> Source2 =
7658 0x25, 0x04, 0x07, 0x21, 0x03,
7659 0x25, 0x04, 0x07, 0x21, 0x04,
7660 0x25, 0x04, 0x07, 0x21, 0x05,
7661 0x25, 0x04, 0x07, 0x21, 0x06
7663 IntroduceBufferSize(Source2,
true);
7665 const int Width = 1907251057;
7666 const int Height = 1907251058;
7668 const auto pData = Component_t::Make(
7670 { uT(
"kind"), uT(
"TextureArray") },
7671 { uT(
"content"), ::std::vector{ Source1, Source2 } },
7672 { uT(
"width"), Width },
7673 { uT(
"height"), Height },
7676 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
7677 Source1 + Source2, 2, Width, Height);
7682TEST_F(OpenGLShader_test, Test_Buffer_Fail)
7684 using GLProxy_t = ::mock::GLProxy;
7686 GLProxy_t::GetInstance() = &GLProxy;
7688 const Tested_t Example{ Data_t{} };
7689 const ITested_t & IExample = Example;
7691 auto itCreator = IExample.GetCreators().find(uT(
"Buffer"));
7692 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7694 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent)
7696 using namespace ::testing;
7700 EXPECT_CALL(GLProxy, GenBuffers(_))
7703 EXPECT_CALL(GLProxy, GetError())
7705 .WillOnce(Return(1908232144));
7707 EXPECT_THROW(itCreator->second(_pComponent), ::std::exception);
7711 const ::std::vector<::covellite::api::Vertex> Source;
7713 const auto pBuffer = Component_t::Make(
7715 { uT(
"content"), Source },
7718 TestCallRender(pBuffer);
7720 const auto pData = Component_t::Make(
7722 { uT(
"kind"), uT(
"Buffer") },
7723 { uT(
"content"), Source },
7726 TestCallRender(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
7730 using BufferMapper_t =
7731 ::covellite::api::cbBufferMap_t<::covellite::api::Vertex>;
7732 const ::std::vector<::covellite::api::Vertex> Source;
7736 const auto pBuffer = Component_t::Make(
7738 { uT(
"content"), Source },
7739 { uT(
"mapper"), Mapper },
7742 TestCallRender(pBuffer);
7744 const auto pData = Component_t::Make(
7746 { uT(
"kind"), uT(
"Buffer") },
7747 { uT(
"content"), Source },
7748 { uT(
"mapper"), Mapper },
7751 TestCallRender(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
7756TEST_F(OpenGLShader_test, Test_Buffer_Vertex_Static)
7760 using GLProxy_t = ::mock::GLProxy;
7762 GLProxy_t::GetInstance() = &GLProxy;
7764 const ::mock::GLuint BufferId = 1908231206;
7765 const ::mock::GLint ProgramId = 1908231246;
7766 const ::mock::GLint PositionId = 1908231301;
7767 const ::mock::GLint TexCoordId = 1908231302;
7768 const ::mock::GLint ExtraId = 1908231304;
7770 ::std::vector<Vertex_t> Source =
7773 1808261932.0f, 1808261933.0f, 1812161256.0f, 1808261934.0f,
7774 1812161257.0f, 1808261935.0f,
7775 1808261936.0f, 1812161258.0f, 1908201939.0f, 1908201940.0f
7778 1808261932.0f, 1808261933.0f, 1812161259.0f, 1808261934.0f,
7779 1812161300.0f, 1808261935.0f,
7780 1808261936.0f, 1812161301.0f, 1908201941.0f, 1908201942.0f
7782 { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f },
7785 IntroduceBufferSize(Source);
7787 const ::mock::GLProxy::Floats_t ExpectedVertexData =
7789 Source[0].px, Source[0].py, Source[0].pz,
7790 Source[1].px, Source[1].py, Source[1].pz,
7793 const ::mock::GLProxy::Floats_t ExpectedTexCoordData =
7795 Source[0].tu, Source[0].tv,
7796 Source[1].tu, Source[1].tv,
7799 const ::mock::GLProxy::Floats_t ExpectedNormalData =
7801 Source[0].ex, Source[0].ey, Source[0].ez,
7802 Source[1].ex, Source[1].ey, Source[1].ez,
7805 const Tested_t Example{ Data_t{} };
7806 const ITested_t & IExample = Example;
7808 auto itCreator = IExample.GetCreators().find(uT(
"Buffer"));
7809 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7811 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent)
7813 using namespace ::testing;
7817 EXPECT_CALL(GLProxy, GenBuffers(1))
7819 .WillOnce(Return(BufferId));
7821 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
7825 static_cast<::mock::GLsizeiptr
>(Source.size() *
sizeof(Vertex_t));
7827 EXPECT_CALL(GLProxy, BufferData(GL_ARRAY_BUFFER, Size,
7828 GetExpected(Source), GL_STATIC_DRAW))
7831 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
7834 EXPECT_CALL(GLProxy, GetError())
7836 .WillOnce(Return(GL_NO_ERROR));
7838 const auto Render = itCreator->second(_pComponent);
7839 ASSERT_NE(
nullptr, Render);
7841 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
7844 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
7846 .WillOnce(Return(&ProgramId));
7848 EXPECT_CALL(GLProxy,
7849 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexPosition")))
7851 .WillOnce(Return(PositionId));
7853 EXPECT_CALL(GLProxy, EnableVertexAttribArray(PositionId))
7856 EXPECT_CALL(GLProxy, VertexAttribPointer(PositionId, 4, GL_FLOAT, GL_FALSE,
7857 sizeof(Vertex_t), (
void*)0))
7860 EXPECT_CALL(GLProxy, VertexAttribDivisor(PositionId, 0))
7863 EXPECT_CALL(GLProxy,
7864 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexTexCoord")))
7866 .WillOnce(Return(TexCoordId));
7868 EXPECT_CALL(GLProxy, EnableVertexAttribArray(TexCoordId))
7871 EXPECT_CALL(GLProxy, VertexAttribPointer(TexCoordId, 2, GL_FLOAT, GL_FALSE,
7872 sizeof(Vertex_t), (
void*)(
sizeof(
float) * 4)))
7875 EXPECT_CALL(GLProxy, VertexAttribDivisor(TexCoordId, 0))
7878 EXPECT_CALL(GLProxy,
7879 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexExtra")))
7881 .WillOnce(Return(ExtraId));
7883 EXPECT_CALL(GLProxy, EnableVertexAttribArray(ExtraId))
7886 EXPECT_CALL(GLProxy, VertexAttribPointer(ExtraId, 4, GL_FLOAT, GL_FALSE,
7887 sizeof(Vertex_t), (
void*)(
sizeof(
float) * 6)))
7890 EXPECT_CALL(GLProxy, VertexAttribDivisor(ExtraId, 0))
7893 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
7898 EXPECT_CALL(GLProxy, DeleteBuffers(1, BufferId))
7905 const auto pBuffer = Component_t::Make(
7907 { uT(
"content"), Source },
7910 TestCallRender(pBuffer);
7916 const auto pData = Component_t::Make(
7918 { uT(
"kind"), uT(
"Buffer") },
7919 { uT(
"content"), Source },
7922 TestCallRender(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
7927TEST_F(OpenGLShader_test, Test_Buffer_Vertex_Dynamic)
7930 using BufferMapper_t = ::covellite::api::cbBufferMap_t<Vertex_t>;
7933 public ::alicorn::extension::testing::Proxy<Proxy>
7936 MOCK_METHOD1(Mapper,
bool(Vertex_t *));
7940 Proxy::GetInstance() = &oProxy;
7942 using GLProxy_t = ::mock::GLProxy;
7944 GLProxy_t::GetInstance() = &GLProxy;
7946 const ::mock::GLuint BufferId = 1908232202;
7947 const ::mock::GLint ProgramId = 1908232203;
7948 const ::mock::GLint PositionId = 1908232204;
7949 const ::mock::GLint TexCoordId = 1908232205;
7950 const ::mock::GLint ExtraId = 1908232206;
7952 ::std::vector<Vertex_t> Source1 =
7955 1808261932.0f, 1808261933.0f, 1812161256.0f, 1808261934.0f,
7956 1812161257.0f, 1808261935.0f,
7957 1808261936.0f, 1812161258.0f, 1908201945.0f, 1908201946.0f
7960 1808261932.0f, 1808261933.0f, 1812161259.0f, 1808261934.0f,
7961 1812161300.0f, 1808261935.0f,
7962 1808261936.0f, 1812161301.0f, 1908201947.0f, 1908201948.0f
7964 { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f },
7967 IntroduceBufferSize(Source1);
7969 const ::std::vector<::mock::GLfloat> Source2 =
7971 1908011341.0f, 1908261933.0f, 1912161256.0f, 1908261934.0f,
7972 1912161257.0f, 1908261935.0f,
7973 1908261936.0f, 1912161258.0f, 1908201949.0f, 1908201950.0f,
7974 1908261932.0f, 1908261933.0f, 1912161259.0f, 1908261934.0f,
7975 1912161300.0f, 1908261935.0f,
7976 1908261936.0f, 1912161301.0f, 1908201951.0f, 1908201952.0f,
7979 const BufferMapper_t Mapper = [&](Vertex_t * _pData)
7981 if (_pData !=
nullptr)
7983 memcpy(_pData, Source2.data(),
sizeof(::mock::GLfloat) * Source2.size());
7986 return oProxy.Mapper(_pData);
7989 const Tested_t Example{ Data_t{} };
7990 const ITested_t & IExample = Example;
7992 auto itCreator = IExample.GetCreators().find(uT(
"Buffer"));
7993 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7995 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent)
7997 using namespace ::testing;
8001 EXPECT_CALL(GLProxy, GenBuffers(1))
8003 .WillOnce(Return(BufferId));
8005 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
8009 static_cast<::mock::GLsizeiptr
>(Source1.size() *
sizeof(Vertex_t));
8011 EXPECT_CALL(GLProxy, BufferData(GL_ARRAY_BUFFER, Size,
8012 GetExpected(Source1), GL_DYNAMIC_DRAW))
8015 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
8018 EXPECT_CALL(GLProxy, GetError())
8020 .WillOnce(Return(GL_NO_ERROR));
8022 const auto Render = itCreator->second(_pComponent);
8023 ASSERT_NE(
nullptr, Render);
8026 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
8029 EXPECT_CALL(oProxy, Mapper(
nullptr))
8031 .WillOnce(Return(
false));
8033 EXPECT_CALL(oProxy, Mapper(_))
8036 EXPECT_CALL(GLProxy, BufferSubData(_, _, _, _))
8039 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8041 .WillOnce(Return(&ProgramId));
8043 EXPECT_CALL(GLProxy,
8044 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexPosition")))
8046 .WillOnce(Return(PositionId));
8048 EXPECT_CALL(GLProxy, EnableVertexAttribArray(PositionId))
8051 EXPECT_CALL(GLProxy, VertexAttribPointer(PositionId, 4, GL_FLOAT, GL_FALSE,
8052 sizeof(Vertex_t), (
void*)0))
8055 EXPECT_CALL(GLProxy, VertexAttribDivisor(PositionId, 0))
8058 EXPECT_CALL(GLProxy,
8059 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexTexCoord")))
8061 .WillOnce(Return(TexCoordId));
8063 EXPECT_CALL(GLProxy, EnableVertexAttribArray(TexCoordId))
8066 EXPECT_CALL(GLProxy, VertexAttribPointer(TexCoordId, 2, GL_FLOAT, GL_FALSE,
8067 sizeof(Vertex_t), (
void*)(
sizeof(
float) * 4)))
8070 EXPECT_CALL(GLProxy, VertexAttribDivisor(TexCoordId, 0))
8073 EXPECT_CALL(GLProxy,
8074 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexExtra")))
8076 .WillOnce(Return(ExtraId));
8078 EXPECT_CALL(GLProxy, EnableVertexAttribArray(ExtraId))
8081 EXPECT_CALL(GLProxy, VertexAttribPointer(ExtraId, 4, GL_FLOAT, GL_FALSE,
8082 sizeof(Vertex_t), (
void*)(
sizeof(
float) * 6)))
8085 EXPECT_CALL(GLProxy, VertexAttribDivisor(ExtraId, 0))
8088 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
8095 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
8098 EXPECT_CALL(oProxy, Mapper(
nullptr))
8100 .WillOnce(Return(
true));
8102 EXPECT_CALL(oProxy, Mapper(_))
8105 EXPECT_CALL(GLProxy, BufferSubData(GL_ARRAY_BUFFER, 0, Size, Source2))
8108 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8110 .WillOnce(Return(&ProgramId));
8112 EXPECT_CALL(GLProxy,
8113 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexPosition")))
8115 .WillOnce(Return(PositionId));
8117 EXPECT_CALL(GLProxy, EnableVertexAttribArray(PositionId))
8120 EXPECT_CALL(GLProxy, VertexAttribPointer(PositionId, 4, GL_FLOAT, GL_FALSE,
8121 sizeof(Vertex_t), (
void*)0))
8124 EXPECT_CALL(GLProxy, VertexAttribDivisor(PositionId, 0))
8127 EXPECT_CALL(GLProxy,
8128 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexTexCoord")))
8130 .WillOnce(Return(TexCoordId));
8132 EXPECT_CALL(GLProxy, EnableVertexAttribArray(TexCoordId))
8135 EXPECT_CALL(GLProxy, VertexAttribPointer(TexCoordId, 2, GL_FLOAT, GL_FALSE,
8136 sizeof(Vertex_t), (
void*)(
sizeof(
float) * 4)))
8139 EXPECT_CALL(GLProxy, VertexAttribDivisor(TexCoordId, 0))
8142 EXPECT_CALL(GLProxy,
8143 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexExtra")))
8145 .WillOnce(Return(ExtraId));
8147 EXPECT_CALL(GLProxy, EnableVertexAttribArray(ExtraId))
8150 EXPECT_CALL(GLProxy, VertexAttribPointer(ExtraId, 4, GL_FLOAT, GL_FALSE,
8151 sizeof(Vertex_t), (
void*)(
sizeof(
float) * 6)))
8154 EXPECT_CALL(GLProxy, VertexAttribDivisor(ExtraId, 0))
8157 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
8163 EXPECT_CALL(GLProxy, DeleteBuffers(1, BufferId))
8170 const auto pBuffer = Component_t::Make(
8172 { uT(
"content"), Source1 },
8173 { uT(
"mapper"), Mapper },
8176 TestCallRender(pBuffer);
8182 const auto pData = Component_t::Make(
8184 { uT(
"kind"), uT(
"Buffer") },
8185 { uT(
"content"), Source1 },
8188 const auto pBuffer = Component_t::Make(
8190 { uT(
"mapper"), Mapper },
8191 { uT(
"service"), Object_t{ pData } }
8194 TestCallRender(pBuffer);
8199TEST_F(OpenGLShader_test, Test_Buffer_Vertex_IgnoreNotExistsVariables)
8202 using BufferMapper_t = ::covellite::api::cbBufferMap_t<Vertex_t>;
8204 using GLProxy_t = ::mock::GLProxy;
8206 GLProxy_t::GetInstance() = &GLProxy;
8208 const ::mock::GLuint BufferId = 1908231206;
8209 const ::mock::GLint ProgramId = 1908231246;
8211 ::std::vector<Vertex_t> Source =
8214 1808261932.0f, 1808261933.0f, 1812161256.0f, 1808261934.0f,
8215 1812161257.0f, 1808261935.0f,
8216 1808261936.0f, 1812161258.0f, 1908201939.0f, 1908201940.0f
8219 1808261932.0f, 1808261933.0f, 1812161259.0f, 1808261934.0f,
8220 1812161300.0f, 1808261935.0f,
8221 1808261936.0f, 1812161301.0f, 1908201941.0f, 1908201942.0f
8223 { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f },
8226 IntroduceBufferSize(Source);
8228 const Tested_t Example{ Data_t{} };
8229 const ITested_t & IExample = Example;
8231 auto itCreator = IExample.GetCreators().find(uT(
"Buffer"));
8232 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8234 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent)
8236 using namespace ::testing;
8240 EXPECT_CALL(GLProxy, GenBuffers(1))
8242 .WillOnce(Return(BufferId));
8244 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
8247 EXPECT_CALL(GLProxy, BufferData(GL_ARRAY_BUFFER, _, _, _))
8250 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
8253 EXPECT_CALL(GLProxy, GetError())
8255 .WillOnce(Return(GL_NO_ERROR));
8257 const auto Render = itCreator->second(_pComponent);
8258 ASSERT_NE(
nullptr, Render);
8260 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
8263 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8265 .WillOnce(Return(&ProgramId));
8267 EXPECT_CALL(GLProxy,
8268 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexPosition")))
8270 .WillOnce(Return(-1));
8272 EXPECT_CALL(GLProxy, EnableVertexAttribArray(_))
8275 EXPECT_CALL(GLProxy, VertexAttribPointer(_, _, _, _, _, _))
8278 EXPECT_CALL(GLProxy, VertexAttribDivisor(_, _))
8281 EXPECT_CALL(GLProxy,
8282 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexTexCoord")))
8284 .WillOnce(Return(-1));
8286 EXPECT_CALL(GLProxy, EnableVertexAttribArray(_))
8289 EXPECT_CALL(GLProxy, VertexAttribPointer(_, _, _, _, _, _))
8292 EXPECT_CALL(GLProxy, VertexAttribDivisor(_, _))
8295 EXPECT_CALL(GLProxy,
8296 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexExtra")))
8298 .WillOnce(Return(-1));
8300 EXPECT_CALL(GLProxy, EnableVertexAttribArray(_))
8303 EXPECT_CALL(GLProxy, VertexAttribPointer(_, _, _, _, _, _))
8306 EXPECT_CALL(GLProxy, VertexAttribDivisor(_, _))
8309 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
8314 EXPECT_CALL(GLProxy, DeleteBuffers(1, BufferId))
8321 const auto pBuffer = Component_t::Make(
8323 { uT(
"content"), Source },
8326 TestCallRender(pBuffer);
8332 const auto pData = Component_t::Make(
8334 { uT(
"kind"), uT(
"Buffer") },
8335 { uT(
"content"), Source },
8338 TestCallRender(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
8346 const auto pBuffer = Component_t::Make(
8348 { uT(
"content"), Source },
8349 { uT(
"mapper"), BufferMapper_t{} },
8352 TestCallRender(pBuffer);
8358 const auto pData = Component_t::Make(
8360 { uT(
"kind"), uT(
"Buffer") },
8361 { uT(
"content"), Source },
8364 const auto pBuffer = Component_t::Make(
8366 { uT(
"mapper"), BufferMapper_t{} },
8367 { uT(
"service"), Object_t{ pData } }
8370 TestCallRender(pBuffer);
8375TEST_F(OpenGLShader_test, Test_Transform_Default)
8377 using GLProxy_t = ::mock::GLProxy;
8379 GLProxy_t::GetInstance() = &GLProxy;
8381 const Tested_t Example{ Data_t{} };
8382 const ITested_t & IExample = Example;
8384 const ::mock::GLint ProgramId = 1908241203;
8385 const ::mock::GLint MatrixWorldLocationId = 1908241207;
8387 auto itCreator = IExample.GetCreators().find(uT(
"Transform"));
8388 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8390 auto pPosition = Component_t::Make({ { uT(
"kind"), uT(
"Position") } });
8391 auto pRotation = Component_t::Make({ { uT(
"kind"), uT(
"Rotation") } });
8392 auto pScale = Component_t::Make({ { uT(
"kind"), uT(
"Scale") } });
8393 const auto pTransform = Component_t::Make(
8395 { uT(
"service"), Object_t{ pPosition, pRotation, pScale } }
8398 const auto Render = itCreator->second(pTransform);
8399 ASSERT_NE(
nullptr, Render);
8401 auto WorldMatrix = ::glm::identity<::glm::mat4>();
8403 auto TestCallRender = [&](
8404 float _X,
float _Y,
float _Z,
8405 float _A,
float _B,
float _C,
8406 float _Sx,
float _Sy,
float _Sz)
8408 (*pPosition)[uT(
"x")] = _X;
8409 (*pPosition)[uT(
"y")] = _Y;
8410 (*pPosition)[uT(
"z")] = _Z;
8412 (*pRotation)[uT(
"x")] = _A;
8413 (*pRotation)[uT(
"y")] = _B;
8414 (*pRotation)[uT(
"z")] = _C;
8416 (*pScale)[uT(
"x")] = _Sx;
8417 (*pScale)[uT(
"y")] = _Sy;
8418 (*pScale)[uT(
"z")] = _Sz;
8420 WorldMatrix = ::glm::identity<::glm::mat4>();
8421 WorldMatrix = ::glm::scale(WorldMatrix, { _Sx, _Sy, _Sz });
8422 WorldMatrix = ::glm::rotate(WorldMatrix, _C, { 0.0f, 0.0f, 1.0f });
8423 WorldMatrix = ::glm::rotate(WorldMatrix, _B, { 0.0f, 1.0f, 0.0f });
8424 WorldMatrix = ::glm::rotate(WorldMatrix, _A, { 1.0f, 0.0f, 0.0f });
8425 WorldMatrix = ::glm::translate(WorldMatrix, { _X, _Y, _Z });
8426 WorldMatrix = ::glm::transpose(WorldMatrix);
8428 using namespace ::testing;
8432 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8434 .WillOnce(Return(&ProgramId));
8436 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"ObjectData.World")))
8438 .WillOnce(Return(MatrixWorldLocationId));
8440 EXPECT_CALL(GLProxy,
8441 UniformMatrix4fv(MatrixWorldLocationId, 1, GL_FALSE, WorldMatrix))
8451 1956.0f, 1957.0f, 1958.0f,
8452 1204.0f, 1205.0f, 1206.0f,
8453 1152.0f, 1153.0f, 1154.0f);
8456 1959.0f, 1960.0f, 1961.0f,
8457 1145.0f, 1146.0f, 1147.0f,
8458 1155.0f, 1157.0f, 1158.0f);
8462TEST_F(OpenGLShader_test, Test_Transform_Static)
8464 using GLProxy_t = ::mock::GLProxy;
8466 GLProxy_t::GetInstance() = &GLProxy;
8468 const Tested_t Example{ Data_t{} };
8469 const ITested_t & IExample = Example;
8471 const ::mock::GLint ProgramId = 1908241203;
8472 const ::mock::GLint MatrixWorldLocationId = 1908241207;
8474 auto itCreator = IExample.GetCreators().find(uT(
"Transform"));
8475 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8477 auto pPosition = Component_t::Make({ { uT(
"kind"), uT(
"Position") } });
8478 auto pRotation = Component_t::Make({ { uT(
"kind"), uT(
"Rotation") } });
8479 auto pScale = Component_t::Make({ { uT(
"kind"), uT(
"Scale") } });
8481 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pTransform)
8483 auto WorldMatrix = ::glm::identity<::glm::mat4>();
8485 auto SetValues = [&](
const bool _IsBuildMatrix,
8486 float _X,
float _Y,
float _Z,
8487 float _A,
float _B,
float _C,
8488 float _Sx,
float _Sy,
float _Sz)
8490 (*pPosition)[uT(
"x")] = _X;
8491 (*pPosition)[uT(
"y")] = _Y;
8492 (*pPosition)[uT(
"z")] = _Z;
8494 (*pRotation)[uT(
"x")] = _A;
8495 (*pRotation)[uT(
"y")] = _B;
8496 (*pRotation)[uT(
"z")] = _C;
8498 (*pScale)[uT(
"x")] = _Sx;
8499 (*pScale)[uT(
"y")] = _Sy;
8500 (*pScale)[uT(
"z")] = _Sz;
8504 WorldMatrix = ::glm::identity<::glm::mat4>();
8505 WorldMatrix = ::glm::scale(WorldMatrix, { _Sx, _Sy, _Sz });
8506 WorldMatrix = ::glm::rotate(WorldMatrix, _C, { 0.0f, 0.0f, 1.0f });
8507 WorldMatrix = ::glm::rotate(WorldMatrix, _B, { 0.0f, 1.0f, 0.0f });
8508 WorldMatrix = ::glm::rotate(WorldMatrix, _A, { 1.0f, 0.0f, 0.0f });
8509 WorldMatrix = ::glm::translate(WorldMatrix, { _X, _Y, _Z });
8510 WorldMatrix = ::glm::transpose(WorldMatrix);
8515 1956.0f, 1957.0f, 1958.0f,
8516 1204.0f, 1205.0f, 1206.0f,
8517 1152.0f, 1153.0f, 1154.0f);
8519 const auto Render = itCreator->second(_pTransform);
8520 ASSERT_NE(
nullptr, Render);
8522 auto TestCallRender = [&](void)
8524 using namespace ::testing;
8528 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8530 .WillOnce(Return(&ProgramId));
8532 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"ObjectData.World")))
8534 .WillOnce(Return(MatrixWorldLocationId));
8536 EXPECT_CALL(GLProxy,
8537 UniformMatrix4fv(MatrixWorldLocationId, 1, GL_FALSE, WorldMatrix))
8549 1959.0f, 1960.0f, 1961.0f,
8550 1145.0f, 1146.0f, 1147.0f,
8551 1155.0f, 1157.0f, 1158.0f);
8556 const auto pTransform = Component_t::Make(
8558 { uT(
"kind"), uT(
"Static") },
8559 { uT(
"service"), Object_t{ pPosition, pRotation, pScale } }
8562 TestCallRender(pTransform);
8566TEST_F(OpenGLShader_test, Test_Transform_Billboard)
8568 using GLProxy_t = ::mock::GLProxy;
8570 GLProxy_t::GetInstance() = &GLProxy;
8572 Tested_t Example{ Data_t{} };
8573 const ITested_t & IExample = Example;
8575 const ::mock::GLint ProgramId = 1908241203;
8576 const ::mock::GLint MatrixWorldLocationId = 1908241207;
8578 auto itCreator = IExample.GetCreators().find(uT(
"Transform"));
8579 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8581 auto pPosition = Component_t::Make({ { uT(
"kind"), uT(
"Position") } });
8583 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pTransform)
8585 const auto Render = itCreator->second(_pTransform);
8586 ASSERT_NE(
nullptr, Render);
8588 auto WorldMatrix = ::glm::identity<::glm::mat4>();
8590 auto TestCallRender = [&](
float _X,
float _Y,
float _Z)
8592 (*pPosition)[uT(
"x")] = _X;
8593 (*pPosition)[uT(
"y")] = _Y;
8594 (*pPosition)[uT(
"z")] = _Z;
8596 WorldMatrix = ::glm::identity<::glm::mat4>();
8597 WorldMatrix = ::glm::translate(WorldMatrix, { _X, _Y, _Z });
8599 const auto ViewMatrix = ::glm::mat4
8601 { 1.0f, 2.0f, 3.0f, 4.0f },
8602 { 5.0f, 6.0f, 7.0f, 8.0f },
8603 { 9.0f, 10.0f, 11.0f, 12.0f },
8604 { 13.0f, 14.0f, 15.0f, 16.0f },
8607 GetCameraMartix(Example).View = ViewMatrix;
8609 auto TransposeViewMatrix = ViewMatrix;
8610 TransposeViewMatrix[0][3] = 0.0f;
8611 TransposeViewMatrix[1][3] = 0.0f;
8612 TransposeViewMatrix[2][3] = 0.0f;
8613 TransposeViewMatrix[3][0] = 0.0f;
8614 TransposeViewMatrix[3][1] = 0.0f;
8615 TransposeViewMatrix[3][2] = 0.0f;
8616 TransposeViewMatrix[3][3] = 1.0f;
8618 WorldMatrix = TransposeViewMatrix *
8619 ::glm::translate(::glm::identity<::glm::mat4>(), { _X, _Y, _Z });
8620 WorldMatrix = ::glm::transpose(WorldMatrix);
8622 using namespace ::testing;
8626 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8628 .WillOnce(Return(&ProgramId));
8630 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"ObjectData.World")))
8632 .WillOnce(Return(MatrixWorldLocationId));
8634 EXPECT_CALL(GLProxy,
8635 UniformMatrix4fv(MatrixWorldLocationId, 1, GL_FALSE, WorldMatrix))
8644 TestCallRender(1956.0f, 1957.0f, 1958.0f);
8645 TestCallRender(1959.0f, 1960.0f, 1961.0f);
8648 const auto pTransform = Component_t::Make(
8650 { uT(
"kind"), uT(
"Billboard") },
8651 { uT(
"service"), Object_t{ pPosition } }
8654 TestCallRender(pTransform);
8658TEST_F(OpenGLShader_test, Test_Transform_DefaultValues)
8660 using GLProxy_t = ::mock::GLProxy;
8662 GLProxy_t::GetInstance() = &GLProxy;
8664 Tested_t Example{ Data_t{} };
8665 const ITested_t & IExample = Example;
8667 auto itCreator = IExample.GetCreators().find(uT(
"Transform"));
8668 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8670 auto pPosition = Component_t::Make({ { uT(
"kind"), uT(
"Position") } });
8671 auto pRotation = Component_t::Make({ { uT(
"kind"), uT(
"Rotation") } });
8672 auto pScale = Component_t::Make({ { uT(
"kind"), uT(
"Scale") } });
8674 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent,
8675 const bool _IsFullTransform =
true)
8677 const auto Render = itCreator->second(_pComponent);
8678 ASSERT_NE(
nullptr, Render);
8680 const auto ViewMatrix = ::glm::mat4
8682 { 1.0f, 2.0f, 3.0f, 4.0f },
8683 { 5.0f, 6.0f, 7.0f, 8.0f },
8684 { 9.0f, 10.0f, 11.0f, 12.0f },
8685 { 13.0f, 14.0f, 15.0f, 16.0f },
8688 GetCameraMartix(Example).View = ViewMatrix;
8690 auto WorldMatrix = ::glm::identity<::glm::mat4>();
8692 if (_IsFullTransform)
8694 WorldMatrix = ::glm::scale(WorldMatrix, { 1.0f, 1.0f, 1.0f });
8695 WorldMatrix = ::glm::transpose(WorldMatrix);
8699 auto TransposeViewMatrix = ViewMatrix;
8700 TransposeViewMatrix[0][3] = 0.0f;
8701 TransposeViewMatrix[1][3] = 0.0f;
8702 TransposeViewMatrix[2][3] = 0.0f;
8703 TransposeViewMatrix[3][0] = 0.0f;
8704 TransposeViewMatrix[3][1] = 0.0f;
8705 TransposeViewMatrix[3][2] = 0.0f;
8706 TransposeViewMatrix[3][3] = 1.0f;
8708 WorldMatrix = TransposeViewMatrix;
8709 WorldMatrix = ::glm::transpose(WorldMatrix);
8712 using namespace ::testing;
8714 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, WorldMatrix))
8720 TestCallRender(Component_t::Make(
8722 { uT(
"service"), Object_t{ pPosition, pRotation, pScale } }
8725 TestCallRender(Component_t::Make(
8727 { uT(
"kind"), uT(
"Static") },
8728 { uT(
"service"), Object_t{ pPosition, pRotation, pScale } }
8731 TestCallRender(Component_t::Make(
8733 { uT(
"kind"), uT(
"Billboard") },
8734 { uT(
"service"), Object_t{ pPosition, pRotation, pScale } }
8739TEST_F(OpenGLShader_test, Test_Transform_Combine)
8741 using GLProxy_t = ::mock::GLProxy;
8743 GLProxy_t::GetInstance() = &GLProxy;
8745 Tested_t Example{ Data_t{} };
8746 const ITested_t & IExample = Example;
8748 auto itCreator = IExample.GetCreators().find(uT(
"Transform"));
8749 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8751 auto MatrixIdentity = ::glm::identity<::glm::mat4>();
8753 ::std::deque<Component_t::ComponentPtr_t> Components;
8755 const auto SetPosition = [&](
float _X,
float _Y,
float _Z)
8757 Components.push_front(Component_t::Make(
8759 { uT(
"kind"), uT(
"Position") },
8765 MatrixIdentity = ::glm::translate(MatrixIdentity, { _X, _Y, _Z });
8768 const auto SetRotation = [&](
float _X,
float _Y,
float _Z)
8770 Components.push_front(Component_t::Make(
8772 { uT(
"kind"), uT(
"Rotation") },
8778 MatrixIdentity = ::glm::rotate(MatrixIdentity, _Z, { 0.0f, 0.0f, 1.0f });
8779 MatrixIdentity = ::glm::rotate(MatrixIdentity, _Y, { 0.0f, 1.0f, 0.0f });
8780 MatrixIdentity = ::glm::rotate(MatrixIdentity, _X, { 1.0f, 0.0f, 0.0f });
8783 const auto SetScale = [&](
float _X,
float _Y,
float _Z)
8785 Components.push_front(Component_t::Make(
8787 { uT(
"kind"), uT(
"Scale") },
8793 MatrixIdentity = ::glm::scale(MatrixIdentity, { _X, _Y, _Z });
8797 MatrixIdentity = ::glm::identity<::glm::mat4>();
8800 SetPosition(1.0f, 2.0f, 3.0f);
8801 SetRotation(4.0f, 5.0f, 6.0f);
8802 SetScale(7.0f, 8.0f, 9.0f);
8804 SetPosition(11.0f, 22.0f, 33.0f);
8805 SetRotation(44.0f, 55.0f, 66.0f);
8806 SetScale(77.0f, 88.0f, 99.0f);
8808 MatrixIdentity = ::glm::transpose(MatrixIdentity);
8810 auto Render = itCreator->second(Component_t::Make(
8812 { uT(
"service"), Object_t{ Components.begin(), Components.end() } }
8814 ASSERT_NE(
nullptr, Render);
8816 using namespace ::testing;
8820 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, MatrixIdentity))
8827 MatrixIdentity = ::glm::identity<::glm::mat4>();
8830 SetPosition(1.0f, 2.0f, 3.0f);
8831 SetRotation(4.0f, 5.0f, 6.0f);
8832 SetScale(7.0f, 8.0f, 9.0f);
8834 SetPosition(11.0f, 22.0f, 33.0f);
8835 SetRotation(44.0f, 55.0f, 66.0f);
8836 SetScale(77.0f, 88.0f, 99.0f);
8838 MatrixIdentity = ::glm::transpose(MatrixIdentity);
8840 auto Render = itCreator->second(Component_t::Make(
8842 { uT(
"kind"), uT(
"Static") },
8843 { uT(
"service"), Object_t{ Components.begin(), Components.end() } }
8845 ASSERT_NE(
nullptr, Render);
8847 using namespace ::testing;
8851 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, MatrixIdentity))
8858 const auto ViewMatrix = ::glm::mat4
8860 { 1.0f, 2.0f, 3.0f, 4.0f },
8861 { 5.0f, 6.0f, 7.0f, 8.0f },
8862 { 9.0f, 10.0f, 11.0f, 12.0f },
8863 { 13.0f, 14.0f, 15.0f, 16.0f },
8866 GetCameraMartix(Example).View = ViewMatrix;
8868 auto TransposeViewMatrix = ViewMatrix;
8869 TransposeViewMatrix[0][3] = 0.0f;
8870 TransposeViewMatrix[1][3] = 0.0f;
8871 TransposeViewMatrix[2][3] = 0.0f;
8872 TransposeViewMatrix[3][0] = 0.0f;
8873 TransposeViewMatrix[3][1] = 0.0f;
8874 TransposeViewMatrix[3][2] = 0.0f;
8875 TransposeViewMatrix[3][3] = 1.0f;
8877 MatrixIdentity = TransposeViewMatrix;
8880 SetPosition(1.0f, 2.0f, 3.0f);
8881 SetPosition(11.0f, 22.0f, 33.0f);
8882 SetPosition(111.0f, 222.0f, 333.0f);
8884 MatrixIdentity = ::glm::transpose(MatrixIdentity);
8886 auto Render = itCreator->second(Component_t::Make(
8888 { uT(
"kind"), uT(
"Billboard") },
8889 { uT(
"service"), Object_t{ Components.begin(), Components.end() } }
8891 ASSERT_NE(
nullptr, Render);
8893 using namespace ::testing;
8897 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, MatrixIdentity))
8905TEST_F(OpenGLShader_test, Test_Buffer_Constant_User_CreateBuffer_Error)
8907 using BufferMapper_t = ::covellite::api::cbBufferMap_t<void>;
8909 using GLProxy_t = ::mock::GLProxy;
8911 GLProxy_t::GetInstance() = &GLProxy;
8914 const BufferMapper_t BufferMapper = [&](
void *) {
return false; };
8916 const Tested_t oExample{ Data_t{} };
8917 const ITested_t & IExample = oExample;
8919 auto itConstBufferCreator = IExample.GetCreators().find(uT(
"Buffer"));
8920 ASSERT_NE(IExample.GetCreators().end(), itConstBufferCreator);
8922 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent)
8924 using namespace ::testing;
8928 EXPECT_CALL(GLProxy, GenBuffers(_))
8931 EXPECT_CALL(GLProxy, GetError())
8933 .WillOnce(Return(1909211243));
8935 EXPECT_THROW(itConstBufferCreator->second(_pComponent), ::std::exception);
8938 const auto pBuffer = Component_t::Make(
8940 { uT(
"mapper"), BufferMapper },
8941 { uT(
"size"),
sizeof(Data) },
8943 TestCallRender(pBuffer);
8947TEST_F(OpenGLShader_test, Test_Buffer_Constant_User_UpdateBuffer_NotExistsName)
8949 using BufferMapper_t = ::covellite::api::cbBufferMap_t<void>;
8951 using GLProxy_t = ::mock::GLProxy;
8953 GLProxy_t::GetInstance() = &GLProxy;
8955 const BufferMapper_t BufferMapper = [&](
void *) {
return false; };
8957 using namespace ::testing;
8959 const Tested_t oExample{ Data_t{} };
8960 const ITested_t & IExample = oExample;
8962 auto itConstBufferCreator = IExample.GetCreators().find(uT(
"Buffer"));
8963 ASSERT_NE(IExample.GetCreators().end(), itConstBufferCreator);
8965 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent)
8967 using namespace ::testing;
8969 const auto Render = itConstBufferCreator->second(_pComponent);
8970 ASSERT_NE(
nullptr, Render);
8974 EXPECT_CALL(GLProxy, GetUniformBlockIndex(_, _))
8976 .WillOnce(Return(GL_INVALID_INDEX));
8978 EXPECT_CALL(GLProxy, BindBuffer(_, _))
8981 EXPECT_CALL(GLProxy, UniformBufferSubData(_, _, _))
8984 EXPECT_CALL(GLProxy, BindBufferBase(_, _, _))
8987 EXPECT_CALL(GLProxy, UniformBlockBinding(_, _, _))
8993 const auto pBuffer = Component_t::Make(
8995 { uT(
"mapper"), BufferMapper },
8996 { uT(
"size"), ::std::size_t{ 4 } },
8999 TestCallRender(pBuffer);
9003TEST_F(OpenGLShader_test, Test_Buffer_Constant_User)
9005 using BufferMapper_t = ::covellite::api::cbBufferMap_t<void>;
9007 using GLProxy_t = ::mock::GLProxy;
9009 GLProxy_t::GetInstance() = &GLProxy;
9012 public ::alicorn::extension::testing::Proxy<MapperProxy>
9015 MOCK_METHOD1(DoMapper,
void(
const void *));
9018 MapperProxy oMapperProxy;
9019 MapperProxy::GetInstance() = &oMapperProxy;
9021 const ::mock::GLuint BufferId = 1909211301;
9022 const ::mock::GLint ProgramId = 1909211302;
9023 const ::mock::GLint BlockIndex = 1909211332;
9024 const ::std::size_t Size = 313;
9026 void * pData =
nullptr;
9028 const BufferMapper_t BufferMapper = [&](
void * _pData)
9031 oMapperProxy.DoMapper(_pData);
9035 const Tested_t oExample{ Data_t{} };
9036 const ITested_t & IExample = oExample;
9038 auto itConstBufferCreator = IExample.GetCreators().find(uT(
"Buffer"));
9039 ASSERT_NE(IExample.GetCreators().end(), itConstBufferCreator);
9041 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent,
9042 const ::std::string & _Name)
9044 using namespace ::testing;
9048 EXPECT_CALL(GLProxy, GenBuffers(1))
9050 .WillOnce(Return(BufferId));
9052 EXPECT_CALL(GLProxy, BindBuffer(GL_UNIFORM_BUFFER, BufferId))
9055 EXPECT_CALL(GLProxy,
9056 BufferData(GL_UNIFORM_BUFFER, Size, _, GL_DYNAMIC_DRAW))
9059 EXPECT_CALL(GLProxy, BindBuffer(GL_UNIFORM_BUFFER, 0))
9062 EXPECT_CALL(GLProxy, GetError())
9064 .WillOnce(Return(GL_NO_ERROR));
9066 const auto Render = itConstBufferCreator->second(_pComponent);
9067 ASSERT_NE(
nullptr, Render);
9069 EXPECT_CALL(oMapperProxy, DoMapper(_))
9072 EXPECT_CALL(GLProxy, GetIntegerv(_))
9075 EXPECT_CALL(GLProxy, GetUniformBlockIndex(_, _))
9077 .WillOnce(Return(BlockIndex));
9079 EXPECT_CALL(GLProxy, BindBuffer(_, _))
9082 EXPECT_CALL(GLProxy, UniformBufferSubData(_, _, _))
9085 EXPECT_CALL(GLProxy, BindBuffer(_, _))
9088 EXPECT_CALL(GLProxy, BindBufferBase(_, _, _))
9091 EXPECT_CALL(GLProxy, UniformBlockBinding(_, _, _))
9096 EXPECT_CALL(oMapperProxy, DoMapper(pData))
9099 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
9101 .WillOnce(Return(&ProgramId));
9103 EXPECT_CALL(GLProxy, GetUniformBlockIndex(ProgramId, _Name))
9105 .WillOnce(Return(BlockIndex));
9107 EXPECT_CALL(GLProxy, BindBuffer(GL_UNIFORM_BUFFER, BufferId))
9110 EXPECT_CALL(GLProxy, UniformBufferSubData(0, Size, pData))
9113 EXPECT_CALL(GLProxy, BindBuffer(GL_UNIFORM_BUFFER, 0))
9116 EXPECT_CALL(GLProxy,
9117 BindBufferBase(GL_UNIFORM_BUFFER, COVELLITE_BUFFER_INDEX_USER, BufferId))
9120 EXPECT_CALL(GLProxy,
9121 UniformBlockBinding(ProgramId, BlockIndex, COVELLITE_BUFFER_INDEX_USER))
9126 EXPECT_CALL(GLProxy, DeleteBuffers(1, BufferId))
9132 const auto pBuffer = Component_t::Make(
9134 { uT(
"mapper"), BufferMapper },
9135 { uT(
"size"), Size },
9138 TestCallRender(pBuffer,
"cbUserData");
9142 const ::std::string Name =
"Name1909211251";
9144 const auto pBuffer = Component_t::Make(
9146 { uT(
"mapper"), BufferMapper },
9147 { uT(
"size"), Size },
9148 { uT(
"name"), Name },
9151 TestCallRender(pBuffer, Name);
9156TEST_F(OpenGLShader_test, Test_Camera_Orthographic_DefaultPosition)
9158 Tested::GetValue() = 1;
9160 ::mock::GLProxy GLProxy;
9162 const Tested_t Example{ Data_t{} };
9163 const ITested_t & IExample = Example;
9165 auto itCreator = IExample.GetCreators().find(uT(
"Camera"));
9166 ASSERT_NE(IExample.GetCreators().end(), itCreator);
9168 auto Render = itCreator->second(Component_t::Make(
9170 { uT(
"kind"), uT(
"Orthographic") },
9172 ASSERT_NE(
nullptr, Render);
9174 auto itShaderCreator = IExample.GetCreators().find(uT(
"Shader"));
9175 ASSERT_NE(IExample.GetCreators().end(), itShaderCreator);
9177 auto VsRender = itShaderCreator->second(Component_t::Make(
9179 { uT(
"entry"), uT(
"vsFlat") },
9181 ASSERT_NE(
nullptr, VsRender);
9183 auto PsRender = itShaderCreator->second(Component_t::Make(
9185 { uT(
"entry"), uT(
"psColored") },
9187 ASSERT_NE(
nullptr, PsRender);
9189 const float Viewport[] =
9191 1812271148.0f, 1812271149.0f, 1812181722.0f, 1812181723.0f
9194 using namespace ::testing;
9196 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, 0))
9199 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
9202 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
9205 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
9208 EXPECT_CALL(GLProxy, Disable(GL_BLEND))
9211 EXPECT_CALL(GLProxy, Disable(GL_DITHER))
9214 EXPECT_CALL(GLProxy, Enable(GL_CULL_FACE))
9217 EXPECT_CALL(GLProxy, CullFace(GL_BACK))
9220 EXPECT_CALL(GLProxy, FrontFace(GL_CCW))
9223 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
9226 EXPECT_CALL(GLProxy, GetFloatv(GL_VIEWPORT))
9228 .WillOnce(Return(Viewport));
9235 const ::mock::GLint ProgramId = 1908251932;
9236 const ::mock::GLint ProjectionLocationId = 1908251933;
9237 const ::mock::GLint ViewLocationId = 1908252005;
9238 const ::mock::GLint ViewInverseLocationId = 1908252013;
9240 const auto Projection = ::glm::transpose(::glm::ortho(
9241 Viewport[0], Viewport[0] + Viewport[2],
9242 Viewport[1] + Viewport[3], Viewport[1],
9244 auto View = ::glm::identity<::glm::mat4>();
9245 const auto ViewInverse = ::glm::transpose(::glm::inverse(View));
9246 View = ::glm::transpose(View);
9250 EXPECT_CALL(GLProxy, GetProgramiv(_, _))
9252 .WillOnce(Return(GL_TRUE));
9254 EXPECT_CALL(GLProxy, UseProgram(_))
9257 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
9259 .WillOnce(Return(&ProgramId));
9263 EXPECT_CALL(GLProxy, GetUniformLocation(_, _))
9266 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, _))
9271 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.Projection")))
9273 .WillOnce(Return(ProjectionLocationId));
9275 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.View")))
9277 .WillOnce(Return(ViewLocationId));
9279 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.ViewInverse")))
9281 .WillOnce(Return(ViewInverseLocationId));
9283 EXPECT_CALL(GLProxy,
9284 UniformMatrix4fv(ProjectionLocationId, 1, GL_FALSE, Projection))
9287 EXPECT_CALL(GLProxy,
9288 UniformMatrix4fv(ViewLocationId, 1, GL_FALSE, View))
9291 EXPECT_CALL(GLProxy,
9292 UniformMatrix4fv(ViewInverseLocationId, 1, GL_FALSE, ViewInverse))
9299TEST_F(OpenGLShader_test, Test_Camera_Orthographic)
9301 Tested::GetValue() = 1;
9303 using GLProxy_t = ::mock::GLProxy;
9305 GLProxy_t::GetInstance() = &GLProxy;
9307 const auto X = 11111.0f;
9308 const auto Y = 22222.0f;
9310 const float SourceViewport[] =
9312 19022.82014f, 19022.82015f, 19022.82016f, 19022.82017f
9315 const Tested_t Example{ Data_t{} };
9316 const ITested_t & IExample = Example;
9318 auto itCreator = IExample.GetCreators().find(uT(
"Camera"));
9319 ASSERT_NE(IExample.GetCreators().end(), itCreator);
9321 auto itShaderCreator = IExample.GetCreators().find(uT(
"Shader"));
9322 ASSERT_NE(IExample.GetCreators().end(), itShaderCreator);
9324 auto VsRender = itShaderCreator->second(Component_t::Make(
9326 { uT(
"entry"), uT(
"vsFlat") },
9328 ASSERT_NE(
nullptr, VsRender);
9330 auto PsRender = itShaderCreator->second(Component_t::Make(
9332 { uT(
"entry"), uT(
"psColored") },
9334 ASSERT_NE(
nullptr, PsRender);
9336 using namespace ::testing;
9338 const auto pPosition = Component_t::Make(
9340 { uT(
"kind"), uT(
"Position") },
9345 const auto pCameraComponent = Component_t::Make(
9347 { uT(
"kind"), uT(
"Orthographic") },
9348 { uT(
"service"), Object_t{ pPosition } },
9351 auto Render = itCreator->second(pCameraComponent);
9352 ASSERT_NE(
nullptr, Render);
9356 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, 0))
9359 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
9362 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
9365 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
9368 EXPECT_CALL(GLProxy, Disable(GL_BLEND))
9371 EXPECT_CALL(GLProxy, Disable(GL_DITHER))
9374 EXPECT_CALL(GLProxy, Enable(GL_CULL_FACE))
9377 EXPECT_CALL(GLProxy, CullFace(GL_BACK))
9380 EXPECT_CALL(GLProxy, FrontFace(GL_CCW))
9383 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
9386 EXPECT_CALL(GLProxy, GetFloatv(GL_VIEWPORT))
9388 .WillOnce(Return(SourceViewport));
9392 const auto Projection = ::glm::transpose(::glm::ortho(
9393 SourceViewport[0] + X,
9394 SourceViewport[0] + SourceViewport[2] + X,
9395 SourceViewport[1] + SourceViewport[3] + Y,
9396 SourceViewport[1] + Y,
9399 auto View = ::glm::identity<::glm::mat4>();
9400 const auto ViewInverse = ::glm::transpose(::glm::inverse(View));
9401 View = ::glm::transpose(View);
9403 EXPECT_EQ(View, (::glm::mat4)(*pCameraComponent)[uT(
"view")].Default(::glm::mat4{ 1.0f }));
9404 EXPECT_EQ(Projection, (::glm::mat4)(*pCameraComponent)[uT(
"projection")].Default(::glm::mat4{ 1.0f }));
9409 EXPECT_CALL(GLProxy, GetProgramiv(_, _))
9411 .WillOnce(Return(GL_TRUE));
9413 EXPECT_CALL(GLProxy, UseProgram(_))
9416 const ::mock::GLint ProgramId = 1908251932;
9417 const ::mock::GLint ProjectionLocationId = 1908251933;
9418 const ::mock::GLint ViewLocationId = 1908252005;
9419 const ::mock::GLint ViewInverseLocationId = 1908252013;
9421 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
9423 .WillRepeatedly(Return(&ProgramId));
9427 EXPECT_CALL(GLProxy, GetUniformLocation(_, _))
9430 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, _))
9435 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.Projection")))
9437 .WillOnce(Return(ProjectionLocationId));
9439 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.View")))
9441 .WillOnce(Return(ViewLocationId));
9443 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.ViewInverse")))
9445 .WillOnce(Return(ViewInverseLocationId));
9447 EXPECT_CALL(GLProxy,
9448 UniformMatrix4fv(ProjectionLocationId, 1, GL_FALSE, Projection))
9451 EXPECT_CALL(GLProxy,
9452 UniformMatrix4fv(ViewLocationId, 1, GL_FALSE, View))
9455 EXPECT_CALL(GLProxy,
9456 UniformMatrix4fv(ViewInverseLocationId, 1, GL_FALSE, ViewInverse))
9463TEST_F(OpenGLShader_test, Test_Camera_Perspective)
9465 ::testing::DefaultValue<int>::Set(GL_TRUE);
9467 Tested::GetValue() = 1;
9469 using GLProxy_t = ::mock::GLProxy;
9471 GLProxy_t::GetInstance() = &GLProxy;
9473 const float Width = 1024.0f;
9474 const float Height = 768.0f;
9476 const Tested_t Example{ Data_t{} };
9477 const ITested_t & IExample = Example;
9479 auto itShaderCreator = IExample.GetCreators().find(uT(
"Shader"));
9480 ASSERT_NE(IExample.GetCreators().end(), itShaderCreator);
9482 auto VsRender = itShaderCreator->second(Component_t::Make(
9484 { uT(
"entry"), uT(
"vsFlat") },
9486 ASSERT_NE(
nullptr, VsRender);
9488 auto PsRender = itShaderCreator->second(Component_t::Make(
9490 { uT(
"entry"), uT(
"psColored") },
9492 ASSERT_NE(
nullptr, PsRender);
9494 using namespace ::testing;
9496 auto TestCallRender = [&](
9497 const Component_t::ComponentPtr_t & _pCameraComponent,
9499 float _AngleY,
float _zNear,
float _zFar,
9500 float _X,
float _Y,
float _Z,
9501 float _A,
float _B,
float _C,
9504 ASSERT_NE(
nullptr, _Render);
9506 const float AngleYRadians = _AngleY *
9507 ::alicorn::extension::cpp::math::Constant<float>::DegreeToRadian;
9511 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, 0))
9514 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
9517 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
9520 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
9523 EXPECT_CALL(GLProxy, Disable(GL_BLEND))
9526 EXPECT_CALL(GLProxy, Disable(GL_DITHER))
9529 EXPECT_CALL(GLProxy, Enable(GL_CULL_FACE))
9532 EXPECT_CALL(GLProxy, CullFace(GL_BACK))
9535 EXPECT_CALL(GLProxy, FrontFace(GL_CCW))
9538 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
9541 const float Viewport[] = { 0, 0, Width, Height };
9543 EXPECT_CALL(GLProxy, GetFloatv(GL_VIEWPORT))
9545 .WillOnce(Return(Viewport));
9549 const auto Projection = ::glm::transpose(::glm::perspectiveFovRH(
9550 AngleYRadians, Viewport[2], Viewport[3], _zFar, _zNear));
9552 auto GetEye = [&](void) -> ::glm::vec3
9554 const auto Distance = _Distance + 0.1f;
9556 ::glm::mat4 Transform = ::glm::identity<::glm::mat4>();
9558 Transform = ::glm::translate(Transform,
9559 ::glm::vec3{ _X, _Y, _Z });
9560 Transform = ::glm::rotate(Transform,
9561 _C, ::glm::vec3{ 0.0f, 0.0f, 1.0f });
9562 Transform = ::glm::rotate(Transform,
9563 _B, ::glm::vec3{ 0.0f, 1.0f, 0.0f });
9564 Transform = ::glm::rotate(Transform,
9565 _A, ::glm::vec3{ 1.0f, 0.0f, 0.0f });
9567 return Transform * ::glm::vec4{ Distance, 0.0f, 0.0f, 1.0f };
9570 auto View = ::glm::lookAtRH(
9572 ::glm::vec3{ _X, _Y, _Z },
9573 ::glm::vec3{ 0.0f, 0.0f, 1.0f });
9574 const auto ViewInverse = ::glm::transpose(::glm::inverse(View));
9575 View = ::glm::transpose(View);
9577 EXPECT_EQ(View, (::glm::mat4)(*_pCameraComponent)[uT(
"view")].Default(::glm::mat4{ 1.0f }));
9578 EXPECT_EQ(Projection, (::glm::mat4)(*_pCameraComponent)[uT(
"projection")].Default(::glm::mat4{ 1.0f }));
9580 EXPECT_CALL(GLProxy, UseProgram(_))
9586 const ::mock::GLint ProgramId = 1908251932;
9587 const ::mock::GLint ProjectionLocationId = 1908251933;
9588 const ::mock::GLint ViewLocationId = 1908252005;
9589 const ::mock::GLint ViewInverseLocationId = 1908252013;
9591 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
9593 .WillRepeatedly(Return(&ProgramId));
9597 EXPECT_CALL(GLProxy, GetUniformLocation(_, _))
9600 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, _))
9605 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.Projection")))
9607 .WillOnce(Return(ProjectionLocationId));
9609 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.View")))
9611 .WillOnce(Return(ViewLocationId));
9613 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.ViewInverse")))
9615 .WillOnce(Return(ViewInverseLocationId));
9617 EXPECT_CALL(GLProxy,
9618 UniformMatrix4fv(ProjectionLocationId, 1, GL_FALSE, Projection))
9621 EXPECT_CALL(GLProxy,
9622 UniformMatrix4fv(ViewLocationId, 1, GL_FALSE, View))
9625 EXPECT_CALL(GLProxy,
9626 UniformMatrix4fv(ViewInverseLocationId, 1, GL_FALSE, ViewInverse))
9631 ::testing::DefaultValue<int>::Clear();
9634 auto itCreator = IExample.GetCreators().find(uT(
"Camera"));
9635 ASSERT_NE(IExample.GetCreators().end(), itCreator);
9647 const ::std::vector<CameraInfo> CameraInfos =
9649 { 90.0f, 0.01f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f },
9650 { 91.0f, 1.11f, 10.1f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f },
9651 { 92.0f, 2.22f, 20.2f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f },
9657 const auto pCamera = Component_t::Make(
9659 { uT(
"kind"), uT(
"Perspective") },
9662 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
9665 auto Render = itCreator->second(pCamera);
9667 auto Info = CameraInfos[0];
9671 Info.AngleY, Info.zNear, Info.zFar,
9672 Info.X, Info.Y, Info.Z,
9673 Info.A, Info.B, Info.C,
9677 const auto pPosition = Component_t::Make(
9679 { uT(
"kind"), uT(
"Position") },
9682 const auto pRotation = Component_t::Make(
9684 { uT(
"kind"), uT(
"Rotation") },
9690 const auto pCamera = Component_t::Make(
9692 { uT(
"kind"), uT(
"Perspective") },
9693 { uT(
"service"), Object_t{ pPosition, pRotation } },
9696 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
9699 auto Render = itCreator->second(pCamera);
9701 auto Info = CameraInfos[0];
9705 Info.AngleY, Info.zNear, Info.zFar,
9706 Info.X, Info.Y, Info.Z,
9707 Info.A, Info.B, Info.C,
9714 const auto pCamera = Component_t::Make(
9716 { uT(
"kind"), uT(
"Perspective") },
9717 { uT(
"service"), Object_t{ pPosition, pRotation } },
9720 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
9723 auto Render = itCreator->second(pCamera);
9725 for (
size_t i = 1; i < CameraInfos.size(); i++)
9727 auto Info = CameraInfos[i];
9729 (*pPosition)[uT(
"x")] = Info.X;
9730 (*pPosition)[uT(
"y")] = Info.Y;
9731 (*pPosition)[uT(
"z")] = Info.Z;
9733 (*pRotation)[uT(
"x")] = Info.A;
9734 (*pRotation)[uT(
"y")] = Info.B;
9735 (*pRotation)[uT(
"z")] = Info.C;
9737 (*pCamera)[uT(
"fov")] = Info.AngleY;
9738 (*pCamera)[uT(
"znear")] = Info.zNear;
9739 (*pCamera)[uT(
"zfar")] = Info.zFar;
9740 (*pCamera)[uT(
"distance")] = Info.Distance;
9744 Info.AngleY, Info.zNear, Info.zFar,
9745 Info.X, Info.Y, Info.Z,
9746 Info.A, Info.B, Info.C,
9753TEST_F(OpenGLShader_test, Test_Camera_SetWindowViewport)
9755 const auto TestCall = [](
const Component_t::ComponentPtr_t & _pCamera)
9757 ::mock::WindowsProxy WindowsProxy;
9758 ::mock::GLProxy GLProxy;
9761 Data.ClientRect.Top = 12345;
9762 Data.ClientRect.Width = 2008131258;
9763 Data.ClientRect.Height = 2008131259;
9765 using namespace ::testing;
9767 Tested_t Example{ Data };
9768 ITested_t & IExample = Example;
9770 auto itCreator = IExample.GetCreators().find(uT(
"Camera"));
9771 ASSERT_NE(IExample.GetCreators().end(), itCreator);
9773 EXPECT_CALL(GLProxy, Viewport(0, 0, Data.ClientRect.Width, Data.ClientRect.Height - Data.ClientRect.Top))
9776 auto Render = itCreator->second(_pCamera);
9777 ASSERT_NE(
nullptr, Render);
9779 EXPECT_CALL(GLProxy, Viewport(0, 0, Data.ClientRect.Width, Data.ClientRect.Height - Data.ClientRect.Top))
9784 IExample.ResizeWindow(::covellite::Rect{ 0, 54321, 2008131300, 2008131301 });
9786 EXPECT_CALL(GLProxy, Viewport(0, 0, 2008131300, 2008131301 - 54321))
9792 TestCall(Component_t::Make(
9794 { uT(
"kind"), uT(
"Orthographic") },
9797 TestCall(Component_t::Make(
9799 { uT(
"kind"), uT(
"Perspective") },
9804TEST_F(OpenGLShader_test, Test_Camera_SetScaleViewport)
9806 const auto TestCall = [](
const float _Scale,
9807 const Component_t::ComponentPtr_t & _pCamera)
9809 ::mock::WindowsProxy WindowsProxy;
9810 ::mock::GLProxy GLProxy;
9813 Data.ClientRect.Top = 123;
9814 Data.ClientRect.Width = 1024;
9815 Data.ClientRect.Height = 2048;
9817 const auto ExpectedWidth =
static_cast<int>(_Scale * Data.ClientRect.Width);
9818 const auto ExpectedHeight =
static_cast<int>(_Scale * (Data.ClientRect.Height - Data.ClientRect.Top));
9820 using namespace ::testing;
9822 Tested_t Example{ Data };
9823 ITested_t & IExample = Example;
9825 auto itCreator = IExample.GetCreators().find(uT(
"Camera"));
9826 ASSERT_NE(IExample.GetCreators().end(), itCreator);
9828 EXPECT_CALL(GLProxy, Viewport(0, 0, ExpectedWidth, ExpectedHeight))
9831 auto Render = itCreator->second(_pCamera);
9832 ASSERT_NE(
nullptr, Render);
9834 EXPECT_CALL(GLProxy, Viewport(0, 0, ExpectedWidth, ExpectedHeight))
9839 IExample.ResizeWindow(::covellite::Rect{ 0, 321, 2048, 4096 });
9841 const auto ExpectedWidth2 =
static_cast<int>(_Scale * 2048);
9842 const auto ExpectedHeight2 =
static_cast<int>(_Scale * (4096 - 321));
9844 EXPECT_CALL(GLProxy, Viewport(0, 0, ExpectedWidth2, ExpectedHeight2))
9850 TestCall(0.5f, Component_t::Make(
9852 { uT(
"kind"), uT(
"Orthographic") },
9853 { uT(
"scale"), 0.5f },
9856 TestCall(2.0f, Component_t::Make(
9858 { uT(
"kind"), uT(
"Perspective") },
9859 { uT(
"scale"), 2.0f },
9862 TestCall(0.25f, Component_t::Make(
9864 { uT(
"kind"), uT(
"Orthographic") },
9865 { uT(
"scale"), 0.25f },
9866 { uT(
"width"), 2009081959 },
9867 { uT(
"height"), 2009082000 },
9870 TestCall(4.0f, Component_t::Make(
9872 { uT(
"kind"), uT(
"Perspective") },
9873 { uT(
"scale"), 4.0f },
9874 { uT(
"width"), 2009081959 },
9875 { uT(
"height"), 2009082000 },
9880TEST_F(OpenGLShader_test, Test_Camera_SetUserViewport)
9882 const auto TestCall = [](
const int _Width,
const int _Height,
9883 const Component_t::ComponentPtr_t & _pCamera)
9885 ::mock::WindowsProxy WindowsProxy;
9886 ::mock::GLProxy GLProxy;
9889 Data.ClientRect.Top = 345;
9890 Data.ClientRect.Width = 2009082008;
9891 Data.ClientRect.Height = 2009082009;
9893 using namespace ::testing;
9895 Tested_t Example{ Data };
9896 ITested_t & IExample = Example;
9898 auto itCreator = IExample.GetCreators().find(uT(
"Camera"));
9899 ASSERT_NE(IExample.GetCreators().end(), itCreator);
9901 EXPECT_CALL(GLProxy, Viewport(0, 0, _Width, _Height))
9904 auto Render = itCreator->second(_pCamera);
9905 ASSERT_NE(
nullptr, Render);
9907 EXPECT_CALL(GLProxy, Viewport(0, 0, _Width, _Height))
9912 IExample.ResizeWindow(::covellite::Rect{ 0, 543, 2008131300, 2008131301 });
9914 EXPECT_CALL(GLProxy, Viewport(0, 0, _Width, _Height))
9920 TestCall(1024, 2048, Component_t::Make(
9922 { uT(
"kind"), uT(
"Orthographic") },
9923 { uT(
"width"), 1024 },
9924 { uT(
"height"), 2048 },
9927 TestCall(2048, 4096, Component_t::Make(
9929 { uT(
"kind"), uT(
"Perspective") },
9930 { uT(
"width"), 2048 },
9931 { uT(
"height"), 4096 },
Класс входит в проект Covellite.Api Класс формата вертексного буфера.
Definition Vertex.hpp:34