/** * Check if primitive restart is enabled, and if so, handle it properly. * * In some cases the support will be handled in software. When available * hardware will handle primitive restart. */ GLboolean brw_handle_primitive_restart(struct gl_context *ctx, const struct _mesa_prim *prims, GLuint nr_prims, const struct _mesa_index_buffer *ib, struct gl_buffer_object *indirect) { struct brw_context *brw = brw_context(ctx); /* We only need to handle cases where there is an index buffer. */ if (ib == NULL) { return GL_FALSE; } /* If the driver has requested software handling of primitive restarts, * then the VBO module has already taken care of things, and we can * just draw as normal. */ if (ctx->Const.PrimitiveRestartInSoftware) { return GL_FALSE; } /* If we have set the in_progress flag, then we are in the middle * of handling the primitive restart draw. */ if (brw->prim_restart.in_progress) { return GL_FALSE; } /* If PrimitiveRestart is not enabled, then we aren't concerned about * handling this draw. */ if (!(ctx->Array._PrimitiveRestart)) { return GL_FALSE; } /* Signal that we are in the process of handling the * primitive restart draw */ brw->prim_restart.in_progress = true; if (can_cut_index_handle_prims(ctx, prims, nr_prims, ib)) { /* Cut index should work for primitive restart, so use it */ brw->prim_restart.enable_cut_index = true; brw_draw_prims(ctx, prims, nr_prims, ib, GL_FALSE, -1, -1, NULL, indirect); brw->prim_restart.enable_cut_index = false; } else { /* Not all the primitive draw modes are supported by the cut index, * so take the software path */ vbo_sw_primitive_restart(ctx, prims, nr_prims, ib, indirect); } brw->prim_restart.in_progress = false; /* The primitive restart draw was completed, so return true. */ return GL_TRUE; }
static void brw_draw_rectlist(struct brw_context *brw, struct rect *rect, int num_instances) { struct gl_context *ctx = &brw->ctx; struct brw_fast_clear_state *clear = brw->fast_clear_state; int start = 0, count = 3; struct _mesa_prim prim; float verts[6]; verts[0] = rect->x1; verts[1] = rect->y1; verts[2] = rect->x0; verts[3] = rect->y1; verts[4] = rect->x0; verts[5] = rect->y0; /* upload new vertex data */ _mesa_buffer_data(ctx, clear->buf_obj, GL_NONE, sizeof(verts), verts, GL_DYNAMIC_DRAW, __func__); if (ctx->NewState) _mesa_update_state(ctx); vbo_bind_arrays(ctx); memset(&prim, 0, sizeof prim); prim.begin = 1; prim.end = 1; prim.mode = BRW_PRIM_OFFSET + _3DPRIM_RECTLIST; prim.num_instances = num_instances; prim.start = start; prim.count = count; /* Make sure our internal prim value doesn't clash with a valid GL value. */ assert(!_mesa_is_valid_prim_mode(ctx, prim.mode)); brw_draw_prims(ctx, &prim, 1, NULL, GL_TRUE, start, start + count - 1, NULL, 0, NULL); }
static void meta_draw_quad(struct intel_context *intel, GLfloat x0, GLfloat x1, GLfloat y0, GLfloat y1, GLfloat z, GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha, GLfloat s0, GLfloat s1, GLfloat t0, GLfloat t1) { GLcontext *ctx = &intel->ctx; struct brw_context *brw = brw_context(&intel->ctx); struct gl_client_array pos_array; struct gl_client_array color_array; struct gl_client_array *attribs[VERT_ATTRIB_MAX]; struct _mesa_prim prim[1]; GLfloat pos[4][3]; GLubyte color[4]; ctx->Driver.BufferData(ctx, GL_ARRAY_BUFFER_ARB, sizeof(pos) + sizeof(color), NULL, GL_DYNAMIC_DRAW_ARB, brw->metaops.vbo); pos[0][0] = x0; pos[0][1] = y0; pos[0][2] = z; pos[1][0] = x1; pos[1][1] = y0; pos[1][2] = z; pos[2][0] = x1; pos[2][1] = y1; pos[2][2] = z; pos[3][0] = x0; pos[3][1] = y1; pos[3][2] = z; ctx->Driver.BufferSubData(ctx, GL_ARRAY_BUFFER_ARB, 0, sizeof(pos), pos, brw->metaops.vbo); color[0] = red; color[1] = green; color[2] = blue; color[3] = alpha; ctx->Driver.BufferSubData(ctx, GL_ARRAY_BUFFER_ARB, sizeof(pos), sizeof(color), color, brw->metaops.vbo); /* Ignoring texture coords. */ memset(attribs, 0, VERT_ATTRIB_MAX * sizeof(*attribs)); attribs[VERT_ATTRIB_POS] = &pos_array; attribs[VERT_ATTRIB_POS]->Ptr = 0; attribs[VERT_ATTRIB_POS]->Type = GL_FLOAT; attribs[VERT_ATTRIB_POS]->Enabled = 1; attribs[VERT_ATTRIB_POS]->Size = 3; attribs[VERT_ATTRIB_POS]->StrideB = 3 * sizeof(GLfloat); attribs[VERT_ATTRIB_POS]->Stride = 3 * sizeof(GLfloat); attribs[VERT_ATTRIB_POS]->_MaxElement = 4; attribs[VERT_ATTRIB_POS]->Normalized = 0; attribs[VERT_ATTRIB_POS]->BufferObj = brw->metaops.vbo; attribs[VERT_ATTRIB_COLOR0] = &color_array; attribs[VERT_ATTRIB_COLOR0]->Ptr = (const GLubyte *)sizeof(pos); attribs[VERT_ATTRIB_COLOR0]->Type = GL_UNSIGNED_BYTE; attribs[VERT_ATTRIB_COLOR0]->Enabled = 1; attribs[VERT_ATTRIB_COLOR0]->Size = 4; attribs[VERT_ATTRIB_COLOR0]->StrideB = 0; attribs[VERT_ATTRIB_COLOR0]->Stride = 0; attribs[VERT_ATTRIB_COLOR0]->_MaxElement = 1; attribs[VERT_ATTRIB_COLOR0]->Normalized = 1; attribs[VERT_ATTRIB_COLOR0]->BufferObj = brw->metaops.vbo; /* Just ignoring texture coordinates for now. */ memset(prim, 0, sizeof(*prim)); prim[0].mode = GL_TRIANGLE_FAN; prim[0].begin = 1; prim[0].end = 1; prim[0].weak = 0; prim[0].pad = 0; prim[0].start = 0; prim[0].count = 4; brw_draw_prims(&brw->intel.ctx, (const struct gl_client_array **)attribs, prim, 1, NULL, 0, 3 ); }