Merge pull request #5377 from samcake/punk

Removing extra gl calls and removing cruff from Application.cpp
This commit is contained in:
Brad Davis 2015-07-21 06:28:27 -07:00
commit 57f9abe5c8
7 changed files with 20 additions and 114 deletions

View file

@ -313,7 +313,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_previousScriptLocation("LastScriptLocation"),
_scriptsLocationHandle("scriptsLocation"),
_fieldOfView("fieldOfView", DEFAULT_FIELD_OF_VIEW_DEGREES),
_viewTransform(),
_scaleMirror(1.0f),
_rotateMirror(0.0f),
_raiseMirror(0.0f),
@ -962,10 +961,6 @@ void Application::paintGL() {
// FIXME: it's happening again in the updateSHadow and it shouldn't, this should be the place
loadViewFrustum(_myCamera, _viewFrustum);
if (getShadowsEnabled()) {
renderArgs._renderMode = RenderArgs::SHADOW_RENDER_MODE;
updateShadowMap(&renderArgs);
}
renderArgs._renderMode = RenderArgs::DEFAULT_RENDER_MODE;
@ -981,7 +976,6 @@ void Application::paintGL() {
} else {
PROFILE_RANGE(__FUNCTION__ "/mainRender");
{
gpu::Batch batch;
auto primaryFbo = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer();
@ -1086,7 +1080,8 @@ void Application::resizeGL() {
if (_renderResolution != toGlm(renderSize)) {
_renderResolution = toGlm(renderSize);
DependencyManager::get<TextureCache>()->setFrameBufferSize(renderSize);
updateProjectionMatrix();
loadViewFrustum(_myCamera, _viewFrustum);
}
resetCameras(_myCamera, _renderResolution);
@ -1099,18 +1094,6 @@ void Application::resizeGL() {
}
void Application::updateProjectionMatrix() {
updateProjectionMatrix(_myCamera);
}
void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) {
_projectionMatrix = camera.getProjection();
// Tell our viewFrustum about this change, using the application camera
if (updateViewFrustum) {
loadViewFrustum(camera, _viewFrustum);
}
}
bool Application::importSVOFromURL(const QString& urlString) {
QUrl url(urlString);
emit svoImportRequested(url.url());
@ -2968,13 +2951,6 @@ glm::vec3 Application::getSunDirection() {
// FIXME, preprocessor guard this check to occur only in DEBUG builds
static QThread * activeRenderingThread = nullptr;
void Application::updateShadowMap(RenderArgs* renderArgs) {
// TODO fix shadows and make them use the GPU library
}
void Application::setupWorldLight(RenderArgs* renderArgs) {
}
bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) {
return DependencyManager::get<LODManager>()->shouldRenderMesh(largestDimension, distanceToCamera);
}
@ -3219,30 +3195,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
// load the view frustum
loadViewFrustum(theCamera, _displayViewFrustum);
// store view matrix without translation, which we'll use for precision-sensitive objects
updateUntranslatedViewMatrix(-theCamera.getPosition());
// Equivalent to what is happening with _untranslatedViewMatrix and the _viewMatrixTranslation
// the viewTransofmr object is updatded with the correct values and saved,
// this is what is used for rendering the Entities and avatars
Transform viewTransform;
viewTransform.setTranslation(theCamera.getPosition());
viewTransform.setRotation(theCamera.getRotation());
if (renderArgs->_renderSide != RenderArgs::MONO) {
glm::mat4 invView = glm::inverse(_untranslatedViewMatrix);
viewTransform.evalFromRawMatrix(invView);
viewTransform.preTranslate(_viewMatrixTranslation);
}
setViewTransform(viewTransform);
// Setup 3D lights (after the camera transform, so that they are positioned in world space)
{
PerformanceTimer perfTimer("lights");
setupWorldLight(renderArgs);
}
// TODO fix shadows and make them use the GPU library
// The pending changes collecting the changes here
@ -3371,26 +3323,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
activeRenderingThread = nullptr;
}
void Application::updateUntranslatedViewMatrix(const glm::vec3& viewMatrixTranslation) {
_viewMatrixTranslation = viewMatrixTranslation;
}
void Application::setViewTransform(const Transform& view) {
_viewTransform = view;
}
void Application::loadTranslatedViewMatrix(const glm::vec3& translation) {
}
void Application::getModelViewMatrix(glm::dmat4* modelViewMatrix) {
(*modelViewMatrix) =_untranslatedViewMatrix;
(*modelViewMatrix)[3] = _untranslatedViewMatrix * glm::vec4(_viewMatrixTranslation, 1);
}
void Application::getProjectionMatrix(glm::dmat4* projectionMatrix) {
*projectionMatrix = _projectionMatrix;
}
void Application::computeOffAxisFrustum(float& left, float& right, float& bottom, float& top, float& nearVal,
float& farVal, glm::vec4& nearClipPlane, glm::vec4& farClipPlane) const {
@ -3443,6 +3375,7 @@ glm::vec2 Application::getScaledScreenPoint(glm::vec2 projectedPoint) {
void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& region, bool billboard) {
auto originalViewport = renderArgs->_viewport;
// Grab current viewport to reset it at the end
float aspect = (float)region.width() / region.height();
float fov = MIRROR_FIELD_OF_VIEW;
@ -3509,15 +3442,14 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi
}
bool updateViewFrustum = false;
updateProjectionMatrix(_mirrorCamera, updateViewFrustum);
loadViewFrustum(_mirrorCamera, _viewFrustum);
// render rear mirror view
displaySide(renderArgs, _mirrorCamera, true, billboard);
//{
// gpu::Batch batch;
// renderArgs->_viewport = originalViewport;
// batch.setViewportTransform(originalViewport);
// renderArgs->_context->render(batch);
//}
renderArgs->_viewport = originalViewport;
}
void Application::resetSensors() {

View file

@ -236,11 +236,6 @@ public:
Overlays& getOverlays() { return _overlays; }
float getFps() const { return _fps; }
const glm::vec3& getViewMatrixTranslation() const { return _viewMatrixTranslation; }
void setViewMatrixTranslation(const glm::vec3& translation) { _viewMatrixTranslation = translation; }
virtual const Transform& getViewTransform() const { return _viewTransform; }
void setViewTransform(const Transform& view);
float getFieldOfView() { return _fieldOfView.get(); }
void setFieldOfView(float fov) { _fieldOfView.set(fov); }
@ -258,26 +253,12 @@ public:
void resetProfile(const QString& username);
virtual void setupWorldLight(RenderArgs* renderArgs);
virtual bool shouldRenderMesh(float largestDimension, float distanceToCamera);
QImage renderAvatarBillboard(RenderArgs* renderArgs);
void displaySide(RenderArgs* renderArgs, Camera& whichCamera, bool selfAvatarOnly = false, bool billboard = false);
/// Stores the current modelview matrix as the untranslated view matrix to use for transforms and the supplied vector as
/// the view matrix translation.
void updateUntranslatedViewMatrix(const glm::vec3& viewMatrixTranslation = glm::vec3());
const glm::mat4& getUntranslatedViewMatrix() const { return _untranslatedViewMatrix; }
/// Loads a view matrix that incorporates the specified model translation without the precision issues that can
/// result from matrix multiplication at high translation magnitudes.
void loadTranslatedViewMatrix(const glm::vec3& translation);
void getModelViewMatrix(glm::dmat4* modelViewMatrix);
void getProjectionMatrix(glm::dmat4* projectionMatrix);
virtual const glm::vec3& getShadowDistances() const { return _shadowDistances; }
/// Computes the off-axis frustum parameters for the view frustum, taking mirroring into account.
@ -470,8 +451,6 @@ private slots:
private:
void resetCameras(Camera& camera, const glm::uvec2& size);
void updateProjectionMatrix();
void updateProjectionMatrix(Camera& camera, bool updateViewFrustum = true);
void sendPingPackets();
@ -502,7 +481,6 @@ private:
glm::vec3 getSunDirection();
void updateShadowMap(RenderArgs* renderArgs);
void renderRearViewMirror(RenderArgs* renderArgs, const QRect& region, bool billboard = false);
void setMenuShortcutsEnabled(bool enabled);
@ -561,11 +539,6 @@ private:
Setting::Handle<QString> _scriptsLocationHandle;
Setting::Handle<float> _fieldOfView;
Transform _viewTransform;
glm::mat4 _untranslatedViewMatrix;
glm::vec3 _viewMatrixTranslation;
glm::mat4 _projectionMatrix;
float _scaleMirror;
float _rotateMirror;
float _raiseMirror;

View file

@ -789,12 +789,11 @@ void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float alpha
// so no need to render it
return;
}
Application::getInstance()->loadTranslatedViewMatrix(_translation);
// draw a blue sphere at the capsule endpoint
glm::vec3 endPoint;
_boundingShape.getEndPoint(endPoint);
endPoint = endPoint - _translation;
endPoint = endPoint + _translation;
Transform transform = Transform();
transform.setTranslation(endPoint);
batch.setModelTransform(transform);
@ -805,7 +804,7 @@ void SkeletonModel::renderBoundingCollisionShapes(gpu::Batch& batch, float alpha
// draw a yellow sphere at the capsule startpoint
glm::vec3 startPoint;
_boundingShape.getStartPoint(startPoint);
startPoint = startPoint - _translation;
startPoint = startPoint + _translation;
glm::vec3 axis = endPoint - startPoint;
Transform axisTransform = Transform();
axisTransform.setTranslation(-axis);

View file

@ -369,14 +369,14 @@ QPoint ApplicationCompositor::getPalmClickLocation(const PalmData *palm) const {
rv.ry() = point.y;
} else {
MyAvatar* myAvatar = DependencyManager::get<AvatarManager>()->getMyAvatar();
glm::dmat4 projection;
qApp->getProjectionMatrix(&projection);
glm::mat4 projection;
qApp->getDisplayViewFrustum()->evalProjectionMatrix(projection);
glm::quat invOrientation = glm::inverse(myAvatar->getOrientation());
glm::vec3 eyePos = myAvatar->getDefaultEyePosition();
glm::vec3 tip = myAvatar->getLaserPointerTipPosition(palm);
glm::vec3 tipPos = invOrientation * (tip - eyePos);
glm::vec4 clipSpacePos = glm::vec4(projection * glm::dvec4(tipPos, 1.0));
glm::vec4 clipSpacePos = glm::vec4(projection * glm::vec4(tipPos, 1.0f));
glm::vec3 ndcSpacePos;
if (clipSpacePos.w != 0) {
ndcSpacePos = glm::vec3(clipSpacePos) / clipSpacePos.w;

View file

@ -34,6 +34,7 @@ void LocalModelsOverlay::render(RenderArgs* args) {
float glowLevel = getGlowLevel(); // FIXME, glowing removed for now
auto batch = args ->_batch;
Transform transform = Transform();
transform.setTranslation(args->_viewFrustum->getPosition() + getPosition());
batch->setViewTransform(transform);

View file

@ -32,7 +32,11 @@ void GLBackend::do_setProjectionTransform(Batch& batch, uint32 paramOffset) {
void GLBackend::do_setViewportTransform(Batch& batch, uint32 paramOffset) {
memcpy(&_transform._viewport, batch.editData(batch._params[paramOffset]._uint), sizeof(Vec4i));
// Where we assign the GL viewport
glViewport(_transform._viewport.x, _transform._viewport.y, _transform._viewport.z, _transform._viewport.w);
// The Viewport is tagged invalid because the CameraTransformUBO is not up to date and willl need update on next drawcall
_transform._invalidViewport = true;
}
@ -86,9 +90,6 @@ void GLBackend::updateTransform() {
// Check all the dirty flags and update the state accordingly
if (_transform._invalidViewport) {
_transform._transformCamera._viewport = glm::vec4(_transform._viewport);
// Where we assign the GL viewport
glViewport(_transform._viewport.x, _transform._viewport.y, _transform._viewport.z, _transform._viewport.w);
}
if (_transform._invalidProj) {

View file

@ -51,7 +51,7 @@ public:
virtual bool getCascadeShadowsEnabled() = 0;
virtual QThread* getMainThread() = 0;
virtual const Transform& getViewTransform() const = 0;
virtual bool shouldRenderMesh(float largestDimension, float distanceToCamera) = 0;
virtual float getSizeScale() const = 0;
virtual int getBoundaryLevelAdjust() const = 0;