1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
32 #include "pipe/p_context.h"
33 #include "util/u_sampler.h"
35 #include "main/mtypes.h"
41 struct st_texture_image
43 struct gl_texture_image base
;
45 /* These aren't stored in gl_texture_image
50 /* If stImage->pt != NULL, image data is stored here.
51 * Else if stImage->base.Data != NULL, image is stored there.
52 * Else there is no image data.
54 struct pipe_resource
*pt
;
56 struct pipe_transfer
*transfer
;
61 struct st_texture_object
63 struct gl_texture_object base
; /* The "parent" object */
65 /* The texture must include at levels [0..lastLevel] once validated:
69 /* On validation any active images held in main memory or in other
70 * textures will be copied to this texture and the old storage freed.
72 struct pipe_resource
*pt
;
74 /* Default sampler view attached to this texture object. Created lazily
77 struct pipe_sampler_view
*sampler_view
;
79 GLboolean teximage_realloc
;
81 /* True if there is/was a surface bound to this texture object. It helps
82 * track whether the texture object is surface based or not.
84 GLboolean surface_based
;
88 static INLINE
struct st_texture_image
*
89 st_texture_image(struct gl_texture_image
*img
)
91 return (struct st_texture_image
*) img
;
94 static INLINE
struct st_texture_object
*
95 st_texture_object(struct gl_texture_object
*obj
)
97 return (struct st_texture_object
*) obj
;
101 static INLINE
struct pipe_resource
*
102 st_get_texobj_texture(struct gl_texture_object
*texObj
)
104 struct st_texture_object
*stObj
= st_texture_object(texObj
);
105 return stObj
? stObj
->pt
: NULL
;
109 static INLINE
struct pipe_resource
*
110 st_get_stobj_texture(struct st_texture_object
*stObj
)
112 return stObj
? stObj
->pt
: NULL
;
116 static INLINE
struct pipe_sampler_view
*
117 st_create_texture_sampler_view(struct pipe_context
*pipe
,
118 struct pipe_resource
*texture
)
120 struct pipe_sampler_view templ
;
122 u_sampler_view_default_template(&templ
,
126 return pipe
->create_sampler_view(pipe
, texture
, &templ
);
130 static INLINE
struct pipe_sampler_view
*
131 st_get_texture_sampler_view(struct st_texture_object
*stObj
,
132 struct pipe_context
*pipe
)
135 if (!stObj
|| !stObj
->pt
) {
139 if (!stObj
->sampler_view
) {
140 stObj
->sampler_view
= st_create_texture_sampler_view(pipe
, stObj
->pt
);
143 return stObj
->sampler_view
;
147 extern struct pipe_resource
*
148 st_texture_create(struct st_context
*st
,
149 enum pipe_texture_target target
,
150 enum pipe_format format
,
158 /* Check if an image fits into an existing texture object.
161 st_texture_match_image(const struct pipe_resource
*pt
,
162 const struct gl_texture_image
*image
,
163 GLuint face
, GLuint level
);
165 /* Return a pointer to an image within a texture. Return image stride as
169 st_texture_image_map(struct st_context
*st
,
170 struct st_texture_image
*stImage
,
172 enum pipe_transfer_usage usage
,
173 unsigned x
, unsigned y
,
174 unsigned w
, unsigned h
);
177 st_texture_image_unmap(struct st_context
*st
,
178 struct st_texture_image
*stImage
);
181 /* Return pointers to each 2d slice within an image. Indexed by depth
184 extern const GLuint
*
185 st_texture_depth_offsets(struct pipe_resource
*pt
, GLuint level
);
188 /* Return the linear offset of an image relative to the start of its region.
191 st_texture_image_offset(const struct pipe_resource
*pt
,
192 GLuint face
, GLuint level
);
195 st_texture_texel_offset(const struct pipe_resource
* pt
,
196 GLuint face
, GLuint level
,
197 GLuint col
, GLuint row
, GLuint img
);
200 /* Upload an image into a texture
203 st_texture_image_data(struct st_context
*st
,
204 struct pipe_resource
*dst
,
205 GLuint face
, GLuint level
, void *src
,
206 GLuint src_row_pitch
, GLuint src_image_pitch
);
209 /* Copy an image between two textures
212 st_texture_image_copy(struct pipe_context
*pipe
,
213 struct pipe_resource
*dst
, GLuint dstLevel
,
214 struct pipe_resource
*src
,
218 st_teximage_flush_before_map(struct st_context
*st
,
219 struct pipe_resource
*pt
,
222 enum pipe_transfer_usage usage
);