mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-05-11 11:33:56 +00:00
drawCircle() writes out vertices now instead of directly rendering. Rework related code to use VBO.
This commit is contained in:
parent
5f9d26c360
commit
854afdda3f
9 changed files with 86 additions and 30 deletions
|
@ -1566,7 +1566,7 @@ void Entity::onUpdate(float dt)
|
|||
}
|
||||
}
|
||||
|
||||
Quad::onUpdate(dt);
|
||||
CollideQuad::onUpdate(dt);
|
||||
|
||||
Vector v = position - lastPos;
|
||||
if (position.isFollowingPath() && swimPath)
|
||||
|
|
|
@ -741,6 +741,8 @@ bool Shot::isObstructed(float dt) const
|
|||
|
||||
void Shot::onUpdate(float dt)
|
||||
{
|
||||
CollideQuad::onUpdate(dt);
|
||||
|
||||
if (game->isPaused()) return;
|
||||
if (game->isWorldPaused()) return;
|
||||
if (!shotData) return;
|
||||
|
@ -800,7 +802,6 @@ void Shot::onUpdate(float dt)
|
|||
}
|
||||
}
|
||||
|
||||
Quad::onUpdate(dt);
|
||||
updateSegments(position);
|
||||
if (!dead)
|
||||
{
|
||||
|
|
|
@ -96,7 +96,7 @@ namespace internal
|
|||
#include "OSFunctions.h"
|
||||
|
||||
// --- Defined in RenderBase.cpp -- Declared here to avoid pulling in gl.h via RenderBase.h --
|
||||
void drawCircle(float radius, int stepSize);
|
||||
float *drawCircle(float *p, float radius, size_t vertices, const Vector& center = Vector(0, 0));
|
||||
unsigned generateEmptyTexture(int res);
|
||||
void sizePowerOf2Texture(int &v);
|
||||
// ----------------------
|
||||
|
@ -162,8 +162,6 @@ int nocasecmp(const std::string &s1, const std::string &s2);
|
|||
bool isTouchingLine(Vector lineStart, Vector lineEnd, Vector point, int radius=1, Vector* closest=0);
|
||||
|
||||
|
||||
void drawCircle(float radius, int steps=1);
|
||||
|
||||
std::string getPathInfoStr();
|
||||
void exit_error(const std::string &message);
|
||||
|
||||
|
@ -181,6 +179,7 @@ std::string splitCamelCase(const std::string &input);
|
|||
std::string removeSpaces(const std::string &input);
|
||||
int randRange(int r1, int r2); // from..to inclusive
|
||||
|
||||
|
||||
enum LerpType
|
||||
{
|
||||
LERP_LINEAR = 0,
|
||||
|
|
|
@ -398,7 +398,8 @@ void PauseQuad::setPositionSnapTo(InterpolatedVector *positionSnapTo)
|
|||
}
|
||||
|
||||
CollideQuad::CollideQuad()
|
||||
: collideRadius(0)
|
||||
: collideRadius(0), prevCollideRadius(0)
|
||||
, cvbo(GPUBUF_VERTEXBUF | GPUBUF_DYNAMIC)
|
||||
{
|
||||
addType(SCO_COLLIDE_QUAD);
|
||||
}
|
||||
|
@ -407,22 +408,47 @@ CollideQuad::~CollideQuad()
|
|||
{
|
||||
}
|
||||
|
||||
enum { CIRCLE_VERTS = 20 };
|
||||
|
||||
void CollideQuad::onUpdate(float dt)
|
||||
{
|
||||
// FIXME: This should be moved to onDebugUpdate() or something
|
||||
if(RenderObject::renderCollisionShape)
|
||||
{
|
||||
if(prevCollideRadius != collideRadius)
|
||||
{
|
||||
prevCollideRadius = collideRadius;
|
||||
if(collideRadius > 0)
|
||||
{
|
||||
const size_t bytes = CIRCLE_VERTS * 2 * sizeof(float);
|
||||
do
|
||||
{
|
||||
float *p = (float*)cvbo.beginWrite(GPUBUFTYPE_VEC2, bytes, GPUACCESS_DEFAULT);
|
||||
drawCircle(p, collideRadius, CIRCLE_VERTS);
|
||||
}
|
||||
while(!cvbo.commitWrite());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Quad::onUpdate(dt);
|
||||
}
|
||||
|
||||
void CollideQuad::renderCollision(const RenderState& rs) const
|
||||
{
|
||||
if (collideRadius > 0)
|
||||
if (collideRadius > 0 && cvbo.size())
|
||||
{
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
core->setupRenderPositionAndScale();
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glTranslatef(position.x+offset.x, position.y+offset.y, 0);
|
||||
|
||||
glTranslatef(internalOffset.x, internalOffset.y, 0);
|
||||
glTranslatef(position.x+offset.x+internalOffset.x, position.y+offset.y+internalOffset.y, 0);
|
||||
|
||||
rs.gpu.setBlend(BLEND_DEFAULT);
|
||||
|
||||
glColor4f(1,0,0,0.5);
|
||||
drawCircle(collideRadius, 8);
|
||||
glColor4f(1,0,0,0.5f);
|
||||
cvbo.apply();
|
||||
glDrawArrays(GL_TRIANGLE_FAN, 0, CIRCLE_VERTS);
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "RenderObject.h"
|
||||
#include "DataStructures.h"
|
||||
#include "VertexBuffer.h"
|
||||
|
||||
|
||||
class DynamicRenderGrid;
|
||||
|
@ -124,8 +125,13 @@ public:
|
|||
CollideQuad();
|
||||
virtual ~CollideQuad();
|
||||
virtual void renderCollision(const RenderState& rs) const OVERRIDE;
|
||||
virtual void onUpdate(float dt) OVERRIDE;
|
||||
|
||||
float collideRadius;
|
||||
|
||||
private:
|
||||
float prevCollideRadius;
|
||||
DynamicGPUBuffer cvbo;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,15 +2,16 @@
|
|||
#include "Base.h"
|
||||
|
||||
|
||||
void drawCircle(float radius, int stepSize)
|
||||
float *drawCircle(float *p, float radius, size_t vertices, const Vector& center)
|
||||
{
|
||||
glBegin(GL_POLYGON);
|
||||
for(int i=0;i < 360; i+=stepSize)
|
||||
{
|
||||
const float degInRad = i*(PI/180.0f);
|
||||
glVertex3f(cosf(degInRad)*radius, sinf(degInRad)*radius,0.0);
|
||||
}
|
||||
glEnd();
|
||||
const float step = (2 * PI) / float(vertices);
|
||||
float a = 0;
|
||||
for(size_t i = 0; i < vertices; ++i, a += step)
|
||||
{
|
||||
*p++ = center.x + cosf(a)*radius;
|
||||
*p++ = center.y + sinf(a)*radius;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
void sizePowerOf2Texture(int &v)
|
||||
|
|
|
@ -113,4 +113,6 @@ extern PFNGLDEBUGMESSAGEINSERTARBPROC glDebugMessageInsertARB;
|
|||
|
||||
extern PFNGLOBJECTLABELPROC glObjectLabel;
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -76,6 +76,7 @@ void SkeletalKeyframe::copyAllButTime(SkeletalKeyframe *copy)
|
|||
}
|
||||
|
||||
Bone::Bone() : CollideQuad()
|
||||
, cmvbo(GPUBUF_VERTEXBUF | GPUBUF_DYNAMIC)
|
||||
{
|
||||
addType(SCO_BONE);
|
||||
fileRenderQuad = true;
|
||||
|
@ -269,9 +270,11 @@ void Bone::spawnParticlesFromCollisionMask(const char *p, unsigned intv, int lay
|
|||
}
|
||||
}
|
||||
|
||||
enum { TINY_CIRCLE_VERTS = 12 };
|
||||
|
||||
void Bone::renderCollision(const RenderState& rs) const
|
||||
{
|
||||
if (!collisionMask.empty())
|
||||
if (!collisionMask.empty() && cmvbo.size())
|
||||
{
|
||||
glPushMatrix();
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
@ -284,17 +287,13 @@ void Bone::renderCollision(const RenderState& rs) const
|
|||
|
||||
glColor4f(1,1,0,0.5);
|
||||
|
||||
cmvbo.apply();
|
||||
|
||||
int first = 0;
|
||||
for (size_t i = 0; i < transformedCollisionMask.size(); i++)
|
||||
{
|
||||
Vector collide = this->transformedCollisionMask[i];
|
||||
|
||||
|
||||
|
||||
glTranslatef(collide.x, collide.y, 0);
|
||||
const RenderObject *parent = this->getTopParent();
|
||||
if (parent)
|
||||
drawCircle(collideRadius*parent->scale.x, 45);
|
||||
glTranslatef(-collide.x, -collide.y, 0);
|
||||
glDrawArrays(GL_TRIANGLE_FAN, first, TINY_CIRCLE_VERTS);
|
||||
first += TINY_CIRCLE_VERTS;
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
|
@ -328,6 +327,27 @@ void Bone::onUpdate(float dt)
|
|||
{
|
||||
transformedCollisionMask[i] = getWorldCollidePosition(collisionMask[i]);
|
||||
}
|
||||
|
||||
// FIXME: This should be moved to onDebugUpdate() or something
|
||||
if(RenderObject::renderCollisionShape)
|
||||
{
|
||||
const size_t bytes = transformedCollisionMask.size() * TINY_CIRCLE_VERTS * 2 * sizeof(float);
|
||||
float *p;
|
||||
do
|
||||
{
|
||||
p = (float*)cmvbo.beginWrite(GPUBUFTYPE_VEC2, bytes, GPUACCESS_DEFAULT);
|
||||
const RenderObject *parent = this->getTopParent();
|
||||
float s = collideRadius;
|
||||
if (parent)
|
||||
s *= parent->scale.x;
|
||||
for(size_t i = 0; i < transformedCollisionMask.size(); ++i)
|
||||
{
|
||||
Vector collide = this->transformedCollisionMask[i];
|
||||
p = drawCircle(p, s, TINY_CIRCLE_VERTS, collide);
|
||||
}
|
||||
}
|
||||
while(!cmvbo.commitWriteExact(p));
|
||||
}
|
||||
}
|
||||
|
||||
// Do this BEFORE updating children
|
||||
|
|
|
@ -108,6 +108,7 @@ protected:
|
|||
int minDist, maxDist, reverse;
|
||||
std::vector<Bone*> segments;
|
||||
void onUpdate(float dt);
|
||||
DynamicGPUBuffer cmvbo; // for collision mask debug render only
|
||||
public:
|
||||
std::vector<Vector> collisionMask;
|
||||
std::vector<Vector> transformedCollisionMask;
|
||||
|
|
Loading…
Add table
Reference in a new issue