intel/fake_bufmgr: Attempt to restrict references to objects in a batchbuffer > apert...
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex_subimage.c
1
2 /**************************************************************************
3 *
4 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29 #include "mtypes.h"
30 #include "texobj.h"
31 #include "texstore.h"
32 #include "enums.h"
33
34 #include "intel_context.h"
35 #include "intel_tex.h"
36 #include "intel_mipmap_tree.h"
37
38 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
39
40 static void
41 intelTexSubimage(GLcontext * ctx,
42 GLint dims,
43 GLenum target, GLint level,
44 GLint xoffset, GLint yoffset, GLint zoffset,
45 GLint width, GLint height, GLint depth,
46 GLenum format, GLenum type, const void *pixels,
47 const struct gl_pixelstore_attrib *packing,
48 struct gl_texture_object *texObj,
49 struct gl_texture_image *texImage)
50 {
51 struct intel_context *intel = intel_context(ctx);
52 struct intel_texture_image *intelImage = intel_texture_image(texImage);
53 GLuint dstRowStride = 0;
54
55 DBG("%s target %s level %d offset %d,%d %dx%d\n", __FUNCTION__,
56 _mesa_lookup_enum_by_nr(target),
57 level, xoffset, yoffset, width, height);
58
59 intelFlush(ctx);
60
61 pixels =
62 _mesa_validate_pbo_teximage(ctx, dims, width, height, depth, format,
63 type, pixels, packing, "glTexSubImage2D");
64 if (!pixels)
65 return;
66
67 LOCK_HARDWARE(intel);
68
69 /* Map buffer if necessary. Need to lock to prevent other contexts
70 * from uploading the buffer under us.
71 */
72 if (intelImage->mt)
73 texImage->Data = intel_miptree_image_map(intel,
74 intelImage->mt,
75 intelImage->face,
76 intelImage->level,
77 &dstRowStride,
78 texImage->ImageOffsets);
79 else {
80 if (texImage->IsCompressed) {
81 dstRowStride =
82 _mesa_compressed_row_stride(texImage->TexFormat->MesaFormat, width);
83 assert(dims != 3);
84 }
85 else {
86 dstRowStride = texImage->RowStride * texImage->TexFormat->TexelBytes;
87 }
88 }
89
90 assert(dstRowStride);
91
92 if (!texImage->TexFormat->StoreImage(ctx, dims, texImage->_BaseFormat,
93 texImage->TexFormat,
94 texImage->Data,
95 xoffset, yoffset, zoffset,
96 dstRowStride,
97 texImage->ImageOffsets,
98 width, height, depth,
99 format, type, pixels, packing)) {
100 _mesa_error(ctx, GL_OUT_OF_MEMORY, "intelTexSubImage");
101 }
102
103 /* GL_SGIS_generate_mipmap */
104 if (level == texObj->BaseLevel && texObj->GenerateMipmap) {
105 intel_generate_mipmap(ctx, target,
106 &ctx->Texture.Unit[ctx->Texture.CurrentUnit],
107 texObj);
108 }
109
110 _mesa_unmap_teximage_pbo(ctx, packing);
111
112 if (intelImage->mt) {
113 intel_miptree_image_unmap(intel, intelImage->mt);
114 texImage->Data = NULL;
115 }
116
117 UNLOCK_HARDWARE(intel);
118 }
119
120
121
122
123
124 void
125 intelTexSubImage3D(GLcontext * ctx,
126 GLenum target,
127 GLint level,
128 GLint xoffset, GLint yoffset, GLint zoffset,
129 GLsizei width, GLsizei height, GLsizei depth,
130 GLenum format, GLenum type,
131 const GLvoid * pixels,
132 const struct gl_pixelstore_attrib *packing,
133 struct gl_texture_object *texObj,
134 struct gl_texture_image *texImage)
135 {
136
137 intelTexSubimage(ctx, 3,
138 target, level,
139 xoffset, yoffset, zoffset,
140 width, height, depth,
141 format, type, pixels, packing, texObj, texImage);
142
143 }
144
145
146
147 void
148 intelTexSubImage2D(GLcontext * ctx,
149 GLenum target,
150 GLint level,
151 GLint xoffset, GLint yoffset,
152 GLsizei width, GLsizei height,
153 GLenum format, GLenum type,
154 const GLvoid * pixels,
155 const struct gl_pixelstore_attrib *packing,
156 struct gl_texture_object *texObj,
157 struct gl_texture_image *texImage)
158 {
159
160 intelTexSubimage(ctx, 2,
161 target, level,
162 xoffset, yoffset, 0,
163 width, height, 1,
164 format, type, pixels, packing, texObj, texImage);
165
166 }
167
168
169 void
170 intelTexSubImage1D(GLcontext * ctx,
171 GLenum target,
172 GLint level,
173 GLint xoffset,
174 GLsizei width,
175 GLenum format, GLenum type,
176 const GLvoid * pixels,
177 const struct gl_pixelstore_attrib *packing,
178 struct gl_texture_object *texObj,
179 struct gl_texture_image *texImage)
180 {
181 intelTexSubimage(ctx, 1,
182 target, level,
183 xoffset, 0, 0,
184 width, 1, 1,
185 format, type, pixels, packing, texObj, texImage);
186
187 }