Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1901 | 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 | /* These aren't stored in gl_texture_image |
||
49 | */ |
||
50 | GLuint level; |
||
51 | GLuint face; |
||
52 | |||
53 | /* If stImage->pt != NULL, image data is stored here. |
||
54 | * Else if stImage->base.Data != 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 | GLuint width0, height0, depth0; |
||
76 | |||
77 | /* On validation any active images held in main memory or in other |
||
78 | * textures will be copied to this texture and the old storage freed. |
||
79 | */ |
||
80 | struct pipe_resource *pt; |
||
81 | |||
82 | /* Default sampler view attached to this texture object. Created lazily |
||
83 | * on first binding. |
||
84 | */ |
||
85 | struct pipe_sampler_view *sampler_view; |
||
86 | |||
87 | /* True if there is/was a surface bound to this texture object. It helps |
||
88 | * track whether the texture object is surface based or not. |
||
89 | */ |
||
90 | GLboolean surface_based; |
||
91 | }; |
||
92 | |||
93 | |||
94 | static INLINE struct st_texture_image * |
||
95 | st_texture_image(struct gl_texture_image *img) |
||
96 | { |
||
97 | return (struct st_texture_image *) img; |
||
98 | } |
||
99 | |||
100 | static INLINE struct st_texture_object * |
||
101 | st_texture_object(struct gl_texture_object *obj) |
||
102 | { |
||
103 | return (struct st_texture_object *) obj; |
||
104 | } |
||
105 | |||
106 | |||
107 | static INLINE struct pipe_resource * |
||
108 | st_get_texobj_resource(struct gl_texture_object *texObj) |
||
109 | { |
||
110 | struct st_texture_object *stObj = st_texture_object(texObj); |
||
111 | return stObj ? stObj->pt : NULL; |
||
112 | } |
||
113 | |||
114 | |||
115 | static INLINE struct pipe_resource * |
||
116 | st_get_stobj_resource(struct st_texture_object *stObj) |
||
117 | { |
||
118 | return stObj ? stObj->pt : NULL; |
||
119 | } |
||
120 | |||
121 | |||
122 | static INLINE struct pipe_sampler_view * |
||
123 | st_create_texture_sampler_view(struct pipe_context *pipe, |
||
124 | struct pipe_resource *texture) |
||
125 | { |
||
126 | struct pipe_sampler_view templ; |
||
127 | |||
128 | u_sampler_view_default_template(&templ, |
||
129 | texture, |
||
130 | texture->format); |
||
131 | |||
132 | return pipe->create_sampler_view(pipe, texture, &templ); |
||
133 | } |
||
134 | |||
135 | |||
136 | static INLINE struct pipe_sampler_view * |
||
137 | st_create_texture_sampler_view_format(struct pipe_context *pipe, |
||
138 | struct pipe_resource *texture, |
||
139 | enum pipe_format format) |
||
140 | { |
||
141 | struct pipe_sampler_view templ; |
||
142 | |||
143 | u_sampler_view_default_template(&templ, |
||
144 | texture, |
||
145 | format); |
||
146 | |||
147 | return pipe->create_sampler_view(pipe, texture, &templ); |
||
148 | } |
||
149 | |||
150 | static INLINE struct pipe_sampler_view * |
||
151 | st_get_texture_sampler_view(struct st_texture_object *stObj, |
||
152 | struct pipe_context *pipe) |
||
153 | |||
154 | { |
||
155 | if (!stObj || !stObj->pt) { |
||
156 | return NULL; |
||
157 | } |
||
158 | |||
159 | if (!stObj->sampler_view) { |
||
160 | stObj->sampler_view = st_create_texture_sampler_view(pipe, stObj->pt); |
||
161 | } |
||
162 | |||
163 | return stObj->sampler_view; |
||
164 | } |
||
165 | |||
166 | |||
167 | extern struct pipe_resource * |
||
168 | st_texture_create(struct st_context *st, |
||
169 | enum pipe_texture_target target, |
||
170 | enum pipe_format format, |
||
171 | GLuint last_level, |
||
172 | GLuint width0, |
||
173 | GLuint height0, |
||
174 | GLuint depth0, |
||
175 | GLuint tex_usage ); |
||
176 | |||
177 | |||
178 | /* Check if an image fits into an existing texture object. |
||
179 | */ |
||
180 | extern GLboolean |
||
181 | st_texture_match_image(const struct pipe_resource *pt, |
||
182 | const struct gl_texture_image *image, |
||
183 | GLuint face, GLuint level); |
||
184 | |||
185 | /* Return a pointer to an image within a texture. Return image stride as |
||
186 | * well. |
||
187 | */ |
||
188 | extern GLubyte * |
||
189 | st_texture_image_map(struct st_context *st, |
||
190 | struct st_texture_image *stImage, |
||
191 | GLuint zoffset, |
||
192 | enum pipe_transfer_usage usage, |
||
193 | unsigned x, unsigned y, |
||
194 | unsigned w, unsigned h); |
||
195 | |||
196 | extern void |
||
197 | st_texture_image_unmap(struct st_context *st, |
||
198 | struct st_texture_image *stImage); |
||
199 | |||
200 | |||
201 | /* Return pointers to each 2d slice within an image. Indexed by depth |
||
202 | * value. |
||
203 | */ |
||
204 | extern const GLuint * |
||
205 | st_texture_depth_offsets(struct pipe_resource *pt, GLuint level); |
||
206 | |||
207 | |||
208 | /* Upload an image into a texture |
||
209 | */ |
||
210 | extern void |
||
211 | st_texture_image_data(struct st_context *st, |
||
212 | struct pipe_resource *dst, |
||
213 | GLuint face, GLuint level, void *src, |
||
214 | GLuint src_row_pitch, GLuint src_image_pitch); |
||
215 | |||
216 | |||
217 | /* Copy an image between two textures |
||
218 | */ |
||
219 | extern void |
||
220 | st_texture_image_copy(struct pipe_context *pipe, |
||
221 | struct pipe_resource *dst, GLuint dstLevel, |
||
222 | struct pipe_resource *src, GLuint srcLevel, |
||
223 | GLuint face); |
||
224 | |||
225 | #endif |