1 #include "swrast/swrast.h"
2 #include "main/renderbuffer.h"
3 #include "main/texobj.h"
4 #include "main/teximage.h"
5 #include "main/mipmap.h"
6 #include "drivers/common/meta.h"
7 #include "intel_context.h"
8 #include "intel_mipmap_tree.h"
11 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
13 static struct gl_texture_image
*
14 intelNewTextureImage(struct gl_context
* ctx
)
16 DBG("%s\n", __FUNCTION__
);
18 return (struct gl_texture_image
*) CALLOC_STRUCT(intel_texture_image
);
22 intelDeleteTextureImage(struct gl_context
* ctx
, struct gl_texture_image
*img
)
24 /* nothing special (yet) for intel_texture_image */
25 _mesa_delete_texture_image(ctx
, img
);
29 static struct gl_texture_object
*
30 intelNewTextureObject(struct gl_context
* ctx
, GLuint name
, GLenum target
)
32 struct intel_texture_object
*obj
= CALLOC_STRUCT(intel_texture_object
);
36 DBG("%s\n", __FUNCTION__
);
37 _mesa_initialize_texture_object(&obj
->base
, name
, target
);
39 obj
->needs_validate
= true;
45 intelDeleteTextureObject(struct gl_context
*ctx
,
46 struct gl_texture_object
*texObj
)
48 struct intel_texture_object
*intelObj
= intel_texture_object(texObj
);
50 intel_miptree_release(&intelObj
->mt
);
51 _mesa_delete_texture_object(ctx
, texObj
);
55 intel_alloc_texture_image_buffer(struct gl_context
*ctx
,
56 struct gl_texture_image
*image
)
58 struct intel_context
*intel
= intel_context(ctx
);
59 struct intel_texture_image
*intel_image
= intel_texture_image(image
);
60 struct gl_texture_object
*texobj
= image
->TexObject
;
61 struct intel_texture_object
*intel_texobj
= intel_texture_object(texobj
);
64 assert(image
->Border
== 0);
66 /* Because the driver uses AllocTextureImageBuffer() internally, it may end
67 * up mismatched with FreeTextureImageBuffer(), but that is safe to call
70 ctx
->Driver
.FreeTextureImageBuffer(ctx
, image
);
72 /* Allocate the swrast_texture_image::ImageOffsets array now */
73 switch (texobj
->Target
) {
75 case GL_TEXTURE_2D_ARRAY
:
76 slices
= image
->Depth
;
78 case GL_TEXTURE_1D_ARRAY
:
79 slices
= image
->Height
;
84 assert(!intel_image
->base
.ImageOffsets
);
85 intel_image
->base
.ImageOffsets
= malloc(slices
* sizeof(GLuint
));
87 _swrast_init_texture_image(image
);
89 if (intel_texobj
->mt
&&
90 intel_miptree_match_image(intel_texobj
->mt
, image
)) {
91 intel_miptree_reference(&intel_image
->mt
, intel_texobj
->mt
);
92 DBG("%s: alloc obj %p level %d %dx%dx%d using object's miptree %p\n",
93 __FUNCTION__
, texobj
, image
->Level
,
94 image
->Width
, image
->Height
, image
->Depth
, intel_texobj
->mt
);
96 intel_image
->mt
= intel_miptree_create_for_teximage(intel
, intel_texobj
,
100 /* Even if the object currently has a mipmap tree associated
101 * with it, this one is a more likely candidate to represent the
102 * whole object since our level didn't fit what was there
103 * before, and any lower levels would fit into our miptree.
105 intel_miptree_reference(&intel_texobj
->mt
, intel_image
->mt
);
107 DBG("%s: alloc obj %p level %d %dx%dx%d using new miptree %p\n",
108 __FUNCTION__
, texobj
, image
->Level
,
109 image
->Width
, image
->Height
, image
->Depth
, intel_image
->mt
);
112 intel_texobj
->needs_validate
= true;
118 * Called via ctx->Driver.AllocTextureStorage()
119 * Just have to allocate memory for the texture images.
122 intel_alloc_texture_storage(struct gl_context
*ctx
,
123 struct gl_texture_object
*texObj
,
124 GLsizei levels
, GLsizei width
,
125 GLsizei height
, GLsizei depth
)
127 const int numFaces
= _mesa_num_tex_faces(texObj
->Target
);
131 for (face
= 0; face
< numFaces
; face
++) {
132 for (level
= 0; level
< levels
; level
++) {
133 struct gl_texture_image
*const texImage
= texObj
->Image
[face
][level
];
134 if (!intel_alloc_texture_image_buffer(ctx
, texImage
))
143 intel_free_texture_image_buffer(struct gl_context
* ctx
,
144 struct gl_texture_image
*texImage
)
146 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
148 DBG("%s\n", __FUNCTION__
);
150 intel_miptree_release(&intelImage
->mt
);
152 if (intelImage
->base
.Buffer
) {
153 _mesa_align_free(intelImage
->base
.Buffer
);
154 intelImage
->base
.Buffer
= NULL
;
157 free(intelImage
->base
.ImageOffsets
);
158 intelImage
->base
.ImageOffsets
= NULL
;
162 * Map texture memory/buffer into user space.
163 * Note: the region of interest parameters are ignored here.
164 * \param mode bitmask of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT
165 * \param mapOut returns start of mapping of region of interest
166 * \param rowStrideOut returns row stride in bytes
169 intel_map_texture_image(struct gl_context
*ctx
,
170 struct gl_texture_image
*tex_image
,
172 GLuint x
, GLuint y
, GLuint w
, GLuint h
,
177 struct intel_context
*intel
= intel_context(ctx
);
178 struct intel_texture_image
*intel_image
= intel_texture_image(tex_image
);
179 struct intel_mipmap_tree
*mt
= intel_image
->mt
;
181 /* Our texture data is always stored in a miptree. */
184 /* Check that our caller wasn't confused about how to map a 1D texture. */
185 assert(tex_image
->TexObject
->Target
!= GL_TEXTURE_1D_ARRAY
||
188 /* intel_miptree_map operates on a unified "slice" number that references the
189 * cube face, since it's all just slices to the miptree code.
191 if (tex_image
->TexObject
->Target
== GL_TEXTURE_CUBE_MAP
)
192 slice
= tex_image
->Face
;
194 intel_miptree_map(intel
, mt
, tex_image
->Level
, slice
, x
, y
, w
, h
, mode
,
195 (void **)map
, stride
);
199 intel_unmap_texture_image(struct gl_context
*ctx
,
200 struct gl_texture_image
*tex_image
, GLuint slice
)
202 struct intel_context
*intel
= intel_context(ctx
);
203 struct intel_texture_image
*intel_image
= intel_texture_image(tex_image
);
204 struct intel_mipmap_tree
*mt
= intel_image
->mt
;
206 if (tex_image
->TexObject
->Target
== GL_TEXTURE_CUBE_MAP
)
207 slice
= tex_image
->Face
;
209 intel_miptree_unmap(intel
, mt
, tex_image
->Level
, slice
);
213 intelInitTextureFuncs(struct dd_function_table
*functions
)
215 functions
->NewTextureObject
= intelNewTextureObject
;
216 functions
->NewTextureImage
= intelNewTextureImage
;
217 functions
->DeleteTextureImage
= intelDeleteTextureImage
;
218 functions
->DeleteTexture
= intelDeleteTextureObject
;
219 functions
->AllocTextureImageBuffer
= intel_alloc_texture_image_buffer
;
220 functions
->FreeTextureImageBuffer
= intel_free_texture_image_buffer
;
221 functions
->AllocTextureStorage
= intel_alloc_texture_storage
;
222 functions
->MapTextureImage
= intel_map_texture_image
;
223 functions
->UnmapTextureImage
= intel_unmap_texture_image
;