mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 21:56:14 +02:00
implement color for dashed lines
This commit is contained in:
parent
018b38e56d
commit
5d2df7b03f
2 changed files with 48 additions and 28 deletions
|
@ -1369,13 +1369,13 @@ void GeometryCache::renderQuad(const glm::vec3& topLeft, const glm::vec3& bottom
|
||||||
// TODO: switch this over to use BatchItemDetails like the other line and vertices functions
|
// TODO: switch this over to use BatchItemDetails like the other line and vertices functions
|
||||||
void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) {
|
void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& end, const glm::vec4& color, int id) {
|
||||||
bool registered = (id != UNKNOWN_ID);
|
bool registered = (id != UNKNOWN_ID);
|
||||||
Vec3Pair key(start, end);
|
Vec3PairVec2Pair key(Vec3Pair(start, end), Vec2Pair(glm::vec2(color.x, color.y), glm::vec2(color.z, color.w)));
|
||||||
BufferDetails& details = registered ? _registeredDashedLines[id] : _dashedLines[key];
|
BatchItemDetails& details = registered ? _registeredDashedLines[id] : _dashedLines[key];
|
||||||
|
|
||||||
// if this is a registered , and we have buffers, then check to see if the geometry changed and rebuild if needed
|
// if this is a registered , and we have buffers, then check to see if the geometry changed and rebuild if needed
|
||||||
if (registered && details.buffer.isCreated()) {
|
if (registered && details.isCreated) {
|
||||||
if (_lastRegisteredDashedLines[id] != key) {
|
if (_lastRegisteredDashedLines[id] != key) {
|
||||||
details.buffer.destroy();
|
details.clear();
|
||||||
_lastRegisteredDashedLines[id] = key;
|
_lastRegisteredDashedLines[id] = key;
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
qDebug() << "renderDashedLine()... RELEASING REGISTERED";
|
qDebug() << "renderDashedLine()... RELEASING REGISTERED";
|
||||||
|
@ -1383,14 +1383,13 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!details.buffer.isCreated()) {
|
if (!details.isCreated) {
|
||||||
|
|
||||||
int compactColor = ((int(color.x * 255.0f) & 0xFF)) |
|
int compactColor = ((int(color.x * 255.0f) & 0xFF)) |
|
||||||
((int(color.y * 255.0f) & 0xFF) << 8) |
|
((int(color.y * 255.0f) & 0xFF) << 8) |
|
||||||
((int(color.z * 255.0f) & 0xFF) << 16) |
|
((int(color.z * 255.0f) & 0xFF) << 16) |
|
||||||
((int(color.w * 255.0f) & 0xFF) << 24);
|
((int(color.w * 255.0f) & 0xFF) << 24);
|
||||||
|
|
||||||
|
|
||||||
// draw each line segment with appropriate gaps
|
// draw each line segment with appropriate gaps
|
||||||
const float DASH_LENGTH = 0.05f;
|
const float DASH_LENGTH = 0.05f;
|
||||||
const float GAP_LENGTH = 0.025f;
|
const float GAP_LENGTH = 0.025f;
|
||||||
|
@ -1406,6 +1405,26 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en
|
||||||
const int FLOATS_PER_VERTEX = 3;
|
const int FLOATS_PER_VERTEX = 3;
|
||||||
details.vertices = (segmentCountFloor + 1) * 2;
|
details.vertices = (segmentCountFloor + 1) * 2;
|
||||||
details.vertexSize = FLOATS_PER_VERTEX;
|
details.vertexSize = FLOATS_PER_VERTEX;
|
||||||
|
details.isCreated = true;
|
||||||
|
|
||||||
|
gpu::BufferPointer verticesBuffer(new gpu::Buffer());
|
||||||
|
gpu::BufferPointer colorBuffer(new gpu::Buffer());
|
||||||
|
gpu::Stream::FormatPointer streamFormat(new gpu::Stream::Format());
|
||||||
|
gpu::BufferStreamPointer stream(new gpu::BufferStream());
|
||||||
|
|
||||||
|
details.verticesBuffer = verticesBuffer;
|
||||||
|
details.colorBuffer = colorBuffer;
|
||||||
|
details.streamFormat = streamFormat;
|
||||||
|
details.stream = stream;
|
||||||
|
|
||||||
|
details.streamFormat->setAttribute(gpu::Stream::POSITION, 0, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0);
|
||||||
|
details.streamFormat->setAttribute(gpu::Stream::COLOR, 1, gpu::Element(gpu::VEC4, gpu::UINT8, gpu::RGBA));
|
||||||
|
|
||||||
|
details.stream->addBuffer(details.verticesBuffer, 0, details.streamFormat->getChannels().at(0)._stride);
|
||||||
|
details.stream->addBuffer(details.colorBuffer, 0, details.streamFormat->getChannels().at(1)._stride);
|
||||||
|
|
||||||
|
int* colorData = new int[details.vertices];
|
||||||
|
int* colorDataAt = colorData;
|
||||||
|
|
||||||
GLfloat* vertexData = new GLfloat[details.vertices * FLOATS_PER_VERTEX];
|
GLfloat* vertexData = new GLfloat[details.vertices * FLOATS_PER_VERTEX];
|
||||||
GLfloat* vertex = vertexData;
|
GLfloat* vertex = vertexData;
|
||||||
|
@ -1414,27 +1433,30 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en
|
||||||
*(vertex++) = point.x;
|
*(vertex++) = point.x;
|
||||||
*(vertex++) = point.y;
|
*(vertex++) = point.y;
|
||||||
*(vertex++) = point.z;
|
*(vertex++) = point.z;
|
||||||
|
*(colorDataAt++) = compactColor;
|
||||||
|
|
||||||
for (int i = 0; i < segmentCountFloor; i++) {
|
for (int i = 0; i < segmentCountFloor; i++) {
|
||||||
point += dashVector;
|
point += dashVector;
|
||||||
*(vertex++) = point.x;
|
*(vertex++) = point.x;
|
||||||
*(vertex++) = point.y;
|
*(vertex++) = point.y;
|
||||||
*(vertex++) = point.z;
|
*(vertex++) = point.z;
|
||||||
|
*(colorDataAt++) = compactColor;
|
||||||
|
|
||||||
point += gapVector;
|
point += gapVector;
|
||||||
*(vertex++) = point.x;
|
*(vertex++) = point.x;
|
||||||
*(vertex++) = point.y;
|
*(vertex++) = point.y;
|
||||||
*(vertex++) = point.z;
|
*(vertex++) = point.z;
|
||||||
|
*(colorDataAt++) = compactColor;
|
||||||
}
|
}
|
||||||
*(vertex++) = end.x;
|
*(vertex++) = end.x;
|
||||||
*(vertex++) = end.y;
|
*(vertex++) = end.y;
|
||||||
*(vertex++) = end.z;
|
*(vertex++) = end.z;
|
||||||
|
*(colorDataAt++) = compactColor;
|
||||||
|
|
||||||
details.buffer.create();
|
details.verticesBuffer->append(sizeof(GLfloat) * FLOATS_PER_VERTEX * details.vertices, (gpu::Buffer::Byte*) vertexData);
|
||||||
details.buffer.setUsagePattern(QOpenGLBuffer::StaticDraw);
|
details.colorBuffer->append(sizeof(int) * details.vertices, (gpu::Buffer::Byte*) colorData);
|
||||||
details.buffer.bind();
|
|
||||||
details.buffer.allocate(vertexData, details.vertices * FLOATS_PER_VERTEX * sizeof(GLfloat));
|
|
||||||
delete[] vertexData;
|
delete[] vertexData;
|
||||||
|
delete[] colorData;
|
||||||
|
|
||||||
#ifdef WANT_DEBUG
|
#ifdef WANT_DEBUG
|
||||||
if (registered) {
|
if (registered) {
|
||||||
|
@ -1443,15 +1465,20 @@ void GeometryCache::renderDashedLine(const glm::vec3& start, const glm::vec3& en
|
||||||
qDebug() << "new dashed lines buffer made -- _dashedLines:" << _dashedLines.size();
|
qDebug() << "new dashed lines buffer made -- _dashedLines:" << _dashedLines.size();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else {
|
|
||||||
details.buffer.bind();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glEnableClientState(GL_VERTEX_ARRAY);
|
gpu::Batch batch;
|
||||||
glVertexPointer(details.vertexSize, GL_FLOAT, 0, 0);
|
|
||||||
glDrawArrays(GL_LINES, 0, details.vertices);
|
batch.setInputFormat(details.streamFormat);
|
||||||
|
batch.setInputStream(0, *details.stream);
|
||||||
|
batch.draw(gpu::LINES, details.vertices, 0);
|
||||||
|
|
||||||
|
gpu::GLBackend::renderBatch(batch);
|
||||||
|
|
||||||
glDisableClientState(GL_VERTEX_ARRAY);
|
glDisableClientState(GL_VERTEX_ARRAY);
|
||||||
details.buffer.release();
|
glDisableClientState(GL_COLOR_ARRAY);
|
||||||
|
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -202,12 +202,7 @@ private:
|
||||||
void clear();
|
void clear();
|
||||||
};
|
};
|
||||||
|
|
||||||
QHash<IntPair, VerticesIndices> _sphereVBOs;
|
|
||||||
QHash<IntPair, VerticesIndices> _coneVBOs;
|
QHash<IntPair, VerticesIndices> _coneVBOs;
|
||||||
QHash<float, VerticesIndices> _wireCubeVBOs;
|
|
||||||
QHash<float, VerticesIndices> _solidCubeVBOs;
|
|
||||||
QHash<Vec2Pair, VerticesIndices> _quad2DVBOs;
|
|
||||||
QHash<Vec2PairPair, BatchItemDetails> _quad2DTextureVBOs;
|
|
||||||
QHash<Vec3PairVec2Pair, VerticesIndices> _quad3DTextureVBOs;
|
QHash<Vec3PairVec2Pair, VerticesIndices> _quad3DTextureVBOs;
|
||||||
QHash<int, VerticesIndices> _registeredQuadVBOs;
|
QHash<int, VerticesIndices> _registeredQuadVBOs;
|
||||||
int _nextID;
|
int _nextID;
|
||||||
|
@ -241,11 +236,9 @@ private:
|
||||||
|
|
||||||
QHash<int, BatchItemDetails> _registeredVertices;
|
QHash<int, BatchItemDetails> _registeredVertices;
|
||||||
|
|
||||||
QHash<int, Vec3Pair> _lastRegisteredDashedLines;
|
QHash<int, Vec3PairVec2Pair> _lastRegisteredDashedLines;
|
||||||
QHash<Vec3Pair, BufferDetails> _dashedLines;
|
QHash<Vec3PairVec2Pair, BatchItemDetails> _dashedLines;
|
||||||
QHash<int, BufferDetails> _registeredDashedLines;
|
QHash<int, BatchItemDetails> _registeredDashedLines;
|
||||||
|
|
||||||
QHash<IntPair, BufferDetails> _colors;
|
|
||||||
|
|
||||||
QHash<IntPair, gpu::BufferPointer> _gridBuffers;
|
QHash<IntPair, gpu::BufferPointer> _gridBuffers;
|
||||||
QHash<int, gpu::BufferPointer> _registeredAlternateGridBuffers;
|
QHash<int, gpu::BufferPointer> _registeredAlternateGridBuffers;
|
||||||
|
@ -281,7 +274,7 @@ public:
|
||||||
|
|
||||||
const FBXGeometry& getFBXGeometry() const { return _geometry; }
|
const FBXGeometry& getFBXGeometry() const { return _geometry; }
|
||||||
const QVector<NetworkMesh>& getMeshes() const { return _meshes; }
|
const QVector<NetworkMesh>& getMeshes() const { return _meshes; }
|
||||||
|
//
|
||||||
QVector<int> getJointMappings(const AnimationPointer& animation);
|
QVector<int> getJointMappings(const AnimationPointer& animation);
|
||||||
|
|
||||||
virtual void setLoadPriority(const QPointer<QObject>& owner, float priority);
|
virtual void setLoadPriority(const QPointer<QObject>& owner, float priority);
|
||||||
|
|
Loading…
Reference in a new issue