mirror of
https://github.com/love2d/love.git
synced 2026-08-21 13:09:56 +02:00
Make VertexBuffers use size_t, raising the limit of vertices that can be stored
This means more sprites in SpriteBatches, yay!
This commit is contained in:
@@ -34,24 +34,21 @@ namespace opengl
|
|||||||
{
|
{
|
||||||
// VertexBuffer
|
// VertexBuffer
|
||||||
|
|
||||||
VertexBuffer *VertexBuffer::Create(int size, GLenum target, GLenum usage)
|
VertexBuffer *VertexBuffer::Create(size_t size, GLenum target, GLenum usage)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Try to create a VBO.
|
// Try to create a VBO.
|
||||||
return new VBO(size, target, usage);
|
return new VBO(size, target, usage);
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (const love::Exception &e)
|
catch (const love::Exception &)
|
||||||
{
|
{
|
||||||
(void)e;
|
|
||||||
|
|
||||||
// VBO not supported ... create regular array.
|
// VBO not supported ... create regular array.
|
||||||
return new VertexArray(size, target, usage);
|
return new VertexArray(size, target, usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexBuffer::VertexBuffer(int size, GLenum target, GLenum usage)
|
VertexBuffer::VertexBuffer(size_t size, GLenum target, GLenum usage)
|
||||||
: size(size)
|
: size(size)
|
||||||
, target(target)
|
, target(target)
|
||||||
, usage(usage)
|
, usage(usage)
|
||||||
@@ -77,7 +74,7 @@ namespace opengl
|
|||||||
|
|
||||||
// VertexArray
|
// VertexArray
|
||||||
|
|
||||||
VertexArray::VertexArray(int size, GLenum target, GLenum usage)
|
VertexArray::VertexArray(size_t size, GLenum target, GLenum usage)
|
||||||
: VertexBuffer(size, target, usage)
|
: VertexBuffer(size, target, usage)
|
||||||
, buf(new char[size])
|
, buf(new char[size])
|
||||||
{
|
{
|
||||||
@@ -105,19 +102,19 @@ namespace opengl
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void VertexArray::fill(int offset, int size, const void *data)
|
void VertexArray::fill(size_t offset, size_t size, const void *data)
|
||||||
{
|
{
|
||||||
memcpy(buf + offset, data, size);
|
memcpy(buf + offset, data, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *VertexArray::getPointer(int offset) const
|
const void *VertexArray::getPointer(size_t offset) const
|
||||||
{
|
{
|
||||||
return buf + offset;
|
return buf + offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
// VBO
|
// VBO
|
||||||
|
|
||||||
VBO::VBO(int size, GLenum target, GLenum usage)
|
VBO::VBO(size_t size, GLenum target, GLenum usage)
|
||||||
: VertexBuffer(size, target, usage)
|
: VertexBuffer(size, target, usage)
|
||||||
, vbo(0)
|
, vbo(0)
|
||||||
, buffer_copy(0)
|
, buffer_copy(0)
|
||||||
@@ -165,7 +162,7 @@ namespace opengl
|
|||||||
glBindBufferARB(getTarget(), 0);
|
glBindBufferARB(getTarget(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VBO::fill(int offset, int size, const void *data)
|
void VBO::fill(size_t offset, size_t size, const void *data)
|
||||||
{
|
{
|
||||||
if (mapped)
|
if (mapped)
|
||||||
memcpy(static_cast<char*>(mapped) + offset, data, size);
|
memcpy(static_cast<char*>(mapped) + offset, data, size);
|
||||||
@@ -173,7 +170,7 @@ namespace opengl
|
|||||||
glBufferSubDataARB(getTarget(), offset, size, data);
|
glBufferSubDataARB(getTarget(), offset, size, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
const void *VBO::getPointer(int offset) const
|
const void *VBO::getPointer(size_t offset) const
|
||||||
{
|
{
|
||||||
return reinterpret_cast<const void*>(offset);
|
return reinterpret_cast<const void*>(offset);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ namespace opengl
|
|||||||
* @param usage GL_DYNAMIC_DRAW, etc.
|
* @param usage GL_DYNAMIC_DRAW, etc.
|
||||||
* @return A new VertexBuffer.
|
* @return A new VertexBuffer.
|
||||||
*/
|
*/
|
||||||
static VertexBuffer *Create(int size, GLenum target, GLenum usage);
|
static VertexBuffer *Create(size_t size, GLenum target, GLenum usage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
@@ -68,7 +68,7 @@ namespace opengl
|
|||||||
* @param target The target VertexBuffer object, e.g. GL_ARRAY_BUFFER.
|
* @param target The target VertexBuffer object, e.g. GL_ARRAY_BUFFER.
|
||||||
* @param usage Usage hint, e.g. GL_DYNAMIC_DRAW.
|
* @param usage Usage hint, e.g. GL_DYNAMIC_DRAW.
|
||||||
*/
|
*/
|
||||||
VertexBuffer(int size, GLenum target, GLenum usage);
|
VertexBuffer(size_t size, GLenum target, GLenum usage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destructor. Does nothing, but must be declared virtual.
|
* Destructor. Does nothing, but must be declared virtual.
|
||||||
@@ -80,7 +80,7 @@ namespace opengl
|
|||||||
*
|
*
|
||||||
* @return The size of the VertexBuffer.
|
* @return The size of the VertexBuffer.
|
||||||
*/
|
*/
|
||||||
int getSize() const { return size; }
|
size_t getSize() const { return size; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the target buffer object.
|
* Get the target buffer object.
|
||||||
@@ -139,7 +139,7 @@ namespace opengl
|
|||||||
* @param size The size of the incoming data.
|
* @param size The size of the incoming data.
|
||||||
* @param data Pointer to memory to copy data from.
|
* @param data Pointer to memory to copy data from.
|
||||||
*/
|
*/
|
||||||
virtual void fill(int offset, int size, const void *data) = 0;
|
virtual void fill(size_t offset, size_t size, const void *data) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a pointer which represents the specified byte offset.
|
* Get a pointer which represents the specified byte offset.
|
||||||
@@ -147,7 +147,7 @@ namespace opengl
|
|||||||
* @param offset The byte offset. (0 is first byte).
|
* @param offset The byte offset. (0 is first byte).
|
||||||
* @return A pointer which represents the offset.
|
* @return A pointer which represents the offset.
|
||||||
*/
|
*/
|
||||||
virtual const void *getPointer(int offset) const = 0;
|
virtual const void *getPointer(size_t offset) const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This helper class can bind a VertexArray temporarily, and
|
* This helper class can bind a VertexArray temporarily, and
|
||||||
@@ -176,7 +176,7 @@ namespace opengl
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
// The size of the buffer, in bytes.
|
// The size of the buffer, in bytes.
|
||||||
int size;
|
size_t size;
|
||||||
|
|
||||||
// The target buffer object. (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER).
|
// The target buffer object. (GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER).
|
||||||
GLenum target;
|
GLenum target;
|
||||||
@@ -198,7 +198,7 @@ namespace opengl
|
|||||||
/**
|
/**
|
||||||
* @copydoc VertexBuffer(int, GLenum, GLenum)
|
* @copydoc VertexBuffer(int, GLenum, GLenum)
|
||||||
*/
|
*/
|
||||||
VertexArray(int size, GLenum target, GLenum usage);
|
VertexArray(size_t size, GLenum target, GLenum usage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frees the data we've allocated.
|
* Frees the data we've allocated.
|
||||||
@@ -210,8 +210,8 @@ namespace opengl
|
|||||||
virtual void unmap();
|
virtual void unmap();
|
||||||
virtual void bind();
|
virtual void bind();
|
||||||
virtual void unbind();
|
virtual void unbind();
|
||||||
virtual void fill(int offset, int size, const void *data);
|
virtual void fill(size_t offset, size_t size, const void *data);
|
||||||
virtual const void *getPointer(int offset) const ;
|
virtual const void *getPointer(size_t offset) const ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Holds the data.
|
// Holds the data.
|
||||||
@@ -230,9 +230,9 @@ namespace opengl
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @copydoc VertexBuffer(int, GLenum, GLenum)
|
* @copydoc VertexBuffer(size_t, GLenum, GLenum)
|
||||||
*/
|
*/
|
||||||
VBO(int size, GLenum target, GLenum usage);
|
VBO(size_t size, GLenum target, GLenum usage);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the VBOs from OpenGL.
|
* Deletes the VBOs from OpenGL.
|
||||||
@@ -244,8 +244,8 @@ namespace opengl
|
|||||||
virtual void unmap();
|
virtual void unmap();
|
||||||
virtual void bind();
|
virtual void bind();
|
||||||
virtual void unbind();
|
virtual void unbind();
|
||||||
virtual void fill(int offset, int size, const void *data);
|
virtual void fill(size_t offset, size_t size, const void *data);
|
||||||
virtual const void *getPointer(int offset) const ;
|
virtual const void *getPointer(size_t offset) const ;
|
||||||
|
|
||||||
// Implements Volatile.
|
// Implements Volatile.
|
||||||
bool loadVolatile();
|
bool loadVolatile();
|
||||||
|
|||||||
Reference in New Issue
Block a user