Call init_state_funcs
[mesa.git] / src / mesa / pipe / i915simple / i915_context.c
1 /**************************************************************************
2 *
3 * Copyright 2003 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 #include "main/imports.h" /* CALLOC */
29 #include "i915_context.h"
30 #include "i915_winsys.h"
31 #include "i915_state.h"
32
33 #include "pipe/draw/draw_context.h"
34 #include "pipe/p_defines.h"
35
36
37
38 /**
39 * Return list of supported surface/texture formats.
40 * If we find texture and drawable support differs, add a selector
41 * parameter or another function.
42 */
43 static const GLuint *
44 i915_supported_formats(struct pipe_context *pipe,
45 // GLuint type,
46 GLuint *numFormats)
47 {
48 #if 0
49 static const GLuint tex_supported[] = {
50 PIPE_FORMAT_U_R8_G8_B8_A8,
51 PIPE_FORMAT_U_A8_R8_G8_B8,
52 PIPE_FORMAT_U_R5_G6_B5,
53 PIPE_FORMAT_U_L8,
54 PIPE_FORMAT_U_A8,
55 PIPE_FORMAT_U_I8,
56 PIPE_FORMAT_U_L8_A8,
57 PIPE_FORMAT_YCBCR,
58 PIPE_FORMAT_YCBCR_REV,
59 PIPE_FORMAT_S8_Z24,
60 };
61
62
63 /* Actually a lot more than this - add later:
64 */
65 static const GLuint render_supported[] = {
66 PIPE_FORMAT_U_A8_R8_G8_B8,
67 PIPE_FORMAT_U_R5_G6_B5,
68 };
69
70 /*
71 */
72 static const GLuint z_stencil_supported[] = {
73 PIPE_FORMAT_U_Z16,
74 PIPE_FORMAT_U_Z32,
75 PIPE_FORMAT_S8_Z24,
76 };
77
78 switch (type) {
79 case PIPE_RENDER_FORMAT:
80 *numFormats = Elements(render_supported);
81 return render_supported;
82
83 case PIPE_TEX_FORMAT:
84 *numFormats = Elements(tex_supported);
85 return render_supported;
86
87 case PIPE_Z_STENCIL_FORMAT:
88 *numFormats = Elements(render_supported);
89 return render_supported;
90
91 default:
92 *numFormats = 0;
93 return NULL;
94 }
95 #else
96 static const GLuint render_supported[] = {
97 PIPE_FORMAT_U_A8_R8_G8_B8,
98 PIPE_FORMAT_U_R5_G6_B5,
99 PIPE_FORMAT_S8_Z24,
100 };
101 *numFormats = 2;
102 return render_supported;
103 #endif
104 }
105
106
107
108 static void i915_destroy( struct pipe_context *pipe )
109 {
110 struct i915_context *i915 = i915_context( pipe );
111
112 draw_destroy( i915->draw );
113
114 free( i915 );
115 }
116
117 static void i915_draw_vb( struct pipe_context *pipe,
118 struct vertex_buffer *VB )
119 {
120 struct i915_context *i915 = i915_context( pipe );
121
122 // if (i915->dirty)
123 // i915_update_derived( i915 );
124
125 draw_vb( i915->draw, VB );
126 }
127
128
129 static void
130 i915_draw_vertices(struct pipe_context *pipe,
131 GLuint mode,
132 GLuint numVertex, const GLfloat *verts,
133 GLuint numAttribs, const GLuint attribs[])
134 {
135 struct i915_context *i915 = i915_context( pipe );
136
137 if (i915->dirty)
138 i915_update_derived( i915 );
139
140 draw_vertices(i915->draw, mode, numVertex, verts, numAttribs, attribs);
141 }
142
143
144
145
146 struct pipe_context *i915_create( struct i915_winsys *winsys )
147 {
148 struct i915_context *i915 = CALLOC_STRUCT(i915_context);
149
150 i915->pipe.destroy = i915_destroy;
151
152 i915->pipe.supported_formats = i915_supported_formats;
153
154 i915->pipe.draw_vb = i915_draw_vb;
155 i915->pipe.draw_vertices = i915_draw_vertices;
156 i915->pipe.clear = i915_clear;
157 i915->pipe.reset_occlusion_counter = NULL; /* no support */
158 i915->pipe.get_occlusion_counter = NULL;
159
160 i915->winsys = winsys;
161
162 /*
163 * Create drawing context and plug our rendering stage into it.
164 */
165 i915->draw = draw_create();
166 assert(i915->draw);
167 draw_set_setup_stage(i915->draw, i915_draw_render_stage(i915));
168
169 i915_init_buffer_functions(i915);
170 i915_init_region_functions(i915);
171 i915_init_surface_functions(i915);
172 i915_init_state_functions(i915);
173
174 /*
175 * XXX we could plug GL selection/feedback into the drawing pipeline
176 * by specifying a different setup/render stage.
177 */
178
179 return &i915->pipe;
180 }
181