Initial work for glClear(), clear color state.
[mesa.git] / src / mesa / pipe / softpipe / sp_context.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /* Author:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32 #include "imports.h"
33 #include "macros.h"
34
35 #include "tnl/t_context.h"
36 #include "vf/vf.h"
37
38 #include "sp_context.h"
39 #include "sp_clear.h"
40 #include "sp_prim.h"
41 #include "sp_state.h"
42 #include "sp_draw.h"
43
44 static void softpipe_destroy( struct pipe_context *pipe )
45 {
46 struct softpipe_context *softpipe = softpipe_context( pipe );
47
48 draw_destroy( softpipe->draw );
49
50 FREE( softpipe );
51 }
52
53
54 static void softpipe_draw_vb( struct pipe_context *pipe,
55 struct vertex_buffer *VB )
56 {
57 struct softpipe_context *softpipe = softpipe_context( pipe );
58
59 if (softpipe->dirty)
60 softpipe_update_derived( softpipe );
61
62 draw_vb( softpipe->draw, VB );
63 }
64
65 struct pipe_context *softpipe_create( void )
66 {
67 struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context);
68
69 softpipe->pipe.destroy = softpipe_destroy;
70 softpipe->pipe.set_framebuffer_state = softpipe_set_framebuffer_state;
71 softpipe->pipe.set_clip_state = softpipe_set_clip_state;
72 softpipe->pipe.set_clear_color_state = softpipe_set_clear_color_state;
73 softpipe->pipe.set_point_state = softpipe_set_point_state;
74 softpipe->pipe.set_viewport = softpipe_set_viewport;
75 softpipe->pipe.set_setup_state = softpipe_set_setup_state;
76 softpipe->pipe.set_scissor_rect = softpipe_set_scissor_rect;
77 softpipe->pipe.set_fs_state = softpipe_set_fs_state;
78 softpipe->pipe.set_polygon_stipple = softpipe_set_polygon_stipple;
79 softpipe->pipe.draw_vb = softpipe_draw_vb;
80 softpipe->pipe.clear = softpipe_clear;
81
82
83 softpipe->prim.setup = prim_setup( softpipe );
84 softpipe->prim.unfilled = prim_unfilled( softpipe );
85 softpipe->prim.twoside = prim_twoside( softpipe );
86 softpipe->prim.offset = prim_offset( softpipe );
87 softpipe->prim.clip = prim_clip( softpipe );
88 softpipe->prim.flatshade = prim_flatshade( softpipe );
89 softpipe->prim.cull = prim_cull( softpipe );
90
91
92 softpipe->draw = draw_create( softpipe );
93
94 ASSIGN_4V( softpipe->plane[0], -1, 0, 0, 1 );
95 ASSIGN_4V( softpipe->plane[1], 1, 0, 0, 1 );
96 ASSIGN_4V( softpipe->plane[2], 0, -1, 0, 1 );
97 ASSIGN_4V( softpipe->plane[3], 0, 1, 0, 1 );
98 ASSIGN_4V( softpipe->plane[4], 0, 0, 1, 1 ); /* yes these are correct */
99 ASSIGN_4V( softpipe->plane[5], 0, 0, -1, 1 ); /* mesa's a bit wonky */
100 softpipe->nr_planes = 6;
101
102 return &softpipe->pipe;
103 }
104
105
106
107
108
109
110 #define MAX_VERTEX_SIZE ((2 + FRAG_ATTRIB_MAX) * 4 * sizeof(GLfloat))
111
112 void prim_alloc_tmps( struct prim_stage *stage, GLuint nr )
113 {
114 stage->nr_tmps = nr;
115
116 if (nr) {
117 GLubyte *store = MALLOC(MAX_VERTEX_SIZE * nr);
118 GLuint i;
119
120 stage->tmp = MALLOC(sizeof(struct vertex_header *) * nr);
121
122 for (i = 0; i < nr; i++)
123 stage->tmp[i] = (struct vertex_header *)(store + i * MAX_VERTEX_SIZE);
124 }
125 }
126
127 void prim_free_tmps( struct prim_stage *stage )
128 {
129 if (stage->tmp) {
130 FREE(stage->tmp[0]);
131 FREE(stage->tmp);
132 }
133 }
134
135
136
137
138