Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4358 | Serge | 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 this texture comes from the window system. Such a texture |
||
91 | * cannot be reallocated and the format can only be changed with a sampler |
||
92 | * view or a surface. |
||
93 | */ |
||
94 | GLboolean surface_based; |
||
95 | |||
96 | /* If surface_based is true, this format should be used for all sampler |
||
97 | * views and surfaces instead of pt->format. |
||
98 | */ |
||
99 | enum pipe_format surface_format; |
||
100 | }; |
||
101 | |||
102 | |||
103 | static INLINE struct st_texture_image * |
||
104 | st_texture_image(struct gl_texture_image *img) |
||
105 | { |
||
106 | return (struct st_texture_image *) img; |
||
107 | } |
||
108 | |||
109 | static INLINE struct st_texture_object * |
||
110 | st_texture_object(struct gl_texture_object *obj) |
||
111 | { |
||
112 | return (struct st_texture_object *) obj; |
||
113 | } |
||
114 | |||
115 | |||
116 | static INLINE struct pipe_resource * |
||
117 | st_get_texobj_resource(struct gl_texture_object *texObj) |
||
118 | { |
||
119 | struct st_texture_object *stObj = st_texture_object(texObj); |
||
120 | return stObj ? stObj->pt : NULL; |
||
121 | } |
||
122 | |||
123 | |||
124 | static INLINE struct pipe_resource * |
||
125 | st_get_stobj_resource(struct st_texture_object *stObj) |
||
126 | { |
||
127 | return stObj ? stObj->pt : NULL; |
||
128 | } |
||
129 | |||
130 | |||
131 | static INLINE struct pipe_sampler_view * |
||
132 | st_create_texture_sampler_view_format(struct pipe_context *pipe, |
||
133 | struct pipe_resource *texture, |
||
134 | enum pipe_format format) |
||
135 | { |
||
136 | struct pipe_sampler_view templ; |
||
137 | |||
138 | u_sampler_view_default_template(&templ, texture, format); |
||
139 | |||
140 | return pipe->create_sampler_view(pipe, texture, &templ); |
||
141 | } |
||
142 | |||
143 | static INLINE struct pipe_sampler_view * |
||
144 | st_create_texture_sampler_view(struct pipe_context *pipe, |
||
145 | struct pipe_resource *texture) |
||
146 | { |
||
147 | return st_create_texture_sampler_view_format(pipe, texture, |
||
148 | texture->format); |
||
149 | } |
||
150 | |||
151 | |||
152 | |||
153 | extern struct pipe_resource * |
||
154 | st_texture_create(struct st_context *st, |
||
155 | enum pipe_texture_target target, |
||
156 | enum pipe_format format, |
||
157 | GLuint last_level, |
||
158 | GLuint width0, |
||
159 | GLuint height0, |
||
160 | GLuint depth0, |
||
161 | GLuint layers, |
||
162 | GLuint nr_samples, |
||
163 | GLuint tex_usage ); |
||
164 | |||
165 | |||
166 | extern void |
||
167 | st_gl_texture_dims_to_pipe_dims(GLenum texture, |
||
168 | GLuint widthIn, |
||
169 | GLuint heightIn, |
||
170 | GLuint depthIn, |
||
171 | GLuint *widthOut, |
||
172 | GLuint *heightOut, |
||
173 | GLuint *depthOut, |
||
174 | GLuint *layersOut); |
||
175 | |||
176 | /* Check if an image fits into an existing texture object. |
||
177 | */ |
||
178 | extern GLboolean |
||
179 | st_texture_match_image(const struct pipe_resource *pt, |
||
180 | const struct gl_texture_image *image); |
||
181 | |||
182 | /* Return a pointer to an image within a texture. Return image stride as |
||
183 | * well. |
||
184 | */ |
||
185 | extern GLubyte * |
||
186 | st_texture_image_map(struct st_context *st, struct st_texture_image *stImage, |
||
187 | enum pipe_transfer_usage usage, |
||
188 | GLuint x, GLuint y, GLuint z, |
||
189 | GLuint w, GLuint h, GLuint d); |
||
190 | |||
191 | extern void |
||
192 | st_texture_image_unmap(struct st_context *st, |
||
193 | struct st_texture_image *stImage); |
||
194 | |||
195 | |||
196 | /* Return pointers to each 2d slice within an image. Indexed by depth |
||
197 | * value. |
||
198 | */ |
||
199 | extern const GLuint * |
||
200 | st_texture_depth_offsets(struct pipe_resource *pt, GLuint level); |
||
201 | |||
202 | |||
203 | /* Upload an image into a texture |
||
204 | */ |
||
205 | extern void |
||
206 | st_texture_image_data(struct st_context *st, |
||
207 | struct pipe_resource *dst, |
||
208 | GLuint face, GLuint level, void *src, |
||
209 | GLuint src_row_pitch, GLuint src_image_pitch); |
||
210 | |||
211 | |||
212 | /* Copy an image between two textures |
||
213 | */ |
||
214 | extern void |
||
215 | st_texture_image_copy(struct pipe_context *pipe, |
||
216 | struct pipe_resource *dst, GLuint dstLevel, |
||
217 | struct pipe_resource *src, GLuint srcLevel, |
||
218 | GLuint face); |
||
219 | |||
220 | |||
221 | extern struct pipe_resource * |
||
222 | st_create_color_map_texture(struct gl_context *ctx); |
||
223 | |||
224 | #endif |