/** * Called via glArrayElement() and glDrawArrays(). * Issue the glNormal, glVertex, glColor, glVertexAttrib, etc functions * for all enabled vertex arrays (for elt-th element). * Note: this may be called during display list construction. */ void GLAPIENTRY _ae_loopback_array_elt( GLint elt ) { GET_CURRENT_CONTEXT(ctx); const AEcontext *actx = AE_CONTEXT(ctx); const AEarray *aa; const AEattrib *at; const struct _glapi_table * const disp = GET_DISPATCH(); if (actx->NewState) _ae_update_state( ctx ); /* generic attributes */ for (at = actx->attribs; at->func; at++) { const GLubyte *src = ADD_POINTERS(at->array->BufferObj->Data, at->array->Ptr) + elt * at->array->StrideB; at->func( at->index, src ); } /* conventional arrays */ for (aa = actx->arrays; aa->offset != -1 ; aa++) { const GLubyte *src = ADD_POINTERS(aa->array->BufferObj->Data, aa->array->Ptr) + elt * aa->array->StrideB; CALL_by_offset( disp, (array_func), aa->offset, ((const void *) src) ); } }
static void evergreenSetupIndexBuffer(GLcontext *ctx, const struct _mesa_index_buffer *mesa_ind_buf) { context_t *context = EVERGREEN_CONTEXT(ctx); if (!mesa_ind_buf) { context->ind_buf.bo = NULL; return; } #if MESA_BIG_ENDIAN if (mesa_ind_buf->type == GL_UNSIGNED_INT) #else if (mesa_ind_buf->type != GL_UNSIGNED_BYTE) #endif { const GLvoid *src_ptr; GLvoid *dst_ptr; GLboolean mapped_named_bo = GL_FALSE; if (mesa_ind_buf->obj->Name && !mesa_ind_buf->obj->Pointer) { ctx->Driver.MapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER, GL_READ_ONLY_ARB, mesa_ind_buf->obj); assert(mesa_ind_buf->obj->Pointer != NULL); mapped_named_bo = GL_TRUE; } src_ptr = ADD_POINTERS(mesa_ind_buf->obj->Pointer, mesa_ind_buf->ptr); const GLuint size = mesa_ind_buf->count * getTypeSize(mesa_ind_buf->type); radeonAllocDmaRegion(&context->radeon, &context->ind_buf.bo, &context->ind_buf.bo_offset, size, 4); radeon_bo_map(context->ind_buf.bo, 1); assert(context->ind_buf.bo->ptr != NULL); dst_ptr = ADD_POINTERS(context->ind_buf.bo->ptr, context->ind_buf.bo_offset); memcpy(dst_ptr, src_ptr, size); radeon_bo_unmap(context->ind_buf.bo); context->ind_buf.is_32bit = (mesa_ind_buf->type == GL_UNSIGNED_INT); context->ind_buf.count = mesa_ind_buf->count; if (mapped_named_bo) { ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER, mesa_ind_buf->obj); } } else { evergreenFixupIndexBuffer(ctx, mesa_ind_buf); } }
void GLAPIENTRY _mesa_GetPixelMapfv( GLenum map, GLfloat *values ) { GET_CURRENT_CONTEXT(ctx); GLuint mapsize, i; const struct gl_pixelmap *pm; ASSERT_OUTSIDE_BEGIN_END(ctx); pm = get_pixelmap(ctx, map); if (!pm) { _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelMapfv(map)"); return; } mapsize = pm->Size; if (ctx->Pack.BufferObj->Name) { /* pack pixelmap into PBO */ GLubyte *buf; /* Note, need to use DefaultPacking and Pack's buffer object */ ctx->DefaultPacking.BufferObj = ctx->Pack.BufferObj; if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1, GL_INTENSITY, GL_FLOAT, values)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glGetPixelMapfv(invalid PBO access)"); return; } /* restore */ ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj; buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, GL_WRITE_ONLY_ARB, ctx->Pack.BufferObj); if (!buf) { /* buffer is already mapped - that's an error */ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetPixelMapfv(PBO is mapped)"); return; } values = (GLfloat *) ADD_POINTERS(buf, values); } else if (!values) { return; } if (map == GL_PIXEL_MAP_S_TO_S) { /* special case */ for (i = 0; i < mapsize; i++) { values[i] = (GLfloat) ctx->PixelMaps.StoS.Map[i]; } } else { MEMCPY(values, pm->Map, mapsize * sizeof(GLfloat)); } if (ctx->Pack.BufferObj->Name) { ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, ctx->Pack.BufferObj); } }
/** * For commands that write to a PBO (glReadPixels, glGetColorTable, etc), * if we're writing to a PBO, map it write-only and return the pointer * into the PBO. If we're not writing to a PBO, return \p dst as-is. * If non-null return, must call _mesa_unmap_pbo_dest() when done. * * \return NULL if error, else pointer to start of data */ void * _mesa_map_pbo_dest(struct gl_context *ctx, const struct gl_pixelstore_attrib *pack, GLvoid *dest) { void *buf; if (_mesa_is_bufferobj(pack->BufferObj)) { /* pack into PBO */ buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, pack->BufferObj->Size, GL_MAP_WRITE_BIT, pack->BufferObj, MAP_INTERNAL); if (!buf) return NULL; buf = ADD_POINTERS(buf, dest); } else { /* pack to normal memory */ buf = dest; } return buf; }
/** * Check if an unpack PBO is active prior to fetching a texture image. * If so, do bounds checking and map the buffer into main memory. * Any errors detected will be recorded. * The caller _must_ call _mesa_unmap_teximage_pbo() too! */ const GLvoid * _mesa_validate_pbo_teximage(struct gl_context *ctx, GLuint dimensions, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const GLvoid *pixels, const struct gl_pixelstore_attrib *unpack, const char *funcName) { GLubyte *buf; if (!_mesa_is_bufferobj(unpack->BufferObj)) { /* no PBO */ return pixels; } if (!_mesa_validate_pbo_access(dimensions, unpack, width, height, depth, format, type, INT_MAX, pixels)) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s%uD(invalid PBO access)", funcName, dimensions); return NULL; } buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, unpack->BufferObj->Size, GL_MAP_READ_BIT, unpack->BufferObj, MAP_INTERNAL); if (!buf) { _mesa_error(ctx, GL_INVALID_OPERATION, "%s%uD(PBO is mapped)", funcName, dimensions); return NULL; } return ADD_POINTERS(buf, pixels); }
/** * Check if an unpack PBO is active prior to fetching a compressed texture * image. * If so, do bounds checking and map the buffer into main memory. * Any errors detected will be recorded. * The caller _must_ call _mesa_unmap_teximage_pbo() too! */ const GLvoid * _mesa_validate_pbo_compressed_teximage(struct gl_context *ctx, GLsizei imageSize, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, const char *funcName) { GLubyte *buf; if (!_mesa_is_bufferobj(packing->BufferObj)) { /* not using a PBO - return pointer unchanged */ return pixels; } if ((const GLubyte *) pixels + imageSize > ((const GLubyte *) 0) + packing->BufferObj->Size) { /* out of bounds read! */ _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(invalid PBO access)"); return NULL; } buf = (GLubyte*) ctx->Driver.MapBufferRange(ctx, 0, packing->BufferObj->Size, GL_MAP_READ_BIT, packing->BufferObj); if (!buf) { _mesa_error(ctx, GL_INVALID_OPERATION, funcName, "(PBO is mapped"); return NULL; } return ADD_POINTERS(buf, pixels); }
/* Unlike the other intel_pixel_* functions, the expectation here is * that the incoming data is not in a PBO. With the XY_TEXT blit * method, there's no benefit haveing it in a PBO, but we could * implement a path based on XY_MONO_SRC_COPY_BLIT which might benefit * PBO bitmaps. I think they are probably pretty rare though - I * wonder if Xgl uses them? */ static const GLubyte *map_pbo( struct gl_context *ctx, GLsizei width, GLsizei height, const struct gl_pixelstore_attrib *unpack, const GLubyte *bitmap ) { GLubyte *buf; if (!_mesa_validate_pbo_access(2, unpack, width, height, 1, GL_COLOR_INDEX, GL_BITMAP, INT_MAX, (const GLvoid *) bitmap)) { _mesa_error(ctx, GL_INVALID_OPERATION,"glBitmap(invalid PBO access)"); return NULL; } buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, unpack->BufferObj->Size, GL_MAP_READ_BIT, unpack->BufferObj, MAP_INTERNAL); if (!buf) { _mesa_error(ctx, GL_INVALID_OPERATION, "glBitmap(PBO is mapped)"); return NULL; } return ADD_POINTERS(buf, bitmap); }
/** * Check if an unpack PBO is active prior to fetching a compressed texture * image. * If so, do bounds checking and map the buffer into main memory. * Any errors detected will be recorded. * The caller _must_ call _mesa_unmap_teximage_pbo() too! */ const GLvoid * _mesa_validate_pbo_compressed_teximage(struct gl_context *ctx, GLuint dimensions, GLsizei imageSize, const GLvoid *pixels, const struct gl_pixelstore_attrib *packing, const char *funcName) { GLubyte *buf; if (!_mesa_validate_pbo_source_compressed(ctx, dimensions, packing, imageSize, pixels, funcName)) { /* error is already set during validation */ return NULL; } if (!_mesa_is_bufferobj(packing->BufferObj)) { /* not using a PBO - return pointer unchanged */ return pixels; } buf = (GLubyte*) ctx->Driver.MapBufferRange(ctx, 0, packing->BufferObj->Size, GL_MAP_READ_BIT, packing->BufferObj, MAP_INTERNAL); /* Validation above already checked that PBO is not mapped, so buffer * should not be null. */ assert(buf); return ADD_POINTERS(buf, pixels); }
/** * This is the software fallback for Driver.GetCompressedTexImage(). * All error checking will have been done before this routine is called. */ void _mesa_get_compressed_teximage(struct gl_context *ctx, struct gl_texture_image *texImage, GLvoid *img) { const GLuint row_stride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width); GLuint i; GLubyte *src; GLint srcRowStride; if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { /* pack texture image into a PBO */ GLubyte *buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, ctx->Pack.BufferObj->Size, GL_MAP_WRITE_BIT, ctx->Pack.BufferObj); if (!buf) { /* out of memory or other unexpected error */ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetCompresssedTexImage(map PBO failed)"); return; } img = ADD_POINTERS(buf, img); } /* map src texture buffer */ ctx->Driver.MapTextureImage(ctx, texImage, 0, 0, 0, texImage->Width, texImage->Height, GL_MAP_READ_BIT, &src, &srcRowStride); if (src) { /* no pixelstore or pixel transfer, but respect stride */ if (row_stride == srcRowStride) { const GLuint size = _mesa_format_image_size(texImage->TexFormat, texImage->Width, texImage->Height, texImage->Depth); memcpy(img, src, size); } else { GLuint bw, bh; _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh); for (i = 0; i < (texImage->Height + bh - 1) / bh; i++) { memcpy((GLubyte *)img + i * row_stride, (GLubyte *)src + i * srcRowStride, row_stride); } } ctx->Driver.UnmapTextureImage(ctx, texImage, 0); } else { _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetCompresssedTexImage"); } if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { ctx->Driver.UnmapBuffer(ctx, ctx->Pack.BufferObj); } }
/** * This is the software fallback for Driver.GetTexImage(). * All error checking will have been done before this routine is called. * We'll call ctx->Driver.MapTextureImage() to access the data, then * unmap with ctx->Driver.UnmapTextureImage(). */ void _mesa_get_teximage(struct gl_context *ctx, GLenum format, GLenum type, GLvoid *pixels, struct gl_texture_image *texImage) { GLuint dimensions; switch (texImage->TexObject->Target) { case GL_TEXTURE_1D: dimensions = 1; break; case GL_TEXTURE_3D: dimensions = 3; break; default: dimensions = 2; } /* map dest buffer, if PBO */ if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { /* Packing texture image into a PBO. * Map the (potentially) VRAM-based buffer into our process space so * we can write into it with the code below. * A hardware driver might use a sophisticated blit to move the * texture data to the PBO if the PBO is in VRAM along with the texture. */ GLubyte *buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, ctx->Pack.BufferObj->Size, GL_MAP_WRITE_BIT, ctx->Pack.BufferObj); if (!buf) { /* out of memory or other unexpected error */ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetTexImage(map PBO failed)"); return; } /* <pixels> was an offset into the PBO. * Now make it a real, client-side pointer inside the mapped region. */ pixels = ADD_POINTERS(buf, pixels); } if (get_tex_memcpy(ctx, format, type, pixels, texImage)) { /* all done */ } else if (format == GL_DEPTH_COMPONENT) { get_tex_depth(ctx, dimensions, format, type, pixels, texImage); } else if (format == GL_DEPTH_STENCIL_EXT) { get_tex_depth_stencil(ctx, dimensions, format, type, pixels, texImage); } else if (format == GL_YCBCR_MESA) { get_tex_ycbcr(ctx, dimensions, format, type, pixels, texImage); } else { get_tex_rgba(ctx, dimensions, format, type, pixels, texImage); } if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { ctx->Driver.UnmapBuffer(ctx, ctx->Pack.BufferObj); } }
static void GLAPIENTRY vbo_exec_DrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices) { GET_CURRENT_CONTEXT(ctx); GLuint min_index = 0; GLuint max_index = 0; if (!_mesa_validate_DrawElements( ctx, mode, count, type, indices )) return; if (!vbo_validate_shaders(ctx)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glDrawElements(bad shader)"); return; } if (ctx->Array.ElementArrayBufferObj->Name) { const GLvoid *map = ctx->Driver.MapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, GL_READ_ONLY, ctx->Array.ElementArrayBufferObj); get_minmax_index(count, type, ADD_POINTERS(map, indices), &min_index, &max_index); ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, ctx->Array.ElementArrayBufferObj); } else { get_minmax_index(count, type, indices, &min_index, &max_index); } vbo_exec_DrawRangeElements(mode, min_index, max_index, count, type, indices); }
static void vbo_bind_vertices(struct gl_context *ctx, const struct gl_client_array **arrays, int base, unsigned min_index, unsigned max_index, int *pdelta) { struct nouveau_render_state *render = to_render_state(ctx); struct nouveau_pushbuf *push = context_push(ctx); struct nouveau_bo *bo[NUM_VERTEX_ATTRS]; unsigned offset[NUM_VERTEX_ATTRS]; GLboolean dirty = GL_FALSE; int i, j, attr; RENDER_LOCALS(ctx); *pdelta = -1; FOR_EACH_BOUND_ATTR(render, i, attr) { const struct gl_client_array *array = arrays[attr]; struct gl_buffer_object *obj = array->BufferObj; struct nouveau_array *a = &render->attrs[attr]; unsigned delta = (base + min_index) * array->StrideB; bo[i] = NULL; if (nouveau_bufferobj_hw(obj)) { /* Array in a buffer obj. */ nouveau_bo_ref(to_nouveau_bufferobj(obj)->bo, &bo[i]); offset[i] = delta + (intptr_t)array->Ptr; } else { int n = max_index - min_index + 1; char *sp = (char *)ADD_POINTERS( nouveau_bufferobj_sys(obj), array->Ptr) + delta; char *dp = nouveau_get_scratch(ctx, n * a->stride, &bo[i], &offset[i]); /* Array in client memory, move it to a * scratch buffer obj. */ for (j = 0; j < n; j++) memcpy(dp + j * a->stride, sp + j * array->StrideB, a->stride); } dirty |= check_update_array(a, offset[i], bo[i], pdelta); } *pdelta -= min_index; if (dirty) { /* Buffers changed, update the attribute binding. */ FOR_EACH_BOUND_ATTR(render, i, attr) { struct nouveau_array *a = &render->attrs[attr]; nouveau_bo_ref(NULL, &a->bo); a->offset = offset[i]; a->bo = bo[i]; } TAG(render_release_vertices)(ctx); TAG(render_bind_vertices)(ctx); } else {
/** * For commands that read from a PBO (glDrawPixels, glTexImage, * glPolygonStipple, etc), if we're reading from a PBO, map it read-only * and return the pointer into the PBO. If we're not reading from a * PBO, return \p src as-is. * If non-null return, must call _mesa_unmap_pbo_source() when done. * * \return NULL if error, else pointer to start of data */ const GLvoid * _mesa_map_pbo_source(struct gl_context *ctx, const struct gl_pixelstore_attrib *unpack, const GLvoid *src) { const GLubyte *buf; if (_mesa_is_bufferobj(unpack->BufferObj)) { /* unpack from PBO */ buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, unpack->BufferObj->Size, GL_MAP_READ_BIT, unpack->BufferObj, MAP_INTERNAL); if (!buf) return NULL; buf = ADD_POINTERS(buf, src); } else { /* unpack from normal memory */ buf = src; } return buf; }
/* Could do better by copying the arrays and element list intact and * then emitting an indexed prim at runtime. */ static void GLAPIENTRY _save_OBE_DrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices) { GET_CURRENT_CONTEXT(ctx); struct vbo_save_context *save = &vbo_context(ctx)->save; struct gl_buffer_object *indexbuf = ctx->Array.VAO->IndexBufferObj; GLint i; if (!_mesa_is_valid_prim_mode(ctx, mode)) { _mesa_compile_error(ctx, GL_INVALID_ENUM, "glDrawElements(mode)"); return; } if (count < 0) { _mesa_compile_error(ctx, GL_INVALID_VALUE, "glDrawElements(count<0)"); return; } if (type != GL_UNSIGNED_BYTE && type != GL_UNSIGNED_SHORT && type != GL_UNSIGNED_INT) { _mesa_compile_error(ctx, GL_INVALID_VALUE, "glDrawElements(count<0)"); return; } if (save->out_of_memory) return; _ae_map_vbos(ctx); if (_mesa_is_bufferobj(indexbuf)) indices = ADD_POINTERS(indexbuf->Mappings[MAP_INTERNAL].Pointer, indices); vbo_save_NotifyBegin(ctx, (mode | VBO_SAVE_PRIM_WEAK | VBO_SAVE_PRIM_NO_CURRENT_UPDATE)); switch (type) { case GL_UNSIGNED_BYTE: for (i = 0; i < count; i++) CALL_ArrayElement(GET_DISPATCH(), (((GLubyte *) indices)[i])); break; case GL_UNSIGNED_SHORT: for (i = 0; i < count; i++) CALL_ArrayElement(GET_DISPATCH(), (((GLushort *) indices)[i])); break; case GL_UNSIGNED_INT: for (i = 0; i < count; i++) CALL_ArrayElement(GET_DISPATCH(), (((GLuint *) indices)[i])); break; default: _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)"); break; } CALL_End(GET_DISPATCH(), ()); _ae_unmap_vbos(ctx); }
void GLAPIENTRY _mesa_PixelMapfv( GLenum map, GLsizei mapsize, const GLfloat *values ) { GET_CURRENT_CONTEXT(ctx); ASSERT_OUTSIDE_BEGIN_END(ctx); /* XXX someday, test against ctx->Const.MaxPixelMapTableSize */ if (mapsize < 1 || mapsize > MAX_PIXEL_MAP_TABLE) { _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" ); return; } if (map >= GL_PIXEL_MAP_S_TO_S && map <= GL_PIXEL_MAP_I_TO_A) { /* test that mapsize is a power of two */ if (_mesa_bitcount((GLuint) mapsize) != 1) { _mesa_error( ctx, GL_INVALID_VALUE, "glPixelMapfv(mapsize)" ); return; } } FLUSH_VERTICES(ctx, _NEW_PIXEL); if (ctx->Unpack.BufferObj->Name) { /* unpack pixelmap from PBO */ GLubyte *buf; /* Note, need to use DefaultPacking and Unpack's buffer object */ ctx->DefaultPacking.BufferObj = ctx->Unpack.BufferObj; if (!_mesa_validate_pbo_access(1, &ctx->DefaultPacking, mapsize, 1, 1, GL_INTENSITY, GL_FLOAT, values)) { _mesa_error(ctx, GL_INVALID_OPERATION, "glPixelMapfv(invalid PBO access)"); return; } /* restore */ ctx->DefaultPacking.BufferObj = ctx->Array.NullBufferObj; buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, GL_READ_ONLY_ARB, ctx->Unpack.BufferObj); if (!buf) { /* buffer is already mapped - that's an error */ _mesa_error(ctx, GL_INVALID_OPERATION, "glPixelMapfv(PBO is mapped)"); return; } values = (const GLfloat *) ADD_POINTERS(buf, values); } else if (!values) { return; } store_pixelmap(ctx, map, mapsize, values); if (ctx->Unpack.BufferObj->Name) { ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, ctx->Unpack.BufferObj); } }
/* Translate indices to GLuints and store in VB->Elts. */ static void bind_indices( struct gl_context *ctx, const struct _mesa_index_buffer *ib, struct gl_buffer_object **bo, GLuint *nr_bo) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; GLuint i; const void *ptr; if (!ib) { VB->Elts = NULL; return; } if (_mesa_is_bufferobj(ib->obj) && !_mesa_bufferobj_mapped(ib->obj, MAP_INTERNAL)) { /* if the buffer object isn't mapped yet, map it now */ bo[*nr_bo] = ib->obj; (*nr_bo)++; ptr = ctx->Driver.MapBufferRange(ctx, (GLsizeiptr) ib->ptr, ib->count * vbo_sizeof_ib_type(ib->type), GL_MAP_READ_BIT, ib->obj, MAP_INTERNAL); assert(ib->obj->Mappings[MAP_INTERNAL].Pointer); } else { /* user-space elements, or buffer already mapped */ ptr = ADD_POINTERS(ib->obj->Mappings[MAP_INTERNAL].Pointer, ib->ptr); } if (ib->type == GL_UNSIGNED_INT && VB->Primitive[0].basevertex == 0) { VB->Elts = (GLuint *) ptr; } else { GLuint *elts = (GLuint *)get_space(ctx, ib->count * sizeof(GLuint)); VB->Elts = elts; if (ib->type == GL_UNSIGNED_INT) { const GLuint *in = (GLuint *)ptr; for (i = 0; i < ib->count; i++) *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } else if (ib->type == GL_UNSIGNED_SHORT) { const GLushort *in = (GLushort *)ptr; for (i = 0; i < ib->count; i++) *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } else { const GLubyte *in = (GLubyte *)ptr; for (i = 0; i < ib->count; i++) *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } } }
static void evergreenAlignDataToDword(GLcontext *ctx, const struct gl_client_array *input, int count, struct StreamDesc *attr) { context_t *context = EVERGREEN_CONTEXT(ctx); const int dst_stride = (input->StrideB + 3) & ~3; const int size = getTypeSize(input->Type) * input->Size * count; GLboolean mapped_named_bo = GL_FALSE; radeonAllocDmaRegion(&context->radeon, &attr->bo, &attr->bo_offset, size, 32); radeon_bo_map(attr->bo, 1); if (!input->BufferObj->Pointer) { ctx->Driver.MapBuffer(ctx, GL_ARRAY_BUFFER, GL_READ_ONLY_ARB, input->BufferObj); mapped_named_bo = GL_TRUE; } { GLvoid *src_ptr = ADD_POINTERS(input->BufferObj->Pointer, input->Ptr); GLvoid *dst_ptr = ADD_POINTERS(attr->bo->ptr, attr->bo_offset); int i; for (i = 0; i < count; ++i) { memcpy(dst_ptr, src_ptr, input->StrideB); src_ptr += input->StrideB; dst_ptr += dst_stride; } } radeon_bo_unmap(attr->bo); if (mapped_named_bo) { ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER, input->BufferObj); } attr->stride = dst_stride; }
/** * Called via glArrayElement() and glDrawArrays(). * Issue the glNormal, glVertex, glColor, glVertexAttrib, etc functions * for all enabled vertex arrays (for elt-th element). * Note: this may be called during display list construction. */ void GLAPIENTRY _ae_ArrayElement( GLint elt ) { GET_CURRENT_CONTEXT(ctx); const AEcontext *actx = AE_CONTEXT(ctx); const AEarray *aa; const AEattrib *at; const struct _glapi_table * const disp = GET_DISPATCH(); GLboolean do_map; if (actx->NewState) { assert(!actx->mapped_vbos); _ae_update_state( ctx ); } /* Determine if w need to map/unmap VBOs */ do_map = actx->nr_vbos && !actx->mapped_vbos; if (do_map) _ae_map_vbos(ctx); /* emit generic attribute elements */ for (at = actx->attribs; at->func; at++) { const GLubyte *src = ADD_POINTERS(at->array->BufferObj->Pointer, at->array->Ptr) + elt * at->array->StrideB; at->func( at->index, src ); } /* emit conventional arrays elements */ for (aa = actx->arrays; aa->offset != -1 ; aa++) { const GLubyte *src = ADD_POINTERS(aa->array->BufferObj->Pointer, aa->array->Ptr) + elt * aa->array->StrideB; CALL_by_offset( disp, (array_func), aa->offset, ((const void *) src) ); } if (do_map) _ae_unmap_vbos(ctx); }
/* Translate indices to GLuints and store in VB->Elts. */ static void bind_indices( struct gl_context *ctx, const struct _mesa_index_buffer *ib, struct gl_buffer_object **bo, GLuint *nr_bo) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; GLuint i; void *ptr; if (!ib) { VB->Elts = NULL; return; } if (ib->obj->Name && !ib->obj->Pointer) { bo[*nr_bo] = ib->obj; (*nr_bo)++; ctx->Driver.MapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER, GL_READ_ONLY_ARB, ib->obj); assert(ib->obj->Pointer); } ptr = ADD_POINTERS(ib->obj->Pointer, ib->ptr); if (ib->type == GL_UNSIGNED_INT && VB->Primitive[0].basevertex == 0) { VB->Elts = (GLuint *) ptr; } else { GLuint *elts = (GLuint *)get_space(ctx, ib->count * sizeof(GLuint)); VB->Elts = elts; if (ib->type == GL_UNSIGNED_INT) { const GLuint *in = (GLuint *)ptr; for (i = 0; i < ib->count; i++) *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } else if (ib->type == GL_UNSIGNED_SHORT) { const GLushort *in = (GLushort *)ptr; for (i = 0; i < ib->count; i++) *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } else { const GLubyte *in = (GLubyte *)ptr; for (i = 0; i < ib->count; i++) *elts++ = (GLuint)(*in++) + VB->Primitive[0].basevertex; } } }
static void r300AlignDataToDword(GLcontext *ctx, const struct gl_client_array *input, int count, struct vertex_attribute *attr) { r300ContextPtr r300 = R300_CONTEXT(ctx); const int dst_stride = (input->StrideB + 3) & ~3; const int size = getTypeSize(input->Type) * input->Size * count; GLboolean mapped_named_bo = GL_FALSE; radeonAllocDmaRegion(&r300->radeon, &attr->bo, &attr->bo_offset, size, 32); radeon_bo_map(attr->bo, 1); if (!input->BufferObj->Pointer) { ctx->Driver.MapBuffer(ctx, GL_ARRAY_BUFFER, GL_READ_ONLY_ARB, input->BufferObj); mapped_named_bo = GL_TRUE; } radeon_print(RADEON_FALLBACKS, RADEON_IMPORTANT, "%s. Vertex alignment doesn't match hw requirements.\n", __func__); { GLvoid *src_ptr = ADD_POINTERS(input->BufferObj->Pointer, input->Ptr); GLvoid *dst_ptr = ADD_POINTERS(attr->bo->ptr, attr->bo_offset); int i; for (i = 0; i < count; ++i) { memcpy(dst_ptr, src_ptr, input->StrideB); src_ptr += input->StrideB; dst_ptr += dst_stride; } } if (mapped_named_bo) { ctx->Driver.UnmapBuffer(ctx, GL_ARRAY_BUFFER, input->BufferObj); } radeon_bo_unmap(attr->bo); attr->stride = dst_stride; }
/** * This is the software fallback for Driver.GetCompressedTexImage(). * All error checking will have been done before this routine is called. */ void _mesa_get_compressed_teximage(GLcontext *ctx, GLenum target, GLint level, GLvoid *img, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { const GLuint row_stride = _mesa_format_row_stride(texImage->TexFormat, texImage->Width); const GLuint row_stride_stored = _mesa_format_row_stride(texImage->TexFormat, texImage->RowStride); GLuint i; if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { /* pack texture image into a PBO */ GLubyte *buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, GL_WRITE_ONLY_ARB, ctx->Pack.BufferObj); if (!buf) { /* out of memory or other unexpected error */ _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGetCompresssedTexImage(map PBO failed)"); return; } img = ADD_POINTERS(buf, img); } /* no pixelstore or pixel transfer, but respect stride */ if (row_stride == row_stride_stored) { const GLuint size = _mesa_format_image_size(texImage->TexFormat, texImage->Width, texImage->Height, texImage->Depth); _mesa_memcpy(img, texImage->Data, size); } else { GLuint bw, bh; _mesa_get_format_block_size(texImage->TexFormat, &bw, &bh); for (i = 0; i < (texImage->Height + bh - 1) / bh; i++) { memcpy((GLubyte *)img + i * row_stride, (GLubyte *)texImage->Data + i * row_stride_stored, row_stride); } } if (_mesa_is_bufferobj(ctx->Pack.BufferObj)) { ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, ctx->Pack.BufferObj); } }
/** * Examine the array's data for NaNs, etc. * For debug purposes; not normally used. */ static void check_draw_elements_data(struct gl_context *ctx, GLsizei count, GLenum elemType, const void *elements, GLint basevertex) { struct gl_array_object *arrayObj = ctx->Array.ArrayObj; const void *elemMap; GLint i, k; if (_mesa_is_bufferobj(ctx->Array.ArrayObj->ElementArrayBufferObj)) { elemMap = ctx->Driver.MapBufferRange(ctx, 0, ctx->Array.ArrayObj->ElementArrayBufferObj->Size, GL_MAP_READ_BIT, ctx->Array.ArrayObj->ElementArrayBufferObj); elements = ADD_POINTERS(elements, elemMap); } for (i = 0; i < count; i++) { GLuint j; /* j = element[i] */ switch (elemType) { case GL_UNSIGNED_BYTE: j = ((const GLubyte *) elements)[i]; break; case GL_UNSIGNED_SHORT: j = ((const GLushort *) elements)[i]; break; case GL_UNSIGNED_INT: j = ((const GLuint *) elements)[i]; break; default: assert(0); } /* check element j of each enabled array */ for (k = 0; k < Elements(arrayObj->VertexAttrib); k++) { check_array_data(ctx, &arrayObj->VertexAttrib[k], k, j); } } if (_mesa_is_bufferobj(arrayObj->ElementArrayBufferObj)) { ctx->Driver.UnmapBuffer(ctx, ctx->Array.ArrayObj->ElementArrayBufferObj); } for (k = 0; k < Elements(arrayObj->VertexAttrib); k++) { unmap_array_buffer(ctx, &arrayObj->VertexAttrib[k]); } }
/** * This is the software fallback for Driver.GetCompressedTexImage(). * All error checking will have been done before this routine is called. */ void _mesa_get_compressed_teximage(GLcontext *ctx, GLenum target, GLint level, GLvoid *img, struct gl_texture_object *texObj, struct gl_texture_image *texImage) { GLuint size; if (ctx->Pack.BufferObj->Name) { /* pack texture image into a PBO */ GLubyte *buf; if ((const GLubyte *) img + texImage->CompressedSize > (const GLubyte *) ctx->Pack.BufferObj->Size) { _mesa_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImage(invalid PBO access)"); return; } buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, GL_WRITE_ONLY_ARB, ctx->Pack.BufferObj); if (!buf) { /* buffer is already mapped - that's an error */ _mesa_error(ctx, GL_INVALID_OPERATION, "glGetCompressedTexImage(PBO is mapped)"); return; } img = ADD_POINTERS(buf, img); } else if (!img) { /* not an error */ return; } /* don't use texImage->CompressedSize since that may be padded out */ size = _mesa_compressed_texture_size(ctx, texImage->Width, texImage->Height, texImage->Depth, texImage->TexFormat->MesaFormat); /* just memcpy, no pixelstore or pixel transfer */ _mesa_memcpy(img, texImage->Data, size); if (ctx->Pack.BufferObj->Name) { ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, ctx->Pack.BufferObj); } }
/* Could do better by copying the arrays and element list intact and * then emitting an indexed prim at runtime. */ static void GLAPIENTRY _save_OBE_DrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid * indices) { GET_CURRENT_CONTEXT(ctx); struct vbo_save_context *save = &vbo_context(ctx)->save; GLint i; if (!_mesa_validate_DrawElements(ctx, mode, count, type, indices, 0)) return; if (save->out_of_memory) return; _ae_map_vbos(ctx); if (_mesa_is_bufferobj(ctx->Array.ArrayObj->ElementArrayBufferObj)) indices = ADD_POINTERS(ctx->Array.ArrayObj->ElementArrayBufferObj->Pointer, indices); vbo_save_NotifyBegin(ctx, (mode | VBO_SAVE_PRIM_WEAK | VBO_SAVE_PRIM_NO_CURRENT_UPDATE)); switch (type) { case GL_UNSIGNED_BYTE: for (i = 0; i < count; i++) CALL_ArrayElement(GET_DISPATCH(), (((GLubyte *) indices)[i])); break; case GL_UNSIGNED_SHORT: for (i = 0; i < count; i++) CALL_ArrayElement(GET_DISPATCH(), (((GLushort *) indices)[i])); break; case GL_UNSIGNED_INT: for (i = 0; i < count; i++) CALL_ArrayElement(GET_DISPATCH(), (((GLuint *) indices)[i])); break; default: _mesa_error(ctx, GL_INVALID_ENUM, "glDrawElements(type)"); break; } CALL_End(GET_DISPATCH(), ()); _ae_unmap_vbos(ctx); }
/** * Check that element 'j' of the array has reasonable data. * Map VBO if needed. * For debugging purposes; not normally used. */ static void check_array_data(struct gl_context *ctx, struct gl_client_array *array, GLuint attrib, GLuint j) { if (array->Enabled) { const void *data = array->Ptr; if (_mesa_is_bufferobj(array->BufferObj)) { if (!array->BufferObj->Pointer) { /* need to map now */ array->BufferObj->Pointer = ctx->Driver.MapBufferRange(ctx, 0, array->BufferObj->Size, GL_MAP_READ_BIT, array->BufferObj); } data = ADD_POINTERS(data, array->BufferObj->Pointer); } switch (array->Type) { case GL_FLOAT: { GLfloat *f = (GLfloat *) ((GLubyte *) data + array->StrideB * j); GLint k; for (k = 0; k < array->Size; k++) { if (IS_INF_OR_NAN(f[k]) || f[k] >= 1.0e20 || f[k] <= -1.0e10) { printf("Bad array data:\n"); printf(" Element[%u].%u = %f\n", j, k, f[k]); printf(" Array %u at %p\n", attrib, (void* ) array); printf(" Type 0x%x, Size %d, Stride %d\n", array->Type, array->Size, array->Stride); printf(" Address/offset %p in Buffer Object %u\n", array->Ptr, array->BufferObj->Name); f[k] = 1.0; /* XXX replace the bad value! */ } /*assert(!IS_INF_OR_NAN(f[k]));*/ } } break; default: ; } } }
/** * Find the max index in the given element/index buffer */ GLuint _mesa_max_buffer_index(struct gl_context *ctx, GLuint count, GLenum type, const void *indices, struct gl_buffer_object *elementBuf) { const GLubyte *map = NULL; GLuint max = 0; GLuint i; if (_mesa_is_bufferobj(elementBuf)) { /* elements are in a user-defined buffer object. need to map it */ map = ctx->Driver.MapBufferRange(ctx, 0, elementBuf->Size, GL_MAP_READ_BIT, elementBuf); /* Actual address is the sum of pointers */ indices = (const GLvoid *) ADD_POINTERS(map, (const GLubyte *) indices); } if (type == GL_UNSIGNED_INT) { for (i = 0; i < count; i++) if (((GLuint *) indices)[i] > max) max = ((GLuint *) indices)[i]; } else if (type == GL_UNSIGNED_SHORT) { for (i = 0; i < count; i++) if (((GLushort *) indices)[i] > max) max = ((GLushort *) indices)[i]; } else { ASSERT(type == GL_UNSIGNED_BYTE); for (i = 0; i < count; i++) if (((GLubyte *) indices)[i] > max) max = ((GLubyte *) indices)[i]; } if (map) { ctx->Driver.UnmapBuffer(ctx, elementBuf); } return max; }
/** * Find the max index in the given element/index buffer */ static GLuint max_buffer_index(GLcontext *ctx, GLuint count, GLenum type, const void *indices, struct gl_buffer_object *elementBuf) { const GLubyte *map = NULL; GLuint max = 0; GLuint i; if (elementBuf->Name) { /* elements are in a user-defined buffer object. need to map it */ map = ctx->Driver.MapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER, GL_READ_ONLY, elementBuf); /* Actual address is the sum of pointers */ indices = (const GLvoid *) ADD_POINTERS(map, (const GLubyte *) indices); } if (type == GL_UNSIGNED_INT) { for (i = 0; i < count; i++) if (((GLuint *) indices)[i] > max) max = ((GLuint *) indices)[i]; } else if (type == GL_UNSIGNED_SHORT) { for (i = 0; i < count; i++) if (((GLushort *) indices)[i] > max) max = ((GLushort *) indices)[i]; } else { ASSERT(type == GL_UNSIGNED_BYTE); for (i = 0; i < count; i++) if (((GLubyte *) indices)[i] > max) max = ((GLubyte *) indices)[i]; } if (map) { ctx->Driver.UnmapBuffer(ctx, GL_ELEMENT_ARRAY_BUFFER_ARB, elementBuf); } return max; }
void nouveau_init_array(struct nouveau_array *a, int attr, int stride, int fields, int type, struct gl_buffer_object *obj, const void *ptr, GLboolean map) { a->attr = attr; a->stride = stride; a->fields = fields; a->type = type; a->buf = NULL; if (obj) { if (nouveau_bufferobj_hw(obj)) { struct nouveau_bufferobj *nbo = to_nouveau_bufferobj(obj); nouveau_bo_ref(nbo->bo, &a->bo); a->offset = (intptr_t)ptr; if (map) { nouveau_bo_map(a->bo, NOUVEAU_BO_RD); a->buf = a->bo->map + a->offset; } } else { nouveau_bo_ref(NULL, &a->bo); a->offset = 0; if (map) a->buf = ADD_POINTERS( nouveau_bufferobj_sys(obj), ptr); } } if (a->buf) get_array_extract(a, &a->extract_u, &a->extract_f); }
/** * If PBO is bound, map the buffer, return dest pointer in mapped buffer. * Call _mesa_unmap_readpix_pbo() when finished * \return NULL if error */ void * _mesa_map_readpix_pbo(GLcontext *ctx, const struct gl_pixelstore_attrib *pack, GLvoid *dest) { void *buf; if (pack->BufferObj->Name) { /* pack into PBO */ buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, GL_WRITE_ONLY_ARB, pack->BufferObj); if (!buf) return NULL; buf = ADD_POINTERS(buf, dest); } else { /* pack to normal memory */ buf = dest; } return buf; }
/** * \sa _mesa_map_bitmap_pbo */ const GLvoid * _mesa_map_drawpix_pbo(GLcontext *ctx, const struct gl_pixelstore_attrib *unpack, const GLvoid *pixels) { const GLvoid *buf; if (unpack->BufferObj->Name) { /* unpack from PBO */ buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, GL_READ_ONLY_ARB, unpack->BufferObj); if (!buf) return NULL; buf = ADD_POINTERS(buf, pixels); } else { /* unpack from normal memory */ buf = pixels; } return buf; }