mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-05-12 20:13:53 +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;
|
Vector v = position - lastPos;
|
||||||
if (position.isFollowingPath() && swimPath)
|
if (position.isFollowingPath() && swimPath)
|
||||||
|
|
|
@ -741,6 +741,8 @@ bool Shot::isObstructed(float dt) const
|
||||||
|
|
||||||
void Shot::onUpdate(float dt)
|
void Shot::onUpdate(float dt)
|
||||||
{
|
{
|
||||||
|
CollideQuad::onUpdate(dt);
|
||||||
|
|
||||||
if (game->isPaused()) return;
|
if (game->isPaused()) return;
|
||||||
if (game->isWorldPaused()) return;
|
if (game->isWorldPaused()) return;
|
||||||
if (!shotData) return;
|
if (!shotData) return;
|
||||||
|
@ -800,7 +802,6 @@ void Shot::onUpdate(float dt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Quad::onUpdate(dt);
|
|
||||||
updateSegments(position);
|
updateSegments(position);
|
||||||
if (!dead)
|
if (!dead)
|
||||||
{
|
{
|
||||||
|
|
|
@ -96,7 +96,7 @@ namespace internal
|
||||||
#include "OSFunctions.h"
|
#include "OSFunctions.h"
|
||||||
|
|
||||||
// --- Defined in RenderBase.cpp -- Declared here to avoid pulling in gl.h via RenderBase.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);
|
unsigned generateEmptyTexture(int res);
|
||||||
void sizePowerOf2Texture(int &v);
|
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);
|
bool isTouchingLine(Vector lineStart, Vector lineEnd, Vector point, int radius=1, Vector* closest=0);
|
||||||
|
|
||||||
|
|
||||||
void drawCircle(float radius, int steps=1);
|
|
||||||
|
|
||||||
std::string getPathInfoStr();
|
std::string getPathInfoStr();
|
||||||
void exit_error(const std::string &message);
|
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);
|
std::string removeSpaces(const std::string &input);
|
||||||
int randRange(int r1, int r2); // from..to inclusive
|
int randRange(int r1, int r2); // from..to inclusive
|
||||||
|
|
||||||
|
|
||||||
enum LerpType
|
enum LerpType
|
||||||
{
|
{
|
||||||
LERP_LINEAR = 0,
|
LERP_LINEAR = 0,
|
||||||
|
|
|
@ -398,7 +398,8 @@ void PauseQuad::setPositionSnapTo(InterpolatedVector *positionSnapTo)
|
||||||
}
|
}
|
||||||
|
|
||||||
CollideQuad::CollideQuad()
|
CollideQuad::CollideQuad()
|
||||||
: collideRadius(0)
|
: collideRadius(0), prevCollideRadius(0)
|
||||||
|
, cvbo(GPUBUF_VERTEXBUF | GPUBUF_DYNAMIC)
|
||||||
{
|
{
|
||||||
addType(SCO_COLLIDE_QUAD);
|
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
|
void CollideQuad::renderCollision(const RenderState& rs) const
|
||||||
{
|
{
|
||||||
if (collideRadius > 0)
|
if (collideRadius > 0 && cvbo.size())
|
||||||
{
|
{
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
core->setupRenderPositionAndScale();
|
core->setupRenderPositionAndScale();
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
glTranslatef(position.x+offset.x, position.y+offset.y, 0);
|
glTranslatef(position.x+offset.x+internalOffset.x, position.y+offset.y+internalOffset.y, 0);
|
||||||
|
|
||||||
glTranslatef(internalOffset.x, internalOffset.y, 0);
|
|
||||||
|
|
||||||
rs.gpu.setBlend(BLEND_DEFAULT);
|
rs.gpu.setBlend(BLEND_DEFAULT);
|
||||||
|
|
||||||
glColor4f(1,0,0,0.5);
|
glColor4f(1,0,0,0.5f);
|
||||||
drawCircle(collideRadius, 8);
|
cvbo.apply();
|
||||||
|
glDrawArrays(GL_TRIANGLE_FAN, 0, CIRCLE_VERTS);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
||||||
#include "RenderObject.h"
|
#include "RenderObject.h"
|
||||||
#include "DataStructures.h"
|
#include "DataStructures.h"
|
||||||
|
#include "VertexBuffer.h"
|
||||||
|
|
||||||
|
|
||||||
class DynamicRenderGrid;
|
class DynamicRenderGrid;
|
||||||
|
@ -124,8 +125,13 @@ public:
|
||||||
CollideQuad();
|
CollideQuad();
|
||||||
virtual ~CollideQuad();
|
virtual ~CollideQuad();
|
||||||
virtual void renderCollision(const RenderState& rs) const OVERRIDE;
|
virtual void renderCollision(const RenderState& rs) const OVERRIDE;
|
||||||
|
virtual void onUpdate(float dt) OVERRIDE;
|
||||||
|
|
||||||
float collideRadius;
|
float collideRadius;
|
||||||
|
|
||||||
|
private:
|
||||||
|
float prevCollideRadius;
|
||||||
|
DynamicGPUBuffer cvbo;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -2,15 +2,16 @@
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
|
|
||||||
|
|
||||||
void drawCircle(float radius, int stepSize)
|
float *drawCircle(float *p, float radius, size_t vertices, const Vector& center)
|
||||||
{
|
{
|
||||||
glBegin(GL_POLYGON);
|
const float step = (2 * PI) / float(vertices);
|
||||||
for(int i=0;i < 360; i+=stepSize)
|
float a = 0;
|
||||||
|
for(size_t i = 0; i < vertices; ++i, a += step)
|
||||||
{
|
{
|
||||||
const float degInRad = i*(PI/180.0f);
|
*p++ = center.x + cosf(a)*radius;
|
||||||
glVertex3f(cosf(degInRad)*radius, sinf(degInRad)*radius,0.0);
|
*p++ = center.y + sinf(a)*radius;
|
||||||
}
|
}
|
||||||
glEnd();
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sizePowerOf2Texture(int &v)
|
void sizePowerOf2Texture(int &v)
|
||||||
|
|
|
@ -113,4 +113,6 @@ extern PFNGLDEBUGMESSAGEINSERTARBPROC glDebugMessageInsertARB;
|
||||||
|
|
||||||
extern PFNGLOBJECTLABELPROC glObjectLabel;
|
extern PFNGLOBJECTLABELPROC glObjectLabel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -76,6 +76,7 @@ void SkeletalKeyframe::copyAllButTime(SkeletalKeyframe *copy)
|
||||||
}
|
}
|
||||||
|
|
||||||
Bone::Bone() : CollideQuad()
|
Bone::Bone() : CollideQuad()
|
||||||
|
, cmvbo(GPUBUF_VERTEXBUF | GPUBUF_DYNAMIC)
|
||||||
{
|
{
|
||||||
addType(SCO_BONE);
|
addType(SCO_BONE);
|
||||||
fileRenderQuad = true;
|
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
|
void Bone::renderCollision(const RenderState& rs) const
|
||||||
{
|
{
|
||||||
if (!collisionMask.empty())
|
if (!collisionMask.empty() && cmvbo.size())
|
||||||
{
|
{
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
@ -284,17 +287,13 @@ void Bone::renderCollision(const RenderState& rs) const
|
||||||
|
|
||||||
glColor4f(1,1,0,0.5);
|
glColor4f(1,1,0,0.5);
|
||||||
|
|
||||||
|
cmvbo.apply();
|
||||||
|
|
||||||
|
int first = 0;
|
||||||
for (size_t i = 0; i < transformedCollisionMask.size(); i++)
|
for (size_t i = 0; i < transformedCollisionMask.size(); i++)
|
||||||
{
|
{
|
||||||
Vector collide = this->transformedCollisionMask[i];
|
glDrawArrays(GL_TRIANGLE_FAN, first, TINY_CIRCLE_VERTS);
|
||||||
|
first += TINY_CIRCLE_VERTS;
|
||||||
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
@ -328,6 +327,27 @@ void Bone::onUpdate(float dt)
|
||||||
{
|
{
|
||||||
transformedCollisionMask[i] = getWorldCollidePosition(collisionMask[i]);
|
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
|
// Do this BEFORE updating children
|
||||||
|
|
|
@ -108,6 +108,7 @@ protected:
|
||||||
int minDist, maxDist, reverse;
|
int minDist, maxDist, reverse;
|
||||||
std::vector<Bone*> segments;
|
std::vector<Bone*> segments;
|
||||||
void onUpdate(float dt);
|
void onUpdate(float dt);
|
||||||
|
DynamicGPUBuffer cmvbo; // for collision mask debug render only
|
||||||
public:
|
public:
|
||||||
std::vector<Vector> collisionMask;
|
std::vector<Vector> collisionMask;
|
||||||
std::vector<Vector> transformedCollisionMask;
|
std::vector<Vector> transformedCollisionMask;
|
||||||
|
|
Loading…
Add table
Reference in a new issue