// Shaders & Uniforms
GLuint mLastShaderIdUsed;
- GLuint mLastProgramIdUsed;
+ GLuint mLastProgramIdUsed{0u};
GLuint mLastUniformIdUsed;
typedef std::map<std::string, GLint> UniformIDMap;
typedef std::map<GLuint, UniformIDMap> ProgramUniformMap;
return const_cast<T*>(static_cast<const T*>(object));
}
+template<typename T>
+T* Uncast(const Graphics::Shader* object)
+{
+ return const_cast<T*>(static_cast<const T*>(object));
+}
+
std::ostream& operator<<(std::ostream& o, const Graphics::BufferCreateInfo& bufferCreateInfo)
{
return o << "usage:" << std::hex << bufferCreateInfo.usage << ", size:" << std::dec << bufferCreateInfo.size;
Graphics::UniquePtr<Graphics::Program> TestGraphicsController::CreateProgram(const Graphics::ProgramCreateInfo& programCreateInfo, Graphics::UniquePtr<Graphics::Program>&& oldProgram)
{
mCallStack.PushCall("CreateProgram", "");
- return Graphics::MakeUnique<TestGraphicsProgram>(mGl, programCreateInfo, mVertexFormats);
+
+ for(auto cacheEntry : mProgramCache)
+ {
+ bool found = true;
+ for(auto& shader : *(programCreateInfo.shaderState))
+ {
+ auto graphicsShader = Uncast<TestGraphicsShader>(shader.shader);
+ if(memcmp(cacheEntry.shaders[shader.pipelineStage], graphicsShader->mCreateInfo.sourceData, graphicsShader->mCreateInfo.sourceSize))
+ {
+ found = false;
+ break;
+ }
+ }
+ if(found)
+ {
+ return Graphics::MakeUnique<TestGraphicsProgram>(cacheEntry.programImpl);
+ }
+ }
+
+ mProgramCache.emplace_back();
+ mProgramCache.back().programImpl = new TestGraphicsProgramImpl(mGl, programCreateInfo, mVertexFormats);
+ for(auto& shader : *(programCreateInfo.shaderState))
+ {
+ auto graphicsShader = Uncast<TestGraphicsShader>(shader.shader);
+ mProgramCache.back().shaders[shader.pipelineStage] = graphicsShader->mCreateInfo.sourceData;
+ }
+ return Graphics::MakeUnique<TestGraphicsProgram>(mProgramCache.back().programImpl);
}
Graphics::UniquePtr<Graphics::Shader> TestGraphicsController::CreateShader(const Graphics::ShaderCreateInfo& shaderCreateInfo, Graphics::UniquePtr<Graphics::Shader>&& oldShader)
return false;
}
-bool TestGraphicsController::GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData )
+bool TestGraphicsController::GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData)
{
mCallStack.PushCall("GetProgramParameter", "");
auto graphicsProgram = Uncast<TestGraphicsProgram>(&program);
#include "test-gl-abstraction.h"
#include "test-gl-context-helper-abstraction.h"
#include "test-gl-sync-abstraction.h"
+#include "test-graphics-program.h"
#include "test-graphics-reflection.h"
namespace Dali
* @param[out] outData Pointer to output memory
* @return True on success
*/
- bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData ) override;
+ bool GetProgramParameter(Graphics::Program& program, uint32_t parameterId, void* outData) override;
public:
mutable TraceCallStack mCallStack;
bool isDrawOnResumeRequiredResult{true};
Property::Array mVertexFormats;
+
+ struct ProgramCache
+ {
+ std::map<Graphics::PipelineStage, const void*> shaders;
+ TestGraphicsProgramImpl* programImpl;
+ };
+ std::vector<ProgramCache> mProgramCache;
};
} // namespace Dali
namespace Dali
{
-TestGraphicsProgram::TestGraphicsProgram(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats)
+TestGraphicsProgramImpl::TestGraphicsProgramImpl(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats)
: mGl(gl),
mCreateInfo(createInfo),
mReflection(gl, vertexFormats)
{
- mId = 0;//mGl.CreateProgram();
+ mId = mGl.CreateProgram();
+ mGl.LinkProgram(1); // Ensure active sampler uniforms are set
}
-bool TestGraphicsProgram::GetParameter(uint32_t parameterId, void* outData )
+bool TestGraphicsProgramImpl::GetParameter(uint32_t parameterId, void* outData)
{
reinterpret_cast<uint32_t*>(outData)[0] = mId;
return true;
}
+TestGraphicsProgram::TestGraphicsProgram(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats)
+{
+ mImpl = new TestGraphicsProgramImpl(gl, createInfo, vertexFormats);
+}
+TestGraphicsProgram::TestGraphicsProgram(TestGraphicsProgramImpl* impl)
+{
+ mImpl = impl;
+}
} // namespace Dali
namespace Dali
{
-class TestGraphicsProgram : public Graphics::Program
+class TestGraphicsProgramImpl
{
public:
- TestGraphicsProgram(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats);
+ TestGraphicsProgramImpl(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats);
// For API
const TestGraphicsReflection& GetReflection() const
}
// For tests
- TestGraphicsReflection& GetProgamReflection()
+ TestGraphicsReflection& GetProgramReflection()
{
return mReflection;
}
- bool GetParameter(uint32_t parameterId, void* outData );
+ bool GetParameter(uint32_t parameterId, void* outData);
public:
TestGlAbstraction& mGl;
TestGraphicsReflection mReflection;
};
+class TestGraphicsProgram : public Graphics::Program
+{
+public:
+ TestGraphicsProgram(TestGlAbstraction& gl, const Graphics::ProgramCreateInfo& createInfo, Property::Array& vertexFormats);
+ TestGraphicsProgram(TestGraphicsProgramImpl* impl);
+
+ const TestGraphicsReflection& GetReflection() const
+ {
+ return mImpl->GetReflection();
+ }
+ bool GetParameter(uint32_t parameterId, void* outData)
+ {
+ return mImpl->GetParameter(parameterId, outData);
+ }
+
+ TestGraphicsReflection& GetProgamReflection()
+ {
+ return mImpl->GetProgramReflection();
+ }
+
+public:
+ TestGraphicsProgramImpl* mImpl;
+};
+
} // namespace Dali
#endif //DALI_TEST_GRAPHICS_PROGRAM_H