mirror of
https://github.com/love2d/love.git
synced 2026-08-14 01:20:56 +02:00
love.graphics internal Buffer objects are no longer OpenGL-specific.
--HG-- branch : minor
This commit is contained in:
@@ -19,17 +19,11 @@
|
||||
**/
|
||||
|
||||
//LOVE
|
||||
#include "common/config.h"
|
||||
#include "ParticleSystem.h"
|
||||
#include "graphics/Graphics.h"
|
||||
|
||||
#include "OpenGL.h"
|
||||
|
||||
// STD
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
@@ -37,32 +31,18 @@ namespace graphics
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
ParticleSystem::ParticleSystem(Texture *texture, uint32 size)
|
||||
: love::graphics::ParticleSystem(texture, size)
|
||||
, buffer(nullptr)
|
||||
, quadIndices(size)
|
||||
ParticleSystem::ParticleSystem(Graphics *gfx, Texture *texture, uint32 size)
|
||||
: love::graphics::ParticleSystem(gfx, texture, size)
|
||||
{
|
||||
createVertices(size);
|
||||
}
|
||||
|
||||
ParticleSystem::ParticleSystem(const ParticleSystem &p)
|
||||
: love::graphics::ParticleSystem(p)
|
||||
, quadIndices(p.quadIndices)
|
||||
{
|
||||
createVertices(maxParticles);
|
||||
}
|
||||
|
||||
ParticleSystem::~ParticleSystem()
|
||||
{
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
void ParticleSystem::createVertices(size_t numparticles)
|
||||
{
|
||||
size_t size = sizeof(Vertex) * numparticles * 4;
|
||||
GLBuffer *newbuffer = new GLBuffer(size, nullptr, BUFFER_VERTEX, vertex::USAGE_STREAM, 0);
|
||||
delete buffer;
|
||||
buffer = newbuffer;
|
||||
}
|
||||
|
||||
ParticleSystem *ParticleSystem::clone()
|
||||
@@ -70,78 +50,28 @@ ParticleSystem *ParticleSystem::clone()
|
||||
return new ParticleSystem(*this);
|
||||
}
|
||||
|
||||
void ParticleSystem::setBufferSize(uint32 size)
|
||||
{
|
||||
love::graphics::ParticleSystem::setBufferSize(size);
|
||||
|
||||
quadIndices = QuadIndices(size);
|
||||
createVertices(size);
|
||||
}
|
||||
|
||||
void ParticleSystem::draw(Graphics *gfx, const Matrix4 &m)
|
||||
{
|
||||
uint32 pCount = getCount();
|
||||
|
||||
if (pCount == 0 || texture.get() == nullptr || pMem == nullptr || buffer == nullptr)
|
||||
if (!prepareDraw(gfx, m))
|
||||
return;
|
||||
|
||||
gfx->flushStreamDraws();
|
||||
|
||||
OpenGL::TempDebugGroup debuggroup("ParticleSystem draw");
|
||||
|
||||
Graphics::TempTransform transform(gfx, m);
|
||||
|
||||
const Vertex *textureVerts = texture->getVertices();
|
||||
Vertex *pVerts = (Vertex *) buffer->map();
|
||||
Particle *p = pHead;
|
||||
|
||||
bool useQuads = !quads.empty();
|
||||
|
||||
Matrix3 t;
|
||||
|
||||
// set the vertex data for each particle (transformation, texcoords, color)
|
||||
while (p)
|
||||
{
|
||||
if (useQuads)
|
||||
textureVerts = quads[p->quadIndex]->getVertices();
|
||||
|
||||
// particle vertices are image vertices transformed by particle info
|
||||
t.setTransformation(p->position.x, p->position.y, p->angle, p->size, p->size, offset.x, offset.y, 0.0f, 0.0f);
|
||||
t.transform(pVerts, textureVerts, 4);
|
||||
|
||||
// Particle colors are stored as floats (0-1) but vertex colors are
|
||||
// unsigned bytes (0-255).
|
||||
Color c = toColor(p->color);
|
||||
|
||||
// set the texture coordinate and color data for particle vertices
|
||||
for (int v = 0; v < 4; v++)
|
||||
{
|
||||
pVerts[v].s = textureVerts[v].s;
|
||||
pVerts[v].t = textureVerts[v].t;
|
||||
pVerts[v].color = c;
|
||||
}
|
||||
|
||||
pVerts += 4;
|
||||
p = p->next;
|
||||
}
|
||||
|
||||
buffer->unmap();
|
||||
|
||||
gl.bindTextureToUnit(texture, 0, false);
|
||||
gl.prepareDraw();
|
||||
|
||||
gl.useVertexAttribArrays(ATTRIBFLAG_POS | ATTRIBFLAG_TEXCOORD | ATTRIBFLAG_COLOR);
|
||||
|
||||
buffer->bind();
|
||||
gl.bindBuffer(BUFFER_VERTEX, (GLuint) buffer->getHandle());
|
||||
glVertexAttribPointer(ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), BUFFER_OFFSET(offsetof(Vertex, color.r)));
|
||||
glVertexAttribPointer(ATTRIB_POS, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(offsetof(Vertex, x)));
|
||||
glVertexAttribPointer(ATTRIB_TEXCOORD, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), BUFFER_OFFSET(offsetof(Vertex, s)));
|
||||
|
||||
GLsizei count = (GLsizei) quadIndices.getIndexCount(pCount);
|
||||
GLenum gltype = quadIndices.getType();
|
||||
GLsizei count = (GLsizei) quadIndices.getIndexCount(getCount());
|
||||
GLenum gltype = OpenGL::getGLIndexDataType(quadIndices.getType());
|
||||
|
||||
quadIndices.getBuffer()->bind();
|
||||
gl.drawElements(GL_TRIANGLES, count, gltype, quadIndices.getPointer(0));
|
||||
gl.bindBuffer(BUFFER_INDEX, (GLuint) quadIndices.getBuffer()->getHandle());
|
||||
gl.drawElements(GL_TRIANGLES, count, gltype, BUFFER_OFFSET(0));
|
||||
}
|
||||
|
||||
} // opengl
|
||||
|
||||
Reference in New Issue
Block a user