mirror of
https://github.com/lubosz/overte.git
synced 2025-04-25 00:03:16 +02:00
Use cache ID when rendering talk bubble sphere
This commit is contained in:
parent
cfa6352c3a
commit
21f12c1d6c
4 changed files with 91 additions and 20 deletions
|
@ -77,7 +77,8 @@ Avatar::Avatar() :
|
|||
_moving(false),
|
||||
_collisionGroups(0),
|
||||
_initialized(false),
|
||||
_shouldRenderBillboard(true)
|
||||
_shouldRenderBillboard(true),
|
||||
_voiceSphereID(GeometryCache::UNKNOWN_ID)
|
||||
{
|
||||
// we may have been created in the network thread, but we live in the main thread
|
||||
moveToThread(Application::getInstance()->thread());
|
||||
|
@ -439,8 +440,13 @@ void Avatar::render(const glm::vec3& cameraPosition, RenderMode renderMode, bool
|
|||
glPushMatrix();
|
||||
glTranslatef(_position.x, _position.y, _position.z);
|
||||
glScalef(height, height, height);
|
||||
|
||||
if (_voiceSphereID == GeometryCache::UNKNOWN_ID) {
|
||||
_voiceSphereID = DependencyManager::get<GeometryCache>()->allocateID();
|
||||
}
|
||||
DependencyManager::get<GeometryCache>()->renderSphere(sphereRadius, 15, 15,
|
||||
glm::vec4(SPHERE_COLOR[0], SPHERE_COLOR[1], SPHERE_COLOR[2], 1.0f - angle / MAX_SPHERE_ANGLE));
|
||||
glm::vec4(SPHERE_COLOR[0], SPHERE_COLOR[1], SPHERE_COLOR[2], 1.0f - angle / MAX_SPHERE_ANGLE), true,
|
||||
_voiceSphereID);
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
|
|
|
@ -243,6 +243,8 @@ private:
|
|||
float getBillboardSize() const;
|
||||
|
||||
static int _jointConesID;
|
||||
|
||||
int _voiceSphereID;
|
||||
};
|
||||
|
||||
#endif // hifi_Avatar_h
|
||||
|
|
|
@ -53,18 +53,33 @@ const int NUM_COORDS_PER_VERTEX = 3;
|
|||
const int NUM_BYTES_PER_VERTEX = NUM_COORDS_PER_VERTEX * sizeof(GLfloat);
|
||||
const int NUM_BYTES_PER_INDEX = sizeof(GLushort);
|
||||
|
||||
void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid) {
|
||||
void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid, int id) {
|
||||
bool registered = (id != UNKNOWN_ID);
|
||||
|
||||
Vec2Pair radiusKey(glm::vec2(radius, slices), glm::vec2(stacks, 0));
|
||||
IntPair slicesStacksKey(slices, stacks);
|
||||
Vec3Pair colorKey(glm::vec3(color.x, color.y, slices), glm::vec3(color.z, color.y, stacks));
|
||||
Vec3Pair colorKey(glm::vec3(color.x, color.y, slices), glm::vec3(color.z, color.w, stacks));
|
||||
|
||||
int vertices = slices * (stacks - 1) + 2;
|
||||
int indices = slices * (stacks - 1) * NUM_VERTICES_PER_TRIANGULATED_QUAD;
|
||||
|
||||
if (!_sphereVertices.contains(radiusKey)) {
|
||||
if (registered && (!_registeredSphereVertices.contains(id) || _lastRegisteredSphereVertices[id] != radiusKey)
|
||||
|| !registered && !_sphereVertices.contains(radiusKey)) {
|
||||
|
||||
if (registered && _registeredSphereVertices.contains(id)) {
|
||||
_registeredSphereVertices[id].clear();
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << "renderSphere()... RELEASING REGISTERED VERTICES BUFFER";
|
||||
#endif
|
||||
}
|
||||
|
||||
gpu::BufferPointer verticesBuffer(new gpu::Buffer());
|
||||
_sphereVertices[radiusKey] = verticesBuffer;
|
||||
if (registered) {
|
||||
_registeredSphereVertices[id] = verticesBuffer;
|
||||
_lastRegisteredSphereVertices[id] = radiusKey;
|
||||
} else {
|
||||
_sphereVertices[radiusKey] = verticesBuffer;
|
||||
}
|
||||
|
||||
GLfloat* vertexData = new GLfloat[vertices * NUM_COORDS_PER_VERTEX];
|
||||
GLfloat* vertex = vertexData;
|
||||
|
@ -106,10 +121,29 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm
|
|||
qDebug() << " _sphereVertices.size():" << _sphereVertices.size();
|
||||
#endif
|
||||
}
|
||||
#ifdef WANT_DEBUG
|
||||
else if (registered) {
|
||||
qDebug() << "renderSphere()... REUSING PREVIOUSLY REGISTERED VERTICES BUFFER";
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!_sphereIndices.contains(slicesStacksKey)) {
|
||||
if (registered && (!_registeredSphereIndices.contains(id) || _lastRegisteredSphereIndices[id] != slicesStacksKey)
|
||||
|| !registered && !_sphereIndices.contains(slicesStacksKey)) {
|
||||
|
||||
if (registered && _registeredSphereIndices.contains(id)) {
|
||||
_registeredSphereIndices[id].clear();
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << "renderSphere()... RELEASING REGISTERED INDICES BUFFER";
|
||||
#endif
|
||||
}
|
||||
|
||||
gpu::BufferPointer indicesBuffer(new gpu::Buffer());
|
||||
_sphereIndices[slicesStacksKey] = indicesBuffer;
|
||||
if (registered) {
|
||||
_registeredSphereIndices[id] = indicesBuffer;
|
||||
_lastRegisteredSphereIndices[id] = slicesStacksKey;
|
||||
} else {
|
||||
_sphereIndices[slicesStacksKey] = indicesBuffer;
|
||||
}
|
||||
|
||||
GLushort* indexData = new GLushort[indices];
|
||||
GLushort* index = indexData;
|
||||
|
@ -164,7 +198,7 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm
|
|||
delete[] indexData;
|
||||
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << "GeometryCache::renderSphere()... --- CREATING INDEX BUFFER";
|
||||
qDebug() << "GeometryCache::renderSphere()... --- CREATING INDICES BUFFER";
|
||||
qDebug() << " radius:" << radius;
|
||||
qDebug() << " slices:" << slices;
|
||||
qDebug() << " stacks:" << stacks;
|
||||
|
@ -173,10 +207,29 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm
|
|||
qDebug() << " _sphereIndices.size():" << _sphereIndices.size();
|
||||
#endif
|
||||
}
|
||||
#ifdef WANT_DEBUG
|
||||
else if (registered) {
|
||||
qDebug() << "renderSphere()... REUSING PREVIOUSLY REGISTERED INDICES BUFFER";
|
||||
}
|
||||
#endif
|
||||
|
||||
if (registered && (!_registeredSphereColors.contains(id) || _lastRegisteredSphereColors[id] != colorKey)
|
||||
|| !registered && !_sphereColors.contains(colorKey)) {
|
||||
|
||||
if (registered && _registeredSphereColors.contains(id)) {
|
||||
_registeredSphereColors[id].clear();
|
||||
#ifdef WANT_DEBUG
|
||||
qDebug() << "renderSphere()... RELEASING REGISTERED COLORS BUFFER";
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!_sphereColors.contains(colorKey)) {
|
||||
gpu::BufferPointer colorBuffer(new gpu::Buffer());
|
||||
_sphereColors[colorKey] = colorBuffer;
|
||||
if (registered) {
|
||||
_registeredSphereColors[id] = colorBuffer;
|
||||
_lastRegisteredSphereColors[id] = colorKey;
|
||||
} else {
|
||||
_sphereColors[colorKey] = colorBuffer;
|
||||
}
|
||||
|
||||
int compactColor = ((int(color.x * 255.0f) & 0xFF)) |
|
||||
((int(color.y * 255.0f) & 0xFF) << 8) |
|
||||
|
@ -201,11 +254,16 @@ void GeometryCache::renderSphere(float radius, int slices, int stacks, const glm
|
|||
qDebug() << " stacks:" << stacks;
|
||||
qDebug() << " _sphereColors.size():" << _sphereColors.size();
|
||||
#endif
|
||||
|
||||
}
|
||||
gpu::BufferPointer verticesBuffer = _sphereVertices[radiusKey];
|
||||
gpu::BufferPointer indicesBuffer = _sphereIndices[slicesStacksKey];
|
||||
gpu::BufferPointer colorBuffer = _sphereColors[colorKey];
|
||||
#ifdef WANT_DEBUG
|
||||
else if (registered) {
|
||||
qDebug() << "renderSphere()... REUSING PREVIOUSLY REGISTERED COLORS BUFFER";
|
||||
}
|
||||
#endif
|
||||
|
||||
gpu::BufferPointer verticesBuffer = registered ? _registeredSphereVertices[id] : _sphereVertices[radiusKey];
|
||||
gpu::BufferPointer indicesBuffer = registered ? _registeredSphereIndices[id] : _sphereIndices[slicesStacksKey];
|
||||
gpu::BufferPointer colorBuffer = registered ? _registeredSphereColors[id] : _sphereColors[colorKey];
|
||||
|
||||
const int VERTICES_SLOT = 0;
|
||||
const int NORMALS_SLOT = 1;
|
||||
|
|
|
@ -134,10 +134,10 @@ public:
|
|||
|
||||
void renderCone(float base, float height, int slices, int stacks);
|
||||
|
||||
void renderSphere(float radius, int slices, int stacks, const glm::vec3& color, bool solid = true)
|
||||
{ renderSphere(radius, slices, stacks, glm::vec4(color, 1.0f), solid); }
|
||||
void renderSphere(float radius, int slices, int stacks, const glm::vec3& color, bool solid = true, int id = UNKNOWN_ID)
|
||||
{ renderSphere(radius, slices, stacks, glm::vec4(color, 1.0f), solid, id); }
|
||||
|
||||
void renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid = true);
|
||||
void renderSphere(float radius, int slices, int stacks, const glm::vec4& color, bool solid = true, int id = UNKNOWN_ID);
|
||||
void renderGrid(int xDivisions, int yDivisions, const glm::vec4& color);
|
||||
void renderGrid(int x, int y, int width, int height, int rows, int cols, const glm::vec4& color, int id = UNKNOWN_ID);
|
||||
void renderSolidCube(float size, const glm::vec4& color);
|
||||
|
@ -290,10 +290,15 @@ private:
|
|||
QHash<Vec3Pair, gpu::BufferPointer> _gridColors;
|
||||
|
||||
QHash<Vec2Pair, gpu::BufferPointer> _sphereVertices;
|
||||
QHash<int, gpu::BufferPointer> _registeredSphereVertices;
|
||||
QHash<int, Vec2Pair> _lastRegisteredSphereVertices;
|
||||
QHash<IntPair, gpu::BufferPointer> _sphereIndices;
|
||||
QHash<int, gpu::BufferPointer> _registeredSphereIndices;
|
||||
QHash<int, IntPair> _lastRegisteredSphereIndices;
|
||||
QHash<Vec3Pair, gpu::BufferPointer> _sphereColors;
|
||||
|
||||
|
||||
QHash<int, gpu::BufferPointer> _registeredSphereColors;
|
||||
QHash<int, Vec3Pair> _lastRegisteredSphereColors;
|
||||
|
||||
QHash<QUrl, QWeakPointer<NetworkGeometry> > _networkGeometry;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue