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 /* ARGB8888 span functions */
65 #define SPANTMP_PIXEL_FMT GL_BGRA
66 #define SPANTMP_PIXEL_TYPE GL_UNSIGNED_INT_8_8_8_8_REV
67 #define TAG(x) nouveau_##x##_argb8888
68 #define TAG2(x, y) nouveau_##x##_argb8888##y
69 #define GET_PTR(x, y) (s->bo->map + (y)*s->pitch + (x)*s->cpp)
73 /* Z16 span functions */
74 #define VALUE_TYPE uint16_t
75 #define READ_DEPTH(v, x, y) \
76 v = *(uint16_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp);
77 #define WRITE_DEPTH(x, y, v) \
78 *(uint16_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp) = v
79 #define TAG(x) nouveau_##x##_z16
83 /* Z24S8 span functions */
84 #define VALUE_TYPE uint32_t
85 #define READ_DEPTH(v, x, y) \
86 v = *(uint32_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp);
87 #define WRITE_DEPTH(x, y, v) \
88 *(uint32_t *)(s->bo->map + (y)*s->pitch + (x)*s->cpp) = v
89 #define TAG(x) nouveau_##x##_z24s8
94 renderbuffer_map_unmap(struct gl_renderbuffer
*rb
, GLboolean map
)
96 struct nouveau_surface
*s
= &to_nouveau_renderbuffer(rb
)->surface
;
100 case MESA_FORMAT_RGB565
:
101 nouveau_InitPointers_rgb565(rb
);
103 case MESA_FORMAT_XRGB8888
:
104 case MESA_FORMAT_ARGB8888
:
105 nouveau_InitPointers_argb8888(rb
);
107 case MESA_FORMAT_Z16
:
108 nouveau_InitDepthPointers_z16(rb
);
110 case MESA_FORMAT_Z24_S8
:
111 nouveau_InitDepthPointers_z24s8(rb
);
117 nouveau_bo_map(s
->bo
, NOUVEAU_BO_RDWR
);
119 nouveau_bo_unmap(s
->bo
);
124 texture_unit_map_unmap(GLcontext
*ctx
, struct gl_texture_unit
*u
, GLboolean map
)
126 if (!u
->_ReallyEnabled
)
130 ctx
->Driver
.MapTexture(ctx
, u
->_Current
);
132 ctx
->Driver
.UnmapTexture(ctx
, u
->_Current
);
136 span_map_unmap(GLcontext
*ctx
, GLboolean map
)
140 for (i
= 0; i
< ctx
->DrawBuffer
->_NumColorDrawBuffers
; i
++)
141 renderbuffer_map_unmap(ctx
->DrawBuffer
->_ColorDrawBuffers
[i
], map
);
143 renderbuffer_map_unmap(ctx
->DrawBuffer
->_ColorReadBuffer
, map
);
145 if (ctx
->DrawBuffer
->_DepthBuffer
)
146 renderbuffer_map_unmap(ctx
->DrawBuffer
->_DepthBuffer
->Wrapped
, map
);
148 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++)
149 texture_unit_map_unmap(ctx
, &ctx
->Texture
.Unit
[i
], map
);
153 nouveau_span_start(GLcontext
*ctx
)
155 nouveau_fallback(ctx
, SWRAST
);
156 span_map_unmap(ctx
, GL_TRUE
);
160 nouveau_span_finish(GLcontext
*ctx
)
162 span_map_unmap(ctx
, GL_FALSE
);
163 nouveau_fallback(ctx
, HWTNL
);
167 nouveau_span_functions_init(GLcontext
*ctx
)
169 struct swrast_device_driver
*swdd
=
170 _swrast_GetDeviceDriverReference(ctx
);
172 swdd
->SpanRenderStart
= nouveau_span_start
;
173 swdd
->SpanRenderFinish
= nouveau_span_finish
;