mirror of
https://github.com/love2d/love.git
synced 2026-08-19 04:06:17 +02:00
Cleaned up some vertex data-related code.
--HG-- branch : minor
This commit is contained in:
@@ -142,22 +142,12 @@ love::graphics::Buffer *Graphics::newBuffer(size_t size, const void *data, Buffe
|
||||
return new Buffer(size, data, type, usage, mapflags);
|
||||
}
|
||||
|
||||
love::graphics::Mesh *Graphics::newMesh(const std::vector<Vertex> &vertices, Mesh::DrawMode drawmode, vertex::Usage usage)
|
||||
{
|
||||
return new Mesh(this, vertices, drawmode, usage);
|
||||
}
|
||||
|
||||
love::graphics::Mesh *Graphics::newMesh(int vertexcount, Mesh::DrawMode drawmode, vertex::Usage usage)
|
||||
{
|
||||
return new Mesh(this, vertexcount, drawmode, usage);
|
||||
}
|
||||
|
||||
love::graphics::Mesh *Graphics::newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, int vertexcount, Mesh::DrawMode drawmode, vertex::Usage usage)
|
||||
love::graphics::Mesh *Graphics::newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage)
|
||||
{
|
||||
return new Mesh(this, vertexformat, vertexcount, drawmode, usage);
|
||||
}
|
||||
|
||||
love::graphics::Mesh *Graphics::newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, const void *data, size_t datasize, Mesh::DrawMode drawmode, vertex::Usage usage)
|
||||
love::graphics::Mesh *Graphics::newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage)
|
||||
{
|
||||
return new Mesh(this, vertexformat, data, datasize, drawmode, usage);
|
||||
}
|
||||
@@ -387,17 +377,7 @@ void Graphics::flushStreamDraws()
|
||||
if (attribs == 0)
|
||||
return;
|
||||
|
||||
GLenum glmode = GL_ZERO;
|
||||
|
||||
switch (sbstate.primitiveMode)
|
||||
{
|
||||
case PrimitiveMode::TRIANGLES:
|
||||
glmode = GL_TRIANGLES;
|
||||
break;
|
||||
case PrimitiveMode::POINTS:
|
||||
glmode = GL_POINTS;
|
||||
break;
|
||||
}
|
||||
GLenum glprimitivetype = OpenGL::getGLPrimitiveType(sbstate.primitiveMode);
|
||||
|
||||
Colorf nc = gl.getConstantColor();
|
||||
if (attribs & ATTRIBFLAG_COLOR)
|
||||
@@ -419,10 +399,10 @@ void Graphics::flushStreamDraws()
|
||||
|
||||
sbstate.indexBufferMap = StreamBuffer::MapInfo();
|
||||
|
||||
gl.drawElements(glmode, sbstate.indexCount, GL_UNSIGNED_SHORT, BUFFER_OFFSET(offset));
|
||||
gl.drawElements(glprimitivetype, sbstate.indexCount, GL_UNSIGNED_SHORT, BUFFER_OFFSET(offset));
|
||||
}
|
||||
else
|
||||
gl.drawArrays(glmode, 0, sbstate.vertexCount);
|
||||
gl.drawArrays(glprimitivetype, 0, sbstate.vertexCount);
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
@@ -1266,7 +1246,7 @@ void Graphics::setBlendMode(BlendMode mode, BlendAlpha alphamode)
|
||||
|
||||
void Graphics::setPointSize(float size)
|
||||
{
|
||||
if (streamBufferState.primitiveMode == vertex::PrimitiveMode::POINTS)
|
||||
if (streamBufferState.primitiveMode == PRIMITIVE_POINTS)
|
||||
flushStreamDraws();
|
||||
|
||||
gl.setPointSize(size * getCurrentDPIScale());
|
||||
|
||||
@@ -71,11 +71,8 @@ public:
|
||||
|
||||
love::graphics::Buffer *newBuffer(size_t size, const void *data, BufferType type, vertex::Usage usage, uint32 mapflags) override;
|
||||
|
||||
love::graphics::Mesh *newMesh(const std::vector<Vertex> &vertices, Mesh::DrawMode drawmode, vertex::Usage usage) override;
|
||||
love::graphics::Mesh *newMesh(int vertexcount, Mesh::DrawMode drawmode, vertex::Usage usage) override;
|
||||
|
||||
love::graphics::Mesh *newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, int vertexcount, Mesh::DrawMode drawmode, vertex::Usage usage) override;
|
||||
love::graphics::Mesh *newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, const void *data, size_t datasize, Mesh::DrawMode drawmode, vertex::Usage usage) override;
|
||||
love::graphics::Mesh *newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage) override;
|
||||
love::graphics::Mesh *newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage) override;
|
||||
|
||||
love::graphics::Text *newText(love::graphics::Font *font, const std::vector<Font::ColoredString> &text = {}) override;
|
||||
|
||||
|
||||
@@ -35,26 +35,16 @@ namespace graphics
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Mesh::Mesh(graphics::Graphics *gfx, const std::vector<AttribFormat> &vertexformat, const void *data, size_t datasize, DrawMode drawmode, vertex::Usage usage)
|
||||
Mesh::Mesh(graphics::Graphics *gfx, const std::vector<AttribFormat> &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage)
|
||||
: love::graphics::Mesh(gfx, vertexformat, data, datasize, drawmode, usage)
|
||||
{
|
||||
}
|
||||
|
||||
Mesh::Mesh(graphics::Graphics *gfx, const std::vector<AttribFormat> &vertexformat, int vertexcount, DrawMode drawmode, vertex::Usage usage)
|
||||
Mesh::Mesh(graphics::Graphics *gfx, const std::vector<AttribFormat> &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage)
|
||||
: love::graphics::Mesh(gfx, vertexformat, vertexcount, drawmode, usage)
|
||||
{
|
||||
}
|
||||
|
||||
Mesh::Mesh(graphics::Graphics *gfx, const std::vector<Vertex> &vertices, DrawMode drawmode, vertex::Usage usage)
|
||||
: Mesh(gfx, getDefaultVertexFormat(), &vertices[0], vertices.size() * sizeof(Vertex), drawmode, usage)
|
||||
{
|
||||
}
|
||||
|
||||
Mesh::Mesh(graphics::Graphics *gfx, int vertexcount, DrawMode drawmode, vertex::Usage usage)
|
||||
: Mesh(gfx, getDefaultVertexFormat(), vertexcount, drawmode, usage)
|
||||
{
|
||||
}
|
||||
|
||||
Mesh::~Mesh()
|
||||
{
|
||||
}
|
||||
@@ -71,7 +61,7 @@ int Mesh::bindAttributeToShaderInput(int attributeindex, const std::string &inpu
|
||||
if (vertex::getConstant(inputname.c_str(), builtinattrib))
|
||||
attriblocation = (GLint) builtinattrib;
|
||||
else if (Shader::current)
|
||||
attriblocation = ((Shader *) Shader::current)->getAttribLocation(inputname);
|
||||
attriblocation = Shader::current->getVertexAttributeIndex(inputname);
|
||||
|
||||
// The active shader might not use this vertex attribute name.
|
||||
if (attriblocation < 0)
|
||||
@@ -81,23 +71,11 @@ int Mesh::bindAttributeToShaderInput(int attributeindex, const std::string &inpu
|
||||
vbo->unmap();
|
||||
|
||||
gl.bindBuffer(BUFFER_VERTEX, (GLuint) vbo->getHandle());
|
||||
|
||||
GLenum datatype = 0;
|
||||
switch (format.type)
|
||||
{
|
||||
case DATA_BYTE:
|
||||
datatype = GL_UNSIGNED_BYTE;
|
||||
break;
|
||||
case DATA_FLOAT:
|
||||
datatype = GL_FLOAT;
|
||||
break;
|
||||
default:
|
||||
datatype = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
GLboolean normalized = GL_FALSE;
|
||||
GLenum datatype = OpenGL::getGLVertexDataType(format.type, normalized);
|
||||
|
||||
const void *gloffset = BUFFER_OFFSET(getAttributeOffset(attributeindex));
|
||||
GLboolean normalized = (datatype == GL_UNSIGNED_BYTE);
|
||||
|
||||
glVertexAttribPointer(attriblocation, format.components, datatype, normalized, (GLsizei) vertexStride, gloffset);
|
||||
|
||||
@@ -111,37 +89,21 @@ void Mesh::drawInternal(int start, int count, int instancecount, bool useindexbu
|
||||
gl.useVertexAttribArrays(attribflags, instancedattribflags);
|
||||
gl.bindTextureToUnit(texture, 0, false);
|
||||
gl.prepareDraw();
|
||||
|
||||
GLenum gldrawmode = GL_TRIANGLES;
|
||||
switch (drawMode)
|
||||
{
|
||||
case DRAWMODE_FAN:
|
||||
gldrawmode = GL_TRIANGLE_FAN;
|
||||
break;
|
||||
case DRAWMODE_STRIP:
|
||||
gldrawmode = GL_TRIANGLE_STRIP;
|
||||
break;
|
||||
case DRAWMODE_TRIANGLES:
|
||||
default:
|
||||
gldrawmode = GL_TRIANGLES;
|
||||
break;
|
||||
case DRAWMODE_POINTS:
|
||||
gldrawmode = GL_POINTS;
|
||||
break;
|
||||
}
|
||||
|
||||
GLenum glprimitivetype = OpenGL::getGLPrimitiveType(primitiveType);
|
||||
|
||||
if (useindexbuffer)
|
||||
{
|
||||
size_t elementsize = vertex::getIndexDataSize(elementDataType);
|
||||
size_t elementsize = vertex::getIndexDataSize(indexDataType);
|
||||
const void *indices = BUFFER_OFFSET(start * elementsize);
|
||||
GLenum type = OpenGL::getGLIndexDataType(elementDataType);
|
||||
GLenum indextype = OpenGL::getGLIndexDataType(indexDataType);
|
||||
|
||||
gl.bindBuffer(BUFFER_INDEX, (GLuint) ibo->getHandle());
|
||||
gl.drawElements(gldrawmode, count, type, indices, instancecount);
|
||||
gl.drawElements(glprimitivetype, count, indextype, indices, instancecount);
|
||||
}
|
||||
else
|
||||
{
|
||||
gl.drawArrays(gldrawmode, start, count, instancecount);
|
||||
gl.drawArrays(glprimitivetype, start, count, instancecount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,11 +35,8 @@ class Mesh final : public love::graphics::Mesh
|
||||
{
|
||||
public:
|
||||
|
||||
Mesh(graphics::Graphics *gfx, const std::vector<AttribFormat> &vertexformat, const void *data, size_t datasize, DrawMode drawmode, vertex::Usage usage);
|
||||
Mesh(graphics::Graphics *gfx, const std::vector<AttribFormat> &vertexformat, int vertexcount, DrawMode drawmode, vertex::Usage usage);
|
||||
|
||||
Mesh(graphics::Graphics *gfx, const std::vector<Vertex> &vertices, DrawMode drawmode, vertex::Usage usage);
|
||||
Mesh(graphics::Graphics *gfx, int vertexcount, DrawMode drawmode, vertex::Usage usage);
|
||||
Mesh(graphics::Graphics *gfx, const std::vector<AttribFormat> &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage);
|
||||
Mesh(graphics::Graphics *gfx, const std::vector<AttribFormat> &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage);
|
||||
|
||||
virtual ~Mesh();
|
||||
|
||||
|
||||
@@ -504,6 +504,25 @@ void OpenGL::prepareDraw()
|
||||
}
|
||||
}
|
||||
|
||||
GLenum OpenGL::getGLPrimitiveType(PrimitiveType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case PRIMITIVE_TRIANGLES:
|
||||
return GL_TRIANGLES;
|
||||
case PRIMITIVE_TRIANGLE_STRIP:
|
||||
return GL_TRIANGLE_STRIP;
|
||||
case PRIMITIVE_TRIANGLE_FAN:
|
||||
return GL_TRIANGLE_FAN;
|
||||
case PRIMITIVE_POINTS:
|
||||
return GL_POINTS;
|
||||
case PRIMITIVE_MAX_ENUM:
|
||||
return GL_ZERO;
|
||||
}
|
||||
|
||||
return GL_ZERO;
|
||||
}
|
||||
|
||||
GLenum OpenGL::getGLBufferType(BufferType type)
|
||||
{
|
||||
switch (type)
|
||||
@@ -551,6 +570,28 @@ GLenum OpenGL::getGLIndexDataType(IndexDataType type)
|
||||
}
|
||||
}
|
||||
|
||||
GLenum OpenGL::getGLVertexDataType(vertex::DataType type, GLboolean &normalized)
|
||||
{
|
||||
normalized = GL_FALSE;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case vertex::DATA_UNORM8:
|
||||
normalized = GL_TRUE;
|
||||
return GL_UNSIGNED_BYTE;
|
||||
case vertex::DATA_UNORM16:
|
||||
normalized = GL_TRUE;
|
||||
return GL_UNSIGNED_SHORT;
|
||||
case vertex::DATA_FLOAT:
|
||||
normalized = GL_FALSE;
|
||||
return GL_FLOAT;
|
||||
case vertex::DATA_MAX_ENUM:
|
||||
return GL_ZERO;
|
||||
}
|
||||
|
||||
return GL_ZERO;
|
||||
}
|
||||
|
||||
GLenum OpenGL::getGLBufferUsage(vertex::Usage usage)
|
||||
{
|
||||
switch (usage)
|
||||
|
||||
@@ -380,8 +380,10 @@ public:
|
||||
**/
|
||||
Vendor getVendor() const;
|
||||
|
||||
static GLenum getGLPrimitiveType(PrimitiveType type);
|
||||
static GLenum getGLBufferType(BufferType type);
|
||||
static GLenum getGLIndexDataType(IndexDataType type);
|
||||
static GLenum getGLVertexDataType(vertex::DataType type, GLboolean &normalized);
|
||||
static GLenum getGLBufferUsage(vertex::Usage usage);
|
||||
static GLenum getGLTextureType(TextureType type);
|
||||
static GLint getGLWrapMode(Texture::WrapMode wmode);
|
||||
|
||||
@@ -669,7 +669,7 @@ ptrdiff_t Shader::getHandle() const
|
||||
return program;
|
||||
}
|
||||
|
||||
GLint Shader::getAttribLocation(const std::string &name)
|
||||
int Shader::getVertexAttributeIndex(const std::string &name)
|
||||
{
|
||||
auto it = attributes.find(name);
|
||||
if (it != attributes.end())
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
// Implements Shader.
|
||||
void attach() override;
|
||||
std::string getWarnings() const override;
|
||||
int getVertexAttributeIndex(const std::string &name) override;
|
||||
const UniformInfo *getUniformInfo(const std::string &name) const override;
|
||||
const UniformInfo *getUniformInfo(BuiltinUniform builtin) const override;
|
||||
void updateUniform(const UniformInfo *info, int count) override;
|
||||
@@ -65,8 +66,6 @@ public:
|
||||
ptrdiff_t getHandle() const override;
|
||||
void setVideoTextures(Texture *ytexture, Texture *cbtexture, Texture *crtexture) override;
|
||||
|
||||
GLint getAttribLocation(const std::string &name);
|
||||
|
||||
void updateScreenParams();
|
||||
void updatePointSize(float size);
|
||||
void updateBuiltinUniforms();
|
||||
|
||||
Reference in New Issue
Block a user