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_BASE_LEVEL
:
89 case GL_TEXTURE_MAX_LEVEL
:
90 case GL_TEXTURE_MIN_LOD
:
91 case GL_TEXTURE_MAX_LOD
:
92 /* The i915 and its successors can do a lot of this without
93 * reloading the textures. A project for someone?
96 driSwapOutTextureObject( (driTextureObject
*) t
);
97 t
->intel
.dirty
= I915_UPLOAD_TEX_ALL
;
106 static void i915TexEnv( GLcontext
*ctx
, GLenum target
,
107 GLenum pname
, const GLfloat
*param
)
109 i915ContextPtr i915
= I915_CONTEXT( ctx
);
110 GLuint unit
= ctx
->Texture
.CurrentUnit
;
113 case GL_TEXTURE_ENV_COLOR
: /* Should be a tracked param */
114 case GL_TEXTURE_ENV_MODE
:
116 case GL_COMBINE_ALPHA
:
120 case GL_SOURCE0_ALPHA
:
121 case GL_SOURCE1_ALPHA
:
122 case GL_SOURCE2_ALPHA
:
123 case GL_OPERAND0_RGB
:
124 case GL_OPERAND1_RGB
:
125 case GL_OPERAND2_RGB
:
126 case GL_OPERAND0_ALPHA
:
127 case GL_OPERAND1_ALPHA
:
128 case GL_OPERAND2_ALPHA
:
131 i915
->tex_program
.translated
= 0;
134 case GL_TEXTURE_LOD_BIAS
: {
135 int b
= (int) ((*param
) * 16.0);
136 if (b
> 255) b
= 255;
137 if (b
< -256) b
= -256;
138 I915_STATECHANGE(i915
, I915_UPLOAD_TEX(unit
));
139 i915
->state
.Tex
[unit
][I915_TEXREG_SS2
] &= ~SS2_LOD_BIAS_MASK
;
140 i915
->state
.Tex
[unit
][I915_TEXREG_SS2
] |=
141 ((b
<< SS2_LOD_BIAS_SHIFT
) & SS2_LOD_BIAS_MASK
);
151 static void i915BindTexture( GLcontext
*ctx
, GLenum target
,
152 struct gl_texture_object
*texObj
)
154 i915TextureObjectPtr tex
= (i915TextureObjectPtr
)texObj
->DriverData
;
156 if (tex
->lastTarget
!= texObj
->Target
) {
157 tex
->intel
.dirty
= I915_UPLOAD_TEX_ALL
;
158 tex
->lastTarget
= texObj
->Target
;
161 /* Need this if image format changes between bound textures.
162 * Could try and shortcircuit by checking for differences in
163 * state between incoming and outgoing textures:
165 I915_CONTEXT(ctx
)->tex_program
.translated
= 0;
170 void i915InitTextureFuncs( struct dd_function_table
*functions
)
172 functions
->BindTexture
= i915BindTexture
;
173 functions
->TexEnv
= i915TexEnv
;
174 functions
->TexParameter
= i915TexParameter
;