1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
35 #include "intel_screen.h"
36 #include "intel_context.h"
37 #include "swrast/swrast.h"
40 static void intelDrawBuffer(GLcontext
*ctx
, GLenum mode
)
42 intelContextPtr intel
= INTEL_CONTEXT(ctx
);
43 intelScreenPrivate
*screen
= intel
->intelScreen
;
46 switch ( ctx
->Color
._DrawDestMask
[0] ) {
47 case DD_FRONT_LEFT_BIT
:
49 FALLBACK( intel
, INTEL_FALLBACK_DRAW_BUFFER
, GL_FALSE
);
51 case DD_BACK_LEFT_BIT
:
53 FALLBACK( intel
, INTEL_FALLBACK_DRAW_BUFFER
, GL_FALSE
);
56 FALLBACK( intel
, INTEL_FALLBACK_DRAW_BUFFER
, GL_TRUE
);
60 /* We want to update the s/w rast state too so that r200SetBuffer()
63 _swrast_DrawBuffer(ctx
, mode
);
65 if ( intel
->sarea
->pf_current_page
== 1 )
68 intelSetFrontClipRects( intel
);
71 intel
->drawOffset
= screen
->frontOffset
;
72 intel
->drawMap
= (char *)intel
->driScreen
->pFB
;
73 intel
->readMap
= (char *)intel
->driScreen
->pFB
;
75 intel
->drawOffset
= screen
->backOffset
;
76 intel
->drawMap
= screen
->back
.map
;
77 intel
->readMap
= screen
->back
.map
;
80 intel
->vtbl
.set_draw_offset( intel
, intel
->drawOffset
);
83 static void intelReadBuffer( GLcontext
*ctx
, GLenum mode
)
85 /* nothing, until we implement h/w glRead/CopyPixels or CopyTexImage */
89 static void intelClearColor(GLcontext
*ctx
, const GLfloat color
[4])
91 intelContextPtr intel
= INTEL_CONTEXT(ctx
);
92 intelScreenPrivate
*screen
= intel
->intelScreen
;
94 CLAMPED_FLOAT_TO_UBYTE(intel
->clear_red
, color
[0]);
95 CLAMPED_FLOAT_TO_UBYTE(intel
->clear_green
, color
[1]);
96 CLAMPED_FLOAT_TO_UBYTE(intel
->clear_blue
, color
[2]);
97 CLAMPED_FLOAT_TO_UBYTE(intel
->clear_alpha
, color
[3]);
99 intel
->ClearColor
= INTEL_PACKCOLOR(screen
->fbFormat
,
107 static void intelCalcViewport( GLcontext
*ctx
)
109 intelContextPtr intel
= INTEL_CONTEXT(ctx
);
110 const GLfloat
*v
= ctx
->Viewport
._WindowMap
.m
;
111 GLfloat
*m
= intel
->ViewportMatrix
.m
;
113 /* See also intel_translate_vertex. SUBPIXEL adjustments can be done
114 * via state vars, too.
116 m
[MAT_SX
] = v
[MAT_SX
];
117 m
[MAT_TX
] = v
[MAT_TX
] + SUBPIXEL_X
;
118 m
[MAT_SY
] = - v
[MAT_SY
];
119 m
[MAT_TY
] = - v
[MAT_TY
] + intel
->driDrawable
->h
+ SUBPIXEL_Y
;
120 m
[MAT_SZ
] = v
[MAT_SZ
] * intel
->depth_scale
;
121 m
[MAT_TZ
] = v
[MAT_TZ
] * intel
->depth_scale
;
124 static void intelViewport( GLcontext
*ctx
,
126 GLsizei width
, GLsizei height
)
128 intelCalcViewport( ctx
);
131 static void intelDepthRange( GLcontext
*ctx
,
132 GLclampd nearval
, GLclampd farval
)
134 intelCalcViewport( ctx
);
137 /* Fallback to swrast for select and feedback.
139 static void intelRenderMode( GLcontext
*ctx
, GLenum mode
)
141 intelContextPtr intel
= INTEL_CONTEXT(ctx
);
142 FALLBACK( intel
, INTEL_FALLBACK_RENDERMODE
, (mode
!= GL_RENDER
) );
146 void intelInitStateFuncs( struct dd_function_table
*functions
)
148 functions
->DrawBuffer
= intelDrawBuffer
;
149 functions
->ReadBuffer
= intelReadBuffer
;
150 functions
->RenderMode
= intelRenderMode
;
151 functions
->Viewport
= intelViewport
;
152 functions
->DepthRange
= intelDepthRange
;
153 functions
->ClearColor
= intelClearColor
;