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 **************************************************************************/
31 #include "simple_list.h"
35 #include "texformat.h"
37 #include "swrast/swrast.h"
41 #include "intel_ioctl.h"
43 #include "i915_context.h"
52 * Allocate space for and load the mesa images into the texture memory block.
53 * This will happen before drawing with a new texture, or drawing with a
54 * texture after it was swapped out or teximaged again.
57 intelTextureObjectPtr
i915AllocTexObj( struct gl_texture_object
*texObj
)
59 i915TextureObjectPtr t
= CALLOC_STRUCT( i915_texture_object
);
63 texObj
->DriverData
= t
;
64 t
->intel
.base
.tObj
= texObj
;
65 t
->intel
.dirty
= I915_UPLOAD_TEX_ALL
;
66 make_empty_list( &t
->intel
.base
);
71 static void i915TexParameter( GLcontext
*ctx
, GLenum target
,
72 struct gl_texture_object
*tObj
,
73 GLenum pname
, const GLfloat
*params
)
75 i915TextureObjectPtr t
= (i915TextureObjectPtr
) tObj
->DriverData
;
78 case GL_TEXTURE_MIN_FILTER
:
79 case GL_TEXTURE_MAG_FILTER
:
80 case GL_TEXTURE_MAX_ANISOTROPY_EXT
:
81 case GL_TEXTURE_WRAP_S
:
82 case GL_TEXTURE_WRAP_T
:
83 case GL_TEXTURE_WRAP_R
:
84 case GL_TEXTURE_BORDER_COLOR
:
85 t
->intel
.dirty
= I915_UPLOAD_TEX_ALL
;
88 case GL_TEXTURE_COMPARE_MODE
:
89 t
->intel
.dirty
= I915_UPLOAD_TEX_ALL
;
91 case GL_TEXTURE_COMPARE_FUNC
:
92 t
->intel
.dirty
= I915_UPLOAD_TEX_ALL
;
95 case GL_TEXTURE_BASE_LEVEL
:
96 case GL_TEXTURE_MAX_LEVEL
:
97 case GL_TEXTURE_MIN_LOD
:
98 case GL_TEXTURE_MAX_LOD
:
99 /* The i915 and its successors can do a lot of this without
100 * reloading the textures. A project for someone?
103 driSwapOutTextureObject( (driTextureObject
*) t
);
104 t
->intel
.dirty
= I915_UPLOAD_TEX_ALL
;
113 static void i915TexEnv( GLcontext
*ctx
, GLenum target
,
114 GLenum pname
, const GLfloat
*param
)
116 i915ContextPtr i915
= I915_CONTEXT( ctx
);
117 GLuint unit
= ctx
->Texture
.CurrentUnit
;
120 case GL_TEXTURE_ENV_COLOR
: /* Should be a tracked param */
121 case GL_TEXTURE_ENV_MODE
:
123 case GL_COMBINE_ALPHA
:
127 case GL_SOURCE0_ALPHA
:
128 case GL_SOURCE1_ALPHA
:
129 case GL_SOURCE2_ALPHA
:
130 case GL_OPERAND0_RGB
:
131 case GL_OPERAND1_RGB
:
132 case GL_OPERAND2_RGB
:
133 case GL_OPERAND0_ALPHA
:
134 case GL_OPERAND1_ALPHA
:
135 case GL_OPERAND2_ALPHA
:
138 i915
->tex_program
.translated
= 0;
141 case GL_TEXTURE_LOD_BIAS
: {
142 int b
= (int) ((*param
) * 16.0);
143 if (b
> 255) b
= 255;
144 if (b
< -256) b
= -256;
145 I915_STATECHANGE(i915
, I915_UPLOAD_TEX(unit
));
146 i915
->state
.Tex
[unit
][I915_TEXREG_SS2
] &= ~SS2_LOD_BIAS_MASK
;
147 i915
->state
.Tex
[unit
][I915_TEXREG_SS2
] |=
148 ((b
<< SS2_LOD_BIAS_SHIFT
) & SS2_LOD_BIAS_MASK
);
158 static void i915BindTexture( GLcontext
*ctx
, GLenum target
,
159 struct gl_texture_object
*texObj
)
161 i915TextureObjectPtr tex
;
163 if (!texObj
->DriverData
)
164 i915AllocTexObj( texObj
);
166 tex
= (i915TextureObjectPtr
)texObj
->DriverData
;
168 if (tex
->lastTarget
!= texObj
->Target
) {
169 tex
->intel
.dirty
= I915_UPLOAD_TEX_ALL
;
170 tex
->lastTarget
= texObj
->Target
;
173 /* Need this if image format changes between bound textures.
174 * Could try and shortcircuit by checking for differences in
175 * state between incoming and outgoing textures:
177 I915_CONTEXT(ctx
)->tex_program
.translated
= 0;
182 void i915InitTextureFuncs( struct dd_function_table
*functions
)
184 functions
->BindTexture
= i915BindTexture
;
185 functions
->TexEnv
= i915TexEnv
;
186 functions
->TexParameter
= i915TexParameter
;