add missing license texts
[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_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?
94 */
95 intelFlush( ctx );
96 driSwapOutTextureObject( (driTextureObject *) t );
97 t->intel.dirty = I915_UPLOAD_TEX_ALL;
98 break;
99
100 default:
101 return;
102 }
103 }
104
105
106 static void i915TexEnv( GLcontext *ctx, GLenum target,
107 GLenum pname, const GLfloat *param )
108 {
109 i915ContextPtr i915 = I915_CONTEXT( ctx );
110 GLuint unit = ctx->Texture.CurrentUnit;
111
112 switch (pname) {
113 case GL_TEXTURE_ENV_COLOR: /* Should be a tracked param */
114 case GL_TEXTURE_ENV_MODE:
115 case GL_COMBINE_RGB:
116 case GL_COMBINE_ALPHA:
117 case GL_SOURCE0_RGB:
118 case GL_SOURCE1_RGB:
119 case GL_SOURCE2_RGB:
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:
129 case GL_RGB_SCALE:
130 case GL_ALPHA_SCALE:
131 i915->tex_program.translated = 0;
132 break;
133
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);
142 break;
143 }
144
145 default:
146 break;
147 }
148 }
149
150
151 static void i915BindTexture( GLcontext *ctx, GLenum target,
152 struct gl_texture_object *texObj )
153 {
154 i915TextureObjectPtr tex = (i915TextureObjectPtr)texObj->DriverData;
155
156 if (tex->lastTarget != texObj->Target) {
157 tex->intel.dirty = I915_UPLOAD_TEX_ALL;
158 tex->lastTarget = texObj->Target;
159 }
160
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:
164 */
165 I915_CONTEXT(ctx)->tex_program.translated = 0;
166 }
167
168
169
170 void i915InitTextureFuncs( struct dd_function_table *functions )
171 {
172 functions->BindTexture = i915BindTexture;
173 functions->TexEnv = i915TexEnv;
174 functions->TexParameter = i915TexParameter;
175 }