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 nouveau_surface *s = &to_nouveau_renderbuffer(rb)->surface; \
39 #define LOCAL_DEPTH_VARS LOCAL_VARS
44 #define HW_CLIPLOOP() { \
47 int maxx = rb->Width; \
48 int maxy = rb->Height;
50 #define HW_ENDCLIPLOOP() }
52 #define Y_FLIP(y) (rb->Name ? (y) : rb->Height - 1 - (y))
54 /* RGB565 span functions */
55 #define SPANTMP_PIXEL_FMT GL_RGB
56 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_SHORT_5_6_5
57 #define TAG(x) nouveau_##x##_rgb565
58 #define TAG2(x, y) nouveau_##x##_rgb565##y
59 #define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
63 /* RGB888 span functions */
64 #define SPANTMP_PIXEL_FMT GL_BGR
65 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
66 #define TAG(x) nouveau_##x##_rgb888
67 #define TAG2(x, y) nouveau_##x##_rgb888##y
68 #define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
72 /* ARGB8888 span functions */
73 #define SPANTMP_PIXEL_FMT GL_BGRA
74 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
75 #define TAG(x) nouveau_##x##_argb8888
76 #define TAG2(x, y) nouveau_##x##_argb8888##y
77 #define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
81 /* Z16 span functions */
82 #define VALUE_TYPE uint16_t
83 #define READ_DEPTH(v, x, y) \
84 v = *(uint16_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp);
85 #define WRITE_DEPTH(x, y, v) \
86 *(uint16_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp) = v
87 #define TAG(x) nouveau_##x##_z16
91 /* Z24S8 span functions */
92 #define VALUE_TYPE uint32_t
93 #define READ_DEPTH(v, x, y) \
94 v = *(uint32_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp);
95 #define WRITE_DEPTH(x, y, v) \
96 *(uint32_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp) = v
97 #define TAG(x) nouveau_##x##_z24s8
102 renderbuffer_map_unmap(struct gl_renderbuffer
*rb
, GLboolean map
)
104 struct nouveau_surface
*s
= &to_nouveau_renderbuffer(rb
)->surface
;
107 switch (rb
->Format
) {
108 case MESA_FORMAT_RGB565
:
109 nouveau_InitPointers_rgb565(rb
);
111 case MESA_FORMAT_XRGB8888
:
112 nouveau_InitPointers_rgb888(rb
);
114 case MESA_FORMAT_ARGB8888
:
115 nouveau_InitPointers_argb8888(rb
);
117 case MESA_FORMAT_Z16
:
118 nouveau_InitDepthPointers_z16(rb
);
120 case MESA_FORMAT_Z24_S8
:
121 nouveau_InitDepthPointers_z24s8(rb
);
127 nouveau_bo_map(s
->bo
, NOUVEAU_BO_RDWR
);
129 nouveau_bo_unmap(s
->bo
);
134 texture_unit_map_unmap(GLcontext
*ctx
, struct gl_texture_unit
*u
, GLboolean map
)
136 if (!u
->_ReallyEnabled
)
140 ctx
->Driver
.MapTexture(ctx
, u
->_Current
);
142 ctx
->Driver
.UnmapTexture(ctx
, u
->_Current
);
146 framebuffer_map_unmap(struct gl_framebuffer
*fb
, GLboolean map
)
150 for (i
= 0; i
< fb
->_NumColorDrawBuffers
; i
++)
151 renderbuffer_map_unmap(fb
->_ColorDrawBuffers
[i
], map
);
153 renderbuffer_map_unmap(fb
->_ColorReadBuffer
, map
);
155 if (fb
->_DepthBuffer
)
156 renderbuffer_map_unmap(fb
->_DepthBuffer
->Wrapped
, map
);
160 span_map_unmap(GLcontext
*ctx
, GLboolean map
)
164 framebuffer_map_unmap(ctx
->DrawBuffer
, map
);
166 if (ctx
->ReadBuffer
!= ctx
->DrawBuffer
)
167 framebuffer_map_unmap(ctx
->ReadBuffer
, map
);
169 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++)
170 texture_unit_map_unmap(ctx
, &ctx
->Texture
.Unit
[i
], map
);
174 nouveau_span_start(GLcontext
*ctx
)
176 nouveau_fallback(ctx
, SWRAST
);
177 span_map_unmap(ctx
, GL_TRUE
);
181 nouveau_span_finish(GLcontext
*ctx
)
183 span_map_unmap(ctx
, GL_FALSE
);
184 nouveau_fallback(ctx
, HWTNL
);
188 nouveau_span_functions_init(GLcontext
*ctx
)
190 struct swrast_device_driver
*swdd
=
191 _swrast_GetDeviceDriverReference(ctx
);
193 swdd
->SpanRenderStart
= nouveau_span_start
;
194 swdd
->SpanRenderFinish
= nouveau_span_finish
;