mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-04-28 23:09:32 -05:00
Merge branch 'feature/globebrowsing' of github.com:OpenSpace/OpenSpace-Development into feature/globebrowsing
This commit is contained in:
@@ -24,6 +24,8 @@
|
||||
|
||||
#include <modules/globebrowsing/rendering/patchrenderer.h>
|
||||
|
||||
#include <modules/globebrowsing/rendering/clipmapgeometry.h>
|
||||
|
||||
// open space includes
|
||||
#include <openspace/engine/wrapper/windowwrapper.h>
|
||||
#include <openspace/engine/openspaceengine.h>
|
||||
@@ -65,15 +67,10 @@ namespace openspace {
|
||||
}
|
||||
}
|
||||
|
||||
void PatchRenderer::renderPatch(const LatLonPatch& patch, const RenderData& data, double radius) {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
void PatchRenderer::setFrustrumCuller(std::shared_ptr<FrustrumCuller> fc) {
|
||||
_frustrumCuller = fc;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
// LATLON PATCH RENDERER //
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -90,8 +87,6 @@ namespace openspace {
|
||||
_programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LatLonPatchRenderer::renderPatch(
|
||||
const LatLonPatch& patch, const RenderData& data, double radius)
|
||||
{
|
||||
@@ -143,6 +138,78 @@ namespace openspace {
|
||||
// disable shader
|
||||
_programObject->deactivate();
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
// CLIPMAP PATCH RENDERER //
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
ClipMapPatchRenderer::ClipMapPatchRenderer()
|
||||
: PatchRenderer(shared_ptr<ClipMapGeometry>(new ClipMapGeometry(32)))
|
||||
{
|
||||
_programObject = OsEng.renderEngine().buildRenderProgram(
|
||||
"LatLonSphereMappingProgram",
|
||||
"${MODULE_GLOBEBROWSING}/shaders/clipmappatch_spheremapping_vs.glsl",
|
||||
"${MODULE_GLOBEBROWSING}/shaders/simple_fs.glsl");
|
||||
ghoul_assert(_programObject != nullptr, "Failed to initialize programObject!");
|
||||
|
||||
using IgnoreError = ghoul::opengl::ProgramObject::IgnoreError;
|
||||
_programObject->setIgnoreSubroutineUniformLocationError(IgnoreError::Yes);
|
||||
}
|
||||
|
||||
void ClipMapPatchRenderer::renderPatch(
|
||||
const LatLonPatch& patch, const RenderData& data, double radius)
|
||||
{
|
||||
// activate shader
|
||||
_programObject->activate();
|
||||
using namespace glm;
|
||||
|
||||
Vec3 cameraPos = data.camera.position().dvec3();
|
||||
|
||||
// Get camera transform matrix
|
||||
// TODO : Should only need to fetch the camera transform and use directly
|
||||
// but this is not currently possible in the camera class.
|
||||
vec3 cameraPosition = data.camera.position().vec3();
|
||||
mat4 viewTransform = inverse(translate(mat4(1.0), cameraPosition));
|
||||
viewTransform = mat4(data.camera.viewRotationMatrix()) * viewTransform;
|
||||
|
||||
// TODO : Model transform should be fetched as a matrix directly.
|
||||
mat4 modelTransform = translate(mat4(1), data.position.vec3());
|
||||
|
||||
// Snap patch position
|
||||
int segmentsPerPatch = 32;
|
||||
LatLon stepSize = LatLon(
|
||||
patch.halfSize.lat * 2 / segmentsPerPatch,
|
||||
patch.halfSize.lon * 2 / segmentsPerPatch);
|
||||
ivec2 patchesToCoverGlobe = ivec2(
|
||||
M_PI / (patch.halfSize.lat * 2) + 0.5,
|
||||
M_PI * 2 / (patch.halfSize.lon * 2) + 0.5);
|
||||
ivec2 intSnapCoord = ivec2(
|
||||
patch.center.lat / (M_PI * 2) * segmentsPerPatch * patchesToCoverGlobe.y,
|
||||
patch.center.lon / (M_PI) * segmentsPerPatch * patchesToCoverGlobe.x);
|
||||
LatLon swCorner = LatLon(
|
||||
stepSize.lat * intSnapCoord.x - patch.halfSize.lat,
|
||||
stepSize.lon * intSnapCoord.y - patch.halfSize.lon);
|
||||
|
||||
ivec2 contraction = ivec2(intSnapCoord.y % 2, intSnapCoord.x % 2);
|
||||
|
||||
//LDEBUG("patch.center = [ " << patch.center.lat << " , " << patch.center.lon << " ]");
|
||||
//LDEBUG("intSnapCoord = [ " << intSnapCoord.x << " , " << intSnapCoord.y << " ]");
|
||||
//LDEBUG("contraction = [ " << contraction.x << " , " << contraction.y << " ]");
|
||||
|
||||
_programObject->setUniform("modelViewProjectionTransform", data.camera.projectionMatrix() * viewTransform * modelTransform);
|
||||
_programObject->setUniform("minLatLon", vec2(swCorner.lat, swCorner.lon));
|
||||
_programObject->setUniform("latLonScalingFactor", 2.0f * vec2(patch.halfSize.lat, patch.halfSize.lon));
|
||||
_programObject->setUniform("globeRadius", float(radius));
|
||||
_programObject->setUniform("contraction", contraction);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
// render
|
||||
_geometry->drawUsingActiveProgram();
|
||||
|
||||
// disable shader
|
||||
_programObject->deactivate();
|
||||
}
|
||||
|
||||
} // namespace openspace
|
||||
|
||||
Reference in New Issue
Block a user