68 if (active_mtl_shader ==
nullptr || !active_mtl_shader->
is_valid() ||
74 "MTLImmediate::end -- cannot perform draw as active shader is NULL or invalid (likely "
75 "unimplemented) (shader %p '%s')",
82 id<MTLRenderCommandEncoder> rec = context_->ensure_begin_render_pass();
93 [rec pushDebugGroup:[NSString
94 stringWithFormat:
@"immEnd(verts: %d, shader: %s)",
97 [rec insertDebugSignpost:[NSString stringWithFormat:
@"immEnd(verts: %d, shader: %s)",
121 for (
int i = 0;
i <
interface->get_total_attributes();
i++) {
130 for (uint32_t a_idx = 0; a_idx < this->
vertex_format.attr_len && attr ==
nullptr; a_idx++) {
134 for (uint32_t n_idx = 0; n_idx < check_attribute->
name_len; n_idx++) {
139 attr = check_attribute;
146 "Could not find expected attribute in immediate mode vertex format.");
147 if (attr ==
nullptr) {
149 "MTLImmediate::end Could not find matching attribute '%s' from Shader Interface in "
150 "Vertex Format! - TODO: Bind Dummy attribute",
157 MTLVertexFormat convertedFormat;
164 if (can_use_implicit_conversion) {
178 BLI_assert(convertedFormat != MTLVertexFormatInvalid);
210 uchar *buffer_data =
reinterpret_cast<uchar *
>(current_allocation_.data);
216 if (this->
shader->is_polyline) {
224 if (context_->ensure_render_pipeline_state(mtl_prim_type)) {
237 bool rendered =
false;
246 uint32_t num_triangles =
max_ii(base_vert_count - 2, 0);
247 uint32_t fan_index_count = num_triangles * 3;
250 uint32_t alloc_size =
sizeof(uint32_t) * fan_index_count;
251 uint32_t *index_buffer =
nullptr;
254 context_->get_scratchbuffer_manager().scratch_buffer_allocate_range_aligned(
256 index_buffer = (uint32_t *)allocation.
data;
259 for (
int i = 0;
i < num_triangles;
i++) {
260 index_buffer[a++] = 0;
261 index_buffer[a++] =
i + 1;
262 index_buffer[a++] =
i + 2;
267 id<MTLBuffer> index_buffer_mtl = nil;
277 context_->ensure_depth_stencil_state(MTLPrimitiveTypeTriangle);
281 current_allocation_.metal_buffer, current_allocation_.buffer_offset, 0);
284 [rec drawIndexedPrimitives:MTLPrimitiveTypeTriangle
285 indexCount:fan_index_count
286 indexType:MTLIndexTypeUInt32
287 indexBuffer:index_buffer_mtl
288 indexBufferOffset:index_buffer_offset];
289 context_->main_command_buffer.register_draw_counters(fan_index_count);
302 MTLPrimitiveType primitive_type = metal_primitive_type_;
307 current_allocation_.metal_buffer, current_allocation_.buffer_offset, 0);
310 context_->ensure_depth_stencil_state(primitive_type);
312 if (this->
shader->is_polyline) {
317 [rec drawPrimitives:primitive_type vertexStart:0 vertexCount:vertex_count];
318 context_->main_command_buffer.register_draw_counters(vertex_count);
326 if (this->
shader->is_polyline) {
327 context_->get_scratchbuffer_manager().unbind_as_ssbo();
340 if (current_allocation_.metal_buffer) {
341 [current_allocation_.metal_buffer release];
342 current_allocation_.metal_buffer = nil;
static MTLContext * get()