2 * Copyright (C) 2009 Francisco Jerez.
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:
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.
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.
27 #include "nouveau_driver.h"
28 #include "nouveau_fbo.h"
29 #include "nouveau_context.h"
30 #include "nouveau_bo.h"
32 #include "swrast/swrast.h"
35 struct gl_framebuffer *fb = ctx->DrawBuffer; \
36 struct nouveau_surface *s = &to_nouveau_renderbuffer(rb)->surface; \
40 #define LOCAL_DEPTH_VARS LOCAL_VARS
45 #define HW_CLIPLOOP() { \
48 int maxx = fb->Width; \
49 int maxy = fb->Height;
51 #define HW_ENDCLIPLOOP() }
53 #define Y_FLIP(y) (fb->Name ? (y) : rb->Height - 1 - (y))
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)
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)
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)
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
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
100 #include "depthtmp.h"
103 renderbuffer_map_unmap(struct gl_renderbuffer
*rb
, GLboolean map
)
105 struct nouveau_surface
*s
= &to_nouveau_renderbuffer(rb
)->surface
;
108 switch (rb
->Format
) {
109 case MESA_FORMAT_RGB565
:
110 nouveau_InitPointers_rgb565(rb
);
112 case MESA_FORMAT_XRGB8888
:
113 nouveau_InitPointers_rgb888(rb
);
115 case MESA_FORMAT_ARGB8888
:
116 nouveau_InitPointers_argb8888(rb
);
118 case MESA_FORMAT_Z16
:
119 nouveau_InitDepthPointers_z16(rb
);
121 case MESA_FORMAT_Z24_S8
:
122 nouveau_InitDepthPointers_z24s8(rb
);
128 nouveau_bo_map(s
->bo
, NOUVEAU_BO_RDWR
);
130 nouveau_bo_unmap(s
->bo
);
135 texture_unit_map_unmap(GLcontext
*ctx
, struct gl_texture_unit
*u
, GLboolean map
)
137 if (!u
->_ReallyEnabled
)
141 ctx
->Driver
.MapTexture(ctx
, u
->_Current
);
143 ctx
->Driver
.UnmapTexture(ctx
, u
->_Current
);
147 span_map_unmap(GLcontext
*ctx
, GLboolean map
)
151 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++)
152 renderbuffer_map_unmap(ctx
->DrawBuffer
->_ColorDrawBuffers
[i
], map
);
154 renderbuffer_map_unmap(ctx
->DrawBuffer
->_ColorReadBuffer
, map
);
156 if (ctx
->DrawBuffer
->_DepthBuffer
)
157 renderbuffer_map_unmap(ctx
->DrawBuffer
->_DepthBuffer
->Wrapped
, map
);
159 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++)
160 texture_unit_map_unmap(ctx
, &ctx
->Texture
.Unit
[i
], map
);
164 nouveau_span_start(GLcontext
*ctx
)
166 nouveau_fallback(ctx
, SWRAST
);
167 span_map_unmap(ctx
, GL_TRUE
);
171 nouveau_span_finish(GLcontext
*ctx
)
173 span_map_unmap(ctx
, GL_FALSE
);
174 nouveau_fallback(ctx
, HWTNL
);
178 nouveau_span_functions_init(GLcontext
*ctx
)
180 struct swrast_device_driver
*swdd
=
181 _swrast_GetDeviceDriverReference(ctx
);
183 swdd
->SpanRenderStart
= nouveau_span_start
;
184 swdd
->SpanRenderFinish
= nouveau_span_finish
;