Files
test/source/blender/gpu/intern/gpu_immediate_private.hh
Clément Foucault 00a8d006fe GPU: Move Polyline shader to primitive expansion
This port is not so straightforward.

This shader is used in different configurations and is
available to python bindings. So we need to keep
compatibility with different attributes configurations.

This is why attributes are loaded per component and a
uniform sets the length of the component.

Since this shader can be used from both the imm and batch
API, we need to inject some workarounds to bind the buffers
correctly.

The end result is still less versatile than the previous
metal workaround (i.e.: more attribute fetch mode supported),
but it is also way less code.

### Limitations:
The new shader has some limitation:
- Both `color` and `pos` attributes need to be `F32`.
- Each attribute needs to be 4byte aligned.
- Fetch type needs to be `GPU_FETCH_FLOAT`.
- Primitive type needs to be `GPU_PRIM_LINES`, `GPU_PRIM_LINE_STRIP` or `GPU_PRIM_LINE_LOOP`.
- If drawing using an index buffer, it must contain no primitive restart.

Rel #127493

Co-authored-by: Jeroen Bakker <jeroen@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/129315
2024-11-27 17:37:04 +01:00

68 lines
1.8 KiB
C++

/* SPDX-FileCopyrightText: 2016 by Mike Erwin. All rights reserved.
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup gpu
*
* Mimics old style opengl immediate mode drawing.
*/
#pragma once
#include <optional>
#include "GPU_batch.hh"
#include "GPU_primitive.hh"
#include "GPU_shader.hh"
#include "GPU_vertex_format.hh"
namespace blender::gpu {
class Immediate {
public:
/** Pointer to the mapped buffer data for the current vertex. */
uchar *vertex_data = nullptr;
/** Current vertex index. */
uint vertex_idx = 0;
/** Length of the buffer in vertices. */
uint vertex_len = 0;
/** Which attributes of current vertex have not been given values? */
uint16_t unassigned_attr_bits = 0;
/** Attributes that needs to be set. One bit per attribute. */
uint16_t enabled_attr_bits = 0;
/** Current draw call specification. */
GPUPrimType prim_type = GPU_PRIM_NONE;
GPUVertFormat vertex_format = {};
GPUShader *shader = nullptr;
/** Enforce strict vertex count (disabled when using #immBeginAtMost). */
bool strict_vertex_len = true;
/** Batch in construction when using #immBeginBatch. */
Batch *batch = nullptr;
/** Wide Line workaround. */
/** Previously bound shader to restore after drawing. */
std::optional<eGPUBuiltinShader> prev_builtin_shader;
/** Builtin shader index. Used to test if the line width workaround can be done. */
std::optional<eGPUBuiltinShader> builtin_shader_bound;
/** Uniform color: Kept here to update the wide-line shader just before #immBegin. */
float uniform_color[4];
Immediate() = default;
virtual ~Immediate() = default;
virtual uchar *begin() = 0;
virtual void end() = 0;
/* To be called after polyline SSBO binding. */
void polyline_draw_workaround(uint64_t offset);
};
} // namespace blender::gpu
void immActivate();
void immDeactivate();