From f667c604a3c86fb05f7a3744525611393be3f5ce Mon Sep 17 00:00:00 2001 From: CeetronResInsight Date: Fri, 20 Sep 2013 09:55:58 +0200 Subject: [PATCH] Integrating changes from CeeViz trunk per changelist 21999 (branch point for CVC) into ResInsight. Done in preparation to convert ResInsight to use CVC-june Changes to Camera class, Camera::fitView() and rename/new impl of Camera::fitViewEyePosition()/ Camera::computeFitViewEyePosition Logging: Use new macro to get hold of logger. Modifications to prefixing of file log messages Changes to OverlayImage Added use of scissoring to Rendering::renderOverlayItems() Upping of CVF version number Tweaks to compile on Android Modifications in shaders to compile on OpenGL ES p4#: 22501 --- VisualizationModules/LibCore/cvfBase.h | 6 +- .../LibCore/cvfLogDestinationFile.cpp | 23 ++++- VisualizationModules/LibCore/cvfLogEvent.h | 8 +- .../LibCore/cvfLogManager.cpp | 5 +- VisualizationModules/LibCore/cvfLogManager.h | 5 +- VisualizationModules/LibCore/cvfLogger.cpp | 3 +- VisualizationModules/LibCore/cvfMutex.cpp | 6 +- VisualizationModules/LibCore/cvfString.cpp | 25 +++++ VisualizationModules/LibCore/cvfString.h | 3 +- VisualizationModules/LibCore/cvfTimer.cpp | 14 +-- VisualizationModules/LibCore/cvfTrace.cpp | 10 +- VisualizationModules/LibCore/cvfVersion.h | 2 +- VisualizationModules/LibRender/cvfCamera.cpp | 16 ++- VisualizationModules/LibRender/cvfCamera.h | 3 +- .../LibRender/cvfCameraAnimation.cpp | 5 +- .../LibRender/cvfCameraAnimation.h | 4 +- VisualizationModules/LibRender/cvfOpenGL.h | 6 ++ .../LibRender/cvfOpenGLContext.h | 4 +- .../LibRender/cvfOpenGLContextGroup.cpp | 4 +- .../LibRender/cvfOverlayColorLegend.cpp | 38 +++++++- .../LibRender/cvfOverlayColorLegend.h | 62 ++++++------ .../LibRender/cvfOverlayImage.cpp | 23 ++++- .../LibRender/cvfOverlayImage.h | 2 + .../LibRender/cvfOverlayNavigationCube.cpp | 40 ++++---- .../LibRender/cvfRenderState.h | 1 + .../LibRender/cvfRenderStateTracker.cpp | 1 + .../LibRender/cvfRenderState_FF.cpp | 97 ++++++++++++++++++- .../LibRender/cvfRenderState_FF.h | 23 +++++ .../LibRender/cvfShaderSourceStrings.h | 29 ++++-- .../LibRender/glsl/calcClipDistances.glsl | 5 + .../glsl/checkDiscard_ClipDistances.glsl | 2 +- .../glsl/fs_CenterLitSpherePoints.glsl | 8 +- .../glsl/fs_ParticleTraceComets.glsl | 4 +- .../glsl/vs_DistanceScaledPoints.glsl | 2 +- .../LibRender/glsl/vs_EnvironmentMapping.glsl | 8 ++ .../LibViewing/cvfRenderEngine.cpp | 16 +-- .../LibViewing/cvfRenderEngine.h | 3 + .../LibViewing/cvfRendering.cpp | 26 +++-- .../LibViewing/cvfRendering.h | 2 + 39 files changed, 400 insertions(+), 144 deletions(-) diff --git a/VisualizationModules/LibCore/cvfBase.h b/VisualizationModules/LibCore/cvfBase.h index bfedc72cd1..674faaa968 100644 --- a/VisualizationModules/LibCore/cvfBase.h +++ b/VisualizationModules/LibCore/cvfBase.h @@ -19,7 +19,7 @@ #pragma once -#if !defined(WIN32) && !defined(CVF_LINUX) && !defined(CVF_IOS) && !defined(CVF_OSX) +#if !defined(WIN32) && !defined(CVF_LINUX) && !defined(CVF_IOS) && !defined(CVF_OSX) && !defined(CVF_ANDROID) #error No platform defined #endif @@ -50,7 +50,7 @@ #endif -#if defined(CVF_LINUX) || defined(CVF_IOS) || defined(CVF_OSX) +#if defined(CVF_LINUX) || defined(CVF_IOS) || defined(CVF_OSX) || defined(CVF_ANDROID) // Used by int64_t on *nix below #include #endif @@ -88,7 +88,7 @@ typedef unsigned int uint; // 64bit integer support via the int64 type #ifdef WIN32 typedef __int64 int64; -#elif defined(CVF_LINUX) || defined(CVF_IOS) || defined(CVF_OSX) +#elif defined(CVF_LINUX) || defined(CVF_IOS) || defined(CVF_OSX) || defined(CVF_ANDROID) typedef int64_t int64; #endif diff --git a/VisualizationModules/LibCore/cvfLogDestinationFile.cpp b/VisualizationModules/LibCore/cvfLogDestinationFile.cpp index 67c65a1bcd..c6b6617e05 100644 --- a/VisualizationModules/LibCore/cvfLogDestinationFile.cpp +++ b/VisualizationModules/LibCore/cvfLogDestinationFile.cpp @@ -33,6 +33,12 @@ namespace cvf { + +//================================================================================================== +// +// +// +//================================================================================================== class FileWrapper { public: @@ -77,6 +83,7 @@ private: }; + //================================================================================================== /// /// \class cvf::LogDestinationFile @@ -86,6 +93,14 @@ private: /// //================================================================================================== +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +LogDestinationFile::LogDestinationFile(const String& fileName) +: m_fileName(fileName) +{ +} + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -97,20 +112,20 @@ void LogDestinationFile::log(const LogEvent& logEvent) Logger::Level logEventLevel = logEvent.level(); if (logEventLevel == Logger::LL_ERROR) { - str = "ERROR: " + logEvent.message(); + str = logEvent.source() + "**ERROR**: " + logEvent.message(); addLocationInfo = true; } else if (logEventLevel == Logger::LL_WARNING) { - str = "warn: " + logEvent.message(); + str = logEvent.source() + "(warn): " + logEvent.message(); } else if (logEventLevel == Logger::LL_INFO) { - str = "info: " + logEvent.message(); + str = logEvent.source() + "(i): " + logEvent.message(); } else if (logEventLevel == Logger::LL_DEBUG) { - str = "debug: " + logEvent.message(); + str = logEvent.source() + "(d): " + logEvent.message(); } if (addLocationInfo) diff --git a/VisualizationModules/LibCore/cvfLogEvent.h b/VisualizationModules/LibCore/cvfLogEvent.h index 25c5c6592e..4cb02f5313 100644 --- a/VisualizationModules/LibCore/cvfLogEvent.h +++ b/VisualizationModules/LibCore/cvfLogEvent.h @@ -49,10 +49,10 @@ private: void swap(LogEvent& other); private: - String m_source; - String m_message; - Logger::Level m_level; - CodeLocation m_codeLocation; + String m_source; // Source of the log event, normally name of the logger + String m_message; // The logged message + Logger::Level m_level; // The log level of the event + CodeLocation m_codeLocation; // Source code location of log statement }; diff --git a/VisualizationModules/LibCore/cvfLogManager.cpp b/VisualizationModules/LibCore/cvfLogManager.cpp index 1facf09548..1e48c0abf9 100644 --- a/VisualizationModules/LibCore/cvfLogManager.cpp +++ b/VisualizationModules/LibCore/cvfLogManager.cpp @@ -19,7 +19,6 @@ #include "cvfBase.h" #include "cvfLogManager.h" -#include "cvfLogger.h" #include "cvfLogDestinationConsole.h" namespace cvf { @@ -137,7 +136,9 @@ Logger* LogManager::rootLogger() //-------------------------------------------------------------------------------------------------- +/// Sets the logging level of the given logger and all its descendants. /// +/// Specify an empty name to set logging level of all current loggers. //-------------------------------------------------------------------------------------------------- void LogManager::setLevelRecursive(const String& baseLoggerName, int logLevel) { @@ -167,7 +168,7 @@ void LogManager::setLevelRecursive(const String& baseLoggerName, int logLevel) //-------------------------------------------------------------------------------------------------- -/// +/// Sets the log destination for the specified logger and all its children. //-------------------------------------------------------------------------------------------------- void LogManager::setDestinationRecursive(const String& baseLoggerName, LogDestination* logDestination) { diff --git a/VisualizationModules/LibCore/cvfLogManager.h b/VisualizationModules/LibCore/cvfLogManager.h index b3dde9e597..50720e7bff 100644 --- a/VisualizationModules/LibCore/cvfLogManager.h +++ b/VisualizationModules/LibCore/cvfLogManager.h @@ -22,12 +22,12 @@ #include "cvfObject.h" #include "cvfString.h" #include "cvfMutex.h" +#include "cvfLogger.h" #include namespace cvf { -class Logger; class LogDestination; @@ -68,6 +68,9 @@ private: }; +// Helper macros for getting or creating a named logger +#define CVF_GET_LOGGER(loggerName) (cvf::LogManager::instance()->logger(loggerName)) + } // cvf diff --git a/VisualizationModules/LibCore/cvfLogger.cpp b/VisualizationModules/LibCore/cvfLogger.cpp index d44feb8d65..5a97eea156 100644 --- a/VisualizationModules/LibCore/cvfLogger.cpp +++ b/VisualizationModules/LibCore/cvfLogger.cpp @@ -68,9 +68,10 @@ const String& Logger::name() const //-------------------------------------------------------------------------------------------------- -/// Set the logging level of this logger +/// Sets the logging level of this logger /// /// Set a level of 0 to disable all logging for this logger. +/// \sa Logger::Level //-------------------------------------------------------------------------------------------------- void Logger::setLevel(int logLevel) { diff --git a/VisualizationModules/LibCore/cvfMutex.cpp b/VisualizationModules/LibCore/cvfMutex.cpp index 532005c7a1..d72a683d1a 100644 --- a/VisualizationModules/LibCore/cvfMutex.cpp +++ b/VisualizationModules/LibCore/cvfMutex.cpp @@ -27,7 +27,7 @@ #pragma warning (pop) #endif -#ifdef CVF_LINUX +#if defined CVF_LINUX || defined(CVF_ANDROID) #include #endif @@ -71,10 +71,10 @@ private: //================================================================================================== // -// Linux implementation using POSIX/Pthreads +// Linux and Android implementation using POSIX/Pthreads // //================================================================================================== -#ifdef CVF_LINUX +#if defined(CVF_LINUX) || defined(CVF_ANDROID) || defined(CVF_IOS) || defined(CVF_OSX) class MutexImpl { public: diff --git a/VisualizationModules/LibCore/cvfString.cpp b/VisualizationModules/LibCore/cvfString.cpp index b042a5daf0..af87068021 100644 --- a/VisualizationModules/LibCore/cvfString.cpp +++ b/VisualizationModules/LibCore/cvfString.cpp @@ -580,6 +580,31 @@ CharArray String::toUtf8() const } + +//-------------------------------------------------------------------------------------------------- +/// Returns a String initialized with the first \a strSize characters from the string str +/// +/// If \a strSize is npos, this function will compute the length of the string. +//-------------------------------------------------------------------------------------------------- +cvf::String String::fromAscii(const char* str, size_t strSize) +{ + if (str != NULL) + { + if (strSize == npos) + { + strSize = strlen(str); + } + + // Raw conversion, no UTF8 + return String(std::wstring(str, str + strSize)); + } + else + { + return String(); + } +} + + //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/VisualizationModules/LibCore/cvfString.h b/VisualizationModules/LibCore/cvfString.h index 35c820e867..342f6d37e6 100644 --- a/VisualizationModules/LibCore/cvfString.h +++ b/VisualizationModules/LibCore/cvfString.h @@ -77,8 +77,9 @@ public: CharArray toAscii() const; // Useful when you need a const char* pointer. std::string toStdString() const; std::wstring toStdWString() const; - CharArray toUtf8() const; + + static String fromAscii(const char* str, size_t strSize = npos); static String fromUtf8(const char* str); bool isEmpty() const; diff --git a/VisualizationModules/LibCore/cvfTimer.cpp b/VisualizationModules/LibCore/cvfTimer.cpp index 287213714b..ddb45b4132 100644 --- a/VisualizationModules/LibCore/cvfTimer.cpp +++ b/VisualizationModules/LibCore/cvfTimer.cpp @@ -27,7 +27,7 @@ #pragma warning (pop) #endif -#ifdef CVF_LINUX +#if defined(CVF_LINUX) || defined(CVF_ANDROID) #include #endif @@ -68,7 +68,7 @@ public: }; #endif //WIN32 -#ifdef CVF_LINUX +#if defined(CVF_LINUX) || defined(CVF_ANDROID) class PrivateTimerState { public: @@ -83,7 +83,7 @@ public: timespec m_timeStart; timespec m_timeMark; }; -#endif // CVF_LINUX +#endif // CVF_LINUX || CVF_ANDROID #if defined(CVF_IOS) || defined(CVF_OSX) @@ -107,7 +107,7 @@ public: //-------------------------------------------------------------------------------------------------- /// Static helper on Linux to compute difference between two timespecs //-------------------------------------------------------------------------------------------------- -#ifdef CVF_LINUX +#if defined(CVF_LINUX) || defined(CVF_ANDROID) static timespec ComputeTimespecDiff(const timespec start, const timespec end) { timespec temp; @@ -170,7 +170,7 @@ void Timer::restart() m_timerState->m_startTick = tick.QuadPart; m_timerState->m_lastLapTick = m_timerState->m_startTick; -#elif CVF_LINUX +#elif defined(CVF_LINUX) || defined(CVF_ANDROID) clock_gettime(CLOCK_MONOTONIC, &m_timerState->m_timeStart); m_timerState->m_timeMark = m_timerState->m_timeStart; @@ -196,7 +196,7 @@ double Timer::time() const QueryPerformanceCounter(&nowTick); return static_cast((nowTick.QuadPart - m_timerState->m_startTick))/static_cast(m_timerState->m_ticksPerSecond); -#elif CVF_LINUX +#elif defined(CVF_LINUX) || defined(CVF_ANDROID) timespec timeNow; clock_gettime(CLOCK_MONOTONIC, &timeNow); @@ -230,7 +230,7 @@ double Timer::lapTime() double lapTime = static_cast((nowTick.QuadPart - m_timerState->m_lastLapTick))/static_cast(m_timerState->m_ticksPerSecond); m_timerState->m_lastLapTick = nowTick.QuadPart; -#elif CVF_LINUX +#elif defined(CVF_LINUX) || defined(CVF_ANDROID) timespec timeNow; clock_gettime(CLOCK_MONOTONIC, &timeNow); diff --git a/VisualizationModules/LibCore/cvfTrace.cpp b/VisualizationModules/LibCore/cvfTrace.cpp index acc80dadef..99fa035708 100644 --- a/VisualizationModules/LibCore/cvfTrace.cpp +++ b/VisualizationModules/LibCore/cvfTrace.cpp @@ -31,10 +31,12 @@ #include #endif +#ifdef CVF_ANDROID +#include +#endif + namespace cvf { - - //================================================================================================== /// /// \class cvf::Trace @@ -70,6 +72,8 @@ void Trace::show(const char* format, ...) #ifdef WIN32 _vsnprintf_s(temp, maxFormatLength, format, argList); +#elif defined(CVF_ANDROID) + __android_log_print(ANDROID_LOG_DEBUG, "CVF_TAG", format, argList); #else vsprintf(temp, format, argList); #endif @@ -115,6 +119,8 @@ void Trace::showTraceOutput(String text, bool addNewLine) WriteConsoleA(hStdOutputHandle, ascii.ptr(), stringLength, &iDum, NULL); if (addNewLine) WriteConsole(hStdOutputHandle, "\n", 1, &iDum, NULL); } +#elif defined(CVF_ANDROID) + __android_log_print(ANDROID_LOG_DEBUG, "CVF_TAG", "%s", text.toAscii().ptr()); #else fprintf(stderr, "%s", text.toAscii().ptr()); if (addNewLine) diff --git a/VisualizationModules/LibCore/cvfVersion.h b/VisualizationModules/LibCore/cvfVersion.h index ccbc3d5178..3b2e8ff665 100644 --- a/VisualizationModules/LibCore/cvfVersion.h +++ b/VisualizationModules/LibCore/cvfVersion.h @@ -24,4 +24,4 @@ #define CVF_MAJOR_VERSION "0" // Major version number #define CVF_MINOR_VERSION "9" // Minor version number #define CVF_SPECIAL_BUILD "" // Special build description -#define CVF_BUILD_NUMBER "4" // Build number. Increase for each shipment +#define CVF_BUILD_NUMBER "5" // Build number. Increase for each shipment diff --git a/VisualizationModules/LibRender/cvfCamera.cpp b/VisualizationModules/LibRender/cvfCamera.cpp index 0aea6f4b47..ebc9f98323 100644 --- a/VisualizationModules/LibRender/cvfCamera.cpp +++ b/VisualizationModules/LibRender/cvfCamera.cpp @@ -271,7 +271,7 @@ void Camera::setProjectionAsPixelExact2D() void Camera::fitView(const BoundingBox& boundingBox, const Vec3d& dir, const Vec3d& up, double coverageFactor) { // Use old view direction, but look towards model center - Vec3d eye = fitViewEyePosition(boundingBox, dir, up, coverageFactor); + Vec3d eye = computeFitViewEyePosition(boundingBox, dir, up, coverageFactor, m_fieldOfViewYDeg, viewport()->aspectRatio()); // Will update cached values setFromLookAt(eye, boundingBox.center(), up); @@ -281,10 +281,8 @@ void Camera::fitView(const BoundingBox& boundingBox, const Vec3d& dir, const Vec //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -Vec3d Camera::fitViewEyePosition(const BoundingBox& boundingBox, const Vec3d& dir, const Vec3d& up, double coverageFactor) const +Vec3d Camera::computeFitViewEyePosition(const BoundingBox& boundingBox, const Vec3d& dir, const Vec3d& up, double coverageFactor, double fieldOfViewYDeg, double aspectRatio) { - CVF_ASSERT(projection() == PERSPECTIVE); - cvf::Vec3d corners[8]; boundingBox.cornerVertices(corners); @@ -299,9 +297,9 @@ Vec3d Camera::fitViewEyePosition(const BoundingBox& boundingBox, const Vec3d& di cvf::Plane planeSide; planeSide.setFromPointAndNormal(boundingBox.center(), right); - // m_fieldOfViewYDeg is the complete angle in degrees, get half in radians - double fovY = Math::toRadians(m_fieldOfViewYDeg/2.0); - double fovX = Math::atan(Math::tan(fovY)*aspectRatio()); + // fieldOfViewYDeg is the complete angle in degrees, get half in radians + double fovY = Math::toRadians(fieldOfViewYDeg/2.0); + double fovX = Math::atan(Math::tan(fovY)*aspectRatio); double dist = 0; @@ -392,9 +390,7 @@ void Camera::fitViewOrtho(const BoundingBox& boundingBox, double eyeDist, const //-------------------------------------------------------------------------------------------------- -/// Set the front and back clipping planes close to the given bounding box (perspective projection) -/// -/// Note that this will setup a perspective projection with the new clipping planes. +/// Set the front and back clipping planes close to the given bounding box //-------------------------------------------------------------------------------------------------- void Camera::setClipPlanesFromBoundingBox(const BoundingBox& boundingBox, double minNearPlaneDistance) { diff --git a/VisualizationModules/LibRender/cvfCamera.h b/VisualizationModules/LibRender/cvfCamera.h index c247c47fe0..58899da671 100644 --- a/VisualizationModules/LibRender/cvfCamera.h +++ b/VisualizationModules/LibRender/cvfCamera.h @@ -65,8 +65,7 @@ public: void fitView(const BoundingBox& boundingBox, const Vec3d& dir, const Vec3d& up, double coverageFactor = 0.9); void fitViewOrtho(const BoundingBox& boundingBox, double eyeDist, const Vec3d& dir, const Vec3d& up, double coverageFactor = 0.9); - - Vec3d fitViewEyePosition(const BoundingBox& boundingBox, const Vec3d& dir, const Vec3d& up, double coverageFactor = 0.9) const; + static Vec3d computeFitViewEyePosition(const BoundingBox& boundingBox, const Vec3d& dir, const Vec3d& up, double coverageFactor, double fieldOfViewYDeg, double aspectRatio); void setClipPlanesFromBoundingBox(const BoundingBox& boundingBox, double minNearPlaneDistance = 0.01); diff --git a/VisualizationModules/LibRender/cvfCameraAnimation.cpp b/VisualizationModules/LibRender/cvfCameraAnimation.cpp index f18144f184..f72739d765 100644 --- a/VisualizationModules/LibRender/cvfCameraAnimation.cpp +++ b/VisualizationModules/LibRender/cvfCameraAnimation.cpp @@ -65,7 +65,7 @@ CameraAnimation::CameraAnimation(const Vec3d& currentPos, const Vec3d& currentDi /// } /// \endcode //-------------------------------------------------------------------------------------------------- -bool CameraAnimation::newPosition(Vec3d* pos, Vec3d* dir, Vec3d* up) +bool CameraAnimation::newPosition(Vec3d* pos, Vec3d* dir, Vec3d* up, double* relativeTimeStamp) { if (m_animDone) { @@ -84,6 +84,7 @@ bool CameraAnimation::newPosition(Vec3d* pos, Vec3d* dir, Vec3d* up) *pos = m_newPos; *dir = m_newDir; *up = m_newUp; + if (relativeTimeStamp) *relativeTimeStamp = 1.0; m_animDone = true; @@ -94,6 +95,8 @@ bool CameraAnimation::newPosition(Vec3d* pos, Vec3d* dir, Vec3d* up) *dir = m_currentDir + (m_newDir - m_currentDir)*(timeNow/m_animDuration); *up = m_currentUp + (m_newUp - m_currentUp )*(timeNow/m_animDuration); + if (relativeTimeStamp) *relativeTimeStamp = timeNow/m_animDuration; + return true; } diff --git a/VisualizationModules/LibRender/cvfCameraAnimation.h b/VisualizationModules/LibRender/cvfCameraAnimation.h index 70e166f8bf..bbd5a50270 100644 --- a/VisualizationModules/LibRender/cvfCameraAnimation.h +++ b/VisualizationModules/LibRender/cvfCameraAnimation.h @@ -21,10 +21,10 @@ #include "cvfObject.h" #include "cvfVector3.h" +#include "cvfTimer.h" namespace cvf { -class Timer; //================================================================================================== // @@ -38,7 +38,7 @@ public: void setDuration(double seconds); - bool newPosition(Vec3d* pos, Vec3d* dir, Vec3d* up); + bool newPosition(Vec3d* pos, Vec3d* dir, Vec3d* up, double* relativeTimeStamp = NULL); private: Vec3d m_currentPos; diff --git a/VisualizationModules/LibRender/cvfOpenGL.h b/VisualizationModules/LibRender/cvfOpenGL.h index 691563dc73..a5e09d3542 100644 --- a/VisualizationModules/LibRender/cvfOpenGL.h +++ b/VisualizationModules/LibRender/cvfOpenGL.h @@ -67,6 +67,12 @@ #include #include +#elif defined(CVF_ANDROID) + +// Android includes +#include +#include + #elif defined(CVF_IOS) // iOS includes diff --git a/VisualizationModules/LibRender/cvfOpenGLContext.h b/VisualizationModules/LibRender/cvfOpenGLContext.h index 2ae21727d9..6cc2d70c93 100644 --- a/VisualizationModules/LibRender/cvfOpenGLContext.h +++ b/VisualizationModules/LibRender/cvfOpenGLContext.h @@ -58,10 +58,8 @@ private: friend class OpenGLContextGroup; }; -#define CVF_LOG_RENDER_ERROR(OGL_CTX_PTR, THE_MESSAGE) OGL_CTX_PTR->group()->logger()->error((THE_MESSAGE), CVF_CODE_LOCATION) -#define CVF_LOG_RENDER_DEBUG(OGL_CTX_PTR, THE_MESSAGE) OGL_CTX_PTR->group()->logger()->debug((THE_MESSAGE), CVF_CODE_LOCATION) -#define CVF_SHOULD_LOG_RENDER_DEBUG(OGL_CTX_PTR) OGL_CTX_PTR->group()->logger()->isDebugEnabled() +#define CVF_LOG_RENDER_ERROR(OGL_CTX_PTR, THE_MESSAGE) CVF_LOG_ERROR( (OGL_CTX_PTR->group()->logger()), (THE_MESSAGE)) } diff --git a/VisualizationModules/LibRender/cvfOpenGLContextGroup.cpp b/VisualizationModules/LibRender/cvfOpenGLContextGroup.cpp index abf299e7b2..a7b9ca2cec 100644 --- a/VisualizationModules/LibRender/cvfOpenGLContextGroup.cpp +++ b/VisualizationModules/LibRender/cvfOpenGLContextGroup.cpp @@ -23,7 +23,7 @@ #include "cvfOpenGLContext.h" #include "cvfOpenGLResourceManager.h" #include "cvfOpenGLCapabilities.h" -#include "cvfLogDestinationConsole.h" +#include "cvfLogManager.h" #include @@ -58,7 +58,7 @@ OpenGLContextGroup::OpenGLContextGroup() m_wglewContextStruct(NULL) { m_resourceManager = new OpenGLResourceManager; - m_logger = new Logger("cvf.OpenGL", Logger::LL_WARNING, new LogDestinationConsole); + m_logger = CVF_GET_LOGGER("cee.cvf.OpenGL"); m_capabilities = new OpenGLCapabilities; } diff --git a/VisualizationModules/LibRender/cvfOverlayColorLegend.cpp b/VisualizationModules/LibRender/cvfOverlayColorLegend.cpp index 76821b25c1..8359f33a11 100644 --- a/VisualizationModules/LibRender/cvfOverlayColorLegend.cpp +++ b/VisualizationModules/LibRender/cvfOverlayColorLegend.cpp @@ -62,7 +62,8 @@ OverlayColorLegend::OverlayColorLegend(Font* font) m_color(Color3::BLACK), m_lineColor(Color3::BLACK), m_lineWidth(1), - m_font(font) + m_font(font), + m_margin(4) { CVF_ASSERT(font); CVF_ASSERT(!font->isEmpty()); @@ -220,7 +221,9 @@ bool OverlayColorLegend::pick(int x, int y, const Vec2i& position, const Vec2ui& { Recti oglRect(position, static_cast(size.x()), static_cast(size.y())); - OverlayColorLegendLayoutInfo layoutInViewPortCoords(oglRect.min(), Vec2ui(static_cast(oglRect.width()), static_cast(oglRect.height()))); + OverlayColorLegendLayoutInfo layoutInViewPortCoords; + layoutInViewPortCoords.position = oglRect.min(); + layoutInViewPortCoords.size = Vec2ui(static_cast(oglRect.width()), static_cast(oglRect.height())); layoutInfo(&layoutInViewPortCoords); Vec2i legendBarOrigin = oglRect.min(); @@ -258,7 +261,9 @@ void OverlayColorLegend::render(OpenGLContext* oglContext, const Vec2i& position // Get layout information // Todo: Cache this between renderings. Update only when needed. - OverlayColorLegendLayoutInfo layout(position, size); + OverlayColorLegendLayoutInfo layout; + layout.position = position; + layout.size = size; layoutInfo(&layout); // Set up text drawer @@ -560,7 +565,7 @@ void OverlayColorLegend::layoutInfo(OverlayColorLegendLayoutInfo* layout) ref glyph = m_font->getGlyph(L'A'); layout->charHeight = static_cast(glyph->height()); layout->lineSpacing = layout->charHeight*1.5f; - layout->margins = Vec2f(4.0f, 4.0f); + layout->margins = Vec2f(static_cast(m_margin), static_cast(m_margin)); float legendWidth = 25.0f; float legendHeight = static_cast(layout->size.y()) - 2*layout->margins.y() - static_cast(m_titleStrings.size())*layout->lineSpacing - layout->lineSpacing; @@ -649,5 +654,30 @@ int OverlayColorLegend::lineWidth() const return m_lineWidth; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void OverlayColorLegend::setWidthToFitText() +{ + cvf::uint textWidth = 0; + for (size_t i = 0; i < m_titleStrings.size(); ++i) + { + cvf::uint lineWidth = m_font->textExtent(m_titleStrings[i]).x(); + + if (lineWidth > textWidth) + { + textWidth = lineWidth; + } + } + + cvf::uint minWidth = m_font->textExtent("-0.00000e-000").x() + 40; + + // +1 to cater for any rasterization inaccuracy + textWidth = CVF_MAX(minWidth + 1, textWidth + m_margin + 1); + + m_sizeHint.x() = textWidth; +} + } // namespace cvf diff --git a/VisualizationModules/LibRender/cvfOverlayColorLegend.h b/VisualizationModules/LibRender/cvfOverlayColorLegend.h index 38656ac030..f4188d3de6 100644 --- a/VisualizationModules/LibRender/cvfOverlayColorLegend.h +++ b/VisualizationModules/LibRender/cvfOverlayColorLegend.h @@ -31,34 +31,7 @@ class Font; class ShaderProgram; class MatrixState; class TextDrawer; - - -//================================================================================================== -// -// Helper for storing layout info -// -//================================================================================================== -struct OverlayColorLegendLayoutInfo -{ - OverlayColorLegendLayoutInfo(const Vec2i& pos, const Vec2ui& setSize) - { - position = pos; - size = setSize; - } - - float charHeight; - float lineSpacing; - Vec2f margins; - float tickX; - float x0, x1; - - Rectf legendRect; - - ref tickPixelPos; - - Vec2i position; - Vec2ui size; -}; +struct OverlayColorLegendLayoutInfo; //================================================================================================== @@ -83,6 +56,7 @@ public: void configureLevels(const Color3ubArray& levelColors, const DoubleArray& tickValues); void setSizeHint(const Vec2ui& size); + void setWidthToFitText(); void setColor(const Color3f& color); const Color3f& color() const; @@ -96,12 +70,12 @@ public: String title() const; protected: - void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software); - virtual void renderLegend(OpenGLContext* oglContext, OverlayColorLegendLayoutInfo* layout, const MatrixState& matrixState); - virtual void renderLegendImmediateMode(OpenGLContext* oglContext, OverlayColorLegendLayoutInfo* layout); - virtual void setupTextDrawer(TextDrawer* textDrawer, OverlayColorLegendLayoutInfo* layout); + void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software); + virtual void renderLegend(OpenGLContext* oglContext, OverlayColorLegendLayoutInfo* layout, const MatrixState& matrixState); + virtual void renderLegendImmediateMode(OpenGLContext* oglContext, OverlayColorLegendLayoutInfo* layout); + virtual void setupTextDrawer(TextDrawer* textDrawer, OverlayColorLegendLayoutInfo* layout); - void layoutInfo(OverlayColorLegendLayoutInfo* layout); + void layoutInfo(OverlayColorLegendLayoutInfo* layout); protected: Color3ubArray m_levelColors; // Colors for n levels @@ -115,6 +89,28 @@ protected: int m_lineWidth; std::vector m_titleStrings; ref m_font; + + const cvf::uint m_margin; +}; + + +//================================================================================================== +// +// Internal helper for storing layout info to allow for custom rendered legends +// +//================================================================================================== +struct OverlayColorLegendLayoutInfo +{ + float charHeight; + float lineSpacing; + Vec2f margins; + float tickX; + float x0; + float x1; + Rectf legendRect; + Vec2i position; + Vec2ui size; + ref tickPixelPos; }; } diff --git a/VisualizationModules/LibRender/cvfOverlayImage.cpp b/VisualizationModules/LibRender/cvfOverlayImage.cpp index 1c42403920..ce7fc16063 100644 --- a/VisualizationModules/LibRender/cvfOverlayImage.cpp +++ b/VisualizationModules/LibRender/cvfOverlayImage.cpp @@ -61,8 +61,6 @@ OverlayImage::OverlayImage(TextureImage* image) { CVF_ASSERT(image); - m_size.x() = image->width(); - m_size.y() = image->height(); m_blendMode = NO_BLENDING; m_sampler = new cvf::Sampler; @@ -342,6 +340,9 @@ void OverlayImage::setImage(TextureImage* image) m_image = image; m_pow2Image = NULL; + m_size.x() = image->width(); + m_size.y() = image->height(); + m_texture = new Texture(image); m_textureBindings = NULL; @@ -383,4 +384,22 @@ void OverlayImage::setBlending(Blending mode) m_blendMode = mode; } + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +float OverlayImage::globalAlpha() const +{ + return m_alpha; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +OverlayImage::Blending OverlayImage::blending() const +{ + return m_blendMode; +} + } // namespace cvf diff --git a/VisualizationModules/LibRender/cvfOverlayImage.h b/VisualizationModules/LibRender/cvfOverlayImage.h index 854f491475..421a84edb1 100644 --- a/VisualizationModules/LibRender/cvfOverlayImage.h +++ b/VisualizationModules/LibRender/cvfOverlayImage.h @@ -61,6 +61,8 @@ public: void setBlending(Blending mode); const TextureImage* image() const; + float globalAlpha() const; + Blending blending() const; private: void render(OpenGLContext* oglContext, const Vec2i& position, const Vec2ui& size, bool software); diff --git a/VisualizationModules/LibRender/cvfOverlayNavigationCube.cpp b/VisualizationModules/LibRender/cvfOverlayNavigationCube.cpp index a28fb8bf08..6caa550c3e 100644 --- a/VisualizationModules/LibRender/cvfOverlayNavigationCube.cpp +++ b/VisualizationModules/LibRender/cvfOverlayNavigationCube.cpp @@ -454,15 +454,19 @@ void OverlayNavigationCube::renderCubeGeos(OpenGLContext* oglContext, bool softw } } - Color3f faceColor; - switch (face) + Color3f faceColor = Color3f(Color3::WHITE); + + if (!hasTexture) { - case NCF_X_POS: - case NCF_X_NEG: faceColor = m_xFaceColor; break; - case NCF_Y_POS: - case NCF_Y_NEG: faceColor = m_yFaceColor; break; - case NCF_Z_POS: - case NCF_Z_NEG: faceColor = m_zFaceColor; break; + switch (face) + { + case NCF_X_POS: + case NCF_X_NEG: faceColor = m_xFaceColor; break; + case NCF_Y_POS: + case NCF_Y_NEG: faceColor = m_yFaceColor; break; + case NCF_Z_POS: + case NCF_Z_NEG: faceColor = m_zFaceColor; break; + } } for (size_t i = 0; i < m_cubeGeos.size(); ++i) @@ -480,16 +484,12 @@ void OverlayNavigationCube::renderCubeGeos(OpenGLContext* oglContext, bool softw if (software) { - if (hasTexture) - { - glColor3f(1.0f, 1.0f, 1.0f); - } - else - { - glColor3fv(renderFaceColor.ptr()); - } - +#ifdef CVF_OPENGL_ES + CVF_FAIL_MSG("Not supported on OpenGL ES"); +#else + glColor3fv(renderFaceColor.ptr()); m_cubeGeos[i]->renderImmediateMode(oglContext, matrixState); +#endif } else { @@ -567,8 +567,12 @@ void OverlayNavigationCube::render2dItems(OpenGLContext* oglContext, const Vec2i if (software) { +#ifdef CVF_OPENGL_ES + CVF_FAIL_MSG("Not supported on OpenGL ES"); +#else glColor3fv(renderFaceColor.ptr()); m_2dGeos[i]->renderImmediateMode(oglContext, matrixState); +#endif } else { @@ -1105,7 +1109,7 @@ OverlayNavigationCube::NavCubeItem OverlayNavigationCube::navCubeItem(NavCubeFac //-------------------------------------------------------------------------------------------------- bool OverlayNavigationCube::pick(int winCoordX, int winCoordY, const Vec2i& position, const Vec2ui& size) { - return pickItem(winCoordX, winCoordY, position, size) != cvf::UNDEFINED_UINT; + return pickItem(winCoordX, winCoordY, position, size) != cvf::UNDEFINED_SIZE_T; } diff --git a/VisualizationModules/LibRender/cvfRenderState.h b/VisualizationModules/LibRender/cvfRenderState.h index 0200e11427..57cfee46a8 100644 --- a/VisualizationModules/LibRender/cvfRenderState.h +++ b/VisualizationModules/LibRender/cvfRenderState.h @@ -53,6 +53,7 @@ public: MATERIAL_FF, //Fixed function NORMALIZE_FF, //Fixed function TEXTURE_MAPPING_FF, //Fixed function + CLIP_PLANES_FF, //Fixed function #endif COUNT // Must be the last entry diff --git a/VisualizationModules/LibRender/cvfRenderStateTracker.cpp b/VisualizationModules/LibRender/cvfRenderStateTracker.cpp index f39c6dc7bf..20100cbc62 100644 --- a/VisualizationModules/LibRender/cvfRenderStateTracker.cpp +++ b/VisualizationModules/LibRender/cvfRenderStateTracker.cpp @@ -87,6 +87,7 @@ void RenderStateTracker::setupDefaultRenderStates() m_defaultRenderStates[RenderState::MATERIAL_FF] = new RenderStateMaterial_FF; m_defaultRenderStates[RenderState::NORMALIZE_FF] = new RenderStateNormalize_FF(false); m_defaultRenderStates[RenderState::TEXTURE_MAPPING_FF] = new RenderStateTextureMapping_FF; + m_defaultRenderStates[RenderState::CLIP_PLANES_FF] = new RenderStateClipPlanes_FF; #endif } diff --git a/VisualizationModules/LibRender/cvfRenderState_FF.cpp b/VisualizationModules/LibRender/cvfRenderState_FF.cpp index 41eddb1fd3..f7b87e423e 100644 --- a/VisualizationModules/LibRender/cvfRenderState_FF.cpp +++ b/VisualizationModules/LibRender/cvfRenderState_FF.cpp @@ -672,5 +672,100 @@ bool RenderStateTextureMapping_FF::isFixedFunction() const return true; } -} // namespace cvf +//================================================================================================== +/// +/// \class cvf::RenderStateClipPlanes_FF +/// \ingroup Render +/// +/// Encapsulate OpenGL glClipPlane() and glEnable()/glDisable() with GL_CLIP_PLANE0 + idx +/// +//================================================================================================== +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +RenderStateClipPlanes_FF::RenderStateClipPlanes_FF() +: RenderState(CLIP_PLANES_FF) +{ +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RenderStateClipPlanes_FF::addPlane(const cvf::Plane& plane) +{ + m_clipPlanes.push_back(plane); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +size_t RenderStateClipPlanes_FF::planeCount() const +{ + return m_clipPlanes.size(); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +const Plane& RenderStateClipPlanes_FF::plane(size_t index) +{ + CVF_ASSERT(index < m_clipPlanes.size()); + return m_clipPlanes[index]; +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +void RenderStateClipPlanes_FF::removeAllPlanes() +{ + m_clipPlanes.clear(); +} + + +//-------------------------------------------------------------------------------------------------- +/// Supports 6 clipping planes, as all implementations of OpenGL is required to have at least 6 +//-------------------------------------------------------------------------------------------------- +void RenderStateClipPlanes_FF::applyOpenGL(OpenGLContext* oglContext) const +{ + for (size_t idx = 0; idx < m_clipPlanes.size(); idx++) + { + if (idx > 5) + { + break; + } + + // Set and enable plane + GLdouble plane[4]; + + plane[0] = m_clipPlanes[idx].A(); + plane[1] = m_clipPlanes[idx].B(); + plane[2] = m_clipPlanes[idx].C(); + plane[3] = m_clipPlanes[idx].D(); + + glClipPlane((GLenum)(GL_CLIP_PLANE0 + idx), plane); + glEnable((GLenum)(GL_CLIP_PLANE0 + idx)); + } + + for (size_t idx = m_clipPlanes.size(); idx < 6; idx++) + { + glDisable((GLenum)(GL_CLIP_PLANE0 + idx)); + } + + CVF_CHECK_OGL(oglContext); +} + + +//-------------------------------------------------------------------------------------------------- +/// +//-------------------------------------------------------------------------------------------------- +bool RenderStateClipPlanes_FF::isFixedFunction() const +{ + return true; +} + +} // namespace cvf diff --git a/VisualizationModules/LibRender/cvfRenderState_FF.h b/VisualizationModules/LibRender/cvfRenderState_FF.h index ab0876fa26..11227ba2bd 100644 --- a/VisualizationModules/LibRender/cvfRenderState_FF.h +++ b/VisualizationModules/LibRender/cvfRenderState_FF.h @@ -21,6 +21,7 @@ #include "cvfRenderState.h" #include "cvfColor4.h" +#include "cvfPlane.h" namespace cvf { @@ -207,4 +208,26 @@ private: +//================================================================================================== +// +// +// +//================================================================================================== +class RenderStateClipPlanes_FF : public RenderState +{ +public: + RenderStateClipPlanes_FF(); + + void addPlane(const cvf::Plane& plane); + size_t planeCount() const; + const Plane& plane(size_t index); + void removeAllPlanes(); + + virtual void applyOpenGL(OpenGLContext* oglContext) const; + virtual bool isFixedFunction() const; + +private: + std::vector m_clipPlanes; +}; + } // namespace cvf diff --git a/VisualizationModules/LibRender/cvfShaderSourceStrings.h b/VisualizationModules/LibRender/cvfShaderSourceStrings.h index dd0f33e580..ac3c2b8bb8 100644 --- a/VisualizationModules/LibRender/cvfShaderSourceStrings.h +++ b/VisualizationModules/LibRender/cvfShaderSourceStrings.h @@ -7,7 +7,12 @@ //############################################################################################################################# static const char calcClipDistances_inl[] = " \n" +"#ifdef CVF_OPENGL_ES \n" +"uniform mediump int u_clipPlaneCount; \n" +"#else \n" "uniform int u_clipPlaneCount; \n" +"#endif \n" +" \n" "uniform vec4 u_ecClipPlanes[6]; \n" " \n" "// The dimensioning should probably be via a define to be consistent between vs and fs \n" @@ -81,7 +86,7 @@ static const char checkDiscard_ClipDistances_inl[] = " int i; \n" " for (i = 0; i < u_clipPlaneCount; i++) \n" " { \n" -" if (v_clipDist[i] < 0) discard; \n" +" if (v_clipDist[i] < 0.0) discard; \n" " } \n" "} \n"; @@ -103,7 +108,7 @@ static const char fs_CenterLitSpherePoints_inl[] = "{ \n" " //const vec3 ecLightPosition = vec3(0.5, 5.0, 7.0); \n" " //vec3 lightDir = normalize(ecLightPosition - v_ecPosition); \n" -" const vec3 lightDir = vec3(0, 0, 1); \n" +" const vec3 lightDir = vec3(0.0, 0.0, 1.0); \n" " \n" " // Calculate normal from texture coordinates \n" " vec3 N; \n" @@ -111,8 +116,8 @@ static const char fs_CenterLitSpherePoints_inl[] = " float mag = dot(N.xy, N.xy); \n" " \n" " // Kill pixels outside circle \n" -" if (mag > 1) discard; \n" -" N.z = sqrt(1 - mag); \n" +" if (mag > 1.0) discard; \n" +" N.z = sqrt(1.0 - mag); \n" " \n" " // Calculate diffuse lighting \n" " float diffuse = max(0.0, dot(lightDir, N)); \n" @@ -120,7 +125,7 @@ static const char fs_CenterLitSpherePoints_inl[] = " vec4 color = srcFragment(); \n" " gl_FragColor = vec4(color.rgb*diffuse, color.a); \n" " \n" -" //gl_FragDepth = gl_FragCoord.z - 15.0*(1-mag); \n" +" //gl_FragDepth = gl_FragCoord.z - 15.0*(1.0-mag); \n" "} \n"; @@ -454,8 +459,8 @@ static const char fs_ParticleTraceComets_inl[] = " vec3 N; \n" " N.xy = vec2(v_circleFactors.x, v_circleFactors.y); \n" " float mag = dot(N.xy, N.xy); \n" -" if (mag > 1) discard; \n" -" N.z = sqrt(1 - mag); \n" +" if (mag > 1.0) discard; \n" +" N.z = sqrt(1.0 - mag); \n" " \n" " float diffuse = max(0.0, dot(lightDir, N)); \n" " \n" @@ -941,7 +946,7 @@ static const char vs_DistanceScaledPoints_inl[] = " // Compute the point diameter in window coords (pixels) \n" " // Scale with distance for perspective correction of the size \n" " float dist = length(v_ecPosition); \n" -" gl_PointSize = 2*u_pointRadius/(cvfu_pixelHeightAtUnitDistance*dist); \n" +" gl_PointSize = 2.0*u_pointRadius/(cvfu_pixelHeightAtUnitDistance*dist); \n" "} \n"; @@ -968,10 +973,18 @@ static const char vs_EnvironmentMapping_inl[] = "//-------------------------------------------------------------------------------------------------- \n" "void main () \n" "{ \n" +"#ifdef CVF_CALC_SHADOW_COORD_IMPL \n" +" calcShadowCoord(); \n" +"#endif \n" +" \n" " // Transforms vertex position and normal vector to eye space \n" " v_ecPosition = (cvfu_modelViewMatrix * cvfa_vertex).xyz; \n" " v_ecNormal = cvfu_normalMatrix * cvfa_normal; \n" " \n" +"#ifdef CVF_CALC_CLIP_DISTANCES_IMPL \n" +" calcClipDistances(vec4(v_ecPosition, 1)); \n" +"#endif \n" +" \n" " gl_Position = cvfu_modelViewProjectionMatrix*cvfa_vertex; \n" " \n" " // Compute the texture coordinate for the environment map texture lookup \n" diff --git a/VisualizationModules/LibRender/glsl/calcClipDistances.glsl b/VisualizationModules/LibRender/glsl/calcClipDistances.glsl index 08ac55c57a..3b23bf1d65 100644 --- a/VisualizationModules/LibRender/glsl/calcClipDistances.glsl +++ b/VisualizationModules/LibRender/glsl/calcClipDistances.glsl @@ -1,5 +1,10 @@ +#ifdef CVF_OPENGL_ES +uniform mediump int u_clipPlaneCount; +#else uniform int u_clipPlaneCount; +#endif + uniform vec4 u_ecClipPlanes[6]; // The dimensioning should probably be via a define to be consistent between vs and fs diff --git a/VisualizationModules/LibRender/glsl/checkDiscard_ClipDistances.glsl b/VisualizationModules/LibRender/glsl/checkDiscard_ClipDistances.glsl index 793bc365fa..4f3e0d0682 100644 --- a/VisualizationModules/LibRender/glsl/checkDiscard_ClipDistances.glsl +++ b/VisualizationModules/LibRender/glsl/checkDiscard_ClipDistances.glsl @@ -13,6 +13,6 @@ void checkDiscardFragment() int i; for (i = 0; i < u_clipPlaneCount; i++) { - if (v_clipDist[i] < 0) discard; + if (v_clipDist[i] < 0.0) discard; } } diff --git a/VisualizationModules/LibRender/glsl/fs_CenterLitSpherePoints.glsl b/VisualizationModules/LibRender/glsl/fs_CenterLitSpherePoints.glsl index 0cc9e31c66..b9f9c8362b 100644 --- a/VisualizationModules/LibRender/glsl/fs_CenterLitSpherePoints.glsl +++ b/VisualizationModules/LibRender/glsl/fs_CenterLitSpherePoints.glsl @@ -11,7 +11,7 @@ void main() { //const vec3 ecLightPosition = vec3(0.5, 5.0, 7.0); //vec3 lightDir = normalize(ecLightPosition - v_ecPosition); - const vec3 lightDir = vec3(0, 0, 1); + const vec3 lightDir = vec3(0.0, 0.0, 1.0); // Calculate normal from texture coordinates vec3 N; @@ -19,8 +19,8 @@ void main() float mag = dot(N.xy, N.xy); // Kill pixels outside circle - if (mag > 1) discard; - N.z = sqrt(1 - mag); + if (mag > 1.0) discard; + N.z = sqrt(1.0 - mag); // Calculate diffuse lighting float diffuse = max(0.0, dot(lightDir, N)); @@ -28,7 +28,7 @@ void main() vec4 color = srcFragment(); gl_FragColor = vec4(color.rgb*diffuse, color.a); - //gl_FragDepth = gl_FragCoord.z - 15.0*(1-mag); + //gl_FragDepth = gl_FragCoord.z - 15.0*(1.0-mag); } diff --git a/VisualizationModules/LibRender/glsl/fs_ParticleTraceComets.glsl b/VisualizationModules/LibRender/glsl/fs_ParticleTraceComets.glsl index 444b1e4b21..8a76ddf656 100644 --- a/VisualizationModules/LibRender/glsl/fs_ParticleTraceComets.glsl +++ b/VisualizationModules/LibRender/glsl/fs_ParticleTraceComets.glsl @@ -15,8 +15,8 @@ void main() vec3 N; N.xy = vec2(v_circleFactors.x, v_circleFactors.y); float mag = dot(N.xy, N.xy); - if (mag > 1) discard; - N.z = sqrt(1 - mag); + if (mag > 1.0) discard; + N.z = sqrt(1.0 - mag); float diffuse = max(0.0, dot(lightDir, N)); diff --git a/VisualizationModules/LibRender/glsl/vs_DistanceScaledPoints.glsl b/VisualizationModules/LibRender/glsl/vs_DistanceScaledPoints.glsl index 60a11fb3ca..7d88eda974 100644 --- a/VisualizationModules/LibRender/glsl/vs_DistanceScaledPoints.glsl +++ b/VisualizationModules/LibRender/glsl/vs_DistanceScaledPoints.glsl @@ -27,5 +27,5 @@ void main () // Compute the point diameter in window coords (pixels) // Scale with distance for perspective correction of the size float dist = length(v_ecPosition); - gl_PointSize = 2*u_pointRadius/(cvfu_pixelHeightAtUnitDistance*dist); + gl_PointSize = 2.0*u_pointRadius/(cvfu_pixelHeightAtUnitDistance*dist); } diff --git a/VisualizationModules/LibRender/glsl/vs_EnvironmentMapping.glsl b/VisualizationModules/LibRender/glsl/vs_EnvironmentMapping.glsl index 1a0a9a7893..3546329307 100644 --- a/VisualizationModules/LibRender/glsl/vs_EnvironmentMapping.glsl +++ b/VisualizationModules/LibRender/glsl/vs_EnvironmentMapping.glsl @@ -17,10 +17,18 @@ varying vec2 v_texCoord; //-------------------------------------------------------------------------------------------------- void main () { +#ifdef CVF_CALC_SHADOW_COORD_IMPL + calcShadowCoord(); +#endif + // Transforms vertex position and normal vector to eye space v_ecPosition = (cvfu_modelViewMatrix * cvfa_vertex).xyz; v_ecNormal = cvfu_normalMatrix * cvfa_normal; +#ifdef CVF_CALC_CLIP_DISTANCES_IMPL + calcClipDistances(vec4(v_ecPosition, 1)); +#endif + gl_Position = cvfu_modelViewProjectionMatrix*cvfa_vertex; // Compute the texture coordinate for the environment map texture lookup diff --git a/VisualizationModules/LibViewing/cvfRenderEngine.cpp b/VisualizationModules/LibViewing/cvfRenderEngine.cpp index 16a8955057..2c9ef45986 100644 --- a/VisualizationModules/LibViewing/cvfRenderEngine.cpp +++ b/VisualizationModules/LibViewing/cvfRenderEngine.cpp @@ -26,12 +26,12 @@ #include "cvfEffect.h" #include "cvfRenderStateSet.h" #include "cvfShaderProgram.h" -#include "cvfTrace.h" #include "cvfOpenGL.h" #include "cvfBufferObjectManaged.h" #include "cvfMatrixState.h" #include "cvfCamera.h" #include "cvfRenderStateTextureBindings.h" +#include "cvfLogManager.h" #include @@ -59,7 +59,8 @@ RenderEngine::RenderEngine() m_disableDrawableRender(false), m_disableApplyEffects(false), m_forceImmediateMode(false), - m_enableItemCountUpdate(false) + m_enableItemCountUpdate(false), + m_logger(CVF_GET_LOGGER("cee.cvf")) { } @@ -110,11 +111,7 @@ void RenderEngine::render(OpenGLContext* oglContext, RenderQueue* renderQueue, s size_t numPartsInQueue = renderQueue->count(); size_t numPartsToDraw = std::min(numPartsInQueue, maxNumPartsToDraw); - bool debugLogging = CVF_SHOULD_LOG_RENDER_DEBUG(oglContext); - if (debugLogging) - { - CVF_LOG_RENDER_DEBUG(oglContext, "RenderEngine::render(), numParts=" + String(static_cast(numPartsInQueue))); - } + CVF_LOG_DEBUG(m_logger, "RenderEngine::render(), numParts=" + String(static_cast(numPartsInQueue))); size_t i; for (i = 0; i < numPartsToDraw; i++) @@ -129,10 +126,7 @@ void RenderEngine::render(OpenGLContext* oglContext, RenderQueue* renderQueue, s CVF_ASSERT(effect); CVF_ASSERT(part); - if (debugLogging) - { - CVF_LOG_RENDER_DEBUG(oglContext, String("part#=%1, partName='%2'").arg(static_cast(i)).arg(part->name())); - } + CVF_LOG_DEBUG(m_logger, String("part#=%1, partName='%2'").arg(static_cast(i)).arg(part->name())); // Update matrix state to reflect any part transformations // Register if the pass modifies the view matrix so that we can reset it at the end of this part diff --git a/VisualizationModules/LibViewing/cvfRenderEngine.h b/VisualizationModules/LibViewing/cvfRenderEngine.h index 3d04f5a6ea..d1d15afeb1 100644 --- a/VisualizationModules/LibViewing/cvfRenderEngine.h +++ b/VisualizationModules/LibViewing/cvfRenderEngine.h @@ -28,6 +28,7 @@ class RenderQueue; class UniformSet; class Camera; class OpenGLContext; +class Logger; //================================================================================================== @@ -73,6 +74,8 @@ private: bool m_disableApplyEffects; bool m_forceImmediateMode; // Can be used to force immediate mode drawing for debugging purposes (good old glBegin()/glEnd()) bool m_enableItemCountUpdate; + + ref m_logger; }; } diff --git a/VisualizationModules/LibViewing/cvfRendering.cpp b/VisualizationModules/LibViewing/cvfRendering.cpp index e5664f7397..013d5769ec 100644 --- a/VisualizationModules/LibViewing/cvfRendering.cpp +++ b/VisualizationModules/LibViewing/cvfRendering.cpp @@ -38,6 +38,7 @@ #include "cvfShaderProgram.h" #include "cvfRayIntersectSpec.h" #include "cvfHitItemCollection.h" +#include "cvfLogManager.h" namespace cvf { @@ -67,7 +68,8 @@ Rendering::Rendering(const String& renderingName) m_enableMask(0xffffffff), m_clearMode(Viewport::CLEAR_COLOR_DEPTH), m_maxNumPartsToDraw(std::numeric_limits::max()), - m_enablePerformanceTiming(true) + m_enablePerformanceTiming(true), + m_logger(CVF_GET_LOGGER("cee.cvf")) { m_camera = new Camera; m_visibleParts = new PartRenderHintCollection; @@ -142,11 +144,7 @@ void Rendering::render(OpenGLContext* oglContext) { CVF_ASSERT(m_camera.notNull() && m_camera->viewport()); - bool debugLogging = CVF_SHOULD_LOG_RENDER_DEBUG(oglContext); - if (debugLogging) - { - CVF_LOG_RENDER_DEBUG(oglContext, String("Entering Rendering::render(), renderingName='%1'").arg(m_renderingName)); - } + CVF_LOG_DEBUG(m_logger, String("Entering Rendering::render(), renderingName='%1'").arg(m_renderingName)); CVF_CHECK_OGL(oglContext); @@ -278,10 +276,7 @@ void Rendering::render(OpenGLContext* oglContext) CVF_CHECK_OGL(oglContext); - if (debugLogging) - { - CVF_LOG_RENDER_DEBUG(oglContext, String("Exiting Rendering::render(), renderingName='%1'").arg(m_renderingName)); - } + CVF_LOG_DEBUG(m_logger, String("Exiting Rendering::render(), renderingName='%1'").arg(m_renderingName)); } @@ -293,6 +288,13 @@ void Rendering::renderOverlayItems(OpenGLContext* oglContext, bool useSoftwareRe OverlayItemRectMap itemRectMap; calculateOverlayItemLayout(&itemRectMap); + // Must setup a scissor to limit the overlay items to the current viewport, as they might setup a local viewport (e.g. navigation cube) + GLboolean scissorWasOn = glIsEnabled(GL_SCISSOR_TEST); + int scissorBox[4] = {0, 0, -1, -1}; + glGetIntegerv(GL_SCISSOR_BOX, scissorBox); + glScissor(static_cast(m_camera->viewport()->x()), static_cast(m_camera->viewport()->y()), static_cast(m_camera->viewport()->width()), static_cast(m_camera->viewport()->height())); + glEnable(GL_SCISSOR_TEST); + OverlayItemRectMap::iterator it; for (it = itemRectMap.begin(); it != itemRectMap.end(); ++it) { @@ -327,6 +329,10 @@ void Rendering::renderOverlayItems(OpenGLContext* oglContext, bool useSoftwareRe } } } + + // Restore scissor settings + if (!scissorWasOn) glDisable(GL_SCISSOR_TEST); + glScissor(scissorBox[0], scissorBox[1], scissorBox[2], scissorBox[3]); } diff --git a/VisualizationModules/LibViewing/cvfRendering.h b/VisualizationModules/LibViewing/cvfRendering.h index 1875538b80..e652e8b482 100644 --- a/VisualizationModules/LibViewing/cvfRendering.h +++ b/VisualizationModules/LibViewing/cvfRendering.h @@ -155,6 +155,8 @@ private: PerformanceInfo m_performanceInfo; bool m_enablePerformanceTiming; + + ref m_logger; }; }