Merge branch 'master' of https://github.com/worklist/hifi into shifty

This commit is contained in:
Andrzej Kapolka 2013-09-04 15:32:15 -07:00
commit 834b671f5a
43 changed files with 356 additions and 388 deletions

View file

@ -237,6 +237,14 @@ Application::~Application() {
NodeList::getInstance()->removeHook(this);
_sharedVoxelSystem.changeTree(new VoxelTree);
delete Menu::getInstance();
delete _oculusProgram;
delete _settings;
delete _networkAccessManager;
delete _followMode;
delete _glWidget;
}
void Application::initializeGL() {

View file

@ -40,19 +40,19 @@ public:
void addReceivedAudioToBuffer(unsigned char* receivedData, int receivedBytes);
float getLastInputLoudness() const { return _lastInputLoudness; };
float getLastInputLoudness() const { return _lastInputLoudness; }
void setLastAcceleration(glm::vec3 lastAcceleration) { _lastAcceleration = lastAcceleration; };
void setLastVelocity(glm::vec3 lastVelocity) { _lastVelocity = lastVelocity; };
void setLastAcceleration(const glm::vec3 lastAcceleration) { _lastAcceleration = lastAcceleration; }
void setLastVelocity(const glm::vec3 lastVelocity) { _lastVelocity = lastVelocity; }
void setJitterBufferSamples(int samples) { _jitterBufferSamples = samples; };
int getJitterBufferSamples() { return _jitterBufferSamples; };
void setJitterBufferSamples(int samples) { _jitterBufferSamples = samples; }
int getJitterBufferSamples() { return _jitterBufferSamples; }
void lowPassFilter(int16_t* inputBuffer);
void startCollisionSound(float magnitude, float frequency, float noise, float duration);
float getCollisionSoundMagnitude() { return _collisionSoundMagnitude; };
float getCollisionSoundMagnitude() { return _collisionSoundMagnitude; }
void ping();
@ -61,8 +61,8 @@ public:
// The results of the analysis are written to the log.
bool eventuallyAnalyzePing();
void setListenMode(AudioRingBuffer::ListenMode mode) { _listenMode = mode; };
void setListenRadius(float radius) { _listenRadius = radius; };
void setListenMode(AudioRingBuffer::ListenMode mode) { _listenMode = mode; }
void setListenRadius(float radius) { _listenRadius = radius; }
void addListenSource(int sourceID);
void removeListenSource(int sourceID);
void clearListenSources();

View file

@ -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) {

View file

@ -14,6 +14,7 @@ const int NUMBER_SPRINGS = 4;
class Balls {
public:
Balls(int numberOfBalls);
~Balls();
void simulate(float deltaTime);
void render();

View file

@ -38,13 +38,31 @@ static sockaddr getZeroAddress() {
return addr;
}
Environment::Environment()
: _initialized(false) {
}
Environment::~Environment() {
if (_initialized) {
delete _skyFromAtmosphereProgram;
delete _skyFromSpaceProgram;
}
}
void Environment::init() {
if (_initialized) {
qDebug("[ERROR] Environment is already initialized.\n");
return;
}
switchToResourcesParentIfRequired();
_skyFromAtmosphereProgram = createSkyProgram("Atmosphere", _skyFromAtmosphereUniformLocations);
_skyFromSpaceProgram = createSkyProgram("Space", _skyFromSpaceUniformLocations);
// start off with a default-constructed environment data
_data[getZeroAddress()][0];
_initialized = true;
}
void Environment::resetToDefault() {

View file

@ -22,6 +22,8 @@ class ProgramObject;
class Environment {
public:
Environment();
~Environment();
void init();
void resetToDefault();
@ -40,6 +42,7 @@ private:
void renderAtmosphere(Camera& camera, const EnvironmentData& data);
bool _initialized;
ProgramObject* _skyFromAtmosphereProgram;
ProgramObject* _skyFromSpaceProgram;

View file

@ -427,6 +427,11 @@ Menu::Menu() :
addCheckableActionToQMenuAndActionHash(developerMenu, MenuOption::DestructiveAddVoxel);
}
Menu::~Menu() {
bandwidthDetailsClosed();
voxelStatsDetailsClosed();
}
void Menu::loadSettings(QSettings* settings) {
if (!settings) {
settings = Application::getInstance()->getSettings();
@ -869,8 +874,10 @@ void Menu::bandwidthDetails() {
}
void Menu::bandwidthDetailsClosed() {
delete _bandwidthDialog;
_bandwidthDialog = NULL;
if (_bandwidthDialog) {
delete _bandwidthDialog;
_bandwidthDialog = NULL;
}
}
void Menu::voxelStatsDetails() {
@ -884,8 +891,10 @@ void Menu::voxelStatsDetails() {
}
void Menu::voxelStatsDetailsClosed() {
delete _voxelStatsDialog;
_voxelStatsDialog = NULL;
if (_voxelStatsDialog) {
delete _voxelStatsDialog;
_voxelStatsDialog = NULL;
}
}
void Menu::cycleFrustumRenderMode() {

View file

@ -31,10 +31,14 @@ struct ViewFrustumOffset {
float up;
};
class BandwidthDialog;
class VoxelStatsDialog;
class Menu : public QMenuBar {
Q_OBJECT
public:
static Menu* getInstance();
~Menu();
bool isOptionChecked(const QString& menuOption);
void triggerOption(const QString& menuOption);

View file

@ -51,8 +51,12 @@ GLubyte identityIndices[] = { 0,2,1, 0,3,2, // Z-
10,11,15, 10,15,14, // Y+
4,5,6, 4,6,7 }; // Z+
VoxelSystem::VoxelSystem(float treeScale, int maxVoxels) :
NodeData(NULL), _treeScale(treeScale), _maxVoxels(maxVoxels) {
VoxelSystem::VoxelSystem(float treeScale, int maxVoxels)
: NodeData(NULL),
_treeScale(treeScale),
_maxVoxels(maxVoxels),
_initialized(false) {
_voxelsInReadArrays = _voxelsInWriteArrays = _voxelsUpdated = 0;
_writeRenderFullVBO = true;
_readRenderFullVBO = true;
@ -115,16 +119,21 @@ void VoxelSystem::clearFreeBufferIndexes() {
}
VoxelSystem::~VoxelSystem() {
glDeleteBuffers(1, &_vboVerticesID);
glDeleteBuffers(1, &_vboNormalsID);
glDeleteBuffers(1, &_vboColorsID);
glDeleteBuffers(1, &_vboIndicesID);
delete[] _readVerticesArray;
delete[] _writeVerticesArray;
delete[] _readColorsArray;
delete[] _writeColorsArray;
delete[] _writeVoxelDirtyArray;
delete[] _readVoxelDirtyArray;
if (_initialized) {
// Destroy glBuffers
glDeleteBuffers(1, &_vboVerticesID);
glDeleteBuffers(1, &_vboNormalsID);
glDeleteBuffers(1, &_vboColorsID);
glDeleteBuffers(1, &_vboIndicesID);
delete[] _readVerticesArray;
delete[] _writeVerticesArray;
delete[] _readColorsArray;
delete[] _writeColorsArray;
delete[] _writeVoxelDirtyArray;
delete[] _readVoxelDirtyArray;
}
delete _tree;
pthread_mutex_destroy(&_bufferWriteLock);
pthread_mutex_destroy(&_treeLock);
@ -536,9 +545,14 @@ 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;
ProgramObject VoxelSystem::_perlinModulateProgram;
void VoxelSystem::init() {
if (_initialized) {
qDebug("[ERROR] VoxelSystem is already initialized.\n");
return;
}
_callsToTreesToArrays = 0;
_setupNewVoxelsForDrawingLastFinished = 0;
_setupNewVoxelsForDrawingLastElapsed = 0;
@ -549,19 +563,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
@ -615,20 +616,34 @@ 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 (!_perlinModulateProgram.isLinked()) {
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();
}
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();
_initialized = true;
}
void VoxelSystem::changeTree(VoxelTree* newTree) {
@ -765,7 +780,7 @@ void VoxelSystem::applyScaleAndBindProgram(bool texture) {
glScalef(_treeScale, _treeScale, _treeScale);
if (texture) {
_perlinModulateProgram->bind();
_perlinModulateProgram.bind();
glBindTexture(GL_TEXTURE_2D, Application::getInstance()->getTextureCache()->getPermutationNormalTextureID());
}
}
@ -775,7 +790,7 @@ void VoxelSystem::removeScaleAndReleaseProgram(bool texture) {
glPopMatrix();
if (texture) {
_perlinModulateProgram->release();
_perlinModulateProgram.release();
glBindTexture(GL_TEXTURE_2D, 0);
}
}

View file

@ -138,6 +138,7 @@ private:
VoxelSystem(const VoxelSystem&);
VoxelSystem& operator= (const VoxelSystem&);
bool _initialized;
int _callsToTreesToArrays;
VoxelNodeBag _removedVoxels;
@ -209,8 +210,8 @@ private:
void updatePartialVBOs(); // multiple segments, only dirty voxels
bool _voxelsDirty;
static ProgramObject* _perlinModulateProgram;
static ProgramObject _perlinModulateProgram;
int _hookID;
std::vector<glBufferIndex> _freeIndexes;

View file

@ -22,25 +22,38 @@ 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;
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 +74,16 @@ 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 (!_skinProgram.isLinked()) {
_skinProgram.addShaderFromSourceFile(QGLShader::Vertex, "resources/shaders/skin_voxels.vert");
_skinProgram.link();
}
_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 +215,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 +235,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) {

View file

@ -58,6 +58,7 @@ private:
void computeBoneIndicesAndWeights(const glm::vec3& vertex, BoneIndices& indices, glm::vec4& weights) const;
bool _initialized;
int _mode;
Avatar* _avatar;
@ -73,8 +74,8 @@ private:
GLuint _vboBoneWeightsID;
QNetworkReply* _voxelReply;
static ProgramObject* _skinProgram;
static ProgramObject _skinProgram;
static int _boneMatricesLocation;
static int _boneIndicesLocation;
static int _boneWeightsLocation;

View file

@ -21,9 +21,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;
@ -292,9 +293,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);
@ -326,7 +327,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);
@ -335,14 +337,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();
@ -466,20 +468,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");
}

View file

@ -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;

View file

@ -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,7 @@ 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;
ProgramObject Head::_irisProgram;
GLuint Head::_irisTextureID;
int Head::_eyePositionLocation;
@ -76,8 +75,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 +97,15 @@ Head::Head(Avatar* owningAvatar) :
}
void Head::init() {
if (_irisProgram == 0) {
if (!_irisProgram.isLinked()) {
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);
@ -347,9 +344,7 @@ void Head::render(float alpha) {
void Head::setScale (float scale) {
_scale = scale;
delete[] _mohawkTriangleFan;
delete[] _mohawkColors;
createMohawk();
if (USING_PHYSICAL_MOHAWK) {
@ -376,8 +371,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;
@ -395,14 +388,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) {
@ -662,7 +650,7 @@ void Head::renderEyeBalls() {
glutSolidSphere(_scale * EYEBALL_RADIUS, 30, 30);
glPopMatrix();
_irisProgram->bind();
_irisProgram.bind();
glBindTexture(GL_TEXTURE_2D, _irisTextureID);
glEnable(GL_TEXTURE_2D);
@ -684,7 +672,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)));
@ -708,7 +696,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)));
@ -717,7 +705,7 @@ void Head::renderEyeBalls() {
}
glPopMatrix();
_irisProgram->release();
_irisProgram.release();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);

View file

@ -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() const { 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;
@ -128,8 +130,8 @@ private:
bool _cameraFollowsHead;
float _cameraFollowHeadRate;
Face _face;
static ProgramObject* _irisProgram;
static ProgramObject _irisProgram;
static GLuint _irisTextureID;
static int _eyePositionLocation;

View file

@ -29,6 +29,12 @@ Transmitter::Transmitter() :
}
Transmitter::~Transmitter() {
if (_lastReceivedPacket) {
delete _lastReceivedPacket;
}
}
void Transmitter::checkForLostTransmitter() {
// If we are in motion, check for loss of transmitter packets
if (glm::length(_estimatedRotation) > 0.f) {

View file

@ -25,6 +25,7 @@ class Transmitter
{
public:
Transmitter();
~Transmitter();
void render();
void checkForLostTransmitter();
void resetLevels();

View file

@ -15,13 +15,28 @@
#include "ProgramObject.h"
#include "RenderUtil.h"
GlowEffect::GlowEffect() : _renderMode(DIFFUSE_ADD_MODE), _isOddFrame(false), _intensity(0.0f) {
GlowEffect::GlowEffect()
: _initialized(false),
_renderMode(DIFFUSE_ADD_MODE),
_isOddFrame(false),
_intensity(0.0f) {
}
GlowEffect::~GlowEffect() {
if (_initialized) {
delete _addProgram;
delete _horizontalBlurProgram;
delete _verticalBlurAddProgram;
delete _verticalBlurProgram;
delete _addSeparateProgram;
delete _diffuseProgram;
}
}
QOpenGLFramebufferObject* GlowEffect::getFreeFramebufferObject() const {
return (_renderMode == DIFFUSE_ADD_MODE && !_isOddFrame) ?
Application::getInstance()->getTextureCache()->getTertiaryFramebufferObject() :
Application::getInstance()->getTextureCache()->getSecondaryFramebufferObject();
Application::getInstance()->getTextureCache()->getTertiaryFramebufferObject() :
Application::getInstance()->getTextureCache()->getSecondaryFramebufferObject();
}
static ProgramObject* createProgram(const QString& name) {
@ -37,6 +52,11 @@ static ProgramObject* createProgram(const QString& name) {
}
void GlowEffect::init() {
if (_initialized) {
qDebug("[ERROR] GlowEffeect is already initialized.\n");
return;
}
switchToResourcesParentIfRequired();
_addProgram = createProgram("glow_add");
@ -59,6 +79,8 @@ void GlowEffect::init() {
_diffuseProgram->release();
_diffusionScaleLocation = _diffuseProgram->uniformLocation("diffusionScale");
_initialized = true;
}
void GlowEffect::prepare() {

View file

@ -21,8 +21,8 @@ class GlowEffect : public QObject {
Q_OBJECT
public:
GlowEffect();
~GlowEffect();
/// Returns a pointer to the framebuffer object that the glow effect is *not* using for persistent state
/// (either the secondary or the tertiary).
@ -53,6 +53,8 @@ private:
enum RenderMode { ADD_MODE, BLUR_ADD_MODE, BLUR_PERSIST_ADD_MODE, DIFFUSE_ADD_MODE, RENDER_MODE_COUNT };
bool _initialized;
RenderMode _renderMode;
ProgramObject* _addProgram;
ProgramObject* _horizontalBlurProgram;

View file

@ -49,9 +49,9 @@ private:
QOpenGLFramebufferObject* createFramebufferObject();
GLuint _permutationNormalTextureID;
QOpenGLFramebufferObject* _primaryFramebufferObject;
GLuint _primaryDepthTextureID;
QOpenGLFramebufferObject* _primaryFramebufferObject;
QOpenGLFramebufferObject* _secondaryFramebufferObject;
QOpenGLFramebufferObject* _tertiaryFramebufferObject;
};

View file

@ -70,6 +70,10 @@ namespace starfield {
_renderer(0l) {
}
~Controller() {
delete _renderer;
}
#if !STARFIELD_MULTITHREADING
#define lock
#define _(x)

View file

@ -38,6 +38,12 @@ BandwidthDialog::BandwidthDialog(QWidget* parent, BandwidthMeter* model) :
}
}
BandwidthDialog::~BandwidthDialog() {
for (int i = 0; i < BandwidthMeter::N_STREAMS; ++i) {
delete _labels[i];
}
}
void BandwidthDialog::paintEvent(QPaintEvent* event) {
// Update labels

View file

@ -18,9 +18,9 @@
class BandwidthDialog : public QDialog {
Q_OBJECT
public:
// Sets up the UI based on the configuration of the BandwidthMeter
BandwidthDialog(QWidget* parent, BandwidthMeter* model);
~BandwidthDialog();
signals:

View file

@ -30,7 +30,7 @@ VoxelStatsDialog::VoxelStatsDialog(QWidget* parent, VoxelSceneStats* model) :
this->QDialog::setLayout(form);
// Setup labels
for (int i = 0; i < (int)VoxelSceneStats::ITEM_COUNT; i++) {
for (int i = 0; i < VoxelSceneStats::ITEM_COUNT; i++) {
VoxelSceneStats::Item item = (VoxelSceneStats::Item)(i);
VoxelSceneStats::ItemInfo& itemInfo = _model->getItemInfo(item);
QLabel* label = _labels[item] = new QLabel();
@ -53,11 +53,17 @@ VoxelStatsDialog::VoxelStatsDialog(QWidget* parent, VoxelSceneStats* model) :
}
}
VoxelStatsDialog::~VoxelStatsDialog() {
for (int i = 0; i < VoxelSceneStats::ITEM_COUNT; ++i) {
delete _labels[i];
}
}
void VoxelStatsDialog::paintEvent(QPaintEvent* event) {
// Update labels
char strBuf[256];
for (int i = 0; i < (int)VoxelSceneStats::ITEM_COUNT; i++) {
for (int i = 0; i < VoxelSceneStats::ITEM_COUNT; i++) {
VoxelSceneStats::Item item = (VoxelSceneStats::Item)(i);
QLabel* label = _labels[item];
snprintf(strBuf, sizeof(strBuf), "%s", _model->getItemValue(item));

View file

@ -19,6 +19,7 @@ class VoxelStatsDialog : public QDialog {
public:
// Sets up the UI
VoxelStatsDialog(QWidget* parent, VoxelSceneStats* model);
~VoxelStatsDialog();
signals:
void closed();

View file

@ -73,16 +73,16 @@ public:
void setBodyYaw(float bodyYaw) { _bodyYaw = bodyYaw; }
float getBodyPitch() const { return _bodyPitch; }
void setBodyPitch(float bodyPitch) { _bodyPitch = bodyPitch; }
float getBodyRoll() const {return _bodyRoll; }
float getBodyRoll() const { return _bodyRoll; }
void setBodyRoll(float bodyRoll) { _bodyRoll = bodyRoll; }
// Hand State
void setHandState(char s) { _handState = s; };
char getHandState() const {return _handState; };
void setHandState(char s) { _handState = s; }
char getHandState() const { return _handState; }
// getters for camera details
const glm::vec3& getCameraPosition() const { return _cameraPosition; };
const glm::vec3& getCameraPosition() const { return _cameraPosition; }
const glm::quat& getCameraOrientation() const { return _cameraOrientation; }
float getCameraFov() const { return _cameraFov; }
float getCameraAspectRatio() const { return _cameraAspectRatio; }

View file

@ -32,12 +32,12 @@ public:
NetworkPacket(sockaddr& address, unsigned char* packetData, ssize_t packetLength);
sockaddr& getAddress() { return _address; };
ssize_t getLength() const { return _packetLength; };
unsigned char* getData() { return &_packetData[0]; };
sockaddr& getAddress() { return _address; }
ssize_t getLength() const { return _packetLength; }
unsigned char* getData() { return &_packetData[0]; }
const sockaddr& getAddress() const { return _address; };
const unsigned char* getData() const { return &_packetData[0]; };
const sockaddr& getAddress() const { return _address; }
const unsigned char* getData() const { return &_packetData[0]; }
private:
void copyContents(const sockaddr& address, const unsigned char* packetData, ssize_t packetLength);

View file

@ -58,15 +58,15 @@ public:
NodeData* getLinkedData() const { return _linkedData; }
void setLinkedData(NodeData* linkedData) { _linkedData = linkedData; }
bool isAlive() const { return _isAlive; };
void setAlive(bool isAlive) { _isAlive = isAlive; };
bool isAlive() const { return _isAlive; }
void setAlive(bool isAlive) { _isAlive = isAlive; }
void recordBytesReceived(int bytesReceived);
float getAverageKilobitsPerSecond();
float getAveragePacketsPerSecond();
int getPingMs() const { return _pingMs; };
void setPingMs(int pingMs) { _pingMs = pingMs; };
int getPingMs() const { return _pingMs; }
void setPingMs(int pingMs) { _pingMs = pingMs; }
void lock() { pthread_mutex_lock(&_mutex); }
void unlock() { pthread_mutex_unlock(&_mutex); }

View file

@ -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 *);
@ -156,9 +156,8 @@ private:
class NodeListIterator : public std::iterator<std::input_iterator_tag, Node> {
public:
NodeListIterator(const NodeList* nodeList, int nodeIndex);
~NodeListIterator() {};
int getNodeIndex() { return _nodeIndex; };
int getNodeIndex() { return _nodeIndex; }
NodeListIterator& operator=(const NodeListIterator& otherValue);

View file

@ -35,9 +35,9 @@ private:
public:
std::string group;
PerfStatHistory(): count(0), totalTime(0.0) {};
PerfStatHistory(): count(0), totalTime(0.0) {}
PerfStatHistory(std::string myGroup, double initialTime, long int initialCount) :
count(initialCount), totalTime(initialTime), group(myGroup) {};
count(initialCount), totalTime(initialTime), group(myGroup) {}
void recordTime(double thisTime) {
totalTime+=thisTime;
@ -94,7 +94,7 @@ public:
_start(usecTimestampNow()),
_message(message),
_renderWarningsOn(renderWarnings),
_alwaysDisplay(alwaysDisplay) { };
_alwaysDisplay(alwaysDisplay) { }
~PerformanceWarning();
};

View file

@ -1,42 +0,0 @@
//
// PointerStack.cpp
// hifi
//
// Created by Brad Hefta-Gaub on 5/11/2013
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
#include "PointerStack.h"
#include <stdio.h>
PointerStack::~PointerStack() {
deleteAll();
}
void PointerStack::deleteAll() {
if (_elements) {
delete[] _elements;
}
_elements = NULL;
_elementsInUse = 0;
_sizeOfElementsArray = 0;
}
const int GROW_BY = 100;
void PointerStack::growAndPush(void* element) {
//printf("PointerStack::growAndPush() _sizeOfElementsArray=%d",_sizeOfElementsArray);
void** oldElements = _elements;
_elements = new void* [_sizeOfElementsArray + GROW_BY];
_sizeOfElementsArray += GROW_BY;
// If we had an old stack...
if (oldElements) {
// copy old elements into the new stack
memcpy(_elements, oldElements, _elementsInUse * sizeof(void*));
delete[] oldElements;
}
_elements[_elementsInUse] = element;
_elementsInUse++;
}

View file

@ -1,59 +0,0 @@
//
// PointerStack.h
// hifi
//
// Created by Brad Hefta-Gaub on 4/25/2013
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
//
//
#ifndef __hifi__PointerStack__
#define __hifi__PointerStack__
#include <cstring> // for NULL
class PointerStack {
public:
PointerStack() :
_elements(NULL),
_elementsInUse(0),
_sizeOfElementsArray(0) {};
~PointerStack();
void push(void* element) {
if (_sizeOfElementsArray < _elementsInUse + 1) {
return growAndPush(element);
}
_elements[_elementsInUse] = element;
_elementsInUse++;
};
void* pop() {
if (_elementsInUse) {
// get the last element
void* element = _elements[_elementsInUse - 1];
// reduce the count
_elementsInUse--;
return element;
}
return NULL;
};
void* top() const { return (_elementsInUse) ? _elements[_elementsInUse - 1] : NULL; }
bool isEmpty() const { return (_elementsInUse == 0); };
bool empty() const { return (_elementsInUse == 0); };
int count() const { return _elementsInUse; };
int size() const { return _elementsInUse; };
private:
void growAndPush(void* element);
void deleteAll();
void** _elements;
int _elementsInUse;
int _sizeOfElementsArray;
};
#endif /* defined(__hifi__PointerStack__) */

View file

@ -106,7 +106,7 @@ int removeFromSortedArrays(void* value, void** valueArray, float* keyArray, int*
// Helper Class for debugging
class debug {
public:
static const char* valueOf(bool checkValue) { return checkValue ? "yes" : "no"; };
static const char* valueOf(bool checkValue) { return checkValue ? "yes" : "no"; }
};
#endif /* defined(__hifi__SharedUtil__) */

View file

@ -16,7 +16,7 @@ class StDev {
void addValue(float v);
float getAverage();
float getStDev();
int getSamples() {return sampleCount;};
int getSamples() const { return sampleCount; }
private:
float * data;
int sampleCount;

View file

@ -108,6 +108,13 @@ TagList::TagList(std::stringstream &ss) :
}
}
TagList::~TagList() {
while (!_data.empty()) {
delete _data.back();
_data.pop_back();
}
}
TagCompound::TagCompound(std::stringstream &ss) :
Tag(TAG_Compound, ss),
_size(0),
@ -145,6 +152,13 @@ TagCompound::TagCompound(std::stringstream &ss) :
}
}
TagCompound::~TagCompound() {
while (!_data.empty()) {
delete _data.back();
_data.pop_back();
}
}
TagIntArray::TagIntArray(std::stringstream &ss) : Tag(TAG_Int_Array, ss) {
_size = ss.get() << 24 | ss.get() << 16 | ss.get() << 8 | ss.get();

View file

@ -124,6 +124,7 @@ private:
class TagList : public Tag {
public:
TagList(std::stringstream &ss);
~TagList();
int getTagId() const {return _tagId;}
int getSize () const {return _size; }
@ -138,6 +139,7 @@ private:
class TagCompound : public Tag {
public:
TagCompound(std::stringstream &ss);
~TagCompound();
int getSize () const {return _size; }
std::list<Tag*> getData () const {return _data; }

View file

@ -34,8 +34,8 @@ public:
VoxelNode(unsigned char * octalCode); // regular constructor
~VoxelNode();
unsigned char* getOctalCode() const { return _octalCode; };
VoxelNode* getChildAtIndex(int childIndex) const { return _children[childIndex]; };
unsigned char* getOctalCode() const { return _octalCode; }
VoxelNode* getChildAtIndex(int childIndex) const { return _children[childIndex]; }
void deleteChildAtIndex(int childIndex);
VoxelNode* removeChildAtIndex(int childIndex);
VoxelNode* addChildAtIndex(int childIndex);
@ -45,15 +45,15 @@ public:
void setRandomColor(int minimumBrightness);
bool collapseIdenticalLeaves();
const AABox& getAABox() const { return _box; };
const glm::vec3& getCenter() const { return _box.getCenter(); };
const glm::vec3& getCorner() const { return _box.getCorner(); };
float getScale() const { return _box.getSize().x; /* voxelScale = (1 / powf(2, *node->getOctalCode())); */ };
int getLevel() const { return *_octalCode + 1; /* one based or zero based? this doesn't correctly handle 2 byte case */ };
const AABox& getAABox() const { return _box; }
const glm::vec3& getCenter() const { return _box.getCenter(); }
const glm::vec3& getCorner() const { return _box.getCorner(); }
float getScale() const { return _box.getSize().x; } // voxelScale = (1 / powf(2, *node->getOctalCode())); }
int getLevel() const { return *_octalCode + 1; } // one based or zero based? this doesn't correctly handle 2 byte case
float getEnclosingRadius() const;
bool isColored() const { return (_trueColor[3]==1); };
bool isColored() const { return _trueColor[3] == 1; }
bool isInView(const ViewFrustum& viewFrustum) const;
ViewFrustum::location inFrustum(const ViewFrustum& viewFrustum) const;
float distanceToCamera(const ViewFrustum& viewFrustum) const;
@ -68,18 +68,18 @@ public:
bool isLeaf() const { return _childCount == 0; }
int getChildCount() const { return _childCount; }
void printDebugDetails(const char* label) const;
bool isDirty() const { return _isDirty; };
void clearDirtyBit() { _isDirty = false; };
bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); };
void markWithChangedTime() { _lastChanged = usecTimestampNow(); };
uint64_t getLastChanged() const { return _lastChanged; };
bool isDirty() const { return _isDirty; }
void clearDirtyBit() { _isDirty = false; }
bool hasChangedSince(uint64_t time) const { return (_lastChanged > time); }
void markWithChangedTime() { _lastChanged = usecTimestampNow(); }
uint64_t getLastChanged() const { return _lastChanged; }
void handleSubtreeChanged(VoxelTree* myTree);
glBufferIndex getBufferIndex() const { return _glBufferIndex; };
bool isKnownBufferIndex() const { return (_glBufferIndex != GLBUFFER_INDEX_UNKNOWN); };
void setBufferIndex(glBufferIndex index) { _glBufferIndex = index; };
VoxelSystem* getVoxelSystem() const { return _voxelSystem; };
void setVoxelSystem(VoxelSystem* voxelSystem) { _voxelSystem = voxelSystem; };
glBufferIndex getBufferIndex() const { return _glBufferIndex; }
bool isKnownBufferIndex() const { return (_glBufferIndex != GLBUFFER_INDEX_UNKNOWN); }
void setBufferIndex(glBufferIndex index) { _glBufferIndex = index; }
VoxelSystem* getVoxelSystem() const { return _voxelSystem; }
void setVoxelSystem(VoxelSystem* voxelSystem) { _voxelSystem = voxelSystem; }
// Used by VoxelSystem for rendering in/out of view and LOD
@ -89,10 +89,10 @@ public:
#ifndef NO_FALSE_COLOR // !NO_FALSE_COLOR means, does have false color
void setFalseColor(colorPart red, colorPart green, colorPart blue);
void setFalseColored(bool isFalseColored);
bool getFalseColored() { return _falseColored; };
bool getFalseColored() { return _falseColored; }
void setColor(const nodeColor& color);
const nodeColor& getTrueColor() const { return _trueColor; };
const nodeColor& getColor() const { return _currentColor; };
const nodeColor& getTrueColor() const { return _trueColor; }
const nodeColor& getColor() const { return _currentColor; }
#else
void setFalseColor(colorPart red, colorPart green, colorPart blue) { /* no op */ };
void setFalseColored(bool isFalseColored) { /* no op */ };
@ -103,18 +103,18 @@ public:
const nodeColor& getColor() const { return _trueColor; };
#endif
void setDensity(float density) { _density = density; };
float getDensity() const { return _density; };
void setSourceID(uint16_t sourceID) { _sourceID = sourceID; };
uint16_t getSourceID() const { return _sourceID; };
void setDensity(float density) { _density = density; }
float getDensity() const { return _density; }
void setSourceID(uint16_t sourceID) { _sourceID = sourceID; }
uint16_t getSourceID() const { return _sourceID; }
static void addDeleteHook(VoxelNodeDeleteHook* hook);
static void removeDeleteHook(VoxelNodeDeleteHook* hook);
void recalculateSubTreeNodeCount();
unsigned long getSubTreeNodeCount() const { return _subtreeNodeCount; };
unsigned long getSubTreeInternalNodeCount() const { return _subtreeNodeCount - _subtreeLeafNodeCount; };
unsigned long getSubTreeLeafNodeCount() const { return _subtreeLeafNodeCount; };
unsigned long getSubTreeNodeCount() const { return _subtreeNodeCount; }
unsigned long getSubTreeInternalNodeCount() const { return _subtreeNodeCount - _subtreeLeafNodeCount; }
unsigned long getSubTreeLeafNodeCount() const { return _subtreeLeafNodeCount; }
private:
void calculateAABox();

View file

@ -27,8 +27,8 @@ public:
bool contains(VoxelNode* node); // is this node in the bag?
void remove(VoxelNode* node); // remove a specific item from the bag
bool isEmpty() const { return (_elementsInUse == 0); };
int count() const { return _elementsInUse; };
bool isEmpty() const { return (_elementsInUse == 0); }
int count() const { return _elementsInUse; }
void deleteAll();

View file

@ -19,19 +19,19 @@ class BoundingBox {
public:
enum { BOTTOM_LEFT, BOTTOM_RIGHT, TOP_RIGHT, TOP_LEFT, VERTEX_COUNT };
BoundingBox(glm::vec2 corner, glm::vec2 size) : corner(corner), size(size), _set(true) {};
BoundingBox() : _set(false) {};
BoundingBox(const glm::vec2 corner, const glm::vec2 size) : corner(corner), size(size), _set(true) {}
BoundingBox() : _set(false) {}
glm::vec2 corner;
glm::vec2 size;
bool contains(const BoundingBox& box) const;
bool contains(const glm::vec2& point) const;
bool pointInside(const glm::vec2& point) const { return contains(point); };
bool pointInside(const glm::vec2& point) const { return contains(point); }
void explandToInclude(const BoundingBox& box);
float area() const { return size.x * size.y; };
float area() const { return size.x * size.y; }
int getVertexCount() const { return VERTEX_COUNT; };
int getVertexCount() const { return VERTEX_COUNT; }
glm::vec2 getVertex(int vertexNumber) const;
BoundingBox topHalf() const;
@ -66,23 +66,23 @@ public:
_vertexCount(vertexCount),
_maxX(-FLT_MAX), _maxY(-FLT_MAX), _minX(FLT_MAX), _minY(FLT_MAX),
_distance(0)
{ };
{ }
~VoxelProjectedPolygon() { };
const ProjectedVertices& getVertices() const { return _vertices; };
const glm::vec2& getVertex(int i) const { return _vertices[i]; };
~VoxelProjectedPolygon() { }
const ProjectedVertices& getVertices() const { return _vertices; }
const glm::vec2& getVertex(int i) const { return _vertices[i]; }
void setVertex(int vertex, const glm::vec2& point);
int getVertexCount() const { return _vertexCount; };
void setVertexCount(int vertexCount) { _vertexCount = vertexCount; };
float getDistance() const { return _distance; }
void setDistance(float distance) { _distance = distance; }
bool getAnyInView() const { return _anyInView; };
void setAnyInView(bool anyInView) { _anyInView = anyInView; };
bool getAllInView() const { return _allInView; };
void setAllInView(bool allInView) { _allInView = allInView; };
void setProjectionType(unsigned char type) { _projectionType = type; };
unsigned char getProjectionType() const { return _projectionType; };
int getVertexCount() const { return _vertexCount; }
float getDistance() const { return _distance; }
bool getAnyInView() const { return _anyInView; }
bool getAllInView() const { return _allInView; }
unsigned char getProjectionType() const { return _projectionType; }
void setVertexCount(int vertexCount) { _vertexCount = vertexCount; }
void setDistance(float distance) { _distance = distance; }
void setAnyInView(bool anyInView) { _anyInView = anyInView; }
void setAllInView(bool allInView) { _allInView = allInView; }
void setProjectionType(unsigned char type) { _projectionType = type; }
bool pointInside(const glm::vec2& point, bool* matchesVertex = NULL) const;

View file

@ -120,7 +120,7 @@ public:
/// Returns details about items tracked by VoxelSceneStats
/// \param Item item The item from the stats you're interested in.
ItemInfo& getItemInfo(Item item) { return _ITEMS[item]; };
ItemInfo& getItemInfo(Item item) { return _ITEMS[item]; }
/// Returns a UI formatted value of an item tracked by VoxelSceneStats
/// \param Item item The item from the stats you're interested in.

View file

@ -70,61 +70,6 @@ VoxelTree::~VoxelTree() {
pthread_mutex_destroy(&_deletePendingSetLock);
}
void VoxelTree::recurseTreeWithOperationDistanceSortedTimed(PointerStack* stackOfNodes, long allowedTime,
RecurseVoxelTreeOperation operation,
const glm::vec3& point, void* extraData) {
long long start = usecTimestampNow();
// start case, stack empty, so start with root...
if (stackOfNodes->empty()) {
stackOfNodes->push(rootNode);
}
while (!stackOfNodes->empty()) {
VoxelNode* node = (VoxelNode*)stackOfNodes->top();
stackOfNodes->pop();
if (operation(node, extraData)) {
//sortChildren... CLOSEST to FURTHEST
// determine the distance sorted order of our children
VoxelNode* sortedChildren[NUMBER_OF_CHILDREN];
float distancesToChildren[NUMBER_OF_CHILDREN];
int indexOfChildren[NUMBER_OF_CHILDREN]; // not really needed
int currentCount = 0;
for (int i = 0; i < NUMBER_OF_CHILDREN; i++) {
VoxelNode* childNode = node->getChildAtIndex(i);
if (childNode) {
// chance to optimize, doesn't need to be actual distance!! Could be distance squared
float distanceSquared = childNode->distanceSquareToPoint(point);
currentCount = insertIntoSortedArrays((void*)childNode, distanceSquared, i,
(void**)&sortedChildren, (float*)&distancesToChildren,
(int*)&indexOfChildren, currentCount, NUMBER_OF_CHILDREN);
}
}
//iterate sorted children FURTHEST to CLOSEST
for (int i = currentCount-1; i >= 0; i--) {
VoxelNode* child = sortedChildren[i];
stackOfNodes->push(child);
}
}
// at this point, we can check to see if we should bail for timing reasons
// because if we bail at this point, then reenter the while, we will basically
// be back to processing the stack from same place we left off, and all can proceed normally
long long now = usecTimestampNow();
long elapsedTime = now - start;
if (elapsedTime > allowedTime) {
return; // caller responsible for calling us again to finish the job!
}
}
}
// Recurses voxel tree calling the RecurseVoxelTreeOperation function for each node.
// stops recursion if operation function returns false.
void VoxelTree::recurseTreeWithOperation(RecurseVoxelTreeOperation operation, void* extraData) {

View file

@ -10,7 +10,6 @@
#define __hifi__VoxelTree__
#include <set>
#include <PointerStack.h>
#include <SimpleMovingAverage.h>
#include "CoverageMap.h"
@ -158,10 +157,10 @@ public:
int encodeTreeBitstream(VoxelNode* node, unsigned char* outputBuffer, int availableBytes, VoxelNodeBag& bag,
EncodeBitstreamParams& params) ;
bool isDirty() const { return _isDirty; };
void clearDirtyBit() { _isDirty = false; };
void setDirtyBit() { _isDirty = true; };
unsigned long int getNodesChangedFromBitstream() const { return _nodesChangedFromBitstream; };
bool isDirty() const { return _isDirty; }
void clearDirtyBit() { _isDirty = false; }
void setDirtyBit() { _isDirty = true; }
unsigned long int getNodesChangedFromBitstream() const { return _nodesChangedFromBitstream; }
bool findRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
VoxelNode*& node, float& distance, BoxFace& face);
@ -189,12 +188,6 @@ public:
void recurseNodeWithOperation(VoxelNode* node, RecurseVoxelTreeOperation operation, void* extraData);
void recurseNodeWithOperationDistanceSorted(VoxelNode* node, RecurseVoxelTreeOperation operation,
const glm::vec3& point, void* extraData);
void recurseTreeWithOperationDistanceSortedTimed(PointerStack* stackOfNodes, long allowedTime,
RecurseVoxelTreeOperation operation,
const glm::vec3& point, void* extraData);
signals:
void importSize(float x, float y, float z);
void importProgress(int progress);