DRW: Manager: Add possibility to record a framebuffer change inside a pass
This is a convenience when one needs to often change the current framebuffer and avoid the overhead of creating many Main/Simple passes.
This commit is contained in:
@@ -30,6 +30,11 @@ void ShaderBind::execute(RecordingState &state) const
|
||||
}
|
||||
}
|
||||
|
||||
void FramebufferBind::execute() const
|
||||
{
|
||||
GPU_framebuffer_bind(framebuffer);
|
||||
}
|
||||
|
||||
void ResourceBind::execute() const
|
||||
{
|
||||
if (slot == -1) {
|
||||
@@ -229,6 +234,11 @@ std::string ShaderBind::serialize() const
|
||||
return std::string(".shader_bind(") + GPU_shader_get_name(shader) + ")";
|
||||
}
|
||||
|
||||
std::string FramebufferBind::serialize() const
|
||||
{
|
||||
return std::string(".framebuffer_bind(") + GPU_framebuffer_get_name(framebuffer) + ")";
|
||||
}
|
||||
|
||||
std::string ResourceBind::serialize() const
|
||||
{
|
||||
switch (type) {
|
||||
|
||||
@@ -88,6 +88,7 @@ enum class Type : uint8_t {
|
||||
DispatchIndirect,
|
||||
Draw,
|
||||
DrawIndirect,
|
||||
FramebufferBind,
|
||||
PushConstant,
|
||||
ResourceBind,
|
||||
ShaderBind,
|
||||
@@ -118,6 +119,13 @@ struct ShaderBind {
|
||||
std::string serialize() const;
|
||||
};
|
||||
|
||||
struct FramebufferBind {
|
||||
GPUFrameBuffer *framebuffer;
|
||||
|
||||
void execute() const;
|
||||
std::string serialize() const;
|
||||
};
|
||||
|
||||
struct ResourceBind {
|
||||
eGPUSamplerState sampler;
|
||||
int slot;
|
||||
|
||||
@@ -14,8 +14,7 @@
|
||||
* #Pass. Use many #PassSub along with a main #Pass to reduce the overhead and allow groupings of
|
||||
* commands. \note The draw call order inside a batch of multiple draw with the exact same state is
|
||||
* not guaranteed and is not even deterministic. Use a #PassSimple or #PassSortable if ordering is
|
||||
* needed. \note As of now, it is also quite limited in the type of draw command it can record
|
||||
* (no custom vertex count, no custom first vertex).
|
||||
* needed. Custom vertex count and custom first vertex will effectively disable batching.
|
||||
*
|
||||
* `PassSimple`:
|
||||
* Does not have the overhead of #PassMain but does not have the culling and batching optimization.
|
||||
@@ -191,6 +190,12 @@ class PassBase {
|
||||
*/
|
||||
void shader_set(GPUShader *shader);
|
||||
|
||||
/**
|
||||
* Bind a framebuffer. This is equivalent to a deferred GPU_framebuffer_bind() call.
|
||||
* \note Changes the global GPU state (outside of DRW).
|
||||
*/
|
||||
void framebuffer_set(GPUFrameBuffer *framebuffer);
|
||||
|
||||
/**
|
||||
* Bind a material shader along with its associated resources. Any following bind() or
|
||||
* push_constant() call will use its interface.
|
||||
@@ -743,6 +748,11 @@ 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)
|
||||
{
|
||||
create_command(Type::FramebufferBind).framebuffer_bind = {framebuffer};
|
||||
}
|
||||
|
||||
template<class T> inline void PassBase<T>::material_set(Manager &manager, GPUMaterial *material)
|
||||
{
|
||||
GPUPass *gpupass = GPU_material_get_pass(material);
|
||||
|
||||
@@ -47,6 +47,9 @@ typedef struct GPUOffScreen GPUOffScreen;
|
||||
GPUFrameBuffer *GPU_framebuffer_create(const char *name);
|
||||
void GPU_framebuffer_free(GPUFrameBuffer *fb);
|
||||
void GPU_framebuffer_bind(GPUFrameBuffer *fb);
|
||||
|
||||
const char *GPU_framebuffer_get_name(GPUFrameBuffer *fb);
|
||||
|
||||
/**
|
||||
* Workaround for binding a SRGB frame-buffer without doing the SRGB transform.
|
||||
*/
|
||||
|
||||
@@ -238,6 +238,11 @@ void GPU_framebuffer_free(GPUFrameBuffer *gpu_fb)
|
||||
delete unwrap(gpu_fb);
|
||||
}
|
||||
|
||||
const char *GPU_framebuffer_get_name(GPUFrameBuffer *gpu_fb)
|
||||
{
|
||||
return unwrap(gpu_fb)->name_get();
|
||||
}
|
||||
|
||||
/* ---------- Binding ----------- */
|
||||
|
||||
void GPU_framebuffer_bind(GPUFrameBuffer *gpu_fb)
|
||||
|
||||
@@ -204,6 +204,11 @@ class FrameBuffer {
|
||||
{
|
||||
return attachments_[GPU_FB_COLOR_ATTACHMENT0 + slot].tex;
|
||||
};
|
||||
|
||||
inline const char *const name_get() const
|
||||
{
|
||||
return name_;
|
||||
};
|
||||
};
|
||||
|
||||
/* Syntactic sugar. */
|
||||
|
||||
Reference in New Issue
Block a user