mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-25 05:28:37 -05:00
- Add currentDrawBufferResolution method in WindowWrapper
- Base renderer resolution on draw buffer resolution instead of window res - Obtain number of aa samples from config file, instead of hard coding to eight samples
This commit is contained in:
@@ -45,7 +45,9 @@ public:
|
||||
uint32_t mouseButtons(int maxNumber) const override;
|
||||
glm::ivec2 currentWindowSize() const override;
|
||||
glm::ivec2 currentWindowResolution() const override;
|
||||
|
||||
glm::ivec2 currentDrawBufferResolution() const override;
|
||||
int currentNumberOfAaSamples() const override;
|
||||
|
||||
bool isRegularRendering() const override;
|
||||
|
||||
glm::mat4 viewProjectionMatrix() const override;
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#define __WINDOWWRAPPER_H__
|
||||
|
||||
#include <ghoul/glm.h>
|
||||
#include <ghoul/misc/exception.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
@@ -104,6 +105,18 @@ public:
|
||||
virtual glm::ivec2 currentWindowResolution() const;
|
||||
|
||||
/**
|
||||
* Returns the resolution of the currently active framebuffer in pixel coordinates.
|
||||
* On default, this method returns the same size as #currentWindowSize.
|
||||
* \return The resolution of the currently active window in pixel coordinates
|
||||
*/
|
||||
virtual glm::ivec2 currentDrawBufferResolution() const;
|
||||
|
||||
/**
|
||||
* Returns the number of anti-aliasing samples used in the current window.
|
||||
*/
|
||||
virtual int currentNumberOfAaSamples() const;
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the current rendering method is regular, i.e., it is
|
||||
* a flat projection without non-linear distortions. Returns <code>false</code> in
|
||||
* other cases, for example fisheye projections. On default, this method will return
|
||||
@@ -163,6 +176,10 @@ public:
|
||||
* Advises the windowing system to take a screenshot. This method defaults to a no-op.
|
||||
*/
|
||||
virtual void takeScreenshot() const;
|
||||
|
||||
struct WindowWrapperException : public ghoul::RuntimeError {
|
||||
explicit WindowWrapperException(const std::string& msg);
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
@@ -104,6 +104,7 @@ private:
|
||||
GLuint _fragmentBuffer;
|
||||
GLuint _fragmentTexture;
|
||||
GLuint _vertexPositionBuffer;
|
||||
int _nAaSamples;
|
||||
|
||||
ghoul::Dictionary _rendererData;
|
||||
}; // ABufferRenderer
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
layout (location = 0) out vec4 finalColor;
|
||||
|
||||
uniform float blackoutFactor;
|
||||
|
||||
uniform int nAaSamples;
|
||||
|
||||
void sortFragments(uint nFrags) {
|
||||
ABufferFragment tmp;
|
||||
@@ -95,7 +95,7 @@ void main() {
|
||||
|
||||
uint nSamples = countSamples(accumulatedMask);
|
||||
color = _color_(fragments[i]); // TODO: Possibly weigh all samples together?
|
||||
color.a *= float(nSamples) * 0.125;
|
||||
color.a *= float(nSamples) / float(nAaSamples);
|
||||
|
||||
finalColor = blend(finalColor, color);
|
||||
}
|
||||
|
||||
@@ -537,7 +537,7 @@ void OpenSpaceEngine::loadFonts() {
|
||||
if (!initSuccess)
|
||||
LERROR("Error initializing default font renderer");
|
||||
|
||||
ghoul::fontrendering::FontRenderer::defaultRenderer().setWindowSize(glm::vec2(_windowWrapper->currentWindowResolution()));
|
||||
ghoul::fontrendering::FontRenderer::defaultRenderer().setWindowSize(glm::vec2(_windowWrapper->currentDrawBufferResolution()));
|
||||
|
||||
}
|
||||
|
||||
@@ -626,12 +626,12 @@ void OpenSpaceEngine::postSynchronizationPreDraw() {
|
||||
|
||||
if (_isMaster && _gui->isEnabled() && _windowWrapper->isRegularRendering()) {
|
||||
glm::vec2 mousePosition = _windowWrapper->mousePosition();
|
||||
glm::ivec2 windowResolution = _windowWrapper->currentWindowResolution();
|
||||
glm::ivec2 drawBufferResolution = _windowWrapper->currentDrawBufferResolution();
|
||||
uint32_t mouseButtons = _windowWrapper->mouseButtons(2);
|
||||
|
||||
double dt = _windowWrapper->averageDeltaTime();
|
||||
|
||||
_gui->startFrame(static_cast<float>(dt), glm::vec2(windowResolution), mousePosition, mouseButtons);
|
||||
_gui->startFrame(static_cast<float>(dt), glm::vec2(drawBufferResolution), mousePosition, mouseButtons);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -83,6 +83,24 @@ glm::ivec2 SGCTWindowWrapper::currentWindowResolution() const {
|
||||
sgct::Engine::instance()->getCurrentWindowPtr()->getFinalFBODimensions(x, y);
|
||||
return glm::ivec2(x, y);
|
||||
}
|
||||
|
||||
glm::ivec2 SGCTWindowWrapper::currentDrawBufferResolution() const {
|
||||
sgct_core::Viewport* viewport = sgct::Engine::instance()->getCurrentWindowPtr()->getViewport(0);
|
||||
if (viewport != nullptr){
|
||||
if (viewport->hasSubViewports() && viewport->getNonLinearProjectionPtr()) {
|
||||
int res = viewport->getNonLinearProjectionPtr()->getCubemapResolution();
|
||||
return glm::ivec2(res, res);
|
||||
} else {
|
||||
return currentWindowResolution();
|
||||
}
|
||||
}
|
||||
throw WindowWrapperException("No viewport available");
|
||||
}
|
||||
|
||||
int SGCTWindowWrapper::currentNumberOfAaSamples() const {
|
||||
return sgct::Engine::instance()->getCurrentWindowPtr()->getNumberOfAASamples();
|
||||
}
|
||||
|
||||
|
||||
bool SGCTWindowWrapper::isRegularRendering() const {
|
||||
// TODO: Needs to implement the nonlinear rendering check ---abock
|
||||
|
||||
@@ -23,8 +23,14 @@
|
||||
****************************************************************************************/
|
||||
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <ghoul/misc/exception.h>
|
||||
#include <string>
|
||||
|
||||
namespace openspace {
|
||||
|
||||
WindowWrapper::WindowWrapperException::WindowWrapperException(const std::string& msg)
|
||||
: ghoul::RuntimeError(msg, "WindowWrapper")
|
||||
{}
|
||||
|
||||
void WindowWrapper::setBarrier(bool) {}
|
||||
|
||||
@@ -54,6 +60,14 @@ glm::ivec2 WindowWrapper::currentWindowResolution() const {
|
||||
return currentWindowSize();
|
||||
}
|
||||
|
||||
glm::ivec2 WindowWrapper::currentDrawBufferResolution() const {
|
||||
return currentWindowSize();
|
||||
}
|
||||
|
||||
int WindowWrapper::currentNumberOfAaSamples() const {
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool WindowWrapper::isRegularRendering() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -96,6 +96,12 @@ void ABufferRenderer::initialize() {
|
||||
"${SHADERS}/abuffer/resolveabuffer.frag",
|
||||
dict);
|
||||
|
||||
_nAaSamples = OsEng.windowWrapper().currentNumberOfAaSamples();
|
||||
if (_nAaSamples > 8) {
|
||||
LERROR("ABuffer does not support more than 8 MSAA samples.");
|
||||
_nAaSamples = 8;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ABufferRenderer::deinitialize() {
|
||||
@@ -163,6 +169,7 @@ void ABufferRenderer::render(float blackoutFactor, bool doPerformanceMeasurement
|
||||
// Step 3: Resolve the buffer
|
||||
_resolveProgram->activate();
|
||||
_resolveProgram->setUniform("blackoutFactor", blackoutFactor);
|
||||
_resolveProgram->setUniform("nAaSamples", _nAaSamples);
|
||||
// todo: pre-ray-cast for each volume
|
||||
glBindVertexArray(_screenQuad);
|
||||
glDrawArrays(GL_TRIANGLES, 0, 6);
|
||||
|
||||
@@ -327,7 +327,7 @@ void RenderEngine::postSynchronizationPreDraw() {
|
||||
bool windowResized = OsEng.windowWrapper().windowHasResized();
|
||||
|
||||
if (windowResized) {
|
||||
glm::ivec2 res = OsEng.windowWrapper().currentWindowResolution();
|
||||
glm::ivec2 res = OsEng.windowWrapper().currentDrawBufferResolution();
|
||||
_renderer->setResolution(res);
|
||||
ghoul::fontrendering::FontRenderer::defaultRenderer().setWindowSize(glm::vec2(res));
|
||||
}
|
||||
@@ -552,7 +552,7 @@ void RenderEngine::setRendererData(const ghoul::Dictionary& data) {
|
||||
* Set renderer
|
||||
*/
|
||||
void RenderEngine::setRenderer(std::unique_ptr<Renderer> renderer) {
|
||||
glm::ivec2 res = OsEng.windowWrapper().currentWindowResolution();
|
||||
glm::ivec2 res = OsEng.windowWrapper().currentDrawBufferResolution();
|
||||
|
||||
if (_renderer) {
|
||||
_renderer->deinitialize();
|
||||
|
||||
Reference in New Issue
Block a user