X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-toolkit%2Fdali-toolkit-test-utils%2Ftest-graphics-controller.cpp;h=08867195432360e2a431ff8c9e8ef6e26dcf6296;hp=51f0721432e4e1cd728b3a2769d944ab1139b006;hb=32d9c82fd183da60e3c54584d888388e73b92d34;hpb=950447e00422e94e22ce64a69a13ebf1235b12c6 diff --git a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-controller.cpp b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-controller.cpp index 51f0721..0886719 100644 --- a/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-controller.cpp +++ b/automated-tests/src/dali-toolkit/dali-toolkit-test-utils/test-graphics-controller.cpp @@ -18,9 +18,13 @@ #include "test-graphics-buffer.h" #include "test-graphics-command-buffer.h" +#include "test-graphics-framebuffer.h" #include "test-graphics-reflection.h" +#include "test-graphics-render-pass.h" +#include "test-graphics-render-target.h" #include "test-graphics-sampler.h" #include "test-graphics-shader.h" +#include "test-graphics-sync-object.h" #include "test-graphics-texture.h" #include @@ -30,36 +34,6 @@ namespace Dali { -template -T* Uncast(const Graphics::CommandBuffer* object) -{ - return const_cast(static_cast(object)); -} - -template -T* Uncast(const Graphics::Texture* object) -{ - return const_cast(static_cast(object)); -} - -template -T* Uncast(const Graphics::Sampler* object) -{ - return const_cast(static_cast(object)); -} - -template -T* Uncast(const Graphics::Buffer* object) -{ - return const_cast(static_cast(object)); -} - -template -T* Uncast(const Graphics::Shader* object) -{ - return const_cast(static_cast(object)); -} - std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo) { return o << "usage:" << std::hex << bufferCreateInfo.usage << ", size:" << std::dec << bufferCreateInfo.size; @@ -173,70 +147,34 @@ std::ostream& operator<<(std::ostream& o, const Graphics::SamplerCreateInfo& cre return o; } -class TestGraphicsMemory : public Graphics::Memory +std::ostream& operator<<(std::ostream& o, const Graphics::ColorAttachment& colorAttachment) { -public: - TestGraphicsMemory(TraceCallStack& callStack, TestGraphicsBuffer& buffer, uint32_t mappedOffset, uint32_t mappedSize) - : mCallStack(callStack), - mBuffer(buffer), - mMappedOffset(mappedOffset), - mMappedSize(mappedSize), - mLockedOffset(0u), - mLockedSize(0u) - { - } - - void* LockRegion(uint32_t offset, uint32_t size) override - { - std::ostringstream o; - o << offset << ", " << size; - mCallStack.PushCall("Memory::LockRegion", o.str()); - - if(offset > mMappedOffset + mMappedSize || - size + offset > mMappedOffset + mMappedSize) - { - fprintf(stderr, "TestGraphics.Memory::LockRegion() Out of bounds"); - mBuffer.memory.resize(mMappedOffset + offset + size); // Grow to prevent memcpy from crashing - } - mLockedOffset = offset; - mLockedSize = size; - return &mBuffer.memory[mMappedOffset + offset]; - } + o << "attachmentId:" << colorAttachment.attachmentId + << " layerId:" << colorAttachment.layerId + << " levelId:" << colorAttachment.levelId + << " texture:" << colorAttachment.texture; + return o; +} - void Unlock(bool flush) override - { - mCallStack.PushCall("Memory::Unlock", (flush ? "Flush" : "NoFlush")); - if(flush) - { - Flush(); - } - } +std::ostream& operator<<(std::ostream& o, const Graphics::DepthStencilAttachment& depthStencilAttachment) +{ + o << "depthTexture:" << depthStencilAttachment.depthTexture + << "depthLevel:" << depthStencilAttachment.depthLevel + << "stencilTexture:" << depthStencilAttachment.stencilTexture + << "stencilLevel:" << depthStencilAttachment.stencilLevel; + return o; +} - void Flush() override +std::ostream& operator<<(std::ostream& o, const Graphics::FramebufferCreateInfo& createInfo) +{ + o << "colorAttachments:"; + for(auto i = 0u; i < createInfo.colorAttachments.size(); ++i) { - mCallStack.PushCall("Memory::Flush", ""); - mBuffer.Bind(); - mBuffer.Upload(mMappedOffset + mLockedOffset, mLockedSize); - mBuffer.Unbind(); + o << "[" << i << "]=" << createInfo.colorAttachments[i] << " "; } - - TraceCallStack& mCallStack; - TestGraphicsBuffer& mBuffer; - uint32_t mMappedOffset; - uint32_t mMappedSize; - uint32_t mLockedOffset; - uint32_t mLockedSize; -}; - -TestGraphicsController::TestGraphicsController() -: mCallStack(true, "TestGraphicsController."), - mCommandBufferCallStack(true, "TestCommandBuffer.") -{ - mCallStack.Enable(true); - mCommandBufferCallStack.Enable(true); - auto& trace = mGl.GetTextureTrace(); - trace.Enable(true); - trace.EnableLogging(true); + o << "depthStencilAttachment:" << createInfo.depthStencilAttachment; + o << "size: " << createInfo.size; + return o; } int GetNumComponents(Graphics::VertexInputFormat vertexFormat) @@ -447,6 +385,143 @@ GLenum GetBlendOp(Graphics::BlendOp blendOp) return op; } +struct GLCompareOp +{ + constexpr explicit GLCompareOp(Graphics::CompareOp compareOp) + { + switch(compareOp) + { + case Graphics::CompareOp::NEVER: + op = GL_NEVER; + break; + case Graphics::CompareOp::LESS: + op = GL_LESS; + break; + case Graphics::CompareOp::EQUAL: + op = GL_EQUAL; + break; + case Graphics::CompareOp::LESS_OR_EQUAL: + op = GL_LEQUAL; + break; + case Graphics::CompareOp::GREATER: + op = GL_GREATER; + break; + case Graphics::CompareOp::NOT_EQUAL: + op = GL_NOTEQUAL; + break; + case Graphics::CompareOp::GREATER_OR_EQUAL: + op = GL_GEQUAL; + break; + case Graphics::CompareOp::ALWAYS: + op = GL_ALWAYS; + break; + } + } + GLenum op{GL_LESS}; +}; + +struct GLStencilOp +{ + constexpr explicit GLStencilOp(Graphics::StencilOp stencilOp) + { + switch(stencilOp) + { + case Graphics::StencilOp::KEEP: + op = GL_KEEP; + break; + case Graphics::StencilOp::ZERO: + op = GL_ZERO; + break; + case Graphics::StencilOp::REPLACE: + op = GL_REPLACE; + break; + case Graphics::StencilOp::INCREMENT_AND_CLAMP: + op = GL_INCR; + break; + case Graphics::StencilOp::DECREMENT_AND_CLAMP: + op = GL_DECR; + break; + case Graphics::StencilOp::INVERT: + op = GL_INVERT; + break; + case Graphics::StencilOp::INCREMENT_AND_WRAP: + op = GL_INCR_WRAP; + break; + case Graphics::StencilOp::DECREMENT_AND_WRAP: + op = GL_DECR_WRAP; + break; + } + } + GLenum op{GL_KEEP}; +}; + +class TestGraphicsMemory : public Graphics::Memory +{ +public: + TestGraphicsMemory(TraceCallStack& callStack, TestGraphicsBuffer& buffer, uint32_t mappedOffset, uint32_t mappedSize) + : mCallStack(callStack), + mBuffer(buffer), + mMappedOffset(mappedOffset), + mMappedSize(mappedSize), + mLockedOffset(0u), + mLockedSize(0u) + { + } + + void* LockRegion(uint32_t offset, uint32_t size) override + { + std::ostringstream o; + o << offset << ", " << size; + mCallStack.PushCall("Memory::LockRegion", o.str()); + + if(offset > mMappedOffset + mMappedSize || + size + offset > mMappedOffset + mMappedSize) + { + fprintf(stderr, "TestGraphics.Memory::LockRegion() Out of bounds"); + mBuffer.memory.resize(mMappedOffset + offset + size); // Grow to prevent memcpy from crashing + } + mLockedOffset = offset; + mLockedSize = size; + return &mBuffer.memory[mMappedOffset + offset]; + } + + void Unlock(bool flush) override + { + mCallStack.PushCall("Memory::Unlock", (flush ? "Flush" : "NoFlush")); + if(flush) + { + Flush(); + } + } + + void Flush() override + { + mCallStack.PushCall("Memory::Flush", ""); + mBuffer.Bind(); + mBuffer.Upload(mMappedOffset + mLockedOffset, mLockedSize); + mBuffer.Unbind(); + } + + TraceCallStack& mCallStack; + TestGraphicsBuffer& mBuffer; + uint32_t mMappedOffset; + uint32_t mMappedSize; + uint32_t mLockedOffset; + uint32_t mLockedSize; +}; + +TestGraphicsController::TestGraphicsController() +: mCallStack(true, "TestGraphicsController."), + mCommandBufferCallStack(true, "TestCommandBuffer."), + mFrameBufferCallStack(true, "TestFrameBuffer.") +{ + mCallStack.Enable(true); + mCommandBufferCallStack.Enable(true); + auto& trace = mGl.GetTextureTrace(); + trace.Enable(true); + trace.EnableLogging(true); +} + void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& submitInfo) { TraceCallStack::NamedParams namedParams; @@ -460,193 +535,420 @@ void TestGraphicsController::SubmitCommandBuffers(const Graphics::SubmitInfo& su for(auto& graphicsCommandBuffer : submitInfo.cmdBuffer) { auto commandBuffer = Uncast(graphicsCommandBuffer); + ProcessCommandBuffer(*commandBuffer); + } +} + +void TestGraphicsController::ProcessCommandBuffer(TestGraphicsCommandBuffer& commandBuffer) +{ + bool scissorEnabled = false; + TestGraphicsFramebuffer* currentFramebuffer{nullptr}; + TestGraphicsPipeline* currentPipeline{nullptr}; - auto value = commandBuffer->GetCommandsByType(0 | CommandType::BIND_TEXTURES); - if(!value.empty()) + for(auto& cmd : commandBuffer.GetCommands()) + { + // process command + switch(cmd.type) { - // must be fixed - for(auto& binding : value[0]->data.bindTextures.textureBindings) + case CommandType::FLUSH: { - if(binding.texture) + // Nothing to do here + break; + } + case CommandType::BIND_TEXTURES: + { + for(auto& binding : cmd.data.bindTextures.textureBindings) { - auto texture = Uncast(binding.texture); - - texture->Bind(binding.binding); - - if(binding.sampler) + if(binding.texture) { - auto sampler = Uncast(binding.sampler); - if(sampler) + auto texture = Uncast(binding.texture); + texture->Bind(binding.binding); + + if(binding.sampler) { - sampler->Apply(texture->GetTarget()); + auto sampler = Uncast(binding.sampler); + if(sampler) + { + sampler->Apply(texture->GetTarget()); + } } - } - texture->Prepare(); // Ensure native texture is ready + texture->Prepare(); // Ensure native texture is ready + } } + break; } - } - - // IndexBuffer binding, - auto bindIndexBufferCmds = commandBuffer->GetCommandsByType(0 | CommandType::BIND_INDEX_BUFFER); - if(!bindIndexBufferCmds.empty()) - { - auto& indexBufferBinding = bindIndexBufferCmds[0]->data.bindIndexBuffer; - if(indexBufferBinding.buffer) + case CommandType::BIND_VERTEX_BUFFERS: { - auto buffer = Uncast(indexBufferBinding.buffer); - buffer->Bind(); + for(auto& binding : cmd.data.bindVertexBuffers.vertexBufferBindings) + { + auto graphicsBuffer = binding.buffer; + auto vertexBuffer = Uncast(graphicsBuffer); + vertexBuffer->Bind(); + } + break; } - } - - // VertexBuffer binding, - auto bindVertexBufferCmds = commandBuffer->GetCommandsByType(0 | CommandType::BIND_VERTEX_BUFFERS); - if(!bindVertexBufferCmds.empty()) - { - for(auto& binding : bindVertexBufferCmds[0]->data.bindVertexBuffers.vertexBufferBindings) + case CommandType::BIND_INDEX_BUFFER: { - auto graphicsBuffer = binding.buffer; - auto vertexBuffer = Uncast(graphicsBuffer); - vertexBuffer->Bind(); + auto& indexBufferBinding = cmd.data.bindIndexBuffer; + if(indexBufferBinding.buffer) + { + auto buffer = Uncast(indexBufferBinding.buffer); + buffer->Bind(); + } + break; } - } - - bool scissorEnabled = false; + case CommandType::BIND_UNIFORM_BUFFER: + { + if(currentPipeline) + { + auto& bindings = cmd.data.bindUniformBuffers; + auto buffer = bindings.standaloneUniformsBufferBinding; - auto scissorTestList = commandBuffer->GetCommandsByType(0 | CommandType::SET_SCISSOR_TEST); - if(!scissorTestList.empty()) - { - if(scissorTestList[0]->data.scissorTest.enable) + // based on reflection, issue gl calls + buffer.buffer->BindAsUniformBuffer(static_cast(currentPipeline->programState.program), bindings.standaloneUniformsBufferBinding); + } + break; + } + case CommandType::BIND_SAMPLERS: { - mGl.Enable(GL_SCISSOR_TEST); - scissorEnabled = true; + break; } - else + case CommandType::BIND_PIPELINE: { - mGl.Disable(GL_SCISSOR_TEST); + currentPipeline = Uncast(cmd.data.bindPipeline.pipeline); + BindPipeline(currentPipeline); + break; + } + case CommandType::DRAW: + { + if(currentPipeline) + { + mGl.DrawArrays(GetTopology(currentPipeline->inputAssemblyState.topology), + 0, + cmd.data.draw.draw.vertexCount); + } + break; + } + case CommandType::DRAW_INDEXED: + { + if(currentPipeline) + { + mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology), + static_cast(cmd.data.draw.drawIndexed.indexCount), + GL_UNSIGNED_SHORT, + reinterpret_cast(cmd.data.draw.drawIndexed.firstIndex)); + } + break; + } + case CommandType::DRAW_INDEXED_INDIRECT: + { + if(currentPipeline) + { + mGl.DrawElements(GetTopology(currentPipeline->inputAssemblyState.topology), + static_cast(cmd.data.draw.drawIndexed.indexCount), + GL_UNSIGNED_SHORT, + reinterpret_cast(cmd.data.draw.drawIndexed.firstIndex)); + } + break; + } + case CommandType::SET_SCISSOR: + { + if(scissorEnabled) + { + auto& rect = cmd.data.scissor.region; + mGl.Scissor(rect.x, rect.y, rect.width, rect.height); + } + break; + } + case CommandType::SET_SCISSOR_TEST: + { + if(cmd.data.scissorTest.enable) + { + mGl.Enable(GL_SCISSOR_TEST); + scissorEnabled = true; + } + else + { + mGl.Disable(GL_SCISSOR_TEST); + scissorEnabled = false; + } + break; + } + case CommandType::SET_VIEWPORT_TEST: + { + break; + } + case CommandType::SET_VIEWPORT: // @todo Consider correcting for orientation here? + { + auto& rect = cmd.data.viewport.region; + mGl.Viewport(rect.x, rect.y, rect.width, rect.height); + break; } - } - - auto scissorList = commandBuffer->GetCommandsByType(0 | CommandType::SET_SCISSOR); - if(!scissorList.empty() && scissorEnabled) - { - auto& rect = scissorList[0]->data.scissor.region; - mGl.Scissor(rect.x, rect.y, rect.width, rect.height); - } - auto viewportList = commandBuffer->GetCommandsByType(0 | CommandType::SET_VIEWPORT); - if(!viewportList.empty()) - { - mGl.Viewport(viewportList[0]->data.viewport.region.x, viewportList[0]->data.viewport.region.y, viewportList[0]->data.viewport.region.width, viewportList[0]->data.viewport.region.height); - } + case CommandType::SET_COLOR_MASK: + { + // Set all channels to the same mask + const bool mask = cmd.data.colorMask.enabled; + mGl.ColorMask(mask, mask, mask, mask); + break; + } + case CommandType::CLEAR_STENCIL_BUFFER: + { + mGl.Clear(GL_STENCIL_BUFFER_BIT); + break; + } + case CommandType::CLEAR_DEPTH_BUFFER: + { + mGl.Clear(GL_DEPTH_BUFFER_BIT); + break; + } - // ignore viewport enable + case CommandType::SET_STENCIL_TEST_ENABLE: + { + if(cmd.data.stencilTest.enabled) + { + mGl.Enable(GL_STENCIL_TEST); + } + else + { + mGl.Disable(GL_STENCIL_TEST); + } + break; + } - // Pipeline attribute setup - auto bindPipelineCmds = commandBuffer->GetCommandsByType(0 | CommandType::BIND_PIPELINE); - if(!bindPipelineCmds.empty()) - { - auto pipeline = bindPipelineCmds[0]->data.bindPipeline.pipeline; - auto& vi = pipeline->vertexInputState; - for(auto& attribute : vi.attributes) + case CommandType::SET_STENCIL_FUNC: { - mGl.EnableVertexAttribArray(attribute.location); - uint32_t attributeOffset = attribute.offset; - GLsizei stride = vi.bufferBindings[attribute.binding].stride; - - mGl.VertexAttribPointer(attribute.location, - GetNumComponents(attribute.format), - GetGlType(attribute.format), - GL_FALSE, // Not normalized - stride, - reinterpret_cast(attributeOffset)); + mGl.StencilFunc(GLCompareOp(cmd.data.stencilFunc.compareOp).op, + cmd.data.stencilFunc.reference, + cmd.data.stencilFunc.compareMask); + break; } - // Cull face setup - auto& rasterizationState = pipeline->rasterizationState; - if(rasterizationState.cullMode == Graphics::CullMode::NONE) + case CommandType::SET_STENCIL_WRITE_MASK: { - mGl.Disable(GL_CULL_FACE); + mGl.StencilMask(cmd.data.stencilWriteMask.mask); + break; } - else + case CommandType::SET_STENCIL_OP: { - mGl.Enable(GL_CULL_FACE); - mGl.CullFace(GetCullFace(rasterizationState.cullMode)); + mGl.StencilOp(GLStencilOp(cmd.data.stencilOp.failOp).op, + GLStencilOp(cmd.data.stencilOp.depthFailOp).op, + GLStencilOp(cmd.data.stencilOp.passOp).op); + break; } - mGl.FrontFace(GetFrontFace(rasterizationState.frontFace)); - // We don't modify glPolygonMode in our context/abstraction from GL_FILL (the GL default), - // so it isn't present in the API (and won't have any tests!) - - // Blending setup - auto& colorBlendState = pipeline->colorBlendState; - if(colorBlendState.blendEnable) + case CommandType::SET_DEPTH_COMPARE_OP: { - mGl.Enable(GL_BLEND); - - mGl.BlendFuncSeparate(GetBlendFactor(colorBlendState.srcColorBlendFactor), - GetBlendFactor(colorBlendState.dstColorBlendFactor), - GetBlendFactor(colorBlendState.srcAlphaBlendFactor), - GetBlendFactor(colorBlendState.dstAlphaBlendFactor)); - if(colorBlendState.colorBlendOp != colorBlendState.alphaBlendOp) + mGl.DepthFunc(GLCompareOp(cmd.data.depth.compareOp).op); + break; + } + case CommandType::SET_DEPTH_TEST_ENABLE: + { + if(cmd.data.depth.testEnabled) { - mGl.BlendEquationSeparate(GetBlendOp(colorBlendState.colorBlendOp), GetBlendOp(colorBlendState.alphaBlendOp)); + mGl.Enable(GL_DEPTH_TEST); } else { - mGl.BlendEquation(GetBlendOp(colorBlendState.colorBlendOp)); + mGl.Disable(GL_DEPTH_TEST); } - mGl.BlendColor(colorBlendState.blendConstants[0], - colorBlendState.blendConstants[1], - colorBlendState.blendConstants[2], - colorBlendState.blendConstants[3]); + break; } - else + case CommandType::SET_DEPTH_WRITE_ENABLE: { - mGl.Disable(GL_BLEND); + mGl.DepthMask(cmd.data.depth.writeEnabled); + break; } - // draw call - auto topology = pipeline->inputAssemblyState.topology; - - // UniformBuffer binding (once we know pipeline) - auto bindUniformBuffersCmds = commandBuffer->GetCommandsByType(0 | CommandType::BIND_UNIFORM_BUFFER); - if(!bindUniformBuffersCmds.empty()) + case CommandType::EXECUTE_COMMAND_BUFFERS: { - auto buffer = bindUniformBuffersCmds[0]->data.bindUniformBuffers.standaloneUniformsBufferBinding; - - // based on reflection, issue gl calls - buffer.buffer->BindAsUniformBuffer(static_cast(pipeline->programState.program)); + // Process secondary command buffers + for(auto& buf : cmd.data.executeCommandBuffers.buffers) + { + ProcessCommandBuffer(*Uncast(buf)); + } + break; } - - auto drawCmds = commandBuffer->GetCommandsByType(0 | - CommandType::DRAW | - CommandType::DRAW_INDEXED_INDIRECT | - CommandType::DRAW_INDEXED); - - if(!drawCmds.empty()) + case CommandType::BEGIN_RENDER_PASS: { - if(drawCmds[0]->data.draw.type == DrawCallDescriptor::Type::DRAW_INDEXED) + auto renderTarget = Uncast(cmd.data.beginRenderPass.renderTarget); + + if(renderTarget) { - mGl.DrawElements(GetTopology(topology), - static_cast(drawCmds[0]->data.draw.drawIndexed.indexCount), - GL_UNSIGNED_SHORT, - reinterpret_cast(drawCmds[0]->data.draw.drawIndexed.firstIndex)); + auto fb = renderTarget->mCreateInfo.framebuffer; + if(fb) + { + if(currentFramebuffer != fb) + { + currentFramebuffer = Uncast(fb); + currentFramebuffer->Bind(); + } + } + else + { + mGl.BindFramebuffer(GL_FRAMEBUFFER, 0); + } } else { - mGl.DrawArrays(GetTopology(topology), 0, drawCmds[0]->data.draw.draw.vertexCount); + mGl.BindFramebuffer(GL_FRAMEBUFFER, 0); } + + auto& clearValues = cmd.data.beginRenderPass.clearValues; + if(clearValues.size() > 0) + { + const auto renderPass = static_cast(cmd.data.beginRenderPass.renderPass); + if(renderPass) + { + const auto& color0 = renderPass->attachments[0]; + GLuint mask = 0; + if(color0.loadOp == Graphics::AttachmentLoadOp::CLEAR) + { + mask |= GL_COLOR_BUFFER_BIT; + + // Set clear color (todo: cache it!) + // Something goes wrong here if Alpha mask is GL_TRUE + mGl.ColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE); + mGl.ClearColor(clearValues[0].color.r, + clearValues[0].color.g, + clearValues[0].color.b, + clearValues[0].color.a); + } + + // check for depth stencil + if(renderPass->attachments.size() > 1) + { + const auto& depthStencil = renderPass->attachments.back(); + if(depthStencil.loadOp == Graphics::AttachmentLoadOp::CLEAR) + { + mGl.DepthMask(true); + uint32_t depthClearColor = 0u; + if(clearValues.size() == renderPass->attachments.size()) + { + depthClearColor = clearValues.back().depthStencil.depth; + } + mGl.ClearDepthf(depthClearColor); + mask |= GL_DEPTH_BUFFER_BIT; + } + if(depthStencil.stencilLoadOp == Graphics::AttachmentLoadOp::CLEAR) + { + uint32_t stencilClearColor = 0u; + if(clearValues.size() == renderPass->attachments.size()) + { + stencilClearColor = clearValues.back().depthStencil.stencil; + } + mGl.ClearStencil(stencilClearColor); + mGl.StencilMask(0xFF); // Clear all the bitplanes (assume 8) + mask |= GL_STENCIL_BUFFER_BIT; + } + } + + if(mask != 0) + { + // Test scissor area and RT size + const auto& area = cmd.data.beginRenderPass.renderArea; + if(area.x == 0 && + area.y == 0 && + renderTarget && + area.width == renderTarget->mCreateInfo.extent.width && + area.height == renderTarget->mCreateInfo.extent.height) + { + mGl.Disable(GL_SCISSOR_TEST); + mGl.Clear(mask); + } + else + { + mGl.Enable(GL_SCISSOR_TEST); + mGl.Scissor(cmd.data.beginRenderPass.renderArea.x, cmd.data.beginRenderPass.renderArea.y, cmd.data.beginRenderPass.renderArea.width, cmd.data.beginRenderPass.renderArea.height); + mGl.Clear(mask); + mGl.Disable(GL_SCISSOR_TEST); + } + } + } + else + { + DALI_ASSERT_DEBUG(0 && "BeginRenderPass has no render pass"); + } + } + break; } - // attribute clear - for(auto& attribute : vi.attributes) + case CommandType::END_RENDER_PASS: { - mGl.DisableVertexAttribArray(attribute.location); + if(cmd.data.endRenderPass.syncObject != nullptr) + { + auto syncObject = Uncast(cmd.data.endRenderPass.syncObject); + syncObject->InitializeResource(); // create the sync object. + } + break; } } } } +void TestGraphicsController::BindPipeline(TestGraphicsPipeline* pipeline) +{ + auto& vi = pipeline->vertexInputState; + for(auto& attribute : vi.attributes) + { + mGl.EnableVertexAttribArray(attribute.location); + uint32_t attributeOffset = attribute.offset; + GLsizei stride = vi.bufferBindings[attribute.binding].stride; + + mGl.VertexAttribPointer(attribute.location, + GetNumComponents(attribute.format), + GetGlType(attribute.format), + GL_FALSE, // Not normalized + stride, + reinterpret_cast(attributeOffset)); + } + + // Cull face setup + auto& rasterizationState = pipeline->rasterizationState; + if(rasterizationState.cullMode == Graphics::CullMode::NONE) + { + mGl.Disable(GL_CULL_FACE); + } + else + { + mGl.Enable(GL_CULL_FACE); + mGl.CullFace(GetCullFace(rasterizationState.cullMode)); + } + + mGl.FrontFace(GetFrontFace(rasterizationState.frontFace)); + + // Blending setup + auto& colorBlendState = pipeline->colorBlendState; + if(colorBlendState.blendEnable) + { + mGl.Enable(GL_BLEND); + + mGl.BlendFuncSeparate(GetBlendFactor(colorBlendState.srcColorBlendFactor), + GetBlendFactor(colorBlendState.dstColorBlendFactor), + GetBlendFactor(colorBlendState.srcAlphaBlendFactor), + GetBlendFactor(colorBlendState.dstAlphaBlendFactor)); + if(colorBlendState.colorBlendOp != colorBlendState.alphaBlendOp) + { + mGl.BlendEquationSeparate(GetBlendOp(colorBlendState.colorBlendOp), GetBlendOp(colorBlendState.alphaBlendOp)); + } + else + { + mGl.BlendEquation(GetBlendOp(colorBlendState.colorBlendOp)); + } + mGl.BlendColor(colorBlendState.blendConstants[0], + colorBlendState.blendConstants[1], + colorBlendState.blendConstants[2], + colorBlendState.blendConstants[3]); + } + else + { + mGl.Disable(GL_BLEND); + } + + auto* program = static_cast(pipeline->programState.program); + mGl.UseProgram(program->mImpl->mId); +} + /** * @brief Presents render target * @param renderTarget render target to present @@ -713,6 +1015,15 @@ void TestGraphicsController::UpdateTextures(const std::vector(&texture); + mGl.BindTexture(gfxTexture->GetTarget(), 0); + mGl.GenerateMipmap(gfxTexture->GetTarget()); +} + bool TestGraphicsController::EnableDepthStencilBuffer(bool enableDepth, bool enableStencil) { TraceCallStack::NamedParams namedParams; @@ -770,7 +1081,7 @@ Graphics::UniquePtr TestGraphicsController::CreateComma Graphics::UniquePtr TestGraphicsController::CreateRenderPass(const Graphics::RenderPassCreateInfo& renderPassCreateInfo, Graphics::UniquePtr&& oldRenderPass) { mCallStack.PushCall("CreateRenderPass", ""); - return nullptr; + return Graphics::MakeUnique(mGl, renderPassCreateInfo); } Graphics::UniquePtr TestGraphicsController::CreateTexture(const Graphics::TextureCreateInfo& textureCreateInfo, Graphics::UniquePtr&& oldTexture) @@ -782,10 +1093,15 @@ Graphics::UniquePtr TestGraphicsController::CreateTexture(con return Graphics::MakeUnique(mGl, textureCreateInfo); } -Graphics::UniquePtr TestGraphicsController::CreateFramebuffer(const Graphics::FramebufferCreateInfo& framebufferCreateInfo, Graphics::UniquePtr&& oldFramebuffer) +Graphics::UniquePtr TestGraphicsController::CreateFramebuffer( + const Graphics::FramebufferCreateInfo& createInfo, + Graphics::UniquePtr&& oldFramebuffer) { - mCallStack.PushCall("CreateFramebuffer", ""); - return nullptr; + TraceCallStack::NamedParams namedParams; + namedParams["framebufferCreateInfo"] << createInfo; + mCallStack.PushCall("Controller::CreateFramebuffer", namedParams.str(), namedParams); + + return Graphics::MakeUnique(mFrameBufferCallStack, mGl, createInfo); } Graphics::UniquePtr TestGraphicsController::CreatePipeline(const Graphics::PipelineCreateInfo& pipelineCreateInfo, Graphics::UniquePtr&& oldPipeline) @@ -849,7 +1165,15 @@ Graphics::UniquePtr TestGraphicsController::CreateSampler(con Graphics::UniquePtr TestGraphicsController::CreateRenderTarget(const Graphics::RenderTargetCreateInfo& renderTargetCreateInfo, Graphics::UniquePtr&& oldRenderTarget) { mCallStack.PushCall("CreateRenderTarget", ""); - return nullptr; + return Graphics::MakeUnique(mGl, renderTargetCreateInfo); +} + +Graphics::UniquePtr TestGraphicsController::CreateSyncObject( + const Graphics::SyncObjectCreateInfo& syncObjectCreateInfo, + Graphics::UniquePtr&& oldSyncObject) +{ + mCallStack.PushCall("CreateSyncObject", ""); + return Graphics::MakeUnique(mGraphicsSyncImpl, syncObjectCreateInfo); } Graphics::UniquePtr TestGraphicsController::MapBufferRange(const Graphics::MapBufferInfo& mapInfo)