1 /**************************************************************************
3 Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
4 Copyright 2003 Eric Anholt
7 Permission is hereby granted, free of charge, to any person obtaining a
8 copy of this software and associated documentation files (the "Software"),
9 to deal in the Software without restriction, including without limitation
10 on the rights to use, copy, modify, merge, publish, distribute, sub
11 license, and/or sell copies of the Software, and to permit persons to whom
12 the Software is furnished to do so, subject to the following conditions:
14 The above copyright notice and this permission notice (including the next
15 paragraph) shall be included in all copies or substantial portions of the
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 ERIC ANHOLT OR SILICON INTEGRATED SYSTEMS CORP BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Sung-Ching Lin <sclin@sis.com.tw>
31 * Eric Anholt <anholt@FreeBSD.org>
35 #include "sis_context.h"
38 #include "sis_alloc.h"
40 #include "sis_state.h"
43 #include "swrast/swrast.h"
44 #include "main/framebuffer.h"
45 #include "main/renderbuffer.h"
49 #define DRIVER_DATE "20060710"
51 /* Return the width and height of the given buffer.
54 sisGetBufferSize( GLframebuffer
*buffer
,
55 GLuint
*width
, GLuint
*height
)
57 GET_CURRENT_CONTEXT(ctx
);
58 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
61 *width
= smesa
->driDrawable
->w
;
62 *height
= smesa
->driDrawable
->h
;
66 /* Return various strings for glGetString().
68 static const GLubyte
*
69 sisGetString( GLcontext
*ctx
, GLenum name
)
71 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
72 static char buffer
[128];
74 GLuint agp_mode
= (smesa
->AGPSize
> 0);
79 return (GLubyte
*)"Eric Anholt";
82 offset
= driGetRendererString( buffer
, "SiS", DRIVER_DATE
, agp_mode
);
84 return (GLubyte
*)buffer
;
91 /* Send all commands to the hardware.
94 sisFlush( GLcontext
*ctx
)
96 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
98 SIS_FIREVERTICES(smesa
);
101 /* Make sure all commands have been sent to the hardware and have
102 * completed processing.
105 sisFinish( GLcontext
*ctx
)
107 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
109 SIS_FIREVERTICES(smesa
);
111 WaitEngIdle( smesa
);
116 sisDeleteRenderbuffer(struct gl_renderbuffer
*rb
)
118 /* Don't free() since we're contained in sis_context struct. */
122 sisRenderbufferStorage(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
123 GLenum internalFormat
, GLuint width
, GLuint height
)
127 rb
->InternalFormat
= internalFormat
;
132 sisInitRenderbuffer(struct gl_renderbuffer
*rb
, GLenum format
)
134 const GLuint name
= 0;
136 _mesa_init_renderbuffer(rb
, name
);
138 /* Make sure we're using a null-valued GetPointer routine */
139 assert(rb
->GetPointer(NULL
, rb
, 0, 0) == NULL
);
141 rb
->InternalFormat
= format
;
143 if (format
== GL_RGBA
) {
145 rb
->_BaseFormat
= GL_RGBA
;
146 rb
->DataType
= GL_UNSIGNED_BYTE
;
148 else if (format
== GL_DEPTH_COMPONENT16
) {
150 rb
->_BaseFormat
= GL_DEPTH_COMPONENT
;
151 /* we always Get/Put 32-bit Z values */
152 rb
->DataType
= GL_UNSIGNED_INT
;
154 else if (format
== GL_DEPTH_COMPONENT24
) {
156 rb
->_BaseFormat
= GL_DEPTH_COMPONENT
;
157 /* we always Get/Put 32-bit Z values */
158 rb
->DataType
= GL_UNSIGNED_INT
;
162 ASSERT(format
== GL_STENCIL_INDEX8_EXT
);
163 rb
->_BaseFormat
= GL_STENCIL_INDEX
;
164 rb
->DataType
= GL_UNSIGNED_BYTE
;
167 rb
->Delete
= sisDeleteRenderbuffer
;
168 rb
->AllocStorage
= sisRenderbufferStorage
;
172 sisUpdateBufferSize(sisContextPtr smesa
)
174 __GLSiSHardware
*current
= &smesa
->current
;
175 __GLSiSHardware
*prev
= &smesa
->prev
;
176 struct gl_framebuffer
*fb
= smesa
->glCtx
->DrawBuffer
;
178 if (!smesa
->front
.Base
.InternalFormat
) {
179 /* do one-time init for the renderbuffers */
180 sisInitRenderbuffer(&smesa
->front
.Base
, GL_RGBA
);
181 sisSetSpanFunctions(&smesa
->front
, &fb
->Visual
);
182 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &smesa
->front
.Base
);
184 if (fb
->Visual
.doubleBufferMode
) {
185 sisInitRenderbuffer(&smesa
->back
.Base
, GL_RGBA
);
186 sisSetSpanFunctions(&smesa
->back
, &fb
->Visual
);
187 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &smesa
->back
.Base
);
190 if (smesa
->glCtx
->Visual
.depthBits
> 0) {
191 sisInitRenderbuffer(&smesa
->depth
.Base
,
192 (smesa
->glCtx
->Visual
.depthBits
== 16
193 ? GL_DEPTH_COMPONENT16
: GL_DEPTH_COMPONENT24
));
194 sisSetSpanFunctions(&smesa
->depth
, &fb
->Visual
);
195 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &smesa
->depth
.Base
);
198 if (smesa
->glCtx
->Visual
.stencilBits
> 0) {
199 sisInitRenderbuffer(&smesa
->stencil
.Base
, GL_STENCIL_INDEX8_EXT
);
200 sisSetSpanFunctions(&smesa
->stencil
, &fb
->Visual
);
201 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &smesa
->stencil
.Base
);
205 /* Make sure initialization did what we think it should */
206 assert(smesa
->front
.Base
.InternalFormat
);
207 assert(smesa
->front
.Base
.AllocStorage
);
208 if (fb
->Visual
.doubleBufferMode
) {
209 assert(fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
);
210 assert(smesa
->front
.Base
.AllocStorage
);
212 if (fb
->Visual
.depthBits
) {
213 assert(fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
214 assert(smesa
->depth
.Base
.AllocStorage
);
217 /* XXX Should get the base offset of the frontbuffer from the X Server */
218 smesa
->front
.offset
= smesa
->driDrawable
->x
* smesa
->bytesPerPixel
+
219 smesa
->driDrawable
->y
* smesa
->front
.pitch
;
220 smesa
->front
.map
= (char *) smesa
->driScreen
->pFB
+ smesa
->front
.offset
;
222 if ( smesa
->width
== smesa
->driDrawable
->w
&&
223 smesa
->height
== smesa
->driDrawable
->h
)
228 smesa
->front
.bpp
= smesa
->bytesPerPixel
* 8;
229 /* Front pitch set on context create */
230 smesa
->front
.size
= smesa
->front
.pitch
* smesa
->driDrawable
->h
;
232 smesa
->width
= smesa
->driDrawable
->w
;
233 smesa
->height
= smesa
->driDrawable
->h
;
234 smesa
->bottom
= smesa
->height
- 1;
236 if (smesa
->back
.offset
)
237 sisFreeBackbuffer( smesa
);
238 if (smesa
->depth
.offset
)
239 sisFreeZStencilBuffer( smesa
);
241 if ( smesa
->glCtx
->Visual
.depthBits
> 0 )
242 sisAllocZStencilBuffer( smesa
);
243 if ( smesa
->glCtx
->Visual
.doubleBufferMode
)
244 sisAllocBackbuffer( smesa
);
246 current
->hwZ
&= ~MASK_ZBufferPitch
;
247 current
->hwZ
|= smesa
->depth
.pitch
>> 2;
248 current
->hwOffsetZ
= smesa
->depth
.offset
>> 2;
250 if ((current
->hwOffsetZ
!= prev
->hwOffsetZ
) || (current
->hwZ
!= prev
->hwZ
)) {
251 prev
->hwOffsetZ
= current
->hwOffsetZ
;
252 prev
->hwZ
= current
->hwZ
;
253 smesa
->GlobalFlag
|= GFLAG_ZSETTING
;
256 sisUpdateClipping( smesa
->glCtx
);
259 /* Initialize the driver's misc functions.
262 sisInitDriverFuncs( struct dd_function_table
*functions
)
264 functions
->GetBufferSize
= sisGetBufferSize
;
265 functions
->GetString
= sisGetString
;
266 functions
->Finish
= sisFinish
;
267 functions
->Flush
= sisFlush
;