Merge remote branch 'origin/master' into radeon-rewrite
[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 "main/mtypes.h"
33
34 struct pipe_context;
35 struct pipe_texture;
36
37
38 struct st_texture_image
39 {
40 struct gl_texture_image base;
41
42 /* These aren't stored in gl_texture_image
43 */
44 GLuint level;
45 GLuint face;
46
47 /* If stImage->pt != NULL, image data is stored here.
48 * Else if stImage->base.Data != NULL, image is stored there.
49 * Else there is no image data.
50 */
51 struct pipe_texture *pt;
52
53 struct pipe_transfer *transfer;
54 };
55
56
57
58 struct st_texture_object
59 {
60 struct gl_texture_object base; /* The "parent" object */
61
62 /* The texture must include at levels [0..lastLevel] once validated:
63 */
64 GLuint lastLevel;
65
66 /* On validation any active images held in main memory or in other
67 * textures will be copied to this texture and the old storage freed.
68 */
69 struct pipe_texture *pt;
70
71 GLboolean teximage_realloc;
72 };
73
74
75 static INLINE struct st_texture_image *
76 st_texture_image(struct gl_texture_image *img)
77 {
78 return (struct st_texture_image *) img;
79 }
80
81 static INLINE struct st_texture_object *
82 st_texture_object(struct gl_texture_object *obj)
83 {
84 return (struct st_texture_object *) obj;
85 }
86
87
88 static INLINE struct pipe_texture *
89 st_get_texobj_texture(struct gl_texture_object *texObj)
90 {
91 struct st_texture_object *stObj = st_texture_object(texObj);
92 return stObj ? stObj->pt : NULL;
93 }
94
95
96 static INLINE struct pipe_texture *
97 st_get_stobj_texture(struct st_texture_object *stObj)
98 {
99 return stObj ? stObj->pt : NULL;
100 }
101
102
103 extern struct pipe_texture *
104 st_texture_create(struct st_context *st,
105 enum pipe_texture_target target,
106 enum pipe_format format,
107 GLuint last_level,
108 GLuint width0,
109 GLuint height0,
110 GLuint depth0,
111 GLuint tex_usage );
112
113
114 /* Check if an image fits into an existing texture object.
115 */
116 extern GLboolean
117 st_texture_match_image(const struct pipe_texture *pt,
118 const struct gl_texture_image *image,
119 GLuint face, GLuint level);
120
121 /* Return a pointer to an image within a texture. Return image stride as
122 * well.
123 */
124 extern GLubyte *
125 st_texture_image_map(struct st_context *st,
126 struct st_texture_image *stImage,
127 GLuint zoffset,
128 enum pipe_transfer_usage usage,
129 unsigned x, unsigned y,
130 unsigned w, unsigned h);
131
132 extern void
133 st_texture_image_unmap(struct st_context *st,
134 struct st_texture_image *stImage);
135
136
137 /* Return pointers to each 2d slice within an image. Indexed by depth
138 * value.
139 */
140 extern const GLuint *
141 st_texture_depth_offsets(struct pipe_texture *pt, GLuint level);
142
143
144 /* Return the linear offset of an image relative to the start of its region.
145 */
146 extern GLuint
147 st_texture_image_offset(const struct pipe_texture *pt,
148 GLuint face, GLuint level);
149
150 extern GLuint
151 st_texture_texel_offset(const struct pipe_texture * pt,
152 GLuint face, GLuint level,
153 GLuint col, GLuint row, GLuint img);
154
155
156 /* Upload an image into a texture
157 */
158 extern void
159 st_texture_image_data(struct st_context *st,
160 struct pipe_texture *dst,
161 GLuint face, GLuint level, void *src,
162 GLuint src_row_pitch, GLuint src_image_pitch);
163
164
165 /* Copy an image between two textures
166 */
167 extern void
168 st_texture_image_copy(struct pipe_context *pipe,
169 struct pipe_texture *dst, GLuint dstLevel,
170 struct pipe_texture *src,
171 GLuint face);
172
173 extern void
174 st_teximage_flush_before_map(struct st_context *st,
175 struct pipe_texture *pt,
176 unsigned int face,
177 unsigned int level,
178 enum pipe_transfer_usage usage);
179 #endif