ad3d00f588505f89e0c9c009979f34ac6dd82137
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_context.h
1 /**************************************************************************
2
3 Copyright 2006 Stephane Marchesin
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 "Software"),
8 to deal in the Software without restriction, including without limitation
9 on the rights to use, copy, modify, merge, publish, distribute, sub
10 license, and/or sell copies of the Software, and to permit persons to whom
11 the Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice (including the next
14 paragraph) shall be included in all copies or substantial portions of the
15 Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
21 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 **************************************************************************/
26
27
28
29 #ifndef __NOUVEAU_CONTEXT_H__
30 #define __NOUVEAU_CONTEXT_H__
31
32 #include "dri_util.h"
33 #include "drm.h"
34 #include "nouveau_drm.h"
35
36 #include "mtypes.h"
37 #include "tnl/t_vertex.h"
38
39 #include "nouveau_reg.h"
40 #include "nouveau_screen.h"
41
42 #include "xmlconfig.h"
43
44 typedef struct nouveau_fifo_t{
45 u_int32_t* buffer;
46 u_int32_t current;
47 u_int32_t put;
48 u_int32_t free;
49 u_int32_t max;
50 }
51 nouveau_fifo;
52
53 #define TAG(x) nouveau##x
54 #include "tnl_dd/t_dd_vertex.h"
55 #undef TAG
56
57 /* Subpixel offsets for window coordinates (triangles): */
58 #define SUBPIXEL_X (0.0F)
59 #define SUBPIXEL_Y (0.125F)
60
61 struct nouveau_context;
62
63 typedef void (*nouveau_tri_func)( struct nouveau_context*,
64 nouveauVertex *,
65 nouveauVertex *,
66 nouveauVertex * );
67
68 typedef void (*nouveau_line_func)( struct nouveau_context*,
69 nouveauVertex *,
70 nouveauVertex * );
71
72 typedef void (*nouveau_point_func)( struct nouveau_context*,
73 nouveauVertex * );
74
75
76 typedef struct nouveau_context {
77 /* Mesa context */
78 GLcontext *glCtx;
79
80 /* The per-context fifo */
81 nouveau_fifo fifo;
82
83 /* The fifo control regs */
84 volatile unsigned char* fifo_mmio;
85
86 /* The read-only regs */
87 volatile unsigned char* mmio;
88
89 /* State for tris */
90 GLuint color_offset;
91 GLuint specular_offset;
92
93 /* Vertex state */
94 GLuint vertex_size;
95 char *verts;
96 struct tnl_attr_map vertex_attrs[VERT_ATTRIB_MAX];
97 GLuint vertex_attr_count;
98
99 /* Clear state */
100 GLuint clear_color;
101 GLuint clear_depth;
102 GLuint clear_stencil;
103
104 /* The drawing fallbacks */
105 GLuint Fallback;
106 nouveau_tri_func draw_tri;
107 nouveau_line_func draw_line;
108 nouveau_point_func draw_point;
109
110 /* Cliprects information */
111 GLuint numClipRects;
112 drm_clip_rect_t *pClipRects;
113
114 /* The rendering context information */
115 GLenum current_primitive; /* the current primitive enum */
116 GLuint render_inputs; /* the current render inputs */
117
118 nouveauScreenRec *screen;
119 drm_nouveau_sarea_t *sarea;
120
121 __DRIcontextPrivate *driContext; /* DRI context */
122 __DRIscreenPrivate *driScreen; /* DRI screen */
123 __DRIdrawablePrivate *driDrawable; /* DRI drawable bound to this ctx */
124
125 drm_context_t hHWContext;
126 drm_hw_lock_t *driHwLock;
127 int driFd;
128
129 /* Configuration cache */
130 driOptionCache optionCache;
131
132 uint32_t vblank_flags;
133
134 GLuint new_state;
135 GLuint new_render_state;
136 GLuint render_index;
137 GLmatrix viewport;
138 GLfloat depth_scale;
139
140 }nouveauContextRec, *nouveauContextPtr;
141
142
143 #define NOUVEAU_CONTEXT(ctx) ((nouveauContextPtr)(ctx->DriverCtx))
144
145 /* Flags for what context state needs to be updated: */
146 #define NOUVEAU_NEW_ALPHA 0x0001
147 #define NOUVEAU_NEW_DEPTH 0x0002
148 #define NOUVEAU_NEW_FOG 0x0004
149 #define NOUVEAU_NEW_CLIP 0x0008
150 #define NOUVEAU_NEW_CULL 0x0010
151 #define NOUVEAU_NEW_MASKS 0x0020
152 #define NOUVEAU_NEW_RENDER_NOT 0x0040
153 #define NOUVEAU_NEW_WINDOW 0x0080
154 #define NOUVEAU_NEW_CONTEXT 0x0100
155 #define NOUVEAU_NEW_ALL 0x01ff
156
157 /* Flags for software fallback cases: */
158 #define NOUVEAU_FALLBACK_TEXTURE 0x0001
159 #define NOUVEAU_FALLBACK_DRAW_BUFFER 0x0002
160 #define NOUVEAU_FALLBACK_READ_BUFFER 0x0004
161 #define NOUVEAU_FALLBACK_STENCIL 0x0008
162 #define NOUVEAU_FALLBACK_RENDER_MODE 0x0010
163 #define NOUVEAU_FALLBACK_LOGICOP 0x0020
164 #define NOUVEAU_FALLBACK_SEP_SPECULAR 0x0040
165 #define NOUVEAU_FALLBACK_BLEND_EQ 0x0080
166 #define NOUVEAU_FALLBACK_BLEND_FUNC 0x0100
167 #define NOUVEAU_FALLBACK_PROJTEX 0x0200
168 #define NOUVEAU_FALLBACK_DISABLE 0x0400
169
170
171 extern GLboolean nouveauCreateContext( const __GLcontextModes *glVisual,
172 __DRIcontextPrivate *driContextPriv,
173 void *sharedContextPrivate );
174
175 extern void nouveauDestroyContext( __DRIcontextPrivate * );
176
177 extern GLboolean nouveauMakeCurrent( __DRIcontextPrivate *driContextPriv,
178 __DRIdrawablePrivate *driDrawPriv,
179 __DRIdrawablePrivate *driReadPriv );
180
181 extern GLboolean nouveauUnbindContext( __DRIcontextPrivate *driContextPriv );
182
183
184 #endif /* __NOUVEAU_CONTEXT_H__ */
185