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 "main/formats.h"
44 #include "main/renderbuffer.h"
48 #define DRIVER_DATE "20060710"
50 /* Return the width and height of the given buffer.
53 sisGetBufferSize( GLframebuffer
*buffer
,
54 GLuint
*width
, GLuint
*height
)
56 GET_CURRENT_CONTEXT(ctx
);
57 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
60 *width
= smesa
->driDrawable
->w
;
61 *height
= smesa
->driDrawable
->h
;
65 /* Return various strings for glGetString().
67 static const GLubyte
*
68 sisGetString( GLcontext
*ctx
, GLenum name
)
70 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
71 static char buffer
[128];
73 GLuint agp_mode
= (smesa
->AGPSize
> 0);
78 return (GLubyte
*)"Eric Anholt";
81 offset
= driGetRendererString( buffer
, "SiS", DRIVER_DATE
, agp_mode
);
83 return (GLubyte
*)buffer
;
90 /* Send all commands to the hardware.
93 sisFlush( GLcontext
*ctx
)
95 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
97 SIS_FIREVERTICES(smesa
);
100 /* Make sure all commands have been sent to the hardware and have
101 * completed processing.
104 sisFinish( GLcontext
*ctx
)
106 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
108 SIS_FIREVERTICES(smesa
);
110 WaitEngIdle( smesa
);
115 sisDeleteRenderbuffer(struct gl_renderbuffer
*rb
)
117 /* Don't free() since we're contained in sis_context struct. */
121 sisRenderbufferStorage(GLcontext
*ctx
, struct gl_renderbuffer
*rb
,
122 GLenum internalFormat
, GLuint width
, GLuint height
)
126 rb
->InternalFormat
= internalFormat
;
131 sisInitRenderbuffer(struct gl_renderbuffer
*rb
, GLenum format
)
133 const GLuint name
= 0;
135 _mesa_init_renderbuffer(rb
, name
);
137 /* Make sure we're using a null-valued GetPointer routine */
138 assert(rb
->GetPointer(NULL
, rb
, 0, 0) == NULL
);
140 rb
->InternalFormat
= format
;
142 if (format
== GL_RGBA
) {
144 rb
->Format
= MESA_FORMAT_ARGB8888
;
145 rb
->DataType
= GL_UNSIGNED_BYTE
;
147 else if (format
== GL_DEPTH_COMPONENT16
) {
149 /* we always Get/Put 32-bit Z values */
150 rb
->Format
= MESA_FORMAT_Z16
;
151 rb
->DataType
= GL_UNSIGNED_INT
;
153 else if (format
== GL_DEPTH_COMPONENT24
) {
155 /* we always Get/Put 32-bit Z values */
156 rb
->Format
= MESA_FORMAT_Z32
;
157 rb
->DataType
= GL_UNSIGNED_INT
;
161 ASSERT(format
== GL_STENCIL_INDEX8_EXT
);
162 rb
->Format
= MESA_FORMAT_S8
;
163 rb
->DataType
= GL_UNSIGNED_BYTE
;
166 rb
->Delete
= sisDeleteRenderbuffer
;
167 rb
->AllocStorage
= sisRenderbufferStorage
;
171 sisUpdateBufferSize(sisContextPtr smesa
)
173 __GLSiSHardware
*current
= &smesa
->current
;
174 __GLSiSHardware
*prev
= &smesa
->prev
;
175 struct gl_framebuffer
*fb
= smesa
->glCtx
->DrawBuffer
;
177 if (!smesa
->front
.Base
.InternalFormat
) {
178 /* do one-time init for the renderbuffers */
179 sisInitRenderbuffer(&smesa
->front
.Base
, GL_RGBA
);
180 sisSetSpanFunctions(&smesa
->front
, &fb
->Visual
);
181 _mesa_add_renderbuffer(fb
, BUFFER_FRONT_LEFT
, &smesa
->front
.Base
);
183 if (fb
->Visual
.doubleBufferMode
) {
184 sisInitRenderbuffer(&smesa
->back
.Base
, GL_RGBA
);
185 sisSetSpanFunctions(&smesa
->back
, &fb
->Visual
);
186 _mesa_add_renderbuffer(fb
, BUFFER_BACK_LEFT
, &smesa
->back
.Base
);
189 if (smesa
->glCtx
->Visual
.depthBits
> 0) {
190 sisInitRenderbuffer(&smesa
->depth
.Base
,
191 (smesa
->glCtx
->Visual
.depthBits
== 16
192 ? GL_DEPTH_COMPONENT16
: GL_DEPTH_COMPONENT24
));
193 sisSetSpanFunctions(&smesa
->depth
, &fb
->Visual
);
194 _mesa_add_renderbuffer(fb
, BUFFER_DEPTH
, &smesa
->depth
.Base
);
197 if (smesa
->glCtx
->Visual
.stencilBits
> 0) {
198 sisInitRenderbuffer(&smesa
->stencil
.Base
, GL_STENCIL_INDEX8_EXT
);
199 sisSetSpanFunctions(&smesa
->stencil
, &fb
->Visual
);
200 _mesa_add_renderbuffer(fb
, BUFFER_STENCIL
, &smesa
->stencil
.Base
);
204 /* Make sure initialization did what we think it should */
205 assert(smesa
->front
.Base
.InternalFormat
);
206 assert(smesa
->front
.Base
.AllocStorage
);
207 if (fb
->Visual
.doubleBufferMode
) {
208 assert(fb
->Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
);
209 assert(smesa
->front
.Base
.AllocStorage
);
211 if (fb
->Visual
.depthBits
) {
212 assert(fb
->Attachment
[BUFFER_DEPTH
].Renderbuffer
);
213 assert(smesa
->depth
.Base
.AllocStorage
);
216 /* XXX Should get the base offset of the frontbuffer from the X Server */
217 smesa
->front
.offset
= smesa
->driDrawable
->x
* smesa
->bytesPerPixel
+
218 smesa
->driDrawable
->y
* smesa
->front
.pitch
;
219 smesa
->front
.map
= (char *) smesa
->driScreen
->pFB
+ smesa
->front
.offset
;
221 if ( smesa
->width
== smesa
->driDrawable
->w
&&
222 smesa
->height
== smesa
->driDrawable
->h
)
227 smesa
->front
.bpp
= smesa
->bytesPerPixel
* 8;
228 /* Front pitch set on context create */
229 smesa
->front
.size
= smesa
->front
.pitch
* smesa
->driDrawable
->h
;
231 smesa
->width
= smesa
->driDrawable
->w
;
232 smesa
->height
= smesa
->driDrawable
->h
;
233 smesa
->bottom
= smesa
->height
- 1;
235 if (smesa
->back
.offset
)
236 sisFreeBackbuffer( smesa
);
237 if (smesa
->depth
.offset
)
238 sisFreeZStencilBuffer( smesa
);
240 if ( smesa
->glCtx
->Visual
.depthBits
> 0 )
241 sisAllocZStencilBuffer( smesa
);
242 if ( smesa
->glCtx
->Visual
.doubleBufferMode
)
243 sisAllocBackbuffer( smesa
);
245 current
->hwZ
&= ~MASK_ZBufferPitch
;
246 current
->hwZ
|= smesa
->depth
.pitch
>> 2;
247 current
->hwOffsetZ
= smesa
->depth
.offset
>> 2;
249 if ((current
->hwOffsetZ
!= prev
->hwOffsetZ
) || (current
->hwZ
!= prev
->hwZ
)) {
250 prev
->hwOffsetZ
= current
->hwOffsetZ
;
251 prev
->hwZ
= current
->hwZ
;
252 smesa
->GlobalFlag
|= GFLAG_ZSETTING
;
255 sisUpdateClipping( smesa
->glCtx
);
258 /* Initialize the driver's misc functions.
261 sisInitDriverFuncs( struct dd_function_table
*functions
)
263 functions
->GetBufferSize
= sisGetBufferSize
;
264 functions
->GetString
= sisGetString
;
265 functions
->Finish
= sisFinish
;
266 functions
->Flush
= sisFlush
;