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_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_BkSurface_Fail)
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 itCreator = IExample.GetCreators().find(uT(
"BkSurface"));
89 ASSERT_NE(IExample.GetCreators().end(), itCreator);
91 const ::mock::GLuint FrameBufferId = 1910041904;
93 using namespace ::testing;
97 EXPECT_CALL(GLProxy, GenFramebuffers(1))
99 .WillOnce(Return(FrameBufferId));
101 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
104 EXPECT_CALL(GLProxy, CheckFramebufferStatus(GL_FRAMEBUFFER))
106 .WillOnce(Return(1910041903));
108 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, 0))
111 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
114 EXPECT_THROW(itCreator->second(Component_t::Make({})), ::std::exception);
118TEST_F(OpenGLShader_test, Test_BkSurface)
120 const auto TestCall = [](
121 const Component_t::ComponentPtr_t & _pBkSurface,
122 const bool _IsUseMapper,
123 const int _Width,
const int _Height,
124 const int _ExpectedWidth,
const int _ExpectedHeight)
126 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
128 ::mock::GLProxy GLProxy;
131 SettingsData.ClientRect.Top = 34;
133 Tested_t Example{ SettingsData };
134 ITested_t & IExample = Example;
135 IExample.PresentFrame();
137 auto itCreator = IExample.GetCreators().find(uT(
"BkSurface"));
138 ASSERT_NE(IExample.GetCreators().end(), itCreator);
140 constexpr ::mock::GLint TextureId = 1910041735;
141 constexpr ::mock::GLint FrameBufferId = 1910041803;
142 constexpr ::mock::GLint BindingFrameBufferId = 2006162207;
144 const ::std::vector<String_t> Destinations =
156 Object_t TextureComponents;
158 for (::std::size_t i = 0; i < Destinations.size(); i++)
160 const auto pTexture = Component_t::Make(
162 { uT(
"kind"), uT(
"Texture") },
163 { uT(
"destination"), Destinations[i] },
166 if (_IsUseMapper) (*pTexture)[uT(
"mapper")] = BufferMapper_t{};
168 TextureComponents.push_back(pTexture);
171 using namespace ::testing;
175 const int Viewport[] = { 0, 0, _Width, _Height };
177 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
179 .WillOnce(Return(Viewport));
181 EXPECT_CALL(GLProxy, GenFramebuffers(1))
183 .WillOnce(Return(FrameBufferId));
185 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
187 .WillOnce(Return(&BindingFrameBufferId));
189 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
192 ::std::vector<::mock::GLenum> AttachmentIndexes;
194 for (::std::size_t i = 0; i < Destinations.size(); i++)
196 auto Format = GL_DEPTH_COMPONENT;
197 auto Attachment = GL_DEPTH_ATTACHMENT;
199 if (Destinations[i] != uT(
"depth"))
202 Attachment = GL_COLOR_ATTACHMENT0 +
203 static_cast<int>(AttachmentIndexes.size());
204 AttachmentIndexes.push_back(Attachment);
207 EXPECT_CALL(GLProxy, GenTextures(1))
209 .WillOnce(Return(TextureId + i));
211 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId + i))
214 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, _,
215 _ExpectedWidth, _ExpectedHeight, 0, Format, _, ::std::vector<uint8_t>{}))
218 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
221 EXPECT_CALL(GLProxy, GetError())
223 .WillOnce(Return(GL_NO_ERROR));
225 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER, Attachment,
226 GL_TEXTURE_2D, TextureId + i, 0))
230 EXPECT_CALL(GLProxy, CheckFramebufferStatus(GL_FRAMEBUFFER))
232 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
234 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, BindingFrameBufferId))
237 (*_pBkSurface)[uT(
"service")] = TextureComponents;
239 auto Render = itCreator->second(_pBkSurface);
240 ASSERT_NE(
nullptr, Render);
242 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
244 .WillOnce(Return(Viewport));
246 EXPECT_CALL(GLProxy, TexImage2D(_, _, _, _, _, _, _, _, _))
249 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
251 .WillOnce(Return(&BindingFrameBufferId));
253 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
256 EXPECT_CALL(GLProxy, DrawBuffers(AttachmentIndexes))
259 EXPECT_CALL(GLProxy, Viewport(_, _, _, _))
264 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
267 ASSERT_EQ(TextureComponents.size(), Destinations.size());
269 EXPECT_EQ(_ExpectedWidth, (
int)(*_pBkSurface)[uT(
"width")]);
270 EXPECT_EQ(_ExpectedHeight, (
int)(*_pBkSurface)[uT(
"height")]);
272 for (::std::size_t i = 0; i < TextureComponents.size(); i++)
274 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
276 const auto pTextureComponent = TextureComponents[i];
277 const Texture_t::Ptr_t pTexture =
278 (*pTextureComponent)[uT(
"entity")].Default(Texture_t::Ptr_t{});
279 ASSERT_NE(
nullptr, pTexture);
280 EXPECT_EQ(TextureId + i, pTexture->m_TextureId);
281 EXPECT_EQ(_IsUseMapper ? 4 * _ExpectedWidth * _ExpectedHeight : 0,
282 pTexture->m_ReadCopyData.size());
283 EXPECT_EQ(_ExpectedWidth, (
int)(*pTextureComponent)[uT(
"width")].Default(0));
284 EXPECT_EQ(_ExpectedHeight, (
int)(*pTextureComponent)[uT(
"height")].Default(0));
288 TestCall(Component_t::Make({ }),
289 false, 12, 45, 12, 45);
290 TestCall(Component_t::Make({ }),
291 true, 45, 12, 45, 12);
295TEST_F(OpenGLShader_test, Test_BkSurface_RenderDepthOnly)
297 using GLProxy_t = ::mock::GLProxy;
299 GLProxy_t::GetInstance() = &GLProxy;
301 const Tested_t Example{ Data_t{} };
302 const ITested_t & IExample = Example;
304 auto itCreator = IExample.GetCreators().find(uT(
"BkSurface"));
305 ASSERT_NE(IExample.GetCreators().end(), itCreator);
307 const ::mock::GLuint TextureId = 1910041735;
308 const ::mock::GLuint FrameBufferId = 1910041803;
310 using namespace ::testing;
314 const auto pTexture = Component_t::Make(
316 { uT(
"kind"), uT(
"Texture") },
317 { uT(
"destination"), uT(
"depth") },
320 EXPECT_CALL(GLProxy, CheckFramebufferStatus(GL_FRAMEBUFFER))
322 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
324 auto Render = itCreator->second(Component_t::Make(
326 { uT(
"service"), Object_t{ pTexture } }
328 ASSERT_NE(
nullptr, Render);
330 EXPECT_CALL(GLProxy, DrawBuffers(::std::vector<::mock::GLenum>{}))
337TEST_F(OpenGLShader_test, Test_BkSurface_ResizeWindow)
339 const auto TestCall = [](
340 const Component_t::ComponentPtr_t & _pBkSurface,
341 const bool _IsUseMapper,
342 const int _Width,
const int _Height,
343 const int _ExpectedWidth,
const int _ExpectedHeight,
344 const int _ExpectedWidth2,
const int _ExpectedHeight2)
346 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
347 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
349 ::mock::GLProxy GLProxy;
352 SettingsData.ClientRect.Top = 45;
354 Tested_t Example{ SettingsData };
355 ITested_t & IExample = Example;
356 IExample.PresentFrame();
358 auto itCreator = IExample.GetCreators().find(uT(
"BkSurface"));
359 ASSERT_NE(IExample.GetCreators().end(), itCreator);
361 constexpr ::mock::GLuint TextureId = 1910091302;
363 const ::std::vector<String_t> Destinations =
373 Object_t TextureComponents;
375 for (::std::size_t i = 0; i < Destinations.size(); i++)
377 const auto pTexture = Component_t::Make(
379 { uT(
"kind"), uT(
"Texture") },
380 { uT(
"destination"), Destinations[i] },
383 if (_IsUseMapper) (*pTexture)[uT(
"mapper")] = BufferMapper_t{};
385 TextureComponents.push_back(pTexture);
388 using namespace ::testing;
392 const int Viewport[] = { 0, 0, _Width, _Height };
394 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
396 .WillOnce(Return(Viewport));
398 EXPECT_CALL(GLProxy, GetIntegerv(_))
401 for (::std::size_t i = 0; i < Destinations.size(); i++)
403 EXPECT_CALL(GLProxy, GenTextures(1))
405 .WillOnce(Return(TextureId + i));
407 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId + i))
410 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, _, _,
411 _ExpectedWidth, _ExpectedHeight, _, _, _, ::std::vector<uint8_t>{}))
414 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
417 EXPECT_CALL(GLProxy, GetError())
419 .WillOnce(Return(GL_NO_ERROR));
422 EXPECT_CALL(GLProxy, CheckFramebufferStatus(GL_FRAMEBUFFER))
424 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE));
426 (*_pBkSurface)[uT(
"service")] = TextureComponents;
428 auto Render = itCreator->second(_pBkSurface);
429 ASSERT_NE(
nullptr, Render);
431 EXPECT_EQ(_ExpectedWidth, (
int)(*_pBkSurface)[uT(
"width")]);
432 EXPECT_EQ(_ExpectedHeight, (
int)(*_pBkSurface)[uT(
"height")]);
434 for (::std::size_t i = 0; i < TextureComponents.size(); i++)
436 const auto pTextureComponent = TextureComponents[i];
437 EXPECT_EQ(_ExpectedWidth, (
int)(*pTextureComponent)[uT(
"width")].Default(0));
438 EXPECT_EQ(_ExpectedHeight, (
int)(*pTextureComponent)[uT(
"height")].Default(0));
440 const Texture_t::Ptr_t pTexture =
441 (*pTextureComponent)[uT(
"entity")].Default(Texture_t::Ptr_t{});
442 ASSERT_NE(
nullptr, pTexture);
443 EXPECT_EQ(_IsUseMapper ? _ExpectedWidth * _ExpectedHeight * 4 : 0,
444 pTexture->m_ReadCopyData.size());
447 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
450 EXPECT_CALL(GLProxy, TexImage2D(_, _, _, _, _, _, _, _, _))
453 EXPECT_CALL(GLProxy, GetIntegerv(_))
456 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, _))
459 EXPECT_CALL(GLProxy, Viewport(_, _, _, _))
464 IExample.PresentFrame();
466 const int Viewport2[] = { 0, 0, _Width * 2, _Height * 2 };
468 IExample.ResizeWindow(::covellite::Rect{ 0, 0, _Width * 2, _Height * 2 });
470 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
472 .WillOnce(Return(Viewport2));
474 for (::std::size_t i = 0; i < Destinations.size(); i++)
476 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId + i))
479 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, _, _,
480 _ExpectedWidth2, _ExpectedHeight2, _, _, _, ::std::vector<uint8_t>{}))
483 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
486 EXPECT_CALL(GLProxy, GetError())
488 .WillOnce(Return(GL_NO_ERROR));
491 EXPECT_CALL(GLProxy, GetIntegerv(_))
494 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, _))
497 EXPECT_CALL(GLProxy, Viewport(_, _, _, _))
502 IExample.PresentFrame();
504 EXPECT_EQ(_ExpectedWidth2, (
int)(*_pBkSurface)[uT(
"width")]);
505 EXPECT_EQ(_ExpectedHeight2, (
int)(*_pBkSurface)[uT(
"height")]);
507 for (::std::size_t i = 0; i < TextureComponents.size(); i++)
509 const auto pTextureComponent = TextureComponents[i];
510 EXPECT_EQ(_ExpectedWidth2, (
int)(*pTextureComponent)[uT(
"width")].Default(0));
511 EXPECT_EQ(_ExpectedHeight2, (
int)(*pTextureComponent)[uT(
"height")].Default(0));
513 const Texture_t::Ptr_t pTexture =
514 (*pTextureComponent)[uT(
"entity")].Default(Texture_t::Ptr_t{});
515 ASSERT_NE(
nullptr, pTexture);
516 EXPECT_EQ(_IsUseMapper ? _ExpectedWidth2 * _ExpectedHeight2 * 4 : 0,
517 pTexture->m_ReadCopyData.size());
520 EXPECT_CALL(GLProxy, GetIntegerv(GL_VIEWPORT))
523 EXPECT_CALL(GLProxy, TexImage2D(_, _, _, _, _, _, _, _, _))
526 EXPECT_CALL(GLProxy, GetIntegerv(_))
529 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, _))
532 EXPECT_CALL(GLProxy, Viewport(_, _, _, _))
537 IExample.PresentFrame();
540 TestCall(Component_t::Make({ }),
541 false, 45, 67, 45, 67, 90, 134);
542 TestCall(Component_t::Make({ }),
543 true, 45, 67, 45, 67, 90, 134);
547TEST_F(OpenGLShader_test, Test_Shader_InvalidType)
549 const ::std::string ShaderData =
550 "Pixel vs1(Polygon _Value)\r\n"
551 "Pixel vs2(Polyhedron _Value)\r\n";
553 using GLProxy_t = ::mock::GLProxy;
555 GLProxy_t::GetInstance() = &GLProxy;
557 const Tested_t Example{ Data_t{} };
558 const ITested_t & IExample = Example;
560 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
561 ASSERT_NE(IExample.GetCreators().end(), itCreator);
563 const ::mock::GLuint ShaderId = 1908250832;
565 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader)
567 using namespace ::testing;
571 EXPECT_CALL(GLProxy, CreateShader(_))
574 auto Render = itCreator->second(_pShader);
575 EXPECT_EQ(
nullptr, Render);
579 const auto pShader = Component_t::Make(
581 { uT(
"entry"), uT(
"vs1") },
582 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
589 const auto pData = Component_t::Make(
591 { uT(
"kind"), uT(
"Shader") },
592 { uT(
"entry"), uT(
"vs2") },
593 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
596 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
601TEST_F(OpenGLShader_test, Test_Shader_NotExistsEntryPoint)
603 using GLProxy_t = ::mock::GLProxy;
605 GLProxy_t::GetInstance() = &GLProxy;
607 const Tested_t Example{ Data_t{} };
608 const ITested_t & IExample = Example;
610 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
611 ASSERT_NE(IExample.GetCreators().end(), itCreator);
613 const ::mock::GLuint ShaderId = 1908250832;
615 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader)
617 using namespace ::testing;
621 EXPECT_CALL(GLProxy, CreateShader(_))
624 EXPECT_THROW(itCreator->second(_pShader), ::std::exception);
628 const auto pShader = Component_t::Make(
630 { uT(
"entry"), uT(
"vsUnknown") },
637 const auto pData = Component_t::Make(
639 { uT(
"kind"), uT(
"Shader") },
640 { uT(
"entry"), uT(
"vsUnknown") },
643 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
648TEST_F(OpenGLShader_test, Test_Shader_CompileFail)
650 using GLProxy_t = ::mock::GLProxy;
652 GLProxy_t::GetInstance() = &GLProxy;
654 const Tested_t Example{ Data_t{} };
655 const ITested_t & IExample = Example;
657 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
658 ASSERT_NE(IExample.GetCreators().end(), itCreator);
660 const ::mock::GLuint ShaderId = 1908251346;
661 const ::std::string ErrorText =
"Error1908251350";
663 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader)
665 using namespace ::testing;
669 EXPECT_CALL(GLProxy, CreateShader(_))
671 .WillOnce(Return(ShaderId));
673 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, _, _, _))
676 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
679 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
681 .WillOnce(Return(GL_FALSE));
683 EXPECT_CALL(GLProxy, GetShaderInfoLog(ShaderId, 512,
nullptr))
685 .WillOnce(Return(ErrorText.c_str()));
687 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
690 EXPECT_STDEXCEPTION(itCreator->second(_pShader),
691 (
".*Compile shader fail \\[header line: 164\\]: " + ErrorText).c_str());
695 const auto pShader = Component_t::Make(
697 { uT(
"entry"), uT(
"vsFlat") },
704 const auto pData = Component_t::Make(
706 { uT(
"kind"), uT(
"Shader") },
707 { uT(
"entry"), uT(
"vsVolume") },
710 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
714::std::string ConvertTextShader(const ::std::vector<uint8_t> & _ShaderText)
716 return ::std::string{ _ShaderText.cbegin(), _ShaderText.cend() };
720TEST_F(OpenGLShader_test, Test_Shader_CreateVertex_Default)
722 using GLProxy_t = ::mock::GLProxy;
724 GLProxy_t::GetInstance() = &GLProxy;
726 const Tested_t Example{ Data_t{} };
727 const ITested_t & IExample = Example;
729 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
730 ASSERT_NE(IExample.GetCreators().end(), itCreator);
732 const ::mock::GLuint ShaderId = 1908250832;
734 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
735 const ::std::string & _Entry)
737 using namespace ::alicorn::extension::std;
739 const auto ExpectedShaderText =
741 "#define COVELLITE_SHADER_GLSL\r\n"
742 "#define COVELLITE_SHADER_VERTEX\r\n" +
743 ConvertTextShader(::Predefined + ::Data + ::Input + ::Default) +
744 "out Pixel PixelValue;\r\n"
747 " Vertex InputData;\r\n"
748 " InputData.Position = Covellite_VertexPosition;\r\n"
749 " InputData.TexCoord = Covellite_VertexTexCoord;\r\n"
750 " InputData.Extra = Covellite_VertexExtra;\r\n"
751 " PixelValue = " + _Entry +
"(InputData);\r\n"
752 " gl_Position = PixelValue.ScreenPos;\r\n"
755 using namespace ::testing;
759 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
761 .WillOnce(Return(ShaderId));
763 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
766 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
769 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
771 .WillOnce(Return(GL_TRUE));
773 auto Render = itCreator->second(_pShader);
774 ASSERT_NE(
nullptr, Render);
778 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
783 const auto pShader = Component_t::Make(
785 { uT(
"entry"), uT(
"vsFlat") },
788 TestCall(pShader,
"vsFlat");
792 const auto pData = Component_t::Make(
794 { uT(
"kind"), uT(
"Shader") },
795 { uT(
"entry"), uT(
"vsVolume") },
798 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"vsVolume");
803TEST_F(OpenGLShader_test, Test_Shader_CreateVertex)
805 const ::std::string ShaderData =
806 "Pixel vs1(Vertex _Value)\r\n"
807 "Pixel vs2_Dummy(Vertex _Value)\r\n"
808 "Pixel vs2(Vertex _Value)\r\n";
810 using GLProxy_t = ::mock::GLProxy;
812 GLProxy_t::GetInstance() = &GLProxy;
814 const Tested_t Example{ Data_t{} };
815 const ITested_t & IExample = Example;
817 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
818 ASSERT_NE(IExample.GetCreators().end(), itCreator);
820 const ::mock::GLuint ShaderId = 1908250832;
822 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
823 const ::std::string & _Entry)
825 using namespace ::alicorn::extension::std;
827 const auto ExpectedShaderText =
829 "#define COVELLITE_SHADER_GLSL\r\n"
830 "#define COVELLITE_SHADER_VERTEX\r\n" +
831 ConvertTextShader(::Predefined + ::Data + ::Input) + ShaderData +
832 "out Pixel PixelValue;\r\n"
835 " Vertex InputData;\r\n"
836 " InputData.Position = Covellite_VertexPosition;\r\n"
837 " InputData.TexCoord = Covellite_VertexTexCoord;\r\n"
838 " InputData.Extra = Covellite_VertexExtra;\r\n"
839 " PixelValue = " + _Entry +
"(InputData);\r\n"
840 " gl_Position = PixelValue.ScreenPos;\r\n"
843 using namespace ::testing;
847 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
849 .WillOnce(Return(ShaderId));
851 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
854 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
857 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
859 .WillOnce(Return(GL_TRUE));
861 auto Render = itCreator->second(_pShader);
862 ASSERT_NE(
nullptr, Render);
866 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
871 const auto pShader = Component_t::Make(
873 { uT(
"entry"), uT(
"vs1") },
874 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
877 TestCall(pShader,
"vs1");
881 const auto pData = Component_t::Make(
883 { uT(
"kind"), uT(
"Shader") },
884 { uT(
"entry"), uT(
"vs2") },
885 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
888 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"vs2");
893TEST_F(OpenGLShader_test, Test_Shader_CreateVertex_Instance_InvalidValue)
895 const ::std::string ShaderData =
896 "Pixel vs1(Vertex _Value)\r\n"
897 "Pixel vs2(Vertex _Value)\r\n";
899 using GLProxy_t = ::mock::GLProxy;
901 GLProxy_t::GetInstance() = &GLProxy;
903 const Tested_t Example{ Data_t{} };
904 const ITested_t & IExample = Example;
906 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
907 ASSERT_NE(IExample.GetCreators().end(), itCreator);
909 using namespace ::testing;
911 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader)
913 EXPECT_CALL(GLProxy, CompileShader(_))
916 EXPECT_THROW(itCreator->second(_pShader), ::std::exception);
920 const auto pShader = Component_t::Make(
922 { uT(
"entry"), uT(
"vs1") },
923 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
924 { uT(
"instance"), uT(
"invalid1909231417") },
931 const auto pData = Component_t::Make(
933 { uT(
"kind"), uT(
"Shader") },
934 { uT(
"entry"), uT(
"vs2") },
935 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
936 { uT(
"instance"), uT(
"invalid1909231418") },
939 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
944TEST_F(OpenGLShader_test, Test_Shader_CreateVertex_Instance)
946 const ::std::string ShaderData =
947 "Pixel vs1(Vertex _Value)\r\n"
948 "Pixel vs2(Vertex _Value)\r\n";
950 using GLProxy_t = ::mock::GLProxy;
952 GLProxy_t::GetInstance() = &GLProxy;
954 const Tested_t Example{ Data_t{} };
955 const ITested_t & IExample = Example;
957 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
958 ASSERT_NE(IExample.GetCreators().end(), itCreator);
960 const ::mock::GLuint ShaderId = 1908250832;
962 auto InputData = ConvertTextShader(::Input);
964 ::boost::algorithm::replace_first(InputData,
965 "/* place for instance variables */", ::std::string{} +
966 "COVELLITE_IN float4 iValue1 COVELLITE_INPUT_SEMANTIC(TEXCOORD1);" + (char)0x5C +
"\r\n"
967 "COVELLITE_IN float4 iValue2 COVELLITE_INPUT_SEMANTIC(TEXCOORD2);" + (char)0x5C +
"\r\n"
968 "COVELLITE_IN int4 iValue3 COVELLITE_INPUT_SEMANTIC(TEXCOORD3);" + (char)0x5C +
"\r\n"
969 "COVELLITE_IN float4 iValue4 COVELLITE_INPUT_SEMANTIC(TEXCOORD4);" + (char)0x5C +
"\r\n"
972 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
973 const ::std::string & _Entry)
975 using namespace ::alicorn::extension::std;
977 const auto ExpectedShaderText =
979 "#define COVELLITE_SHADER_GLSL\r\n"
980 "#define COVELLITE_SHADER_VERTEX\r\n" +
981 ConvertTextShader(::Predefined + ::Data) + InputData + ShaderData +
982 "out Pixel PixelValue;\r\n"
985 " Vertex InputData;\r\n"
986 " InputData.Position = Covellite_VertexPosition;\r\n"
987 " InputData.TexCoord = Covellite_VertexTexCoord;\r\n"
988 " InputData.Extra = Covellite_VertexExtra;\r\n"
989 " InputData.iValue1 = iValue1;\r\n"
990 " InputData.iValue2 = iValue2;\r\n"
991 " InputData.iValue3 = iValue3;\r\n"
992 " InputData.iValue4 = iValue4;\r\n"
993 " PixelValue = " + _Entry +
"(InputData);\r\n"
994 " gl_Position = PixelValue.ScreenPos;\r\n"
997 using namespace ::testing;
1001 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
1003 .WillOnce(Return(ShaderId));
1005 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
1008 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1011 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1013 .WillOnce(Return(GL_TRUE));
1015 auto Render = itCreator->second(_pShader);
1016 ASSERT_NE(
nullptr, Render);
1020 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1025 const auto pShader = Component_t::Make(
1027 { uT(
"entry"), uT(
"vs1") },
1028 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1029 { uT(
"instance"), uT(
"f4f4i4f4") },
1032 TestCall(pShader,
"vs1");
1036 const auto pData = Component_t::Make(
1038 { uT(
"kind"), uT(
"Shader") },
1039 { uT(
"entry"), uT(
"vs2") },
1040 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1041 { uT(
"instance"), uT(
"f4f4i4f4") },
1044 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"vs2");
1049TEST_F(OpenGLShader_test, Test_Shader_CreatePixel_Default)
1051 using GLProxy_t = ::mock::GLProxy;
1053 GLProxy_t::GetInstance() = &GLProxy;
1055 const Tested_t Example{ Data_t{} };
1056 const ITested_t & IExample = Example;
1058 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1059 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1061 const ::mock::GLuint ShaderId = 1908250832;
1063 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
1064 const ::std::string & _Entry)
1066 using namespace ::alicorn::extension::std;
1068 const auto ExpectedShaderText =
1070 "#define COVELLITE_SHADER_GLSL\r\n"
1071 "#define COVELLITE_SHADER_PIXEL\r\n" +
1072 ConvertTextShader(::Predefined + ::Data + ::Input + ::Default) +
1073 "in Pixel PixelValue;\r\n"
1074 "out vec4 Covellite_OutPixelColor;\r\n"
1077 " Covellite_OutPixelColor = " + _Entry +
"(PixelValue);\r\n"
1080 using namespace ::testing;
1084 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1086 .WillOnce(Return(ShaderId));
1088 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
1091 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1094 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1096 .WillOnce(Return(GL_TRUE));
1098 auto Render = itCreator->second(_pShader);
1099 ASSERT_NE(
nullptr, Render);
1103 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1108 const auto pShader = Component_t::Make(
1110 { uT(
"entry"), uT(
"psColored") },
1113 TestCall(pShader,
"psColored");
1117 const auto pData = Component_t::Make(
1119 { uT(
"kind"), uT(
"Shader") },
1120 { uT(
"entry"), uT(
"psTextured") },
1123 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"psTextured");
1128TEST_F(OpenGLShader_test, Test_Shader_CreatePixel_SingleTarget)
1130 const ::std::string ShaderData =
1131 "float4 ps1(Pixel _Value)\r\n"
1132 "vec4 ps2_Dummy(Pixel _Value)\r\n"
1133 "vec4 ps2(Pixel _Value)\r\n";
1135 using GLProxy_t = ::mock::GLProxy;
1137 GLProxy_t::GetInstance() = &GLProxy;
1139 const Tested_t Example{ Data_t{} };
1140 const ITested_t & IExample = Example;
1142 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1143 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1145 const ::mock::GLuint ShaderId = 1908250832;
1147 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
1148 const ::std::string & _Entry)
1150 using namespace ::alicorn::extension::std;
1152 const auto ExpectedShaderText =
1154 "#define COVELLITE_SHADER_GLSL\r\n"
1155 "#define COVELLITE_SHADER_PIXEL\r\n" +
1156 ConvertTextShader(::Predefined + ::Data + ::Input) + ShaderData +
1157 "in Pixel PixelValue;\r\n"
1158 "out vec4 Covellite_OutPixelColor;\r\n"
1161 " Covellite_OutPixelColor = " + _Entry +
"(PixelValue);\r\n"
1164 using namespace ::testing;
1168 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1170 .WillOnce(Return(ShaderId));
1172 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
1175 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1178 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1180 .WillOnce(Return(GL_TRUE));
1182 auto Render = itCreator->second(_pShader);
1183 ASSERT_NE(
nullptr, Render);
1187 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1192 const auto pShader = Component_t::Make(
1194 { uT(
"entry"), uT(
"ps1") },
1195 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1198 TestCall(pShader,
"ps1");
1202 const auto pData = Component_t::Make(
1204 { uT(
"kind"), uT(
"Shader") },
1205 { uT(
"entry"), uT(
"ps2") },
1206 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1209 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"ps2");
1214TEST_F(OpenGLShader_test, Test_Shader_CreatePixel_MultiTarget)
1216 const ::std::string ShaderData =
1217 "Multi1910031832 ps(Pixel _Value)\r\n";
1219 using GLProxy_t = ::mock::GLProxy;
1221 GLProxy_t::GetInstance() = &GLProxy;
1223 const Tested_t Example{ Data_t{} };
1224 const ITested_t & IExample = Example;
1226 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1227 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1229 const ::mock::GLuint ShaderId = 1908250832;
1231 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
1232 const ::std::string & _Entry)
1234 using namespace ::alicorn::extension::std;
1236 const auto ExpectedShaderText =
1238 "#define COVELLITE_SHADER_GLSL\r\n"
1239 "#define COVELLITE_SHADER_PIXEL\r\n" +
1240 ConvertTextShader(::Predefined + ::Data + ::Input) + ShaderData +
1241 "in Pixel PixelValue;\r\n"
1244 " Covellite_MultiOutPixelColor = " + _Entry +
"(PixelValue).Target;\r\n"
1247 using namespace ::testing;
1251 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1253 .WillOnce(Return(ShaderId));
1255 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
1258 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1261 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1263 .WillOnce(Return(GL_TRUE));
1265 auto Render = itCreator->second(_pShader);
1266 ASSERT_NE(
nullptr, Render);
1270 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1275 const auto pShader = Component_t::Make(
1277 { uT(
"entry"), uT(
"ps") },
1278 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1281 TestCall(pShader,
"ps");
1285 const auto pData = Component_t::Make(
1287 { uT(
"kind"), uT(
"Shader") },
1288 { uT(
"entry"), uT(
"ps") },
1289 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1292 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"ps");
1297TEST_F(OpenGLShader_test, Test_Shader_CreatePixel_NoReturn)
1299 const ::std::string ShaderData =
1300 "void ps(Pixel _Value)\r\n";
1302 using GLProxy_t = ::mock::GLProxy;
1304 GLProxy_t::GetInstance() = &GLProxy;
1306 const Tested_t Example{ Data_t{} };
1307 const ITested_t & IExample = Example;
1309 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1310 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1312 const ::mock::GLuint ShaderId = 1908250832;
1314 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pShader,
1315 const ::std::string & _Entry)
1317 using namespace ::alicorn::extension::std;
1319 const auto ExpectedShaderText =
1321 "#define COVELLITE_SHADER_GLSL\r\n"
1322 "#define COVELLITE_SHADER_PIXEL\r\n" +
1323 ConvertTextShader(::Predefined + ::Data + ::Input) + ShaderData +
1324 "in Pixel PixelValue;\r\n"
1327 " " + _Entry +
"(PixelValue);\r\n"
1330 using namespace ::testing;
1334 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1336 .WillOnce(Return(ShaderId));
1338 EXPECT_CALL(GLProxy, ShaderSource(ShaderId, 1, ExpectedShaderText,
nullptr))
1341 EXPECT_CALL(GLProxy, CompileShader(ShaderId))
1344 EXPECT_CALL(GLProxy, GetShaderiv(ShaderId, GL_COMPILE_STATUS))
1346 .WillOnce(Return(GL_TRUE));
1348 auto Render = itCreator->second(_pShader);
1349 ASSERT_NE(
nullptr, Render);
1353 EXPECT_CALL(GLProxy, DeleteShader(ShaderId))
1358 const auto pShader = Component_t::Make(
1360 { uT(
"entry"), uT(
"ps") },
1361 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1364 TestCall(pShader,
"ps");
1368 const auto pData = Component_t::Make(
1370 { uT(
"kind"), uT(
"Shader") },
1371 { uT(
"entry"), uT(
"ps") },
1372 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1375 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
"ps");
1380TEST_F(OpenGLShader_test, Test_Shader_UsingProgram_DeleteVertexShader)
1382 const ::std::string ShaderData =
1383 "Pixel vs(Vertex _Value)\r\n"
1384 "float4 ps(Pixel _Value)\r\n";
1386 using GLProxy_t = ::mock::GLProxy;
1388 GLProxy_t::GetInstance() = &GLProxy;
1390 const Tested_t Example{ Data_t{} };
1391 const ITested_t & IExample = Example;
1393 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1394 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1396 const auto pVertexShader0 = Component_t::Make(
1398 { uT(
"entry"), uT(
"vs") },
1399 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1402 const auto pVertexShader1 = Component_t::Make(
1404 { uT(
"entry"), uT(
"vs") },
1405 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1408 const auto pPixelShader0 = Component_t::Make(
1410 { uT(
"entry"), uT(
"ps") },
1411 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1414 const auto pPixelShader1 = Component_t::Make(
1416 { uT(
"entry"), uT(
"ps") },
1417 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1420 const ::mock::GLuint VertexShader0Id = 1908251613;
1421 const ::mock::GLuint VertexShader1Id = 1908251614;
1422 const ::mock::GLuint PixelShader0Id = 1908251615;
1423 const ::mock::GLuint PixelShader1Id = 1908251616;
1425 const ::mock::GLuint Program00Id = 1908251641;
1426 const ::mock::GLuint Program01Id = 1908251652;
1427 const ::mock::GLuint Program10Id = 1908251653;
1428 const ::mock::GLuint Program11Id = 1908251654;
1430 using namespace ::testing;
1432 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1434 .WillOnce(Return(PixelShader0Id))
1435 .WillOnce(Return(PixelShader1Id));
1437 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
1439 .WillOnce(Return(VertexShader0Id))
1440 .WillOnce(Return(VertexShader1Id));
1442 auto PixelShaderRender0 = itCreator->second(pPixelShader0);
1443 ASSERT_NE(
nullptr, PixelShaderRender0);
1445 auto PixelShaderRender1 = itCreator->second(pPixelShader1);
1446 ASSERT_NE(
nullptr, PixelShaderRender1);
1448 auto VertexShaderRender0 = itCreator->second(pVertexShader0);
1449 ASSERT_NE(
nullptr, VertexShaderRender0);
1454 auto VertexShaderRender1 = itCreator->second(pVertexShader1);
1455 ASSERT_NE(
nullptr, VertexShaderRender1);
1457 const auto TestCreateProgram = [&](
1458 const ::mock::GLuint _ProgramId,
1459 const ::mock::GLuint _VertexShaderId,
1460 const ::mock::GLuint _PixelShaderId)
1462 EXPECT_CALL(GLProxy, CreateProgram())
1464 .WillOnce(Return(_ProgramId));
1466 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _VertexShaderId))
1469 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _PixelShaderId))
1472 EXPECT_CALL(GLProxy, LinkProgram(_ProgramId))
1475 EXPECT_CALL(GLProxy, GetProgramiv(_ProgramId, GL_LINK_STATUS))
1477 .WillOnce(Return(GL_TRUE));
1482 EXPECT_CALL(GLProxy, CreateProgram())
1485 VertexShaderRender0();
1487 TestCreateProgram(Program00Id, VertexShader0Id, PixelShader0Id);
1489 EXPECT_CALL(GLProxy, UseProgram(Program00Id))
1492 PixelShaderRender0();
1494 TestCreateProgram(Program10Id, VertexShader1Id, PixelShader0Id);
1496 EXPECT_CALL(GLProxy, UseProgram(Program10Id))
1499 VertexShaderRender1();
1501 TestCreateProgram(Program11Id, VertexShader1Id, PixelShader1Id);
1503 EXPECT_CALL(GLProxy, UseProgram(Program11Id))
1506 PixelShaderRender1();
1508 TestCreateProgram(Program01Id, VertexShader0Id, PixelShader1Id);
1510 EXPECT_CALL(GLProxy, UseProgram(Program01Id))
1513 VertexShaderRender0();
1517 EXPECT_CALL(GLProxy, CreateProgram())
1520 EXPECT_CALL(GLProxy, UseProgram(Program00Id))
1523 PixelShaderRender0();
1525 EXPECT_CALL(GLProxy, CreateProgram())
1528 EXPECT_CALL(GLProxy, UseProgram(Program10Id))
1531 VertexShaderRender1();
1533 EXPECT_CALL(GLProxy, CreateProgram())
1536 EXPECT_CALL(GLProxy, UseProgram(Program11Id))
1539 PixelShaderRender1();
1541 EXPECT_CALL(GLProxy, CreateProgram())
1544 EXPECT_CALL(GLProxy, UseProgram(Program01Id))
1547 VertexShaderRender0();
1549 EXPECT_CALL(GLProxy, DeleteProgram(Program10Id))
1552 EXPECT_CALL(GLProxy, DeleteProgram(Program11Id))
1555 EXPECT_CALL(GLProxy, DeleteShader(VertexShader1Id))
1559 EXPECT_CALL(GLProxy, DeleteProgram(Program00Id))
1562 EXPECT_CALL(GLProxy, DeleteProgram(Program01Id))
1565 EXPECT_CALL(GLProxy, DeleteShader(VertexShader0Id))
1568 EXPECT_CALL(GLProxy, DeleteShader(PixelShader1Id))
1571 EXPECT_CALL(GLProxy, DeleteShader(PixelShader0Id))
1576TEST_F(OpenGLShader_test, Test_Shader_UsingProgram_DeletePixelShader)
1578 const ::std::string ShaderData =
1579 "Pixel vs(Vertex _Value)\r\n"
1580 "float4 ps(Pixel _Value)\r\n";
1582 using GLProxy_t = ::mock::GLProxy;
1584 GLProxy_t::GetInstance() = &GLProxy;
1586 const Tested_t Example{ Data_t{} };
1587 const ITested_t & IExample = Example;
1589 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1590 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1592 const auto pVertexShader0 = Component_t::Make(
1594 { uT(
"entry"), uT(
"vs") },
1595 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1598 const auto pVertexShader1 = Component_t::Make(
1600 { uT(
"entry"), uT(
"vs") },
1601 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1604 const auto pPixelShader0 = Component_t::Make(
1606 { uT(
"entry"), uT(
"ps") },
1607 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1610 const auto pPixelShader1 = Component_t::Make(
1612 { uT(
"entry"), uT(
"ps") },
1613 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1616 const ::mock::GLuint VertexShader0Id = 1908251613;
1617 const ::mock::GLuint VertexShader1Id = 1908251614;
1618 const ::mock::GLuint PixelShader0Id = 1908251615;
1619 const ::mock::GLuint PixelShader1Id = 1908251616;
1621 const ::mock::GLuint Program00Id = 1908251641;
1622 const ::mock::GLuint Program01Id = 1908251652;
1623 const ::mock::GLuint Program10Id = 1908251653;
1624 const ::mock::GLuint Program11Id = 1908251654;
1626 using namespace ::testing;
1628 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
1630 .WillOnce(Return(VertexShader0Id))
1631 .WillOnce(Return(VertexShader1Id));
1633 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1635 .WillOnce(Return(PixelShader0Id))
1636 .WillOnce(Return(PixelShader1Id));
1638 auto VertexShaderRender0 = itCreator->second(pVertexShader0);
1639 ASSERT_NE(
nullptr, VertexShaderRender0);
1641 auto VertexShaderRender1 = itCreator->second(pVertexShader1);
1642 ASSERT_NE(
nullptr, VertexShaderRender1);
1644 auto PixelShaderRender0 = itCreator->second(pPixelShader0);
1645 ASSERT_NE(
nullptr, PixelShaderRender0);
1650 auto PixelShaderRender1 = itCreator->second(pPixelShader1);
1651 ASSERT_NE(
nullptr, PixelShaderRender1);
1653 const auto TestCreateProgram = [&](
1654 const ::mock::GLuint _ProgramId,
1655 const ::mock::GLuint _VertexShaderId,
1656 const ::mock::GLuint _PixelShaderId)
1658 EXPECT_CALL(GLProxy, CreateProgram())
1660 .WillOnce(Return(_ProgramId));
1662 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _VertexShaderId))
1665 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _PixelShaderId))
1668 EXPECT_CALL(GLProxy, LinkProgram(_ProgramId))
1671 EXPECT_CALL(GLProxy, GetProgramiv(_ProgramId, GL_LINK_STATUS))
1673 .WillOnce(Return(GL_TRUE));
1678 EXPECT_CALL(GLProxy, CreateProgram())
1681 VertexShaderRender0();
1683 TestCreateProgram(Program00Id, VertexShader0Id, PixelShader0Id);
1685 EXPECT_CALL(GLProxy, UseProgram(Program00Id))
1688 PixelShaderRender0();
1690 TestCreateProgram(Program10Id, VertexShader1Id, PixelShader0Id);
1692 EXPECT_CALL(GLProxy, UseProgram(Program10Id))
1695 VertexShaderRender1();
1697 TestCreateProgram(Program11Id, VertexShader1Id, PixelShader1Id);
1699 EXPECT_CALL(GLProxy, UseProgram(Program11Id))
1702 PixelShaderRender1();
1704 TestCreateProgram(Program01Id, VertexShader0Id, PixelShader1Id);
1706 EXPECT_CALL(GLProxy, UseProgram(Program01Id))
1709 VertexShaderRender0();
1713 EXPECT_CALL(GLProxy, CreateProgram())
1716 EXPECT_CALL(GLProxy, UseProgram(Program00Id))
1719 PixelShaderRender0();
1721 EXPECT_CALL(GLProxy, CreateProgram())
1724 EXPECT_CALL(GLProxy, UseProgram(Program10Id))
1727 VertexShaderRender1();
1729 EXPECT_CALL(GLProxy, CreateProgram())
1732 EXPECT_CALL(GLProxy, UseProgram(Program11Id))
1735 PixelShaderRender1();
1737 EXPECT_CALL(GLProxy, CreateProgram())
1740 EXPECT_CALL(GLProxy, UseProgram(Program01Id))
1743 VertexShaderRender0();
1745 EXPECT_CALL(GLProxy, DeleteProgram(Program01Id))
1748 EXPECT_CALL(GLProxy, DeleteProgram(Program11Id))
1751 EXPECT_CALL(GLProxy, DeleteShader(PixelShader1Id))
1755 EXPECT_CALL(GLProxy, DeleteProgram(Program00Id))
1758 EXPECT_CALL(GLProxy, DeleteProgram(Program10Id))
1761 EXPECT_CALL(GLProxy, DeleteShader(PixelShader0Id))
1764 EXPECT_CALL(GLProxy, DeleteShader(VertexShader1Id))
1767 EXPECT_CALL(GLProxy, DeleteShader(VertexShader0Id))
1772TEST_F(OpenGLShader_test, Test_Shader_UsingProgram_LinkProgramFail)
1774 const ::std::string ShaderData =
1775 "Pixel vs(Vertex _Value)\r\n"
1776 "float4 ps(Pixel _Value)\r\n";
1778 const ::std::string ErrorText =
"Error1908291952";
1780 using GLProxy_t = ::mock::GLProxy;
1782 GLProxy_t::GetInstance() = &GLProxy;
1784 const Tested_t Example{ Data_t{} };
1785 const ITested_t & IExample = Example;
1787 auto itCreator = IExample.GetCreators().find(uT(
"Shader"));
1788 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1790 const auto pVertexShader0 = Component_t::Make(
1792 { uT(
"entry"), uT(
"vs") },
1793 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1796 const auto pVertexShader1 = Component_t::Make(
1798 { uT(
"entry"), uT(
"vs") },
1799 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1802 const auto pPixelShader0 = Component_t::Make(
1804 { uT(
"entry"), uT(
"ps") },
1805 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1808 const auto pPixelShader1 = Component_t::Make(
1810 { uT(
"entry"), uT(
"ps") },
1811 { uT(
"content"), ::std::vector<uint8_t>{ ShaderData.begin(), ShaderData.end() } },
1814 const ::mock::GLuint VertexShader0Id = 1908251613;
1815 const ::mock::GLuint VertexShader1Id = 1908251614;
1816 const ::mock::GLuint PixelShader0Id = 1908251615;
1817 const ::mock::GLuint PixelShader1Id = 1908251616;
1819 const ::mock::GLuint Program00Id = 1908251641;
1820 const ::mock::GLuint Program01Id = 1908251652;
1821 const ::mock::GLuint Program10Id = 1908251653;
1822 const ::mock::GLuint Program11Id = 1908251654;
1824 using namespace ::testing;
1826 EXPECT_CALL(GLProxy, CreateShader(GL_VERTEX_SHADER))
1828 .WillOnce(Return(VertexShader0Id))
1829 .WillOnce(Return(VertexShader1Id));
1831 EXPECT_CALL(GLProxy, CreateShader(GL_FRAGMENT_SHADER))
1833 .WillOnce(Return(PixelShader0Id))
1834 .WillOnce(Return(PixelShader1Id));
1836 auto VertexShaderRender0 = itCreator->second(pVertexShader0);
1837 ASSERT_NE(
nullptr, VertexShaderRender0);
1839 auto VertexShaderRender1 = itCreator->second(pVertexShader1);
1840 ASSERT_NE(
nullptr, VertexShaderRender1);
1842 auto PixelShaderRender0 = itCreator->second(pPixelShader0);
1843 ASSERT_NE(
nullptr, PixelShaderRender0);
1848 auto PixelShaderRender1 = itCreator->second(pPixelShader1);
1849 ASSERT_NE(
nullptr, PixelShaderRender1);
1851 const auto TestCreateProgram = [&](
1852 const ::mock::GLuint _ProgramId,
1853 const ::mock::GLuint _VertexShaderId,
1854 const ::mock::GLuint _PixelShaderId,
1855 const Render_t & _Render)
1857 EXPECT_CALL(GLProxy, CreateProgram())
1859 .WillOnce(Return(_ProgramId));
1861 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _VertexShaderId))
1864 EXPECT_CALL(GLProxy, AttachShader(_ProgramId, _PixelShaderId))
1867 EXPECT_CALL(GLProxy, LinkProgram(_ProgramId))
1870 EXPECT_CALL(GLProxy, GetProgramiv(_ProgramId, GL_LINK_STATUS))
1872 .WillOnce(Return(GL_FALSE));
1874 EXPECT_CALL(GLProxy, GetProgramInfoLog(_ProgramId, 512,
nullptr))
1876 .WillOnce(Return(ErrorText.c_str()));
1878 EXPECT_STDEXCEPTION(_Render(),
1879 (
".*Link program fail: " + ErrorText).c_str());
1882 EXPECT_CALL(GLProxy, CreateProgram())
1885 EXPECT_CALL(GLProxy, UseProgram(_))
1888 VertexShaderRender0();
1890 TestCreateProgram(Program00Id, VertexShader0Id, PixelShader0Id,
1891 PixelShaderRender0);
1893 TestCreateProgram(Program10Id, VertexShader1Id, PixelShader0Id,
1894 VertexShaderRender1);
1896 TestCreateProgram(Program11Id, VertexShader1Id, PixelShader1Id,
1897 PixelShaderRender1);
1899 TestCreateProgram(Program01Id, VertexShader0Id, PixelShader1Id,
1900 VertexShaderRender0);
1902 EXPECT_CALL(GLProxy, DeleteProgram(Program01Id))
1905 EXPECT_CALL(GLProxy, DeleteProgram(Program11Id))
1909 EXPECT_CALL(GLProxy, DeleteProgram(Program00Id))
1912 EXPECT_CALL(GLProxy, DeleteProgram(Program10Id))
1917TEST_F(OpenGLShader_test, Test_Texture_Default)
1919 using GLProxy_t = ::mock::GLProxy;
1921 GLProxy_t::GetInstance() = &GLProxy;
1923 const Tested_t Example{ Data_t{} };
1924 const ITested_t & IExample = Example;
1926 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
1927 ASSERT_NE(IExample.GetCreators().end(), itCreator);
1929 const ::mock::GLuint TextureId = 1812181809;
1930 const ::mock::GLint ProgramId = 1908221258;
1931 const ::mock::GLint LocationId = 1908221259;
1933 const auto TestCall = [&](
const Component_t::ComponentPtr_t & _pTexture,
1934 const ::std::vector<uint8_t> & _Source,
const int _Width,
const int _Height)
1936 using namespace ::testing;
1940 EXPECT_CALL(GLProxy, GenTextures(1))
1942 .WillOnce(Return(TextureId));
1944 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
1947 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
1949 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
1952 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
1955 EXPECT_CALL(GLProxy, GetError())
1957 .WillOnce(Return(GL_NO_ERROR));
1959 auto Render = itCreator->second(_pTexture);
1960 ASSERT_NE(
nullptr, Render);
1962 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0))
1965 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
1968 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
1970 .WillOnce(Return(&ProgramId));
1972 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"TexDiffuse")))
1974 .WillOnce(Return(LocationId));
1976 EXPECT_CALL(GLProxy, Uniform1i(LocationId, 0))
1981 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
1986 ::std::vector<uint8_t> Source =
1988 0x20, 0x06, 0x15, 0x12, 0x28,
1989 0x20, 0x06, 0x15, 0x12, 0x28,
1990 0x20, 0x06, 0x15, 0x12, 0x28,
1991 0x20, 0x06, 0x15, 0x12, 0x28,
1992 0x20, 0x06, 0x15, 0x12, 0x28,
1993 0x20, 0x06, 0x15, 0x12, 0x28,
1994 0x20, 0x06, 0x15, 0x12, 0x28,
1995 0x20, 0x06, 0x15, 0x12, 0x28,
1997 IntroduceBufferSize(Source);
1999 const int Width = 1812181807;
2000 const int Height = 1812181808;
2002 const auto pTexture = Component_t::Make(
2004 { uT(
"content"), Source },
2005 { uT(
"width"), Width },
2006 { uT(
"height"), Height },
2009 TestCall(pTexture, Source, Width, Height);
2013 ::std::vector<uint8_t> Source =
2015 0x20, 0x06, 0x15, 0x12, 0x29,
2016 0x20, 0x06, 0x15, 0x12, 0x29,
2017 0x20, 0x06, 0x15, 0x12, 0x29,
2018 0x20, 0x06, 0x15, 0x12, 0x29,
2019 0x20, 0x06, 0x15, 0x12, 0x29,
2021 IntroduceBufferSize(Source);
2023 const int Width = 1907251057;
2024 const int Height = 1907251058;
2026 const auto pData = Component_t::Make(
2028 { uT(
"kind"), uT(
"Texture") },
2029 { uT(
"content"), Source },
2030 { uT(
"width"), Width },
2031 { uT(
"height"), Height },
2034 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }), Source, Width, Height);
2039TEST_F(OpenGLShader_test, Test_Texture_NameAndIndex)
2041 using GLProxy_t = ::mock::GLProxy;
2043 GLProxy_t::GetInstance() = &GLProxy;
2045 const Tested_t Example{ Data_t{} };
2046 const ITested_t & IExample = Example;
2048 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
2049 ASSERT_NE(IExample.GetCreators().end(), itCreator);
2051 const ::mock::GLuint TextureId = 1908221839;
2052 const ::mock::GLint ProgramId = 1908221840;
2053 const ::mock::GLint LocationId = 1908221841;
2055 const auto TestCall = [&](
2056 const Component_t::ComponentPtr_t & _pTexture,
2057 const ::std::vector<uint8_t> & _Source,
2058 const int _Width,
const int _Height,
2059 const ::std::size_t _Index,
2060 const ::std::string & _TexName)
2062 const auto Index =
static_cast<::mock::GLint
>(_Index);
2064 using namespace ::testing;
2068 EXPECT_CALL(GLProxy, GenTextures(1))
2070 .WillOnce(Return(TextureId));
2072 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2075 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
2077 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
2080 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2083 EXPECT_CALL(GLProxy, GetError())
2085 .WillOnce(Return(GL_NO_ERROR));
2087 EXPECT_CALL(GLProxy, GenFramebuffers(1))
2090 auto Render = itCreator->second(_pTexture);
2091 ASSERT_NE(
nullptr, Render);
2093 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
2096 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2099 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2101 .WillOnce(Return(&ProgramId));
2103 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
2105 .WillOnce(Return(LocationId));
2107 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
2110 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
2115 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
2119 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
2121 { uT(
"TexEnvironment"),
"TexEnvironment" },
2122 { uT(
"TexReflection"),
"TexReflection" },
2123 { uT(
"TexBaseColor"),
"TexBaseColor" },
2126 for (
int Index = 0; Index < Names.size(); Index++)
2128 ::std::vector<uint8_t> Source =
2130 0x20, 0x06, 0x15, 0x12, 0x30,
2131 0x20, 0x06, 0x15, 0x12, 0x30,
2132 0x20, 0x06, 0x15, 0x12, 0x30,
2133 0x20, 0x06, 0x15, 0x12, 0x30,
2134 0x20, 0x06, 0x15, 0x12, 0x30,
2136 IntroduceBufferSize(Source);
2139 const int Width = 1908221843;
2140 const int Height = 1908221844;
2142 const auto pTexture = Component_t::Make(
2144 { uT(
"content"), Source },
2145 { uT(
"width"), Width },
2146 { uT(
"height"), Height },
2147 { uT(
"name"), Names[Index].first },
2148 { uT(
"index"), Index },
2152 Source, Width, Height, Index, Names[Index].second);
2156 const int Width = 1908221845;
2157 const int Height = 1908221847;
2159 const auto pData = Component_t::Make(
2161 { uT(
"kind"), uT(
"Texture") },
2162 { uT(
"content"), Source },
2163 { uT(
"width"), Width },
2164 { uT(
"height"), Height },
2165 { uT(
"name"), Names[Index].first },
2166 { uT(
"index"), Index },
2169 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2170 Source, Width, Height, Index, Names[Index].second);
2174 const int Width = 1908221843;
2175 const int Height = 1908221844;
2177 const auto pTexture = Component_t::Make(
2179 { uT(
"content"), Source },
2180 { uT(
"width"), Width },
2181 { uT(
"height"), Height },
2182 { uT(
"name"), Names[Index].first },
2183 { uT(
"index"), Index },
2184 { uT(
"mipmapping"),
false },
2188 Source, Width, Height, Index, Names[Index].second);
2192 const int Width = 1908221845;
2193 const int Height = 1908221847;
2195 const auto pData = Component_t::Make(
2197 { uT(
"kind"), uT(
"Texture") },
2198 { uT(
"content"), Source },
2199 { uT(
"width"), Width },
2200 { uT(
"height"), Height },
2201 { uT(
"name"), Names[Index].first },
2202 { uT(
"index"), Index },
2203 { uT(
"mipmapping"),
false },
2206 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2207 Source, Width, Height, Index, Names[Index].second);
2210 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
2212 { uT(
"albedo"),
"TexAlbedo" },
2213 { uT(
"metalness"),
"TexMetalness" },
2214 { uT(
"roughness"),
"TexRoughness" },
2215 { uT(
"normal"),
"TexNormal" },
2216 { uT(
"occlusion"),
"TexOcclusion" },
2220 for (::std::size_t i = 0; i < Destinations.size(); i++)
2223 const int Width = 1908221843;
2224 const int Height = 1908221844;
2226 const auto pTexture = Component_t::Make(
2228 { uT(
"content"), Source },
2229 { uT(
"width"), Width },
2230 { uT(
"height"), Height },
2231 { uT(
"name"), Names[Index].first },
2232 { uT(
"index"), Index },
2233 { uT(
"destination"), Destinations[i].first },
2237 Source, Width, Height, Index, Names[Index].second);
2241 const int Width = 1908221845;
2242 const int Height = 1908221847;
2244 const auto pData = Component_t::Make(
2246 { uT(
"kind"), uT(
"Texture") },
2247 { uT(
"content"), Source },
2248 { uT(
"width"), Width },
2249 { uT(
"height"), Height },
2250 { uT(
"name"), Names[Index].first },
2251 { uT(
"index"), Index },
2252 { uT(
"destination"), Destinations[i].first },
2255 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2256 Source, Width, Height, Index, Names[Index].second);
2260 const int Width = 1908221843;
2261 const int Height = 1908221844;
2263 const auto pTexture = Component_t::Make(
2265 { uT(
"content"), Source },
2266 { uT(
"width"), Width },
2267 { uT(
"height"), Height },
2268 { uT(
"name"), Names[Index].first },
2269 { uT(
"index"), Index },
2270 { uT(
"destination"), Destinations[i].first },
2271 { uT(
"mipmapping"),
false },
2275 Source, Width, Height, Index, Names[Index].second);
2279 const int Width = 1908221845;
2280 const int Height = 1908221847;
2282 const auto pData = Component_t::Make(
2284 { uT(
"kind"), uT(
"Texture") },
2285 { uT(
"content"), Source },
2286 { uT(
"width"), Width },
2287 { uT(
"height"), Height },
2288 { uT(
"name"), Names[Index].first },
2289 { uT(
"index"), Index },
2290 { uT(
"destination"), Destinations[i].first },
2291 { uT(
"mipmapping"),
false },
2294 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2295 Source, Width, Height, Index, Names[Index].second);
2302TEST_F(OpenGLShader_test, Test_Texture_NameAndIndex_Capacity16)
2304 using GLProxy_t = ::mock::GLProxy;
2306 GLProxy_t::GetInstance() = &GLProxy;
2308 const Tested_t Example{ Data_t{} };
2309 const ITested_t & IExample = Example;
2311 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
2312 ASSERT_NE(IExample.GetCreators().end(), itCreator);
2314 const ::mock::GLuint TextureId = 1908221839;
2315 const ::mock::GLint ProgramId = 1908221840;
2316 const ::mock::GLint LocationId = 1908221841;
2318 const auto TestCall = [&](
2319 const Component_t::ComponentPtr_t & _pTexture,
2320 const ::std::vector<uint8_t> & _Source,
2321 const int _Width,
const int _Height,
2322 const ::std::size_t _Index,
2323 const ::std::string & _TexName)
2325 const auto Index =
static_cast<::mock::GLint
>(_Index);
2327 using namespace ::testing;
2331 EXPECT_CALL(GLProxy, GenTextures(1))
2333 .WillOnce(Return(TextureId));
2335 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2338 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
2340 GL_RGBA, GL_HALF_FLOAT, _Source))
2343 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2346 EXPECT_CALL(GLProxy, GetError())
2348 .WillOnce(Return(GL_NO_ERROR));
2350 EXPECT_CALL(GLProxy, GenFramebuffers(1))
2353 auto Render = itCreator->second(_pTexture);
2354 ASSERT_NE(
nullptr, Render);
2356 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
2359 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2362 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2364 .WillOnce(Return(&ProgramId));
2366 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
2368 .WillOnce(Return(LocationId));
2370 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
2373 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
2378 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
2382 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
2384 { uT(
"TexEnvironment"),
"TexEnvironment" },
2385 { uT(
"TexReflection"),
"TexReflection" },
2386 { uT(
"TexBaseColor"),
"TexBaseColor" },
2389 for (
int Index = 0; Index < Names.size(); Index++)
2391 ::std::vector<uint8_t> Source =
2393 0x20, 0x06, 0x15, 0x12, 0x30,
2394 0x20, 0x06, 0x15, 0x12, 0x30,
2395 0x20, 0x06, 0x15, 0x12, 0x30,
2396 0x20, 0x06, 0x15, 0x12, 0x30,
2397 0x20, 0x06, 0x15, 0x12, 0x30,
2399 IntroduceBufferSize(Source);
2402 const int Width = 1908221843;
2403 const int Height = 1908221844;
2405 const auto pTexture = Component_t::Make(
2407 { uT(
"content"), Source },
2408 { uT(
"width"), Width },
2409 { uT(
"height"), Height },
2410 { uT(
"name"), Names[Index].first },
2411 { uT(
"index"), Index },
2412 { uT(
"capacity"), 16 },
2416 Source, Width, Height, Index, Names[Index].second);
2420 const int Width = 1908221845;
2421 const int Height = 1908221847;
2423 const auto pData = Component_t::Make(
2425 { uT(
"kind"), uT(
"Texture") },
2426 { uT(
"content"), Source },
2427 { uT(
"width"), Width },
2428 { uT(
"height"), Height },
2429 { uT(
"name"), Names[Index].first },
2430 { uT(
"index"), Index },
2431 { uT(
"capacity"), 16 },
2434 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2435 Source, Width, Height, Index, Names[Index].second);
2439 const int Width = 1908221843;
2440 const int Height = 1908221844;
2442 const auto pTexture = Component_t::Make(
2444 { uT(
"content"), Source },
2445 { uT(
"width"), Width },
2446 { uT(
"height"), Height },
2447 { uT(
"name"), Names[Index].first },
2448 { uT(
"index"), Index },
2449 { uT(
"mipmapping"),
false },
2450 { uT(
"capacity"), 16 },
2454 Source, Width, Height, Index, Names[Index].second);
2458 const int Width = 1908221845;
2459 const int Height = 1908221847;
2461 const auto pData = Component_t::Make(
2463 { uT(
"kind"), uT(
"Texture") },
2464 { uT(
"content"), Source },
2465 { uT(
"width"), Width },
2466 { uT(
"height"), Height },
2467 { uT(
"name"), Names[Index].first },
2468 { uT(
"index"), Index },
2469 { uT(
"mipmapping"),
false },
2470 { uT(
"capacity"), 16 },
2473 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2474 Source, Width, Height, Index, Names[Index].second);
2477 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
2479 { uT(
"albedo"),
"TexAlbedo" },
2480 { uT(
"metalness"),
"TexMetalness" },
2481 { uT(
"roughness"),
"TexRoughness" },
2482 { uT(
"normal"),
"TexNormal" },
2483 { uT(
"occlusion"),
"TexOcclusion" },
2487 for (::std::size_t i = 0; i < Destinations.size(); i++)
2490 const int Width = 1908221843;
2491 const int Height = 1908221844;
2493 const auto pTexture = Component_t::Make(
2495 { uT(
"content"), Source },
2496 { uT(
"width"), Width },
2497 { uT(
"height"), Height },
2498 { uT(
"name"), Names[Index].first },
2499 { uT(
"index"), Index },
2500 { uT(
"destination"), Destinations[i].first },
2501 { uT(
"capacity"), 16 },
2505 Source, Width, Height, Index, Names[Index].second);
2509 const int Width = 1908221845;
2510 const int Height = 1908221847;
2512 const auto pData = Component_t::Make(
2514 { uT(
"kind"), uT(
"Texture") },
2515 { uT(
"content"), Source },
2516 { uT(
"width"), Width },
2517 { uT(
"height"), Height },
2518 { uT(
"name"), Names[Index].first },
2519 { uT(
"index"), Index },
2520 { uT(
"destination"), Destinations[i].first },
2521 { uT(
"capacity"), 16 },
2524 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2525 Source, Width, Height, Index, Names[Index].second);
2529 const int Width = 1908221843;
2530 const int Height = 1908221844;
2532 const auto pTexture = Component_t::Make(
2534 { uT(
"content"), Source },
2535 { uT(
"width"), Width },
2536 { uT(
"height"), Height },
2537 { uT(
"name"), Names[Index].first },
2538 { uT(
"index"), Index },
2539 { uT(
"destination"), Destinations[i].first },
2540 { uT(
"mipmapping"),
false },
2541 { uT(
"capacity"), 16 },
2545 Source, Width, Height, Index, Names[Index].second);
2549 const int Width = 1908221845;
2550 const int Height = 1908221847;
2552 const auto pData = Component_t::Make(
2554 { uT(
"kind"), uT(
"Texture") },
2555 { uT(
"content"), Source },
2556 { uT(
"width"), Width },
2557 { uT(
"height"), Height },
2558 { uT(
"name"), Names[Index].first },
2559 { uT(
"index"), Index },
2560 { uT(
"destination"), Destinations[i].first },
2561 { uT(
"mipmapping"),
false },
2562 { uT(
"capacity"), 16 },
2565 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2566 Source, Width, Height, Index, Names[Index].second);
2573TEST_F(OpenGLShader_test, Test_Texture_NameAndIndex_Capacity32)
2575 using GLProxy_t = ::mock::GLProxy;
2577 GLProxy_t::GetInstance() = &GLProxy;
2579 const Tested_t Example{ Data_t{} };
2580 const ITested_t & IExample = Example;
2582 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
2583 ASSERT_NE(IExample.GetCreators().end(), itCreator);
2585 const ::mock::GLuint TextureId = 1908221839;
2586 const ::mock::GLint ProgramId = 1908221840;
2587 const ::mock::GLint LocationId = 1908221841;
2589 const auto TestCall = [&](
2590 const Component_t::ComponentPtr_t & _pTexture,
2591 const ::std::vector<uint8_t> & _Source,
2592 const int _Width,
const int _Height,
2593 const ::std::size_t _Index,
2594 const ::std::string & _TexName)
2596 const auto Index =
static_cast<::mock::GLint
>(_Index);
2598 using namespace ::testing;
2602 EXPECT_CALL(GLProxy, GenTextures(1))
2604 .WillOnce(Return(TextureId));
2606 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2609 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
2611 GL_RGBA, GL_FLOAT, _Source))
2614 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2617 EXPECT_CALL(GLProxy, GetError())
2619 .WillOnce(Return(GL_NO_ERROR));
2621 EXPECT_CALL(GLProxy, GenFramebuffers(1))
2624 auto Render = itCreator->second(_pTexture);
2625 ASSERT_NE(
nullptr, Render);
2627 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
2630 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2633 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2635 .WillOnce(Return(&ProgramId));
2637 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
2639 .WillOnce(Return(LocationId));
2641 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
2644 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
2649 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
2653 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
2655 { uT(
"TexEnvironment"),
"TexEnvironment" },
2656 { uT(
"TexReflection"),
"TexReflection" },
2657 { uT(
"TexBaseColor"),
"TexBaseColor" },
2660 for (
int Index = 0; Index < Names.size(); Index++)
2662 ::std::vector<uint8_t> Source =
2664 0x20, 0x06, 0x15, 0x12, 0x30,
2665 0x20, 0x06, 0x15, 0x12, 0x30,
2666 0x20, 0x06, 0x15, 0x12, 0x30,
2667 0x20, 0x06, 0x15, 0x12, 0x30,
2668 0x20, 0x06, 0x15, 0x12, 0x30,
2670 IntroduceBufferSize(Source);
2673 const int Width = 1908221843;
2674 const int Height = 1908221844;
2676 const auto pTexture = Component_t::Make(
2678 { uT(
"content"), Source },
2679 { uT(
"width"), Width },
2680 { uT(
"height"), Height },
2681 { uT(
"name"), Names[Index].first },
2682 { uT(
"index"), Index },
2683 { uT(
"capacity"), 32 },
2687 Source, Width, Height, Index, Names[Index].second);
2691 const int Width = 1908221845;
2692 const int Height = 1908221847;
2694 const auto pData = Component_t::Make(
2696 { uT(
"kind"), uT(
"Texture") },
2697 { uT(
"content"), Source },
2698 { uT(
"width"), Width },
2699 { uT(
"height"), Height },
2700 { uT(
"name"), Names[Index].first },
2701 { uT(
"index"), Index },
2702 { uT(
"capacity"), 32 },
2705 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2706 Source, Width, Height, Index, Names[Index].second);
2710 const int Width = 1908221843;
2711 const int Height = 1908221844;
2713 const auto pTexture = Component_t::Make(
2715 { uT(
"content"), Source },
2716 { uT(
"width"), Width },
2717 { uT(
"height"), Height },
2718 { uT(
"name"), Names[Index].first },
2719 { uT(
"index"), Index },
2720 { uT(
"mipmapping"),
false },
2721 { uT(
"capacity"), 32 },
2725 Source, Width, Height, Index, Names[Index].second);
2729 const int Width = 1908221845;
2730 const int Height = 1908221847;
2732 const auto pData = Component_t::Make(
2734 { uT(
"kind"), uT(
"Texture") },
2735 { uT(
"content"), Source },
2736 { uT(
"width"), Width },
2737 { uT(
"height"), Height },
2738 { uT(
"name"), Names[Index].first },
2739 { uT(
"index"), Index },
2740 { uT(
"mipmapping"),
false },
2741 { uT(
"capacity"), 32 },
2744 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2745 Source, Width, Height, Index, Names[Index].second);
2748 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
2750 { uT(
"albedo"),
"TexAlbedo" },
2751 { uT(
"metalness"),
"TexMetalness" },
2752 { uT(
"roughness"),
"TexRoughness" },
2753 { uT(
"normal"),
"TexNormal" },
2754 { uT(
"occlusion"),
"TexOcclusion" },
2758 for (::std::size_t i = 0; i < Destinations.size(); i++)
2761 const int Width = 1908221843;
2762 const int Height = 1908221844;
2764 const auto pTexture = Component_t::Make(
2766 { uT(
"content"), Source },
2767 { uT(
"width"), Width },
2768 { uT(
"height"), Height },
2769 { uT(
"name"), Names[Index].first },
2770 { uT(
"index"), Index },
2771 { uT(
"destination"), Destinations[i].first },
2772 { uT(
"capacity"), 32 },
2776 Source, Width, Height, Index, Names[Index].second);
2780 const int Width = 1908221845;
2781 const int Height = 1908221847;
2783 const auto pData = Component_t::Make(
2785 { uT(
"kind"), uT(
"Texture") },
2786 { uT(
"content"), Source },
2787 { uT(
"width"), Width },
2788 { uT(
"height"), Height },
2789 { uT(
"name"), Names[Index].first },
2790 { uT(
"index"), Index },
2791 { uT(
"destination"), Destinations[i].first },
2792 { uT(
"capacity"), 32 },
2795 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2796 Source, Width, Height, Index, Names[Index].second);
2800 const int Width = 1908221843;
2801 const int Height = 1908221844;
2803 const auto pTexture = Component_t::Make(
2805 { uT(
"content"), Source },
2806 { uT(
"width"), Width },
2807 { uT(
"height"), Height },
2808 { uT(
"name"), Names[Index].first },
2809 { uT(
"index"), Index },
2810 { uT(
"destination"), Destinations[i].first },
2811 { uT(
"mipmapping"),
false },
2812 { uT(
"capacity"), 32 },
2816 Source, Width, Height, Index, Names[Index].second);
2820 const int Width = 1908221845;
2821 const int Height = 1908221847;
2823 const auto pData = Component_t::Make(
2825 { uT(
"kind"), uT(
"Texture") },
2826 { uT(
"content"), Source },
2827 { uT(
"width"), Width },
2828 { uT(
"height"), Height },
2829 { uT(
"name"), Names[Index].first },
2830 { uT(
"index"), Index },
2831 { uT(
"destination"), Destinations[i].first },
2832 { uT(
"mipmapping"),
false },
2833 { uT(
"capacity"), 32 },
2836 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2837 Source, Width, Height, Index, Names[Index].second);
2844TEST_F(OpenGLShader_test, Test_Texture_Destination)
2846 using GLProxy_t = ::mock::GLProxy;
2848 GLProxy_t::GetInstance() = &GLProxy;
2850 const Tested_t Example{ Data_t{} };
2851 const ITested_t & IExample = Example;
2853 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
2854 ASSERT_NE(IExample.GetCreators().end(), itCreator);
2856 const ::mock::GLuint TextureId = 1908221839;
2857 const ::mock::GLint ProgramId = 1908221840;
2858 const ::mock::GLint LocationId = 1908221841;
2860 const auto TestCall = [&](
2861 const Component_t::ComponentPtr_t & _pTexture,
2862 const ::std::vector<uint8_t> & _Source,
2863 const int _Width,
const int _Height,
2864 const ::std::size_t _Index,
2865 const ::std::string & _TexName)
2867 const auto Index =
static_cast<::mock::GLint
>(_Index);
2869 using namespace ::testing;
2873 EXPECT_CALL(GLProxy, GenTextures(1))
2875 .WillOnce(Return(TextureId));
2877 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2880 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
2882 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
2885 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
2888 EXPECT_CALL(GLProxy, GetError())
2890 .WillOnce(Return(GL_NO_ERROR));
2892 EXPECT_CALL(GLProxy, GenFramebuffers(1))
2895 auto Render = itCreator->second(_pTexture);
2896 ASSERT_NE(
nullptr, Render);
2898 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
2901 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
2904 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
2906 .WillOnce(Return(&ProgramId));
2908 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
2910 .WillOnce(Return(LocationId));
2912 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
2915 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
2920 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
2924 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
2926 { uT(
"albedo"),
"TexAlbedo" },
2927 { uT(
"metalness"),
"TexMetalness" },
2928 { uT(
"roughness"),
"TexRoughness" },
2929 { uT(
"normal"),
"TexNormal" },
2930 { uT(
"occlusion"),
"TexOcclusion" },
2934 ::std::vector<uint8_t> Source =
2936 0x20, 0x06, 0x15, 0x12, 0x30,
2937 0x20, 0x06, 0x15, 0x12, 0x30,
2938 0x20, 0x06, 0x15, 0x12, 0x30,
2939 0x20, 0x06, 0x15, 0x12, 0x30,
2940 0x20, 0x06, 0x15, 0x12, 0x30,
2942 IntroduceBufferSize(Source);
2944 for (::std::size_t i = 0; i < Destinations.size(); i++)
2947 const int Width = 1908221843;
2948 const int Height = 1908221844;
2950 const auto pTexture = Component_t::Make(
2952 { uT(
"content"), Source },
2953 { uT(
"width"), Width },
2954 { uT(
"height"), Height },
2955 { uT(
"destination"), Destinations[i].first },
2959 Source, Width, Height, i, Destinations[i].second);
2963 const int Width = 1908221845;
2964 const int Height = 1908221847;
2966 const auto pData = Component_t::Make(
2968 { uT(
"kind"), uT(
"Texture") },
2969 { uT(
"content"), Source },
2970 { uT(
"width"), Width },
2971 { uT(
"height"), Height },
2972 { uT(
"destination"), Destinations[i].first },
2975 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
2976 Source, Width, Height, i, Destinations[i].second);
2980 const int Width = 1908221843;
2981 const int Height = 1908221844;
2983 const auto pTexture = Component_t::Make(
2985 { uT(
"content"), Source },
2986 { uT(
"width"), Width },
2987 { uT(
"height"), Height },
2988 { uT(
"destination"), Destinations[i].first },
2989 { uT(
"mipmapping"),
false },
2993 Source, Width, Height, i, Destinations[i].second);
2997 const int Width = 1908221845;
2998 const int Height = 1908221847;
3000 const auto pData = Component_t::Make(
3002 { uT(
"kind"), uT(
"Texture") },
3003 { uT(
"content"), Source },
3004 { uT(
"width"), Width },
3005 { uT(
"height"), Height },
3006 { uT(
"destination"), Destinations[i].first },
3007 { uT(
"mipmapping"),
false },
3010 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3011 Source, Width, Height, i, Destinations[i].second);
3017TEST_F(OpenGLShader_test, Test_Texture_Destination_Capacity16)
3019 using GLProxy_t = ::mock::GLProxy;
3021 GLProxy_t::GetInstance() = &GLProxy;
3023 const Tested_t Example{ Data_t{} };
3024 const ITested_t & IExample = Example;
3026 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
3027 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3029 const ::mock::GLuint TextureId = 1908221839;
3030 const ::mock::GLint ProgramId = 1908221840;
3031 const ::mock::GLint LocationId = 1908221841;
3033 const auto TestCall = [&](
3034 const Component_t::ComponentPtr_t & _pTexture,
3035 const ::std::vector<uint8_t> & _Source,
3036 const int _Width,
const int _Height,
3037 const ::std::size_t _Index,
3038 const ::std::string & _TexName)
3040 const auto Index =
static_cast<::mock::GLint
>(_Index);
3042 using namespace ::testing;
3046 EXPECT_CALL(GLProxy, GenTextures(1))
3048 .WillOnce(Return(TextureId));
3050 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3053 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
3055 GL_RGBA, GL_HALF_FLOAT, _Source))
3058 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3061 EXPECT_CALL(GLProxy, GetError())
3063 .WillOnce(Return(GL_NO_ERROR));
3065 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3068 auto Render = itCreator->second(_pTexture);
3069 ASSERT_NE(
nullptr, Render);
3071 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3074 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3077 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3079 .WillOnce(Return(&ProgramId));
3081 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3083 .WillOnce(Return(LocationId));
3085 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
3088 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3093 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3097 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3099 { uT(
"albedo"),
"TexAlbedo" },
3100 { uT(
"metalness"),
"TexMetalness" },
3101 { uT(
"roughness"),
"TexRoughness" },
3102 { uT(
"normal"),
"TexNormal" },
3103 { uT(
"occlusion"),
"TexOcclusion" },
3107 ::std::vector<uint8_t> Source =
3109 0x20, 0x06, 0x15, 0x12, 0x30,
3110 0x20, 0x06, 0x15, 0x12, 0x30,
3111 0x20, 0x06, 0x15, 0x12, 0x30,
3112 0x20, 0x06, 0x15, 0x12, 0x30,
3113 0x20, 0x06, 0x15, 0x12, 0x30,
3115 IntroduceBufferSize(Source);
3117 for (::std::size_t i = 0; i < Destinations.size(); i++)
3120 const int Width = 1908221843;
3121 const int Height = 1908221844;
3123 const auto pTexture = Component_t::Make(
3125 { uT(
"content"), Source },
3126 { uT(
"width"), Width },
3127 { uT(
"height"), Height },
3128 { uT(
"destination"), Destinations[i].first },
3129 { uT(
"capacity"), 16 },
3133 Source, Width, Height, i, Destinations[i].second);
3137 const int Width = 1908221845;
3138 const int Height = 1908221847;
3140 const auto pData = Component_t::Make(
3142 { uT(
"kind"), uT(
"Texture") },
3143 { uT(
"content"), Source },
3144 { uT(
"width"), Width },
3145 { uT(
"height"), Height },
3146 { uT(
"destination"), Destinations[i].first },
3147 { uT(
"capacity"), 16 },
3150 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3151 Source, Width, Height, i, Destinations[i].second);
3155 const int Width = 1908221843;
3156 const int Height = 1908221844;
3158 const auto pTexture = Component_t::Make(
3160 { uT(
"content"), Source },
3161 { uT(
"width"), Width },
3162 { uT(
"height"), Height },
3163 { uT(
"destination"), Destinations[i].first },
3164 { uT(
"mipmapping"),
false },
3165 { uT(
"capacity"), 16 },
3169 Source, Width, Height, i, Destinations[i].second);
3173 const int Width = 1908221845;
3174 const int Height = 1908221847;
3176 const auto pData = Component_t::Make(
3178 { uT(
"kind"), uT(
"Texture") },
3179 { uT(
"content"), Source },
3180 { uT(
"width"), Width },
3181 { uT(
"height"), Height },
3182 { uT(
"destination"), Destinations[i].first },
3183 { uT(
"mipmapping"),
false },
3184 { uT(
"capacity"), 16 },
3187 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3188 Source, Width, Height, i, Destinations[i].second);
3194TEST_F(OpenGLShader_test, Test_Texture_Destination_Capacity32)
3196 using GLProxy_t = ::mock::GLProxy;
3198 GLProxy_t::GetInstance() = &GLProxy;
3200 const Tested_t Example{ Data_t{} };
3201 const ITested_t & IExample = Example;
3203 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
3204 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3206 const ::mock::GLuint TextureId = 1908221839;
3207 const ::mock::GLint ProgramId = 1908221840;
3208 const ::mock::GLint LocationId = 1908221841;
3210 const auto TestCall = [&](
3211 const Component_t::ComponentPtr_t & _pTexture,
3212 const ::std::vector<uint8_t> & _Source,
3213 const int _Width,
const int _Height,
3214 const ::std::size_t _Index,
3215 const ::std::string & _TexName)
3217 const auto Index =
static_cast<::mock::GLint
>(_Index);
3219 using namespace ::testing;
3223 EXPECT_CALL(GLProxy, GenTextures(1))
3225 .WillOnce(Return(TextureId));
3227 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3230 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
3232 GL_RGBA, GL_FLOAT, _Source))
3235 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3238 EXPECT_CALL(GLProxy, GetError())
3240 .WillOnce(Return(GL_NO_ERROR));
3242 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3245 auto Render = itCreator->second(_pTexture);
3246 ASSERT_NE(
nullptr, Render);
3248 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3251 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3254 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3256 .WillOnce(Return(&ProgramId));
3258 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3260 .WillOnce(Return(LocationId));
3262 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
3265 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3270 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3274 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3276 { uT(
"albedo"),
"TexAlbedo" },
3277 { uT(
"metalness"),
"TexMetalness" },
3278 { uT(
"roughness"),
"TexRoughness" },
3279 { uT(
"normal"),
"TexNormal" },
3280 { uT(
"occlusion"),
"TexOcclusion" },
3284 ::std::vector<uint8_t> Source =
3286 0x20, 0x06, 0x15, 0x12, 0x30,
3287 0x20, 0x06, 0x15, 0x12, 0x30,
3288 0x20, 0x06, 0x15, 0x12, 0x30,
3289 0x20, 0x06, 0x15, 0x12, 0x30,
3290 0x20, 0x06, 0x15, 0x12, 0x30,
3292 IntroduceBufferSize(Source);
3294 for (::std::size_t i = 0; i < Destinations.size(); i++)
3297 const int Width = 1908221843;
3298 const int Height = 1908221844;
3300 const auto pTexture = Component_t::Make(
3302 { uT(
"content"), Source },
3303 { uT(
"width"), Width },
3304 { uT(
"height"), Height },
3305 { uT(
"destination"), Destinations[i].first },
3306 { uT(
"capacity"), 32 },
3310 Source, Width, Height, i, Destinations[i].second);
3314 const int Width = 1908221845;
3315 const int Height = 1908221847;
3317 const auto pData = Component_t::Make(
3319 { uT(
"kind"), uT(
"Texture") },
3320 { uT(
"content"), Source },
3321 { uT(
"width"), Width },
3322 { uT(
"height"), Height },
3323 { uT(
"destination"), Destinations[i].first },
3324 { uT(
"capacity"), 32 },
3327 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3328 Source, Width, Height, i, Destinations[i].second);
3332 const int Width = 1908221843;
3333 const int Height = 1908221844;
3335 const auto pTexture = Component_t::Make(
3337 { uT(
"content"), Source },
3338 { uT(
"width"), Width },
3339 { uT(
"height"), Height },
3340 { uT(
"destination"), Destinations[i].first },
3341 { uT(
"mipmapping"),
false },
3342 { uT(
"capacity"), 32 },
3346 Source, Width, Height, i, Destinations[i].second);
3350 const int Width = 1908221845;
3351 const int Height = 1908221847;
3353 const auto pData = Component_t::Make(
3355 { uT(
"kind"), uT(
"Texture") },
3356 { uT(
"content"), Source },
3357 { uT(
"width"), Width },
3358 { uT(
"height"), Height },
3359 { uT(
"destination"), Destinations[i].first },
3360 { uT(
"mipmapping"),
false },
3361 { uT(
"capacity"), 32 },
3364 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3365 Source, Width, Height, i, Destinations[i].second);
3371TEST_F(OpenGLShader_test, Test_Texture_Mipmapping_NameAndIndex)
3373 using GLProxy_t = ::mock::GLProxy;
3375 GLProxy_t::GetInstance() = &GLProxy;
3377 const Tested_t Example{ Data_t{} };
3378 const ITested_t & IExample = Example;
3380 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
3381 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3383 const ::mock::GLuint TextureId = 1908221839;
3384 const ::mock::GLint ProgramId = 1908221840;
3385 const ::mock::GLint LocationId = 1908221841;
3387 const auto TestCall = [&](
3388 const Component_t::ComponentPtr_t & _pTexture,
3389 const ::std::vector<uint8_t> & _Source,
3390 const int _Width,
const int _Height,
3391 const ::std::size_t _Index,
3392 const ::std::string & _TexName)
3394 const auto Index =
static_cast<::mock::GLint
>(_Index);
3396 using namespace ::testing;
3400 EXPECT_CALL(GLProxy, GenTextures(1))
3402 .WillOnce(Return(TextureId));
3404 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3407 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
3409 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
3412 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3415 EXPECT_CALL(GLProxy, GetError())
3417 .WillOnce(Return(GL_NO_ERROR));
3419 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3422 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
3425 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3428 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3431 auto Render = itCreator->second(_pTexture);
3432 ASSERT_NE(
nullptr, Render);
3434 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3437 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3440 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3442 .WillOnce(Return(&ProgramId));
3444 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3446 .WillOnce(Return(LocationId));
3448 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
3451 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3456 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3460 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
3462 { uT(
"TexEnvironment"),
"TexEnvironment" },
3463 { uT(
"TexReflection"),
"TexReflection" },
3464 { uT(
"TexBaseColor"),
"TexBaseColor" },
3467 for (
int Index = 0; Index < Names.size(); Index++)
3469 ::std::vector<uint8_t> Source =
3471 0x20, 0x06, 0x15, 0x12, 0x31,
3472 0x20, 0x06, 0x15, 0x12, 0x31,
3473 0x20, 0x06, 0x15, 0x12, 0x31,
3474 0x20, 0x06, 0x15, 0x12, 0x31,
3475 0x20, 0x06, 0x15, 0x12, 0x31,
3477 IntroduceBufferSize(Source);
3480 const int Width = 1908221843;
3481 const int Height = 1908221844;
3483 const auto pTexture = Component_t::Make(
3485 { uT(
"content"), Source },
3486 { uT(
"width"), Width },
3487 { uT(
"height"), Height },
3488 { uT(
"name"), Names[Index].first },
3489 { uT(
"index"), Index },
3490 { uT(
"mipmapping"),
true },
3494 Source, Width, Height, Index, Names[Index].second);
3498 const int Width = 1908221845;
3499 const int Height = 1908221847;
3501 const auto pData = Component_t::Make(
3503 { uT(
"kind"), uT(
"Texture") },
3504 { uT(
"content"), Source },
3505 { uT(
"width"), Width },
3506 { uT(
"height"), Height },
3507 { uT(
"name"), Names[Index].first },
3508 { uT(
"index"), Index },
3509 { uT(
"mipmapping"),
true },
3512 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3513 Source, Width, Height, Index, Names[Index].second);
3516 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3518 { uT(
"albedo"),
"TexAlbedo" },
3519 { uT(
"metalness"),
"TexMetalness" },
3520 { uT(
"roughness"),
"TexRoughness" },
3521 { uT(
"normal"),
"TexNormal" },
3522 { uT(
"occlusion"),
"TexOcclusion" },
3525 for (::std::size_t i = 0; i < Destinations.size(); i++)
3528 const int Width = 1908221843;
3529 const int Height = 1908221844;
3531 const auto pTexture = Component_t::Make(
3533 { uT(
"content"), Source },
3534 { uT(
"width"), Width },
3535 { uT(
"height"), Height },
3536 { uT(
"name"), Names[Index].first },
3537 { uT(
"index"), Index },
3538 { uT(
"destination"), Destinations[i].first },
3539 { uT(
"mipmapping"),
true },
3543 Source, Width, Height, Index, Names[Index].second);
3547 const int Width = 1908221845;
3548 const int Height = 1908221847;
3550 const auto pData = Component_t::Make(
3552 { uT(
"kind"), uT(
"Texture") },
3553 { uT(
"content"), Source },
3554 { uT(
"width"), Width },
3555 { uT(
"height"), Height },
3556 { uT(
"name"), Names[Index].first },
3557 { uT(
"index"), Index },
3558 { uT(
"destination"), Destinations[i].first },
3559 { uT(
"mipmapping"),
true },
3562 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3563 Source, Width, Height, Index, Names[Index].second);
3570TEST_F(OpenGLShader_test, Test_Texture_Mipmapping_NameAndIndex_Capacity16)
3572 using GLProxy_t = ::mock::GLProxy;
3574 GLProxy_t::GetInstance() = &GLProxy;
3576 const Tested_t Example{ Data_t{} };
3577 const ITested_t & IExample = Example;
3579 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
3580 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3582 const ::mock::GLuint TextureId = 1908221839;
3583 const ::mock::GLint ProgramId = 1908221840;
3584 const ::mock::GLint LocationId = 1908221841;
3586 const auto TestCall = [&](
3587 const Component_t::ComponentPtr_t & _pTexture,
3588 const ::std::vector<uint8_t> & _Source,
3589 const int _Width,
const int _Height,
3590 const ::std::size_t _Index,
3591 const ::std::string & _TexName)
3593 const auto Index =
static_cast<::mock::GLint
>(_Index);
3595 using namespace ::testing;
3599 EXPECT_CALL(GLProxy, GenTextures(1))
3601 .WillOnce(Return(TextureId));
3603 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3606 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
3608 GL_RGBA, GL_HALF_FLOAT, _Source))
3611 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3614 EXPECT_CALL(GLProxy, GetError())
3616 .WillOnce(Return(GL_NO_ERROR));
3618 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3621 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
3624 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3627 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3630 auto Render = itCreator->second(_pTexture);
3631 ASSERT_NE(
nullptr, Render);
3633 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3636 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3639 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3641 .WillOnce(Return(&ProgramId));
3643 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3645 .WillOnce(Return(LocationId));
3647 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
3650 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3655 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3659 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
3661 { uT(
"TexEnvironment"),
"TexEnvironment" },
3662 { uT(
"TexReflection"),
"TexReflection" },
3663 { uT(
"TexBaseColor"),
"TexBaseColor" },
3666 for (
int Index = 0; Index < Names.size(); Index++)
3668 ::std::vector<uint8_t> Source =
3670 0x20, 0x06, 0x15, 0x12, 0x31,
3671 0x20, 0x06, 0x15, 0x12, 0x31,
3672 0x20, 0x06, 0x15, 0x12, 0x31,
3673 0x20, 0x06, 0x15, 0x12, 0x31,
3674 0x20, 0x06, 0x15, 0x12, 0x31,
3676 IntroduceBufferSize(Source);
3679 const int Width = 1908221843;
3680 const int Height = 1908221844;
3682 const auto pTexture = Component_t::Make(
3684 { uT(
"content"), Source },
3685 { uT(
"width"), Width },
3686 { uT(
"height"), Height },
3687 { uT(
"name"), Names[Index].first },
3688 { uT(
"index"), Index },
3689 { uT(
"mipmapping"),
true },
3690 { uT(
"capacity"), 16 },
3694 Source, Width, Height, Index, Names[Index].second);
3698 const int Width = 1908221845;
3699 const int Height = 1908221847;
3701 const auto pData = Component_t::Make(
3703 { uT(
"kind"), uT(
"Texture") },
3704 { uT(
"content"), Source },
3705 { uT(
"width"), Width },
3706 { uT(
"height"), Height },
3707 { uT(
"name"), Names[Index].first },
3708 { uT(
"index"), Index },
3709 { uT(
"mipmapping"),
true },
3710 { uT(
"capacity"), 16 },
3713 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3714 Source, Width, Height, Index, Names[Index].second);
3717 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3719 { uT(
"albedo"),
"TexAlbedo" },
3720 { uT(
"metalness"),
"TexMetalness" },
3721 { uT(
"roughness"),
"TexRoughness" },
3722 { uT(
"normal"),
"TexNormal" },
3723 { uT(
"occlusion"),
"TexOcclusion" },
3726 for (::std::size_t i = 0; i < Destinations.size(); i++)
3729 const int Width = 1908221843;
3730 const int Height = 1908221844;
3732 const auto pTexture = Component_t::Make(
3734 { uT(
"content"), Source },
3735 { uT(
"width"), Width },
3736 { uT(
"height"), Height },
3737 { uT(
"name"), Names[Index].first },
3738 { uT(
"index"), Index },
3739 { uT(
"destination"), Destinations[i].first },
3740 { uT(
"mipmapping"),
true },
3741 { uT(
"capacity"), 16 },
3745 Source, Width, Height, Index, Names[Index].second);
3749 const int Width = 1908221845;
3750 const int Height = 1908221847;
3752 const auto pData = Component_t::Make(
3754 { uT(
"kind"), uT(
"Texture") },
3755 { uT(
"content"), Source },
3756 { uT(
"width"), Width },
3757 { uT(
"height"), Height },
3758 { uT(
"name"), Names[Index].first },
3759 { uT(
"index"), Index },
3760 { uT(
"destination"), Destinations[i].first },
3761 { uT(
"mipmapping"),
true },
3762 { uT(
"capacity"), 16 },
3765 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3766 Source, Width, Height, Index, Names[Index].second);
3773TEST_F(OpenGLShader_test, Test_Texture_Mipmapping_NameAndIndex_Capacity32)
3775 using GLProxy_t = ::mock::GLProxy;
3777 GLProxy_t::GetInstance() = &GLProxy;
3779 const Tested_t Example{ Data_t{} };
3780 const ITested_t & IExample = Example;
3782 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
3783 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3785 const ::mock::GLuint TextureId = 1908221839;
3786 const ::mock::GLint ProgramId = 1908221840;
3787 const ::mock::GLint LocationId = 1908221841;
3789 const auto TestCall = [&](
3790 const Component_t::ComponentPtr_t & _pTexture,
3791 const ::std::vector<uint8_t> & _Source,
3792 const int _Width,
const int _Height,
3793 const ::std::size_t _Index,
3794 const ::std::string & _TexName)
3796 const auto Index =
static_cast<::mock::GLint
>(_Index);
3798 using namespace ::testing;
3802 EXPECT_CALL(GLProxy, GenTextures(1))
3804 .WillOnce(Return(TextureId));
3806 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3809 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
3811 GL_RGBA, GL_FLOAT, _Source))
3814 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3817 EXPECT_CALL(GLProxy, GetError())
3819 .WillOnce(Return(GL_NO_ERROR));
3821 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3824 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
3827 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
3830 EXPECT_CALL(GLProxy, GenFramebuffers(1))
3833 auto Render = itCreator->second(_pTexture);
3834 ASSERT_NE(
nullptr, Render);
3836 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
3839 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
3842 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
3844 .WillOnce(Return(&ProgramId));
3846 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
3848 .WillOnce(Return(LocationId));
3850 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
3853 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
3858 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
3862 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
3864 { uT(
"TexEnvironment"),
"TexEnvironment" },
3865 { uT(
"TexReflection"),
"TexReflection" },
3866 { uT(
"TexBaseColor"),
"TexBaseColor" },
3869 for (
int Index = 0; Index < Names.size(); Index++)
3871 ::std::vector<uint8_t> Source =
3873 0x20, 0x06, 0x15, 0x12, 0x31,
3874 0x20, 0x06, 0x15, 0x12, 0x31,
3875 0x20, 0x06, 0x15, 0x12, 0x31,
3876 0x20, 0x06, 0x15, 0x12, 0x31,
3877 0x20, 0x06, 0x15, 0x12, 0x31,
3879 IntroduceBufferSize(Source);
3882 const int Width = 1908221843;
3883 const int Height = 1908221844;
3885 const auto pTexture = Component_t::Make(
3887 { uT(
"content"), Source },
3888 { uT(
"width"), Width },
3889 { uT(
"height"), Height },
3890 { uT(
"name"), Names[Index].first },
3891 { uT(
"index"), Index },
3892 { uT(
"mipmapping"),
true },
3893 { uT(
"capacity"), 32 },
3897 Source, Width, Height, Index, Names[Index].second);
3901 const int Width = 1908221845;
3902 const int Height = 1908221847;
3904 const auto pData = Component_t::Make(
3906 { uT(
"kind"), uT(
"Texture") },
3907 { uT(
"content"), Source },
3908 { uT(
"width"), Width },
3909 { uT(
"height"), Height },
3910 { uT(
"name"), Names[Index].first },
3911 { uT(
"index"), Index },
3912 { uT(
"mipmapping"),
true },
3913 { uT(
"capacity"), 32 },
3916 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3917 Source, Width, Height, Index, Names[Index].second);
3920 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
3922 { uT(
"albedo"),
"TexAlbedo" },
3923 { uT(
"metalness"),
"TexMetalness" },
3924 { uT(
"roughness"),
"TexRoughness" },
3925 { uT(
"normal"),
"TexNormal" },
3926 { uT(
"occlusion"),
"TexOcclusion" },
3929 for (::std::size_t i = 0; i < Destinations.size(); i++)
3932 const int Width = 1908221843;
3933 const int Height = 1908221844;
3935 const auto pTexture = Component_t::Make(
3937 { uT(
"content"), Source },
3938 { uT(
"width"), Width },
3939 { uT(
"height"), Height },
3940 { uT(
"name"), Names[Index].first },
3941 { uT(
"index"), Index },
3942 { uT(
"destination"), Destinations[i].first },
3943 { uT(
"mipmapping"),
true },
3944 { uT(
"capacity"), 32 },
3948 Source, Width, Height, Index, Names[Index].second);
3952 const int Width = 1908221845;
3953 const int Height = 1908221847;
3955 const auto pData = Component_t::Make(
3957 { uT(
"kind"), uT(
"Texture") },
3958 { uT(
"content"), Source },
3959 { uT(
"width"), Width },
3960 { uT(
"height"), Height },
3961 { uT(
"name"), Names[Index].first },
3962 { uT(
"index"), Index },
3963 { uT(
"destination"), Destinations[i].first },
3964 { uT(
"mipmapping"),
true },
3965 { uT(
"capacity"), 32 },
3968 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
3969 Source, Width, Height, Index, Names[Index].second);
3976TEST_F(OpenGLShader_test, Test_Texture_Mipmapping_Destination)
3978 using GLProxy_t = ::mock::GLProxy;
3980 GLProxy_t::GetInstance() = &GLProxy;
3982 const Tested_t Example{ Data_t{} };
3983 const ITested_t & IExample = Example;
3985 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
3986 ASSERT_NE(IExample.GetCreators().end(), itCreator);
3988 const ::mock::GLuint TextureId = 1908221839;
3989 const ::mock::GLint ProgramId = 1908221840;
3990 const ::mock::GLint LocationId = 1908221841;
3992 const auto TestCall = [&](
3993 const Component_t::ComponentPtr_t & _pTexture,
3994 const ::std::vector<uint8_t> & _Source,
3995 const int _Width,
const int _Height,
3996 const ::std::size_t _Index,
3997 const ::std::string & _TexName)
3999 const auto Index =
static_cast<::mock::GLint
>(_Index);
4001 using namespace ::testing;
4005 EXPECT_CALL(GLProxy, GenTextures(1))
4007 .WillOnce(Return(TextureId));
4009 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4012 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
4014 GL_RGBA, GL_UNSIGNED_BYTE, _Source))
4017 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4020 EXPECT_CALL(GLProxy, GetError())
4022 .WillOnce(Return(GL_NO_ERROR));
4024 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4027 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
4030 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4033 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4036 auto Render = itCreator->second(_pTexture);
4037 ASSERT_NE(
nullptr, Render);
4039 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4042 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4045 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4047 .WillOnce(Return(&ProgramId));
4049 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4051 .WillOnce(Return(LocationId));
4053 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
4056 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4061 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4065 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4067 { uT(
"albedo"),
"TexAlbedo" },
4068 { uT(
"metalness"),
"TexMetalness" },
4069 { uT(
"roughness"),
"TexRoughness" },
4070 { uT(
"normal"),
"TexNormal" },
4071 { uT(
"occlusion"),
"TexOcclusion" },
4074 ::std::vector<uint8_t> Source =
4076 0x20, 0x06, 0x15, 0x12, 0x31,
4077 0x20, 0x06, 0x15, 0x12, 0x31,
4078 0x20, 0x06, 0x15, 0x12, 0x31,
4079 0x20, 0x06, 0x15, 0x12, 0x31,
4080 0x20, 0x06, 0x15, 0x12, 0x31,
4082 IntroduceBufferSize(Source);
4084 for (::std::size_t i = 0; i < Destinations.size(); i++)
4087 const int Width = 1908221843;
4088 const int Height = 1908221844;
4090 const auto pTexture = Component_t::Make(
4092 { uT(
"content"), Source },
4093 { uT(
"width"), Width },
4094 { uT(
"height"), Height },
4095 { uT(
"destination"), Destinations[i].first },
4096 { uT(
"mipmapping"),
true },
4100 Source, Width, Height, i, Destinations[i].second);
4104 const int Width = 1908221845;
4105 const int Height = 1908221847;
4107 const auto pData = Component_t::Make(
4109 { uT(
"kind"), uT(
"Texture") },
4110 { uT(
"content"), Source },
4111 { uT(
"width"), Width },
4112 { uT(
"height"), Height },
4113 { uT(
"destination"), Destinations[i].first },
4114 { uT(
"mipmapping"),
true },
4117 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
4118 Source, Width, Height, i, Destinations[i].second);
4124TEST_F(OpenGLShader_test, Test_Texture_Mipmapping_Destination_Capacity16)
4126 using GLProxy_t = ::mock::GLProxy;
4128 GLProxy_t::GetInstance() = &GLProxy;
4130 const Tested_t Example{ Data_t{} };
4131 const ITested_t & IExample = Example;
4133 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
4134 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4136 const ::mock::GLuint TextureId = 1908221839;
4137 const ::mock::GLint ProgramId = 1908221840;
4138 const ::mock::GLint LocationId = 1908221841;
4140 const auto TestCall = [&](
4141 const Component_t::ComponentPtr_t & _pTexture,
4142 const ::std::vector<uint8_t> & _Source,
4143 const int _Width,
const int _Height,
4144 const ::std::size_t _Index,
4145 const ::std::string & _TexName)
4147 const auto Index =
static_cast<::mock::GLint
>(_Index);
4149 using namespace ::testing;
4153 EXPECT_CALL(GLProxy, GenTextures(1))
4155 .WillOnce(Return(TextureId));
4157 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4160 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
4162 GL_RGBA, GL_HALF_FLOAT, _Source))
4165 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4168 EXPECT_CALL(GLProxy, GetError())
4170 .WillOnce(Return(GL_NO_ERROR));
4172 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4175 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
4178 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4181 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4184 auto Render = itCreator->second(_pTexture);
4185 ASSERT_NE(
nullptr, Render);
4187 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4190 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4193 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4195 .WillOnce(Return(&ProgramId));
4197 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4199 .WillOnce(Return(LocationId));
4201 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
4204 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4209 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4213 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4215 { uT(
"albedo"),
"TexAlbedo" },
4216 { uT(
"metalness"),
"TexMetalness" },
4217 { uT(
"roughness"),
"TexRoughness" },
4218 { uT(
"normal"),
"TexNormal" },
4219 { uT(
"occlusion"),
"TexOcclusion" },
4222 ::std::vector<uint8_t> Source =
4224 0x20, 0x06, 0x15, 0x12, 0x31,
4225 0x20, 0x06, 0x15, 0x12, 0x31,
4226 0x20, 0x06, 0x15, 0x12, 0x31,
4227 0x20, 0x06, 0x15, 0x12, 0x31,
4228 0x20, 0x06, 0x15, 0x12, 0x31,
4230 IntroduceBufferSize(Source);
4232 for (::std::size_t i = 0; i < Destinations.size(); i++)
4235 const int Width = 1908221843;
4236 const int Height = 1908221844;
4238 const auto pTexture = Component_t::Make(
4240 { uT(
"content"), Source },
4241 { uT(
"width"), Width },
4242 { uT(
"height"), Height },
4243 { uT(
"destination"), Destinations[i].first },
4244 { uT(
"mipmapping"),
true },
4245 { uT(
"capacity"), 16 },
4249 Source, Width, Height, i, Destinations[i].second);
4253 const int Width = 1908221845;
4254 const int Height = 1908221847;
4256 const auto pData = Component_t::Make(
4258 { uT(
"kind"), uT(
"Texture") },
4259 { uT(
"content"), Source },
4260 { uT(
"width"), Width },
4261 { uT(
"height"), Height },
4262 { uT(
"destination"), Destinations[i].first },
4263 { uT(
"mipmapping"),
true },
4264 { uT(
"capacity"), 16 },
4267 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
4268 Source, Width, Height, i, Destinations[i].second);
4274TEST_F(OpenGLShader_test, Test_Texture_Mipmapping_Destination_Capacity32)
4276 using GLProxy_t = ::mock::GLProxy;
4278 GLProxy_t::GetInstance() = &GLProxy;
4280 const Tested_t Example{ Data_t{} };
4281 const ITested_t & IExample = Example;
4283 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
4284 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4286 const ::mock::GLuint TextureId = 1908221839;
4287 const ::mock::GLint ProgramId = 1908221840;
4288 const ::mock::GLint LocationId = 1908221841;
4290 const auto TestCall = [&](
4291 const Component_t::ComponentPtr_t & _pTexture,
4292 const ::std::vector<uint8_t> & _Source,
4293 const int _Width,
const int _Height,
4294 const ::std::size_t _Index,
4295 const ::std::string & _TexName)
4297 const auto Index =
static_cast<::mock::GLint
>(_Index);
4299 using namespace ::testing;
4303 EXPECT_CALL(GLProxy, GenTextures(1))
4305 .WillOnce(Return(TextureId));
4307 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4310 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
4312 GL_RGBA, GL_FLOAT, _Source))
4315 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4318 EXPECT_CALL(GLProxy, GetError())
4320 .WillOnce(Return(GL_NO_ERROR));
4322 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4325 EXPECT_CALL(GLProxy, GenerateMipmap(GL_TEXTURE_2D))
4328 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4331 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4334 auto Render = itCreator->second(_pTexture);
4335 ASSERT_NE(
nullptr, Render);
4337 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4340 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4343 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4345 .WillOnce(Return(&ProgramId));
4347 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4349 .WillOnce(Return(LocationId));
4351 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
4354 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4359 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4363 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4365 { uT(
"albedo"),
"TexAlbedo" },
4366 { uT(
"metalness"),
"TexMetalness" },
4367 { uT(
"roughness"),
"TexRoughness" },
4368 { uT(
"normal"),
"TexNormal" },
4369 { uT(
"occlusion"),
"TexOcclusion" },
4372 ::std::vector<uint8_t> Source =
4374 0x20, 0x06, 0x15, 0x12, 0x31,
4375 0x20, 0x06, 0x15, 0x12, 0x31,
4376 0x20, 0x06, 0x15, 0x12, 0x31,
4377 0x20, 0x06, 0x15, 0x12, 0x31,
4378 0x20, 0x06, 0x15, 0x12, 0x31,
4380 IntroduceBufferSize(Source);
4382 for (::std::size_t i = 0; i < Destinations.size(); i++)
4385 const int Width = 1908221843;
4386 const int Height = 1908221844;
4388 const auto pTexture = Component_t::Make(
4390 { uT(
"content"), Source },
4391 { uT(
"width"), Width },
4392 { uT(
"height"), Height },
4393 { uT(
"destination"), Destinations[i].first },
4394 { uT(
"mipmapping"),
true },
4395 { uT(
"capacity"), 32 },
4399 Source, Width, Height, i, Destinations[i].second);
4403 const int Width = 1908221845;
4404 const int Height = 1908221847;
4406 const auto pData = Component_t::Make(
4408 { uT(
"kind"), uT(
"Texture") },
4409 { uT(
"content"), Source },
4410 { uT(
"width"), Width },
4411 { uT(
"height"), Height },
4412 { uT(
"destination"), Destinations[i].first },
4413 { uT(
"mipmapping"),
true },
4414 { uT(
"capacity"), 32 },
4417 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
4418 Source, Width, Height, i, Destinations[i].second);
4424TEST_F(OpenGLShader_test, Test_Texture_ReadData_NameAndIndex)
4426 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
4427 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
4429 using GLProxy_t = ::mock::GLProxy;
4431 GLProxy_t::GetInstance() = &GLProxy;
4434 public ::alicorn::extension::testing::Proxy<MapperProxy>
4437 MOCK_METHOD1(Map,
bool(
const void *));
4438 MOCK_METHOD1(CheckData,
void(::std::vector<uint32_t>));
4441 MapperProxy oMapperProxy;
4442 MapperProxy::GetInstance() = &oMapperProxy;
4444 const int Width = 3;
4445 const int Height = 4;
4447 const BufferMapper_t Mapper = [&](
const void * _pData)
4449 if (_pData !=
nullptr)
4451 ::std::vector<uint32_t> Data(Width * Height);
4452 memcpy(Data.data(), _pData, Width * Height * 4);
4453 oMapperProxy.CheckData(Data);
4456 return oMapperProxy.Map(_pData);
4459 const Tested_t Example{ Data_t{} };
4460 const ITested_t & IExample = Example;
4462 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
4463 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4465 const ::mock::GLint TextureId = 1910221154;
4466 const ::mock::GLint ProgramId = 1910221155;
4467 const ::mock::GLint LocationId = 1910221156;
4468 const ::mock::GLint FrameBufferId = 1910221209;
4469 const ::mock::GLint DefaultFrameBufferId = 1910221236;
4471 const auto TestCall = [&](
4472 const Component_t::ComponentPtr_t & _pDataTexture,
4473 const ::std::size_t _Index,
4474 const ::std::string & _TexName,
4475 const ::std::vector<uint32_t> & _RawData,
4476 const ::std::vector<uint32_t> & _ExpectData)
4478 const auto Index =
static_cast<::mock::GLint
>(_Index);
4480 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT(
"") };
4482 using namespace ::testing;
4486 EXPECT_CALL(GLProxy, GenTextures(1))
4488 .WillOnce(Return(TextureId));
4490 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4493 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
4495 GL_RGBA, GL_UNSIGNED_BYTE, ::std::vector<uint8_t>{}))
4498 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4501 EXPECT_CALL(GLProxy, GetError())
4503 .WillOnce(Return(GL_NO_ERROR));
4505 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
4506 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
4508 (*_pDataTexture)[uT(
"entity")] = pTexture;
4510 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4512 .WillOnce(Return(FrameBufferId));
4514 EXPECT_CALL(GLProxy, GenTextures(1))
4517 auto Render = itCreator->second(Component_t::Make(
4519 { uT(
"service"), Object_t{ _pDataTexture } }
4521 ASSERT_NE(
nullptr, Render);
4523 const auto TestCallActivateTexture = [&](void)
4525 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4528 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4531 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4533 .WillOnce(Return(&ProgramId));
4535 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4537 .WillOnce(Return(LocationId));
4539 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
4542 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4548 EXPECT_CALL(oMapperProxy, Map(
nullptr))
4550 .WillOnce(Return(
false));
4552 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
4555 TestCallActivateTexture();
4560 EXPECT_CALL(oMapperProxy, Map(
nullptr))
4562 .WillOnce(Return(
true));
4564 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
4566 .WillOnce(Return(&DefaultFrameBufferId));
4568 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
4571 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
4572 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
4575 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
4577 .WillOnce(Return(_RawData));
4579 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
4580 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
4583 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
4586 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
4589 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
4592 TestCallActivateTexture();
4597 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
4600 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4604 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
4606 { uT(
"TexEnvironment"),
"TexEnvironment" },
4607 { uT(
"TexReflection"),
"TexReflection" },
4608 { uT(
"TexBaseColor"),
"TexBaseColor" },
4611 for (
int Index = 0; Index < Names.size(); Index++)
4613 const ::std::vector<uint32_t> RawData =
4615 0x10221334, 0x10221335, 0x10221336,
4616 0x10221337, 0x10221338, 0x10221339,
4617 0x10221340, 0x10221341, 0x10221342,
4618 0x10221343, 0x10221344, 0x10221345,
4621 const ::std::vector<uint32_t> ExpectData =
4623 0x10221343, 0x10221344, 0x10221345,
4624 0x10221340, 0x10221341, 0x10221342,
4625 0x10221337, 0x10221338, 0x10221339,
4626 0x10221334, 0x10221335, 0x10221336,
4629 const auto pData = Component_t::Make(
4631 { uT(
"kind"), uT(
"Texture") },
4632 { uT(
"width"), Width },
4633 { uT(
"height"), Height },
4634 { uT(
"mapper"), Mapper },
4635 { uT(
"name"), Names[Index].first },
4636 { uT(
"index"), Index },
4639 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
4641 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4643 { uT(
"albedo"),
"TexAlbedo" },
4644 { uT(
"metalness"),
"TexMetalness" },
4645 { uT(
"roughness"),
"TexRoughness" },
4646 { uT(
"normal"),
"TexNormal" },
4647 { uT(
"occlusion"),
"TexOcclusion" },
4650 for (::std::size_t i = 0; i < Destinations.size(); i++)
4652 const auto pData = Component_t::Make(
4654 { uT(
"kind"), uT(
"Texture") },
4655 { uT(
"width"), Width },
4656 { uT(
"height"), Height },
4657 { uT(
"mapper"), Mapper },
4658 { uT(
"name"), Names[Index].first },
4659 { uT(
"index"), Index },
4660 { uT(
"destination"), Destinations[i].first },
4663 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
4669TEST_F(OpenGLShader_test, Test_Texture_ReadData_NameAndIndex_Capacity16)
4671 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
4672 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
4674 using GLProxy_t = ::mock::GLProxy;
4676 GLProxy_t::GetInstance() = &GLProxy;
4679 public ::alicorn::extension::testing::Proxy<MapperProxy>
4682 MOCK_METHOD1(Map,
bool(
const void *));
4683 MOCK_METHOD1(CheckData,
void(::std::vector<uint32_t>));
4686 MapperProxy oMapperProxy;
4687 MapperProxy::GetInstance() = &oMapperProxy;
4689 const int Width = 3;
4690 const int Height = 4;
4692 const BufferMapper_t Mapper = [&](
const void * _pData)
4694 if (_pData !=
nullptr)
4696 ::std::vector<uint32_t> Data(Width * Height);
4697 memcpy(Data.data(), _pData, Width * Height * 4);
4698 oMapperProxy.CheckData(Data);
4701 return oMapperProxy.Map(_pData);
4704 const Tested_t Example{ Data_t{} };
4705 const ITested_t & IExample = Example;
4707 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
4708 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4710 const ::mock::GLint TextureId = 1910221154;
4711 const ::mock::GLint ProgramId = 1910221155;
4712 const ::mock::GLint LocationId = 1910221156;
4713 const ::mock::GLint FrameBufferId = 1910221209;
4714 const ::mock::GLint DefaultFrameBufferId = 1910221236;
4716 const auto TestCall = [&](
4717 const Component_t::ComponentPtr_t & _pDataTexture,
4718 const ::std::size_t _Index,
4719 const ::std::string & _TexName,
4720 const ::std::vector<uint32_t> & _RawData,
4721 const ::std::vector<uint32_t> & _ExpectData)
4723 const auto Index =
static_cast<::mock::GLint
>(_Index);
4725 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT(
"") };
4727 using namespace ::testing;
4731 EXPECT_CALL(GLProxy, GenTextures(1))
4733 .WillOnce(Return(TextureId));
4735 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4738 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
4740 GL_RGBA, GL_HALF_FLOAT, ::std::vector<uint8_t>{}))
4743 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4746 EXPECT_CALL(GLProxy, GetError())
4748 .WillOnce(Return(GL_NO_ERROR));
4750 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
4751 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
4753 (*_pDataTexture)[uT(
"entity")] = pTexture;
4755 EXPECT_CALL(GLProxy, GenFramebuffers(1))
4757 .WillOnce(Return(FrameBufferId));
4759 EXPECT_CALL(GLProxy, GenTextures(1))
4762 auto Render = itCreator->second(Component_t::Make(
4764 { uT(
"service"), Object_t{ _pDataTexture } }
4766 ASSERT_NE(
nullptr, Render);
4768 const auto TestCallActivateTexture = [&](void)
4770 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
4773 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4776 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
4778 .WillOnce(Return(&ProgramId));
4780 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
4782 .WillOnce(Return(LocationId));
4784 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
4787 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
4793 EXPECT_CALL(oMapperProxy, Map(
nullptr))
4795 .WillOnce(Return(
false));
4797 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
4800 TestCallActivateTexture();
4805 EXPECT_CALL(oMapperProxy, Map(
nullptr))
4807 .WillOnce(Return(
true));
4809 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
4811 .WillOnce(Return(&DefaultFrameBufferId));
4813 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
4816 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
4817 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
4820 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
4822 .WillOnce(Return(_RawData));
4824 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
4825 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
4828 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
4831 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
4834 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
4837 TestCallActivateTexture();
4842 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
4845 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
4849 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
4851 { uT(
"TexEnvironment"),
"TexEnvironment" },
4852 { uT(
"TexReflection"),
"TexReflection" },
4853 { uT(
"TexBaseColor"),
"TexBaseColor" },
4856 for (
int Index = 0; Index < Names.size(); Index++)
4858 const ::std::vector<uint32_t> RawData =
4860 0x10221334, 0x10221335, 0x10221336,
4861 0x10221337, 0x10221338, 0x10221339,
4862 0x10221340, 0x10221341, 0x10221342,
4863 0x10221343, 0x10221344, 0x10221345,
4866 const ::std::vector<uint32_t> ExpectData =
4868 0x10221343, 0x10221344, 0x10221345,
4869 0x10221340, 0x10221341, 0x10221342,
4870 0x10221337, 0x10221338, 0x10221339,
4871 0x10221334, 0x10221335, 0x10221336,
4874 const auto pData = Component_t::Make(
4876 { uT(
"kind"), uT(
"Texture") },
4877 { uT(
"width"), Width },
4878 { uT(
"height"), Height },
4879 { uT(
"mapper"), Mapper },
4880 { uT(
"name"), Names[Index].first },
4881 { uT(
"index"), Index },
4882 { uT(
"capacity"), 16 },
4885 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
4887 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
4889 { uT(
"albedo"),
"TexAlbedo" },
4890 { uT(
"metalness"),
"TexMetalness" },
4891 { uT(
"roughness"),
"TexRoughness" },
4892 { uT(
"normal"),
"TexNormal" },
4893 { uT(
"occlusion"),
"TexOcclusion" },
4896 for (::std::size_t i = 0; i < Destinations.size(); i++)
4898 const auto pData = Component_t::Make(
4900 { uT(
"kind"), uT(
"Texture") },
4901 { uT(
"width"), Width },
4902 { uT(
"height"), Height },
4903 { uT(
"mapper"), Mapper },
4904 { uT(
"name"), Names[Index].first },
4905 { uT(
"index"), Index },
4906 { uT(
"destination"), Destinations[i].first },
4907 { uT(
"capacity"), 16 },
4910 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
4916TEST_F(OpenGLShader_test, Test_Texture_ReadData_NameAndIndex_Capacity32)
4918 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
4919 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
4921 using GLProxy_t = ::mock::GLProxy;
4923 GLProxy_t::GetInstance() = &GLProxy;
4926 public ::alicorn::extension::testing::Proxy<MapperProxy>
4929 MOCK_METHOD1(Map,
bool(
const void *));
4930 MOCK_METHOD1(CheckData,
void(::std::vector<uint32_t>));
4933 MapperProxy oMapperProxy;
4934 MapperProxy::GetInstance() = &oMapperProxy;
4936 const int Width = 3;
4937 const int Height = 4;
4939 const BufferMapper_t Mapper = [&](
const void * _pData)
4941 if (_pData !=
nullptr)
4943 ::std::vector<uint32_t> Data(Width * Height);
4944 memcpy(Data.data(), _pData, Width * Height * 4);
4945 oMapperProxy.CheckData(Data);
4948 return oMapperProxy.Map(_pData);
4951 const Tested_t Example{ Data_t{} };
4952 const ITested_t & IExample = Example;
4954 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
4955 ASSERT_NE(IExample.GetCreators().end(), itCreator);
4957 const ::mock::GLint TextureId = 1910221154;
4958 const ::mock::GLint ProgramId = 1910221155;
4959 const ::mock::GLint LocationId = 1910221156;
4960 const ::mock::GLint FrameBufferId = 1910221209;
4961 const ::mock::GLint DefaultFrameBufferId = 1910221236;
4963 const auto TestCall = [&](
4964 const Component_t::ComponentPtr_t & _pDataTexture,
4965 const ::std::size_t _Index,
4966 const ::std::string & _TexName,
4967 const ::std::vector<uint32_t> & _RawData,
4968 const ::std::vector<uint32_t> & _ExpectData)
4970 const auto Index =
static_cast<::mock::GLint
>(_Index);
4972 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT(
"") };
4974 using namespace ::testing;
4978 EXPECT_CALL(GLProxy, GenTextures(1))
4980 .WillOnce(Return(TextureId));
4982 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
4985 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
4987 GL_RGBA, GL_FLOAT, ::std::vector<uint8_t>{}))
4990 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
4993 EXPECT_CALL(GLProxy, GetError())
4995 .WillOnce(Return(GL_NO_ERROR));
4997 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
4998 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
5000 (*_pDataTexture)[uT(
"entity")] = pTexture;
5002 EXPECT_CALL(GLProxy, GenFramebuffers(1))
5004 .WillOnce(Return(FrameBufferId));
5006 EXPECT_CALL(GLProxy, GenTextures(1))
5009 auto Render = itCreator->second(Component_t::Make(
5011 { uT(
"service"), Object_t{ _pDataTexture } }
5013 ASSERT_NE(
nullptr, Render);
5015 const auto TestCallActivateTexture = [&](void)
5017 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5020 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5023 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5025 .WillOnce(Return(&ProgramId));
5027 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5029 .WillOnce(Return(LocationId));
5031 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
5034 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5040 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5042 .WillOnce(Return(
false));
5044 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
5047 TestCallActivateTexture();
5052 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5054 .WillOnce(Return(
true));
5056 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
5058 .WillOnce(Return(&DefaultFrameBufferId));
5060 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
5063 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
5064 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
5067 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
5069 .WillOnce(Return(_RawData));
5071 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
5072 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
5075 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
5078 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
5081 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
5084 TestCallActivateTexture();
5089 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
5092 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5096 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
5098 { uT(
"TexEnvironment"),
"TexEnvironment" },
5099 { uT(
"TexReflection"),
"TexReflection" },
5100 { uT(
"TexBaseColor"),
"TexBaseColor" },
5103 for (
int Index = 0; Index < Names.size(); Index++)
5105 const ::std::vector<uint32_t> RawData =
5107 0x10221334, 0x10221335, 0x10221336,
5108 0x10221337, 0x10221338, 0x10221339,
5109 0x10221340, 0x10221341, 0x10221342,
5110 0x10221343, 0x10221344, 0x10221345,
5113 const ::std::vector<uint32_t> ExpectData =
5115 0x10221343, 0x10221344, 0x10221345,
5116 0x10221340, 0x10221341, 0x10221342,
5117 0x10221337, 0x10221338, 0x10221339,
5118 0x10221334, 0x10221335, 0x10221336,
5121 const auto pData = Component_t::Make(
5123 { uT(
"kind"), uT(
"Texture") },
5124 { uT(
"width"), Width },
5125 { uT(
"height"), Height },
5126 { uT(
"mapper"), Mapper },
5127 { uT(
"name"), Names[Index].first },
5128 { uT(
"index"), Index },
5129 { uT(
"capacity"), 32 },
5132 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
5134 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
5136 { uT(
"albedo"),
"TexAlbedo" },
5137 { uT(
"metalness"),
"TexMetalness" },
5138 { uT(
"roughness"),
"TexRoughness" },
5139 { uT(
"normal"),
"TexNormal" },
5140 { uT(
"occlusion"),
"TexOcclusion" },
5143 for (::std::size_t i = 0; i < Destinations.size(); i++)
5145 const auto pData = Component_t::Make(
5147 { uT(
"kind"), uT(
"Texture") },
5148 { uT(
"width"), Width },
5149 { uT(
"height"), Height },
5150 { uT(
"mapper"), Mapper },
5151 { uT(
"name"), Names[Index].first },
5152 { uT(
"index"), Index },
5153 { uT(
"destination"), Destinations[i].first },
5154 { uT(
"capacity"), 32 },
5157 TestCall(pData, Index, Names[Index].second, RawData, ExpectData);
5163TEST_F(OpenGLShader_test, Test_Texture_ReadData_Destination)
5165 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
5166 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
5168 using GLProxy_t = ::mock::GLProxy;
5170 GLProxy_t::GetInstance() = &GLProxy;
5173 public ::alicorn::extension::testing::Proxy<MapperProxy>
5176 MOCK_METHOD1(Map,
bool(
const void *));
5177 MOCK_METHOD1(CheckData,
void(::std::vector<uint32_t>));
5180 MapperProxy oMapperProxy;
5181 MapperProxy::GetInstance() = &oMapperProxy;
5183 const int Width = 3;
5184 const int Height = 4;
5186 const BufferMapper_t Mapper = [&](
const void * _pData)
5188 if (_pData !=
nullptr)
5190 ::std::vector<uint32_t> Data(Width * Height);
5191 memcpy(Data.data(), _pData, Width * Height * 4);
5192 oMapperProxy.CheckData(Data);
5195 return oMapperProxy.Map(_pData);
5198 const Tested_t Example{ Data_t{} };
5199 const ITested_t & IExample = Example;
5201 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
5202 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5204 const ::mock::GLint TextureId = 1910221154;
5205 const ::mock::GLint ProgramId = 1910221155;
5206 const ::mock::GLint LocationId = 1910221156;
5207 const ::mock::GLint FrameBufferId = 1910221209;
5208 const ::mock::GLint DefaultFrameBufferId = 1910221236;
5210 const auto TestCall = [&](
5211 const Component_t::ComponentPtr_t & _pDataTexture,
5212 const ::std::size_t _Index,
5213 const ::std::string & _TexName,
5214 const ::std::vector<uint32_t> & _RawData,
5215 const ::std::vector<uint32_t> & _ExpectData)
5217 const auto Index =
static_cast<::mock::GLint
>(_Index);
5219 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT(
"") };
5221 using namespace ::testing;
5225 EXPECT_CALL(GLProxy, GenTextures(1))
5227 .WillOnce(Return(TextureId));
5229 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5232 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
5234 GL_RGBA, GL_UNSIGNED_BYTE, ::std::vector<uint8_t>{}))
5237 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5240 EXPECT_CALL(GLProxy, GetError())
5242 .WillOnce(Return(GL_NO_ERROR));
5244 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
5245 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
5247 (*_pDataTexture)[uT(
"entity")] = pTexture;
5249 EXPECT_CALL(GLProxy, GenFramebuffers(1))
5251 .WillOnce(Return(FrameBufferId));
5253 EXPECT_CALL(GLProxy, GenTextures(1))
5256 auto Render = itCreator->second(Component_t::Make(
5258 { uT(
"service"), Object_t{ _pDataTexture } }
5260 ASSERT_NE(
nullptr, Render);
5262 const auto TestCallActivateTexture = [&](void)
5264 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5267 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5270 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5272 .WillOnce(Return(&ProgramId));
5274 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5276 .WillOnce(Return(LocationId));
5278 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
5281 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5287 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5289 .WillOnce(Return(
false));
5291 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
5294 TestCallActivateTexture();
5299 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5301 .WillOnce(Return(
true));
5303 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
5305 .WillOnce(Return(&DefaultFrameBufferId));
5307 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
5310 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
5311 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
5314 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
5316 .WillOnce(Return(_RawData));
5318 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
5319 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
5322 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
5325 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
5328 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
5331 TestCallActivateTexture();
5336 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
5339 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5343 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
5345 { uT(
"albedo"),
"TexAlbedo" },
5346 { uT(
"metalness"),
"TexMetalness" },
5347 { uT(
"roughness"),
"TexRoughness" },
5348 { uT(
"normal"),
"TexNormal" },
5349 { uT(
"occlusion"),
"TexOcclusion" },
5352 for (::std::size_t i = 0; i < Destinations.size(); i++)
5354 const ::std::vector<uint32_t> RawData =
5356 0x10221334, 0x10221335, 0x10221336,
5357 0x10221337, 0x10221338, 0x10221339,
5358 0x10221340, 0x10221341, 0x10221342,
5359 0x10221343, 0x10221344, 0x10221345,
5362 const ::std::vector<uint32_t> ExpectData =
5364 0x10221343, 0x10221344, 0x10221345,
5365 0x10221340, 0x10221341, 0x10221342,
5366 0x10221337, 0x10221338, 0x10221339,
5367 0x10221334, 0x10221335, 0x10221336,
5370 const auto pData = Component_t::Make(
5372 { uT(
"kind"), uT(
"Texture") },
5373 { uT(
"width"), Width },
5374 { uT(
"height"), Height },
5375 { uT(
"mapper"), Mapper },
5376 { uT(
"destination"), Destinations[i].first },
5379 TestCall(pData, i, Destinations[i].second, RawData, ExpectData);
5384TEST_F(OpenGLShader_test, Test_Texture_ReadData_Destination_Capacity16)
5386 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
5387 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
5389 using GLProxy_t = ::mock::GLProxy;
5391 GLProxy_t::GetInstance() = &GLProxy;
5394 public ::alicorn::extension::testing::Proxy<MapperProxy>
5397 MOCK_METHOD1(Map,
bool(
const void *));
5398 MOCK_METHOD1(CheckData,
void(::std::vector<uint32_t>));
5401 MapperProxy oMapperProxy;
5402 MapperProxy::GetInstance() = &oMapperProxy;
5404 const int Width = 3;
5405 const int Height = 4;
5407 const BufferMapper_t Mapper = [&](
const void * _pData)
5409 if (_pData !=
nullptr)
5411 ::std::vector<uint32_t> Data(Width * Height);
5412 memcpy(Data.data(), _pData, Width * Height * 4);
5413 oMapperProxy.CheckData(Data);
5416 return oMapperProxy.Map(_pData);
5419 const Tested_t Example{ Data_t{} };
5420 const ITested_t & IExample = Example;
5422 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
5423 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5425 const ::mock::GLint TextureId = 1910221154;
5426 const ::mock::GLint ProgramId = 1910221155;
5427 const ::mock::GLint LocationId = 1910221156;
5428 const ::mock::GLint FrameBufferId = 1910221209;
5429 const ::mock::GLint DefaultFrameBufferId = 1910221236;
5431 const auto TestCall = [&](
5432 const Component_t::ComponentPtr_t & _pDataTexture,
5433 const ::std::size_t _Index,
5434 const ::std::string & _TexName,
5435 const ::std::vector<uint32_t> & _RawData,
5436 const ::std::vector<uint32_t> & _ExpectData)
5438 const auto Index =
static_cast<::mock::GLint
>(_Index);
5440 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT(
"") };
5442 using namespace ::testing;
5446 EXPECT_CALL(GLProxy, GenTextures(1))
5448 .WillOnce(Return(TextureId));
5450 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5453 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F,
5455 GL_RGBA, GL_HALF_FLOAT, ::std::vector<uint8_t>{}))
5458 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5461 EXPECT_CALL(GLProxy, GetError())
5463 .WillOnce(Return(GL_NO_ERROR));
5465 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
5466 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
5468 (*_pDataTexture)[uT(
"entity")] = pTexture;
5470 EXPECT_CALL(GLProxy, GenFramebuffers(1))
5472 .WillOnce(Return(FrameBufferId));
5474 EXPECT_CALL(GLProxy, GenTextures(1))
5477 auto Render = itCreator->second(Component_t::Make(
5479 { uT(
"service"), Object_t{ _pDataTexture } }
5481 ASSERT_NE(
nullptr, Render);
5483 const auto TestCallActivateTexture = [&](void)
5485 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5488 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5491 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5493 .WillOnce(Return(&ProgramId));
5495 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5497 .WillOnce(Return(LocationId));
5499 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
5502 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5508 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5510 .WillOnce(Return(
false));
5512 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
5515 TestCallActivateTexture();
5520 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5522 .WillOnce(Return(
true));
5524 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
5526 .WillOnce(Return(&DefaultFrameBufferId));
5528 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
5531 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
5532 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
5535 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
5537 .WillOnce(Return(_RawData));
5539 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
5540 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
5543 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
5546 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
5549 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
5552 TestCallActivateTexture();
5557 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
5560 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5564 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
5566 { uT(
"albedo"),
"TexAlbedo" },
5567 { uT(
"metalness"),
"TexMetalness" },
5568 { uT(
"roughness"),
"TexRoughness" },
5569 { uT(
"normal"),
"TexNormal" },
5570 { uT(
"occlusion"),
"TexOcclusion" },
5573 for (::std::size_t i = 0; i < Destinations.size(); i++)
5575 const ::std::vector<uint32_t> RawData =
5577 0x10221334, 0x10221335, 0x10221336,
5578 0x10221337, 0x10221338, 0x10221339,
5579 0x10221340, 0x10221341, 0x10221342,
5580 0x10221343, 0x10221344, 0x10221345,
5583 const ::std::vector<uint32_t> ExpectData =
5585 0x10221343, 0x10221344, 0x10221345,
5586 0x10221340, 0x10221341, 0x10221342,
5587 0x10221337, 0x10221338, 0x10221339,
5588 0x10221334, 0x10221335, 0x10221336,
5591 const auto pData = Component_t::Make(
5593 { uT(
"kind"), uT(
"Texture") },
5594 { uT(
"width"), Width },
5595 { uT(
"height"), Height },
5596 { uT(
"mapper"), Mapper },
5597 { uT(
"destination"), Destinations[i].first },
5598 { uT(
"capacity"), 16 },
5601 TestCall(pData, i, Destinations[i].second, RawData, ExpectData);
5606TEST_F(OpenGLShader_test, Test_Texture_ReadData_Destination_Capacity32)
5608 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
5609 using BufferMapper_t = ::covellite::api::cbBufferMap_t<const void>;
5611 using GLProxy_t = ::mock::GLProxy;
5613 GLProxy_t::GetInstance() = &GLProxy;
5616 public ::alicorn::extension::testing::Proxy<MapperProxy>
5619 MOCK_METHOD1(Map,
bool(
const void *));
5620 MOCK_METHOD1(CheckData,
void(::std::vector<uint32_t>));
5623 MapperProxy oMapperProxy;
5624 MapperProxy::GetInstance() = &oMapperProxy;
5626 const int Width = 3;
5627 const int Height = 4;
5629 const BufferMapper_t Mapper = [&](
const void * _pData)
5631 if (_pData !=
nullptr)
5633 ::std::vector<uint32_t> Data(Width * Height);
5634 memcpy(Data.data(), _pData, Width * Height * 4);
5635 oMapperProxy.CheckData(Data);
5638 return oMapperProxy.Map(_pData);
5641 const Tested_t Example{ Data_t{} };
5642 const ITested_t & IExample = Example;
5644 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
5645 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5647 const ::mock::GLint TextureId = 1910221154;
5648 const ::mock::GLint ProgramId = 1910221155;
5649 const ::mock::GLint LocationId = 1910221156;
5650 const ::mock::GLint FrameBufferId = 1910221209;
5651 const ::mock::GLint DefaultFrameBufferId = 1910221236;
5653 const auto TestCall = [&](
5654 const Component_t::ComponentPtr_t & _pDataTexture,
5655 const ::std::size_t _Index,
5656 const ::std::string & _TexName,
5657 const ::std::vector<uint32_t> & _RawData,
5658 const ::std::vector<uint32_t> & _ExpectData)
5660 const auto Index =
static_cast<::mock::GLint
>(_Index);
5662 ::covellite::api::renderer::Component::Texture TextureData{ *_pDataTexture, uT(
"") };
5664 using namespace ::testing;
5668 EXPECT_CALL(GLProxy, GenTextures(1))
5670 .WillOnce(Return(TextureId));
5672 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5675 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F,
5677 GL_RGBA, GL_FLOAT, ::std::vector<uint8_t>{}))
5680 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5683 EXPECT_CALL(GLProxy, GetError())
5685 .WillOnce(Return(GL_NO_ERROR));
5687 const auto pTexture = ::std::make_shared<Texture_t>(TextureData);
5688 ASSERT_EQ(Width * Height * 4, pTexture->m_ReadCopyData.size());
5690 (*_pDataTexture)[uT(
"entity")] = pTexture;
5692 EXPECT_CALL(GLProxy, GenFramebuffers(1))
5694 .WillOnce(Return(FrameBufferId));
5696 EXPECT_CALL(GLProxy, GenTextures(1))
5699 auto Render = itCreator->second(Component_t::Make(
5701 { uT(
"service"), Object_t{ _pDataTexture } }
5703 ASSERT_NE(
nullptr, Render);
5705 const auto TestCallActivateTexture = [&](void)
5707 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5710 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5713 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5715 .WillOnce(Return(&ProgramId));
5717 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5719 .WillOnce(Return(LocationId));
5721 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
5724 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5730 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5732 .WillOnce(Return(
false));
5734 EXPECT_CALL(GLProxy, BindFramebuffer(_, _))
5737 TestCallActivateTexture();
5742 EXPECT_CALL(oMapperProxy, Map(
nullptr))
5744 .WillOnce(Return(
true));
5746 EXPECT_CALL(GLProxy, GetIntegerv(GL_FRAMEBUFFER_BINDING))
5748 .WillOnce(Return(&DefaultFrameBufferId));
5750 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, FrameBufferId))
5753 EXPECT_CALL(GLProxy, FramebufferTexture2D(GL_FRAMEBUFFER,
5754 GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, TextureId, 0))
5757 EXPECT_CALL(GLProxy, GetReadPixelsRawData())
5759 .WillOnce(Return(_RawData));
5761 EXPECT_CALL(GLProxy, ReadPixels(0, 0, Width, Height, GL_RGBA,
5762 GL_UNSIGNED_BYTE, pTexture->m_ReadCopyData.data()))
5765 EXPECT_CALL(oMapperProxy, CheckData(_ExpectData))
5768 EXPECT_CALL(oMapperProxy, Map(pTexture->m_ReadCopyData.data()))
5771 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, DefaultFrameBufferId))
5774 TestCallActivateTexture();
5779 EXPECT_CALL(GLProxy, DeleteFramebuffers(1, FrameBufferId))
5782 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5786 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
5788 { uT(
"albedo"),
"TexAlbedo" },
5789 { uT(
"metalness"),
"TexMetalness" },
5790 { uT(
"roughness"),
"TexRoughness" },
5791 { uT(
"normal"),
"TexNormal" },
5792 { uT(
"occlusion"),
"TexOcclusion" },
5795 for (::std::size_t i = 0; i < Destinations.size(); i++)
5797 const ::std::vector<uint32_t> RawData =
5799 0x10221334, 0x10221335, 0x10221336,
5800 0x10221337, 0x10221338, 0x10221339,
5801 0x10221340, 0x10221341, 0x10221342,
5802 0x10221343, 0x10221344, 0x10221345,
5805 const ::std::vector<uint32_t> ExpectData =
5807 0x10221343, 0x10221344, 0x10221345,
5808 0x10221340, 0x10221341, 0x10221342,
5809 0x10221337, 0x10221338, 0x10221339,
5810 0x10221334, 0x10221335, 0x10221336,
5813 const auto pData = Component_t::Make(
5815 { uT(
"kind"), uT(
"Texture") },
5816 { uT(
"width"), Width },
5817 { uT(
"height"), Height },
5818 { uT(
"mapper"), Mapper },
5819 { uT(
"destination"), Destinations[i].first },
5820 { uT(
"capacity"), 32 },
5823 TestCall(pData, i, Destinations[i].second, RawData, ExpectData);
5828TEST_F(OpenGLShader_test, Test_Texture_Depth_NameAndIndex)
5830 using GLProxy_t = ::mock::GLProxy;
5832 GLProxy_t::GetInstance() = &GLProxy;
5834 const Tested_t Example{ Data_t{} };
5835 const ITested_t & IExample = Example;
5837 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
5838 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5840 const ::mock::GLuint TextureId = 1910041336;
5841 const ::mock::GLint ProgramId = 1910041337;
5842 const ::mock::GLint LocationId = 1910041338;
5844 const auto TestCall = [&](
5845 const Component_t::ComponentPtr_t & _pTexture,
5846 const ::std::vector<uint8_t> & _Source,
5847 const int _Width,
const int _Height,
5848 const ::std::size_t _Index,
5849 const ::std::string & _TexName)
5851 const auto Index =
static_cast<::mock::GLint
>(_Index);
5853 using namespace ::testing;
5857 EXPECT_CALL(GLProxy, GenTextures(1))
5859 .WillOnce(Return(TextureId));
5861 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5864 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
5866 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, _Source))
5869 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
5872 EXPECT_CALL(GLProxy, GetError())
5874 .WillOnce(Return(GL_NO_ERROR));
5876 auto Render = itCreator->second(_pTexture);
5877 ASSERT_NE(
nullptr, Render);
5879 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
5882 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5885 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
5887 .WillOnce(Return(&ProgramId));
5889 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
5891 .WillOnce(Return(LocationId));
5893 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
5896 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
5901 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
5905 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
5907 { uT(
"TexEnvironment"),
"TexEnvironment" },
5908 { uT(
"TexReflection"),
"TexReflection" },
5909 { uT(
"TexBaseColor"),
"TexBaseColor" },
5912 for (
int Index = 0; Index < Names.size(); Index++)
5914 ::std::vector<uint8_t> Source =
5916 0x20, 0x06, 0x15, 0x12, 0x32,
5917 0x20, 0x06, 0x15, 0x12, 0x32,
5918 0x20, 0x06, 0x15, 0x12, 0x32,
5919 0x20, 0x06, 0x15, 0x12, 0x32,
5920 0x20, 0x06, 0x15, 0x12, 0x32,
5922 IntroduceBufferSize(Source);
5925 const int Width = 1910041343;
5926 const int Height = 1910041344;
5928 const auto pTexture = Component_t::Make(
5930 { uT(
"content"), Source },
5931 { uT(
"width"), Width },
5932 { uT(
"height"), Height },
5933 { uT(
"name"), Names[Index].first },
5934 { uT(
"index"), Index },
5935 { uT(
"destination"), uT(
"depth") },
5938 TestCall(pTexture, Source, Width, Height, Index, Names[Index].second);
5942 const int Width = 1910041346;
5943 const int Height = 1910041347;
5945 const auto pData = Component_t::Make(
5947 { uT(
"kind"), uT(
"Texture") },
5948 { uT(
"content"), Source },
5949 { uT(
"width"), Width },
5950 { uT(
"height"), Height },
5951 { uT(
"name"), Names[Index].first },
5952 { uT(
"index"), Index },
5953 { uT(
"destination"), uT(
"depth") },
5956 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
5957 Source, Width, Height, Index, Names[Index].second);
5963TEST_F(OpenGLShader_test, Test_Texture_Depth_Destination)
5965 using GLProxy_t = ::mock::GLProxy;
5967 GLProxy_t::GetInstance() = &GLProxy;
5969 const Tested_t Example{ Data_t{} };
5970 const ITested_t & IExample = Example;
5972 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
5973 ASSERT_NE(IExample.GetCreators().end(), itCreator);
5975 const ::mock::GLuint TextureId = 1910041336;
5976 const ::mock::GLint ProgramId = 1910041337;
5977 const ::mock::GLint LocationId = 1910041338;
5979 const auto TestCall = [&](
5980 const Component_t::ComponentPtr_t & _pTexture,
5981 const ::std::vector<uint8_t> & _Source,
5982 const int _Width,
const int _Height,
5983 const ::std::size_t _Index,
5984 const ::std::string & _TexName)
5986 const auto Index =
static_cast<::mock::GLint
>(_Index);
5988 using namespace ::testing;
5992 EXPECT_CALL(GLProxy, GenTextures(1))
5994 .WillOnce(Return(TextureId));
5996 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
5999 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
6001 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, _Source))
6004 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
6007 EXPECT_CALL(GLProxy, GetError())
6009 .WillOnce(Return(GL_NO_ERROR));
6011 auto Render = itCreator->second(_pTexture);
6012 ASSERT_NE(
nullptr, Render);
6014 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
6017 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6020 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6022 .WillOnce(Return(&ProgramId));
6024 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
6026 .WillOnce(Return(LocationId));
6028 EXPECT_CALL(GLProxy, GetUniformLocation(_, Eq(
"TexDiffuse")))
6031 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
6036 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6040 ::std::vector<uint8_t> Source =
6042 0x20, 0x06, 0x15, 0x12, 0x32,
6043 0x20, 0x06, 0x15, 0x12, 0x32,
6044 0x20, 0x06, 0x15, 0x12, 0x32,
6045 0x20, 0x06, 0x15, 0x12, 0x32,
6046 0x20, 0x06, 0x15, 0x12, 0x32,
6048 IntroduceBufferSize(Source);
6051 const int Width = 1910041343;
6052 const int Height = 1910041344;
6054 const auto pTexture = Component_t::Make(
6056 { uT(
"content"), Source },
6057 { uT(
"width"), Width },
6058 { uT(
"height"), Height },
6059 { uT(
"destination"), uT(
"depth") },
6062 TestCall(pTexture, Source, Width, Height, 5,
"TexDepth");
6066 const int Width = 1910041346;
6067 const int Height = 1910041347;
6069 const auto pData = Component_t::Make(
6071 { uT(
"kind"), uT(
"Texture") },
6072 { uT(
"content"), Source },
6073 { uT(
"width"), Width },
6074 { uT(
"height"), Height },
6075 { uT(
"destination"), uT(
"depth") },
6078 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6079 Source, Width, Height, 5,
"TexDepth");
6084TEST_F(OpenGLShader_test, Test_Texture_UsingExists_NameAndIndex)
6086 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
6088 using GLProxy_t = ::mock::GLProxy;
6090 GLProxy_t::GetInstance() = &GLProxy;
6092 const Tested_t Example{ Data_t{} };
6093 const ITested_t & IExample = Example;
6095 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
6096 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6098 const ::mock::GLuint TextureId = 1908221839;
6099 const ::mock::GLint ProgramId = 1908221840;
6100 const ::mock::GLint LocationId = 1908221841;
6102 const auto TestCall = [&](
6103 const Component_t::ComponentPtr_t & _pData,
6104 const Component_t::ComponentPtr_t & _pTexture,
6105 const ::std::vector<uint8_t> & _Source,
6106 const int _Width,
const int _Height,
6107 const ::std::size_t _Index,
6108 const ::std::string & _TexName)
6110 const ::covellite::api::renderer::Component::Texture TextureData{ *_pData, uT(
"") };
6111 const auto Index =
static_cast<::mock::GLint
>(_Index);
6113 using namespace ::testing;
6117 EXPECT_CALL(GLProxy, GenTextures(1))
6119 .WillOnce(Return(TextureId));
6121 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6124 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, _,
6125 _Width, _Height, 0, _, _, _Source))
6128 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
6131 EXPECT_CALL(GLProxy, GetError())
6133 .WillOnce(Return(GL_NO_ERROR));
6135 (*_pData)[uT(
"entity")] = ::std::make_shared<Texture_t>(TextureData);
6137 EXPECT_CALL(GLProxy, GenTextures(_))
6140 auto Render = itCreator->second(_pTexture);
6141 ASSERT_NE(
nullptr, Render);
6143 const Texture_t::Ptr_t pEntity = (*_pData)[uT(
"entity")].Default(Texture_t::Ptr_t{});
6144 EXPECT_EQ(
nullptr, pEntity);
6146 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
6149 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6152 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6154 .WillOnce(Return(&ProgramId));
6156 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
6158 .WillOnce(Return(LocationId));
6160 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
6165 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6169 const ::std::vector<::std::pair<String_t, ::std::string>> Names =
6171 { uT(
"TexEnvironment"),
"TexEnvironment" },
6172 { uT(
"TexReflection"),
"TexReflection" },
6173 { uT(
"TexBaseColor"),
"TexBaseColor" },
6176 for (
int Index = 0; Index < Names.size(); Index++)
6178 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
6180 { uT(
"albedo"),
"TexAlbedo" },
6181 { uT(
"metalness"),
"TexMetalness" },
6182 { uT(
"roughness"),
"TexRoughness" },
6183 { uT(
"normal"),
"TexNormal" },
6184 { uT(
"occlusion"),
"TexOcclusion" },
6185 { uT(
"depth"),
"TexDepth" },
6188 ::std::vector<uint8_t> Source =
6190 0x20, 0x06, 0x15, 0x12, 0x33,
6191 0x20, 0x06, 0x15, 0x12, 0x33,
6192 0x20, 0x06, 0x15, 0x12, 0x33,
6193 0x20, 0x06, 0x15, 0x12, 0x33,
6194 0x20, 0x06, 0x15, 0x12, 0x33,
6196 IntroduceBufferSize(Source);
6198 for (::std::size_t i = 0; i < Destinations.size(); i++)
6200 const int Width = 1908221845;
6201 const int Height = 1908221847;
6203 const auto pData = Component_t::Make(
6205 { uT(
"kind"), uT(
"Texture") },
6206 { uT(
"content"), Source },
6207 { uT(
"width"), Width },
6208 { uT(
"height"), Height },
6209 { uT(
"name"), Names[Index].first },
6210 { uT(
"index"), Index },
6211 { uT(
"destination"), Destinations[i].first },
6214 TestCall(pData, Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6215 Source, Width, Height, Index, Names[Index].second);
6221TEST_F(OpenGLShader_test, Test_Texture_UsingExists_Destination)
6223 using Texture_t = ::covellite::api::renderer::OpenGLCommon::Texture;
6225 using GLProxy_t = ::mock::GLProxy;
6227 GLProxy_t::GetInstance() = &GLProxy;
6229 const Tested_t Example{ Data_t{} };
6230 const ITested_t & IExample = Example;
6232 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
6233 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6235 const ::mock::GLuint TextureId = 1908221839;
6236 const ::mock::GLint ProgramId = 1908221840;
6237 const ::mock::GLint LocationId = 1908221841;
6239 const auto TestCall = [&](
6240 const Component_t::ComponentPtr_t & _pData,
6241 const Component_t::ComponentPtr_t & _pTexture,
6242 const ::std::vector<uint8_t> & _Source,
6243 const int _Width,
const int _Height,
6244 const ::std::size_t _Index,
6245 const ::std::string & _TexName)
6247 const ::covellite::api::renderer::Component::Texture TextureData{ *_pData, uT(
"") };
6248 const auto Index =
static_cast<::mock::GLint
>(_Index);
6250 using namespace ::testing;
6254 EXPECT_CALL(GLProxy, GenTextures(1))
6256 .WillOnce(Return(TextureId));
6258 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6261 EXPECT_CALL(GLProxy, TexImage2D(GL_TEXTURE_2D, 0, _,
6262 _Width, _Height, 0, _, _, _Source))
6265 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, 0))
6268 EXPECT_CALL(GLProxy, GetError())
6270 .WillOnce(Return(GL_NO_ERROR));
6272 (*_pData)[uT(
"entity")] = ::std::make_shared<Texture_t>(TextureData);
6274 EXPECT_CALL(GLProxy, GenTextures(_))
6277 auto Render = itCreator->second(_pTexture);
6278 ASSERT_NE(
nullptr, Render);
6280 const Texture_t::Ptr_t pEntity = (*_pData)[uT(
"entity")].Default(Texture_t::Ptr_t{});
6281 EXPECT_EQ(
nullptr, pEntity);
6283 EXPECT_CALL(GLProxy, ActiveTexture(GL_TEXTURE0 + Index))
6286 EXPECT_CALL(GLProxy, BindTexture(GL_TEXTURE_2D, TextureId))
6289 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6291 .WillOnce(Return(&ProgramId));
6293 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, _TexName))
6295 .WillOnce(Return(LocationId));
6297 EXPECT_CALL(GLProxy, Uniform1i(LocationId, Index))
6302 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6306 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
6308 { uT(
"albedo"),
"TexAlbedo" },
6309 { uT(
"metalness"),
"TexMetalness" },
6310 { uT(
"roughness"),
"TexRoughness" },
6311 { uT(
"normal"),
"TexNormal" },
6312 { uT(
"occlusion"),
"TexOcclusion" },
6313 { uT(
"depth"),
"TexDepth" },
6316 ::std::vector<uint8_t> Source =
6318 0x20, 0x06, 0x15, 0x12, 0x33,
6319 0x20, 0x06, 0x15, 0x12, 0x33,
6320 0x20, 0x06, 0x15, 0x12, 0x33,
6321 0x20, 0x06, 0x15, 0x12, 0x33,
6322 0x20, 0x06, 0x15, 0x12, 0x33,
6324 IntroduceBufferSize(Source);
6326 for (::std::size_t i = 0; i < Destinations.size(); i++)
6328 const int Width = 1908221845;
6329 const int Height = 1908221847;
6331 const auto pData = Component_t::Make(
6333 { uT(
"kind"), uT(
"Texture") },
6334 { uT(
"content"), Source },
6335 { uT(
"width"), Width },
6336 { uT(
"height"), Height },
6337 { uT(
"destination"), Destinations[i].first },
6340 TestCall(pData, Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6341 Source, Width, Height, i, Destinations[i].second);
6346TEST_F(OpenGLShader_test, Test_Texture_NoDeclaredInShader)
6348 using GLProxy_t = ::mock::GLProxy;
6350 GLProxy_t::GetInstance() = &GLProxy;
6352 const Tested_t Example{ Data_t{} };
6353 const ITested_t & IExample = Example;
6355 auto itCreator = IExample.GetCreators().find(uT(
"Texture"));
6356 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6358 const ::mock::GLuint TextureId = 1908221839;
6360 const auto TestCall = [&](
6361 const Component_t::ComponentPtr_t & _pTexture,
6362 const ::std::vector<uint8_t> & ,
6363 const int ,
const int ,
6364 const ::std::size_t _Index,
6365 const ::std::string & _TexName)
6367 const auto Index =
static_cast<::mock::GLint
>(_Index);
6369 using namespace ::testing;
6373 EXPECT_CALL(GLProxy, GenTextures(1))
6375 .WillOnce(Return(TextureId));
6377 auto Render = itCreator->second(_pTexture);
6378 ASSERT_NE(
nullptr, Render);
6380 EXPECT_CALL(GLProxy, GetUniformLocation(_, _TexName))
6382 .WillOnce(Return(-1));
6384 EXPECT_CALL(GLProxy, Uniform1i(_, _))
6389 EXPECT_CALL(GLProxy, DeleteTextures(1, TextureId))
6393 const ::std::vector<::std::pair<String_t, ::std::string>> Destinations =
6395 { uT(
"albedo"),
"TexAlbedo" },
6396 { uT(
"metalness"),
"TexMetalness" },
6397 { uT(
"roughness"),
"TexRoughness" },
6398 { uT(
"normal"),
"TexNormal" },
6399 { uT(
"occlusion"),
"TexOcclusion" },
6400 { uT(
"depth"),
"TexDepth" },
6403 ::std::vector<uint8_t> Source =
6405 0x20, 0x06, 0x15, 0x12, 0x34,
6406 0x20, 0x06, 0x15, 0x12, 0x34,
6407 0x20, 0x06, 0x15, 0x12, 0x34,
6408 0x20, 0x06, 0x15, 0x12, 0x34,
6409 0x20, 0x06, 0x15, 0x12, 0x34,
6411 IntroduceBufferSize(Source);
6413 for (::std::size_t i = 0; i < Destinations.size(); i++)
6416 const uint8_t * pSource = (uint8_t *)1908221842;
6417 const int Width = 1908221843;
6418 const int Height = 1908221844;
6420 const auto pTexture = Component_t::Make(
6422 { uT(
"content"), Source },
6423 { uT(
"width"), Width },
6424 { uT(
"height"), Height },
6425 { uT(
"destination"), Destinations[i].first },
6429 Source, Width, Height, i, Destinations[i].second);
6433 const uint8_t * pSource = (uint8_t *)1908221846;
6434 const int Width = 1908221845;
6435 const int Height = 1908221847;
6437 const auto pData = Component_t::Make(
6439 { uT(
"kind"), uT(
"Texture") },
6440 { uT(
"content"), Source },
6441 { uT(
"width"), Width },
6442 { uT(
"height"), Height },
6443 { uT(
"destination"), Destinations[i].first },
6446 TestCall(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }),
6447 Source, Width, Height, i, Destinations[i].second);
6453TEST_F(OpenGLShader_test, Test_Buffer_Fail)
6455 using GLProxy_t = ::mock::GLProxy;
6457 GLProxy_t::GetInstance() = &GLProxy;
6459 const Tested_t Example{ Data_t{} };
6460 const ITested_t & IExample = Example;
6462 auto itCreator = IExample.GetCreators().find(uT(
"Buffer"));
6463 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6465 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent)
6467 using namespace ::testing;
6471 EXPECT_CALL(GLProxy, GenBuffers(_))
6474 EXPECT_CALL(GLProxy, GetError())
6476 .WillOnce(Return(1908232144));
6478 EXPECT_THROW(itCreator->second(_pComponent), ::std::exception);
6482 const ::std::vector<::covellite::api::Vertex> Source;
6484 const auto pBuffer = Component_t::Make(
6486 { uT(
"content"), Source },
6489 TestCallRender(pBuffer);
6491 const auto pData = Component_t::Make(
6493 { uT(
"kind"), uT(
"Buffer") },
6494 { uT(
"content"), Source },
6497 TestCallRender(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
6501 using BufferMapper_t =
6502 ::covellite::api::cbBufferMap_t<::covellite::api::Vertex>;
6503 const ::std::vector<::covellite::api::Vertex> Source;
6507 const auto pBuffer = Component_t::Make(
6509 { uT(
"content"), Source },
6510 { uT(
"mapper"), Mapper },
6513 TestCallRender(pBuffer);
6515 const auto pData = Component_t::Make(
6517 { uT(
"kind"), uT(
"Buffer") },
6518 { uT(
"content"), Source },
6519 { uT(
"mapper"), Mapper },
6522 TestCallRender(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
6527TEST_F(OpenGLShader_test, Test_Buffer_Vertex_Static)
6531 using GLProxy_t = ::mock::GLProxy;
6533 GLProxy_t::GetInstance() = &GLProxy;
6535 const ::mock::GLuint BufferId = 1908231206;
6536 const ::mock::GLint ProgramId = 1908231246;
6537 const ::mock::GLint PositionId = 1908231301;
6538 const ::mock::GLint TexCoordId = 1908231302;
6539 const ::mock::GLint ExtraId = 1908231304;
6541 ::std::vector<Vertex_t> Source =
6544 1808261932.0f, 1808261933.0f, 1812161256.0f, 1808261934.0f,
6545 1812161257.0f, 1808261935.0f,
6546 1808261936.0f, 1812161258.0f, 1908201939.0f, 1908201940.0f
6549 1808261932.0f, 1808261933.0f, 1812161259.0f, 1808261934.0f,
6550 1812161300.0f, 1808261935.0f,
6551 1808261936.0f, 1812161301.0f, 1908201941.0f, 1908201942.0f
6553 { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f },
6556 IntroduceBufferSize(Source);
6558 const ::mock::GLProxy::Floats_t ExpectedVertexData =
6560 Source[0].px, Source[0].py, Source[0].pz,
6561 Source[1].px, Source[1].py, Source[1].pz,
6564 const ::mock::GLProxy::Floats_t ExpectedTexCoordData =
6566 Source[0].tu, Source[0].tv,
6567 Source[1].tu, Source[1].tv,
6570 const ::mock::GLProxy::Floats_t ExpectedNormalData =
6572 Source[0].ex, Source[0].ey, Source[0].ez,
6573 Source[1].ex, Source[1].ey, Source[1].ez,
6576 const Tested_t Example{ Data_t{} };
6577 const ITested_t & IExample = Example;
6579 auto itCreator = IExample.GetCreators().find(uT(
"Buffer"));
6580 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6582 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent)
6584 using namespace ::testing;
6588 EXPECT_CALL(GLProxy, GenBuffers(1))
6590 .WillOnce(Return(BufferId));
6592 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
6596 static_cast<::mock::GLsizeiptr
>(Source.size() *
sizeof(Vertex_t));
6598 EXPECT_CALL(GLProxy, BufferData(GL_ARRAY_BUFFER, Size,
6599 GetExpected(Source), GL_STATIC_DRAW))
6602 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
6605 EXPECT_CALL(GLProxy, GetError())
6607 .WillOnce(Return(GL_NO_ERROR));
6609 const auto Render = itCreator->second(_pComponent);
6610 ASSERT_NE(
nullptr, Render);
6612 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
6615 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6617 .WillOnce(Return(&ProgramId));
6619 EXPECT_CALL(GLProxy,
6620 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexPosition")))
6622 .WillOnce(Return(PositionId));
6624 EXPECT_CALL(GLProxy, EnableVertexAttribArray(PositionId))
6627 EXPECT_CALL(GLProxy, VertexAttribPointer(PositionId, 4, GL_FLOAT, GL_FALSE,
6628 sizeof(Vertex_t), (
void*)0))
6631 EXPECT_CALL(GLProxy, VertexAttribDivisor(PositionId, 0))
6634 EXPECT_CALL(GLProxy,
6635 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexTexCoord")))
6637 .WillOnce(Return(TexCoordId));
6639 EXPECT_CALL(GLProxy, EnableVertexAttribArray(TexCoordId))
6642 EXPECT_CALL(GLProxy, VertexAttribPointer(TexCoordId, 2, GL_FLOAT, GL_FALSE,
6643 sizeof(Vertex_t), (
void*)(
sizeof(
float) * 4)))
6646 EXPECT_CALL(GLProxy, VertexAttribDivisor(TexCoordId, 0))
6649 EXPECT_CALL(GLProxy,
6650 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexExtra")))
6652 .WillOnce(Return(ExtraId));
6654 EXPECT_CALL(GLProxy, EnableVertexAttribArray(ExtraId))
6657 EXPECT_CALL(GLProxy, VertexAttribPointer(ExtraId, 4, GL_FLOAT, GL_FALSE,
6658 sizeof(Vertex_t), (
void*)(
sizeof(
float) * 6)))
6661 EXPECT_CALL(GLProxy, VertexAttribDivisor(ExtraId, 0))
6664 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
6669 EXPECT_CALL(GLProxy, DeleteBuffers(1, BufferId))
6676 const auto pBuffer = Component_t::Make(
6678 { uT(
"content"), Source },
6681 TestCallRender(pBuffer);
6687 const auto pData = Component_t::Make(
6689 { uT(
"kind"), uT(
"Buffer") },
6690 { uT(
"content"), Source },
6693 TestCallRender(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
6698TEST_F(OpenGLShader_test, Test_Buffer_Vertex_Dynamic)
6701 using BufferMapper_t = ::covellite::api::cbBufferMap_t<Vertex_t>;
6704 public ::alicorn::extension::testing::Proxy<Proxy>
6707 MOCK_METHOD1(Mapper,
bool(Vertex_t *));
6711 Proxy::GetInstance() = &oProxy;
6713 using GLProxy_t = ::mock::GLProxy;
6715 GLProxy_t::GetInstance() = &GLProxy;
6717 const ::mock::GLuint BufferId = 1908232202;
6718 const ::mock::GLint ProgramId = 1908232203;
6719 const ::mock::GLint PositionId = 1908232204;
6720 const ::mock::GLint TexCoordId = 1908232205;
6721 const ::mock::GLint ExtraId = 1908232206;
6723 ::std::vector<Vertex_t> Source1 =
6726 1808261932.0f, 1808261933.0f, 1812161256.0f, 1808261934.0f,
6727 1812161257.0f, 1808261935.0f,
6728 1808261936.0f, 1812161258.0f, 1908201945.0f, 1908201946.0f
6731 1808261932.0f, 1808261933.0f, 1812161259.0f, 1808261934.0f,
6732 1812161300.0f, 1808261935.0f,
6733 1808261936.0f, 1812161301.0f, 1908201947.0f, 1908201948.0f
6735 { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f },
6738 IntroduceBufferSize(Source1);
6740 const ::std::vector<::mock::GLfloat> Source2 =
6742 1908011341.0f, 1908261933.0f, 1912161256.0f, 1908261934.0f,
6743 1912161257.0f, 1908261935.0f,
6744 1908261936.0f, 1912161258.0f, 1908201949.0f, 1908201950.0f,
6745 1908261932.0f, 1908261933.0f, 1912161259.0f, 1908261934.0f,
6746 1912161300.0f, 1908261935.0f,
6747 1908261936.0f, 1912161301.0f, 1908201951.0f, 1908201952.0f,
6750 const BufferMapper_t Mapper = [&](Vertex_t * _pData)
6752 if (_pData !=
nullptr)
6754 memcpy(_pData, Source2.data(),
sizeof(::mock::GLfloat) * Source2.size());
6757 return oProxy.Mapper(_pData);
6760 const Tested_t Example{ Data_t{} };
6761 const ITested_t & IExample = Example;
6763 auto itCreator = IExample.GetCreators().find(uT(
"Buffer"));
6764 ASSERT_NE(IExample.GetCreators().end(), itCreator);
6766 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent)
6768 using namespace ::testing;
6772 EXPECT_CALL(GLProxy, GenBuffers(1))
6774 .WillOnce(Return(BufferId));
6776 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
6780 static_cast<::mock::GLsizeiptr
>(Source1.size() *
sizeof(Vertex_t));
6782 EXPECT_CALL(GLProxy, BufferData(GL_ARRAY_BUFFER, Size,
6783 GetExpected(Source1), GL_DYNAMIC_DRAW))
6786 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
6789 EXPECT_CALL(GLProxy, GetError())
6791 .WillOnce(Return(GL_NO_ERROR));
6793 const auto Render = itCreator->second(_pComponent);
6794 ASSERT_NE(
nullptr, Render);
6797 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
6800 EXPECT_CALL(oProxy, Mapper(
nullptr))
6802 .WillOnce(Return(
false));
6804 EXPECT_CALL(oProxy, Mapper(_))
6807 EXPECT_CALL(GLProxy, BufferSubData(_, _, _, _))
6810 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6812 .WillOnce(Return(&ProgramId));
6814 EXPECT_CALL(GLProxy,
6815 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexPosition")))
6817 .WillOnce(Return(PositionId));
6819 EXPECT_CALL(GLProxy, EnableVertexAttribArray(PositionId))
6822 EXPECT_CALL(GLProxy, VertexAttribPointer(PositionId, 4, GL_FLOAT, GL_FALSE,
6823 sizeof(Vertex_t), (
void*)0))
6826 EXPECT_CALL(GLProxy, VertexAttribDivisor(PositionId, 0))
6829 EXPECT_CALL(GLProxy,
6830 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexTexCoord")))
6832 .WillOnce(Return(TexCoordId));
6834 EXPECT_CALL(GLProxy, EnableVertexAttribArray(TexCoordId))
6837 EXPECT_CALL(GLProxy, VertexAttribPointer(TexCoordId, 2, GL_FLOAT, GL_FALSE,
6838 sizeof(Vertex_t), (
void*)(
sizeof(
float) * 4)))
6841 EXPECT_CALL(GLProxy, VertexAttribDivisor(TexCoordId, 0))
6844 EXPECT_CALL(GLProxy,
6845 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexExtra")))
6847 .WillOnce(Return(ExtraId));
6849 EXPECT_CALL(GLProxy, EnableVertexAttribArray(ExtraId))
6852 EXPECT_CALL(GLProxy, VertexAttribPointer(ExtraId, 4, GL_FLOAT, GL_FALSE,
6853 sizeof(Vertex_t), (
void*)(
sizeof(
float) * 6)))
6856 EXPECT_CALL(GLProxy, VertexAttribDivisor(ExtraId, 0))
6859 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
6866 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
6869 EXPECT_CALL(oProxy, Mapper(
nullptr))
6871 .WillOnce(Return(
true));
6873 EXPECT_CALL(oProxy, Mapper(_))
6876 EXPECT_CALL(GLProxy, BufferSubData(GL_ARRAY_BUFFER, 0, Size, Source2))
6879 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
6881 .WillOnce(Return(&ProgramId));
6883 EXPECT_CALL(GLProxy,
6884 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexPosition")))
6886 .WillOnce(Return(PositionId));
6888 EXPECT_CALL(GLProxy, EnableVertexAttribArray(PositionId))
6891 EXPECT_CALL(GLProxy, VertexAttribPointer(PositionId, 4, GL_FLOAT, GL_FALSE,
6892 sizeof(Vertex_t), (
void*)0))
6895 EXPECT_CALL(GLProxy, VertexAttribDivisor(PositionId, 0))
6898 EXPECT_CALL(GLProxy,
6899 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexTexCoord")))
6901 .WillOnce(Return(TexCoordId));
6903 EXPECT_CALL(GLProxy, EnableVertexAttribArray(TexCoordId))
6906 EXPECT_CALL(GLProxy, VertexAttribPointer(TexCoordId, 2, GL_FLOAT, GL_FALSE,
6907 sizeof(Vertex_t), (
void*)(
sizeof(
float) * 4)))
6910 EXPECT_CALL(GLProxy, VertexAttribDivisor(TexCoordId, 0))
6913 EXPECT_CALL(GLProxy,
6914 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexExtra")))
6916 .WillOnce(Return(ExtraId));
6918 EXPECT_CALL(GLProxy, EnableVertexAttribArray(ExtraId))
6921 EXPECT_CALL(GLProxy, VertexAttribPointer(ExtraId, 4, GL_FLOAT, GL_FALSE,
6922 sizeof(Vertex_t), (
void*)(
sizeof(
float) * 6)))
6925 EXPECT_CALL(GLProxy, VertexAttribDivisor(ExtraId, 0))
6928 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
6934 EXPECT_CALL(GLProxy, DeleteBuffers(1, BufferId))
6941 const auto pBuffer = Component_t::Make(
6943 { uT(
"content"), Source1 },
6944 { uT(
"mapper"), Mapper },
6947 TestCallRender(pBuffer);
6953 const auto pData = Component_t::Make(
6955 { uT(
"kind"), uT(
"Buffer") },
6956 { uT(
"content"), Source1 },
6959 const auto pBuffer = Component_t::Make(
6961 { uT(
"mapper"), Mapper },
6962 { uT(
"service"), Object_t{ pData } }
6965 TestCallRender(pBuffer);
6970TEST_F(OpenGLShader_test, Test_Buffer_Vertex_IgnoreNotExistsVariables)
6973 using BufferMapper_t = ::covellite::api::cbBufferMap_t<Vertex_t>;
6975 using GLProxy_t = ::mock::GLProxy;
6977 GLProxy_t::GetInstance() = &GLProxy;
6979 const ::mock::GLuint BufferId = 1908231206;
6980 const ::mock::GLint ProgramId = 1908231246;
6982 ::std::vector<Vertex_t> Source =
6985 1808261932.0f, 1808261933.0f, 1812161256.0f, 1808261934.0f,
6986 1812161257.0f, 1808261935.0f,
6987 1808261936.0f, 1812161258.0f, 1908201939.0f, 1908201940.0f
6990 1808261932.0f, 1808261933.0f, 1812161259.0f, 1808261934.0f,
6991 1812161300.0f, 1808261935.0f,
6992 1808261936.0f, 1812161301.0f, 1908201941.0f, 1908201942.0f
6994 { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f },
6997 IntroduceBufferSize(Source);
6999 const Tested_t Example{ Data_t{} };
7000 const ITested_t & IExample = Example;
7002 auto itCreator = IExample.GetCreators().find(uT(
"Buffer"));
7003 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7005 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent)
7007 using namespace ::testing;
7011 EXPECT_CALL(GLProxy, GenBuffers(1))
7013 .WillOnce(Return(BufferId));
7015 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
7018 EXPECT_CALL(GLProxy, BufferData(GL_ARRAY_BUFFER, _, _, _))
7021 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
7024 EXPECT_CALL(GLProxy, GetError())
7026 .WillOnce(Return(GL_NO_ERROR));
7028 const auto Render = itCreator->second(_pComponent);
7029 ASSERT_NE(
nullptr, Render);
7031 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, BufferId))
7034 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
7036 .WillOnce(Return(&ProgramId));
7038 EXPECT_CALL(GLProxy,
7039 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexPosition")))
7041 .WillOnce(Return(-1));
7043 EXPECT_CALL(GLProxy, EnableVertexAttribArray(_))
7046 EXPECT_CALL(GLProxy, VertexAttribPointer(_, _, _, _, _, _))
7049 EXPECT_CALL(GLProxy, VertexAttribDivisor(_, _))
7052 EXPECT_CALL(GLProxy,
7053 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexTexCoord")))
7055 .WillOnce(Return(-1));
7057 EXPECT_CALL(GLProxy, EnableVertexAttribArray(_))
7060 EXPECT_CALL(GLProxy, VertexAttribPointer(_, _, _, _, _, _))
7063 EXPECT_CALL(GLProxy, VertexAttribDivisor(_, _))
7066 EXPECT_CALL(GLProxy,
7067 GetAttribLocation(ProgramId, Eq(
"Covellite_VertexExtra")))
7069 .WillOnce(Return(-1));
7071 EXPECT_CALL(GLProxy, EnableVertexAttribArray(_))
7074 EXPECT_CALL(GLProxy, VertexAttribPointer(_, _, _, _, _, _))
7077 EXPECT_CALL(GLProxy, VertexAttribDivisor(_, _))
7080 EXPECT_CALL(GLProxy, BindBuffer(GL_ARRAY_BUFFER, 0))
7085 EXPECT_CALL(GLProxy, DeleteBuffers(1, BufferId))
7092 const auto pBuffer = Component_t::Make(
7094 { uT(
"content"), Source },
7097 TestCallRender(pBuffer);
7103 const auto pData = Component_t::Make(
7105 { uT(
"kind"), uT(
"Buffer") },
7106 { uT(
"content"), Source },
7109 TestCallRender(Component_t::Make({ { uT(
"service"), Object_t{ pData } } }));
7117 const auto pBuffer = Component_t::Make(
7119 { uT(
"content"), Source },
7120 { uT(
"mapper"), BufferMapper_t{} },
7123 TestCallRender(pBuffer);
7129 const auto pData = Component_t::Make(
7131 { uT(
"kind"), uT(
"Buffer") },
7132 { uT(
"content"), Source },
7135 const auto pBuffer = Component_t::Make(
7137 { uT(
"mapper"), BufferMapper_t{} },
7138 { uT(
"service"), Object_t{ pData } }
7141 TestCallRender(pBuffer);
7146TEST_F(OpenGLShader_test, Test_Transform_Default)
7148 using GLProxy_t = ::mock::GLProxy;
7150 GLProxy_t::GetInstance() = &GLProxy;
7152 const Tested_t Example{ Data_t{} };
7153 const ITested_t & IExample = Example;
7155 const ::mock::GLint ProgramId = 1908241203;
7156 const ::mock::GLint MatrixWorldLocationId = 1908241207;
7158 auto itCreator = IExample.GetCreators().find(uT(
"Transform"));
7159 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7161 auto pPosition = Component_t::Make({ { uT(
"kind"), uT(
"Position") } });
7162 auto pRotation = Component_t::Make({ { uT(
"kind"), uT(
"Rotation") } });
7163 auto pScale = Component_t::Make({ { uT(
"kind"), uT(
"Scale") } });
7164 const auto pTransform = Component_t::Make(
7166 { uT(
"service"), Object_t{ pPosition, pRotation, pScale } }
7169 const auto Render = itCreator->second(pTransform);
7170 ASSERT_NE(
nullptr, Render);
7172 auto WorldMatrix = ::glm::identity<::glm::mat4>();
7174 auto TestCallRender = [&](
7175 float _X,
float _Y,
float _Z,
7176 float _A,
float _B,
float _C,
7177 float _Sx,
float _Sy,
float _Sz)
7179 (*pPosition)[uT(
"x")] = _X;
7180 (*pPosition)[uT(
"y")] = _Y;
7181 (*pPosition)[uT(
"z")] = _Z;
7183 (*pRotation)[uT(
"x")] = _A;
7184 (*pRotation)[uT(
"y")] = _B;
7185 (*pRotation)[uT(
"z")] = _C;
7187 (*pScale)[uT(
"x")] = _Sx;
7188 (*pScale)[uT(
"y")] = _Sy;
7189 (*pScale)[uT(
"z")] = _Sz;
7191 WorldMatrix = ::glm::identity<::glm::mat4>();
7192 WorldMatrix = ::glm::scale(WorldMatrix, { _Sx, _Sy, _Sz });
7193 WorldMatrix = ::glm::rotate(WorldMatrix, _C, { 0.0f, 0.0f, 1.0f });
7194 WorldMatrix = ::glm::rotate(WorldMatrix, _B, { 0.0f, 1.0f, 0.0f });
7195 WorldMatrix = ::glm::rotate(WorldMatrix, _A, { 1.0f, 0.0f, 0.0f });
7196 WorldMatrix = ::glm::translate(WorldMatrix, { _X, _Y, _Z });
7197 WorldMatrix = ::glm::transpose(WorldMatrix);
7199 using namespace ::testing;
7203 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
7205 .WillOnce(Return(&ProgramId));
7207 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"ObjectData.World")))
7209 .WillOnce(Return(MatrixWorldLocationId));
7211 EXPECT_CALL(GLProxy,
7212 UniformMatrix4fv(MatrixWorldLocationId, 1, GL_FALSE, WorldMatrix))
7222 1956.0f, 1957.0f, 1958.0f,
7223 1204.0f, 1205.0f, 1206.0f,
7224 1152.0f, 1153.0f, 1154.0f);
7227 1959.0f, 1960.0f, 1961.0f,
7228 1145.0f, 1146.0f, 1147.0f,
7229 1155.0f, 1157.0f, 1158.0f);
7233TEST_F(OpenGLShader_test, Test_Transform_Static)
7235 using GLProxy_t = ::mock::GLProxy;
7237 GLProxy_t::GetInstance() = &GLProxy;
7239 const Tested_t Example{ Data_t{} };
7240 const ITested_t & IExample = Example;
7242 const ::mock::GLint ProgramId = 1908241203;
7243 const ::mock::GLint MatrixWorldLocationId = 1908241207;
7245 auto itCreator = IExample.GetCreators().find(uT(
"Transform"));
7246 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7248 auto pPosition = Component_t::Make({ { uT(
"kind"), uT(
"Position") } });
7249 auto pRotation = Component_t::Make({ { uT(
"kind"), uT(
"Rotation") } });
7250 auto pScale = Component_t::Make({ { uT(
"kind"), uT(
"Scale") } });
7252 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pTransform)
7254 auto WorldMatrix = ::glm::identity<::glm::mat4>();
7256 auto SetValues = [&](
const bool _IsBuildMatrix,
7257 float _X,
float _Y,
float _Z,
7258 float _A,
float _B,
float _C,
7259 float _Sx,
float _Sy,
float _Sz)
7261 (*pPosition)[uT(
"x")] = _X;
7262 (*pPosition)[uT(
"y")] = _Y;
7263 (*pPosition)[uT(
"z")] = _Z;
7265 (*pRotation)[uT(
"x")] = _A;
7266 (*pRotation)[uT(
"y")] = _B;
7267 (*pRotation)[uT(
"z")] = _C;
7269 (*pScale)[uT(
"x")] = _Sx;
7270 (*pScale)[uT(
"y")] = _Sy;
7271 (*pScale)[uT(
"z")] = _Sz;
7275 WorldMatrix = ::glm::identity<::glm::mat4>();
7276 WorldMatrix = ::glm::scale(WorldMatrix, { _Sx, _Sy, _Sz });
7277 WorldMatrix = ::glm::rotate(WorldMatrix, _C, { 0.0f, 0.0f, 1.0f });
7278 WorldMatrix = ::glm::rotate(WorldMatrix, _B, { 0.0f, 1.0f, 0.0f });
7279 WorldMatrix = ::glm::rotate(WorldMatrix, _A, { 1.0f, 0.0f, 0.0f });
7280 WorldMatrix = ::glm::translate(WorldMatrix, { _X, _Y, _Z });
7281 WorldMatrix = ::glm::transpose(WorldMatrix);
7286 1956.0f, 1957.0f, 1958.0f,
7287 1204.0f, 1205.0f, 1206.0f,
7288 1152.0f, 1153.0f, 1154.0f);
7290 const auto Render = itCreator->second(_pTransform);
7291 ASSERT_NE(
nullptr, Render);
7293 auto TestCallRender = [&](void)
7295 using namespace ::testing;
7299 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
7301 .WillOnce(Return(&ProgramId));
7303 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"ObjectData.World")))
7305 .WillOnce(Return(MatrixWorldLocationId));
7307 EXPECT_CALL(GLProxy,
7308 UniformMatrix4fv(MatrixWorldLocationId, 1, GL_FALSE, WorldMatrix))
7320 1959.0f, 1960.0f, 1961.0f,
7321 1145.0f, 1146.0f, 1147.0f,
7322 1155.0f, 1157.0f, 1158.0f);
7327 const auto pTransform = Component_t::Make(
7329 { uT(
"kind"), uT(
"Static") },
7330 { uT(
"service"), Object_t{ pPosition, pRotation, pScale } }
7333 TestCallRender(pTransform);
7337TEST_F(OpenGLShader_test, Test_Transform_Billboard)
7339 using GLProxy_t = ::mock::GLProxy;
7341 GLProxy_t::GetInstance() = &GLProxy;
7343 Tested_t Example{ Data_t{} };
7344 const ITested_t & IExample = Example;
7346 const ::mock::GLint ProgramId = 1908241203;
7347 const ::mock::GLint MatrixWorldLocationId = 1908241207;
7349 auto itCreator = IExample.GetCreators().find(uT(
"Transform"));
7350 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7352 auto pPosition = Component_t::Make({ { uT(
"kind"), uT(
"Position") } });
7354 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pTransform)
7356 const auto Render = itCreator->second(_pTransform);
7357 ASSERT_NE(
nullptr, Render);
7359 auto WorldMatrix = ::glm::identity<::glm::mat4>();
7361 auto TestCallRender = [&](
float _X,
float _Y,
float _Z)
7363 (*pPosition)[uT(
"x")] = _X;
7364 (*pPosition)[uT(
"y")] = _Y;
7365 (*pPosition)[uT(
"z")] = _Z;
7367 WorldMatrix = ::glm::identity<::glm::mat4>();
7368 WorldMatrix = ::glm::translate(WorldMatrix, { _X, _Y, _Z });
7370 const auto ViewMatrix = ::glm::mat4
7372 { 1.0f, 2.0f, 3.0f, 4.0f },
7373 { 5.0f, 6.0f, 7.0f, 8.0f },
7374 { 9.0f, 10.0f, 11.0f, 12.0f },
7375 { 13.0f, 14.0f, 15.0f, 16.0f },
7378 GetCameraMartix(Example).View = ViewMatrix;
7380 auto TransposeViewMatrix = ViewMatrix;
7381 TransposeViewMatrix[0][3] = 0.0f;
7382 TransposeViewMatrix[1][3] = 0.0f;
7383 TransposeViewMatrix[2][3] = 0.0f;
7384 TransposeViewMatrix[3][0] = 0.0f;
7385 TransposeViewMatrix[3][1] = 0.0f;
7386 TransposeViewMatrix[3][2] = 0.0f;
7387 TransposeViewMatrix[3][3] = 1.0f;
7389 WorldMatrix = TransposeViewMatrix *
7390 ::glm::translate(::glm::identity<::glm::mat4>(), { _X, _Y, _Z });
7391 WorldMatrix = ::glm::transpose(WorldMatrix);
7393 using namespace ::testing;
7397 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
7399 .WillOnce(Return(&ProgramId));
7401 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"ObjectData.World")))
7403 .WillOnce(Return(MatrixWorldLocationId));
7405 EXPECT_CALL(GLProxy,
7406 UniformMatrix4fv(MatrixWorldLocationId, 1, GL_FALSE, WorldMatrix))
7415 TestCallRender(1956.0f, 1957.0f, 1958.0f);
7416 TestCallRender(1959.0f, 1960.0f, 1961.0f);
7419 const auto pTransform = Component_t::Make(
7421 { uT(
"kind"), uT(
"Billboard") },
7422 { uT(
"service"), Object_t{ pPosition } }
7425 TestCallRender(pTransform);
7429TEST_F(OpenGLShader_test, Test_Transform_DefaultValues)
7431 using GLProxy_t = ::mock::GLProxy;
7433 GLProxy_t::GetInstance() = &GLProxy;
7435 Tested_t Example{ Data_t{} };
7436 const ITested_t & IExample = Example;
7438 auto itCreator = IExample.GetCreators().find(uT(
"Transform"));
7439 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7441 auto pPosition = Component_t::Make({ { uT(
"kind"), uT(
"Position") } });
7442 auto pRotation = Component_t::Make({ { uT(
"kind"), uT(
"Rotation") } });
7443 auto pScale = Component_t::Make({ { uT(
"kind"), uT(
"Scale") } });
7445 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent,
7446 const bool _IsFullTransform =
true)
7448 const auto Render = itCreator->second(_pComponent);
7449 ASSERT_NE(
nullptr, Render);
7451 const auto ViewMatrix = ::glm::mat4
7453 { 1.0f, 2.0f, 3.0f, 4.0f },
7454 { 5.0f, 6.0f, 7.0f, 8.0f },
7455 { 9.0f, 10.0f, 11.0f, 12.0f },
7456 { 13.0f, 14.0f, 15.0f, 16.0f },
7459 GetCameraMartix(Example).View = ViewMatrix;
7461 auto WorldMatrix = ::glm::identity<::glm::mat4>();
7463 if (_IsFullTransform)
7465 WorldMatrix = ::glm::scale(WorldMatrix, { 1.0f, 1.0f, 1.0f });
7466 WorldMatrix = ::glm::transpose(WorldMatrix);
7470 auto TransposeViewMatrix = ViewMatrix;
7471 TransposeViewMatrix[0][3] = 0.0f;
7472 TransposeViewMatrix[1][3] = 0.0f;
7473 TransposeViewMatrix[2][3] = 0.0f;
7474 TransposeViewMatrix[3][0] = 0.0f;
7475 TransposeViewMatrix[3][1] = 0.0f;
7476 TransposeViewMatrix[3][2] = 0.0f;
7477 TransposeViewMatrix[3][3] = 1.0f;
7479 WorldMatrix = TransposeViewMatrix;
7480 WorldMatrix = ::glm::transpose(WorldMatrix);
7483 using namespace ::testing;
7485 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, WorldMatrix))
7491 TestCallRender(Component_t::Make(
7493 { uT(
"service"), Object_t{ pPosition, pRotation, pScale } }
7496 TestCallRender(Component_t::Make(
7498 { uT(
"kind"), uT(
"Static") },
7499 { uT(
"service"), Object_t{ pPosition, pRotation, pScale } }
7502 TestCallRender(Component_t::Make(
7504 { uT(
"kind"), uT(
"Billboard") },
7505 { uT(
"service"), Object_t{ pPosition, pRotation, pScale } }
7510TEST_F(OpenGLShader_test, Test_Transform_Combine)
7512 using GLProxy_t = ::mock::GLProxy;
7514 GLProxy_t::GetInstance() = &GLProxy;
7516 Tested_t Example{ Data_t{} };
7517 const ITested_t & IExample = Example;
7519 auto itCreator = IExample.GetCreators().find(uT(
"Transform"));
7520 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7522 auto MatrixIdentity = ::glm::identity<::glm::mat4>();
7524 ::std::deque<Component_t::ComponentPtr_t> Components;
7526 const auto SetPosition = [&](
float _X,
float _Y,
float _Z)
7528 Components.push_front(Component_t::Make(
7530 { uT(
"kind"), uT(
"Position") },
7536 MatrixIdentity = ::glm::translate(MatrixIdentity, { _X, _Y, _Z });
7539 const auto SetRotation = [&](
float _X,
float _Y,
float _Z)
7541 Components.push_front(Component_t::Make(
7543 { uT(
"kind"), uT(
"Rotation") },
7549 MatrixIdentity = ::glm::rotate(MatrixIdentity, _Z, { 0.0f, 0.0f, 1.0f });
7550 MatrixIdentity = ::glm::rotate(MatrixIdentity, _Y, { 0.0f, 1.0f, 0.0f });
7551 MatrixIdentity = ::glm::rotate(MatrixIdentity, _X, { 1.0f, 0.0f, 0.0f });
7554 const auto SetScale = [&](
float _X,
float _Y,
float _Z)
7556 Components.push_front(Component_t::Make(
7558 { uT(
"kind"), uT(
"Scale") },
7564 MatrixIdentity = ::glm::scale(MatrixIdentity, { _X, _Y, _Z });
7568 MatrixIdentity = ::glm::identity<::glm::mat4>();
7571 SetPosition(1.0f, 2.0f, 3.0f);
7572 SetRotation(4.0f, 5.0f, 6.0f);
7573 SetScale(7.0f, 8.0f, 9.0f);
7575 SetPosition(11.0f, 22.0f, 33.0f);
7576 SetRotation(44.0f, 55.0f, 66.0f);
7577 SetScale(77.0f, 88.0f, 99.0f);
7579 MatrixIdentity = ::glm::transpose(MatrixIdentity);
7581 auto Render = itCreator->second(Component_t::Make(
7583 { uT(
"service"), Object_t{ Components.begin(), Components.end() } }
7585 ASSERT_NE(
nullptr, Render);
7587 using namespace ::testing;
7591 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, MatrixIdentity))
7598 MatrixIdentity = ::glm::identity<::glm::mat4>();
7601 SetPosition(1.0f, 2.0f, 3.0f);
7602 SetRotation(4.0f, 5.0f, 6.0f);
7603 SetScale(7.0f, 8.0f, 9.0f);
7605 SetPosition(11.0f, 22.0f, 33.0f);
7606 SetRotation(44.0f, 55.0f, 66.0f);
7607 SetScale(77.0f, 88.0f, 99.0f);
7609 MatrixIdentity = ::glm::transpose(MatrixIdentity);
7611 auto Render = itCreator->second(Component_t::Make(
7613 { uT(
"kind"), uT(
"Static") },
7614 { uT(
"service"), Object_t{ Components.begin(), Components.end() } }
7616 ASSERT_NE(
nullptr, Render);
7618 using namespace ::testing;
7622 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, MatrixIdentity))
7629 const auto ViewMatrix = ::glm::mat4
7631 { 1.0f, 2.0f, 3.0f, 4.0f },
7632 { 5.0f, 6.0f, 7.0f, 8.0f },
7633 { 9.0f, 10.0f, 11.0f, 12.0f },
7634 { 13.0f, 14.0f, 15.0f, 16.0f },
7637 GetCameraMartix(Example).View = ViewMatrix;
7639 auto TransposeViewMatrix = ViewMatrix;
7640 TransposeViewMatrix[0][3] = 0.0f;
7641 TransposeViewMatrix[1][3] = 0.0f;
7642 TransposeViewMatrix[2][3] = 0.0f;
7643 TransposeViewMatrix[3][0] = 0.0f;
7644 TransposeViewMatrix[3][1] = 0.0f;
7645 TransposeViewMatrix[3][2] = 0.0f;
7646 TransposeViewMatrix[3][3] = 1.0f;
7648 MatrixIdentity = TransposeViewMatrix;
7651 SetPosition(1.0f, 2.0f, 3.0f);
7652 SetPosition(11.0f, 22.0f, 33.0f);
7653 SetPosition(111.0f, 222.0f, 333.0f);
7655 MatrixIdentity = ::glm::transpose(MatrixIdentity);
7657 auto Render = itCreator->second(Component_t::Make(
7659 { uT(
"kind"), uT(
"Billboard") },
7660 { uT(
"service"), Object_t{ Components.begin(), Components.end() } }
7662 ASSERT_NE(
nullptr, Render);
7664 using namespace ::testing;
7668 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, MatrixIdentity))
7676TEST_F(OpenGLShader_test, Test_Buffer_Constant_User_CreateBuffer_Error)
7678 using BufferMapper_t = ::covellite::api::cbBufferMap_t<void>;
7680 using GLProxy_t = ::mock::GLProxy;
7682 GLProxy_t::GetInstance() = &GLProxy;
7685 const BufferMapper_t BufferMapper = [&](
void *) {
return false; };
7687 const Tested_t oExample{ Data_t{} };
7688 const ITested_t & IExample = oExample;
7690 auto itConstBufferCreator = IExample.GetCreators().find(uT(
"Buffer"));
7691 ASSERT_NE(IExample.GetCreators().end(), itConstBufferCreator);
7693 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent)
7695 using namespace ::testing;
7699 EXPECT_CALL(GLProxy, GenBuffers(_))
7702 EXPECT_CALL(GLProxy, GetError())
7704 .WillOnce(Return(1909211243));
7706 EXPECT_THROW(itConstBufferCreator->second(_pComponent), ::std::exception);
7709 const auto pBuffer = Component_t::Make(
7711 { uT(
"mapper"), BufferMapper },
7712 { uT(
"size"),
sizeof(Data) },
7714 TestCallRender(pBuffer);
7718TEST_F(OpenGLShader_test, Test_Buffer_Constant_User_UpdateBuffer_NotExistsName)
7720 using BufferMapper_t = ::covellite::api::cbBufferMap_t<void>;
7722 using GLProxy_t = ::mock::GLProxy;
7724 GLProxy_t::GetInstance() = &GLProxy;
7726 const BufferMapper_t BufferMapper = [&](
void *) {
return false; };
7728 using namespace ::testing;
7730 const Tested_t oExample{ Data_t{} };
7731 const ITested_t & IExample = oExample;
7733 auto itConstBufferCreator = IExample.GetCreators().find(uT(
"Buffer"));
7734 ASSERT_NE(IExample.GetCreators().end(), itConstBufferCreator);
7736 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent)
7738 using namespace ::testing;
7740 const auto Render = itConstBufferCreator->second(_pComponent);
7741 ASSERT_NE(
nullptr, Render);
7745 EXPECT_CALL(GLProxy, GetUniformBlockIndex(_, _))
7747 .WillOnce(Return(GL_INVALID_INDEX));
7749 EXPECT_CALL(GLProxy, BindBuffer(_, _))
7752 EXPECT_CALL(GLProxy, UniformBufferSubData(_, _, _))
7755 EXPECT_CALL(GLProxy, BindBufferBase(_, _, _))
7758 EXPECT_CALL(GLProxy, UniformBlockBinding(_, _, _))
7764 const auto pBuffer = Component_t::Make(
7766 { uT(
"mapper"), BufferMapper },
7767 { uT(
"size"), ::std::size_t{ 4 } },
7770 TestCallRender(pBuffer);
7774TEST_F(OpenGLShader_test, Test_Buffer_Constant_User)
7776 using BufferMapper_t = ::covellite::api::cbBufferMap_t<void>;
7778 using GLProxy_t = ::mock::GLProxy;
7780 GLProxy_t::GetInstance() = &GLProxy;
7783 public ::alicorn::extension::testing::Proxy<MapperProxy>
7786 MOCK_METHOD1(DoMapper,
void(
const void *));
7789 MapperProxy oMapperProxy;
7790 MapperProxy::GetInstance() = &oMapperProxy;
7792 const ::mock::GLuint BufferId = 1909211301;
7793 const ::mock::GLint ProgramId = 1909211302;
7794 const ::mock::GLint BlockIndex = 1909211332;
7795 const ::std::size_t Size = 313;
7797 void * pData =
nullptr;
7799 const BufferMapper_t BufferMapper = [&](
void * _pData)
7802 oMapperProxy.DoMapper(_pData);
7806 const Tested_t oExample{ Data_t{} };
7807 const ITested_t & IExample = oExample;
7809 auto itConstBufferCreator = IExample.GetCreators().find(uT(
"Buffer"));
7810 ASSERT_NE(IExample.GetCreators().end(), itConstBufferCreator);
7812 auto TestCallRender = [&](
const Component_t::ComponentPtr_t & _pComponent,
7813 const ::std::string & _Name)
7815 using namespace ::testing;
7819 EXPECT_CALL(GLProxy, GenBuffers(1))
7821 .WillOnce(Return(BufferId));
7823 EXPECT_CALL(GLProxy, BindBuffer(GL_UNIFORM_BUFFER, BufferId))
7826 EXPECT_CALL(GLProxy,
7827 BufferData(GL_UNIFORM_BUFFER, Size, _, GL_DYNAMIC_DRAW))
7830 EXPECT_CALL(GLProxy, BindBuffer(GL_UNIFORM_BUFFER, 0))
7833 EXPECT_CALL(GLProxy, GetError())
7835 .WillOnce(Return(GL_NO_ERROR));
7837 const auto Render = itConstBufferCreator->second(_pComponent);
7838 ASSERT_NE(
nullptr, Render);
7840 EXPECT_CALL(oMapperProxy, DoMapper(_))
7843 EXPECT_CALL(GLProxy, GetIntegerv(_))
7846 EXPECT_CALL(GLProxy, GetUniformBlockIndex(_, _))
7848 .WillOnce(Return(BlockIndex));
7850 EXPECT_CALL(GLProxy, BindBuffer(_, _))
7853 EXPECT_CALL(GLProxy, UniformBufferSubData(_, _, _))
7856 EXPECT_CALL(GLProxy, BindBuffer(_, _))
7859 EXPECT_CALL(GLProxy, BindBufferBase(_, _, _))
7862 EXPECT_CALL(GLProxy, UniformBlockBinding(_, _, _))
7867 EXPECT_CALL(oMapperProxy, DoMapper(pData))
7870 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
7872 .WillOnce(Return(&ProgramId));
7874 EXPECT_CALL(GLProxy, GetUniformBlockIndex(ProgramId, _Name))
7876 .WillOnce(Return(BlockIndex));
7878 EXPECT_CALL(GLProxy, BindBuffer(GL_UNIFORM_BUFFER, BufferId))
7881 EXPECT_CALL(GLProxy, UniformBufferSubData(0, Size, pData))
7884 EXPECT_CALL(GLProxy, BindBuffer(GL_UNIFORM_BUFFER, 0))
7887 EXPECT_CALL(GLProxy,
7888 BindBufferBase(GL_UNIFORM_BUFFER, COVELLITE_BUFFER_INDEX_USER, BufferId))
7891 EXPECT_CALL(GLProxy,
7892 UniformBlockBinding(ProgramId, BlockIndex, COVELLITE_BUFFER_INDEX_USER))
7897 EXPECT_CALL(GLProxy, DeleteBuffers(1, BufferId))
7903 const auto pBuffer = Component_t::Make(
7905 { uT(
"mapper"), BufferMapper },
7906 { uT(
"size"), Size },
7909 TestCallRender(pBuffer,
"cbUserData");
7913 const ::std::string Name =
"Name1909211251";
7915 const auto pBuffer = Component_t::Make(
7917 { uT(
"mapper"), BufferMapper },
7918 { uT(
"size"), Size },
7919 { uT(
"name"), Name },
7922 TestCallRender(pBuffer, Name);
7927TEST_F(OpenGLShader_test, Test_Camera_Orthographic_DefaultPosition)
7929 Tested::GetValue() = 1;
7931 ::mock::GLProxy GLProxy;
7933 const Tested_t Example{ Data_t{} };
7934 const ITested_t & IExample = Example;
7936 auto itCreator = IExample.GetCreators().find(uT(
"Camera"));
7937 ASSERT_NE(IExample.GetCreators().end(), itCreator);
7939 auto Render = itCreator->second(Component_t::Make(
7941 { uT(
"kind"), uT(
"Orthographic") },
7943 ASSERT_NE(
nullptr, Render);
7945 auto itShaderCreator = IExample.GetCreators().find(uT(
"Shader"));
7946 ASSERT_NE(IExample.GetCreators().end(), itShaderCreator);
7948 auto VsRender = itShaderCreator->second(Component_t::Make(
7950 { uT(
"entry"), uT(
"vsFlat") },
7952 ASSERT_NE(
nullptr, VsRender);
7954 auto PsRender = itShaderCreator->second(Component_t::Make(
7956 { uT(
"entry"), uT(
"psColored") },
7958 ASSERT_NE(
nullptr, PsRender);
7960 const float Viewport[] =
7962 1812271148.0f, 1812271149.0f, 1812181722.0f, 1812181723.0f
7965 using namespace ::testing;
7967 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, 0))
7970 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
7973 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
7976 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
7979 EXPECT_CALL(GLProxy, Disable(GL_BLEND))
7982 EXPECT_CALL(GLProxy, Disable(GL_DITHER))
7985 EXPECT_CALL(GLProxy, Enable(GL_CULL_FACE))
7988 EXPECT_CALL(GLProxy, CullFace(GL_BACK))
7991 EXPECT_CALL(GLProxy, FrontFace(GL_CCW))
7994 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
7997 EXPECT_CALL(GLProxy, GetFloatv(GL_VIEWPORT))
7999 .WillOnce(Return(Viewport));
8006 const ::mock::GLint ProgramId = 1908251932;
8007 const ::mock::GLint ProjectionLocationId = 1908251933;
8008 const ::mock::GLint ViewLocationId = 1908252005;
8009 const ::mock::GLint ViewInverseLocationId = 1908252013;
8011 const auto Projection = ::glm::transpose(::glm::ortho(
8012 Viewport[0], Viewport[0] + Viewport[2],
8013 Viewport[1] + Viewport[3], Viewport[1],
8015 auto View = ::glm::identity<::glm::mat4>();
8016 const auto ViewInverse = ::glm::transpose(::glm::inverse(View));
8017 View = ::glm::transpose(View);
8021 EXPECT_CALL(GLProxy, UseProgram(_))
8024 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8026 .WillOnce(Return(&ProgramId));
8030 EXPECT_CALL(GLProxy, GetUniformLocation(_, _))
8033 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, _))
8038 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.Projection")))
8040 .WillOnce(Return(ProjectionLocationId));
8042 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.View")))
8044 .WillOnce(Return(ViewLocationId));
8046 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.ViewInverse")))
8048 .WillOnce(Return(ViewInverseLocationId));
8050 EXPECT_CALL(GLProxy,
8051 UniformMatrix4fv(ProjectionLocationId, 1, GL_FALSE, Projection))
8054 EXPECT_CALL(GLProxy,
8055 UniformMatrix4fv(ViewLocationId, 1, GL_FALSE, View))
8058 EXPECT_CALL(GLProxy,
8059 UniformMatrix4fv(ViewInverseLocationId, 1, GL_FALSE, ViewInverse))
8066TEST_F(OpenGLShader_test, Test_Camera_Orthographic)
8068 Tested::GetValue() = 1;
8070 using GLProxy_t = ::mock::GLProxy;
8072 GLProxy_t::GetInstance() = &GLProxy;
8074 const auto X = 11111.0f;
8075 const auto Y = 22222.0f;
8077 const float SourceViewport[] =
8079 19022.82014f, 19022.82015f, 19022.82016f, 19022.82017f
8082 const Tested_t Example{ Data_t{} };
8083 const ITested_t & IExample = Example;
8085 auto itCreator = IExample.GetCreators().find(uT(
"Camera"));
8086 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8088 auto itShaderCreator = IExample.GetCreators().find(uT(
"Shader"));
8089 ASSERT_NE(IExample.GetCreators().end(), itShaderCreator);
8091 auto VsRender = itShaderCreator->second(Component_t::Make(
8093 { uT(
"entry"), uT(
"vsFlat") },
8095 ASSERT_NE(
nullptr, VsRender);
8097 auto PsRender = itShaderCreator->second(Component_t::Make(
8099 { uT(
"entry"), uT(
"psColored") },
8101 ASSERT_NE(
nullptr, PsRender);
8103 using namespace ::testing;
8105 const auto pPosition = Component_t::Make(
8107 { uT(
"kind"), uT(
"Position") },
8112 const auto pCameraComponent = Component_t::Make(
8114 { uT(
"kind"), uT(
"Orthographic") },
8115 { uT(
"service"), Object_t{ pPosition } },
8118 auto Render = itCreator->second(pCameraComponent);
8119 ASSERT_NE(
nullptr, Render);
8123 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, 0))
8126 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
8129 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
8132 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
8135 EXPECT_CALL(GLProxy, Disable(GL_BLEND))
8138 EXPECT_CALL(GLProxy, Disable(GL_DITHER))
8141 EXPECT_CALL(GLProxy, Enable(GL_CULL_FACE))
8144 EXPECT_CALL(GLProxy, CullFace(GL_BACK))
8147 EXPECT_CALL(GLProxy, FrontFace(GL_CCW))
8150 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
8153 EXPECT_CALL(GLProxy, GetFloatv(GL_VIEWPORT))
8155 .WillOnce(Return(SourceViewport));
8159 const auto Projection = ::glm::transpose(::glm::ortho(
8160 SourceViewport[0] + X,
8161 SourceViewport[0] + SourceViewport[2] + X,
8162 SourceViewport[1] + SourceViewport[3] + Y,
8163 SourceViewport[1] + Y,
8166 auto View = ::glm::identity<::glm::mat4>();
8167 const auto ViewInverse = ::glm::transpose(::glm::inverse(View));
8168 View = ::glm::transpose(View);
8170 EXPECT_EQ(View, (::glm::mat4)(*pCameraComponent)[uT(
"view")].Default(::glm::mat4{ 1.0f }));
8171 EXPECT_EQ(Projection, (::glm::mat4)(*pCameraComponent)[uT(
"projection")].Default(::glm::mat4{ 1.0f }));
8176 EXPECT_CALL(GLProxy, UseProgram(_))
8179 const ::mock::GLint ProgramId = 1908251932;
8180 const ::mock::GLint ProjectionLocationId = 1908251933;
8181 const ::mock::GLint ViewLocationId = 1908252005;
8182 const ::mock::GLint ViewInverseLocationId = 1908252013;
8184 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8186 .WillRepeatedly(Return(&ProgramId));
8190 EXPECT_CALL(GLProxy, GetUniformLocation(_, _))
8193 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, _))
8198 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.Projection")))
8200 .WillOnce(Return(ProjectionLocationId));
8202 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.View")))
8204 .WillOnce(Return(ViewLocationId));
8206 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.ViewInverse")))
8208 .WillOnce(Return(ViewInverseLocationId));
8210 EXPECT_CALL(GLProxy,
8211 UniformMatrix4fv(ProjectionLocationId, 1, GL_FALSE, Projection))
8214 EXPECT_CALL(GLProxy,
8215 UniformMatrix4fv(ViewLocationId, 1, GL_FALSE, View))
8218 EXPECT_CALL(GLProxy,
8219 UniformMatrix4fv(ViewInverseLocationId, 1, GL_FALSE, ViewInverse))
8226TEST_F(OpenGLShader_test, Test_Camera_Perspective)
8228 Tested::GetValue() = 1;
8230 using GLProxy_t = ::mock::GLProxy;
8232 GLProxy_t::GetInstance() = &GLProxy;
8234 const float Width = 1024.0f;
8235 const float Height = 768.0f;
8237 const Tested_t Example{ Data_t{} };
8238 const ITested_t & IExample = Example;
8240 auto itShaderCreator = IExample.GetCreators().find(uT(
"Shader"));
8241 ASSERT_NE(IExample.GetCreators().end(), itShaderCreator);
8243 auto VsRender = itShaderCreator->second(Component_t::Make(
8245 { uT(
"entry"), uT(
"vsFlat") },
8247 ASSERT_NE(
nullptr, VsRender);
8249 auto PsRender = itShaderCreator->second(Component_t::Make(
8251 { uT(
"entry"), uT(
"psColored") },
8253 ASSERT_NE(
nullptr, PsRender);
8255 using namespace ::testing;
8257 auto TestCallRender = [&](
8258 const Component_t::ComponentPtr_t & _pCameraComponent,
8260 float _AngleY,
float _zNear,
float _zFar,
8261 float _X,
float _Y,
float _Z,
8262 float _A,
float _B,
float _C,
8265 ASSERT_NE(
nullptr, _Render);
8267 const float AngleYRadians = _AngleY *
8268 ::alicorn::extension::cpp::math::Constant<float>::DegreeToRadian;
8272 EXPECT_CALL(GLProxy, BindFramebuffer(GL_FRAMEBUFFER, 0))
8275 EXPECT_CALL(GLProxy, Disable(GL_DEPTH_TEST))
8278 EXPECT_CALL(GLProxy, Enable(GL_DEPTH_TEST))
8281 EXPECT_CALL(GLProxy, Clear(GL_DEPTH_BUFFER_BIT))
8284 EXPECT_CALL(GLProxy, Disable(GL_BLEND))
8287 EXPECT_CALL(GLProxy, Disable(GL_DITHER))
8290 EXPECT_CALL(GLProxy, Enable(GL_CULL_FACE))
8293 EXPECT_CALL(GLProxy, CullFace(GL_BACK))
8296 EXPECT_CALL(GLProxy, FrontFace(GL_CCW))
8299 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
8302 const float Viewport[] = { 0, 0, Width, Height };
8304 EXPECT_CALL(GLProxy, GetFloatv(GL_VIEWPORT))
8306 .WillOnce(Return(Viewport));
8310 const auto Projection = ::glm::transpose(::glm::perspectiveFovRH(
8311 AngleYRadians, Viewport[2], Viewport[3], _zFar, _zNear));
8313 auto GetEye = [&](void) -> ::glm::vec3
8315 const auto Distance = _Distance + 0.1f;
8317 ::glm::mat4 Transform = ::glm::identity<::glm::mat4>();
8319 Transform = ::glm::translate(Transform,
8320 ::glm::vec3{ _X, _Y, _Z });
8321 Transform = ::glm::rotate(Transform,
8322 _C, ::glm::vec3{ 0.0f, 0.0f, 1.0f });
8323 Transform = ::glm::rotate(Transform,
8324 _B, ::glm::vec3{ 0.0f, 1.0f, 0.0f });
8325 Transform = ::glm::rotate(Transform,
8326 _A, ::glm::vec3{ 1.0f, 0.0f, 0.0f });
8328 return Transform * ::glm::vec4{ Distance, 0.0f, 0.0f, 1.0f };
8331 auto View = ::glm::lookAtRH(
8333 ::glm::vec3{ _X, _Y, _Z },
8334 ::glm::vec3{ 0.0f, 0.0f, 1.0f });
8335 const auto ViewInverse = ::glm::transpose(::glm::inverse(View));
8336 View = ::glm::transpose(View);
8338 EXPECT_EQ(View, (::glm::mat4)(*_pCameraComponent)[uT(
"view")].Default(::glm::mat4{ 1.0f }));
8339 EXPECT_EQ(Projection, (::glm::mat4)(*_pCameraComponent)[uT(
"projection")].Default(::glm::mat4{ 1.0f }));
8341 EXPECT_CALL(GLProxy, UseProgram(_))
8347 const ::mock::GLint ProgramId = 1908251932;
8348 const ::mock::GLint ProjectionLocationId = 1908251933;
8349 const ::mock::GLint ViewLocationId = 1908252005;
8350 const ::mock::GLint ViewInverseLocationId = 1908252013;
8352 EXPECT_CALL(GLProxy, GetIntegerv(GL_CURRENT_PROGRAM))
8354 .WillRepeatedly(Return(&ProgramId));
8358 EXPECT_CALL(GLProxy, GetUniformLocation(_, _))
8361 EXPECT_CALL(GLProxy, UniformMatrix4fv(_, _, _, _))
8366 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.Projection")))
8368 .WillOnce(Return(ProjectionLocationId));
8370 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.View")))
8372 .WillOnce(Return(ViewLocationId));
8374 EXPECT_CALL(GLProxy, GetUniformLocation(ProgramId, Eq(
"CameraData.ViewInverse")))
8376 .WillOnce(Return(ViewInverseLocationId));
8378 EXPECT_CALL(GLProxy,
8379 UniformMatrix4fv(ProjectionLocationId, 1, GL_FALSE, Projection))
8382 EXPECT_CALL(GLProxy,
8383 UniformMatrix4fv(ViewLocationId, 1, GL_FALSE, View))
8386 EXPECT_CALL(GLProxy,
8387 UniformMatrix4fv(ViewInverseLocationId, 1, GL_FALSE, ViewInverse))
8393 auto itCreator = IExample.GetCreators().find(uT(
"Camera"));
8394 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8406 const ::std::vector<CameraInfo> CameraInfos =
8408 { 90.0f, 0.01f, 200.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f },
8409 { 91.0f, 1.11f, 10.1f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f },
8410 { 92.0f, 2.22f, 20.2f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f },
8416 const auto pCamera = Component_t::Make(
8418 { uT(
"kind"), uT(
"Perspective") },
8421 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
8424 auto Render = itCreator->second(pCamera);
8426 auto Info = CameraInfos[0];
8430 Info.AngleY, Info.zNear, Info.zFar,
8431 Info.X, Info.Y, Info.Z,
8432 Info.A, Info.B, Info.C,
8436 const auto pPosition = Component_t::Make(
8438 { uT(
"kind"), uT(
"Position") },
8441 const auto pRotation = Component_t::Make(
8443 { uT(
"kind"), uT(
"Rotation") },
8449 const auto pCamera = Component_t::Make(
8451 { uT(
"kind"), uT(
"Perspective") },
8452 { uT(
"service"), Object_t{ pPosition, pRotation } },
8455 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
8458 auto Render = itCreator->second(pCamera);
8460 auto Info = CameraInfos[0];
8464 Info.AngleY, Info.zNear, Info.zFar,
8465 Info.X, Info.Y, Info.Z,
8466 Info.A, Info.B, Info.C,
8473 const auto pCamera = Component_t::Make(
8475 { uT(
"kind"), uT(
"Perspective") },
8476 { uT(
"service"), Object_t{ pPosition, pRotation } },
8479 EXPECT_CALL(GLProxy, Viewport(0, 0, _, _))
8482 auto Render = itCreator->second(pCamera);
8484 for (
size_t i = 1; i < CameraInfos.size(); i++)
8486 auto Info = CameraInfos[i];
8488 (*pPosition)[uT(
"x")] = Info.X;
8489 (*pPosition)[uT(
"y")] = Info.Y;
8490 (*pPosition)[uT(
"z")] = Info.Z;
8492 (*pRotation)[uT(
"x")] = Info.A;
8493 (*pRotation)[uT(
"y")] = Info.B;
8494 (*pRotation)[uT(
"z")] = Info.C;
8496 (*pCamera)[uT(
"fov")] = Info.AngleY;
8497 (*pCamera)[uT(
"znear")] = Info.zNear;
8498 (*pCamera)[uT(
"zfar")] = Info.zFar;
8499 (*pCamera)[uT(
"distance")] = Info.Distance;
8503 Info.AngleY, Info.zNear, Info.zFar,
8504 Info.X, Info.Y, Info.Z,
8505 Info.A, Info.B, Info.C,
8512TEST_F(OpenGLShader_test, Test_Camera_SetWindowViewport)
8514 const auto TestCall = [](
const Component_t::ComponentPtr_t & _pCamera)
8516 ::mock::WindowsProxy WindowsProxy;
8517 ::mock::GLProxy GLProxy;
8520 Data.ClientRect.Top = 12345;
8521 Data.ClientRect.Width = 2008131258;
8522 Data.ClientRect.Height = 2008131259;
8524 using namespace ::testing;
8526 Tested_t Example{ Data };
8527 ITested_t & IExample = Example;
8529 auto itCreator = IExample.GetCreators().find(uT(
"Camera"));
8530 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8532 EXPECT_CALL(GLProxy, Viewport(0, 0, Data.ClientRect.Width, Data.ClientRect.Height - Data.ClientRect.Top))
8535 auto Render = itCreator->second(_pCamera);
8536 ASSERT_NE(
nullptr, Render);
8538 EXPECT_CALL(GLProxy, Viewport(0, 0, Data.ClientRect.Width, Data.ClientRect.Height - Data.ClientRect.Top))
8543 IExample.ResizeWindow(::covellite::Rect{ 0, 54321, 2008131300, 2008131301 });
8545 EXPECT_CALL(GLProxy, Viewport(0, 0, 2008131300, 2008131301 - 54321))
8551 TestCall(Component_t::Make(
8553 { uT(
"kind"), uT(
"Orthographic") },
8556 TestCall(Component_t::Make(
8558 { uT(
"kind"), uT(
"Perspective") },
8563TEST_F(OpenGLShader_test, Test_Camera_SetScaleViewport)
8565 const auto TestCall = [](
const float _Scale,
8566 const Component_t::ComponentPtr_t & _pCamera)
8568 ::mock::WindowsProxy WindowsProxy;
8569 ::mock::GLProxy GLProxy;
8572 Data.ClientRect.Top = 123;
8573 Data.ClientRect.Width = 1024;
8574 Data.ClientRect.Height = 2048;
8576 const auto ExpectedWidth =
static_cast<int>(_Scale * Data.ClientRect.Width);
8577 const auto ExpectedHeight =
static_cast<int>(_Scale * (Data.ClientRect.Height - Data.ClientRect.Top));
8579 using namespace ::testing;
8581 Tested_t Example{ Data };
8582 ITested_t & IExample = Example;
8584 auto itCreator = IExample.GetCreators().find(uT(
"Camera"));
8585 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8587 EXPECT_CALL(GLProxy, Viewport(0, 0, ExpectedWidth, ExpectedHeight))
8590 auto Render = itCreator->second(_pCamera);
8591 ASSERT_NE(
nullptr, Render);
8593 EXPECT_CALL(GLProxy, Viewport(0, 0, ExpectedWidth, ExpectedHeight))
8598 IExample.ResizeWindow(::covellite::Rect{ 0, 321, 2048, 4096 });
8600 const auto ExpectedWidth2 =
static_cast<int>(_Scale * 2048);
8601 const auto ExpectedHeight2 =
static_cast<int>(_Scale * (4096 - 321));
8603 EXPECT_CALL(GLProxy, Viewport(0, 0, ExpectedWidth2, ExpectedHeight2))
8609 TestCall(0.5f, Component_t::Make(
8611 { uT(
"kind"), uT(
"Orthographic") },
8612 { uT(
"scale"), 0.5f },
8615 TestCall(2.0f, Component_t::Make(
8617 { uT(
"kind"), uT(
"Perspective") },
8618 { uT(
"scale"), 2.0f },
8621 TestCall(0.25f, Component_t::Make(
8623 { uT(
"kind"), uT(
"Orthographic") },
8624 { uT(
"scale"), 0.25f },
8625 { uT(
"width"), 2009081959 },
8626 { uT(
"height"), 2009082000 },
8629 TestCall(4.0f, Component_t::Make(
8631 { uT(
"kind"), uT(
"Perspective") },
8632 { uT(
"scale"), 4.0f },
8633 { uT(
"width"), 2009081959 },
8634 { uT(
"height"), 2009082000 },
8639TEST_F(OpenGLShader_test, Test_Camera_SetUserViewport)
8641 const auto TestCall = [](
const int _Width,
const int _Height,
8642 const Component_t::ComponentPtr_t & _pCamera)
8644 ::mock::WindowsProxy WindowsProxy;
8645 ::mock::GLProxy GLProxy;
8648 Data.ClientRect.Top = 345;
8649 Data.ClientRect.Width = 2009082008;
8650 Data.ClientRect.Height = 2009082009;
8652 using namespace ::testing;
8654 Tested_t Example{ Data };
8655 ITested_t & IExample = Example;
8657 auto itCreator = IExample.GetCreators().find(uT(
"Camera"));
8658 ASSERT_NE(IExample.GetCreators().end(), itCreator);
8660 EXPECT_CALL(GLProxy, Viewport(0, 0, _Width, _Height))
8663 auto Render = itCreator->second(_pCamera);
8664 ASSERT_NE(
nullptr, Render);
8666 EXPECT_CALL(GLProxy, Viewport(0, 0, _Width, _Height))
8671 IExample.ResizeWindow(::covellite::Rect{ 0, 543, 2008131300, 2008131301 });
8673 EXPECT_CALL(GLProxy, Viewport(0, 0, _Width, _Height))
8679 TestCall(1024, 2048, Component_t::Make(
8681 { uT(
"kind"), uT(
"Orthographic") },
8682 { uT(
"width"), 1024 },
8683 { uT(
"height"), 2048 },
8686 TestCall(2048, 4096, Component_t::Make(
8688 { uT(
"kind"), uT(
"Perspective") },
8689 { uT(
"width"), 2048 },
8690 { uT(
"height"), 4096 },
Класс входит в проект Covellite.Api Класс формата вертексного буфера.
Definition Vertex.hpp:34