mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-08 21:57:05 +02:00
more removal of immediate mode
This commit is contained in:
parent
d796ebf632
commit
fb68037b74
2 changed files with 109 additions and 96 deletions
|
@ -31,7 +31,8 @@ Circle3DOverlay::Circle3DOverlay() :
|
||||||
_minorTickMarksLength(0.0f),
|
_minorTickMarksLength(0.0f),
|
||||||
_quadVerticesID(GeometryCache::UNKNOWN_ID),
|
_quadVerticesID(GeometryCache::UNKNOWN_ID),
|
||||||
_lineVerticesID(GeometryCache::UNKNOWN_ID),
|
_lineVerticesID(GeometryCache::UNKNOWN_ID),
|
||||||
_ticksVerticesID(GeometryCache::UNKNOWN_ID),
|
_majorTicksVerticesID(GeometryCache::UNKNOWN_ID),
|
||||||
|
_minorTicksVerticesID(GeometryCache::UNKNOWN_ID),
|
||||||
_lastStartAt(-1.0f),
|
_lastStartAt(-1.0f),
|
||||||
_lastEndAt(-1.0f),
|
_lastEndAt(-1.0f),
|
||||||
_lastOuterRadius(-1.0f),
|
_lastOuterRadius(-1.0f),
|
||||||
|
@ -56,7 +57,8 @@ Circle3DOverlay::Circle3DOverlay(const Circle3DOverlay* circle3DOverlay) :
|
||||||
_minorTickMarksColor(circle3DOverlay->_minorTickMarksColor),
|
_minorTickMarksColor(circle3DOverlay->_minorTickMarksColor),
|
||||||
_quadVerticesID(GeometryCache::UNKNOWN_ID),
|
_quadVerticesID(GeometryCache::UNKNOWN_ID),
|
||||||
_lineVerticesID(GeometryCache::UNKNOWN_ID),
|
_lineVerticesID(GeometryCache::UNKNOWN_ID),
|
||||||
_ticksVerticesID(GeometryCache::UNKNOWN_ID),
|
_majorTicksVerticesID(GeometryCache::UNKNOWN_ID),
|
||||||
|
_minorTicksVerticesID(GeometryCache::UNKNOWN_ID),
|
||||||
_lastStartAt(-1.0f),
|
_lastStartAt(-1.0f),
|
||||||
_lastEndAt(-1.0f),
|
_lastEndAt(-1.0f),
|
||||||
_lastOuterRadius(-1.0f),
|
_lastOuterRadius(-1.0f),
|
||||||
|
@ -78,7 +80,15 @@ void Circle3DOverlay::render(RenderArgs* args) {
|
||||||
return; // do nothing if our alpha is 0, we're not visible
|
return; // do nothing if our alpha is 0, we're not visible
|
||||||
}
|
}
|
||||||
|
|
||||||
bool geometryChanged = false;
|
// Create the circle in the coordinates origin
|
||||||
|
float outerRadius = getOuterRadius();
|
||||||
|
float innerRadius = getInnerRadius(); // only used in solid case
|
||||||
|
float startAt = getStartAt();
|
||||||
|
float endAt = getEndAt();
|
||||||
|
|
||||||
|
bool geometryChanged = (startAt != _lastStartAt || endAt != _lastEndAt ||
|
||||||
|
innerRadius != _lastInnerRadius || outerRadius != _lastOuterRadius);
|
||||||
|
|
||||||
|
|
||||||
const float FULL_CIRCLE = 360.0f;
|
const float FULL_CIRCLE = 360.0f;
|
||||||
const float SLICES = 180.0f; // The amount of segment to create the circle
|
const float SLICES = 180.0f; // The amount of segment to create the circle
|
||||||
|
@ -112,12 +122,6 @@ void Circle3DOverlay::render(RenderArgs* args) {
|
||||||
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z);
|
||||||
glScalef(dimensions.x, dimensions.y, 1.0f);
|
glScalef(dimensions.x, dimensions.y, 1.0f);
|
||||||
|
|
||||||
// Create the circle in the coordinates origin
|
|
||||||
float outerRadius = getOuterRadius();
|
|
||||||
float innerRadius = getInnerRadius(); // only used in solid case
|
|
||||||
float startAt = getStartAt();
|
|
||||||
float endAt = getEndAt();
|
|
||||||
|
|
||||||
glLineWidth(_lineWidth);
|
glLineWidth(_lineWidth);
|
||||||
|
|
||||||
GeometryCache::SharedPointer geometryCache = DependencyManager::get<GeometryCache>();
|
GeometryCache::SharedPointer geometryCache = DependencyManager::get<GeometryCache>();
|
||||||
|
@ -128,12 +132,8 @@ void Circle3DOverlay::render(RenderArgs* args) {
|
||||||
if (_quadVerticesID == GeometryCache::UNKNOWN_ID) {
|
if (_quadVerticesID == GeometryCache::UNKNOWN_ID) {
|
||||||
_quadVerticesID = geometryCache->allocateID();
|
_quadVerticesID = geometryCache->allocateID();
|
||||||
}
|
}
|
||||||
//glBegin(GL_QUAD_STRIP);
|
|
||||||
|
|
||||||
if (startAt != _lastStartAt || endAt != _lastEndAt ||
|
if (geometryChanged) {
|
||||||
innerRadius != _lastInnerRadius || outerRadius != _lastOuterRadius) {
|
|
||||||
|
|
||||||
geometryChanged = true;
|
|
||||||
|
|
||||||
QVector<glm::vec2> points;
|
QVector<glm::vec2> points;
|
||||||
|
|
||||||
|
@ -142,8 +142,6 @@ void Circle3DOverlay::render(RenderArgs* args) {
|
||||||
glm::vec2 firstInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius);
|
glm::vec2 firstInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius);
|
||||||
glm::vec2 firstOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
glm::vec2 firstOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
||||||
|
|
||||||
//glVertex2f(firstInnerPoint.x, firstInnerPoint.y);
|
|
||||||
//glVertex2f(firstOuterPoint.x, firstOuterPoint.y);
|
|
||||||
points << firstInnerPoint << firstOuterPoint;
|
points << firstInnerPoint << firstOuterPoint;
|
||||||
|
|
||||||
while (angle < endAt) {
|
while (angle < endAt) {
|
||||||
|
@ -151,9 +149,6 @@ void Circle3DOverlay::render(RenderArgs* args) {
|
||||||
glm::vec2 thisInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius);
|
glm::vec2 thisInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius);
|
||||||
glm::vec2 thisOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
glm::vec2 thisOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
||||||
|
|
||||||
//glVertex2f(thisOuterPoint.x, thisOuterPoint.y);
|
|
||||||
//glVertex2f(thisInnerPoint.x, thisInnerPoint.y);
|
|
||||||
|
|
||||||
points << thisOuterPoint << thisInnerPoint;
|
points << thisOuterPoint << thisInnerPoint;
|
||||||
|
|
||||||
angle += SLICE_ANGLE;
|
angle += SLICE_ANGLE;
|
||||||
|
@ -165,9 +160,6 @@ void Circle3DOverlay::render(RenderArgs* args) {
|
||||||
glm::vec2 lastInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius);
|
glm::vec2 lastInnerPoint(cos(angleInRadians) * innerRadius, sin(angleInRadians) * innerRadius);
|
||||||
glm::vec2 lastOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
glm::vec2 lastOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
||||||
|
|
||||||
//glVertex2f(lastOuterPoint.x, lastOuterPoint.y);
|
|
||||||
//glVertex2f(lastInnerPoint.x, lastInnerPoint.y);
|
|
||||||
|
|
||||||
points << lastOuterPoint << lastInnerPoint;
|
points << lastOuterPoint << lastInnerPoint;
|
||||||
|
|
||||||
geometryCache->updateVertices(_quadVerticesID, points);
|
geometryCache->updateVertices(_quadVerticesID, points);
|
||||||
|
@ -176,99 +168,119 @@ void Circle3DOverlay::render(RenderArgs* args) {
|
||||||
geometryCache->renderVertices(GL_QUAD_STRIP, _quadVerticesID);
|
geometryCache->renderVertices(GL_QUAD_STRIP, _quadVerticesID);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (getIsDashedLine()) {
|
if (_lineVerticesID == GeometryCache::UNKNOWN_ID) {
|
||||||
glBegin(GL_LINES);
|
_lineVerticesID = geometryCache->allocateID();
|
||||||
} else {
|
|
||||||
glBegin(GL_LINE_STRIP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float angle = startAt;
|
if (geometryChanged) {
|
||||||
float angleInRadians = glm::radians(angle);
|
QVector<glm::vec2> points;
|
||||||
glm::vec2 firstPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
|
||||||
glVertex2f(firstPoint.x, firstPoint.y);
|
float angle = startAt;
|
||||||
|
float angleInRadians = glm::radians(angle);
|
||||||
|
glm::vec2 firstPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
||||||
|
points << firstPoint;
|
||||||
|
|
||||||
while (angle < endAt) {
|
while (angle < endAt) {
|
||||||
angle += SLICE_ANGLE;
|
angle += SLICE_ANGLE;
|
||||||
angleInRadians = glm::radians(angle);
|
|
||||||
glm::vec2 thisPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
|
||||||
glVertex2f(thisPoint.x, thisPoint.y);
|
|
||||||
|
|
||||||
if (getIsDashedLine()) {
|
|
||||||
angle += SLICE_ANGLE / 2.0f; // short gap
|
|
||||||
angleInRadians = glm::radians(angle);
|
angleInRadians = glm::radians(angle);
|
||||||
glm::vec2 dashStartPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
glm::vec2 thisPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
||||||
glVertex2f(dashStartPoint.x, dashStartPoint.y);
|
points << thisPoint;
|
||||||
|
|
||||||
|
if (getIsDashedLine()) {
|
||||||
|
angle += SLICE_ANGLE / 2.0f; // short gap
|
||||||
|
angleInRadians = glm::radians(angle);
|
||||||
|
glm::vec2 dashStartPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
||||||
|
points << dashStartPoint;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// get the last slice portion....
|
// get the last slice portion....
|
||||||
angle = endAt;
|
angle = endAt;
|
||||||
angleInRadians = glm::radians(angle);
|
angleInRadians = glm::radians(angle);
|
||||||
glm::vec2 lastOuterPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
glm::vec2 lastPoint(cos(angleInRadians) * outerRadius, sin(angleInRadians) * outerRadius);
|
||||||
glVertex2f(lastOuterPoint.x, lastOuterPoint.y);
|
points << lastPoint;
|
||||||
glEnd();
|
|
||||||
|
geometryCache->updateVertices(_lineVerticesID, points);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getIsDashedLine()) {
|
||||||
|
geometryCache->renderVertices(GL_LINES, _lineVerticesID);
|
||||||
|
} else {
|
||||||
|
geometryCache->renderVertices(GL_LINE_STRIP, _lineVerticesID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw our tick marks
|
// draw our tick marks
|
||||||
// for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise
|
// for our overlay, is solid means we draw a ring between the inner and outer radius of the circle, otherwise
|
||||||
// we just draw a line...
|
// we just draw a line...
|
||||||
if (getHasTickMarks()) {
|
if (getHasTickMarks()) {
|
||||||
glBegin(GL_LINES);
|
|
||||||
|
|
||||||
// draw our major tick marks
|
if (_majorTicksVerticesID == GeometryCache::UNKNOWN_ID) {
|
||||||
if (getMajorTickMarksAngle() > 0.0f && getMajorTickMarksLength() != 0.0f) {
|
_majorTicksVerticesID = geometryCache->allocateID();
|
||||||
|
}
|
||||||
xColor color = getMajorTickMarksColor();
|
if (_minorTicksVerticesID == GeometryCache::UNKNOWN_ID) {
|
||||||
glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
_minorTicksVerticesID = geometryCache->allocateID();
|
||||||
|
|
||||||
float tickMarkAngle = getMajorTickMarksAngle();
|
|
||||||
float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle;
|
|
||||||
float angleInRadians = glm::radians(angle);
|
|
||||||
float tickMarkLength = getMajorTickMarksLength();
|
|
||||||
float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius;
|
|
||||||
float endRadius = startRadius + tickMarkLength;
|
|
||||||
|
|
||||||
while (angle <= endAt) {
|
|
||||||
angleInRadians = glm::radians(angle);
|
|
||||||
|
|
||||||
glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius);
|
|
||||||
glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius);
|
|
||||||
|
|
||||||
glVertex2f(thisPointA.x, thisPointA.y);
|
|
||||||
glVertex2f(thisPointB.x, thisPointB.y);
|
|
||||||
|
|
||||||
angle += tickMarkAngle;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw our minor tick marks
|
if (geometryChanged) {
|
||||||
if (getMinorTickMarksAngle() > 0.0f && getMinorTickMarksLength() != 0.0f) {
|
QVector<glm::vec2> majorPoints;
|
||||||
|
QVector<glm::vec2> minorPoints;
|
||||||
xColor color = getMinorTickMarksColor();
|
|
||||||
glColor4f(color.red / MAX_COLOR, color.green / MAX_COLOR, color.blue / MAX_COLOR, alpha);
|
|
||||||
|
|
||||||
float tickMarkAngle = getMinorTickMarksAngle();
|
|
||||||
float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle;
|
|
||||||
float angleInRadians = glm::radians(angle);
|
|
||||||
float tickMarkLength = getMinorTickMarksLength();
|
|
||||||
float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius;
|
|
||||||
float endRadius = startRadius + tickMarkLength;
|
|
||||||
|
|
||||||
while (angle <= endAt) {
|
// draw our major tick marks
|
||||||
angleInRadians = glm::radians(angle);
|
if (getMajorTickMarksAngle() > 0.0f && getMajorTickMarksLength() != 0.0f) {
|
||||||
|
|
||||||
glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius);
|
|
||||||
glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius);
|
|
||||||
|
|
||||||
glVertex2f(thisPointA.x, thisPointA.y);
|
|
||||||
glVertex2f(thisPointB.x, thisPointB.y);
|
|
||||||
|
|
||||||
angle += tickMarkAngle;
|
float tickMarkAngle = getMajorTickMarksAngle();
|
||||||
|
float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle;
|
||||||
|
float angleInRadians = glm::radians(angle);
|
||||||
|
float tickMarkLength = getMajorTickMarksLength();
|
||||||
|
float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius;
|
||||||
|
float endRadius = startRadius + tickMarkLength;
|
||||||
|
|
||||||
|
while (angle <= endAt) {
|
||||||
|
angleInRadians = glm::radians(angle);
|
||||||
|
|
||||||
|
glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius);
|
||||||
|
glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius);
|
||||||
|
|
||||||
|
majorPoints << thisPointA << thisPointB;
|
||||||
|
|
||||||
|
angle += tickMarkAngle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// draw our minor tick marks
|
||||||
|
if (getMinorTickMarksAngle() > 0.0f && getMinorTickMarksLength() != 0.0f) {
|
||||||
|
|
||||||
|
float tickMarkAngle = getMinorTickMarksAngle();
|
||||||
|
float angle = startAt - fmod(startAt, tickMarkAngle) + tickMarkAngle;
|
||||||
|
float angleInRadians = glm::radians(angle);
|
||||||
|
float tickMarkLength = getMinorTickMarksLength();
|
||||||
|
float startRadius = (tickMarkLength > 0.0f) ? innerRadius : outerRadius;
|
||||||
|
float endRadius = startRadius + tickMarkLength;
|
||||||
|
|
||||||
|
while (angle <= endAt) {
|
||||||
|
angleInRadians = glm::radians(angle);
|
||||||
|
|
||||||
|
glm::vec2 thisPointA(cos(angleInRadians) * startRadius, sin(angleInRadians) * startRadius);
|
||||||
|
glm::vec2 thisPointB(cos(angleInRadians) * endRadius, sin(angleInRadians) * endRadius);
|
||||||
|
|
||||||
|
minorPoints << thisPointA << thisPointB;
|
||||||
|
|
||||||
|
angle += tickMarkAngle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
geometryCache->updateVertices(_majorTicksVerticesID, majorPoints);
|
||||||
|
geometryCache->updateVertices(_minorTicksVerticesID, minorPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnd();
|
xColor majorColor = getMajorTickMarksColor();
|
||||||
|
glColor4f(majorColor.red / MAX_COLOR, majorColor.green / MAX_COLOR, majorColor.blue / MAX_COLOR, alpha);
|
||||||
|
geometryCache->renderVertices(GL_LINES, _majorTicksVerticesID);
|
||||||
|
|
||||||
|
xColor minorColor = getMinorTickMarksColor();
|
||||||
|
glColor4f(minorColor.red / MAX_COLOR, minorColor.green / MAX_COLOR, minorColor.blue / MAX_COLOR, alpha);
|
||||||
|
geometryCache->renderVertices(GL_LINES, _minorTicksVerticesID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,8 @@ protected:
|
||||||
|
|
||||||
int _quadVerticesID;
|
int _quadVerticesID;
|
||||||
int _lineVerticesID;
|
int _lineVerticesID;
|
||||||
int _ticksVerticesID;
|
int _majorTicksVerticesID;
|
||||||
|
int _minorTicksVerticesID;
|
||||||
|
|
||||||
float _lastStartAt;
|
float _lastStartAt;
|
||||||
float _lastEndAt;
|
float _lastEndAt;
|
||||||
|
|
Loading…
Reference in a new issue