mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-02-25 00:22:10 +00:00
Draw: Use uniform locs for GLES, add samplers.
So that we can initialize and bind samplers.
This commit is contained in:
parent
dcf4498f82
commit
64435e56b1
@ -929,9 +929,9 @@ void GLQueueRunner::PerformRenderPass(const GLRStep &step) {
|
||||
case GLRRenderCommand::UNIFORMMATRIX:
|
||||
{
|
||||
assert(curProgram);
|
||||
int loc = c.uniform4.loc ? *c.uniform4.loc : -1;
|
||||
if (c.uniform4.name) {
|
||||
loc = curProgram->GetUniformLoc(c.uniform4.name);
|
||||
int loc = c.uniformMatrix4.loc ? *c.uniformMatrix4.loc : -1;
|
||||
if (c.uniformMatrix4.name) {
|
||||
loc = curProgram->GetUniformLoc(c.uniformMatrix4.name);
|
||||
}
|
||||
if (loc >= 0) {
|
||||
glUniformMatrix4fv(loc, 1, false, c.uniformMatrix4.m);
|
||||
|
@ -117,13 +117,13 @@ struct GLRRenderData {
|
||||
} drawIndexed;
|
||||
struct {
|
||||
const char *name; // if null, use loc
|
||||
GLint *loc; // NOTE: This is a pointer so we can immediately use things that are "queried" during program creation.
|
||||
const GLint *loc; // NOTE: This is a pointer so we can immediately use things that are "queried" during program creation.
|
||||
GLint count;
|
||||
float v[4];
|
||||
} uniform4;
|
||||
struct {
|
||||
const char *name; // if null, use loc
|
||||
GLint *loc;
|
||||
const GLint *loc;
|
||||
float m[16];
|
||||
} uniformMatrix4;
|
||||
struct {
|
||||
|
@ -647,7 +647,7 @@ public:
|
||||
curRenderStep_->commands.push_back(data);
|
||||
}
|
||||
|
||||
void SetUniformI(GLint *loc, int count, const int *udata) {
|
||||
void SetUniformI(const GLint *loc, int count, const int *udata) {
|
||||
_dbg_assert_(G3D, curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER);
|
||||
#ifdef _DEBUG
|
||||
assert(curProgram_);
|
||||
@ -659,7 +659,7 @@ public:
|
||||
curRenderStep_->commands.push_back(data);
|
||||
}
|
||||
|
||||
void SetUniformI1(GLint *loc, int udata) {
|
||||
void SetUniformI1(const GLint *loc, int udata) {
|
||||
_dbg_assert_(G3D, curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER);
|
||||
#ifdef _DEBUG
|
||||
assert(curProgram_);
|
||||
@ -671,7 +671,7 @@ public:
|
||||
curRenderStep_->commands.push_back(data);
|
||||
}
|
||||
|
||||
void SetUniformF(GLint *loc, int count, const float *udata) {
|
||||
void SetUniformF(const GLint *loc, int count, const float *udata) {
|
||||
_dbg_assert_(G3D, curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER);
|
||||
#ifdef _DEBUG
|
||||
assert(curProgram_);
|
||||
@ -683,7 +683,7 @@ public:
|
||||
curRenderStep_->commands.push_back(data);
|
||||
}
|
||||
|
||||
void SetUniformF1(GLint *loc, const float udata) {
|
||||
void SetUniformF1(const GLint *loc, const float udata) {
|
||||
_dbg_assert_(G3D, curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER);
|
||||
#ifdef _DEBUG
|
||||
assert(curProgram_);
|
||||
@ -707,7 +707,7 @@ public:
|
||||
curRenderStep_->commands.push_back(data);
|
||||
}
|
||||
|
||||
void SetUniformM4x4(GLint *loc, const float *udata) {
|
||||
void SetUniformM4x4(const GLint *loc, const float *udata) {
|
||||
_dbg_assert_(G3D, curRenderStep_ && curRenderStep_->stepType == GLRStepType::RENDER);
|
||||
#ifdef _DEBUG
|
||||
assert(curProgram_);
|
||||
|
@ -323,6 +323,8 @@ public:
|
||||
|
||||
// TODO: Optimize by getting the locations first and putting in a custom struct
|
||||
UniformBufferDesc dynamicUniforms;
|
||||
GLint samplerLocs_[8];
|
||||
std::vector<GLint> dynamicUniformLocs_;
|
||||
GLRProgram *program_ = nullptr;
|
||||
|
||||
private:
|
||||
@ -964,6 +966,10 @@ Pipeline *OpenGLContext::CreateGraphicsPipeline(const PipelineDesc &desc) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
if (desc.uniformDesc) {
|
||||
pipeline->dynamicUniforms = *desc.uniformDesc;
|
||||
pipeline->dynamicUniformLocs_.resize(desc.uniformDesc->uniforms.size());
|
||||
}
|
||||
ILOG("Linking shaders.");
|
||||
if (pipeline->LinkShaders()) {
|
||||
// Build the rest of the virtual pipeline object.
|
||||
@ -976,8 +982,6 @@ Pipeline *OpenGLContext::CreateGraphicsPipeline(const PipelineDesc &desc) {
|
||||
pipeline->blend->AddRef();
|
||||
pipeline->raster->AddRef();
|
||||
pipeline->inputLayout->AddRef();
|
||||
if (desc.uniformDesc)
|
||||
pipeline->dynamicUniforms = *desc.uniformDesc;
|
||||
return pipeline;
|
||||
} else {
|
||||
ELOG("Failed to create pipeline - shaders failed to link");
|
||||
@ -1050,7 +1054,14 @@ bool OpenGLPipeline::LinkShaders() {
|
||||
semantics.push_back({ SEM_POSITION, "a_position" });
|
||||
semantics.push_back({ SEM_TEXCOORD0, "a_texcoord0" });
|
||||
std::vector<GLRProgram::UniformLocQuery> queries;
|
||||
queries.push_back({ &samplerLocs_[0], "sampler0" });
|
||||
queries.push_back({ &samplerLocs_[1], "sampler1" });
|
||||
for (size_t i = 0; i < dynamicUniforms.uniforms.size(); ++i) {
|
||||
queries.push_back({ &dynamicUniformLocs_[i], dynamicUniforms.uniforms[i].name });
|
||||
}
|
||||
std::vector<GLRProgram::Initializer> initialize;
|
||||
initialize.push_back({ &samplerLocs_[0], 0, 0 });
|
||||
initialize.push_back({ &samplerLocs_[1], 0, 1 });
|
||||
program_ = render_->CreateProgram(linkShaders, semantics, queries, initialize, false);
|
||||
return true;
|
||||
}
|
||||
@ -1070,17 +1081,19 @@ void OpenGLContext::UpdateDynamicUniformBuffer(const void *ub, size_t size) {
|
||||
Crash();
|
||||
}
|
||||
|
||||
for (auto &uniform : curPipeline_->dynamicUniforms.uniforms) {
|
||||
for (size_t i = 0; i < curPipeline_->dynamicUniforms.uniforms.size(); ++i) {
|
||||
const auto &uniform = curPipeline_->dynamicUniforms.uniforms[i];
|
||||
const GLint &loc = curPipeline_->dynamicUniformLocs_[i];
|
||||
const float *data = (const float *)((uint8_t *)ub + uniform.offset);
|
||||
switch (uniform.type) {
|
||||
case UniformType::FLOAT1:
|
||||
case UniformType::FLOAT2:
|
||||
case UniformType::FLOAT3:
|
||||
case UniformType::FLOAT4:
|
||||
renderManager_.SetUniformF(uniform.name, 1 + (int)uniform.type - (int)UniformType::FLOAT1, data);
|
||||
renderManager_.SetUniformF(&loc, 1 + (int)uniform.type - (int)UniformType::FLOAT1, data);
|
||||
break;
|
||||
case UniformType::MATRIX4X4:
|
||||
renderManager_.SetUniformM4x4(uniform.name, data);
|
||||
renderManager_.SetUniformM4x4(&loc, data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user