From de665c2d48cfe4e2189d0150480f6d3513c8ab4e Mon Sep 17 00:00:00 2001 From: tosh Date: Sun, 19 May 2013 13:01:57 +0200 Subject: [PATCH] adjusts names --- interface/src/Log.cpp | 160 +++++++-------- interface/src/Log.h | 34 ++-- interface/src/LogStream.h | 36 ++-- interface/src/Oscilloscope.cpp | 44 ++-- interface/src/Oscilloscope.h | 18 +- interface/src/Stars.cpp | 14 +- interface/src/Stars.h | 2 +- interface/src/starfield/Controller.h | 188 +++++++++--------- interface/src/starfield/Loader.h | 66 +++--- interface/src/starfield/data/GpuVertex.h | 6 +- interface/src/starfield/data/InputVertex.h | 18 +- interface/src/starfield/renderer/Renderer.h | 176 ++++++++-------- interface/src/starfield/renderer/Tiling.h | 14 +- .../src/starfield/renderer/VertexOrder.h | 6 +- 14 files changed, 391 insertions(+), 391 deletions(-) diff --git a/interface/src/Log.cpp b/interface/src/Log.cpp index 9b57df1694..5b50074444 100644 --- a/interface/src/Log.cpp +++ b/interface/src/Log.cpp @@ -49,27 +49,27 @@ namespace { Log::Log(FILE* tPipeTo, unsigned bufferedLines, unsigned defaultLogWidth, unsigned defaultCharWidth, unsigned defaultCharHeight) : - _ptrStream(tPipeTo), - _arrChars(0l), - _arrLines(0l), - _valLogWidth(defaultLogWidth) { + _stream(tPipeTo), + _chars(0l), + _lines(0l), + _logWidth(defaultLogWidth) { - pthread_mutex_init(& _mtx, 0l); + pthread_mutex_init(& _mutex, 0l); // allocate twice as much (so we have spare space for a copy not to block // logging from other threads during 'render') - _arrChars = new char[CHARACTER_BUFFER_SIZE * 2]; - _ptrCharsEnd = _arrChars + CHARACTER_BUFFER_SIZE; - _arrLines = new char*[LINE_BUFFER_SIZE * 2]; - _ptrLinesEnd = _arrLines + LINE_BUFFER_SIZE; + _chars = new char[CHARACTER_BUFFER_SIZE * 2]; + _charsEnd = _chars + CHARACTER_BUFFER_SIZE; + _lines = new char*[LINE_BUFFER_SIZE * 2]; + _linesEnd = _lines + LINE_BUFFER_SIZE; // initialize the log to all empty lines - _arrChars[0] = '\0'; - _itrWritePos = _arrChars; - _itrWriteLineStart = _arrChars; - _itrLastLine = _arrLines; - _valWrittenInLine = 0; - memset(_arrLines, 0, LINE_BUFFER_SIZE * sizeof(char*)); + _chars[0] = '\0'; + _writePos = _chars; + _writeLineStartPos = _chars; + _lastLinePos = _lines; + _writtenInLine = 0; + memset(_lines, 0, LINE_BUFFER_SIZE * sizeof(char*)); setCharacterSize(defaultCharWidth, defaultCharHeight); } @@ -77,8 +77,8 @@ Log::Log(FILE* tPipeTo, unsigned bufferedLines, Log::~Log() { - delete[] _arrChars; - delete[] _arrLines; + delete[] _chars; + delete[] _lines; } inline void Log::addMessage(char const* ptr) { @@ -86,8 +86,8 @@ inline void Log::addMessage(char const* ptr) { // precondition: mutex is locked so noone gets in our way // T-pipe, if requested - if (_ptrStream != 0l) { - fprintf(_ptrStream, "%s", ptr); + if (_stream != 0l) { + fprintf(_stream, "%s", ptr); } while (*ptr != '\0') { @@ -104,51 +104,51 @@ inline void Log::addMessage(char const* ptr) { // found LF -> write NUL (c == '\0' tells us to wrap, below) c = '\0'; } - *_itrWritePos++ = c; + *_writePos++ = c; - if (_itrWritePos == _ptrCharsEnd) { + if (_writePos == _charsEnd) { // reached the end of the circular character buffer? -> start over - _itrWritePos = _arrChars; + _writePos = _chars; } - if (++_valWrittenInLine >= _valLineLength || c == '\0') { + if (++_writtenInLine >= _lineLength || c == '\0') { // new line? store its start to the line buffer and mark next line as empty - ++_itrLastLine; + ++_lastLinePos; - if (_itrLastLine == _ptrLinesEnd) { - _itrLastLine = _arrLines; - _itrLastLine[1] = 0l; - } else if (_itrLastLine + 1 != _ptrLinesEnd) { - _itrLastLine[1] = 0l; + if (_lastLinePos == _linesEnd) { + _lastLinePos = _lines; + _lastLinePos[1] = 0l; + } else if (_lastLinePos + 1 != _linesEnd) { + _lastLinePos[1] = 0l; } else { - _arrLines[0] = 0l; + _lines[0] = 0l; } - *_itrLastLine = _itrWriteLineStart; + *_lastLinePos = _writeLineStartPos; // debug mode: make sure all line pointers we write here are valid - assert(! (_itrLastLine < _arrLines || _itrLastLine >= _ptrLinesEnd)); - assert(! (*_itrLastLine < _arrChars || *_itrLastLine >= _ptrCharsEnd)); + assert(! (_lastLinePos < _lines || _lastLinePos >= _linesEnd)); + assert(! (*_lastLinePos < _chars || *_lastLinePos >= _charsEnd)); // terminate line, unless done already if (c != '\0') { - *_itrWritePos++ = '\0'; + *_writePos++ = '\0'; - if (_itrWritePos == _ptrCharsEnd) { - _itrWritePos = _arrChars; + if (_writePos == _charsEnd) { + _writePos = _chars; } } // remember start position in character buffer for next line and reset character count - _itrWriteLineStart = _itrWritePos; - _valWrittenInLine = 0; + _writeLineStartPos = _writePos; + _writtenInLine = 0; } } } int Log::vprint(char const* fmt, va_list args) { - pthread_mutex_lock(& _mtx); + pthread_mutex_lock(& _mutex); // print to buffer char buf[MAX_MESSAGE_LENGTH]; @@ -161,11 +161,11 @@ int Log::vprint(char const* fmt, va_list args) { } else { // error? -> mutter on stream or stderr - fprintf(_ptrStream != 0l ? _ptrStream : stderr, + fprintf(_stream != 0l ? _stream : stderr, "Log: Failed to log message with format string = \"%s\".\n", fmt); } - pthread_mutex_unlock(& _mtx); + pthread_mutex_unlock(& _mutex); return n; } @@ -179,22 +179,22 @@ void Log::operator()(char const* fmt, ...) { void Log::setLogWidth(unsigned pixels) { - pthread_mutex_lock(& _mtx); - _valLogWidth = pixels; - _valLineLength = _valLogWidth / _valCharWidth; - pthread_mutex_unlock(& _mtx); + pthread_mutex_lock(& _mutex); + _logWidth = pixels; + _lineLength = _logWidth / _charWidth; + pthread_mutex_unlock(& _mutex); } void Log::setCharacterSize(unsigned width, unsigned height) { - pthread_mutex_lock(& _mtx); - _valCharWidth = width; - _valCharHeight = height; - _valCharYoffset = height * CHAR_FRACT_BASELINE; - _valCharScale = float(width) / CHAR_WIDTH; - _valCharAspect = (height * CHAR_WIDTH) / (width * CHAR_HEIGHT); - _valLineLength = _valLogWidth / _valCharWidth; - pthread_mutex_unlock(& _mtx); + pthread_mutex_lock(& _mutex); + _charWidth = width; + _charHeight = height; + _charYoffset = height * CHAR_FRACT_BASELINE; + _charScale = float(width) / CHAR_WIDTH; + _charAspect = (height * CHAR_WIDTH) / (width * CHAR_HEIGHT); + _lineLength = _logWidth / _charWidth; + pthread_mutex_unlock(& _mutex); } static TextRenderer* textRenderer() { @@ -206,17 +206,17 @@ void Log::render(unsigned screenWidth, unsigned screenHeight) { // rendering might take some time, so create a local copy of the portion we need // instead of having to hold the mutex all the time - pthread_mutex_lock(& _mtx); + pthread_mutex_lock(& _mutex); // determine number of visible lines - unsigned showLines = divRoundUp(screenHeight, _valCharHeight); + unsigned showLines = divRoundUp(screenHeight, _charHeight); - char** lastLine = _itrLastLine; - char** firstLine = _itrLastLine; + char** lastLine = _lastLinePos; + char** firstLine = _lastLinePos; if (! *lastLine) { // empty log - pthread_mutex_unlock(& _mtx); + pthread_mutex_unlock(& _mutex); return; } @@ -225,8 +225,8 @@ void Log::render(unsigned screenWidth, unsigned screenHeight) { char** prevFirstLine = firstLine; --firstLine; - if (firstLine < _arrLines) { - firstLine = _ptrLinesEnd - 1; + if (firstLine < _lines) { + firstLine = _linesEnd - 1; } if (! *firstLine) { firstLine = prevFirstLine; @@ -235,37 +235,37 @@ void Log::render(unsigned screenWidth, unsigned screenHeight) { } // debug mode: make sure all line pointers we find here are valid - assert(! (firstLine < _arrLines || firstLine >= _ptrLinesEnd)); - assert(! (*firstLine < _arrChars || *firstLine >= _ptrCharsEnd)); + assert(! (firstLine < _lines || firstLine >= _linesEnd)); + assert(! (*firstLine < _chars || *firstLine >= _charsEnd)); } - // copy the line buffer portion into a contiguous region at _ptrLinesEnd + // copy the line buffer portion into a contiguous region at _linesEnd if (firstLine <= lastLine) { - memcpy(_ptrLinesEnd, firstLine, showLines * sizeof(char*)); + memcpy(_linesEnd, firstLine, showLines * sizeof(char*)); } else { - unsigned atEnd = _ptrLinesEnd - firstLine; - memcpy(_ptrLinesEnd, firstLine, atEnd * sizeof(char*)); - memcpy(_ptrLinesEnd + atEnd, _arrLines, (showLines - atEnd) * sizeof(char*)); + unsigned atEnd = _linesEnd - firstLine; + memcpy(_linesEnd, firstLine, atEnd * sizeof(char*)); + memcpy(_linesEnd + atEnd, _lines, (showLines - atEnd) * sizeof(char*)); } // copy relevant char buffer portion and determine information to remap the pointers char* firstChar = *firstLine; char* lastChar = *lastLine + strlen(*lastLine) + 1; - ptrdiff_t charOffset = _ptrCharsEnd - firstChar, charOffsetBeforeFirst = 0; + ptrdiff_t charOffset = _charsEnd - firstChar, charOffsetBeforeFirst = 0; if (firstChar <= lastChar) { - memcpy(_ptrCharsEnd, firstChar, lastChar - firstChar + 1); + memcpy(_charsEnd, firstChar, lastChar - firstChar + 1); } else { - unsigned atEnd = _ptrCharsEnd - firstChar; - memcpy(_ptrCharsEnd, firstChar, atEnd); - memcpy(_ptrCharsEnd + atEnd, _arrChars, lastChar + 1 - _arrChars); + unsigned atEnd = _charsEnd - firstChar; + memcpy(_charsEnd, firstChar, atEnd); + memcpy(_charsEnd + atEnd, _chars, lastChar + 1 - _chars); - charOffsetBeforeFirst = _ptrCharsEnd + atEnd - _arrChars; + charOffsetBeforeFirst = _charsEnd + atEnd - _chars; } // get values for rendering @@ -273,31 +273,31 @@ void Log::render(unsigned screenWidth, unsigned screenHeight) { int yStart = screenHeight - textRenderer()->metrics().descent(); // render text - char** line = _ptrLinesEnd + showLines; - int x = screenWidth - _valLogWidth; + char** line = _linesEnd + showLines; + int x = screenWidth - _logWidth; - pthread_mutex_unlock(& _mtx); + pthread_mutex_unlock(& _mutex); // ok, we got all we need for (int y = yStart; y > 0; y -= yStep) { // debug mode: check line pointer is valid - assert(! (line < _ptrLinesEnd || line >= _ptrLinesEnd + (_ptrLinesEnd - _arrLines))); + assert(! (line < _linesEnd || line >= _linesEnd + (_linesEnd - _lines))); // get character pointer - if (--line < _ptrLinesEnd) { + if (--line < _linesEnd) { break; } char* chars = *line; // debug mode: check char pointer we find is valid - assert(! (chars < _arrChars || chars >= _ptrCharsEnd)); + assert(! (chars < _chars || chars >= _charsEnd)); // remap character pointer it to copied buffer chars += chars >= firstChar ? charOffset : charOffsetBeforeFirst; // debug mode: check char pointer is still valid (in new range) - assert(! (chars < _ptrCharsEnd || chars >= _ptrCharsEnd + (_ptrCharsEnd - _arrChars))); + assert(! (chars < _charsEnd || chars >= _charsEnd + (_charsEnd - _chars))); // render the string glColor3f(TEXT_RED, TEXT_GREEN, TEXT_BLUE); diff --git a/interface/src/Log.h b/interface/src/Log.h index beaca0abf0..17c693142c 100644 --- a/interface/src/Log.h +++ b/interface/src/Log.h @@ -48,26 +48,26 @@ extern Log logger; // Logging subsystem. // class Log { - FILE* _ptrStream; - char* _arrChars; - char* _ptrCharsEnd; - char** _arrLines; - char** _ptrLinesEnd; + FILE* _stream; + char* _chars; + char* _charsEnd; + char** _lines; + char** _linesEnd; - char* _itrWritePos; // character position to write to - char* _itrWriteLineStart; // character position where line being written starts - char** _itrLastLine; // last line in the log - unsigned _valWrittenInLine; // character counter for line wrapping - unsigned _valLineLength; // number of characters before line wrap + char* _writePos; // character position to write to + char* _writeLineStartPos; // character position where line being written starts + char** _lastLinePos; // last line in the log + unsigned _writtenInLine; // character counter for line wrapping + unsigned _lineLength; // number of characters before line wrap - unsigned _valLogWidth; // width of the log in pixels - unsigned _valCharWidth; // width of a character in pixels - unsigned _valCharHeight; // height of a character in pixels - unsigned _valCharYoffset; // baseline offset in pixels - float _valCharScale; // scale factor - float _valCharAspect; // aspect (h/w) + unsigned _logWidth; // width of the log in pixels + unsigned _charWidth; // width of a character in pixels + unsigned _charHeight; // height of a character in pixels + unsigned _charYoffset; // baseline offset in pixels + float _charScale; // scale factor + float _charAspect; // aspect (h/w) - pthread_mutex_t _mtx; + pthread_mutex_t _mutex; public: diff --git a/interface/src/LogStream.h b/interface/src/LogStream.h index 88e5d4fff0..2b8cc25669 100644 --- a/interface/src/LogStream.h +++ b/interface/src/LogStream.h @@ -26,9 +26,9 @@ // lOut << "Hello there!" << std::endl; // class LogStream { - std::ostringstream _objOutStream; - Log& _refLog; - bool _flgThreadSafe; + std::ostringstream _outStream; + Log& _logRef; + bool _isThreadSafe; public: inline LogStream(Log& log, bool threadSafe = false); @@ -46,26 +46,26 @@ private: }; inline LogStream::LogStream(Log& log, bool threadSafe) : - _objOutStream(std::ios_base::out), _refLog(log), _flgThreadSafe(threadSafe) { } + _outStream(std::ios_base::out), _logRef(log), _isThreadSafe(threadSafe) { } inline void LogStream::ostreamBegin() { - if (_flgThreadSafe) { + if (_isThreadSafe) { // the user wants to share this LogStream among threads, // so lock the global log here, already - pthread_mutex_lock(& _refLog._mtx); + pthread_mutex_lock(& _logRef._mutex); } - _objOutStream.str(""); + _outStream.str(""); } inline void LogStream::ostreamEnd() { - if (! _flgThreadSafe) { + if (! _isThreadSafe) { // haven't locked, so far (we have memory for each thread) - pthread_mutex_lock(& _refLog._mtx); + pthread_mutex_lock(& _logRef._mutex); } - _refLog.addMessage(_objOutStream.str().c_str()); - pthread_mutex_unlock(& _refLog._mtx); + _logRef.addMessage(_outStream.str().c_str()); + pthread_mutex_unlock(& _logRef._mutex); } @@ -73,22 +73,22 @@ inline void LogStream::ostreamEnd() { // The Log::StreamRef class makes operator<< work. It... // class LogStream::StreamRef { - mutable LogStream* _ptrLogStream; + mutable LogStream* _logStream; typedef std::ostream& (*manipulator)(std::ostream&); friend class LogStream; template< typename T > friend inline LogStream::StreamRef const operator<<(LogStream&, T const&); - StreamRef(LogStream* log) : _ptrLogStream(log) { } + StreamRef(LogStream* log) : _logStream(log) { } public: // ...forwards << operator calls to stringstream... - template< typename T > StreamRef const operator<<(T const& x) const { _ptrLogStream->_objOutStream << x; return *this; } + template< typename T > StreamRef const operator<<(T const& x) const { _logStream->_outStream << x; return *this; } // ...has to dance around to make manipulators (such as std::hex, std::endl) work... - StreamRef const operator<<(manipulator x) const { _ptrLogStream->_objOutStream << x; return *this; } + StreamRef const operator<<(manipulator x) const { _logStream->_outStream << x; return *this; } // ...informs the logger that a stream has ended when it has the responsibility... - ~StreamRef() { if (_ptrLogStream != 0l) { _ptrLogStream->ostreamEnd(); } } + ~StreamRef() { if (_logStream != 0l) { _logStream->ostreamEnd(); } } // ...which is passed on upon copy. - StreamRef(StreamRef const& other) : _ptrLogStream(other._ptrLogStream) { other._ptrLogStream = 0l; } + StreamRef(StreamRef const& other) : _logStream(other._logStream) { other._logStream = 0l; } private: // don't @@ -98,7 +98,7 @@ private: template< typename T > inline LogStream::StreamRef const operator<<(LogStream& s, T const& x) { s.ostreamBegin(); - s._objOutStream << x; + s._outStream << x; return LogStream::StreamRef(& s); // calls streamEnd at the end of the stream expression } diff --git a/interface/src/Oscilloscope.cpp b/interface/src/Oscilloscope.cpp index d4b6a103bb..e5f076c7b3 100644 --- a/interface/src/Oscilloscope.cpp +++ b/interface/src/Oscilloscope.cpp @@ -33,26 +33,26 @@ namespace { // everything in here only exists while compiling this .cpp file Oscilloscope::Oscilloscope(int w, int h, bool isEnabled) : - _valWidth(w), _valHeight(h), - _arrSamples(0l), _arrVertices(0l), - _valLowpassFactor(0.4f), _valDownsampleFactor(3), + _width(w), _height(h), + _samples(0l), _vertices(0l), + _lowpassFactor(0.4f), _downsampleFactor(3), enabled(isEnabled), inputPaused(false) { // allocate enough space for the sample data and to turn it into // vertices and since they're all 'short', do so in one shot - _arrSamples = new short[N_INT16_TO_ALLOC]; - memset(_arrSamples, 0, N_INT16_TO_ALLOC * sizeof(short)); - _arrVertices = _arrSamples + MAX_SAMPLES; + _samples = new short[N_INT16_TO_ALLOC]; + memset(_samples, 0, N_INT16_TO_ALLOC * sizeof(short)); + _vertices = _samples + MAX_SAMPLES; // initialize write positions to start of each channel's region for (unsigned ch = 0; ch < MAX_CHANNELS; ++ch) { - _arrWritePos[ch] = MAX_SAMPLES_PER_CHANNEL * ch; + _writePos[ch] = MAX_SAMPLES_PER_CHANNEL * ch; } } Oscilloscope::~Oscilloscope() { - delete[] _arrSamples; + delete[] _samples; } void Oscilloscope::addSamples(unsigned ch, short const* data, unsigned n) { @@ -66,7 +66,7 @@ void Oscilloscope::addSamples(unsigned ch, short const* data, unsigned n) { unsigned endOffs = baseOffs + MAX_SAMPLES_PER_CHANNEL; // fetch write position for this channel - unsigned writePos = _arrWritePos[ch]; + unsigned writePos = _writePos[ch]; // determine write position after adding the samples unsigned newWritePos = writePos + n; @@ -79,13 +79,13 @@ void Oscilloscope::addSamples(unsigned ch, short const* data, unsigned n) { } // copy data - memcpy(_arrSamples + writePos, data, n * sizeof(short)); + memcpy(_samples + writePos, data, n * sizeof(short)); if (n2 > 0) { - memcpy(_arrSamples + baseOffs, data + n, n2 * sizeof(short)); + memcpy(_samples + baseOffs, data + n, n2 * sizeof(short)); } // set new write position for this channel - _arrWritePos[ch] = newWritePos; + _writePos[ch] = newWritePos; } void Oscilloscope::render(int x, int y) { @@ -95,19 +95,19 @@ void Oscilloscope::render(int x, int y) { } // determine lowpass / downsample factors - int lowpass = -int(std::numeric_limits::min()) * _valLowpassFactor; - unsigned downsample = _valDownsampleFactor; + int lowpass = -int(std::numeric_limits::min()) * _lowpassFactor; + unsigned downsample = _downsampleFactor; // keep half of the buffer for writing and ensure an even vertex count - unsigned usedWidth = min(_valWidth, MAX_SAMPLES_PER_CHANNEL / (downsample * 2)) & ~1u; + unsigned usedWidth = min(_width, MAX_SAMPLES_PER_CHANNEL / (downsample * 2)) & ~1u; unsigned usedSamples = usedWidth * downsample; // expand samples to vertex data for (unsigned ch = 0; ch < MAX_CHANNELS; ++ch) { // for each channel: determine memory regions - short const* basePtr = _arrSamples + MAX_SAMPLES_PER_CHANNEL * ch; + short const* basePtr = _samples + MAX_SAMPLES_PER_CHANNEL * ch; short const* endPtr = basePtr + MAX_SAMPLES_PER_CHANNEL; - short const* inPtr = _arrSamples + _arrWritePos[ch]; - short* outPtr = _arrVertices + MAX_COORDS_PER_CHANNEL * ch; + short const* inPtr = _samples + _writePos[ch]; + short* outPtr = _vertices + MAX_COORDS_PER_CHANNEL * ch; int sample = 0, x = usedWidth; for (int i = int(usedSamples); --i >= 0 ;) { if (inPtr == basePtr) { @@ -124,13 +124,13 @@ void Oscilloscope::render(int x, int y) { } } - // set up rendering state (vertex data lives at _arrVertices) + // set up rendering state (vertex data lives at _vertices) glLineWidth(1.0); glDisable(GL_LINE_SMOOTH); glPushMatrix(); - glTranslatef((float)x + 0.0f, (float)y + _valHeight / 2.0f, 0.0f); - glScaled(1.0f, _valHeight / 32767.0f, 1.0f); - glVertexPointer(2, GL_SHORT, 0, _arrVertices); + glTranslatef((float)x + 0.0f, (float)y + _height / 2.0f, 0.0f); + glScaled(1.0f, _height / 32767.0f, 1.0f); + glVertexPointer(2, GL_SHORT, 0, _vertices); glEnableClientState(GL_VERTEX_ARRAY); // render channel 0 diff --git a/interface/src/Oscilloscope.h b/interface/src/Oscilloscope.h index 23a6632896..e13ecb1ce9 100644 --- a/interface/src/Oscilloscope.h +++ b/interface/src/Oscilloscope.h @@ -26,8 +26,8 @@ public: volatile bool enabled; volatile bool inputPaused; - void setLowpass(float w) { assert(w > 0.0f && w <= 1.0f); _valLowpassFactor = w; } - void setDownsampling(unsigned f) { assert(f > 0); _valDownsampleFactor = f; } + void setLowpass(float w) { assert(w > 0.0f && w <= 1.0f); _lowpassFactor = w; } + void setDownsampling(unsigned f) { assert(f > 0); _downsampleFactor = f; } private: // don't copy/assign @@ -36,14 +36,14 @@ private: // state variables - unsigned _valWidth; - unsigned _valHeight; - short* _arrSamples; - short* _arrVertices; - unsigned _arrWritePos[MAX_CHANNELS]; + unsigned _width; + unsigned _height; + short* _samples; + short* _vertices; + unsigned _writePos[MAX_CHANNELS]; - float _valLowpassFactor; - unsigned _valDownsampleFactor; + float _lowpassFactor; + unsigned _downsampleFactor; }; #endif /* defined(__interface__oscilloscope__) */ diff --git a/interface/src/Stars.cpp b/interface/src/Stars.cpp index e8e0222420..7934190e4c 100644 --- a/interface/src/Stars.cpp +++ b/interface/src/Stars.cpp @@ -14,24 +14,24 @@ #undef __interface__Starfield_impl__ Stars::Stars() : - _ptrController(0l) { - _ptrController = new starfield::Controller; + _controller(0l) { + _controller = new starfield::Controller; } Stars::~Stars() { - delete _ptrController; + delete _controller; } bool Stars::readInput(const char* url, const char* cacheFile, unsigned limit) { - return _ptrController->readInput(url, cacheFile, limit); + return _controller->readInput(url, cacheFile, limit); } bool Stars::setResolution(unsigned k) { - return _ptrController->setResolution(k); + return _controller->setResolution(k); } float Stars::changeLOD(float fraction, float overalloc, float realloc) { - return float(_ptrController->changeLOD(fraction, overalloc, realloc)); + return float(_controller->changeLOD(fraction, overalloc, realloc)); } void Stars::render(float fovY, float aspect, float nearZ, float alpha) { @@ -46,7 +46,7 @@ void Stars::render(float fovY, float aspect, float nearZ, float alpha) { // pull the modelview matrix off the GL stack glm::mat4 view; glGetFloatv(GL_MODELVIEW_MATRIX, glm::value_ptr(view)); - _ptrController->render(fovDiagonal, aspect, glm::affineInverse(view), alpha); + _controller->render(fovDiagonal, aspect, glm::affineInverse(view), alpha); } diff --git a/interface/src/Stars.h b/interface/src/Stars.h index 7088bee36e..8fa425f3a6 100644 --- a/interface/src/Stars.h +++ b/interface/src/Stars.h @@ -18,7 +18,7 @@ namespace starfield { class Controller; } // class Stars { - starfield::Controller* _ptrController; + starfield::Controller* _controller; public: diff --git a/interface/src/starfield/Controller.h b/interface/src/starfield/Controller.h index 3bbb7009a7..3ac15712d6 100644 --- a/interface/src/starfield/Controller.h +++ b/interface/src/starfield/Controller.h @@ -56,35 +56,35 @@ namespace starfield { class Controller { - InputVertices _seqInput; + InputVertices _inputSequence; #if STARFIELD_MULTITHREADING - mutex _mtxInput; - atomic _valTileResolution; + mutex _inputMutex; + atomic _tileResolution; - mutex _mtxLodState; + mutex _lodStateMutex; #else - unsigned _valTileResolution; + unsigned _tileResolution; #endif - double _valLodFraction; - double _valLodLowWaterMark; - double _valLodHighWaterMark; - double _valLodOveralloc; - size_t _valLodNalloc; - size_t _valLodNRender; - BrightnessLevels _seqLodBrightness; + double _lodFraction; + double _lodLowWaterMark; + double _lodHighWaterMark; + double _lodOveralloc; + size_t _lodNalloc; + size_t _lodNRender; + BrightnessLevels _lodBrightnessSequence; #if STARFIELD_MULTITHREADING - atomic _valLodBrightness; - BrightnessLevel _valLodAllocBrightness; + atomic _lodBrightness; + BrightnessLevel _lodAllocBrightness; - atomic _ptrRenderer; + atomic _renderer; typedef lock_guard lock; #else - BrightnessLevel _valLodBrightness; - BrightnessLevel _valLodAllocBrightness; + BrightnessLevel _lodBrightness; + BrightnessLevel _lodAllocBrightness; - Renderer* _ptrRenderer; + Renderer* _renderer; #define lock #define _(x) @@ -97,16 +97,16 @@ namespace starfield { public: Controller() : - _valTileResolution(20), - _valLodFraction(1.0), - _valLodLowWaterMark(0.8), - _valLodHighWaterMark(1.0), - _valLodOveralloc(1.2), - _valLodNalloc(0), - _valLodNRender(0), - _valLodBrightness(0), - _valLodAllocBrightness(0), - _ptrRenderer(0l) { + _tileResolution(20), + _lodFraction(1.0), + _lodLowWaterMark(0.8), + _lodHighWaterMark(1.0), + _lodOveralloc(1.2), + _lodNalloc(0), + _lodNRender(0), + _lodBrightness(0), + _lodAllocBrightness(0), + _renderer(0l) { } bool readInput(const char* url, const char* cacheFile, unsigned limit) @@ -121,13 +121,13 @@ namespace starfield { // input is read, now run the entire data pipeline on the new input - { lock _(_mtxInput); + { lock _(_inputMutex); - _seqInput.swap(vertices); + _inputSequence.swap(vertices); #if STARFIELD_MULTITHREADING - unsigned k = _valTileResolution.load(memory_order_relaxed); + unsigned k = _tileResolution.load(memory_order_relaxed); #else - unsigned k = _valTileResolution; + unsigned k = _tileResolution; #endif size_t n, nRender; BrightnessLevel bMin, b; @@ -136,27 +136,27 @@ namespace starfield { // we'll have to build a new LOD state for a new total N, // ideally keeping allocation size and number of vertices - { lock _(_mtxLodState); + { lock _(_lodStateMutex); - size_t newLast = _seqInput.size() - 1; + size_t newLast = _inputSequence.size() - 1; // reciprocal change N_old/N_new tells us how to scale // the fractions - rcpChange = min(1.0, double(vertices.size()) / _seqInput.size()); + rcpChange = min(1.0, double(vertices.size()) / _inputSequence.size()); // initialization? use defaults / previously set values if (rcpChange == 0.0) { rcpChange = 1.0; - nRender = toBufSize(_valLodFraction * newLast); - n = min(newLast, toBufSize(_valLodOveralloc * nRender)); + nRender = toBufSize(_lodFraction * newLast); + n = min(newLast, toBufSize(_lodOveralloc * nRender)); } else { // cannot allocate or render more than we have - n = min(newLast, _valLodNalloc); - nRender = min(newLast, _valLodNRender); + n = min(newLast, _lodNalloc); + nRender = min(newLast, _lodNRender); } // determine new minimum brightness levels @@ -178,26 +178,26 @@ namespace starfield { } catch (...) { // rollback transaction and rethrow - vertices.swap(_seqInput); + vertices.swap(_inputSequence); throw; } // finally publish the new LOD state - { lock _(_mtxLodState); + { lock _(_lodStateMutex); - _seqLodBrightness.swap(brightness); - _valLodFraction *= rcpChange; - _valLodLowWaterMark *= rcpChange; - _valLodHighWaterMark *= rcpChange; - _valLodOveralloc *= rcpChange; - _valLodNalloc = n; - _valLodNRender = nRender; - _valLodAllocBrightness = bMin; + _lodBrightnessSequence.swap(brightness); + _lodFraction *= rcpChange; + _lodLowWaterMark *= rcpChange; + _lodHighWaterMark *= rcpChange; + _lodOveralloc *= rcpChange; + _lodNalloc = n; + _lodNRender = nRender; + _lodAllocBrightness = bMin; #if STARFIELD_MULTITHREADING - _valLodBrightness.store(b, memory_order_relaxed); + _lodBrightness.store(b, memory_order_relaxed); #else - _valLodBrightness = b; + _lodBrightness = b; #endif } } @@ -214,24 +214,24 @@ namespace starfield { // printLog("Stars.cpp: setResolution(%d)\n", k); #if STARFIELD_MULTITHREADING - if (k != _valTileResolution.load(memory_order_relaxed)) + if (k != _tileResolution.load(memory_order_relaxed)) #else - if (k != _valTileResolution) + if (k != _tileResolution) #endif - { lock _(_mtxInput); + { lock _(_inputMutex); unsigned n; BrightnessLevel b, bMin; - { lock _(_mtxLodState); + { lock _(_lodStateMutex); - n = _valLodNalloc; + n = _lodNalloc; #if STARFIELD_MULTITHREADING - b = _valLodBrightness.load(memory_order_relaxed); + b = _lodBrightness.load(memory_order_relaxed); #else - b = _valLodBrightness; + b = _lodBrightness; #endif - bMin = _valLodAllocBrightness; + bMin = _lodAllocBrightness; } this->retile(n, k, b, bMin); @@ -249,14 +249,14 @@ namespace starfield { Tiling tiling(k); VertexOrder scanner(tiling); - radix2InplaceSort(_seqInput.begin(), _seqInput.end(), scanner); + radix2InplaceSort(_inputSequence.begin(), _inputSequence.end(), scanner); // printLog( // "Stars.cpp: recreateRenderer(%d, %d, %d, %d)\n", n, k, b, bMin); recreateRenderer(n, k, b, bMin); - _valTileResolution = k; + _tileResolution = k; } public: @@ -273,13 +273,13 @@ namespace starfield { BrightnessLevel bMin, b; double fraction, lwm, hwm; - { lock _(_mtxLodState); + { lock _(_lodStateMutex); // acuire a consistent copy of the current LOD state - fraction = _valLodFraction; - lwm = _valLodLowWaterMark; - hwm = _valLodHighWaterMark; - size_t last = _seqLodBrightness.size() - 1; + fraction = _lodFraction; + lwm = _lodLowWaterMark; + hwm = _lodHighWaterMark; + size_t last = _lodBrightnessSequence.size() - 1; // apply factor fraction = max(0.0, min(1.0, fraction * factor)); @@ -288,23 +288,23 @@ namespace starfield { // threshold double oaFract = std::min(fraction * (1.0 + overalloc), 1.0); n = toBufSize(oaFract * last); - bMin = _seqLodBrightness[n]; + bMin = _lodBrightnessSequence[n]; n = std::upper_bound( - _seqLodBrightness.begin() + n - 1, - _seqLodBrightness.end(), - bMin, GreaterBrightness() ) - _seqLodBrightness.begin(); + _lodBrightnessSequence.begin() + n - 1, + _lodBrightnessSequence.end(), + bMin, GreaterBrightness() ) - _lodBrightnessSequence.begin(); // also determine number of vertices to render and brightness nRender = toBufSize(fraction * last); // Note: nRender does not have to be accurate - b = _seqLodBrightness[nRender]; + b = _lodBrightnessSequence[nRender]; // this setting controls the renderer, also keep b as the // brightness becomes volatile as soon as the mutex is // released, so keep b #if STARFIELD_MULTITHREADING - _valLodBrightness.store(b, memory_order_relaxed); + _lodBrightness.store(b, memory_order_relaxed); #else - _valLodBrightness = b; + _lodBrightness = b; #endif // printLog("Stars.cpp: " @@ -313,34 +313,34 @@ namespace starfield { // will not have to reallocate? set new fraction right away // (it is consistent with the rest of the state in this case) - if (fraction >= _valLodLowWaterMark - && fraction <= _valLodHighWaterMark) { + if (fraction >= _lodLowWaterMark + && fraction <= _lodHighWaterMark) { - _valLodFraction = fraction; + _lodFraction = fraction; return fraction; } } // reallocate - { lock _(_mtxInput); + { lock _(_inputMutex); - recreateRenderer(n, _valTileResolution, b, bMin); + recreateRenderer(n, _tileResolution, b, bMin); // printLog("Stars.cpp: LOD reallocation\n"); // publish new lod state - { lock _(_mtxLodState); + { lock _(_lodStateMutex); - _valLodNalloc = n; - _valLodNRender = nRender; + _lodNalloc = n; + _lodNRender = nRender; - _valLodFraction = fraction; - _valLodLowWaterMark = fraction * (1.0 - realloc); - _valLodHighWaterMark = fraction * (1.0 + realloc); - _valLodOveralloc = fraction * (1.0 + overalloc); - _valLodAllocBrightness = bMin; + _lodFraction = fraction; + _lodLowWaterMark = fraction * (1.0 - realloc); + _lodHighWaterMark = fraction * (1.0 + realloc); + _lodOveralloc = fraction * (1.0 + overalloc); + _lodAllocBrightness = bMin; } } return fraction; @@ -352,10 +352,10 @@ namespace starfield { BrightnessLevel b, BrightnessLevel bMin) { #if STARFIELD_MULTITHREADING - delete _ptrRenderer.exchange(new Renderer(_seqInput, n, k, b, bMin) ); + delete _renderer.exchange(new Renderer(_inputSequence, n, k, b, bMin) ); #else - delete _ptrRenderer; - _ptrRenderer = new Renderer(_seqInput, n, k, b, bMin); + delete _renderer; + _renderer = new Renderer(_inputSequence, n, k, b, bMin); #endif } @@ -365,17 +365,17 @@ namespace starfield { #if STARFIELD_MULTITHREADING // check out renderer - Renderer* renderer = _ptrRenderer.exchange(0l); + Renderer* renderer = _renderer.exchange(0l); #else - Renderer* renderer = _ptrRenderer; + Renderer* renderer = _renderer; #endif // have it render if (renderer != 0l) { #if STARFIELD_MULTITHREADING - BrightnessLevel b = _valLodBrightness.load(memory_order_relaxed); + BrightnessLevel b = _lodBrightness.load(memory_order_relaxed); #else - BrightnessLevel b = _valLodBrightness; + BrightnessLevel b = _lodBrightness; #endif renderer->render(perspective, angle, orientation, b, alpha); } @@ -383,7 +383,7 @@ namespace starfield { #if STARFIELD_MULTITHREADING // check in - or dispose if there is a new one Renderer* newOne = 0l; - if (! _ptrRenderer.compare_exchange_strong(newOne, renderer)) { + if (! _renderer.compare_exchange_strong(newOne, renderer)) { assert(!! newOne); delete renderer; diff --git a/interface/src/starfield/Loader.h b/interface/src/starfield/Loader.h index 79ae7f7700..9bb0aa076c 100644 --- a/interface/src/starfield/Loader.h +++ b/interface/src/starfield/Loader.h @@ -24,35 +24,35 @@ namespace starfield { class Loader : UrlReader { - InputVertices* _ptrVertices; - unsigned _valLimit; + InputVertices* _vertices; + unsigned _limit; - unsigned _valLineNo; - char const* _strUrl; + unsigned _lineNo; + char const* _urlStr; - unsigned _valRecordsRead; - BrightnessLevel _valMinBrightness; + unsigned _recordsRead; + BrightnessLevel _minBrightness; public: bool loadVertices( InputVertices& destination, char const* url, char const* cacheFile, unsigned limit) { - _ptrVertices = & destination; - _valLimit = limit; + _vertices = & destination; + _limit = limit; #if STARFIELD_SAVE_MEMORY - if (_valLimit == 0 || _valLimit > 60000u) - _valLimit = 60000u; + if (_limit == 0 || _limit > 60000u) + _limit = 60000u; #endif - _strUrl = url; // in case we fail early + _urlStr = url; // in case we fail early if (! UrlReader::readUrl(url, *this, cacheFile)) { printLog("%s:%d: %s\n", - _strUrl, _valLineNo, getError()); + _urlStr, _lineNo, getError()); return false; } - printLog("Loaded %u stars.\n", _valRecordsRead); + printLog("Loaded %u stars.\n", _recordsRead); return true; } @@ -66,13 +66,13 @@ namespace starfield { int64_t size, int64_t stardate) { - _valLineNo = 0u; - _strUrl = url; // new value in http redirect + _lineNo = 0u; + _urlStr = url; // new value in http redirect - _valRecordsRead = 0u; + _recordsRead = 0u; - _ptrVertices->clear(); - _ptrVertices->reserve(_valLimit); + _vertices->clear(); + _vertices->reserve(_limit); // printLog("Stars.cpp: loader begin %s\n", url); } @@ -88,7 +88,7 @@ namespace starfield { for (; next != end && isspace(*next); ++next); consumed = next - input; line = next; - ++_valLineNo; + ++_lineNo; for (; next != end && *next != '\n' && *next != '\r'; ++next); if (next == end) return consumed; @@ -109,12 +109,12 @@ namespace starfield { storeVertex(azi, alt, c); } - ++_valRecordsRead; + ++_recordsRead; } else { printLog("Stars.cpp:%d: Bad input from %s\n", - _valLineNo, _strUrl); + _lineNo, _urlStr); } } @@ -126,7 +126,7 @@ namespace starfield { private: - bool atLimit() { return _valLimit > 0u && _valRecordsRead >= _valLimit; } + bool atLimit() { return _limit > 0u && _recordsRead >= _limit; } bool spaceFor(BrightnessLevel b) { @@ -136,42 +136,42 @@ namespace starfield { // just reached the limit? -> establish a minimum heap and // remember the brightness at its top - if (_valRecordsRead == _valLimit) { + if (_recordsRead == _limit) { // printLog("Stars.cpp: vertex limit reached -> heap mode\n"); make_heap( - _ptrVertices->begin(), _ptrVertices->end(), + _vertices->begin(), _vertices->end(), GreaterBrightness() ); - _valMinBrightness = getBrightness( - _ptrVertices->begin()->getColor() ); + _minBrightness = getBrightness( + _vertices->begin()->getColor() ); } // not interested? say so - if (_valMinBrightness >= b) + if (_minBrightness >= b) return false; // otherwise free up space for the new vertex pop_heap( - _ptrVertices->begin(), _ptrVertices->end(), + _vertices->begin(), _vertices->end(), GreaterBrightness() ); - _ptrVertices->pop_back(); + _vertices->pop_back(); return true; } void storeVertex(float azi, float alt, unsigned color) { - _ptrVertices->push_back(InputVertex(azi, alt, color)); + _vertices->push_back(InputVertex(azi, alt, color)); if (atLimit()) { push_heap( - _ptrVertices->begin(), _ptrVertices->end(), + _vertices->begin(), _vertices->end(), GreaterBrightness() ); - _valMinBrightness = getBrightness( - _ptrVertices->begin()->getColor() ); + _minBrightness = getBrightness( + _vertices->begin()->getColor() ); } } }; diff --git a/interface/src/starfield/data/GpuVertex.h b/interface/src/starfield/data/GpuVertex.h index 6de3b5a15f..1cc3e001a9 100644 --- a/interface/src/starfield/data/GpuVertex.h +++ b/interface/src/starfield/data/GpuVertex.h @@ -19,7 +19,7 @@ namespace starfield { class GpuVertex { - unsigned _valColor; + unsigned _color; float _valX; float _valY; float _valZ; @@ -29,7 +29,7 @@ namespace starfield { GpuVertex(InputVertex const& in) { - _valColor = in.getColor(); + _color = in.getColor(); float azi = in.getAzimuth(); float alt = in.getAltitude(); @@ -44,7 +44,7 @@ namespace starfield { _valZ = gz * exz; } - unsigned getColor() const { return _valColor; } + unsigned getColor() const { return _color; } }; } // anonymous namespace diff --git a/interface/src/starfield/data/InputVertex.h b/interface/src/starfield/data/InputVertex.h index 670056bd74..bfc8093f86 100644 --- a/interface/src/starfield/data/InputVertex.h +++ b/interface/src/starfield/data/InputVertex.h @@ -19,14 +19,14 @@ namespace starfield { class InputVertex { - unsigned _valColor; - float _valAzimuth; - float _valAltitude; + unsigned _color; + float _azimuth; + float _altitude; public: InputVertex(float azimuth, float altitude, unsigned color) { - _valColor = ((color >> 16) & 0xffu) | (color & 0xff00u) | + _color = ((color >> 16) & 0xffu) | (color & 0xff00u) | ((color << 16) & 0xff0000u) | 0xff000000u; azimuth = angleConvert(azimuth); @@ -34,13 +34,13 @@ namespace starfield { angleHorizontalPolar(azimuth, altitude); - _valAzimuth = azimuth; - _valAltitude = altitude; + _azimuth = azimuth; + _altitude = altitude; } - float getAzimuth() const { return _valAzimuth; } - float getAltitude() const { return _valAltitude; } - unsigned getColor() const { return _valColor; } + float getAzimuth() const { return _azimuth; } + float getAltitude() const { return _altitude; } + unsigned getColor() const { return _color; } }; typedef std::vector InputVertices; diff --git a/interface/src/starfield/renderer/Renderer.h b/interface/src/starfield/renderer/Renderer.h index cf7cee6234..1d08951d03 100644 --- a/interface/src/starfield/renderer/Renderer.h +++ b/interface/src/starfield/renderer/Renderer.h @@ -65,20 +65,20 @@ namespace starfield { class Renderer { - GpuVertex* _arrData; - Tile* _arrTile; - GLint* _arrBatchOffs; - GLsizei* _arrBatchCount; - GLuint _hndVertexArray; - ProgramObject _objProgram; + GpuVertex* _dataArray; + Tile* _tileArray; + GLint* _batchOffs; + GLsizei* _batchCountArray; + GLuint _vertexArrayHandle; + ProgramObject _program; int _alphaLocationHandle; - Tiling _objTiling; + Tiling _tiling; - unsigned* _itrOutIndex; - vec3 _vecWRow; - float _valHalfPerspectiveAngle; - BrightnessLevel _valMinBright; + unsigned* _outIndexPos; + vec3 _wRowVec; + float _halfPerspectiveAngle; + BrightnessLevel _minBright; public: @@ -88,9 +88,9 @@ namespace starfield { BrightnessLevel b, BrightnessLevel bMin) : - _arrData(0l), - _arrTile(0l), - _objTiling(k) { + _dataArray(0l), + _tileArray(0l), + _tiling(k) { this->glAlloc(); @@ -101,10 +101,10 @@ namespace starfield { // REVISIT: batch arrays are probably oversized, but - hey - they // are not very large (unless for insane tiling) and we're better // off safe than sorry - _arrData = new GpuVertex[n]; - _arrTile = new Tile[nTiles + 1]; - _arrBatchOffs = new GLint[nTiles * 2]; - _arrBatchCount = new GLsizei[nTiles * 2]; + _dataArray = new GpuVertex[n]; + _tileArray = new Tile[nTiles + 1]; + _batchOffs = new GLint[nTiles * 2]; + _batchCountArray = new GLsizei[nTiles * 2]; prepareVertexData(src, n, tiling, b, bMin); @@ -113,10 +113,10 @@ namespace starfield { ~Renderer() { - delete[] _arrData; - delete[] _arrTile; - delete[] _arrBatchCount; - delete[] _arrBatchOffs; + delete[] _dataArray; + delete[] _tileArray; + delete[] _batchCountArray; + delete[] _batchOffs; this->glFree(); } @@ -172,23 +172,23 @@ namespace starfield { matrix = glm::frustum(-hw,hw, -hh,hh, nearClip,10.0f) * glm::affineInverse(matrix); - this->_itrOutIndex = (unsigned*) _arrBatchOffs; - this->_vecWRow = vec3(row(matrix, 3)); - this->_valHalfPerspectiveAngle = halfPersp; - this->_valMinBright = minBright; + this->_outIndexPos = (unsigned*) _batchOffs; + this->_wRowVec = vec3(row(matrix, 3)); + this->_halfPerspectiveAngle = halfPersp; + this->_minBright = minBright; TileSelection::Cursor cursor; - cursor.current = _arrTile + _objTiling.getTileIndex(azimuth, altitude); - cursor.firstInRow = _arrTile + _objTiling.getTileIndex(0.0f, altitude); + cursor.current = _tileArray + _tiling.getTileIndex(azimuth, altitude); + cursor.firstInRow = _tileArray + _tiling.getTileIndex(0.0f, altitude); - floodFill(cursor, TileSelection(*this, _arrTile, _arrTile + _objTiling.getTileCount(), - (TileSelection::Cursor*) _arrBatchCount)); + floodFill(cursor, TileSelection(*this, _tileArray, _tileArray + _tiling.getTileCount(), + (TileSelection::Cursor*) _batchCountArray)); #if STARFIELD_DEBUG_CULLING # define matrix matrix_debug #endif this->glBatch(glm::value_ptr(matrix), prepareBatch( - (unsigned*) _arrBatchOffs, _itrOutIndex), alpha); + (unsigned*) _batchOffs, _outIndexPos), alpha); #if STARFIELD_DEBUG_CULLING # undef matrix @@ -206,9 +206,9 @@ namespace starfield { size_t nTiles = tiling.getTileCount(); size_t vertexIndex = 0u, currTileIndex = 0u, count_active = 0u; - _arrTile[0].offset = 0u; - _arrTile[0].lod = b; - _arrTile[0].flags = 0u; + _tileArray[0].offset = 0u; + _tileArray[0].lod = b; + _tileArray[0].flags = 0u; for (InputVertices::const_iterator i = src.begin(), e = src.end(); i != e; ++i) { @@ -225,8 +225,8 @@ namespace starfield { // moved on to another tile? -> flush if (tileIndex != currTileIndex) { - Tile* t = _arrTile + currTileIndex; - Tile* tLast = _arrTile + tileIndex; + Tile* t = _tileArray + currTileIndex; + Tile* tLast = _tileArray + tileIndex; // set count of active vertices (upcoming lod) t->count = count_active; @@ -251,14 +251,14 @@ namespace starfield { // printLog("Stars.cpp: Vertex %d on tile #%d\n", vertexIndex, tileIndex); // write converted vertex - _arrData[vertexIndex++] = *i; + _dataArray[vertexIndex++] = *i; } } assert(vertexIndex == n); // flush last tile (see above) - Tile* t = _arrTile + currTileIndex; + Tile* t = _tileArray + currTileIndex; t->count = count_active; - for (Tile* e = _arrTile + nTiles + 1; ++t != e;) { + for (Tile* e = _tileArray + nTiles + 1; ++t != e;) { t->offset = vertexIndex, t->count = 0u, t->lod = b, t->flags = 0; } @@ -275,22 +275,22 @@ namespace starfield { public: struct Cursor { Tile* current, * firstInRow; }; private: - Renderer& _refRenderer; - Cursor* const _arrStack; - Cursor* _itrStack; - Tile const* const _arrTile; - Tile const* const _ptrTilesEnd; + Renderer& _rendererRef; + Cursor* const _stackArray; + Cursor* _stackPos; + Tile const* const _tileArray; + Tile const* const _tilesEnd; public: TileSelection(Renderer& renderer, Tile const* tiles, Tile const* tiles_end, Cursor* stack) : - _refRenderer(renderer), - _arrStack(stack), - _itrStack(stack), - _arrTile(tiles), - _ptrTilesEnd(tiles_end) { + _rendererRef(renderer), + _stackArray(stack), + _stackPos(stack), + _tileArray(tiles), + _tilesEnd(tiles_end) { } protected: @@ -300,7 +300,7 @@ namespace starfield { bool select(Cursor const& c) { Tile* t = c.current; - if (t < _arrTile || t >= _ptrTilesEnd || + if (t < _tileArray || t >= _tilesEnd || !! (t->flags & Tile::checked)) { // out of bounds or been here already @@ -309,7 +309,7 @@ namespace starfield { // will check now and never again t->flags |= Tile::checked; - if (_refRenderer.visitTile(t)) { + if (_rendererRef.visitTile(t)) { // good one -> remember (for batching) and propagate t->flags |= Tile::render; @@ -332,39 +332,39 @@ namespace starfield { void right(Cursor& c) const { c.current += 1; - if (c.current == c.firstInRow + _refRenderer._objTiling.getAzimuthalTiles()) { + if (c.current == c.firstInRow + _rendererRef._tiling.getAzimuthalTiles()) { c.current = c.firstInRow; } } void left(Cursor& c) const { if (c.current == c.firstInRow) { - c.current = c.firstInRow + _refRenderer._objTiling.getAzimuthalTiles(); + c.current = c.firstInRow + _rendererRef._tiling.getAzimuthalTiles(); } c.current -= 1; } void up(Cursor& c) const { - unsigned d = _refRenderer._objTiling.getAzimuthalTiles(); + unsigned d = _rendererRef._tiling.getAzimuthalTiles(); c.current += d; c.firstInRow += d; } void down(Cursor& c) const { - unsigned d = _refRenderer._objTiling.getAzimuthalTiles(); + unsigned d = _rendererRef._tiling.getAzimuthalTiles(); c.current -= d; c.firstInRow -= d; } void defer(Cursor const& t) { - *_itrStack++ = t; + *_stackPos++ = t; } bool deferred(Cursor& cursor) { - if (_itrStack != _arrStack) { - cursor = *--_itrStack; + if (_stackPos != _stackArray) { + cursor = *--_stackPos; return true; } return false; @@ -373,35 +373,35 @@ namespace starfield { bool visitTile(Tile* t) { - unsigned index = t - _arrTile; - *_itrOutIndex++ = index; + unsigned index = t - _tileArray; + *_outIndexPos++ = index; if (! tileVisible(t, index)) { return false; } - if (t->lod != _valMinBright) { - updateVertexCount(t, _valMinBright); + if (t->lod != _minBright) { + updateVertexCount(t, _minBright); } return true; } bool tileVisible(Tile* t, unsigned i) { - float slice = _objTiling.getSliceAngle(); + float slice = _tiling.getSliceAngle(); float halfSlice = 0.5f * slice; - unsigned stride = _objTiling.getAzimuthalTiles(); + unsigned stride = _tiling.getAzimuthalTiles(); float azimuth = (i % stride) * slice; float altitude = (i / stride) * slice - Radians::halfPi(); float gx = sin(azimuth); float gz = -cos(azimuth); float exz = cos(altitude); vec3 tileCenter = vec3(gx * exz, sin(altitude), gz * exz); - float w = dot(_vecWRow, tileCenter); + float w = dot(_wRowVec, tileCenter); float daz = halfSlice * cos(std::max(0.0f, abs(altitude) - halfSlice)); float dal = halfSlice; - float adjustedNear = cos(_valHalfPerspectiveAngle + sqrt(daz * daz + dal * dal)); + float adjustedNear = cos(_halfPerspectiveAngle + sqrt(daz * daz + dal * dal)); // printLog("Stars.cpp: checking tile #%d, w = %f, near = %f\n", i, w, nearClip); @@ -415,8 +415,8 @@ namespace starfield { // perform a binary search in the so found partition for the // new vertex count of this tile - GpuVertex const* start = _arrData + t[0].offset; - GpuVertex const* end = _arrData + t[1].offset; + GpuVertex const* start = _dataArray + t[0].offset; + GpuVertex const* end = _dataArray + t[1].offset; assert(end >= start); @@ -431,9 +431,9 @@ namespace starfield { end = std::upper_bound( start, end, minBright, GreaterBrightness()); - assert(end >= _arrData + t[0].offset); + assert(end >= _dataArray + t[0].offset); - t->count = end - _arrData - t[0].offset; + t->count = end - _dataArray - t[0].offset; t->lod = minBright; } @@ -441,13 +441,13 @@ namespace starfield { unsigned const* indicesEnd) { unsigned nRanges = 0u; - GLint* offs = _arrBatchOffs; - GLsizei* count = _arrBatchCount; + GLint* offs = _batchOffs; + GLsizei* count = _batchCountArray; - for (unsigned* i = (unsigned*) _arrBatchOffs; + for (unsigned* i = (unsigned*) _batchOffs; i != indicesEnd; ++i) { - Tile* t = _arrTile + *i; + Tile* t = _tileArray + *i; if ((t->flags & Tile::render) > 0u && t->count > 0u) { *offs++ = t->offset; @@ -476,28 +476,28 @@ namespace starfield { " gl_PointSize = s;\n" "}\n"; - _objProgram.addShaderFromSourceCode(QGLShader::Vertex, VERTEX_SHADER); + _program.addShaderFromSourceCode(QGLShader::Vertex, VERTEX_SHADER); GLchar const* const FRAGMENT_SHADER = "#version 120\n" "void main(void) {\n" " gl_FragColor = gl_Color;\n" "}\n"; - _objProgram.addShaderFromSourceCode(QGLShader::Fragment, FRAGMENT_SHADER); - _objProgram.link(); - _alphaLocationHandle = _objProgram.uniformLocation("alpha"); + _program.addShaderFromSourceCode(QGLShader::Fragment, FRAGMENT_SHADER); + _program.link(); + _alphaLocationHandle = _program.uniformLocation("alpha"); - glGenBuffersARB(1, & _hndVertexArray); + glGenBuffersARB(1, & _vertexArrayHandle); } void glFree() { - glDeleteBuffersARB(1, & _hndVertexArray); + glDeleteBuffersARB(1, & _vertexArrayHandle); } void glUpload(GLsizei n) { - glBindBufferARB(GL_ARRAY_BUFFER, _hndVertexArray); + glBindBufferARB(GL_ARRAY_BUFFER, _vertexArrayHandle); glBufferData(GL_ARRAY_BUFFER, - n * sizeof(GpuVertex), _arrData, GL_STATIC_DRAW); + n * sizeof(GpuVertex), _dataArray, GL_STATIC_DRAW); //glInterleavedArrays(GL_C4UB_V3F, sizeof(GpuVertex), 0l); glBindBufferARB(GL_ARRAY_BUFFER, 0); @@ -509,7 +509,7 @@ namespace starfield { // for (int i = 0; i < n_ranges; ++i) // printLog("Stars.cpp: Batch #%d - %d stars @ %d\n", i, -// _arrBatchOffs[i], _arrBatchCount[i]); +// _batchOffs[i], _batchCountArray[i]); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); @@ -531,18 +531,18 @@ namespace starfield { glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); // select shader and vertex array - _objProgram.bind(); - _objProgram.setUniformValue(_alphaLocationHandle, alpha); - glBindBufferARB(GL_ARRAY_BUFFER, _hndVertexArray); + _program.bind(); + _program.setUniformValue(_alphaLocationHandle, alpha); + glBindBufferARB(GL_ARRAY_BUFFER, _vertexArrayHandle); glInterleavedArrays(GL_C4UB_V3F, sizeof(GpuVertex), 0l); // render glMultiDrawArrays(GL_POINTS, - _arrBatchOffs, _arrBatchCount, n_ranges); + _batchOffs, _batchCountArray, n_ranges); // restore state glBindBufferARB(GL_ARRAY_BUFFER, 0); - _objProgram.release(); + _program.release(); glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); glDisable(GL_POINT_SMOOTH); glPopMatrix(); diff --git a/interface/src/starfield/renderer/Tiling.h b/interface/src/starfield/renderer/Tiling.h index 4737e318f9..6e7d7e46de 100644 --- a/interface/src/starfield/renderer/Tiling.h +++ b/interface/src/starfield/renderer/Tiling.h @@ -20,20 +20,20 @@ namespace starfield { class Tiling { unsigned _valK; - float _valRcpSlice; - unsigned _valNBits; + float _rcpSlice; + unsigned _nBits; public: Tiling(unsigned k) : _valK(k), - _valRcpSlice(k / Radians::twicePi()) { - _valNBits = ceil(log(getTileCount()) * 1.4426950408889634); // log2 + _rcpSlice(k / Radians::twicePi()) { + _nBits = ceil(log(getTileCount()) * 1.4426950408889634); // log2 } unsigned getAzimuthalTiles() const { return _valK; } unsigned getAltitudinalTiles() const { return _valK / 2 + 1; } - unsigned getTileIndexBits() const { return _valNBits; } + unsigned getTileIndexBits() const { return _nBits; } unsigned getTileCount() const { return getAzimuthalTiles() * getAltitudinalTiles(); @@ -45,14 +45,14 @@ namespace starfield { } float getSliceAngle() const { - return 1.0f / _valRcpSlice; + return 1.0f / _rcpSlice; } private: unsigned discreteAngle(float unsigned_angle) const { - return unsigned(floor(unsigned_angle * _valRcpSlice + 0.5f)); + return unsigned(floor(unsigned_angle * _rcpSlice + 0.5f)); } unsigned discreteAzimuth(float a) const { diff --git a/interface/src/starfield/renderer/VertexOrder.h b/interface/src/starfield/renderer/VertexOrder.h index 13784de53e..7f652b8dcd 100644 --- a/interface/src/starfield/renderer/VertexOrder.h +++ b/interface/src/starfield/renderer/VertexOrder.h @@ -25,7 +25,7 @@ namespace starfield { */ class VertexOrder : public Radix2IntegerScanner { - Tiling _objTiling; + Tiling _tiling; typedef Radix2IntegerScanner base; public: @@ -33,14 +33,14 @@ namespace starfield { explicit VertexOrder(Tiling const& tiling) : base(tiling.getTileIndexBits() + BrightnessBits), - _objTiling(tiling) { + _tiling(tiling) { } bool bit(InputVertex const& v, state_type const& s) const { // inspect (tile_index, brightness) tuples unsigned key = getBrightness(v.getColor()) ^ BrightnessMask; - key |= _objTiling.getTileIndex( + key |= _tiling.getTileIndex( v.getAzimuth(), v.getAltitude()) << BrightnessBits; return base::bit(key, s); }