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"
42 * Subclass of gl_texure_image.
44 struct st_texture_image
46 struct gl_texture_image base
;
48 /* These aren't stored in gl_texture_image
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.
57 struct pipe_resource
*pt
;
59 struct pipe_transfer
*transfer
;
64 * Subclass of gl_texure_object.
66 struct st_texture_object
68 struct gl_texture_object base
; /* The "parent" object */
70 /* The texture must include at levels [0..lastLevel] once validated:
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.
78 GLuint width0
, height0
, depth0
;
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.
83 struct pipe_resource
*pt
;
85 /* Default sampler view attached to this texture object. Created lazily
88 struct pipe_sampler_view
*sampler_view
;
90 /* True if there is/was a surface bound to this texture object. It helps
91 * track whether the texture object is surface based or not.
93 GLboolean surface_based
;
97 static INLINE
struct st_texture_image
*
98 st_texture_image(struct gl_texture_image
*img
)
100 return (struct st_texture_image
*) img
;
103 static INLINE
struct st_texture_object
*
104 st_texture_object(struct gl_texture_object
*obj
)
106 return (struct st_texture_object
*) obj
;
110 static INLINE
struct pipe_resource
*
111 st_get_texobj_resource(struct gl_texture_object
*texObj
)
113 struct st_texture_object
*stObj
= st_texture_object(texObj
);
114 return stObj
? stObj
->pt
: NULL
;
118 static INLINE
struct pipe_resource
*
119 st_get_stobj_resource(struct st_texture_object
*stObj
)
121 return stObj
? stObj
->pt
: NULL
;
125 static INLINE
struct pipe_sampler_view
*
126 st_create_texture_sampler_view(struct pipe_context
*pipe
,
127 struct pipe_resource
*texture
)
129 struct pipe_sampler_view templ
;
131 u_sampler_view_default_template(&templ
, texture
, texture
->format
);
133 return pipe
->create_sampler_view(pipe
, texture
, &templ
);
137 static INLINE
struct pipe_sampler_view
*
138 st_create_texture_sampler_view_format(struct pipe_context
*pipe
,
139 struct pipe_resource
*texture
,
140 enum pipe_format format
)
142 struct pipe_sampler_view templ
;
144 u_sampler_view_default_template(&templ
, texture
, format
);
146 return pipe
->create_sampler_view(pipe
, texture
, &templ
);
150 static INLINE
struct pipe_sampler_view
*
151 st_get_texture_sampler_view(struct st_texture_object
*stObj
,
152 struct pipe_context
*pipe
)
154 if (!stObj
|| !stObj
->pt
) {
158 if (!stObj
->sampler_view
) {
159 stObj
->sampler_view
= st_create_texture_sampler_view(pipe
, stObj
->pt
);
162 return stObj
->sampler_view
;
166 extern struct pipe_resource
*
167 st_texture_create(struct st_context
*st
,
168 enum pipe_texture_target target
,
169 enum pipe_format format
,
179 st_gl_texture_dims_to_pipe_dims(GLenum texture
,
188 /* Check if an image fits into an existing texture object.
191 st_texture_match_image(const struct pipe_resource
*pt
,
192 const struct gl_texture_image
*image
,
193 GLuint face
, GLuint level
);
195 /* Return a pointer to an image within a texture. Return image stride as
199 st_texture_image_map(struct st_context
*st
,
200 struct st_texture_image
*stImage
,
202 enum pipe_transfer_usage usage
,
203 unsigned x
, unsigned y
,
204 unsigned w
, unsigned h
);
207 st_texture_image_unmap(struct st_context
*st
,
208 struct st_texture_image
*stImage
);
211 /* Return pointers to each 2d slice within an image. Indexed by depth
214 extern const GLuint
*
215 st_texture_depth_offsets(struct pipe_resource
*pt
, GLuint level
);
218 /* Upload an image into a texture
221 st_texture_image_data(struct st_context
*st
,
222 struct pipe_resource
*dst
,
223 GLuint face
, GLuint level
, void *src
,
224 GLuint src_row_pitch
, GLuint src_image_pitch
);
227 /* Copy an image between two textures
230 st_texture_image_copy(struct pipe_context
*pipe
,
231 struct pipe_resource
*dst
, GLuint dstLevel
,
232 struct pipe_resource
*src
, GLuint srcLevel
,