mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Fixed Mesh:setDrawRange when the Mesh has a vertex map and the first argument to setDrawRange is non-zero. Removed mesh-specific instancing code.
This commit is contained in:
@@ -39,7 +39,6 @@ Mesh::Mesh(const std::vector<Vertex> &verts, Mesh::DrawMode mode)
|
||||
, ibo(nullptr)
|
||||
, element_count(0)
|
||||
, element_data_type(getGLDataTypeFromMax(verts.size()))
|
||||
, instance_count(1)
|
||||
, draw_mode(mode)
|
||||
, range_min(-1)
|
||||
, range_max(-1)
|
||||
@@ -55,7 +54,6 @@ Mesh::Mesh(int vertexcount, Mesh::DrawMode mode)
|
||||
, ibo(nullptr)
|
||||
, element_count(0)
|
||||
, element_data_type(getGLDataTypeFromMax(vertexcount))
|
||||
, instance_count(1)
|
||||
, draw_mode(mode)
|
||||
, range_min(-1)
|
||||
, range_max(-1)
|
||||
@@ -176,20 +174,7 @@ void Mesh::setVertexMap(const std::vector<uint32> &map)
|
||||
GLenum datatype = getGLDataTypeFromMax(vertex_count);
|
||||
|
||||
// Calculate the size in bytes of the index buffer data.
|
||||
size_t size = map.size();
|
||||
switch (datatype)
|
||||
{
|
||||
case GL_UNSIGNED_BYTE:
|
||||
size *= sizeof(uint8);
|
||||
break;
|
||||
case GL_UNSIGNED_SHORT:
|
||||
size *= sizeof(uint16);
|
||||
break;
|
||||
case GL_UNSIGNED_INT:
|
||||
default:
|
||||
size *= sizeof(uint32);
|
||||
break;
|
||||
}
|
||||
size_t size = map.size() * getGLDataTypeSize(datatype);
|
||||
|
||||
if (ibo && size > ibo->getSize())
|
||||
{
|
||||
@@ -274,16 +259,6 @@ size_t Mesh::getVertexMapCount() const
|
||||
return element_count;
|
||||
}
|
||||
|
||||
void Mesh::setInstanceCount(int count)
|
||||
{
|
||||
instance_count = std::max(count, 1);
|
||||
}
|
||||
|
||||
int Mesh::getInstanceCount() const
|
||||
{
|
||||
return instance_count;
|
||||
}
|
||||
|
||||
void Mesh::setTexture(Texture *tex)
|
||||
{
|
||||
tex->retain();
|
||||
@@ -399,35 +374,29 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
|
||||
|
||||
int max = element_count - 1;
|
||||
if (range_max >= 0)
|
||||
max = std::min(std::max(range_max, 0), (int) element_count - 1);
|
||||
max = std::min(range_max, max);
|
||||
|
||||
int min = 0;
|
||||
if (range_min >= 0)
|
||||
min = std::min(std::max(range_min, 0), max);
|
||||
min = std::min(range_min, max);
|
||||
|
||||
const void *indices = ibo->getPointer(min * sizeof(uint32));
|
||||
GLenum type = element_data_type;
|
||||
const void *indices = ibo->getPointer(min * getGLDataTypeSize(type));
|
||||
|
||||
if (instance_count > 1)
|
||||
gl.drawElementsInstanced(mode, max - min + 1, type, indices, instance_count);
|
||||
else
|
||||
glDrawElements(mode, max - min + 1, type, indices);
|
||||
glDrawElements(mode, max - min + 1, type, indices);
|
||||
}
|
||||
else
|
||||
{
|
||||
int max = vertex_count - 1;
|
||||
if (range_max >= 0)
|
||||
max = std::min(std::max(range_max, 0), (int) vertex_count - 1);
|
||||
max = std::min(range_max, max);
|
||||
|
||||
int min = 0;
|
||||
if (range_min >= 0)
|
||||
min = std::min(std::max(range_min, 0), max);
|
||||
min = std::min(range_min, max);
|
||||
|
||||
// Normal non-indexed drawing (no custom vertex map.)
|
||||
if (instance_count > 1)
|
||||
gl.drawArraysInstanced(mode, min, max - min + 1, instance_count);
|
||||
else
|
||||
glDrawArrays(mode, min, max - min + 1);
|
||||
glDrawArrays(mode, min, max - min + 1);
|
||||
}
|
||||
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
@@ -455,24 +424,34 @@ GLenum Mesh::getGLDrawMode(DrawMode mode) const
|
||||
case DRAW_MODE_STRIP:
|
||||
return GL_TRIANGLE_STRIP;
|
||||
case DRAW_MODE_TRIANGLES:
|
||||
default:
|
||||
return GL_TRIANGLES;
|
||||
case DRAW_MODE_POINTS:
|
||||
return GL_POINTS;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return GL_TRIANGLES;
|
||||
}
|
||||
|
||||
GLenum Mesh::getGLDataTypeFromMax(size_t maxvalue) const
|
||||
{
|
||||
if (maxvalue > LOVE_UINT16_MAX)
|
||||
return GL_UNSIGNED_INT;
|
||||
else if (maxvalue > LOVE_UINT8_MAX)
|
||||
return GL_UNSIGNED_SHORT;
|
||||
else
|
||||
return GL_UNSIGNED_BYTE;
|
||||
return GL_UNSIGNED_SHORT;
|
||||
}
|
||||
|
||||
size_t Mesh::getGLDataTypeSize(GLenum datatype) const
|
||||
{
|
||||
switch (datatype)
|
||||
{
|
||||
case GL_UNSIGNED_BYTE:
|
||||
return sizeof(uint8);
|
||||
case GL_UNSIGNED_SHORT:
|
||||
return sizeof(uint16);
|
||||
case GL_UNSIGNED_INT:
|
||||
return sizeof(uint32);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool Mesh::getConstant(const char *in, Mesh::DrawMode &out)
|
||||
|
||||
@@ -119,15 +119,6 @@ public:
|
||||
**/
|
||||
size_t getVertexMapCount() const;
|
||||
|
||||
/**
|
||||
* Sets the number of instances of this Mesh to draw (uses hardware
|
||||
* instancing when possible.)
|
||||
* A custom vertex shader is necessary in order to introduce differences
|
||||
* in each instance.
|
||||
**/
|
||||
void setInstanceCount(int count);
|
||||
int getInstanceCount() const;
|
||||
|
||||
/**
|
||||
* Sets the texture used when drawing the Mesh.
|
||||
**/
|
||||
@@ -171,6 +162,7 @@ private:
|
||||
|
||||
GLenum getGLDrawMode(DrawMode mode) const;
|
||||
GLenum getGLDataTypeFromMax(size_t maxvalue) const;
|
||||
size_t getGLDataTypeSize(GLenum datatype) const;
|
||||
|
||||
// Vertex buffer.
|
||||
VertexBuffer *vbo;
|
||||
@@ -181,8 +173,6 @@ private:
|
||||
size_t element_count;
|
||||
GLenum element_data_type;
|
||||
|
||||
int instance_count;
|
||||
|
||||
DrawMode draw_mode;
|
||||
|
||||
int range_min;
|
||||
|
||||
@@ -240,20 +240,6 @@ int w_Mesh_getVertexMap(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Mesh_setInstanceCount(lua_State *L)
|
||||
{
|
||||
Mesh *t = luax_checkmesh(L, 1);
|
||||
t->setInstanceCount(luaL_checkint(L, 2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Mesh_getInstanceCount(lua_State *L)
|
||||
{
|
||||
Mesh *t = luax_checkmesh(L, 1);
|
||||
lua_pushinteger(L, t->getInstanceCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Mesh_setTexture(lua_State *L)
|
||||
{
|
||||
Mesh *t = luax_checkmesh(L, 1);
|
||||
@@ -374,12 +360,6 @@ static const luaL_Reg functions[] =
|
||||
{ "getVertexCount", w_Mesh_getVertexCount },
|
||||
{ "setVertexMap", w_Mesh_setVertexMap },
|
||||
{ "getVertexMap", w_Mesh_getVertexMap },
|
||||
|
||||
// Disabled for now, since implementation is incomplete and might change
|
||||
// if/when VertexBuffers / custom vertex attributes are added.
|
||||
// { "setInstanceCount", w_Mesh_setInstanceCount },
|
||||
// { "getInstanceCount", w_Mesh_getInstanceCount },
|
||||
|
||||
{ "setTexture", w_Mesh_setTexture },
|
||||
{ "getTexture", w_Mesh_getTexture },
|
||||
{ "setDrawMode", w_Mesh_setDrawMode },
|
||||
|
||||
@@ -41,8 +41,6 @@ int w_Mesh_getVertices(lua_State *L);
|
||||
int w_Mesh_getVertexCount(lua_State *L);
|
||||
int w_Mesh_setVertexMap(lua_State *L);
|
||||
int w_Mesh_getVertexMap(lua_State *L);
|
||||
int w_Mesh_setInstanceCount(lua_State *L);
|
||||
int w_Mesh_getInstanceCount(lua_State *L);
|
||||
int w_Mesh_setTexture(lua_State *L);
|
||||
int w_Mesh_getTexture(lua_State *L);
|
||||
int w_Mesh_setDrawMode(lua_State *L);
|
||||
|
||||
Reference in New Issue
Block a user