Merge branch 'i915tex_privbuffers' into softpipe_0_1_branch
[mesa.git] / src / mesa / state_tracker / st_atom_sampler.c
1 /**************************************************************************
2 *
3 * Copyright 2007 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 /*
29 * Authors:
30 * Keith Whitwell <keith@tungstengraphics.com>
31 * Brian Paul
32 */
33
34
35 #include "st_context.h"
36 #include "st_atom.h"
37 #include "pipe/p_context.h"
38 #include "pipe/p_defines.h"
39
40
41 /**
42 * Convert GLenum texcoord wrap tokens to pipe tokens.
43 */
44 static GLuint
45 gl_wrap_to_sp(GLenum wrap)
46 {
47 switch (wrap) {
48 case GL_REPEAT:
49 return PIPE_TEX_WRAP_REPEAT;
50 case GL_CLAMP:
51 return PIPE_TEX_WRAP_CLAMP;
52 case GL_CLAMP_TO_EDGE:
53 return PIPE_TEX_WRAP_CLAMP_TO_EDGE;
54 case GL_CLAMP_TO_BORDER:
55 return PIPE_TEX_WRAP_CLAMP_TO_BORDER;
56 case GL_MIRRORED_REPEAT:
57 return PIPE_TEX_WRAP_MIRROR_REPEAT;
58 case GL_MIRROR_CLAMP_EXT:
59 return PIPE_TEX_WRAP_MIRROR_CLAMP;
60 case GL_MIRROR_CLAMP_TO_EDGE_EXT:
61 return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE;
62 case GL_MIRROR_CLAMP_TO_BORDER_EXT:
63 return PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER;
64 default:
65 abort();
66 return 0;
67 }
68 }
69
70
71 static GLuint
72 gl_filter_to_sp(GLenum filter)
73 {
74 switch (filter) {
75 case GL_NEAREST:
76 return PIPE_TEX_FILTER_NEAREST;
77 case GL_LINEAR:
78 return PIPE_TEX_FILTER_LINEAR;
79 case GL_NEAREST_MIPMAP_NEAREST:
80 return PIPE_TEX_FILTER_NEAREST_MIPMAP_NEAREST;
81 case GL_NEAREST_MIPMAP_LINEAR:
82 return PIPE_TEX_FILTER_NEAREST_MIPMAP_LINEAR;
83 case GL_LINEAR_MIPMAP_NEAREST:
84 return PIPE_TEX_FILTER_LINEAR_MIPMAP_NEAREST;
85 case GL_LINEAR_MIPMAP_LINEAR:
86 return PIPE_TEX_FILTER_LINEAR_MIPMAP_LINEAR;
87 default:
88 abort();
89 return 0;
90 }
91 }
92
93
94 static void
95 update_samplers(struct st_context *st)
96 {
97 GLuint u;
98
99 for (u = 0; u < st->ctx->Const.MaxTextureImageUnits; u++) {
100 const struct gl_texture_object *texobj
101 = st->ctx->Texture.Unit[u]._Current;
102 struct pipe_sampler_state sampler;
103
104 memset(&sampler, 0, sizeof(sampler));
105
106 sampler.wrap_s = gl_wrap_to_sp(texobj->WrapS);
107 sampler.wrap_t = gl_wrap_to_sp(texobj->WrapT);
108 sampler.wrap_r = gl_wrap_to_sp(texobj->WrapR);
109
110 sampler.min_filter = gl_filter_to_sp(texobj->MinFilter);
111 sampler.mag_filter = gl_filter_to_sp(texobj->MagFilter);
112
113 /* XXX more sampler state here */
114
115 if (memcmp(&sampler, &st->state.sampler[u], sizeof(sampler)) != 0) {
116 /* state has changed */
117 st->state.sampler[u] = sampler;
118 st->pipe->set_sampler_state(st->pipe, u, &sampler);
119 }
120 }
121 }
122
123
124 const struct st_tracked_state st_update_sampler = {
125 .dirty = {
126 .mesa = _NEW_TEXTURE,
127 .st = 0,
128 },
129 .update = update_samplers
130 };
131
132
133
134
135