fix fd.o bug #12217, recalcuate urb when clip plane size change
[mesa.git] / src / mesa / drivers / dri / i915 / i915_tex.c
1 /**************************************************************************
2 *
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #include "glheader.h"
29 #include "mtypes.h"
30 #include "imports.h"
31 #include "simple_list.h"
32 #include "enums.h"
33 #include "image.h"
34 #include "texstore.h"
35 #include "texformat.h"
36 #include "texmem.h"
37 #include "swrast/swrast.h"
38
39 #include "mm.h"
40
41 #include "intel_ioctl.h"
42
43 #include "i915_context.h"
44 #include "i915_reg.h"
45
46
47
48
49
50
51 /**
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.
55 */
56
57 intelTextureObjectPtr i915AllocTexObj( struct gl_texture_object *texObj )
58 {
59 i915TextureObjectPtr t = CALLOC_STRUCT( i915_texture_object );
60 if ( !t )
61 return NULL;
62
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 );
67 return &t->intel;
68 }
69
70
71 static void i915TexParameter( GLcontext *ctx, GLenum target,
72 struct gl_texture_object *tObj,
73 GLenum pname, const GLfloat *params )
74 {
75 i915TextureObjectPtr t = (i915TextureObjectPtr) tObj->DriverData;
76
77 switch (pname) {
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;
86 break;
87
88 case GL_TEXTURE_COMPARE_MODE:
89 t->intel.dirty = I915_UPLOAD_TEX_ALL;
90 break;
91 case GL_TEXTURE_COMPARE_FUNC:
92 t->intel.dirty = I915_UPLOAD_TEX_ALL;
93 break;
94
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?
101 */
102 intelFlush( ctx );
103 driSwapOutTextureObject( (driTextureObject *) t );
104 t->intel.dirty = I915_UPLOAD_TEX_ALL;
105 break;
106
107 default:
108 return;
109 }
110 }
111
112
113 static void i915TexEnv( GLcontext *ctx, GLenum target,
114 GLenum pname, const GLfloat *param )
115 {
116 i915ContextPtr i915 = I915_CONTEXT( ctx );
117 GLuint unit = ctx->Texture.CurrentUnit;
118
119 switch (pname) {
120 case GL_TEXTURE_ENV_COLOR: /* Should be a tracked param */
121 case GL_TEXTURE_ENV_MODE:
122 case GL_COMBINE_RGB:
123 case GL_COMBINE_ALPHA:
124 case GL_SOURCE0_RGB:
125 case GL_SOURCE1_RGB:
126 case GL_SOURCE2_RGB:
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:
136 case GL_RGB_SCALE:
137 case GL_ALPHA_SCALE:
138 i915->tex_program.translated = 0;
139 break;
140
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);
149 break;
150 }
151
152 default:
153 break;
154 }
155 }
156
157
158 static void i915BindTexture( GLcontext *ctx, GLenum target,
159 struct gl_texture_object *texObj )
160 {
161 i915TextureObjectPtr tex;
162
163 if (!texObj->DriverData)
164 i915AllocTexObj( texObj );
165
166 tex = (i915TextureObjectPtr)texObj->DriverData;
167
168 if (tex->lastTarget != texObj->Target) {
169 tex->intel.dirty = I915_UPLOAD_TEX_ALL;
170 tex->lastTarget = texObj->Target;
171 }
172
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:
176 */
177 I915_CONTEXT(ctx)->tex_program.translated = 0;
178 }
179
180
181
182 void i915InitTextureFuncs( struct dd_function_table *functions )
183 {
184 functions->BindTexture = i915BindTexture;
185 functions->TexEnv = i915TexEnv;
186 functions->TexParameter = i915TexParameter;
187 }