Allow RBUG to start blocked
[mesa.git] / src / mesa / state_tracker / st_texture.h
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 #ifndef ST_TEXTURE_H
29 #define ST_TEXTURE_H
30
31
32 #include "pipe/p_context.h"
33 #include "util/u_sampler.h"
34
35 #include "main/mtypes.h"
36
37
38 struct pipe_resource;
39
40
41 /**
42 * Subclass of gl_texure_image.
43 */
44 struct st_texture_image
45 {
46 struct gl_texture_image base;
47
48 /* If stImage->pt != NULL, image data is stored here.
49 * Else if stImage->base.Data != NULL, image is stored there.
50 * Else there is no image data.
51 */
52 struct pipe_resource *pt;
53
54 struct pipe_transfer *transfer;
55 };
56
57
58 /**
59 * Subclass of gl_texure_object.
60 */
61 struct st_texture_object
62 {
63 struct gl_texture_object base; /* The "parent" object */
64
65 /* The texture must include at levels [0..lastLevel] once validated:
66 */
67 GLuint lastLevel;
68
69 /** The size of the level=0 mipmap image.
70 * Note that the number of 1D array layers will be in height0 and the
71 * number of 2D array layers will be in depth0, as in GL.
72 */
73 GLuint width0, height0, depth0;
74
75 /* On validation any active images held in main memory or in other
76 * textures will be copied to this texture and the old storage freed.
77 */
78 struct pipe_resource *pt;
79
80 /* Default sampler view attached to this texture object. Created lazily
81 * on first binding.
82 */
83 struct pipe_sampler_view *sampler_view;
84
85 /* True if there is/was a surface bound to this texture object. It helps
86 * track whether the texture object is surface based or not.
87 */
88 GLboolean surface_based;
89 };
90
91
92 static INLINE struct st_texture_image *
93 st_texture_image(struct gl_texture_image *img)
94 {
95 return (struct st_texture_image *) img;
96 }
97
98 static INLINE struct st_texture_object *
99 st_texture_object(struct gl_texture_object *obj)
100 {
101 return (struct st_texture_object *) obj;
102 }
103
104
105 static INLINE struct pipe_resource *
106 st_get_texobj_resource(struct gl_texture_object *texObj)
107 {
108 struct st_texture_object *stObj = st_texture_object(texObj);
109 return stObj ? stObj->pt : NULL;
110 }
111
112
113 static INLINE struct pipe_resource *
114 st_get_stobj_resource(struct st_texture_object *stObj)
115 {
116 return stObj ? stObj->pt : NULL;
117 }
118
119
120 static INLINE struct pipe_sampler_view *
121 st_create_texture_sampler_view(struct pipe_context *pipe,
122 struct pipe_resource *texture)
123 {
124 struct pipe_sampler_view templ;
125
126 u_sampler_view_default_template(&templ, texture, texture->format);
127
128 return pipe->create_sampler_view(pipe, texture, &templ);
129 }
130
131
132 static INLINE struct pipe_sampler_view *
133 st_create_texture_sampler_view_format(struct pipe_context *pipe,
134 struct pipe_resource *texture,
135 enum pipe_format format)
136 {
137 struct pipe_sampler_view templ;
138
139 u_sampler_view_default_template(&templ, texture, format);
140
141 return pipe->create_sampler_view(pipe, texture, &templ);
142 }
143
144
145 static INLINE struct pipe_sampler_view *
146 st_get_texture_sampler_view(struct st_texture_object *stObj,
147 struct pipe_context *pipe)
148 {
149 if (!stObj || !stObj->pt) {
150 return NULL;
151 }
152
153 if (!stObj->sampler_view) {
154 stObj->sampler_view = st_create_texture_sampler_view(pipe, stObj->pt);
155 }
156
157 return stObj->sampler_view;
158 }
159
160
161 extern struct pipe_resource *
162 st_texture_create(struct st_context *st,
163 enum pipe_texture_target target,
164 enum pipe_format format,
165 GLuint last_level,
166 GLuint width0,
167 GLuint height0,
168 GLuint depth0,
169 GLuint layers,
170 GLuint tex_usage );
171
172
173 extern void
174 st_gl_texture_dims_to_pipe_dims(GLenum texture,
175 GLuint widthIn,
176 GLuint heightIn,
177 GLuint depthIn,
178 GLuint *widthOut,
179 GLuint *heightOut,
180 GLuint *depthOut,
181 GLuint *layersOut);
182
183 /* Check if an image fits into an existing texture object.
184 */
185 extern GLboolean
186 st_texture_match_image(const struct pipe_resource *pt,
187 const struct gl_texture_image *image);
188
189 /* Return a pointer to an image within a texture. Return image stride as
190 * well.
191 */
192 extern GLubyte *
193 st_texture_image_map(struct st_context *st,
194 struct st_texture_image *stImage,
195 GLuint zoffset,
196 enum pipe_transfer_usage usage,
197 unsigned x, unsigned y,
198 unsigned w, unsigned h);
199
200 extern void
201 st_texture_image_unmap(struct st_context *st,
202 struct st_texture_image *stImage);
203
204
205 /* Return pointers to each 2d slice within an image. Indexed by depth
206 * value.
207 */
208 extern const GLuint *
209 st_texture_depth_offsets(struct pipe_resource *pt, GLuint level);
210
211
212 /* Upload an image into a texture
213 */
214 extern void
215 st_texture_image_data(struct st_context *st,
216 struct pipe_resource *dst,
217 GLuint face, GLuint level, void *src,
218 GLuint src_row_pitch, GLuint src_image_pitch);
219
220
221 /* Copy an image between two textures
222 */
223 extern void
224 st_texture_image_copy(struct pipe_context *pipe,
225 struct pipe_resource *dst, GLuint dstLevel,
226 struct pipe_resource *src, GLuint srcLevel,
227 GLuint face);
228
229
230 extern struct pipe_resource *
231 st_create_color_map_texture(struct gl_context *ctx);
232
233 #endif