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