mesa: consolidate code in _mesa_update_array_max_element()
This commit is contained in:
@@ -50,6 +50,7 @@
|
|||||||
#include "arrayobj.h"
|
#include "arrayobj.h"
|
||||||
#include "macros.h"
|
#include "macros.h"
|
||||||
#include "mtypes.h"
|
#include "mtypes.h"
|
||||||
|
#include "varray.h"
|
||||||
#include "main/dispatch.h"
|
#include "main/dispatch.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -279,37 +280,6 @@ remove_array_object( struct gl_context *ctx, struct gl_array_object *obj )
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compute the index of the last array element that can be safely accessed
|
|
||||||
* in a vertex array. We can really only do this when the array lives in
|
|
||||||
* a VBO.
|
|
||||||
* The array->_MaxElement field will be updated.
|
|
||||||
* Later in glDrawArrays/Elements/etc we can do some bounds checking.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
compute_max_element(struct gl_client_array *array)
|
|
||||||
{
|
|
||||||
if (array->BufferObj->Name) {
|
|
||||||
/* Compute the max element we can access in the VBO without going
|
|
||||||
* out of bounds.
|
|
||||||
*/
|
|
||||||
array->_MaxElement = ((GLsizeiptrARB) array->BufferObj->Size
|
|
||||||
- (GLsizeiptrARB) array->Ptr + array->StrideB
|
|
||||||
- array->_ElementSize) / array->StrideB;
|
|
||||||
if (0)
|
|
||||||
printf("%s Object %u Size %u MaxElement %u\n",
|
|
||||||
__FUNCTION__,
|
|
||||||
array->BufferObj->Name,
|
|
||||||
(GLuint) array->BufferObj->Size,
|
|
||||||
array->_MaxElement);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* user-space array, no idea how big it is */
|
|
||||||
array->_MaxElement = 2 * 1000 * 1000 * 1000; /* just a big number */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for update_arrays().
|
* Helper for update_arrays().
|
||||||
* \return min(current min, array->_MaxElement).
|
* \return min(current min, array->_MaxElement).
|
||||||
@@ -317,7 +287,7 @@ compute_max_element(struct gl_client_array *array)
|
|||||||
static GLuint
|
static GLuint
|
||||||
update_min(GLuint min, struct gl_client_array *array)
|
update_min(GLuint min, struct gl_client_array *array)
|
||||||
{
|
{
|
||||||
compute_max_element(array);
|
_mesa_update_array_max_element(array);
|
||||||
if (array->Enabled)
|
if (array->Enabled)
|
||||||
return MIN2(min, array->_MaxElement);
|
return MIN2(min, array->_MaxElement);
|
||||||
else
|
else
|
||||||
|
@@ -48,6 +48,7 @@
|
|||||||
#include "texenvprogram.h"
|
#include "texenvprogram.h"
|
||||||
#include "texobj.h"
|
#include "texobj.h"
|
||||||
#include "texstate.h"
|
#include "texstate.h"
|
||||||
|
#include "varray.h"
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -60,36 +61,6 @@ update_separate_specular(struct gl_context *ctx)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Compute the index of the last array element that can be safely accessed
|
|
||||||
* in a vertex array. We can really only do this when the array lives in
|
|
||||||
* a VBO.
|
|
||||||
* The array->_MaxElement field will be updated.
|
|
||||||
* Later in glDrawArrays/Elements/etc we can do some bounds checking.
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
compute_max_element(struct gl_client_array *array)
|
|
||||||
{
|
|
||||||
assert(array->Enabled);
|
|
||||||
if (array->BufferObj->Name) {
|
|
||||||
GLsizeiptrARB offset = (GLsizeiptrARB) array->Ptr;
|
|
||||||
GLsizeiptrARB obj_size = (GLsizeiptrARB) array->BufferObj->Size;
|
|
||||||
|
|
||||||
if (offset < obj_size) {
|
|
||||||
array->_MaxElement = (obj_size - offset +
|
|
||||||
array->StrideB -
|
|
||||||
array->_ElementSize) / array->StrideB;
|
|
||||||
} else {
|
|
||||||
array->_MaxElement = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* user-space array, no idea how big it is */
|
|
||||||
array->_MaxElement = 2 * 1000 * 1000 * 1000; /* just a big number */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper for update_arrays().
|
* Helper for update_arrays().
|
||||||
* \return min(current min, array->_MaxElement).
|
* \return min(current min, array->_MaxElement).
|
||||||
@@ -97,7 +68,7 @@ compute_max_element(struct gl_client_array *array)
|
|||||||
static GLuint
|
static GLuint
|
||||||
update_min(GLuint min, struct gl_client_array *array)
|
update_min(GLuint min, struct gl_client_array *array)
|
||||||
{
|
{
|
||||||
compute_max_element(array);
|
_mesa_update_array_max_element(array);
|
||||||
return MIN2(min, array->_MaxElement);
|
return MIN2(min, array->_MaxElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -34,6 +34,37 @@
|
|||||||
struct gl_client_array;
|
struct gl_client_array;
|
||||||
struct gl_context;
|
struct gl_context;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute the index of the last array element that can be safely accessed in
|
||||||
|
* a vertex array. We can really only do this when the array lives in a VBO.
|
||||||
|
* The array->_MaxElement field will be updated.
|
||||||
|
* Later in glDrawArrays/Elements/etc we can do some bounds checking.
|
||||||
|
*/
|
||||||
|
static INLINE void
|
||||||
|
_mesa_update_array_max_element(struct gl_client_array *array)
|
||||||
|
{
|
||||||
|
assert(array->Enabled);
|
||||||
|
|
||||||
|
if (array->BufferObj->Name) {
|
||||||
|
GLsizeiptrARB offset = (GLsizeiptrARB) array->Ptr;
|
||||||
|
GLsizeiptrARB bufSize = (GLsizeiptrARB) array->BufferObj->Size;
|
||||||
|
|
||||||
|
if (offset < bufSize) {
|
||||||
|
array->_MaxElement = (bufSize - offset + array->StrideB
|
||||||
|
- array->_ElementSize) / array->StrideB;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
array->_MaxElement = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* user-space array, no idea how big it is */
|
||||||
|
array->_MaxElement = 2 * 1000 * 1000 * 1000; /* just a big number */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if _HAVE_FULL_GL
|
#if _HAVE_FULL_GL
|
||||||
|
|
||||||
extern void GLAPIENTRY
|
extern void GLAPIENTRY
|
||||||
|
Reference in New Issue
Block a user