quads painting

This commit is contained in:
ericrius1 2015-06-23 16:20:29 -07:00
parent 32eade9ead
commit 101400809a
4 changed files with 36 additions and 8 deletions

View file

@ -39,7 +39,7 @@ void RenderableLineEntityItem::updateGeometry() {
void RenderableLineEntityItem::render(RenderArgs* args) {
PerformanceTimer perfTimer("RenderableLineEntityItem::render");
Q_ASSERT(getType() == EntityTypes::Line);
updateGeometry(); 
updateGeometry();
Q_ASSERT(args->_batch);
gpu::Batch& batch = *args->_batch;

View file

@ -31,7 +31,7 @@ void RenderableQuadEntityItem::updateGeometry() {
}
if (_pointsChanged) {
glm::vec4 lineColor(toGlm(getXColor()), getLocalRenderAlpha());
geometryCache->updateVertices(_lineVerticesID, getLinePoints(), lineColor);
geometryCache->updateVertices(_lineVerticesID, getQuadVertices(), lineColor);
_pointsChanged = false;
}
}
@ -48,9 +48,9 @@ void RenderableQuadEntityItem::render(RenderArgs* args) {
batch.setModelTransform(transform);
batch._glLineWidth(getLineWidth());
if (getLinePoints().size() > 1) {
if (getLinePoints().size() > 3) {
DependencyManager::get<DeferredLightingEffect>()->bindSimpleProgram(batch);
DependencyManager::get<GeometryCache>()->renderVertices(batch, gpu::LINE_STRIP, _lineVerticesID);
DependencyManager::get<GeometryCache>()->renderVertices(batch, gpu::QUAD_STRIP, _lineVerticesID);
}
batch._glLineWidth(1.0f);

View file

@ -22,7 +22,7 @@
const float QuadEntityItem::DEFAULT_LINE_WIDTH = 2.0f;
const float QuadEntityItem::DEFAULT_LINE_WIDTH = 0.1f;
const int QuadEntityItem::MAX_POINTS_PER_LINE = 70;
@ -35,7 +35,8 @@ QuadEntityItem::QuadEntityItem(const EntityItemID& entityItemID, const EntityIte
EntityItem(entityItemID) ,
_lineWidth(DEFAULT_LINE_WIDTH),
_pointsChanged(true),
_points(QVector<glm::vec3>(0))
_points(QVector<glm::vec3>(0)),
_quadVertices(QVector<glm::vec3>(0))
{
_type = EntityTypes::Quad;
_created = properties.getCreated();
@ -105,6 +106,20 @@ bool QuadEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
if (points.size() > MAX_POINTS_PER_LINE) {
return false;
}
//Check to see if points actually changed. If they haven't, return before doing anything else
if (points.size() == _points.size()) {
//same number of points, so now compare every point
for (int i = 0; i < points.size(); i++ ) {
if (points.at(i) != _points.at(i)){
_pointsChanged = true;
break;
}
}
}
if (!_pointsChanged) {
return false;
}
for (int i = 0; i < points.size(); i++) {
glm::vec3 point = points.at(i);
glm::vec3 pos = getPosition();
@ -115,9 +130,18 @@ bool QuadEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
}
}
_points = points;
_pointsChanged = true;
//All our points are valid and at least one point has changed, now create quads from points
_quadVertices.clear();
for (int i = 0; i < points.size(); i++) {
glm::vec3 point = points.at(i);
glm::vec3 p1 = glm::vec3(point.x - _lineWidth, point.y - _lineWidth, point.z);
glm::vec3 p2 = glm::vec3(point.x + _lineWidth, point.y - _lineWidth, point.z);
glm::vec3 p3 = glm::vec3(point.x + _lineWidth, point.y + _lineWidth, point.z);
glm::vec3 p4 = glm::vec3(point.x - _lineWidth, point.y + _lineWidth, point.z);
_quadVertices << p1 << p2 << p3 << p4;
}
return true;
}

View file

@ -57,6 +57,9 @@ class QuadEntityItem : public EntityItem {
bool setLinePoints(const QVector<glm::vec3>& points);
bool appendPoint(const glm::vec3& point);
const QVector<glm::vec3>& getQuadVertices() const{ return _quadVertices; }
const QVector<glm::vec3>& getLinePoints() const{ return _points; }
virtual ShapeType getShapeType() const { return SHAPE_TYPE_LINE; }
@ -76,6 +79,7 @@ class QuadEntityItem : public EntityItem {
float _lineWidth;
bool _pointsChanged;
QVector<glm::vec3> _points;
QVector<glm::vec3> _quadVertices;
};
#endif // hifi_QuadEntityItem_h