Implement new draw_vertices() path for simple vertex array drawing, use it for glClear.
This commit is contained in:
@@ -70,5 +70,10 @@ void draw_set_vertex_attributes( struct draw_context *draw,
|
|||||||
void draw_vb(struct draw_context *draw,
|
void draw_vb(struct draw_context *draw,
|
||||||
struct vertex_buffer *VB );
|
struct vertex_buffer *VB );
|
||||||
|
|
||||||
|
void draw_vertices(struct draw_context *draw,
|
||||||
|
GLuint mode,
|
||||||
|
GLuint numVertex, const GLfloat *verts,
|
||||||
|
GLuint numAttribs, const GLuint attribs[]);
|
||||||
|
|
||||||
|
|
||||||
#endif /* DRAW_CONTEXT_H */
|
#endif /* DRAW_CONTEXT_H */
|
||||||
|
@@ -57,7 +57,7 @@ static void draw_allocate_vertices( struct draw_context *draw,
|
|||||||
GLuint nr_vertices )
|
GLuint nr_vertices )
|
||||||
{
|
{
|
||||||
draw->nr_vertices = nr_vertices;
|
draw->nr_vertices = nr_vertices;
|
||||||
draw->verts = MALLOC( nr_vertices * draw->vertex_size );
|
draw->verts = (GLubyte *) malloc( nr_vertices * draw->vertex_size );
|
||||||
|
|
||||||
draw->pipeline.first->begin( draw->pipeline.first );
|
draw->pipeline.first->begin( draw->pipeline.first );
|
||||||
}
|
}
|
||||||
@@ -453,7 +453,7 @@ static void draw_release_vertices( struct draw_context *draw )
|
|||||||
{
|
{
|
||||||
draw->pipeline.first->end( draw->pipeline.first );
|
draw->pipeline.first->end( draw->pipeline.first );
|
||||||
|
|
||||||
FREE(draw->verts);
|
free(draw->verts);
|
||||||
draw->verts = NULL;
|
draw->verts = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -646,6 +646,63 @@ void draw_vb(struct draw_context *draw,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XXX Temporary mechanism to draw simple vertex arrays.
|
||||||
|
* All attribs are GLfloat[4]. Arrays are interleaved, in GL-speak.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
draw_vertices(struct draw_context *draw,
|
||||||
|
GLuint mode,
|
||||||
|
GLuint numVerts, const GLfloat *vertices,
|
||||||
|
GLuint numAttrs, const GLuint attribs[])
|
||||||
|
{
|
||||||
|
/*GLuint first, incr;*/
|
||||||
|
GLuint i, j;
|
||||||
|
|
||||||
|
assert(mode <= GL_POLYGON);
|
||||||
|
|
||||||
|
draw->vertex_size
|
||||||
|
= sizeof(struct vertex_header) + numAttrs * 4 * sizeof(GLfloat);
|
||||||
|
|
||||||
|
/*draw_prim_info(mode, &first, &incr);*/
|
||||||
|
draw_allocate_vertices( draw, numVerts );
|
||||||
|
if (draw->prim != mode)
|
||||||
|
draw_set_prim( draw, mode );
|
||||||
|
|
||||||
|
/* setup attr info */
|
||||||
|
draw->nr_attrs = numAttrs + 2;
|
||||||
|
draw->attrs[0].attrib = VF_ATTRIB_VERTEX_HEADER;
|
||||||
|
draw->attrs[0].format = EMIT_1F;
|
||||||
|
draw->attrs[1].attrib = VF_ATTRIB_CLIP_POS;
|
||||||
|
draw->attrs[1].format = EMIT_4F;
|
||||||
|
for (j = 0; j < numAttrs; j++) {
|
||||||
|
draw->vf_attr_to_slot[attribs[j]] = 2+j;
|
||||||
|
draw->attrs[2+j].attrib = attribs[j];
|
||||||
|
draw->attrs[2+j].format = EMIT_4F;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* build vertices */
|
||||||
|
for (i = 0; i < numVerts; i++) {
|
||||||
|
struct vertex_header *v
|
||||||
|
= (struct vertex_header *) (draw->verts + i * draw->vertex_size);
|
||||||
|
v->clipmask = 0x0;
|
||||||
|
v->edgeflag = 0;
|
||||||
|
for (j = 0; j < numAttrs; j++) {
|
||||||
|
COPY_4FV(v->data[j], vertices + (i * numAttrs + j) * 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* draw */
|
||||||
|
draw_prim(draw, 0, numVerts);
|
||||||
|
|
||||||
|
/* clean up */
|
||||||
|
draw_release_vertices( draw );
|
||||||
|
draw->verts = NULL;
|
||||||
|
draw->in_vb = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Accumulate another attribute's info.
|
* Accumulate another attribute's info.
|
||||||
* Note the "- 2" factor here. We need this because the vertex->data[]
|
* Note the "- 2" factor here. We need this because the vertex->data[]
|
||||||
|
@@ -55,6 +55,11 @@ struct pipe_context {
|
|||||||
void (*draw_vb)( struct pipe_context *pipe,
|
void (*draw_vb)( struct pipe_context *pipe,
|
||||||
struct vertex_buffer *VB );
|
struct vertex_buffer *VB );
|
||||||
|
|
||||||
|
void (*draw_vertices)( struct pipe_context *pipe,
|
||||||
|
GLuint mode,
|
||||||
|
GLuint numVertex, const GLfloat *verts,
|
||||||
|
GLuint numAttribs, const GLuint attribs[]);
|
||||||
|
|
||||||
/** Clear framebuffer */
|
/** Clear framebuffer */
|
||||||
void (*clear)(struct pipe_context *pipe, GLboolean color, GLboolean depth,
|
void (*clear)(struct pipe_context *pipe, GLboolean color, GLboolean depth,
|
||||||
GLboolean stencil);
|
GLboolean stencil);
|
||||||
|
@@ -102,6 +102,25 @@ static void softpipe_draw_vb( struct pipe_context *pipe,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
softpipe_draw_vertices(struct pipe_context *pipe,
|
||||||
|
GLuint mode,
|
||||||
|
GLuint numVertex, const GLfloat *verts,
|
||||||
|
GLuint numAttribs, const GLuint attribs[])
|
||||||
|
{
|
||||||
|
struct softpipe_context *softpipe = softpipe_context( pipe );
|
||||||
|
|
||||||
|
if (softpipe->dirty)
|
||||||
|
softpipe_update_derived( softpipe );
|
||||||
|
|
||||||
|
/* XXX move mapping/unmapping to higher/coarser level? */
|
||||||
|
map_surfaces(softpipe);
|
||||||
|
draw_vertices(softpipe->draw, mode, numVertex, verts, numAttribs, attribs);
|
||||||
|
unmap_surfaces(softpipe);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void softpipe_reset_occlusion_counter(struct pipe_context *pipe)
|
static void softpipe_reset_occlusion_counter(struct pipe_context *pipe)
|
||||||
{
|
{
|
||||||
struct softpipe_context *softpipe = softpipe_context( pipe );
|
struct softpipe_context *softpipe = softpipe_context( pipe );
|
||||||
@@ -137,6 +156,7 @@ struct pipe_context *softpipe_create( void )
|
|||||||
softpipe->pipe.set_texture_state = softpipe_set_texture_state;
|
softpipe->pipe.set_texture_state = softpipe_set_texture_state;
|
||||||
softpipe->pipe.set_viewport_state = softpipe_set_viewport_state;
|
softpipe->pipe.set_viewport_state = softpipe_set_viewport_state;
|
||||||
softpipe->pipe.draw_vb = softpipe_draw_vb;
|
softpipe->pipe.draw_vb = softpipe_draw_vb;
|
||||||
|
softpipe->pipe.draw_vertices = softpipe_draw_vertices;
|
||||||
softpipe->pipe.clear = softpipe_clear;
|
softpipe->pipe.clear = softpipe_clear;
|
||||||
softpipe->pipe.reset_occlusion_counter = softpipe_reset_occlusion_counter;
|
softpipe->pipe.reset_occlusion_counter = softpipe_reset_occlusion_counter;
|
||||||
softpipe->pipe.get_occlusion_counter = softpipe_get_occlusion_counter;
|
softpipe->pipe.get_occlusion_counter = softpipe_get_occlusion_counter;
|
||||||
|
@@ -40,6 +40,51 @@
|
|||||||
#include "st_public.h"
|
#include "st_public.h"
|
||||||
#include "pipe/p_context.h"
|
#include "pipe/p_context.h"
|
||||||
#include "pipe/p_defines.h"
|
#include "pipe/p_defines.h"
|
||||||
|
#include "vf/vf.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw a screen-aligned quadrilateral.
|
||||||
|
* Coords are window coords.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
draw_quad(GLcontext *ctx,
|
||||||
|
float x0, float y0, float x1, float y1, GLfloat z,
|
||||||
|
const GLfloat color[4])
|
||||||
|
{
|
||||||
|
static const GLuint attribs[2] = {
|
||||||
|
VF_ATTRIB_POS,
|
||||||
|
VF_ATTRIB_COLOR0
|
||||||
|
};
|
||||||
|
GLfloat verts[4][2][4]; /* four verts, two attribs, XYZW */
|
||||||
|
GLuint i;
|
||||||
|
|
||||||
|
/* positions */
|
||||||
|
verts[0][0][0] = x0;
|
||||||
|
verts[0][0][1] = y0;
|
||||||
|
|
||||||
|
verts[1][0][0] = x1;
|
||||||
|
verts[1][0][1] = y0;
|
||||||
|
|
||||||
|
verts[2][0][0] = x1;
|
||||||
|
verts[2][0][1] = y1;
|
||||||
|
|
||||||
|
verts[3][0][0] = x0;
|
||||||
|
verts[3][0][1] = y1;
|
||||||
|
|
||||||
|
/* same for all verts: */
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
verts[i][0][2] = z;
|
||||||
|
verts[i][0][3] = 1.0;
|
||||||
|
verts[i][1][0] = color[0];
|
||||||
|
verts[i][1][1] = color[1];
|
||||||
|
verts[i][1][2] = color[2];
|
||||||
|
verts[i][1][3] = color[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->st->pipe->draw_vertices(ctx->st->pipe, GL_QUADS,
|
||||||
|
4, (GLfloat *) verts, 2, attribs);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -48,14 +93,12 @@
|
|||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
clear_with_quad(GLcontext *ctx,
|
clear_with_quad(GLcontext *ctx,
|
||||||
GLboolean color, GLboolean depth,
|
GLboolean color, GLboolean depth, GLboolean stencil)
|
||||||
GLboolean stencil)
|
|
||||||
{
|
{
|
||||||
struct st_context *st = ctx->st;
|
struct st_context *st = ctx->st;
|
||||||
struct pipe_blend_state blend;
|
struct pipe_blend_state blend;
|
||||||
struct pipe_depth_state depth_test;
|
struct pipe_depth_state depth_test;
|
||||||
struct pipe_stencil_state stencil_test;
|
struct pipe_stencil_state stencil_test;
|
||||||
GLfloat z = ctx->Depth.Clear;
|
|
||||||
|
|
||||||
/* depth state: always pass */
|
/* depth state: always pass */
|
||||||
memset(&depth_test, 0, sizeof(depth));
|
memset(&depth_test, 0, sizeof(depth));
|
||||||
@@ -96,13 +139,19 @@ clear_with_quad(GLcontext *ctx,
|
|||||||
}
|
}
|
||||||
st->pipe->set_blend_state(st->pipe, &blend);
|
st->pipe->set_blend_state(st->pipe, &blend);
|
||||||
|
|
||||||
|
draw_quad(ctx,
|
||||||
/*
|
ctx->Scissor.X, ctx->Scissor.Y,
|
||||||
* XXX Render quad here
|
ctx->Scissor.X + ctx->Scissor.Width,
|
||||||
*/
|
ctx->Scissor.Y + ctx->Scissor.Height,
|
||||||
|
ctx->Depth.Clear, ctx->Color.ClearColor);
|
||||||
|
|
||||||
/* Restore GL state */
|
/* Restore GL state */
|
||||||
|
st->pipe->set_blend_state(st->pipe, &st->state.blend);
|
||||||
|
st->pipe->set_depth_state(st->pipe, &st->state.depth);
|
||||||
|
st->pipe->set_stencil_state(st->pipe, &st->state.stencil);
|
||||||
|
/* OR:
|
||||||
st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL);
|
st_invalidate_state(ctx, _NEW_COLOR | _NEW_DEPTH | _NEW_STENCIL);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -121,7 +170,7 @@ static void st_clear(GLcontext *ctx, GLbitfield mask)
|
|||||||
GLboolean accum = (mask & BUFFER_BIT_ACCUM) ? GL_TRUE : GL_FALSE;
|
GLboolean accum = (mask & BUFFER_BIT_ACCUM) ? GL_TRUE : GL_FALSE;
|
||||||
|
|
||||||
GLboolean maskColor, maskStencil;
|
GLboolean maskColor, maskStencil;
|
||||||
GLboolean fullscreen = 1; /* :-) */
|
GLboolean fullscreen = !ctx->Scissor.Enabled;
|
||||||
GLuint stencilMax = stencil ? (1 << ctx->DrawBuffer->_StencilBuffer->StencilBits) : 0;
|
GLuint stencilMax = stencil ? (1 << ctx->DrawBuffer->_StencilBuffer->StencilBits) : 0;
|
||||||
|
|
||||||
/* This makes sure the softpipe has the latest scissor, etc values */
|
/* This makes sure the softpipe has the latest scissor, etc values */
|
||||||
@@ -148,8 +197,6 @@ static void st_clear(GLcontext *ctx, GLbitfield mask)
|
|||||||
assert(!accum);
|
assert(!accum);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Convert to geometry, etc:
|
|
||||||
*/
|
|
||||||
clear_with_quad(ctx, color, depth, stencil);
|
clear_with_quad(ctx, color, depth, stencil);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user