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 **************************************************************************/
27 /* $XFree86: xc/lib/GL/mesa/src/drv/sis/sis_ctx.c,v 1.3 2000/09/26 15:56:48 tsi Exp $ */
31 * Sung-Ching Lin <sclin@sis.com.tw>
32 * Eric Anholt <anholt@FreeBSD.org>
36 #include "sis_context.h"
39 #include "sis_alloc.h"
40 #include "sis_state.h"
43 #include "swrast/swrast.h"
47 #define DRIVER_DATE "20040925"
49 /* Return the width and height of the given buffer.
52 sisGetBufferSize( GLframebuffer
*buffer
,
53 GLuint
*width
, GLuint
*height
)
55 GET_CURRENT_CONTEXT(ctx
);
56 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
59 *width
= smesa
->driDrawable
->w
;
60 *height
= smesa
->driDrawable
->h
;
64 /* Return various strings for glGetString().
66 static const GLubyte
*
67 sisGetString( GLcontext
*ctx
, GLenum name
)
69 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
70 static char buffer
[128];
72 GLuint agp_mode
= (smesa
->AGPSize
> 0);
77 return (GLubyte
*)"Eric Anholt";
80 offset
= driGetRendererString( buffer
, "SiS", DRIVER_DATE
, agp_mode
);
82 return (GLubyte
*)buffer
;
89 /* Send all commands to the hardware.
92 sisFlush( GLcontext
*ctx
)
94 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
96 SIS_FIREVERTICES(smesa
);
99 /* Make sure all commands have been sent to the hardware and have
100 * completed processing.
103 sisFinish( GLcontext
*ctx
)
105 sisContextPtr smesa
= SIS_CONTEXT(ctx
);
107 SIS_FIREVERTICES(smesa
);
109 WaitEngIdle( smesa
);
114 sisUpdateBufferSize( sisContextPtr smesa
)
116 __GLSiSHardware
*current
= &smesa
->current
;
117 __GLSiSHardware
*prev
= &smesa
->prev
;
120 /* XXX Should get the base offset of the frontbuffer from the X Server */
121 smesa
->frontOffset
= smesa
->driDrawable
->x
* smesa
->bytesPerPixel
+
122 smesa
->driDrawable
->y
* smesa
->frontPitch
;
124 if ( smesa
->width
== smesa
->driDrawable
->w
&&
125 smesa
->height
== smesa
->driDrawable
->h
)
130 smesa
->width
= smesa
->driDrawable
->w
;
131 smesa
->height
= smesa
->driDrawable
->h
;
132 smesa
->bottom
= smesa
->height
- 1;
134 if ( smesa
->backbuffer
)
135 sisFreeBackbuffer( smesa
);
136 if ( smesa
->depthbuffer
)
137 sisFreeZStencilBuffer( smesa
);
139 if ( smesa
->glCtx
->Visual
.depthBits
> 0 )
140 sisAllocZStencilBuffer( smesa
);
141 if ( smesa
->glCtx
->Visual
.doubleBufferMode
)
142 sisAllocBackbuffer( smesa
);
144 switch (smesa
->zFormat
)
146 case SiS_ZFORMAT_Z16
:
149 case SiS_ZFORMAT_Z32
:
150 case SiS_ZFORMAT_S8Z24
:
154 sis_fatal_error("Bad Z format\n");
157 current
->hwZ
&= ~MASK_ZBufferPitch
;
158 current
->hwZ
|= smesa
->width
* z_depth
>> 2;
159 current
->hwOffsetZ
= smesa
->depthOffset
>> 2;
161 if ((current
->hwOffsetZ
!= prev
->hwOffsetZ
) || (current
->hwZ
!= prev
->hwZ
)) {
162 prev
->hwOffsetZ
= current
->hwOffsetZ
;
163 prev
->hwZ
= current
->hwZ
;
164 smesa
->GlobalFlag
|= GFLAG_ZSETTING
;
167 sisUpdateClipping( smesa
->glCtx
);
170 /* Initialize the driver's misc functions.
173 sisInitDriverFuncs( struct dd_function_table
*functions
)
175 functions
->GetBufferSize
= sisGetBufferSize
;
176 functions
->ResizeBuffers
= _swrast_alloc_buffers
;
177 functions
->GetString
= sisGetString
;
178 functions
->Finish
= sisFinish
;
179 functions
->Flush
= sisFlush
;