DRW: Manager: Finish / change implementation of framebuffer_set command

Use reference instead of direct pointer. This is because framebuffers
often use temp textures and are configured later just before submission.
This commit is contained in:
2022-11-13 16:08:33 +01:00
parent f1466ce9a8
commit 930d14cc62
3 changed files with 14 additions and 5 deletions

View File

@@ -32,7 +32,7 @@ void ShaderBind::execute(RecordingState &state) const
void FramebufferBind::execute() const
{
GPU_framebuffer_bind(framebuffer);
GPU_framebuffer_bind(*framebuffer);
}
void ResourceBind::execute() const
@@ -234,7 +234,8 @@ std::string ShaderBind::serialize() const
std::string FramebufferBind::serialize() const
{
return std::string(".framebuffer_bind(") + GPU_framebuffer_get_name(framebuffer) + ")";
return std::string(".framebuffer_bind(") +
(*framebuffer == nullptr ? "nullptr" : GPU_framebuffer_get_name(*framebuffer)) + ")";
}
std::string ResourceBind::serialize() const

View File

@@ -120,7 +120,7 @@ struct ShaderBind {
};
struct FramebufferBind {
GPUFrameBuffer *framebuffer;
GPUFrameBuffer **framebuffer;
void execute() const;
std::string serialize() const;
@@ -343,6 +343,7 @@ struct StencilSet {
union Undetermined {
ShaderBind shader_bind;
ResourceBind resource_bind;
FramebufferBind framebuffer_bind;
PushConstant push_constant;
Draw draw;
DrawMulti draw_multi;

View File

@@ -195,8 +195,9 @@ class PassBase {
/**
* Bind a framebuffer. This is equivalent to a deferred GPU_framebuffer_bind() call.
* \note Changes the global GPU state (outside of DRW).
* \note Capture reference to the framebuffer so it can be initialized later.
*/
void framebuffer_set(GPUFrameBuffer *framebuffer);
void framebuffer_set(GPUFrameBuffer **framebuffer);
/**
* Bind a material shader along with its associated resources. Any following bind() or
@@ -506,6 +507,9 @@ template<class T> void PassBase<T>::submit(command::RecordingState &state) const
case Type::SubPass:
sub_passes_[header.index].submit(state);
break;
case command::Type::FramebufferBind:
commands_[header.index].framebuffer_bind.execute();
break;
case command::Type::ShaderBind:
commands_[header.index].shader_bind.execute(state);
break;
@@ -561,6 +565,9 @@ template<class T> std::string PassBase<T>::serialize(std::string line_prefix) co
case Type::SubPass:
ss << sub_passes_[header.index].serialize(line_prefix);
break;
case Type::FramebufferBind:
ss << line_prefix << commands_[header.index].framebuffer_bind.serialize() << std::endl;
break;
case Type::ShaderBind:
ss << line_prefix << commands_[header.index].shader_bind.serialize() << std::endl;
break;
@@ -754,7 +761,7 @@ template<class T> inline void PassBase<T>::shader_set(GPUShader *shader)
create_command(Type::ShaderBind).shader_bind = {shader};
}
template<class T> inline void PassBase<T>::framebuffer_set(GPUFrameBuffer *framebuffer)
template<class T> inline void PassBase<T>::framebuffer_set(GPUFrameBuffer **framebuffer)
{
create_command(Type::FramebufferBind).framebuffer_bind = {framebuffer};
}