Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 1
/**************************************************************************
2
 *
3
 * Copyright 2007 VMware, Inc.
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 VMWARE 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
struct st_texture_image_transfer {
42
   struct pipe_transfer *transfer;
43
 
44
   /* For ETC fallback. */
45
   GLubyte *temp_data; /**< Temporary ETC texture storage. */
46
   unsigned temp_stride; /**< Stride of the ETC texture storage. */
47
   GLubyte *map; /**< Saved map pointer of the uncompressed transfer. */
48
};
49
 
50
 
51
/**
52
 * Subclass of gl_texure_image.
53
 */
54
struct st_texture_image
55
{
56
   struct gl_texture_image base;
57
 
58
   /* If stImage->pt != NULL, image data is stored here.
59
    * Else there is no image data.
60
    */
61
   struct pipe_resource *pt;
62
 
63
   /* List of transfers, allocated on demand.
64
    * transfer[layer] is a mapping for that layer.
65
    */
66
   struct st_texture_image_transfer *transfer;
67
   unsigned num_transfers;
68
};
69
 
70
 
71
/**
72
 * Subclass of gl_texure_object.
73
 */
74
struct st_texture_object
75
{
76
   struct gl_texture_object base;       /* The "parent" object */
77
 
78
   /* The texture must include at levels [0..lastLevel] once validated:
79
    */
80
   GLuint lastLevel;
81
 
82
   /** The size of the level=0 mipmap image.
83
    * Note that the number of 1D array layers will be in height0 and the
84
    * number of 2D array layers will be in depth0, as in GL.
85
    */
86
   GLuint width0, height0, depth0;
87
 
88
   /* On validation any active images held in main memory or in other
89
    * textures will be copied to this texture and the old storage freed.
90
    */
91
   struct pipe_resource *pt;
92
 
93
   /* Number of views in sampler_views array */
94
   GLuint num_sampler_views;
95
 
96
   /* Array of sampler views (one per context) attached to this texture
97
    * object. Created lazily on first binding in context.
98
    */
99
   struct pipe_sampler_view **sampler_views;
100
 
101
   /* True if this texture comes from the window system. Such a texture
102
    * cannot be reallocated and the format can only be changed with a sampler
103
    * view or a surface.
104
    */
105
   GLboolean surface_based;
106
 
107
   /* If surface_based is true, this format should be used for all sampler
108
    * views and surfaces instead of pt->format.
109
    */
110
   enum pipe_format surface_format;
111
};
112
 
113
 
114
static inline struct st_texture_image *
115
st_texture_image(struct gl_texture_image *img)
116
{
117
   return (struct st_texture_image *) img;
118
}
119
 
120
static inline const struct st_texture_image *
121
st_texture_image_const(const struct gl_texture_image *img)
122
{
123
   return (const struct st_texture_image *) img;
124
}
125
 
126
static inline struct st_texture_object *
127
st_texture_object(struct gl_texture_object *obj)
128
{
129
   return (struct st_texture_object *) obj;
130
}
131
 
132
static inline const struct st_texture_object *
133
st_texture_object_const(const struct gl_texture_object *obj)
134
{
135
   return (const struct st_texture_object *) obj;
136
}
137
 
138
 
139
static inline struct pipe_resource *
140
st_get_texobj_resource(struct gl_texture_object *texObj)
141
{
142
   struct st_texture_object *stObj = st_texture_object(texObj);
143
   return stObj ? stObj->pt : NULL;
144
}
145
 
146
 
147
static inline struct pipe_resource *
148
st_get_stobj_resource(struct st_texture_object *stObj)
149
{
150
   return stObj ? stObj->pt : NULL;
151
}
152
 
153
 
154
static inline struct pipe_sampler_view *
155
st_create_texture_sampler_view_format(struct pipe_context *pipe,
156
                                      struct pipe_resource *texture,
157
                                      enum pipe_format format)
158
{
159
   struct pipe_sampler_view templ;
160
 
161
   u_sampler_view_default_template(&templ, texture, format);
162
 
163
   return pipe->create_sampler_view(pipe, texture, &templ);
164
}
165
 
166
static inline struct pipe_sampler_view *
167
st_create_texture_sampler_view(struct pipe_context *pipe,
168
                               struct pipe_resource *texture)
169
{
170
   return st_create_texture_sampler_view_format(pipe, texture,
171
                                                texture->format);
172
}
173
 
174
 
175
 
176
extern struct pipe_resource *
177
st_texture_create(struct st_context *st,
178
                  enum pipe_texture_target target,
179
		  enum pipe_format format,
180
                  GLuint last_level,
181
                  GLuint width0,
182
                  GLuint height0,
183
                  GLuint depth0,
184
                  GLuint layers,
185
                  GLuint nr_samples,
186
                  GLuint tex_usage );
187
 
188
 
189
extern void
190
st_gl_texture_dims_to_pipe_dims(GLenum texture,
191
                                GLuint widthIn,
192
                                GLuint heightIn,
193
                                GLuint depthIn,
194
                                GLuint *widthOut,
195
                                GLuint *heightOut,
196
                                GLuint *depthOut,
197
                                GLuint *layersOut);
198
 
199
/* Check if an image fits into an existing texture object.
200
 */
201
extern GLboolean
202
st_texture_match_image(struct st_context *st,
203
                       const struct pipe_resource *pt,
204
                       const struct gl_texture_image *image);
205
 
206
/* Return a pointer to an image within a texture.  Return image stride as
207
 * well.
208
 */
209
extern GLubyte *
210
st_texture_image_map(struct st_context *st, struct st_texture_image *stImage,
211
                     enum pipe_transfer_usage usage,
212
                     GLuint x, GLuint y, GLuint z,
213
                     GLuint w, GLuint h, GLuint d,
214
                     struct pipe_transfer **transfer);
215
 
216
extern void
217
st_texture_image_unmap(struct st_context *st,
218
                       struct st_texture_image *stImage, unsigned slice);
219
 
220
 
221
/* Return pointers to each 2d slice within an image.  Indexed by depth
222
 * value.
223
 */
224
extern const GLuint *
225
st_texture_depth_offsets(struct pipe_resource *pt, GLuint level);
226
 
227
/* Copy an image between two textures
228
 */
229
extern void
230
st_texture_image_copy(struct pipe_context *pipe,
231
                      struct pipe_resource *dst, GLuint dstLevel,
232
                      struct pipe_resource *src, GLuint srcLevel,
233
                      GLuint face);
234
 
235
 
236
extern struct pipe_resource *
237
st_create_color_map_texture(struct gl_context *ctx);
238
 
239
extern struct pipe_sampler_view **
240
st_texture_get_sampler_view(struct st_context *st,
241
                            struct st_texture_object *stObj);
242
 
243
extern void
244
st_texture_release_sampler_view(struct st_context *st,
245
                                struct st_texture_object *stObj);
246
 
247
extern void
248
st_texture_release_all_sampler_views(struct st_context *st,
249
                                     struct st_texture_object *stObj);
250
 
251
void
252
st_texture_free_sampler_views(struct st_texture_object *stObj);
253
 
254
#endif