gl: updated glxext.h to version 27
[mesa.git] / src / mesa / drivers / dri / nouveau / nouveau_span.c
1 /*
2 * Copyright (C) 2009 Francisco Jerez.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 */
26
27 #include "nouveau_driver.h"
28 #include "nouveau_fbo.h"
29 #include "nouveau_context.h"
30 #include "nouveau_bo.h"
31
32 #include "swrast/swrast.h"
33
34 #define LOCAL_VARS \
35 struct gl_framebuffer *fb = ctx->DrawBuffer; \
36 struct nouveau_surface *s = &to_nouveau_renderbuffer(rb)->surface; \
37 GLuint p; \
38 (void)p;
39
40 #define LOCAL_DEPTH_VARS LOCAL_VARS
41
42 #define HW_LOCK()
43 #define HW_UNLOCK()
44
45 #define HW_CLIPLOOP() { \
46 int minx = 0; \
47 int miny = 0; \
48 int maxx = fb->Width; \
49 int maxy = fb->Height;
50
51 #define HW_ENDCLIPLOOP() }
52
53 #define Y_FLIP(y) (fb->Name ? (y) : rb->Height - 1 - (y))
54
55 /* RGB565 span functions */
56 #define SPANTMP_PIXEL_FMT GL_RGB
57 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
58 #define TAG(x) nouveau_##x##_rgb565
59 #define TAG2(x, y) nouveau_##x##_rgb565##y
60 #define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
61
62 #include "spantmp2.h"
63
64 /* RGB888 span functions */
65 #define SPANTMP_PIXEL_FMT GL_BGR
66 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
67 #define TAG(x) nouveau_##x##_rgb888
68 #define TAG2(x, y) nouveau_##x##_rgb888##y
69 #define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
70
71 #include "spantmp2.h"
72
73 /* ARGB8888 span functions */
74 #define SPANTMP_PIXEL_FMT GL_BGRA
75 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
76 #define TAG(x) nouveau_##x##_argb8888
77 #define TAG2(x, y) nouveau_##x##_argb8888##y
78 #define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
79
80 #include "spantmp2.h"
81
82 /* Z16 span functions */
83 #define VALUE_TYPE uint16_t
84 #define READ_DEPTH(v, x, y) \
85 v = *(uint16_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp);
86 #define WRITE_DEPTH(x, y, v) \
87 *(uint16_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp) = v
88 #define TAG(x) nouveau_##x##_z16
89
90 #include "depthtmp.h"
91
92 /* Z24S8 span functions */
93 #define VALUE_TYPE uint32_t
94 #define READ_DEPTH(v, x, y) \
95 v = *(uint32_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp);
96 #define WRITE_DEPTH(x, y, v) \
97 *(uint32_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp) = v
98 #define TAG(x) nouveau_##x##_z24s8
99
100 #include "depthtmp.h"
101
102 static void
103 renderbuffer_map_unmap(struct gl_renderbuffer *rb, GLboolean map)
104 {
105 struct nouveau_surface *s = &to_nouveau_renderbuffer(rb)->surface;
106
107 if (map) {
108 switch (rb->Format) {
109 case MESA_FORMAT_RGB565:
110 nouveau_InitPointers_rgb565(rb);
111 break;
112 case MESA_FORMAT_XRGB8888:
113 nouveau_InitPointers_rgb888(rb);
114 break;
115 case MESA_FORMAT_ARGB8888:
116 nouveau_InitPointers_argb8888(rb);
117 break;
118 case MESA_FORMAT_Z16:
119 nouveau_InitDepthPointers_z16(rb);
120 break;
121 case MESA_FORMAT_Z24_S8:
122 nouveau_InitDepthPointers_z24s8(rb);
123 break;
124 default:
125 assert(0);
126 }
127
128 nouveau_bo_map(s->bo, NOUVEAU_BO_RDWR);
129 } else {
130 nouveau_bo_unmap(s->bo);
131 }
132 }
133
134 static void
135 texture_unit_map_unmap(GLcontext *ctx, struct gl_texture_unit *u, GLboolean map)
136 {
137 if (!u->_ReallyEnabled)
138 return;
139
140 if (map)
141 ctx->Driver.MapTexture(ctx, u->_Current);
142 else
143 ctx->Driver.UnmapTexture(ctx, u->_Current);
144 }
145
146 static void
147 span_map_unmap(GLcontext *ctx, GLboolean map)
148 {
149 int i;
150
151 for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++)
152 renderbuffer_map_unmap(ctx->DrawBuffer->_ColorDrawBuffers[i], map);
153
154 renderbuffer_map_unmap(ctx->DrawBuffer->_ColorReadBuffer, map);
155
156 if (ctx->DrawBuffer->_DepthBuffer)
157 renderbuffer_map_unmap(ctx->DrawBuffer->_DepthBuffer->Wrapped, map);
158
159 for (i = 0; i < ctx->Const.MaxTextureUnits; i++)
160 texture_unit_map_unmap(ctx, &ctx->Texture.Unit[i], map);
161 }
162
163 static void
164 nouveau_span_start(GLcontext *ctx)
165 {
166 nouveau_fallback(ctx, SWRAST);
167 span_map_unmap(ctx, GL_TRUE);
168 }
169
170 static void
171 nouveau_span_finish(GLcontext *ctx)
172 {
173 span_map_unmap(ctx, GL_FALSE);
174 nouveau_fallback(ctx, HWTNL);
175 }
176
177 void
178 nouveau_span_functions_init(GLcontext *ctx)
179 {
180 struct swrast_device_driver *swdd =
181 _swrast_GetDeviceDriverReference(ctx);
182
183 swdd->SpanRenderStart = nouveau_span_start;
184 swdd->SpanRenderFinish = nouveau_span_finish;
185 }