mirror of
https://github.com/overte-org/overte.git
synced 2025-08-16 11:32:22 +02:00
Fixed avatar related files memory wastes
This commit is contained in:
parent
e124c164c1
commit
688bc17954
12 changed files with 153 additions and 114 deletions
|
@ -38,6 +38,10 @@ Balls::Balls(int numberOfBalls) {
|
|||
_origin = glm::vec3(0, 0, 0);
|
||||
}
|
||||
|
||||
Balls::~Balls() {
|
||||
delete[] _balls;
|
||||
}
|
||||
|
||||
void Balls::moveOrigin(const glm::vec3& newOrigin) {
|
||||
glm::vec3 delta = newOrigin - _origin;
|
||||
if (glm::length(delta) > EPSILON) {
|
||||
|
|
|
@ -14,6 +14,7 @@ const int NUMBER_SPRINGS = 4;
|
|||
class Balls {
|
||||
public:
|
||||
Balls(int numberOfBalls);
|
||||
~Balls();
|
||||
|
||||
void simulate(float deltaTime);
|
||||
void render();
|
||||
|
|
|
@ -31,6 +31,9 @@ struct ViewFrustumOffset {
|
|||
float up;
|
||||
};
|
||||
|
||||
class BandwidthDialog;
|
||||
class VoxelStatsDialog;
|
||||
|
||||
class Menu : public QMenuBar {
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
@ -125,6 +125,12 @@ VoxelSystem::~VoxelSystem() {
|
|||
pthread_mutex_destroy(&_bufferWriteLock);
|
||||
pthread_mutex_destroy(&_treeLock);
|
||||
|
||||
// Destroy glBuffers
|
||||
glDeleteBuffers(1, &_vboVerticesID);
|
||||
glDeleteBuffers(1, &_vboNormalsID);
|
||||
glDeleteBuffers(1, &_vboColorsID);
|
||||
glDeleteBuffers(1, &_vboIndicesID);
|
||||
|
||||
VoxelNode::removeDeleteHook(this);
|
||||
}
|
||||
|
||||
|
@ -532,9 +538,15 @@ glm::vec3 VoxelSystem::computeVoxelVertex(const glm::vec3& startVertex, float vo
|
|||
return startVertex + glm::vec3(identityVertex[0], identityVertex[1], identityVertex[2]) * voxelScale;
|
||||
}
|
||||
|
||||
ProgramObject* VoxelSystem::_perlinModulateProgram = 0;
|
||||
bool VoxelSystem::_perlinModulateProgramInitialized = false;
|
||||
ProgramObject VoxelSystem::_perlinModulateProgram;
|
||||
|
||||
void VoxelSystem::init() {
|
||||
if (_initialized) {
|
||||
qDebug("[ERROR] VoxelSystem is already initialized.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
_callsToTreesToArrays = 0;
|
||||
_setupNewVoxelsForDrawingLastFinished = 0;
|
||||
_setupNewVoxelsForDrawingLastElapsed = 0;
|
||||
|
@ -545,19 +557,6 @@ void VoxelSystem::init() {
|
|||
_voxelsInWriteArrays = 0;
|
||||
_voxelsInReadArrays = 0;
|
||||
|
||||
// we will track individual dirty sections with these arrays of bools
|
||||
_writeVoxelDirtyArray = new bool[_maxVoxels];
|
||||
memset(_writeVoxelDirtyArray, false, _maxVoxels * sizeof(bool));
|
||||
_readVoxelDirtyArray = new bool[_maxVoxels];
|
||||
memset(_readVoxelDirtyArray, false, _maxVoxels * sizeof(bool));
|
||||
|
||||
// prep the data structures for incoming voxel data
|
||||
_writeVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
|
||||
_readVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
|
||||
|
||||
_writeColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
|
||||
_readColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
|
||||
|
||||
GLuint* indicesArray = new GLuint[INDICES_PER_VOXEL * _maxVoxels];
|
||||
|
||||
// populate the indicesArray
|
||||
|
@ -611,20 +610,35 @@ void VoxelSystem::init() {
|
|||
// delete the indices and normals arrays that are no longer needed
|
||||
delete[] indicesArray;
|
||||
delete[] normalsArray;
|
||||
|
||||
|
||||
|
||||
// we will track individual dirty sections with these arrays of bools
|
||||
_writeVoxelDirtyArray = new bool[_maxVoxels];
|
||||
memset(_writeVoxelDirtyArray, false, _maxVoxels * sizeof(bool));
|
||||
_readVoxelDirtyArray = new bool[_maxVoxels];
|
||||
memset(_readVoxelDirtyArray, false, _maxVoxels * sizeof(bool));
|
||||
|
||||
// prep the data structures for incoming voxel data
|
||||
_writeVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
|
||||
_readVerticesArray = new GLfloat[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
|
||||
|
||||
_writeColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
|
||||
_readColorsArray = new GLubyte[VERTEX_POINTS_PER_VOXEL * _maxVoxels];
|
||||
|
||||
|
||||
// create our simple fragment shader if we're the first system to init
|
||||
if (_perlinModulateProgram != 0) {
|
||||
return;
|
||||
if (!_perlinModulateProgramInitialized) {
|
||||
switchToResourcesParentIfRequired();
|
||||
_perlinModulateProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/perlin_modulate.vert");
|
||||
_perlinModulateProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/perlin_modulate.frag");
|
||||
_perlinModulateProgram.link();
|
||||
|
||||
_perlinModulateProgram.bind();
|
||||
_perlinModulateProgram.setUniformValue("permutationNormalTexture", 0);
|
||||
_perlinModulateProgram.release();
|
||||
|
||||
_perlinModulateProgramInitialized = true;
|
||||
}
|
||||
switchToResourcesParentIfRequired();
|
||||
_perlinModulateProgram = new ProgramObject();
|
||||
_perlinModulateProgram->addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/perlin_modulate.vert");
|
||||
_perlinModulateProgram->addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/perlin_modulate.frag");
|
||||
_perlinModulateProgram->link();
|
||||
|
||||
_perlinModulateProgram->bind();
|
||||
_perlinModulateProgram->setUniformValue("permutationNormalTexture", 0);
|
||||
_perlinModulateProgram->release();
|
||||
}
|
||||
|
||||
void VoxelSystem::updateFullVBOs() {
|
||||
|
@ -749,7 +763,7 @@ void VoxelSystem::applyScaleAndBindProgram(bool texture) {
|
|||
glScalef(_treeScale, _treeScale, _treeScale);
|
||||
|
||||
if (texture) {
|
||||
_perlinModulateProgram->bind();
|
||||
_perlinModulateProgram.bind();
|
||||
glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPermutationNormalTextureID());
|
||||
}
|
||||
}
|
||||
|
@ -759,7 +773,7 @@ void VoxelSystem::removeScaleAndReleaseProgram(bool texture) {
|
|||
glPopMatrix();
|
||||
|
||||
if (texture) {
|
||||
_perlinModulateProgram->release();
|
||||
_perlinModulateProgram.release();
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,6 +135,7 @@ private:
|
|||
VoxelSystem(const VoxelSystem&);
|
||||
VoxelSystem& operator= (const VoxelSystem&);
|
||||
|
||||
bool _initialized;
|
||||
int _callsToTreesToArrays;
|
||||
VoxelNodeBag _removedVoxels;
|
||||
|
||||
|
@ -207,7 +208,8 @@ private:
|
|||
|
||||
bool _voxelsDirty;
|
||||
|
||||
static ProgramObject* _perlinModulateProgram;
|
||||
static bool _perlinModulateProgramInitialized;
|
||||
static ProgramObject _perlinModulateProgram;
|
||||
|
||||
int _hookID;
|
||||
std::vector<glBufferIndex> _freeIndexes;
|
||||
|
|
|
@ -22,25 +22,39 @@ const int BONE_ELEMENTS_PER_VOXEL = BONE_ELEMENTS_PER_VERTEX * VERTICES_PER_VOXE
|
|||
|
||||
AvatarVoxelSystem::AvatarVoxelSystem(Avatar* avatar) :
|
||||
VoxelSystem(AVATAR_TREE_SCALE, MAX_VOXELS_PER_AVATAR),
|
||||
_mode(0), _avatar(avatar), _voxelReply(0) {
|
||||
_initialized(false),
|
||||
_mode(0),
|
||||
_avatar(avatar),
|
||||
_voxelReply(0) {
|
||||
|
||||
// we may have been created in the network thread, but we live in the main thread
|
||||
moveToThread(Application::getInstance()->thread());
|
||||
}
|
||||
|
||||
AvatarVoxelSystem::~AvatarVoxelSystem() {
|
||||
delete[] _readBoneIndicesArray;
|
||||
delete[] _readBoneWeightsArray;
|
||||
delete[] _writeBoneIndicesArray;
|
||||
delete[] _writeBoneWeightsArray;
|
||||
AvatarVoxelSystem::~AvatarVoxelSystem() {
|
||||
if (_initialized) {
|
||||
delete[] _readBoneIndicesArray;
|
||||
delete[] _readBoneWeightsArray;
|
||||
delete[] _writeBoneIndicesArray;
|
||||
delete[] _writeBoneWeightsArray;
|
||||
|
||||
glDeleteBuffers(1, &_vboBoneIndicesID);
|
||||
glDeleteBuffers(1, &_vboBoneWeightsID);
|
||||
}
|
||||
}
|
||||
|
||||
ProgramObject* AvatarVoxelSystem::_skinProgram = 0;
|
||||
bool AvatarVoxelSystem::_skinProgramInitialized = false;
|
||||
ProgramObject AvatarVoxelSystem::_skinProgram;
|
||||
int AvatarVoxelSystem::_boneMatricesLocation;
|
||||
int AvatarVoxelSystem::_boneIndicesLocation;
|
||||
int AvatarVoxelSystem::_boneWeightsLocation;
|
||||
|
||||
void AvatarVoxelSystem::init() {
|
||||
if (_initialized) {
|
||||
qDebug("[ERROR] AvatarVoxelSystem is already initialized.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
VoxelSystem::init();
|
||||
|
||||
// prep the data structures for incoming voxel data
|
||||
|
@ -61,16 +75,17 @@ void AvatarVoxelSystem::init() {
|
|||
glBufferData(GL_ARRAY_BUFFER, BONE_ELEMENTS_PER_VOXEL * sizeof(GLfloat) * _maxVoxels, NULL, GL_DYNAMIC_DRAW);
|
||||
|
||||
// load our skin program if this is the first avatar system to initialize
|
||||
if (_skinProgram != 0) {
|
||||
return;
|
||||
if (!_skinProgramInitialized) {
|
||||
_skinProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/skin_voxels.vert");
|
||||
_skinProgram.link();
|
||||
_skinProgramInitialized = true;
|
||||
}
|
||||
_skinProgram = new ProgramObject();
|
||||
_skinProgram->addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/skin_voxels.vert");
|
||||
_skinProgram->link();
|
||||
|
||||
_boneMatricesLocation = _skinProgram->uniformLocation("boneMatrices");
|
||||
_boneIndicesLocation = _skinProgram->attributeLocation("boneIndices");
|
||||
_boneWeightsLocation = _skinProgram->attributeLocation("boneWeights");
|
||||
_boneMatricesLocation = _skinProgram.uniformLocation("boneMatrices");
|
||||
_boneIndicesLocation = _skinProgram.attributeLocation("boneIndices");
|
||||
_boneWeightsLocation = _skinProgram.attributeLocation("boneWeights");
|
||||
|
||||
_initialized = true;
|
||||
}
|
||||
|
||||
void AvatarVoxelSystem::removeOutOfView() {
|
||||
|
@ -202,7 +217,7 @@ void AvatarVoxelSystem::updateVBOSegment(glBufferIndex segmentStart, glBufferInd
|
|||
}
|
||||
|
||||
void AvatarVoxelSystem::applyScaleAndBindProgram(bool texture) {
|
||||
_skinProgram->bind();
|
||||
_skinProgram.bind();
|
||||
|
||||
// the base matrix includes centering and scale
|
||||
QMatrix4x4 baseMatrix;
|
||||
|
@ -222,21 +237,21 @@ void AvatarVoxelSystem::applyScaleAndBindProgram(bool texture) {
|
|||
boneMatrices[i].translate(-bindPosition.x, -bindPosition.y, -bindPosition.z);
|
||||
boneMatrices[i] *= baseMatrix;
|
||||
}
|
||||
_skinProgram->setUniformValueArray(_boneMatricesLocation, boneMatrices, NUM_AVATAR_JOINTS);
|
||||
_skinProgram.setUniformValueArray(_boneMatricesLocation, boneMatrices, NUM_AVATAR_JOINTS);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboBoneIndicesID);
|
||||
glVertexAttribPointer(_boneIndicesLocation, BONE_ELEMENTS_PER_VERTEX, GL_UNSIGNED_BYTE, false, 0, 0);
|
||||
_skinProgram->enableAttributeArray(_boneIndicesLocation);
|
||||
_skinProgram.enableAttributeArray(_boneIndicesLocation);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboBoneWeightsID);
|
||||
_skinProgram->setAttributeBuffer(_boneWeightsLocation, GL_FLOAT, 0, BONE_ELEMENTS_PER_VERTEX);
|
||||
_skinProgram->enableAttributeArray(_boneWeightsLocation);
|
||||
_skinProgram.setAttributeBuffer(_boneWeightsLocation, GL_FLOAT, 0, BONE_ELEMENTS_PER_VERTEX);
|
||||
_skinProgram.enableAttributeArray(_boneWeightsLocation);
|
||||
}
|
||||
|
||||
void AvatarVoxelSystem::removeScaleAndReleaseProgram(bool texture) {
|
||||
_skinProgram->release();
|
||||
_skinProgram->disableAttributeArray(_boneIndicesLocation);
|
||||
_skinProgram->disableAttributeArray(_boneWeightsLocation);
|
||||
_skinProgram.release();
|
||||
_skinProgram.disableAttributeArray(_boneIndicesLocation);
|
||||
_skinProgram.disableAttributeArray(_boneWeightsLocation);
|
||||
}
|
||||
|
||||
void AvatarVoxelSystem::handleVoxelDownloadProgress(qint64 bytesReceived, qint64 bytesTotal) {
|
||||
|
|
|
@ -58,6 +58,7 @@ private:
|
|||
|
||||
void computeBoneIndicesAndWeights(const glm::vec3& vertex, BoneIndices& indices, glm::vec4& weights) const;
|
||||
|
||||
bool _initialized;
|
||||
int _mode;
|
||||
|
||||
Avatar* _avatar;
|
||||
|
@ -74,7 +75,8 @@ private:
|
|||
|
||||
QNetworkReply* _voxelReply;
|
||||
|
||||
static ProgramObject* _skinProgram;
|
||||
static bool _skinProgramInitialized;
|
||||
static ProgramObject _skinProgram;
|
||||
static int _boneMatricesLocation;
|
||||
static int _boneIndicesLocation;
|
||||
static int _boneWeightsLocation;
|
||||
|
|
|
@ -22,9 +22,10 @@
|
|||
|
||||
using namespace cv;
|
||||
|
||||
ProgramObject* Face::_videoProgram = 0;
|
||||
bool Face::_initialized = false;
|
||||
ProgramObject Face::_videoProgram;
|
||||
Face::Locations Face::_videoProgramLocations;
|
||||
ProgramObject* Face::_texturedProgram = 0;
|
||||
ProgramObject Face::_texturedProgram;
|
||||
Face::Locations Face::_texturedProgramLocations;
|
||||
GLuint Face::_vboID;
|
||||
GLuint Face::_iboID;
|
||||
|
@ -53,6 +54,9 @@ Face::~Face() {
|
|||
glDeleteTextures(1, &_depthTextureID);
|
||||
}
|
||||
}
|
||||
|
||||
glDeleteBuffers(1, &_vboID);
|
||||
glDeleteBuffers(1, &_iboID);
|
||||
}
|
||||
|
||||
void Face::setFrameFromWebcam() {
|
||||
|
@ -293,9 +297,9 @@ bool Face::render(float alpha) {
|
|||
const int INDICES_PER_TRIANGLE = 3;
|
||||
const int INDEX_COUNT = QUAD_COUNT * TRIANGLES_PER_QUAD * INDICES_PER_TRIANGLE;
|
||||
|
||||
if (_videoProgram == 0) {
|
||||
_videoProgram = loadProgram(QString(), "colorTexture", _videoProgramLocations);
|
||||
_texturedProgram = loadProgram("_textured", "permutationNormalTexture", _texturedProgramLocations);
|
||||
if (!_initialized) {
|
||||
loadProgram(_videoProgram, QString(), "colorTexture", _videoProgramLocations);
|
||||
loadProgram(_texturedProgram, "_textured", "permutationNormalTexture", _texturedProgramLocations);
|
||||
|
||||
glGenBuffers(1, &_vboID);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboID);
|
||||
|
@ -327,7 +331,8 @@ bool Face::render(float alpha) {
|
|||
}
|
||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, INDEX_COUNT * sizeof(int), indices, GL_STATIC_DRAW);
|
||||
delete[] indices;
|
||||
|
||||
|
||||
_initialized = true;
|
||||
} else {
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _vboID);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _iboID);
|
||||
|
@ -336,14 +341,14 @@ bool Face::render(float alpha) {
|
|||
|
||||
glActiveTexture(GL_TEXTURE1);
|
||||
|
||||
ProgramObject* program = _videoProgram;
|
||||
ProgramObject* program = &_videoProgram;
|
||||
Locations* locations = &_videoProgramLocations;
|
||||
if (_colorTextureID != 0) {
|
||||
glBindTexture(GL_TEXTURE_2D, _colorTextureID);
|
||||
|
||||
} else {
|
||||
glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPermutationNormalTextureID());
|
||||
program = _texturedProgram;
|
||||
program = &_texturedProgram;
|
||||
locations = &_texturedProgramLocations;
|
||||
}
|
||||
program->bind();
|
||||
|
@ -467,20 +472,17 @@ void Face::destroyCodecs() {
|
|||
}
|
||||
}
|
||||
|
||||
ProgramObject* Face::loadProgram(const QString& suffix, const char* secondTextureUniform, Locations& locations) {
|
||||
ProgramObject* program = new ProgramObject();
|
||||
program->addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/face" + suffix + ".vert");
|
||||
program->addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/face" + suffix + ".frag");
|
||||
program->link();
|
||||
void Face::loadProgram(ProgramObject& program, const QString& suffix, const char* secondTextureUniform, Locations& locations) {
|
||||
program.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/face" + suffix + ".vert");
|
||||
program.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/face" + suffix + ".frag");
|
||||
program.link();
|
||||
|
||||
program->bind();
|
||||
program->setUniformValue("depthTexture", 0);
|
||||
program->setUniformValue(secondTextureUniform, 1);
|
||||
program->release();
|
||||
program.bind();
|
||||
program.setUniformValue("depthTexture", 0);
|
||||
program.setUniformValue(secondTextureUniform, 1);
|
||||
program.release();
|
||||
|
||||
locations.texCoordCorner = program->uniformLocation("texCoordCorner");
|
||||
locations.texCoordRight = program->uniformLocation("texCoordRight");
|
||||
locations.texCoordUp = program->uniformLocation("texCoordUp");
|
||||
|
||||
return program;
|
||||
locations.texCoordCorner = program.uniformLocation("texCoordCorner");
|
||||
locations.texCoordRight = program.uniformLocation("texCoordRight");
|
||||
locations.texCoordUp = program.uniformLocation("texCoordUp");
|
||||
}
|
||||
|
|
|
@ -77,12 +77,14 @@ private:
|
|||
int texCoordUp;
|
||||
};
|
||||
|
||||
static ProgramObject* loadProgram(const QString& suffix, const char* secondTextureUniform, Locations& locations);
|
||||
static void loadProgram(ProgramObject& progam, const QString& suffix, const char* secondTextureUniform, Locations& locations);
|
||||
|
||||
static ProgramObject* _videoProgram;
|
||||
static bool _initialized;
|
||||
|
||||
static ProgramObject _videoProgram;
|
||||
static Locations _videoProgramLocations;
|
||||
|
||||
static ProgramObject* _texturedProgram;
|
||||
static ProgramObject _texturedProgram;
|
||||
static Locations _texturedProgramLocations;
|
||||
|
||||
static GLuint _vboID;
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
const int MOHAWK_TRIANGLES = 50;
|
||||
const bool USING_PHYSICAL_MOHAWK = true;
|
||||
const float EYE_RIGHT_OFFSET = 0.27f;
|
||||
const float EYE_UP_OFFSET = 0.36f;
|
||||
|
@ -47,7 +46,8 @@ const float IRIS_RADIUS = 0.007;
|
|||
const float IRIS_PROTRUSION = 0.0145f;
|
||||
const char IRIS_TEXTURE_FILENAME[] = "resources/images/iris.png";
|
||||
|
||||
ProgramObject* Head::_irisProgram = 0;
|
||||
bool Head::_irisProgramInitialized = false;
|
||||
ProgramObject Head::_irisProgram;
|
||||
GLuint Head::_irisTextureID;
|
||||
int Head::_eyePositionLocation;
|
||||
|
||||
|
@ -76,8 +76,7 @@ Head::Head(Avatar* owningAvatar) :
|
|||
_returnSpringScale(1.0f),
|
||||
_bodyRotation(0.0f, 0.0f, 0.0f),
|
||||
_renderLookatVectors(false),
|
||||
_mohawkTriangleFan(NULL),
|
||||
_mohawkColors(NULL),
|
||||
_mohawkInitialized(false),
|
||||
_saccade(0.0f, 0.0f, 0.0f),
|
||||
_saccadeTarget(0.0f, 0.0f, 0.0f),
|
||||
_leftEyeBlink(0.0f),
|
||||
|
@ -99,16 +98,15 @@ Head::Head(Avatar* owningAvatar) :
|
|||
}
|
||||
|
||||
void Head::init() {
|
||||
if (_irisProgram == 0) {
|
||||
if (!_irisProgramInitialized) {
|
||||
switchToResourcesParentIfRequired();
|
||||
_irisProgram = new ProgramObject();
|
||||
_irisProgram->addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/iris.vert");
|
||||
_irisProgram->addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/iris.frag");
|
||||
_irisProgram->link();
|
||||
|
||||
_irisProgram->setUniformValue("texture", 0);
|
||||
_eyePositionLocation = _irisProgram->uniformLocation("eyePosition");
|
||||
|
||||
_irisProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/iris.vert");
|
||||
_irisProgram.addShaderFromSourceFile(QGLShader::Fragment, "resources/shaders/iris.frag");
|
||||
_irisProgram.link();
|
||||
|
||||
_irisProgram.setUniformValue("texture", 0);
|
||||
_eyePositionLocation = _irisProgram.uniformLocation("eyePosition");
|
||||
|
||||
QImage image = QImage(IRIS_TEXTURE_FILENAME).convertToFormat(QImage::Format_ARGB32);
|
||||
|
||||
glGenTextures(1, &_irisTextureID);
|
||||
|
@ -118,6 +116,8 @@ void Head::init() {
|
|||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
|
||||
_irisProgramInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -334,9 +334,7 @@ void Head::render(float alpha) {
|
|||
|
||||
void Head::setScale (float scale) {
|
||||
_scale = scale;
|
||||
|
||||
delete[] _mohawkTriangleFan;
|
||||
delete[] _mohawkColors;
|
||||
|
||||
createMohawk();
|
||||
|
||||
if (USING_PHYSICAL_MOHAWK) {
|
||||
|
@ -363,8 +361,6 @@ void Head::createMohawk() {
|
|||
float height = _scale * (0.08f + randFloat() * 0.05f);
|
||||
float variance = 0.03 + randFloat() * 0.03f;
|
||||
const float RAD_PER_TRIANGLE = (2.3f + randFloat() * 0.2f) / (float)MOHAWK_TRIANGLES;
|
||||
_mohawkTriangleFan = new glm::vec3[MOHAWK_TRIANGLES];
|
||||
_mohawkColors = new glm::vec3[MOHAWK_TRIANGLES];
|
||||
_mohawkTriangleFan[0] = glm::vec3(0, 0, 0);
|
||||
glm::vec3 basicColor(randFloat(), randFloat(), randFloat());
|
||||
_mohawkColors[0] = basicColor;
|
||||
|
@ -382,14 +378,9 @@ void Head::createMohawk() {
|
|||
|
||||
void Head::renderMohawk() {
|
||||
|
||||
if (!_mohawkTriangleFan) {
|
||||
if (!_mohawkInitialized) {
|
||||
createMohawk();
|
||||
|
||||
// if we get here and still don't have a mohawk then we don't know who we are
|
||||
// so return out since we can't render it yet
|
||||
if (!_mohawkTriangleFan) {
|
||||
return;
|
||||
}
|
||||
_mohawkInitialized = true;
|
||||
}
|
||||
|
||||
if (USING_PHYSICAL_MOHAWK) {
|
||||
|
@ -649,7 +640,7 @@ void Head::renderEyeBalls() {
|
|||
glutSolidSphere(_scale * EYEBALL_RADIUS, 30, 30);
|
||||
glPopMatrix();
|
||||
|
||||
_irisProgram->bind();
|
||||
_irisProgram.bind();
|
||||
glBindTexture(GL_TEXTURE_2D, _irisTextureID);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
|
@ -671,7 +662,7 @@ void Head::renderEyeBalls() {
|
|||
_scale * IRIS_RADIUS); // flatten the iris
|
||||
|
||||
// this ugliness is simply to invert the model transform and get the eye position in model space
|
||||
_irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) *
|
||||
_irisProgram.setUniform(_eyePositionLocation, (glm::inverse(rotation) *
|
||||
(Application::getInstance()->getCamera()->getPosition() - _leftEyePosition) +
|
||||
glm::vec3(0.0f, 0.0f, _scale * IRIS_PROTRUSION)) * glm::vec3(1.0f / (_scale * IRIS_RADIUS * 2.0f),
|
||||
1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / (_scale * IRIS_RADIUS)));
|
||||
|
@ -695,7 +686,7 @@ void Head::renderEyeBalls() {
|
|||
_scale * IRIS_RADIUS); // flatten the iris
|
||||
|
||||
// this ugliness is simply to invert the model transform and get the eye position in model space
|
||||
_irisProgram->setUniform(_eyePositionLocation, (glm::inverse(rotation) *
|
||||
_irisProgram.setUniform(_eyePositionLocation, (glm::inverse(rotation) *
|
||||
(Application::getInstance()->getCamera()->getPosition() - _rightEyePosition) +
|
||||
glm::vec3(0.0f, 0.0f, _scale * IRIS_PROTRUSION)) * glm::vec3(1.0f / (_scale * IRIS_RADIUS * 2.0f),
|
||||
1.0f / (_scale * IRIS_RADIUS * 2.0f), 1.0f / (_scale * IRIS_RADIUS)));
|
||||
|
@ -704,7 +695,7 @@ void Head::renderEyeBalls() {
|
|||
}
|
||||
glPopMatrix();
|
||||
|
||||
_irisProgram->release();
|
||||
_irisProgram.release();
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@ enum eyeContactTargets {
|
|||
MOUTH
|
||||
};
|
||||
|
||||
const int MOHAWK_TRIANGLES = 50;
|
||||
const int NUM_HAIR_TUFTS = 4;
|
||||
|
||||
class Avatar;
|
||||
|
@ -71,7 +72,7 @@ public:
|
|||
Face& getFace() { return _face; }
|
||||
|
||||
const bool getReturnToCenter() const { return _returnHeadToCenter; } // Do you want head to try to return to center (depends on interface detected)
|
||||
float getAverageLoudness() {return _averageLoudness;};
|
||||
float getAverageLoudness() {return _averageLoudness;}
|
||||
glm::vec3 calculateAverageEyePosition() { return _leftEyePosition + (_rightEyePosition - _leftEyePosition ) * ONE_HALF; }
|
||||
|
||||
float yawRate;
|
||||
|
@ -87,7 +88,7 @@ private:
|
|||
glm::vec3 right;
|
||||
glm::vec3 front;
|
||||
};
|
||||
|
||||
|
||||
float _renderAlpha;
|
||||
bool _returnHeadToCenter;
|
||||
glm::vec3 _skinColor;
|
||||
|
@ -112,8 +113,9 @@ private:
|
|||
glm::vec3 _bodyRotation;
|
||||
bool _renderLookatVectors;
|
||||
BendyLine _hairTuft[NUM_HAIR_TUFTS];
|
||||
glm::vec3* _mohawkTriangleFan;
|
||||
glm::vec3* _mohawkColors;
|
||||
bool _mohawkInitialized;
|
||||
glm::vec3 _mohawkTriangleFan[MOHAWK_TRIANGLES];
|
||||
glm::vec3 _mohawkColors[MOHAWK_TRIANGLES];
|
||||
glm::vec3 _saccade;
|
||||
glm::vec3 _saccadeTarget;
|
||||
float _leftEyeBlink;
|
||||
|
@ -129,7 +131,8 @@ private:
|
|||
float _cameraFollowHeadRate;
|
||||
Face _face;
|
||||
|
||||
static ProgramObject* _irisProgram;
|
||||
static bool _irisProgramInitialized;
|
||||
static ProgramObject _irisProgram;
|
||||
static GLuint _irisTextureID;
|
||||
static int _eyePositionLocation;
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ public:
|
|||
NODE_TYPE getOwnerType() const { return _ownerType; }
|
||||
void setOwnerType(NODE_TYPE ownerType) { _ownerType = ownerType; }
|
||||
|
||||
const char* getDomainHostname() const { return _domainHostname; };
|
||||
const char* getDomainHostname() const { return _domainHostname; }
|
||||
void setDomainHostname(const char* domainHostname);
|
||||
|
||||
void setDomainIP(const char* domainIP);
|
||||
|
@ -81,7 +81,7 @@ public:
|
|||
|
||||
UDPSocket* getNodeSocket() { return &_nodeSocket; }
|
||||
|
||||
unsigned short int getSocketListenPort() const { return _nodeSocket.getListeningPort(); };
|
||||
unsigned short int getSocketListenPort() const { return _nodeSocket.getListeningPort(); }
|
||||
|
||||
void(*linkedDataCreateCallback)(Node *);
|
||||
|
||||
|
|
Loading…
Reference in a new issue