resolve conflicts on merge with upstream/master

This commit is contained in:
Stephen Birarda 2015-07-20 12:29:36 -07:00
commit 0177513285
128 changed files with 807 additions and 2228 deletions
examples
interface
libraries

View file

@ -286,6 +286,8 @@ var usersWindow = (function () {
MENU_ITEM = "Users Online",
MENU_ITEM_AFTER = "Chat...",
SETTING_USERS_WINDOW_MINIMIZED = "UsersWindow.Minimized",
isVisible = true,
isMinimized = false,
@ -869,9 +871,13 @@ var usersWindow = (function () {
pollUsers();
// Set minimized at end - setup code does not handle `minimized == false` correctly
setMinimized(Settings.getValue(SETTING_USERS_WINDOW_MINIMIZED, false));
}
function tearDown() {
Settings.setValue(SETTING_USERS_WINDOW_MINIMIZED, isMinimized);
Menu.removeMenuItem(MENU_NAME, MENU_ITEM);
Script.clearTimeout(usersTimer);

View file

@ -22,23 +22,13 @@ else ()
set(BUILD_SEQ "dev")
endif ()
if (APPLE)
set(GL_HEADERS "#include <OpenGL/glext.h>")
elseif (UNIX)
# include the right GL headers for UNIX
set(GL_HEADERS "#include <GL/gl.h>\n#include <GL/glext.h>")
elseif (WIN32)
add_definitions(-D_USE_MATH_DEFINES) # apparently needed to get M_PI and other defines from cmath/math.h
add_definitions(-DWINDOWS_LEAN_AND_MEAN) # needed to make sure windows doesn't go to crazy with its defines
if (WIN32)
add_definitions(-D_USE_MATH_DEFINES) # apparently needed to get M_PI and other defines from cmath/math.h
add_definitions(-DWINDOWS_LEAN_AND_MEAN) # needed to make sure windows doesn't go to crazy with its defines
endif()
set(GL_HEADERS "#include <windowshacks.h>\n#include <GL/glew.h>\n#include <GL/wglew.h>")
endif ()
# create the InterfaceConfig.h file based on GL_HEADERS above
configure_file(InterfaceConfig.h.in "${PROJECT_BINARY_DIR}/includes/InterfaceConfig.h")
configure_file(InterfaceVersion.h.in "${PROJECT_BINARY_DIR}/includes/InterfaceVersion.h")
macro(GroupSources curdir)
file(GLOB children RELATIVE ${PROJECT_SOURCE_DIR}/${curdir} ${PROJECT_SOURCE_DIR}/${curdir}/*)
foreach(child ${children})

View file

@ -1,18 +0,0 @@
//
// InterfaceConfig.h
// interface/src
//
// Created by Stephen Birarda on 2/8/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef interface__InterfaceConfig__
#define interface__InterfaceConfig__
#define GL_GLEXT_PROTOTYPES 1
@GL_HEADERS@
#endif

View file

@ -21,9 +21,6 @@
#include <glm/gtx/vector_angle.hpp>
#include <glm/gtc/type_ptr.hpp>
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include <QAbstractNativeEventFilter>
#include <QActionGroup>
#include <QColorDialog>
@ -84,7 +81,6 @@
#include <PathUtils.h>
#include <PerfStat.h>
#include <PhysicsEngine.h>
#include <ProgramObject.h>
#include <RenderDeferredTask.h>
#include <ResourceCache.h>
#include <SceneScriptingInterface.h>
@ -100,6 +96,7 @@
#include "Application.h"
#include "AudioClient.h"
#include "DiscoverabilityManager.h"
#include "GLCanvas.h"
#include "InterfaceVersion.h"
#include "LODManager.h"
#include "Menu.h"
@ -174,8 +171,6 @@ public:
using namespace std;
// Starfield information
static unsigned STARFIELD_NUM_STARS = 50000;
static unsigned STARFIELD_SEED = 1;
static uint8_t THROTTLED_IDLE_TIMER_DELAY = 10;
const qint64 MAXIMUM_CACHE_SIZE = 10 * BYTES_PER_GIGABYTES; // 10GB
@ -343,7 +338,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_domainConnectionRefusals(QList<QString>()),
_maxOctreePPS(maxOctreePacketsPerSecond.get()),
_lastFaceTrackerUpdate(0),
_applicationOverlay()
_applicationOverlay(),
_glWidget(new GLCanvas())
{
setInstance(this);
#ifdef Q_OS_WIN
@ -987,39 +983,42 @@ void Application::paintGL() {
} else {
PROFILE_RANGE(__FUNCTION__ "/mainRender");
auto primaryFBO = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer();
GLuint fbo = gpu::GLBackend::getFramebufferID(primaryFBO);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Viewport is assigned to the size of the framebuffer
QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
glViewport(0, 0, size.width(), size.height());
renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height());
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
displaySide(&renderArgs, _myCamera);
glPopMatrix();
{
gpu::Batch batch;
auto primaryFbo = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer();
batch.setFramebuffer(primaryFbo);
// clear the normal and specular buffers
batch.clearFramebuffer(
gpu::Framebuffer::BUFFER_COLOR0 |
gpu::Framebuffer::BUFFER_COLOR1 |
gpu::Framebuffer::BUFFER_COLOR2 |
gpu::Framebuffer::BUFFER_DEPTH,
vec4(vec3(0), 1), 1.0, 0.0);
renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
renderRearViewMirror(&renderArgs, _mirrorViewRect);
// Viewport is assigned to the size of the framebuffer
QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
renderArgs._viewport = glm::ivec4(0, 0, size.width(), size.height());
batch.setViewportTransform(renderArgs._viewport);
renderArgs._context->render(batch);
}
renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
displaySide(&renderArgs, _myCamera);
auto finalFbo = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer();
if (_myCamera.getMode() != CAMERA_MODE_MIRROR && Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
renderRearViewMirror(&renderArgs, _mirrorViewRect);
renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
}
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBindFramebuffer(GL_READ_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(finalFbo));
glBlitFramebuffer(0, 0, _renderResolution.x, _renderResolution.y,
0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height(),
GL_COLOR_BUFFER_BIT, GL_LINEAR);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0); // ???
{
auto geometryCache = DependencyManager::get<GeometryCache>();
auto primaryFbo = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer();
gpu::Batch batch;
batch.blit(primaryFbo, glm::ivec4(0, 0, _renderResolution.x, _renderResolution.y),
nullptr, glm::ivec4(0, 0, _glWidget->getDeviceSize().width(), _glWidget->getDeviceSize().height()));
renderArgs._context->render(batch);
}
_compositor.displayOverlayTexture(&renderArgs);
}
@ -1089,11 +1088,7 @@ void Application::resizeGL() {
if (_renderResolution != toGlm(renderSize)) {
_renderResolution = toGlm(renderSize);
DependencyManager::get<TextureCache>()->setFrameBufferSize(renderSize);
glViewport(0, 0, _renderResolution.x, _renderResolution.y); // shouldn't this account for the menu???
updateProjectionMatrix();
glLoadIdentity();
}
resetCameras(_myCamera, _renderResolution);
@ -1112,16 +1107,10 @@ void Application::updateProjectionMatrix() {
void Application::updateProjectionMatrix(Camera& camera, bool updateViewFrustum) {
_projectionMatrix = camera.getProjection();
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(glm::value_ptr(_projectionMatrix));
// Tell our viewFrustum about this change, using the application camera
if (updateViewFrustum) {
loadViewFrustum(camera, _viewFrustum);
}
glMatrixMode(GL_MODELVIEW);
}
bool Application::importSVOFromURL(const QString& urlString) {
@ -1968,7 +1957,6 @@ void Application::setEnableVRMode(bool enableVRMode) {
OculusManager::connect(_glWidget->context()->contextHandle());
_glWidget->setFocus();
_glWidget->makeCurrent();
glClear(GL_COLOR_BUFFER_BIT);
}
OculusManager::recalibrate();
} else {
@ -2164,12 +2152,6 @@ QVector<EntityItemID> Application::pasteEntities(float x, float y, float z) {
}
void Application::initDisplay() {
glEnable(GL_BLEND);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
glShadeModel(GL_SMOOTH);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST);
}
void Application::init() {
@ -2996,166 +2978,10 @@ glm::vec3 Application::getSunDirection() {
static QThread * activeRenderingThread = nullptr;
void Application::updateShadowMap(RenderArgs* renderArgs) {
activeRenderingThread = QThread::currentThread();
PerformanceTimer perfTimer("shadowMap");
auto shadowFramebuffer = DependencyManager::get<TextureCache>()->getShadowFramebuffer();
glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(shadowFramebuffer));
glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT);
glm::vec3 lightDirection = getSunDirection();
glm::quat rotation = rotationBetween(IDENTITY_FRONT, lightDirection);
glm::quat inverseRotation = glm::inverse(rotation);
const float SHADOW_MATRIX_DISTANCES[] = { 0.0f, 2.0f, 6.0f, 14.0f, 30.0f };
const glm::vec2 MAP_COORDS[] = { glm::vec2(0.0f, 0.0f), glm::vec2(0.5f, 0.0f),
glm::vec2(0.0f, 0.5f), glm::vec2(0.5f, 0.5f) };
float frustumScale = 1.0f / (_viewFrustum.getFarClip() - _viewFrustum.getNearClip());
loadViewFrustum(_myCamera, _viewFrustum);
int matrixCount = 1;
//int targetSize = fbo->width();
int sourceSize = shadowFramebuffer->getWidth();
int targetSize = shadowFramebuffer->getWidth();
float targetScale = 1.0f;
if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) {
matrixCount = CASCADED_SHADOW_MATRIX_COUNT;
targetSize = sourceSize / 2;
targetScale = 0.5f;
}
for (int i = 0; i < matrixCount; i++) {
const glm::vec2& coord = MAP_COORDS[i];
glViewport(coord.s * sourceSize, coord.t * sourceSize, targetSize, targetSize);
// if simple shadow then since the resolution is twice as much as with cascaded, cover 2 regions with the map, not just one
int regionIncrement = (matrixCount == 1 ? 2 : 1);
float nearScale = SHADOW_MATRIX_DISTANCES[i] * frustumScale;
float farScale = SHADOW_MATRIX_DISTANCES[i + regionIncrement] * frustumScale;
glm::vec3 points[] = {
glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), nearScale),
glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), nearScale),
glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), nearScale),
glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), nearScale),
glm::mix(_viewFrustum.getNearTopLeft(), _viewFrustum.getFarTopLeft(), farScale),
glm::mix(_viewFrustum.getNearTopRight(), _viewFrustum.getFarTopRight(), farScale),
glm::mix(_viewFrustum.getNearBottomLeft(), _viewFrustum.getFarBottomLeft(), farScale),
glm::mix(_viewFrustum.getNearBottomRight(), _viewFrustum.getFarBottomRight(), farScale) };
glm::vec3 center;
for (size_t j = 0; j < sizeof(points) / sizeof(points[0]); j++) {
center += points[j];
}
center /= (float)(sizeof(points) / sizeof(points[0]));
float radius = 0.0f;
for (size_t j = 0; j < sizeof(points) / sizeof(points[0]); j++) {
radius = qMax(radius, glm::distance(points[j], center));
}
if (i < 3) {
const float RADIUS_SCALE = 0.5f;
_shadowDistances[i] = -glm::distance(_viewFrustum.getPosition(), center) - radius * RADIUS_SCALE;
}
center = inverseRotation * center;
// to reduce texture "shimmer," move in texel increments
float texelSize = (2.0f * radius) / targetSize;
center = glm::vec3(roundf(center.x / texelSize) * texelSize, roundf(center.y / texelSize) * texelSize,
roundf(center.z / texelSize) * texelSize);
glm::vec3 minima(center.x - radius, center.y - radius, center.z - radius);
glm::vec3 maxima(center.x + radius, center.y + radius, center.z + radius);
// stretch out our extents in z so that we get all of the avatars
minima.z -= _viewFrustum.getFarClip() * 0.5f;
maxima.z += _viewFrustum.getFarClip() * 0.5f;
// save the combined matrix for rendering
_shadowMatrices[i] = glm::transpose(glm::translate(glm::vec3(coord, 0.0f)) *
glm::scale(glm::vec3(targetScale, targetScale, 1.0f)) *
glm::translate(glm::vec3(0.5f, 0.5f, 0.5f)) * glm::scale(glm::vec3(0.5f, 0.5f, 0.5f)) *
glm::ortho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z) * glm::mat4_cast(inverseRotation));
// update the shadow view frustum
// glm::vec3 shadowFrustumCenter = glm::vec3((minima.x + maxima.x) * 0.5f, (minima.y + maxima.y) * 0.5f, (minima.z + maxima.z) * 0.5f);
glm::vec3 shadowFrustumCenter = rotation * ((minima + maxima) * 0.5f);
_shadowViewFrustum.setPosition(shadowFrustumCenter);
_shadowViewFrustum.setOrientation(rotation);
_shadowViewFrustum.setProjection(glm::ortho(minima.x, maxima.x, minima.y, maxima.y, minima.z, maxima.z));
_shadowViewFrustum.calculate();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(minima.x, maxima.x, minima.y, maxima.y, -maxima.z, -minima.z);
glm::mat4 projAgain;
glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat*)&projAgain);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glm::vec3 axis = glm::axis(inverseRotation);
glRotatef(glm::degrees(glm::angle(inverseRotation)), axis.x, axis.y, axis.z);
// store view matrix without translation, which we'll use for precision-sensitive objects
updateUntranslatedViewMatrix();
// 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.setRotation(rotation);
// viewTransform.postTranslate(shadowFrustumCenter);
setViewTransform(viewTransform);
glEnable(GL_POLYGON_OFFSET_FILL);
glPolygonOffset(1.1f, 4.0f); // magic numbers courtesy http://www.eecs.berkeley.edu/~ravir/6160/papers/shadowmaps.ppt
{
PerformanceTimer perfTimer("entities");
_entities.render(renderArgs);
}
glDisable(GL_POLYGON_OFFSET_FILL);
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
// fbo->release();
glViewport(0, 0, _glWidget->getDeviceWidth(), _glWidget->getDeviceHeight());
activeRenderingThread = nullptr;
// TODO fix shadows and make them use the GPU library
}
const GLfloat WORLD_AMBIENT_COLOR[] = { 0.525f, 0.525f, 0.6f };
const GLfloat WORLD_DIFFUSE_COLOR[] = { 0.6f, 0.525f, 0.525f };
const GLfloat WORLD_SPECULAR_COLOR[] = { 0.08f, 0.08f, 0.08f, 1.0f };
const glm::vec3 GLOBAL_LIGHT_COLOR = { 0.6f, 0.525f, 0.525f };
void Application::setupWorldLight() {
// Setup 3D lights (after the camera transform, so that they are positioned in world space)
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glm::vec3 sunDirection = getSunDirection();
GLfloat light_position0[] = { sunDirection.x, sunDirection.y, sunDirection.z, 0.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
glLightfv(GL_LIGHT0, GL_AMBIENT, WORLD_AMBIENT_COLOR);
glLightfv(GL_LIGHT0, GL_DIFFUSE, WORLD_DIFFUSE_COLOR);
glLightfv(GL_LIGHT0, GL_SPECULAR, WORLD_SPECULAR_COLOR);
glMaterialfv(GL_FRONT, GL_SPECULAR, WORLD_SPECULAR_COLOR);
glMateriali(GL_FRONT, GL_SHININESS, 96);
void Application::setupWorldLight(RenderArgs* renderArgs) {
}
bool Application::shouldRenderMesh(float largestDimension, float distanceToCamera) {
@ -3311,9 +3137,6 @@ namespace render {
PerformanceTimer perfTimer("stars");
PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings),
"Application::payloadRender<BackgroundRenderData>() ... stars...");
if (!background->_stars.isStarsLoaded()) {
background->_stars.generate(STARFIELD_NUM_STARS, STARFIELD_SEED);
}
// should be the first rendering pass - w/o depth buffer / lighting
// compute starfield alpha based on distance from atmosphere
@ -3361,7 +3184,7 @@ namespace render {
// finally render the starfield
if (hasStars) {
background->_stars.render(args->_viewFrustum->getFieldOfView(), args->_viewFrustum->getAspectRatio(), args->_viewFrustum->getNearClip(), alpha);
background->_stars.render(args, alpha);
}
// draw the sky dome
@ -3405,14 +3228,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
// load the view frustum
loadViewFrustum(theCamera, _displayViewFrustum);
// transform view according to theCamera
// could be myCamera (if in normal mode)
// or could be viewFrustumOffsetCamera if in offset mode
glm::quat rotation = theCamera.getRotation();
glm::vec3 axis = glm::axis(rotation);
glRotatef(-glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
// store view matrix without translation, which we'll use for precision-sensitive objects
updateUntranslatedViewMatrix(-theCamera.getPosition());
@ -3421,7 +3236,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
// this is what is used for rendering the Entities and avatars
Transform viewTransform;
viewTransform.setTranslation(theCamera.getPosition());
viewTransform.setRotation(rotation);
viewTransform.setRotation(theCamera.getRotation());
if (renderArgs->_renderSide != RenderArgs::MONO) {
glm::mat4 invView = glm::inverse(_untranslatedViewMatrix);
@ -3431,27 +3246,13 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
setViewTransform(viewTransform);
glTranslatef(_viewMatrixTranslation.x, _viewMatrixTranslation.y, _viewMatrixTranslation.z);
// Setup 3D lights (after the camera transform, so that they are positioned in world space)
{
PerformanceTimer perfTimer("lights");
setupWorldLight();
}
// setup shadow matrices (again, after the camera transform)
int shadowMatrixCount = 0;
if (Menu::getInstance()->isOptionChecked(MenuOption::SimpleShadows)) {
shadowMatrixCount = 1;
} else if (Menu::getInstance()->isOptionChecked(MenuOption::CascadedShadows)) {
shadowMatrixCount = CASCADED_SHADOW_MATRIX_COUNT;
}
for (int i = shadowMatrixCount - 1; i >= 0; i--) {
glActiveTexture(GL_TEXTURE0 + i);
glTexGenfv(GL_S, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][0]);
glTexGenfv(GL_T, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][1]);
glTexGenfv(GL_R, GL_EYE_PLANE, (const GLfloat*)&_shadowMatrices[i][2]);
setupWorldLight(renderArgs);
}
// TODO fix shadows and make them use the GPU library
// The pending changes collecting the changes here
render::PendingChanges pendingChanges;
@ -3470,11 +3271,7 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
glEnable(GL_LIGHTING);
glEnable(GL_DEPTH_TEST);
// Assuming nothing get's rendered through that
if (!selfAvatarOnly) {
if (DependencyManager::get<SceneScriptingInterface>()->shouldRenderEntities()) {
// render models...
@ -3600,7 +3397,6 @@ void Application::displaySide(RenderArgs* renderArgs, Camera& theCamera, bool se
}
void Application::updateUntranslatedViewMatrix(const glm::vec3& viewMatrixTranslation) {
glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat*)&_untranslatedViewMatrix);
_viewMatrixTranslation = viewMatrixTranslation;
}
@ -3609,9 +3405,6 @@ void Application::setViewTransform(const Transform& view) {
}
void Application::loadTranslatedViewMatrix(const glm::vec3& translation) {
glLoadMatrixf((const GLfloat*)&_untranslatedViewMatrix);
glTranslatef(translation.x + _viewMatrixTranslation.x, translation.y + _viewMatrixTranslation.y,
translation.z + _viewMatrixTranslation.z);
}
void Application::getModelViewMatrix(glm::dmat4* modelViewMatrix) {
@ -3673,9 +3466,8 @@ 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
int viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
float aspect = (float)region.width() / region.height();
float fov = MIRROR_FIELD_OF_VIEW;
@ -3712,37 +3504,45 @@ void Application::renderRearViewMirror(RenderArgs* renderArgs, const QRect& regi
_mirrorCamera.setProjection(glm::perspective(glm::radians(fov), aspect, DEFAULT_NEAR_CLIP, DEFAULT_FAR_CLIP));
_mirrorCamera.setRotation(_myAvatar->getWorldAlignedOrientation() * glm::quat(glm::vec3(0.0f, PI, 0.0f)));
// set the bounds of rear mirror view
gpu::Vec4i viewport;
if (billboard) {
QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
glViewport(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
glScissor(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
renderArgs->_viewport = glm::ivec4(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
viewport = gpu::Vec4i(region.x(), size.height() - region.y() - region.height(), region.width(), region.height());
} else {
// if not rendering the billboard, the region is in device independent coordinates; must convert to device
QSize size = DependencyManager::get<TextureCache>()->getFrameBufferSize();
float ratio = (float)QApplication::desktop()->windowHandle()->devicePixelRatio() * getRenderResolutionScale();
int x = region.x() * ratio, y = region.y() * ratio, width = region.width() * ratio, height = region.height() * ratio;
glViewport(x, size.height() - y - height, width, height);
glScissor(x, size.height() - y - height, width, height);
renderArgs->_viewport = glm::ivec4(x, size.height() - y - height, width, height);
viewport = gpu::Vec4i(x, size.height() - y - height, width, height);
}
renderArgs->_viewport = viewport;
{
gpu::Batch batch;
batch.setViewportTransform(viewport);
batch.setStateScissorRect(viewport);
batch.clearFramebuffer(
gpu::Framebuffer::BUFFER_COLOR0 |
gpu::Framebuffer::BUFFER_COLOR1 |
gpu::Framebuffer::BUFFER_COLOR2 |
gpu::Framebuffer::BUFFER_DEPTH,
vec4(vec3(0), 1), 1.0, 0.0, true);
// Viewport is assigned to the size of the framebuffer
renderArgs->_context->render(batch);
}
bool updateViewFrustum = false;
updateProjectionMatrix(_mirrorCamera, updateViewFrustum);
glEnable(GL_SCISSOR_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// render rear mirror view
glPushMatrix();
displaySide(renderArgs, _mirrorCamera, true, billboard);
glPopMatrix();
// reset Viewport and projection matrix
renderArgs->_viewport = glm::ivec4(viewport[0], viewport[1], viewport[2], viewport[3]);
glViewport(viewport[0], viewport[1], viewport[2], viewport[3]);
glDisable(GL_SCISSOR_TEST);
updateProjectionMatrix(_myCamera, updateViewFrustum);
//{
// gpu::Batch batch;
// renderArgs->_viewport = originalViewport;
// batch.setViewportTransform(originalViewport);
// renderArgs->_context->render(batch);
//}
}
void Application::resetSensors() {

View file

@ -12,8 +12,6 @@
#ifndef hifi_Application_h
#define hifi_Application_h
#include <gpu/GPUConfig.h>
#include <QApplication>
#include <QHash>
#include <QImage>
@ -45,7 +43,6 @@
#include "Camera.h"
#include "Environment.h"
#include "FileLogger.h"
#include "GLCanvas.h"
#include "Menu.h"
#include "Physics.h"
#include "Stars.h"
@ -81,10 +78,10 @@ class QSystemTrayIcon;
class QTouchEvent;
class QWheelEvent;
class GLCanvas;
class FaceTracker;
class MainWindow;
class Node;
class ProgramObject;
class ScriptEngine;
static const QString SNAPSHOT_EXTENSION = ".jpg";
@ -261,7 +258,7 @@ public:
void resetProfile(const QString& username);
virtual void setupWorldLight();
virtual void setupWorldLight(RenderArgs* renderArgs);
virtual bool shouldRenderMesh(float largestDimension, float distanceToCamera);
QImage renderAvatarBillboard(RenderArgs* renderArgs);
@ -643,8 +640,8 @@ private:
QThread _settingsThread;
QTimer _settingsTimer;
GLCanvas* _glWidget = new GLCanvas(); // our GLCanvas has a couple extra features
GLCanvas* _glWidget{ nullptr };
void checkSkeleton();

View file

@ -13,6 +13,7 @@
#define hifi_GLCanvas_h
#include <QDebug>
#include <gpu/GPUConfig.h>
#include <QGLWidget>
#include <QTimer>

View file

@ -9,9 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include <QFileDialog>
#include <QMenuBar>
#include <QShortcut>

View file

@ -11,39 +11,173 @@
#include "Stars.h"
#include <mutex>
#include <QElapsedTimer>
#include <gpu/Batch.h>
#include <gpu/Context.h>
#include <NumericalConstants.h>
#include <DependencyManager.h>
#include <GeometryCache.h>
#include <TextureCache.h>
#include <RenderArgs.h>
#include <ViewFrustum.h>
#include "InterfaceConfig.h"
#include "starfield/Controller.h"
#include "../../libraries/render-utils/standardTransformPNTC_vert.h"
#include "../../libraries/render-utils/stars_frag.h"
Stars::Stars() :
_controller(0l), _starsLoaded(false) {
_controller = new starfield::Controller;
//static const float TILT = 0.23f;
static const float TILT = 0.0f;
static const unsigned int STARFIELD_NUM_STARS = 50000;
static const unsigned int STARFIELD_SEED = 1;
static const float STAR_COLORIZATION = 0.1f;
static const float TAU = 6.28318530717958f;
static const float HALF_TAU = TAU / 2.0f;
static const float QUARTER_TAU = TAU / 4.0f;
static const float MILKY_WAY_WIDTH = TAU / 30.0f; // width in radians of one half of the Milky Way
static const float MILKY_WAY_INCLINATION = 0.0f; // angle of Milky Way from horizontal in degrees
static const float MILKY_WAY_RATIO = 0.4f;
static const char* UNIFORM_TIME_NAME = "iGlobalTime";
Stars::Stars() {
}
Stars::~Stars() {
delete _controller;
}
bool Stars::generate(unsigned numStars, unsigned seed) {
_starsLoaded = _controller->computeStars(numStars, seed);
return _starsLoaded;
// Produce a random float value between 0 and 1
static float frand() {
return (float)rand() / (float)RAND_MAX;
}
bool Stars::setResolution(unsigned k) {
return _controller->setResolution(k);
// Produce a random radian value between 0 and 2 PI (TAU)
static float rrand() {
return frand() * TAU;
}
void Stars::render(float fovY, float aspect, float nearZ, float alpha) {
// determine length of screen diagonal from quadrant height and aspect ratio
float quadrantHeight = nearZ * tanf(RADIANS_PER_DEGREE * fovY * 0.5f);
float halfDiagonal = sqrt(quadrantHeight * quadrantHeight * (1.0f + aspect * aspect));
// determine fov angle in respect to the diagonal
float fovDiagonal = atanf(halfDiagonal / nearZ) * 2.0f;
// pull the modelview matrix off the GL stack
glm::mat4 view; glGetFloatv(GL_MODELVIEW_MATRIX, glm::value_ptr(view));
_controller->render(fovDiagonal, aspect, glm::affineInverse(view), alpha);
// http://mathworld.wolfram.com/SpherePointPicking.html
static vec2 randPolar() {
vec2 result(frand(), frand());
result.x *= TAU;
result.y = powf(result.y, 2.0) / 2.0f;
if (frand() > 0.5f) {
result.y = 0.5f - result.y;
} else {
result.y += 0.5f;
}
result.y = acos((2.0f * result.y) - 1.0f);
return result;
}
static vec3 fromPolar(const vec2& polar) {
float sinTheta = sin(polar.x);
float cosTheta = cos(polar.x);
float sinPhi = sin(polar.y);
float cosPhi = cos(polar.y);
return vec3(
cosTheta * sinPhi,
cosPhi,
sinTheta * sinPhi);
}
// computeStarColor
// - Generate a star color.
//
// colorization can be a value between 0 and 1 specifying how colorful the resulting star color is.
//
// 0 = completely black & white
// 1 = very colorful
unsigned computeStarColor(float colorization) {
unsigned char red, green, blue;
if (randFloat() < 0.3f) {
// A few stars are colorful
red = 2 + (rand() % 254);
green = 2 + round((red * (1 - colorization)) + ((rand() % 254) * colorization));
blue = 2 + round((red * (1 - colorization)) + ((rand() % 254) * colorization));
} else {
// Most stars are dimmer and white
red = green = blue = 2 + (rand() % 128);
}
return red | (green << 8) | (blue << 16);
}
// FIXME star colors
void Stars::render(RenderArgs* renderArgs, float alpha) {
static gpu::BufferPointer vertexBuffer;
static gpu::Stream::FormatPointer streamFormat;
static gpu::Element positionElement, colorElement;
static gpu::PipelinePointer _pipeline;
static int32_t _timeSlot{ -1 };
static std::once_flag once;
const int VERTICES_SLOT = 0;
const int COLOR_SLOT = 2;
std::call_once(once, [&] {
QElapsedTimer startTime;
startTime.start();
vertexBuffer.reset(new gpu::Buffer);
srand(STARFIELD_SEED);
unsigned limit = STARFIELD_NUM_STARS;
std::vector<vec3> points;
points.resize(limit);
for (size_t star = 0; star < limit; ++star) {
points[star] = fromPolar(randPolar());
//auto color = computeStarColor(STAR_COLORIZATION);
//vertexBuffer->append(sizeof(color), (const gpu::Byte*)&color);
}
vertexBuffer->append(sizeof(vec3) * limit, (const gpu::Byte*)&points[0]);
streamFormat.reset(new gpu::Stream::Format()); // 1 for everyone
streamFormat->setAttribute(gpu::Stream::POSITION, VERTICES_SLOT, gpu::Element(gpu::VEC3, gpu::FLOAT, gpu::XYZ), 0);
positionElement = streamFormat->getAttributes().at(gpu::Stream::POSITION)._element;
double timeDiff = (double)startTime.nsecsElapsed() / 1000000.0; // ns to ms
qDebug() << "Total time to generate stars: " << timeDiff << " msec";
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(std::string(standardTransformPNTC_vert)));
auto ps = gpu::ShaderPointer(gpu::Shader::createPixel(std::string(stars_frag)));
auto program = gpu::ShaderPointer(gpu::Shader::createProgram(vs, ps));
gpu::Shader::makeProgram((*program));
_timeSlot = program->getBuffers().findLocation(UNIFORM_TIME_NAME);
if (_timeSlot == gpu::Shader::INVALID_LOCATION) {
_timeSlot = program->getUniforms().findLocation(UNIFORM_TIME_NAME);
}
auto state = gpu::StatePointer(new gpu::State());
// enable decal blend
state->setDepthTest(gpu::State::DepthTest(false));
state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA);
_pipeline.reset(gpu::Pipeline::create(program, state));
});
auto geometryCache = DependencyManager::get<GeometryCache>();
auto textureCache = DependencyManager::get<TextureCache>();
gpu::Batch batch;
batch.setViewTransform(Transform());
batch.setProjectionTransform(renderArgs->_viewFrustum->getProjection());
batch.setModelTransform(Transform().setRotation(glm::inverse(renderArgs->_viewFrustum->getOrientation()) *
quat(vec3(TILT, 0, 0))));
batch.setResourceTexture(0, textureCache->getWhiteTexture());
// Render the world lines
batch.setPipeline(_pipeline);
static auto start = usecTimestampNow();
float msecs = (float)(usecTimestampNow() - start) / (float)USECS_PER_MSEC;
float secs = msecs / (float)MSECS_PER_SECOND;
batch._glUniform1f(_timeSlot, secs);
geometryCache->renderUnitCube(batch);
// Render the stars
geometryCache->useSimpleDrawPipeline(batch);
batch.setInputFormat(streamFormat);
batch.setInputBuffer(VERTICES_SLOT, gpu::BufferView(vertexBuffer, positionElement));
batch.draw(gpu::Primitive::POINTS, STARFIELD_NUM_STARS);
renderArgs->_context->render(batch);
}

View file

@ -12,9 +12,7 @@
#ifndef hifi_Stars_h
#define hifi_Stars_h
#include <glm/glm.hpp>
namespace starfield { class Controller; }
class RenderArgs;
// Starfield rendering component.
class Stars {
@ -22,33 +20,13 @@ public:
Stars();
~Stars();
// Generate stars from random number
// The numStars parameter sets the number of stars to generate.
bool generate(unsigned numStars, unsigned seed);
// Renders the starfield from a local viewer's perspective.
// The parameters specifiy the field of view.
void render(float fovY, float aspect, float nearZ, float alpha);
// Sets the resolution for FOV culling.
//
// The parameter determines the number of tiles in azimuthal
// and altitudinal directions.
//
// GPU resources are updated upon change in which case 'true'
// is returned.
bool setResolution(unsigned k);
// Returns true when stars have been loaded
bool isStarsLoaded() const { return _starsLoaded; };
void render(RenderArgs* args, float alpha);
private:
// don't copy/assign
Stars(Stars const&); // = delete;
Stars& operator=(Stars const&); // delete;
starfield::Controller* _controller;
bool _starsLoaded;
};

View file

@ -24,7 +24,6 @@
#include <ByteCountCoding.h>
#include <SharedUtil.h>
#include "InterfaceConfig.h"
#include "world.h"
#include "Application.h"
#include "InterfaceLogging.h"

View file

@ -9,8 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <gpu/GPUConfig.h>
#include <limits>
#include <AudioClient.h>

View file

@ -11,8 +11,6 @@
#include <vector>
#include <gpu/GPUConfig.h>
#include <QDesktopWidget>
#include <QWindow>

View file

@ -24,7 +24,6 @@
#include "Hand.h"
#include "Head.h"
#include "InterfaceConfig.h"
#include "SkeletonModel.h"
#include "world.h"

View file

@ -8,13 +8,10 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <gpu/GPUConfig.h> // hack to get windows to build
#include <QImage>
#include <GeometryUtil.h>
#include <NodeList.h>
#include <ProgramObject.h>
#include "AvatarManager.h"
#include "Hand.h"

View file

@ -11,8 +11,6 @@
#ifndef hifi_Hand_h
#define hifi_Hand_h
#include "InterfaceConfig.h"
#include <vector>
#include <QAction>
@ -30,7 +28,6 @@
class Avatar;
class ProgramObject;
const float HAND_PADDLE_OFFSET = 0.1f;
const float HAND_PADDLE_THICKNESS = 0.01f;

View file

@ -9,7 +9,6 @@
//
#include <glm/gtx/quaternion.hpp>
#include <gpu/GPUConfig.h>
#include <gpu/Batch.h>
#include <DependencyManager.h>

View file

@ -19,14 +19,12 @@
#include <HeadData.h>
#include "FaceModel.h"
#include "InterfaceConfig.h"
#include "world.h"
const float EYE_EAR_GAP = 0.08f;
class Avatar;
class ProgramObject;
class Head : public HeadData {
public:

View file

@ -19,7 +19,6 @@
#include <QtCore/QTimer>
#include <gpu/GPUConfig.h>
#include <AccountManager.h>
#include <AddressManager.h>
#include <AnimationHandle.h>

View file

@ -10,16 +10,16 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "InterfaceConfig.h"
#include "OculusManager.h"
#include "ui/overlays/Text3DOverlay.h"
#include <gpu/GPUConfig.h>
#include <CursorManager.h>
#include <QDesktopWidget>
#include <QGuiApplication>
#include <QScreen>
#include <QOpenGLTimerQuery>
#include <QGLWidget>
#include <CursorManager.h>
#include <glm/glm.hpp>
#include <avatar/AvatarManager.h>
@ -35,6 +35,7 @@
#include "InterfaceLogging.h"
#include "Application.h"
#include "ui/overlays/Text3DOverlay.h"
template <typename Function>
void for_each_eye(Function function) {
@ -647,12 +648,6 @@ void OculusManager::display(QGLWidget * glCanvas, RenderArgs* renderArgs, const
glBindFramebuffer(GL_FRAMEBUFFER, gpu::GLBackend::getFramebufferID(primaryFBO));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glm::quat orientation;
glm::vec3 trackerPosition;
auto deviceSize = qApp->getDeviceSize();
@ -696,12 +691,6 @@ void OculusManager::display(QGLWidget * glCanvas, RenderArgs* renderArgs, const
configureCamera(*_camera);
_camera->update(1.0f / Application::getInstance()->getFps());
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(glm::value_ptr(_camera->getProjection()));
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
ovrRecti & vp = _eyeViewports[eye];
vp.Size.h = _recommendedTexSize.h * _offscreenRenderScale;
vp.Size.w = _recommendedTexSize.w * _offscreenRenderScale;
@ -714,15 +703,10 @@ void OculusManager::display(QGLWidget * glCanvas, RenderArgs* renderArgs, const
});
_activeEye = ovrEye_Count;
glPopMatrix();
gpu::FramebufferPointer finalFbo;
finalFbo = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer();
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
// restore our normal viewport
glViewport(0, 0, deviceSize.width(), deviceSize.height());

View file

@ -13,14 +13,16 @@
#ifndef hifi_OculusManager_h
#define hifi_OculusManager_h
#include <ProgramObject.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <QSize>
#include "RenderArgs.h"
class QOpenGLContext;
class QGLWidget;
class Camera;
/// Handles interaction with the Oculus Rift.

View file

@ -13,6 +13,7 @@
#include <avatar/AvatarManager.h>
#include <PerfStat.h>
#include <NumericalConstants.h>
#include "Application.h"
#include "SixenseManager.h"
@ -527,8 +528,8 @@ void SixenseManager::emulateMouse(PalmData* palm, int index) {
glm::vec3 direction = glm::inverse(avatar->getOrientation()) * palm->getFingerDirection();
// Get the angles, scaled between (-0.5,0.5)
float xAngle = (atan2(direction.z, direction.x) + M_PI_2);
float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)M_PI_2));
float xAngle = (atan2(direction.z, direction.x) + PI_OVER_TWO);
float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)PI_OVER_TWO));
auto canvasSize = qApp->getCanvasSize();
// Get the pixel range over which the xAngle and yAngle are scaled
float cursorRange = canvasSize.x * getCursorPixelRangeMult();

View file

@ -9,8 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "InterfaceConfig.h"
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
@ -74,10 +72,6 @@ void TV3DManager::configureCamera(Camera& whichCamera, int screenWidth, int scre
setFrustum(whichCamera);
glViewport (0, 0, _screenWidth, _screenHeight); // sets drawing viewport
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) {
@ -105,7 +99,6 @@ void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) {
eyeCamera.setPosition(whichCamera.getPosition());
glEnable(GL_SCISSOR_TEST);
glPushMatrix();
forEachEye([&](eyeFrustum& eye){
_activeEye = &eye;
glViewport(portalX, portalY, portalW, portalH);
@ -115,14 +108,7 @@ void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) {
glm::mat4 projection = glm::frustum<float>(eye.left, eye.right, eye.bottom, eye.top, nearZ, farZ);
projection = glm::translate(projection, vec3(eye.modelTranslation, 0, 0));
eyeCamera.setProjection(projection);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); // reset projection matrix
glLoadMatrixf(glm::value_ptr(projection));
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
renderArgs->_renderSide = RenderArgs::MONO;
qApp->displaySide(renderArgs, eyeCamera, false);
qApp->getApplicationCompositor().displayOverlayTexture(renderArgs);
_activeEye = NULL;
@ -130,7 +116,6 @@ void TV3DManager::display(RenderArgs* renderArgs, Camera& whichCamera) {
// render right side view
portalX = deviceSize.width() / 2;
});
glPopMatrix();
glDisable(GL_SCISSOR_TEST);
// FIXME - glow effect is removed, 3D TV mode broken until we get display plugins working

View file

@ -111,4 +111,3 @@ void OctreePacketProcessor::processPacket(QSharedPointer<NLPacket> packet, Share
} break;
}
}

View file

@ -1,62 +0,0 @@
//
// Config.h
// interface/src/starfield
//
// Created by Tobias Schwinger on 3/29/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_Config_h
#define hifi_Config_h
#include "InterfaceConfig.h"
#include <cstddef>
#include <cfloat>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cctype>
#include <stdint.h>
#include <new>
#include <vector>
#include <memory>
#include <algorithm>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/matrix_inverse.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/matrix_access.hpp>
#include <ProgramObject.h>
#include "AngleUtil.h"
#include "Radix2InplaceSort.h"
#include "Radix2IntegerScanner.h"
#include "FloodFill.h"
// Namespace configuration:
namespace starfield {
using glm::vec3;
using glm::vec4;
using glm::dot;
using glm::normalize;
using glm::mat4;
using glm::row;
using namespace std;
typedef uint32_t nuint;
typedef quint64 wuint;
}
#endif // hifi_Config_h

View file

@ -1,70 +0,0 @@
//
// Controller.cpp
// interface/src/starfield
//
// Created by Chris Barnard on 10/16/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QElapsedTimer>
#include "InterfaceLogging.h"
#include "starfield/Controller.h"
using namespace starfield;
bool Controller::computeStars(unsigned numStars, unsigned seed) {
QElapsedTimer startTime;
startTime.start();
Generator::computeStarPositions(_inputSequence, numStars, seed);
this->retile(numStars, _tileResolution);
double NSEC_TO_MSEC = 1.0 / 1000000.0;
double timeDiff = (double)startTime.nsecsElapsed() * NSEC_TO_MSEC;
qCDebug(interfaceapp) << "Total time to retile and generate stars: " << timeDiff << "msec";
return true;
}
bool Controller::setResolution(unsigned tileResolution) {
if (tileResolution <= 3) {
return false;
}
if (tileResolution != _tileResolution) {
this->retile(_numStars, tileResolution);
return true;
} else {
return false;
}
}
void Controller::render(float perspective, float angle, mat4 const& orientation, float alpha) {
Renderer* renderer = _renderer;
if (renderer != 0l) {
renderer->render(perspective, angle, orientation, alpha);
}
}
void Controller::retile(unsigned numStars, unsigned tileResolution) {
Tiling tiling(tileResolution);
VertexOrder scanner(tiling);
radix2InplaceSort(_inputSequence.begin(), _inputSequence.end(), scanner);
recreateRenderer(numStars, tileResolution);
_tileResolution = tileResolution;
}
void Controller::recreateRenderer(unsigned numStars, unsigned tileResolution) {
delete _renderer;
_renderer = new Renderer(_inputSequence, numStars, tileResolution);
}

View file

@ -1,44 +0,0 @@
//
// Controller.h
// interface/src/starfield
//
// Created by Tobias Schwinger on 3/29/13.
// Modified by Chris Barnard on 10/16/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_Controller_h
#define hifi_Controller_h
#include <time.h>
#include "starfield/Generator.h"
#include "starfield/data/InputVertex.h"
#include "starfield/renderer/Renderer.h"
#include "starfield/renderer/VertexOrder.h"
namespace starfield {
class Controller {
public:
Controller() : _tileResolution(20), _renderer(0l) { }
~Controller() { delete _renderer; }
bool computeStars(unsigned numStars, unsigned seed);
bool setResolution(unsigned tileResolution);
void render(float perspective, float angle, mat4 const& orientation, float alpha);
private:
void retile(unsigned numStars, unsigned tileResolution);
void recreateRenderer(unsigned numStars, unsigned tileResolution);
InputVertices _inputSequence;
unsigned _tileResolution;
unsigned _numStars;
Renderer* _renderer;
};
}
#endif // hifi_Controller_h

View file

@ -1,94 +0,0 @@
//
// Generator.cpp
// interface/src/starfield
//
// Created by Chris Barnard on 10/13/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <QElapsedTimer>
#include "starfield/Generator.h"
using namespace starfield;
const float Generator::STAR_COLORIZATION = 0.1f;
const float PI_OVER_180 = 3.14159265358979f / 180.0f;
void Generator::computeStarPositions(InputVertices& destination, unsigned limit, unsigned seed) {
InputVertices* vertices = & destination;
//_limit = limit;
QElapsedTimer startTime;
startTime.start();
srand(seed);
vertices->clear();
vertices->reserve(limit);
const unsigned MILKY_WAY_WIDTH = 12.0; // width in degrees of one half of the Milky Way
const float MILKY_WAY_INCLINATION = 0.0f; // angle of Milky Way from horizontal in degrees
const float MILKY_WAY_RATIO = 0.4f;
const unsigned NUM_DEGREES = 360;
for(int star = 0; star < floor(limit * (1 - MILKY_WAY_RATIO)); ++star) {
float azimuth, altitude;
azimuth = (((float)rand() / (float) RAND_MAX) * NUM_DEGREES) - (NUM_DEGREES / 2);
altitude = (acos((2.0f * ((float)rand() / (float)RAND_MAX)) - 1.0f) / PI_OVER_180) + 90;
vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION)));
}
for(int star = 0; star < ceil(limit * MILKY_WAY_RATIO); ++star) {
float azimuth = ((float)rand() / (float) RAND_MAX) * NUM_DEGREES;
float altitude = powf(randFloat()*0.5f, 2.0f)/0.25f * MILKY_WAY_WIDTH;
if (randFloat() > 0.5f) {
altitude *= -1.0f;
}
// we need to rotate the Milky Way band to the correct orientation in the sky
// convert from spherical coordinates to cartesian, rotate the point and then convert back.
// An improvement would be to convert all stars to cartesian at this point and not have to convert back.
float tempX = sin(azimuth * PI_OVER_180) * cos(altitude * PI_OVER_180);
float tempY = sin(altitude * PI_OVER_180);
float tempZ = -cos(azimuth * PI_OVER_180) * cos(altitude * PI_OVER_180);
float xangle = MILKY_WAY_INCLINATION * PI_OVER_180;
float newX = (tempX * cos(xangle)) - (tempY * sin(xangle));
float newY = (tempX * sin(xangle)) + (tempY * cos(xangle));
float newZ = tempZ;
azimuth = (atan2(newX,-newZ) + Radians::pi()) / PI_OVER_180;
altitude = atan2(-newY, hypotf(newX, newZ)) / PI_OVER_180;
vertices->push_back(InputVertex(azimuth, altitude, computeStarColor(STAR_COLORIZATION)));
}
double timeDiff = (double)startTime.nsecsElapsed() / 1000000.0; // ns to ms
qDebug() << "Total time to generate stars: " << timeDiff << " msec";
}
// computeStarColor
// - Generate a star color.
//
// colorization can be a value between 0 and 1 specifying how colorful the resulting star color is.
//
// 0 = completely black & white
// 1 = very colorful
unsigned Generator::computeStarColor(float colorization) {
unsigned char red, green, blue;
if (randFloat() < 0.3f) {
// A few stars are colorful
red = 2 + (rand() % 254);
green = 2 + round((red * (1 - colorization)) + ((rand() % 254) * colorization));
blue = 2 + round((red * (1 - colorization)) + ((rand() % 254) * colorization));
} else {
// Most stars are dimmer and white
red = green = blue = 2 + (rand() % 128);
}
return red | (green << 8) | (blue << 16);
}

View file

@ -1,40 +0,0 @@
//
// Generator.h
// interface/src/starfield
//
// Created by Chris Barnard on 10/13/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_Generator_h
#define hifi_Generator_h
#include <locale.h>
#include <time.h>
#include "Config.h"
#include "SharedUtil.h"
#include "starfield/data/InputVertex.h"
namespace starfield {
class Generator {
public:
Generator() {}
~Generator() {}
static void computeStarPositions(InputVertices& destination, unsigned limit, unsigned seed);
static unsigned computeStarColor(float colorization);
private:
static const float STAR_COLORIZATION;
};
}
#endif // hifi_Generator_h

View file

@ -1,26 +0,0 @@
//
// GpuVertex.cpp
// interface/src/starfield/data
//
// Created by Chris Barnard on 10/17/13.
// Based on code by Tobias Schwinger on 3/29/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "starfield/data/GpuVertex.h"
using namespace starfield;
GpuVertex::GpuVertex(InputVertex const& inputVertex) {
_color = inputVertex.getColor();
float azimuth = inputVertex.getAzimuth();
float altitude = inputVertex.getAltitude();
// compute altitude/azimuth into X/Y/Z point on a sphere
_valX = sin(azimuth) * cos(altitude);
_valY = sin(altitude);
_valZ = -cos(azimuth) * cos(altitude);
}

View file

@ -1,37 +0,0 @@
//
// GpuVertex.h
// interface/src/starfield/data
//
// Created by Tobias Schwinger on 3/29/13.
// Modified by Chris Barnard on 10/17/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_GpuVertex_h
#define hifi_GpuVertex_h
#include "starfield/data/InputVertex.h"
namespace starfield {
class GpuVertex {
public:
GpuVertex() { }
GpuVertex(InputVertex const& inputVertex);
unsigned getColor() const { return _color; }
private:
unsigned _color;
float _valX;
float _valY;
float _valZ;
};
}
#endif // hifi_GpuVertex_h

View file

@ -1,27 +0,0 @@
//
// InputVertex.cpp
// interface/src/starfield/data
//
// Created by Chris Barnard on 10/17/13.
// Based on code by Tobias Schwinger 3/29/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "starfield/data/InputVertex.h"
using namespace starfield;
InputVertex::InputVertex(float azimuth, float altitude, unsigned color) {
_color = color | 0xff000000u;
azimuth = angleConvert<Degrees,Radians>(azimuth);
altitude = angleConvert<Degrees,Radians>(altitude);
angleHorizontalPolar<Radians>(azimuth, altitude);
_azimuth = azimuth;
_altitude = altitude;
}

View file

@ -1,39 +0,0 @@
//
// InputVertex.h
// interface/src/starfield/data
//
// Created by Tobias Schwinger on 3/29/13.
// Modified by Chris Barnard on 10/17/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_InputVertex_h
#define hifi_InputVertex_h
#include "starfield/Config.h"
namespace starfield {
class InputVertex {
public:
InputVertex(float azimuth, float altitude, unsigned color);
float getAzimuth() const { return _azimuth; }
float getAltitude() const { return _altitude; }
unsigned getColor() const { return _color; }
private:
unsigned _color;
float _azimuth;
float _altitude;
};
typedef std::vector<InputVertex> InputVertices;
}
#endif // hifi_InputVertex_h

View file

@ -1,32 +0,0 @@
//
// Tile.h
// interface/src/starfield/data
//
// Created by Tobias Schwinger on 3/22/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_Tile_h
#define hifi_Tile_h
#include "starfield/Config.h"
namespace starfield {
struct Tile {
nuint offset;
nuint count;
nuint flags;
// flags
static uint16_t const checked = 1;
static uint16_t const visited = 2;
static uint16_t const render = 4;
};
}
#endif // hifi_Tile_h

View file

@ -1,324 +0,0 @@
//
// Renderer.cpp
// interface/src/starfield/renderer
//
// Created by Chris Barnard on 10/17/13.
// Based on earlier work by Tobias Schwinger 3/22/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "starfield/renderer/Renderer.h"
#include "Application.h"
using namespace starfield;
Renderer::Renderer(InputVertices const& stars, unsigned numStars, unsigned tileResolution) : _dataArray(0l),
_tileArray(0l), _tiling(tileResolution) {
this->glAlloc();
Tiling tiling(tileResolution);
size_t numTiles = tiling.getTileCount();
// 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
_dataArray = new GpuVertex[numStars];
_tileArray = new Tile[numTiles + 1];
_batchOffs = new GLint[numTiles * 2];
_batchCountArray = new GLsizei[numTiles * 2];
prepareVertexData(stars, numStars, tiling);
this->glUpload(numStars);
}
Renderer::~Renderer() {
delete[] _dataArray;
delete[] _tileArray;
delete[] _batchCountArray;
delete[] _batchOffs;
this->glFree();
}
void Renderer::render(float perspective, float aspect, mat4 const& orientation, float alpha) {
float halfPersp = perspective * 0.5f;
// cancel all translation
mat4 matrix = orientation;
matrix[3][0] = 0.0f;
matrix[3][1] = 0.0f;
matrix[3][2] = 0.0f;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadMatrixf(glm::value_ptr(qApp->getDisplayViewFrustum()->getProjection()));
glMatrixMode(GL_MODELVIEW);
// extract local z vector
vec3 ahead = vec3(matrix[2]);
float azimuth = atan2(ahead.x,-ahead.z) + Radians::pi();
float altitude = atan2(-ahead.y, hypotf(ahead.x, ahead.z));
angleHorizontalPolar<Radians>(azimuth, altitude);
float const eps = 0.002f;
altitude = glm::clamp(altitude, -Radians::halfPi() + eps, Radians::halfPi() - eps);
matrix = glm::affineInverse(matrix);
this->_outIndexPos = (unsigned*) _batchOffs;
this->_wRowVec = -vec3(row(matrix, 2));
this->_halfPerspectiveAngle = halfPersp;
TileSelection::Cursor cursor;
cursor.current = _tileArray + _tiling.getTileIndex(azimuth, altitude);
cursor.firstInRow = _tileArray + _tiling.getTileIndex(0.0f, altitude);
floodFill(cursor, TileSelection(*this, _tileArray, _tileArray + _tiling.getTileCount(), (TileSelection::Cursor*) _batchCountArray));
this->glBatch(glm::value_ptr(matrix), prepareBatch((unsigned*) _batchOffs, _outIndexPos), alpha);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
}
// renderer construction
void Renderer::prepareVertexData(InputVertices const& vertices, unsigned numStars, Tiling const& tiling) {
size_t nTiles = tiling.getTileCount();
size_t vertexIndex = 0u, currTileIndex = 0u, count_active = 0u;
_tileArray[0].offset = 0u;
_tileArray[0].flags = 0u;
for (InputVertices::const_iterator i = vertices.begin(), e = vertices.end(); i != e; ++i) {
size_t tileIndex = tiling.getTileIndex(i->getAzimuth(), i->getAltitude());
assert(tileIndex >= currTileIndex);
// moved on to another tile? -> flush
if (tileIndex != currTileIndex) {
Tile* tile = _tileArray + currTileIndex;
Tile* lastTile = _tileArray + tileIndex;
// set count of active vertices (upcoming lod)
tile->count = count_active;
// generate skipped, empty tiles
for(size_t offset = vertexIndex; ++tile != lastTile ;) {
tile->offset = offset, tile->count = 0u, tile->flags = 0u;
}
// initialize next (as far as possible here)
lastTile->offset = vertexIndex;
lastTile->flags = 0u;
currTileIndex = tileIndex;
count_active = 0u;
}
++count_active;
// write converted vertex
_dataArray[vertexIndex++] = *i;
}
assert(vertexIndex == numStars);
// flush last tile (see above)
Tile* tile = _tileArray + currTileIndex;
tile->count = count_active;
for (Tile* e = _tileArray + nTiles + 1; ++tile != e;) {
tile->offset = vertexIndex, tile->count = 0u, tile->flags = 0;
}
}
bool Renderer::visitTile(Tile* tile) {
unsigned index = tile - _tileArray;
*_outIndexPos++ = index;
return isTileVisible(index);
}
bool Renderer::isTileVisible(unsigned index) {
float slice = _tiling.getSliceAngle();
float halfSlice = 0.5f * slice;
unsigned stride = _tiling.getAzimuthalTiles();
float azimuth = (index % stride) * slice;
float altitude = (index / stride) * slice - Radians::halfPi();
float groundX = sin(azimuth);
float groundZ = -cos(azimuth);
float elevation = cos(altitude);
vec3 tileCenter = vec3(groundX * elevation, sin(altitude), groundZ * elevation);
float w = dot(_wRowVec, tileCenter);
float daz = halfSlice * cos(std::max(0.0f, abs(altitude) - halfSlice));
float dal = halfSlice;
float adjustedNear = cos(_halfPerspectiveAngle + sqrt(daz * daz + dal * dal));
return w >= adjustedNear;
}
unsigned Renderer::prepareBatch(unsigned const* indices, unsigned const* indicesEnd) {
unsigned nRanges = 0u;
GLint* offs = _batchOffs;
GLsizei* count = _batchCountArray;
for (unsigned* i = (unsigned*) _batchOffs; i != indicesEnd; ++i) {
Tile* t = _tileArray + *i;
if ((t->flags & Tile::render) > 0u && t->count > 0u) {
*offs++ = t->offset;
*count++ = t->count;
++nRanges;
}
t->flags = 0;
}
return nRanges;
}
// GL API handling
void Renderer::glAlloc() {
GLchar const* const VERTEX_SHADER =
"#version 120\n"
"uniform float alpha;\n"
"void main(void) {\n"
" vec3 c = gl_Color.rgb * 1.22;\n"
" float s = min(max(tan((c.r + c.g + c.b) / 3), 1.0), 3.0);\n"
" gl_Position = ftransform();\n"
" gl_FrontColor= gl_Color * alpha * 1.5;\n"
" gl_PointSize = s;\n"
"}\n";
_program.addShaderFromSourceCode(QGLShader::Vertex, VERTEX_SHADER);
GLchar const* const FRAGMENT_SHADER =
"#version 120\n"
"void main(void) {\n"
" gl_FragColor = gl_Color;\n"
"}\n";
_program.addShaderFromSourceCode(QGLShader::Fragment, FRAGMENT_SHADER);
_program.link();
_alphaLocationHandle = _program.uniformLocation("alpha");
glGenBuffersARB(1, & _vertexArrayHandle);
}
void Renderer::glFree() {
glDeleteBuffersARB(1, & _vertexArrayHandle);
}
void Renderer::glUpload(GLsizei numStars) {
glBindBufferARB(GL_ARRAY_BUFFER, _vertexArrayHandle);
glBufferData(GL_ARRAY_BUFFER, numStars * sizeof(GpuVertex), _dataArray, GL_STATIC_DRAW);
glBindBufferARB(GL_ARRAY_BUFFER, 0);
}
void Renderer::glBatch(GLfloat const* matrix, GLsizei n_ranges, float alpha) {
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glEnable(GL_BLEND);
// setup modelview matrix
glPushMatrix();
glLoadMatrixf(matrix);
// set point size and smoothing + shader control
glPointSize(1.0f);
glEnable(GL_POINT_SMOOTH);
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glEnable(GL_VERTEX_PROGRAM_POINT_SIZE);
// select shader and vertex array
_program.bind();
_program.setUniformValue(_alphaLocationHandle, alpha);
glBindBufferARB(GL_ARRAY_BUFFER, _vertexArrayHandle);
glInterleavedArrays(GL_C4UB_V3F, sizeof(GpuVertex), 0l);
// render
glMultiDrawArrays(GL_POINTS, _batchOffs, _batchCountArray, n_ranges);
// restore state
glBindBufferARB(GL_ARRAY_BUFFER, 0);
_program.release();
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE);
glDisable(GL_POINT_SMOOTH);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glPopMatrix();
}
// flood fill strategy
bool Renderer::TileSelection::select(Renderer::TileSelection::Cursor const& cursor) {
Tile* tile = cursor.current;
if (tile < _tileArray || tile >= _tilesEnd || !! (tile->flags & Tile::checked)) {
// out of bounds or been here already
return false;
}
// will check now and never again
tile->flags |= Tile::checked;
if (_rendererRef.visitTile(tile)) {
// good one -> remember (for batching) and propagate
tile->flags |= Tile::render;
return true;
}
return false;
}
bool Renderer::TileSelection::process(Renderer::TileSelection::Cursor const& cursor) {
Tile* tile = cursor.current;
if (! (tile->flags & Tile::visited)) {
tile->flags |= Tile::visited;
return true;
}
return false;
}
void Renderer::TileSelection::right(Renderer::TileSelection::Cursor& cursor) const {
cursor.current += 1;
if (cursor.current == cursor.firstInRow + _rendererRef._tiling.getAzimuthalTiles()) {
cursor.current = cursor.firstInRow;
}
}
void Renderer::TileSelection::left(Renderer::TileSelection::Cursor& cursor) const {
if (cursor.current == cursor.firstInRow) {
cursor.current = cursor.firstInRow + _rendererRef._tiling.getAzimuthalTiles();
}
cursor.current -= 1;
}
void Renderer::TileSelection::up(Renderer::TileSelection::Cursor& cursor) const {
unsigned numTiles = _rendererRef._tiling.getAzimuthalTiles();
cursor.current += numTiles;
cursor.firstInRow += numTiles;
}
void Renderer::TileSelection::down(Renderer::TileSelection::Cursor& cursor) const {
unsigned numTiles = _rendererRef._tiling.getAzimuthalTiles();
cursor.current -= numTiles;
cursor.firstInRow -= numTiles;
}
void Renderer::TileSelection::defer(Renderer::TileSelection::Cursor const& cursor) {
*_stackPos++ = cursor;
}
bool Renderer::TileSelection::deferred(Renderer::TileSelection::Cursor& cursor) {
if (_stackPos != _stackArray) {
cursor = *--_stackPos;
return true;
}
return false;
}

View file

@ -1,142 +0,0 @@
//
// Renderer.h
// interface/src/starfield/renderer
//
// Created by Tobias Schwinger on 3/22/13.
// Modified by Chris Barnard on 10/17/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_Renderer_h
#define hifi_Renderer_h
#include "starfield/Config.h"
#include "starfield/data/InputVertex.h"
#include "starfield/data/Tile.h"
#include "starfield/data/GpuVertex.h"
#include "starfield/renderer/Tiling.h"
//
// FOV culling
// ===========
//
// As stars can be thought of as at infinity distance, the field of view only
// depends on perspective and rotation:
//
// _----_ <-- visible stars
// from above +-near-+ - -
// \ / |
// near width: \ / | cos(p/2)
// 2sin(p/2) \/ _
// center
//
//
// Now it is important to note that a change in altitude maps uniformly to a
// distance on a sphere. This is NOT the case for azimuthal angles: In this
// case a factor of 'cos(alt)' (the orbital radius) applies:
//
//
// |<-cos alt ->| | |<-|<----->|->| d_azi cos(alt)
// |
// __--* | --------- -
// __-- * | | | ^ d_alt
// __-- alt) * | | | v
// --------------*- | ------------- -
// |
// side view | tile on sphere
//
//
// This lets us find a worst-case (Eigen) angle from the center to the edge
// of a tile as
//
// hypot( 0.5 d_alt, 0.5 d_azi cos(alt_absmin) ).
//
// This angle must be added to 'p' (the perspective angle) in order to find
// an altered near plane for the culling decision.
//
namespace starfield {
class Renderer {
public:
Renderer(InputVertices const& src, unsigned numStars, unsigned tileResolution);
~Renderer();
void render(float perspective, float aspect, mat4 const& orientation, float alpha);
private:
// renderer construction
void prepareVertexData(InputVertices const& vertices, unsigned numStars, Tiling const& tiling);
// FOV culling / LOD
class TileSelection;
friend class Renderer::TileSelection;
class TileSelection {
public:
struct Cursor { Tile* current, * firstInRow; };
private:
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) :
_rendererRef(renderer),
_stackArray(stack),
_stackPos(stack),
_tileArray(tiles),
_tilesEnd(tiles_end) { }
protected:
bool select(Cursor const& cursor);
bool process(Cursor const& cursor);
void right(Cursor& cursor) const;
void left(Cursor& cursor) const;
void up(Cursor& cursor) const;
void down(Cursor& cursor) const;
void defer(Cursor const& cursor);
bool deferred(Cursor& cursor);
};
bool visitTile(Tile* tile);
bool isTileVisible(unsigned index);
unsigned prepareBatch(unsigned const* indices, unsigned const* indicesEnd);
// GL API handling
void glAlloc();
void glFree();
void glUpload(GLsizei numStars);
void glBatch(GLfloat const* matrix, GLsizei n_ranges, float alpha);
// variables
GpuVertex* _dataArray;
Tile* _tileArray;
GLint* _batchOffs;
GLsizei* _batchCountArray;
GLuint _vertexArrayHandle;
ProgramObject _program;
int _alphaLocationHandle;
Tiling _tiling;
unsigned* _outIndexPos;
vec3 _wRowVec;
float _halfPerspectiveAngle;
};
}
#endif // hifi_Renderer_h

View file

@ -1,48 +0,0 @@
//
// Tiling.h
// interface/src/starfield/renderer
//
// Created by Tobias Schwinger on 3/22/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_Tiling_h
#define hifi_Tiling_h
#include "starfield/Config.h"
namespace starfield {
const float LOG2 = 1.4426950408889634f;
class Tiling {
public:
Tiling(unsigned tileResolution) : _tileResolution(tileResolution), _rcpSlice(tileResolution / Radians::twicePi()) {
_nBits = ceil(log((float)getTileCount()) * LOG2); }
unsigned getAzimuthalTiles() const { return _tileResolution; }
unsigned getAltitudinalTiles() const { return _tileResolution / 2 + 1; }
unsigned getTileIndexBits() const { return _nBits; }
unsigned getTileCount() const { return getAzimuthalTiles() * getAltitudinalTiles(); }
unsigned getTileIndex(float azimuth, float altitude) const { return discreteAzimuth(azimuth) +
_tileResolution * discreteAltitude(altitude); }
float getSliceAngle() const { return 1.0f / _rcpSlice; }
private:
unsigned discreteAngle(float unsigned_angle) const { return unsigned(floor(unsigned_angle * _rcpSlice + 0.5f)); }
unsigned discreteAzimuth(float angle) const { return discreteAngle(angle) % _tileResolution; }
unsigned discreteAltitude(float angle) const { return min( getAltitudinalTiles() - 1,
discreteAngle(angle + Radians::halfPi()) ); }
// variables
unsigned _tileResolution;
float _rcpSlice;
unsigned _nBits;
};
}
#endif // hifi_Tiling_h

View file

@ -1,20 +0,0 @@
//
// VertexOrder.cpp
// interface/src/starfield/renderer
//
// Created by Chris Barnard on 10/17/13.
// Based on code by Tobias Schwinger on 3/22/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "starfield/renderer/VertexOrder.h"
using namespace starfield;
bool VertexOrder::bit(InputVertex const& vertex, state_type const& state) const {
unsigned key = _tiling.getTileIndex(vertex.getAzimuth(), vertex.getAltitude());
return base::bit(key, state);
}

View file

@ -1,41 +0,0 @@
//
// VertexOrder.h
// interface/src/starfield/renderer
//
// Created by Tobias Schwinger on 3/22/13.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_VertexOrder_h
#define hifi_VertexOrder_h
#include "starfield/Config.h"
#include "starfield/data/InputVertex.h"
#include "starfield/renderer/Tiling.h"
namespace starfield {
// Defines the vertex order for the renderer as a bit extractor for
//binary in-place Radix Sort.
class VertexOrder : public Radix2IntegerScanner<unsigned>
{
public:
explicit VertexOrder(Tiling const& tiling) :
base(tiling.getTileIndexBits()), _tiling(tiling) { }
bool bit(InputVertex const& vertex, state_type const& state) const;
private:
Tiling _tiling;
typedef Radix2IntegerScanner<unsigned> base;
};
} // anonymous namespace
#endif // hifi_VertexOrder_h

View file

@ -9,14 +9,13 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "InterfaceConfig.h"
#include "ApplicationCompositor.h"
#include <glm/gtc/type_ptr.hpp>
#include <avatar/AvatarManager.h>
#include <gpu/GLBackend.h>
#include <NumericalConstants.h>
#include "CursorManager.h"
#include "Tooltip.h"
@ -501,8 +500,8 @@ void ApplicationCompositor::renderControllerPointers(gpu::Batch& batch) {
glm::vec3 direction = glm::inverse(myAvatar->getOrientation()) * palmData->getFingerDirection();
// Get the angles, scaled between (-0.5,0.5)
float xAngle = (atan2(direction.z, direction.x) + M_PI_2);
float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)M_PI_2));
float xAngle = (atan2(direction.z, direction.x) + PI_OVER_TWO);
float yAngle = 0.5f - ((atan2f(direction.z, direction.y) + (float)PI_OVER_TWO));
// Get the pixel range over which the xAngle and yAngle are scaled
float cursorRange = canvasSize.x * SixenseManager::getInstance().getCursorPixelRangeMult();

View file

@ -62,7 +62,7 @@ public:
glm::vec2 screenToOverlay(const glm::vec2 & screenPos) const;
glm::vec2 overlayToScreen(const glm::vec2 & overlayPos) const;
void computeHmdPickRay(glm::vec2 cursorPos, glm::vec3& origin, glm::vec3& direction) const;
GLuint getOverlayTexture() const;
uint32_t getOverlayTexture() const;
static glm::vec2 directionToSpherical(const glm::vec3 & direction);
static glm::vec3 sphericalToDirection(const glm::vec2 & sphericalPos);

View file

@ -9,11 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "InterfaceConfig.h"
#include <QOpenGLFramebufferObject>
#include <QOpenGLTexture>
#include <glm/gtc/type_ptr.hpp>
#include <avatar/AvatarManager.h>
@ -54,7 +49,6 @@ ApplicationOverlay::ApplicationOverlay()
connect(offscreenUi.data(), &OffscreenUi::textureUpdated, this, [&](GLuint textureId) {
auto offscreenUi = DependencyManager::get<OffscreenUi>();
offscreenUi->lockTexture(textureId);
assert(!glGetError());
std::swap(_uiTexture, textureId);
if (textureId) {
offscreenUi->releaseTexture(textureId);

View file

@ -40,7 +40,7 @@ private:
float _alpha{ 1.0f };
float _trailingAudioLoudness{ 0.0f };
GLuint _uiTexture{ 0 };
uint32_t _uiTexture{ 0 };
int _domainStatusBorder;
int _magnifierBorder;

View file

@ -9,9 +9,9 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <cstdio>
#include "AudioStatsDialog.h"
#include "InterfaceConfig.h"
#include <cstdio>
#include <AudioClient.h>
#include <AudioConstants.h>
@ -22,7 +22,6 @@
#include <Util.h>
#include "AudioStatsDialog.h"
const unsigned COLOR0 = 0x33cc99ff;
const unsigned COLOR1 = 0xffef40c0;

View file

@ -1,78 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** You may use this file under the terms of the BSD license as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
** of its contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
#ifndef FLOWLAYOUT_H
#define FLOWLAYOUT_H
#include <QLayout>
#include <QRect>
#include <QStyle>
//! [0]
class FlowLayout : public QLayout
{
public:
explicit FlowLayout(QWidget *parent, int margin = -1, int hSpacing = -1, int vSpacing = -1);
explicit FlowLayout(int margin = -1, int hSpacing = -1, int vSpacing = -1);
~FlowLayout();
void addItem(QLayoutItem *item);
int horizontalSpacing() const;
int verticalSpacing() const;
Qt::Orientations expandingDirections() const;
bool hasHeightForWidth() const;
int heightForWidth(int) const;
int count() const;
QLayoutItem *itemAt(int index) const;
QSize minimumSize() const;
void setGeometry(const QRect &rect);
QSize sizeHint() const;
QLayoutItem *takeAt(int index);
private:
int doLayout(const QRect &rect, bool testOnly) const;
int smartSpacing(QStyle::PixelMetric pm) const;
QList<QLayoutItem *> itemList;
int m_hSpace;
int m_vSpace;
};
//! [0]
#endif // FLOWLAYOUT_H

View file

@ -9,8 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "InterfaceConfig.h"
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdouble-promotion"
@ -18,7 +16,6 @@
#include <QDesktopWidget>
#include <QTextBlock>
#include <QtGui>
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop

View file

@ -12,8 +12,6 @@
#ifndef hifi_LogDialog_h
#define hifi_LogDialog_h
#include "InterfaceConfig.h"
#include <QDialog>
#include <QMutex>
#include <QPlainTextEdit>

View file

@ -94,7 +94,6 @@ void OctreeStatsDialog::moreless(const QString& link) {
int OctreeStatsDialog::AddStatItem(const char* caption, unsigned colorRGBA) {
char strBuf[64];
const int STATS_LABEL_WIDTH = 600;
_statCount++; // increment our current stat count
@ -115,8 +114,7 @@ int OctreeStatsDialog::AddStatItem(const char* caption, unsigned colorRGBA) {
rgb = ((rgb & colorpart1) >> 1) + ((rgb & colorpart2) >> 3);
palette.setColor(QPalette::WindowText, QColor::fromRgb(rgb));
label->setPalette(palette);
snprintf(strBuf, sizeof(strBuf), " %s:", caption);
_form->addRow(strBuf, label);
_form->addRow(QString(" %1:").arg(caption), label);
label->setFixedWidth(STATS_LABEL_WIDTH);
return _statCount;

View file

@ -28,7 +28,6 @@
#include <QWidget>
#include "Application.h"
#include "FlowLayout.h"
#include "JSConsole.h"
#include "PathUtils.h"

View file

@ -6,8 +6,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <gpu/GPUConfig.h>
#include "Stats.h"
#include <sstream>
@ -26,7 +24,6 @@
#include <PerfStat.h>
#include "BandwidthRecorder.h"
#include "InterfaceConfig.h"
#include "Menu.h"
#include "Util.h"
#include "SequenceNumberStats.h"

View file

@ -9,12 +9,9 @@
#ifndef hifi_Stats_h
#define hifi_Stats_h
#include <QObject>
#include <QQuickItem>
#include <QVector3D>
#include <OffscreenUi.h>
#include <OffscreenQmlElement.h>
#include <RenderArgs.h>
#include <QVector3D>
#define STATS_PROPERTY(type, name, initialValue) \
Q_PROPERTY(type name READ name NOTIFY name##Changed) \

View file

@ -8,13 +8,14 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include "Base3DOverlay.h"
#include <QScriptValue>
#include <RegisteredMetaTypes.h>
#include <SharedUtil.h>
#include "Application.h"
#include "Base3DOverlay.h"
const float DEFAULT_LINE_WIDTH = 1.0f;
const bool DEFAULT_IS_SOLID = false;

View file

@ -11,6 +11,12 @@
#include "BillboardOverlay.h"
#include <QScriptValue>
#include <DependencyManager.h>
#include <GeometryCache.h>
#include <gpu/Batch.h>
#include "Application.h"
#include "GeometryUtil.h"

View file

@ -12,8 +12,6 @@
#define hifi_Circle3DOverlay_h
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include "Planar3DOverlay.h"
class Circle3DOverlay : public Planar3DOverlay {

View file

@ -9,14 +9,15 @@
//
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include "Cube3DOverlay.h"
#include <QScriptValue>
#include <DeferredLightingEffect.h>
#include <SharedUtil.h>
#include <StreamUtils.h>
#include "Application.h"
#include "Cube3DOverlay.h"
#include <GeometryCache.h>
#include <DependencyManager.h>
Cube3DOverlay::Cube3DOverlay(const Cube3DOverlay* cube3DOverlay) :
Volume3DOverlay(cube3DOverlay)

View file

@ -9,16 +9,14 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include "Grid3DOverlay.h"
#include <QScriptValue>
#include <DependencyManager.h>
#include <GeometryCache.h>
#include <PathUtils.h>
#include "Application.h"
ProgramObject Grid3DOverlay::_gridProgram;
#include <ViewFrustum.h>
Grid3DOverlay::Grid3DOverlay() :
_minorGridWidth(1.0),
@ -42,7 +40,7 @@ void Grid3DOverlay::render(RenderArgs* args) {
const float MAX_COLOR = 255.0f;
// center the grid around the camera position on the plane
glm::vec3 rotated = glm::inverse(getRotation()) * Application::getInstance()->getCamera()->getPosition();
glm::vec3 rotated = glm::inverse(getRotation()) * args->_viewFrustum->getPosition();
float spacing = _minorGridWidth;
@ -118,3 +116,4 @@ QScriptValue Grid3DOverlay::getProperty(const QString& property) {
Grid3DOverlay* Grid3DOverlay::createClone() const {
return new Grid3DOverlay(this);
}

View file

@ -12,11 +12,6 @@
#ifndef hifi_Grid3DOverlay_h
#define hifi_Grid3DOverlay_h
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include <ProgramObject.h>
#include "Planar3DOverlay.h"
class Grid3DOverlay : public Planar3DOverlay {
@ -35,8 +30,6 @@ public:
private:
float _minorGridWidth;
int _majorGridEvery;
static ProgramObject _gridProgram;
};
#endif // hifi_Grid3DOverlay_h

View file

@ -12,13 +12,10 @@
#include <DependencyManager.h>
#include <GeometryCache.h>
#include <gpu/Context.h>
#include <gpu/StandardShaderLib.h>
#include <RegisteredMetaTypes.h>
#include "qapplication.h"
#include "gpu/Context.h"
#include "gpu/StandardShaderLib.h"
ImageOverlay::ImageOverlay() :
_imageURL(),
_renderImage(false),

View file

@ -12,8 +12,6 @@
#define hifi_ImageOverlay_h
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include <QImage>
#include <QRect>
#include <QUrl>

View file

@ -8,15 +8,11 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include "Line3DOverlay.h"
#include <GeometryCache.h>
#include <RegisteredMetaTypes.h>
#include "Line3DOverlay.h"
Line3DOverlay::Line3DOverlay() :
_geometryCacheID(DependencyManager::get<GeometryCache>()->allocateID())
{

View file

@ -9,10 +9,11 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "Application.h"
#include "LocalModelsOverlay.h"
#include <EntityTreeRenderer.h>
#include <gpu/Batch.h>
LocalModelsOverlay::LocalModelsOverlay(EntityTreeRenderer* entityTreeRenderer) :
Volume3DOverlay(),
_entityTreeRenderer(entityTreeRenderer) {
@ -33,13 +34,11 @@ void LocalModelsOverlay::render(RenderArgs* args) {
float glowLevel = getGlowLevel(); // FIXME, glowing removed for now
auto batch = args ->_batch;
Application* app = Application::getInstance();
glm::vec3 oldTranslation = app->getViewMatrixTranslation();
Transform transform = Transform();
transform.setTranslation(oldTranslation + getPosition());
transform.setTranslation(args->_viewFrustum->getPosition() + getPosition());
batch->setViewTransform(transform);
_entityTreeRenderer->render(args);
transform.setTranslation(oldTranslation);
transform.setTranslation(args->_viewFrustum->getPosition());
batch->setViewTransform(transform);
}
}

View file

@ -11,7 +11,7 @@
#include "ModelOverlay.h"
#include <Application.h>
#include "Application.h"
ModelOverlay::ModelOverlay()
: _model(),

View file

@ -12,8 +12,6 @@
#define hifi_Overlay_h
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include <SharedUtil.h> // for xColor
#include <render/Scene.h>

View file

@ -11,9 +11,6 @@
#ifndef hifi_Overlay2D_h
#define hifi_Overlay2D_h
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include <QRect>
#include "Overlay.h"

View file

@ -14,10 +14,11 @@
#include <limits>
#include <Application.h>
#include <render/Scene.h>
#include <gpu/GLBackend.h>
#include <RegisteredMetaTypes.h>
#include "Application.h"
#include "BillboardOverlay.h"
#include "Circle3DOverlay.h"
#include "Cube3DOverlay.h"

View file

@ -11,9 +11,6 @@
#ifndef hifi_Planar3DOverlay_h
#define hifi_Planar3DOverlay_h
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include "Base3DOverlay.h"
class Planar3DOverlay : public Base3DOverlay {

View file

@ -8,9 +8,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include "Rectangle3DOverlay.h"
#include <GeometryCache.h>

View file

@ -8,14 +8,12 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include <SharedUtil.h>
#include "Sphere3DOverlay.h"
#include "Application.h"
#include <DependencyManager.h>
#include <GeometryCache.h>
#include <gpu/Batch.h>
#include <SharedUtil.h>
Sphere3DOverlay::Sphere3DOverlay(const Sphere3DOverlay* Sphere3DOverlay) :
Volume3DOverlay(Sphere3DOverlay)

View file

@ -8,9 +8,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include "Text3DOverlay.h"
#include <DeferredLightingEffect.h>

View file

@ -11,9 +11,6 @@
#ifndef hifi_Text3DOverlay_h
#define hifi_Text3DOverlay_h
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include <QString>
#include "Planar3DOverlay.h"

View file

@ -8,21 +8,22 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include "Application.h"
#include "TextOverlay.h"
#include "OffscreenUi.h"
#include "text/FontFamilies.h"
#include <gpu/GLBackend.h>
#include <QQuickItem>
#include <DependencyManager.h>
#include <GeometryCache.h>
#include <TextureCache.h>
#include <GLMHelpers.h>
#include <gpu/GLBackend.h>
#include <OffscreenUi.h>
#include <RegisteredMetaTypes.h>
#include <SharedUtil.h>
#include <TextureCache.h>
#include <ViewFrustum.h>
#include <QQuickItem>
#include "Application.h"
#include "text/FontFamilies.h"
#define TEXT_OVERLAY_PROPERTY(type, name, initialValue) \
Q_PROPERTY(type name READ name WRITE set##name NOTIFY name##Changed) \

View file

@ -11,9 +11,6 @@
#ifndef hifi_TextOverlay_h
#define hifi_TextOverlay_h
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include <QString>
#include <SharedUtil.h>

View file

@ -11,9 +11,6 @@
#ifndef hifi_Volume3DOverlay_h
#define hifi_Volume3DOverlay_h
// include this before QGLWidget, which includes an earlier version of OpenGL
#include "InterfaceConfig.h"
#include "Base3DOverlay.h"
class Volume3DOverlay : public Base3DOverlay {

View file

@ -93,6 +93,7 @@ void AudioInjector::injectAudio() {
}
void AudioInjector::restart() {
_isPlaying = true;
connect(this, &AudioInjector::finished, this, &AudioInjector::restartPortionAfterFinished);
if (!_isStarted || _isFinished) {
emit finished();
@ -274,6 +275,7 @@ void AudioInjector::injectToMixer() {
}
setIsFinished(true);
_isPlaying = !_isFinished; // Which can be false if a restart was requested
}
void AudioInjector::stop() {
@ -281,6 +283,7 @@ void AudioInjector::stop() {
if (_options.localOnly) {
// we're only a local injector, so we can say we are finished right away too
_isPlaying = false;
setIsFinished(true);
}
}
@ -338,6 +341,7 @@ AudioInjector* AudioInjector::playSound(const QByteArray& buffer, const AudioInj
injectorThread->setObjectName("Audio Injector Thread");
AudioInjector* injector = new AudioInjector(buffer, options);
injector->_isPlaying = true;
injector->setLocalAudioInterface(localInterface);
injector->moveToThread(injectorThread);

View file

@ -62,7 +62,7 @@ public slots:
void setCurrentSendPosition(int currentSendPosition) { _currentSendPosition = currentSendPosition; }
float getLoudness() const { return _loudness; }
bool isPlaying() const { return !_isFinished; }
bool isPlaying() const { return _isPlaying; }
void restartPortionAfterFinished();
signals:
@ -78,6 +78,7 @@ private:
AudioInjectorOptions _options;
bool _shouldStop = false;
float _loudness = 0.0f;
bool _isPlaying = false;
bool _isStarted = false;
bool _isFinished = false;
bool _shouldDeleteAfterFinish = false;

View file

@ -9,9 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <gpu/GPUConfig.h>
#include <gpu/GLBackend.h>
#include <glm/gtx/quaternion.hpp>
#include <QEventLoop>

View file

@ -13,7 +13,6 @@
#include <glm/gtx/quaternion.hpp>
#include <gpu/GPUConfig.h>
#include <gpu/Batch.h>
#include <DeferredLightingEffect.h>

View file

@ -14,7 +14,6 @@
#include <glm/gtx/quaternion.hpp>
#include <gpu/GPUConfig.h>
#include <gpu/Batch.h>
#include <DeferredLightingEffect.h>
#include <ObjectMotionState.h>

View file

@ -11,7 +11,6 @@
#include <glm/gtx/quaternion.hpp>
#include <gpu/GPUConfig.h>
#include <gpu/Batch.h>
#include <DeferredLightingEffect.h>

View file

@ -11,7 +11,6 @@
#include <glm/gtx/quaternion.hpp>
#include <gpu/GPUConfig.h>
#include <gpu/Batch.h>
#include <GeometryCache.h>

View file

@ -11,8 +11,6 @@
#include <glm/gtx/quaternion.hpp>
#include <gpu/GPUConfig.h>
#include <QJsonDocument>
#include <AbstractViewStateInterface.h>

View file

@ -10,8 +10,6 @@
#include <glm/gtx/quaternion.hpp>
#include <gpu/GPUConfig.h>
#include <DependencyManager.h>
#include <DeferredLightingEffect.h>
#include <PerfStat.h>

View file

@ -23,8 +23,6 @@
#pragma GCC diagnostic pop
#endif
#include <gpu/GPUConfig.h>
#include <DeferredLightingEffect.h>
#include <Model.h>
#include <PerfStat.h>

View file

@ -13,7 +13,6 @@
#include <glm/gtx/quaternion.hpp>
#include <gpu/GPUConfig.h>
#include <gpu/Batch.h>
#include <DependencyManager.h>

View file

@ -11,8 +11,6 @@
#include <glm/gtx/quaternion.hpp>
#include <gpu/GPUConfig.h>
#include <DeferredLightingEffect.h>
#include <GeometryCache.h>
#include <PerfStat.h>

View file

@ -8,12 +8,14 @@
#include "RenderableWebEntityItem.h"
#include <gpu/GPUConfig.h>
#include <QMouseEvent>
#include <QQuickItem>
#include <QQuickWindow>
#include <QOpenGLContext>
#include <glm/gtx/quaternion.hpp>
#include <gpu/GPUConfig.h>
#include <DeferredLightingEffect.h>
#include <GeometryCache.h>
#include <PerfStat.h>

View file

@ -11,7 +11,6 @@
#include "RenderableZoneEntityItem.h"
#include <gpu/GPUConfig.h>
#include <gpu/Batch.h>
#include <AbstractViewStateInterface.h>

View file

@ -9,9 +9,13 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "Batch.h"
#include "GPUConfig.h"
#include <QDebug>
#include <GLMHelpers.h>
#if defined(NSIGHT_FOUND)
#include "nvToolsExt.h"
@ -254,6 +258,22 @@ void Batch::setFramebuffer(const FramebufferPointer& framebuffer) {
}
void Batch::blit(const FramebufferPointer& src, const Vec4i& srcViewport,
const FramebufferPointer& dst, const Vec4i& dstViewport) {
ADD_COMMAND(blit);
_params.push_back(_framebuffers.cache(src));
_params.push_back(srcViewport.x);
_params.push_back(srcViewport.y);
_params.push_back(srcViewport.z);
_params.push_back(srcViewport.w);
_params.push_back(_framebuffers.cache(dst));
_params.push_back(dstViewport.x);
_params.push_back(dstViewport.y);
_params.push_back(dstViewport.z);
_params.push_back(dstViewport.w);
}
void Batch::beginQuery(const QueryPointer& query) {
ADD_COMMAND(beginQuery);
@ -271,3 +291,16 @@ void Batch::getQuery(const QueryPointer& query) {
_params.push_back(_queries.cache(query));
}
void push_back(Batch::Params& params, const vec3& v) {
params.push_back(v.x);
params.push_back(v.y);
params.push_back(v.z);
}
void push_back(Batch::Params& params, const vec4& v) {
params.push_back(v.x);
params.push_back(v.y);
params.push_back(v.z);
params.push_back(v.a);
}

View file

@ -11,20 +11,14 @@
#ifndef hifi_gpu_Batch_h
#define hifi_gpu_Batch_h
#include <assert.h>
#include "GPUConfig.h"
#include "Transform.h"
#include <vector>
#include "Framebuffer.h"
#include "Pipeline.h"
#include "Query.h"
#include "Stream.h"
#include "Texture.h"
#include "Pipeline.h"
#include "Framebuffer.h"
#include "Transform.h"
#if defined(NSIGHT_FOUND)
class ProfileRange {
@ -111,6 +105,9 @@ public:
// Framebuffer Stage
void setFramebuffer(const FramebufferPointer& framebuffer);
void blit(const FramebufferPointer& src, const Vec4i& srcViewport,
const FramebufferPointer& dst, const Vec4i& dstViewport);
// Query Section
void beginQuery(const QueryPointer& query);
@ -123,42 +120,42 @@ public:
// For now, instead of calling the raw gl Call, use the equivalent call on the batch so the call is beeing recorded
// THe implementation of these functions is in GLBackend.cpp
void _glEnable(GLenum cap);
void _glDisable(GLenum cap);
void _glEnable(unsigned int cap);
void _glDisable(unsigned int cap);
void _glEnableClientState(GLenum array);
void _glDisableClientState(GLenum array);
void _glEnableClientState(unsigned int array);
void _glDisableClientState(unsigned int array);
void _glCullFace(GLenum mode);
void _glAlphaFunc(GLenum func, GLclampf ref);
void _glCullFace(unsigned int mode);
void _glAlphaFunc(unsigned int func, float ref);
void _glDepthFunc(GLenum func);
void _glDepthMask(GLboolean flag);
void _glDepthRange(GLfloat zNear, GLfloat zFar);
void _glDepthFunc(unsigned int func);
void _glDepthMask(unsigned char flag);
void _glDepthRange(float zNear, float zFar);
void _glBindBuffer(GLenum target, GLuint buffer);
void _glBindBuffer(unsigned int target, unsigned int buffer);
void _glBindTexture(GLenum target, GLuint texture);
void _glActiveTexture(GLenum texture);
void _glTexParameteri(GLenum target, GLenum pname, GLint param);
void _glBindTexture(unsigned int target, unsigned int texture);
void _glActiveTexture(unsigned int texture);
void _glTexParameteri(unsigned int target, unsigned int pname, int param);
void _glDrawBuffers(GLsizei n, const GLenum* bufs);
void _glDrawBuffers(int n, const unsigned int* bufs);
void _glUseProgram(GLuint program);
void _glUniform1i(GLint location, GLint v0);
void _glUniform1f(GLint location, GLfloat v0);
void _glUniform2f(GLint location, GLfloat v0, GLfloat v1);
void _glUniform3f(GLint location, GLfloat v0, GLfloat v1, GLfloat v2);
void _glUniform3fv(GLint location, GLsizei count, const GLfloat* value);
void _glUniform4fv(GLint location, GLsizei count, const GLfloat* value);
void _glUniform4iv(GLint location, GLsizei count, const GLint* value);
void _glUniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value);
void _glUseProgram(unsigned int program);
void _glUniform1i(int location, int v0);
void _glUniform1f(int location, float v0);
void _glUniform2f(int location, float v0, float v1);
void _glUniform3f(int location, float v0, float v1, float v2);
void _glUniform3fv(int location, int count, const float* value);
void _glUniform4fv(int location, int count, const float* value);
void _glUniform4iv(int location, int count, const int* value);
void _glUniformMatrix4fv(int location, int count, unsigned char transpose, const float* value);
void _glEnableVertexAttribArray(GLint location);
void _glDisableVertexAttribArray(GLint location);
void _glEnableVertexAttribArray(int location);
void _glDisableVertexAttribArray(int location);
void _glColor4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha);
void _glLineWidth(GLfloat width);
void _glColor4f(float red, float green, float blue, float alpha);
void _glLineWidth(float width);
enum Command {
COMMAND_draw = 0,
@ -185,6 +182,7 @@ public:
COMMAND_setResourceTexture,
COMMAND_setFramebuffer,
COMMAND_blit,
COMMAND_beginQuery,
COMMAND_endQuery,

View file

@ -39,6 +39,7 @@ GLBackend::CommandCall GLBackend::_commandCalls[Batch::NUM_COMMANDS] =
(&::gpu::GLBackend::do_setResourceTexture),
(&::gpu::GLBackend::do_setFramebuffer),
(&::gpu::GLBackend::do_blit),
(&::gpu::GLBackend::do_beginQuery),
(&::gpu::GLBackend::do_endQuery),
@ -746,45 +747,3 @@ void GLBackend::do_glLineWidth(Batch& batch, uint32 paramOffset) {
glLineWidth(batch._params[paramOffset]._float);
(void) CHECK_GL_ERROR();
}
void GLBackend::loadMatrix(GLenum target, const glm::mat4 & m) {
glMatrixMode(target);
glLoadMatrixf(glm::value_ptr(m));
}
void GLBackend::fetchMatrix(GLenum target, glm::mat4 & m) {
switch (target) {
case GL_MODELVIEW_MATRIX:
case GL_PROJECTION_MATRIX:
break;
// Lazy cheating
case GL_MODELVIEW:
target = GL_MODELVIEW_MATRIX;
break;
case GL_PROJECTION:
target = GL_PROJECTION_MATRIX;
break;
default:
Q_ASSERT_X(false, "GLBackend::fetchMatrix", "Bad matrix target");
}
glGetFloatv(target, glm::value_ptr(m));
}
void GLBackend::checkGLStackStable(std::function<void()> f) {
#ifdef DEBUG
GLint mvDepth, prDepth;
glGetIntegerv(GL_MODELVIEW_STACK_DEPTH, &mvDepth);
glGetIntegerv(GL_PROJECTION_STACK_DEPTH, &prDepth);
#endif
f();
#ifdef DEBUG
GLint mvDepthFinal, prDepthFinal;
glGetIntegerv(GL_MODELVIEW_STACK_DEPTH, &mvDepthFinal);
glGetIntegerv(GL_PROJECTION_STACK_DEPTH, &prDepthFinal);
Q_ASSERT(mvDepth == mvDepthFinal);
Q_ASSERT(prDepth == prDepthFinal);
#endif
}

View file

@ -107,10 +107,6 @@ public:
static GLShader* syncGPUObject(const Shader& shader);
static GLuint getShaderID(const ShaderPointer& shader);
// FIXME: Please remove these 2 calls once the text renderer doesn't use naked gl calls anymore
static void loadMatrix(GLenum target, const glm::mat4 & m);
static void fetchMatrix(GLenum target, glm::mat4 & m);
class GLState : public GPUObject {
public:
class Command {
@ -394,6 +390,8 @@ protected:
// Output stage
void do_setFramebuffer(Batch& batch, uint32 paramOffset);
void do_blit(Batch& batch, uint32 paramOffset);
struct OutputStageState {

View file

@ -101,7 +101,7 @@ void GLBackend::syncInputStateCache() {
//_input._defaultVAO
glBindVertexArray(_input._defaultVAO);
#else
int i = 0;
size_t i = 0;
#if defined(SUPPORT_LEGACY_OPENGL)
for (; i < NUM_CLASSIC_ATTRIBS; i++) {
_input._attributeActivation[i] = glIsEnabled(attributeSlotToClassicAttribName[i]);
@ -298,3 +298,10 @@ void GLBackend::do_setIndexBuffer(Batch& batch, uint32 paramOffset) {
}
(void) CHECK_GL_ERROR();
}
template <typename V>
void popParam(Batch::Params& params, uint32& paramOffset, V& v) {
for (size_t i = 0; i < v.length(); ++i) {
v[i] = params[paramOffset++]._float;
}
}

View file

@ -166,3 +166,22 @@ void GLBackend::do_setFramebuffer(Batch& batch, uint32 paramOffset) {
_output._framebuffer = framebuffer;
}
}
void GLBackend::do_blit(Batch& batch, uint32 paramOffset) {
auto srcframebuffer = batch._framebuffers.get(batch._params[paramOffset]._uint);
Vec4i srcvp;
for (size_t i = 0; i < 4; ++i) {
srcvp[i] = batch._params[paramOffset + 1 + i]._int;
}
auto dstframebuffer = batch._framebuffers.get(batch._params[paramOffset + 5]._uint);
Vec4i dstvp;
for (size_t i = 0; i < 4; ++i) {
dstvp[i] = batch._params[paramOffset + 6 + i]._int;
}
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, getFramebufferID(dstframebuffer));
glBindFramebuffer(GL_READ_FRAMEBUFFER, getFramebufferID(srcframebuffer));
glBlitFramebuffer(srcvp.x, srcvp.y, srcvp.z, srcvp.w,
dstvp.x, dstvp.y, dstvp.z, dstvp.w,
GL_COLOR_BUFFER_BIT, GL_LINEAR);
}

View file

@ -53,6 +53,4 @@ static const GLenum _elementTypeToGLType[gpu::NUM_TYPES] = {
// #define CHECK_GL_ERROR() gpu::GLBackend::checkGLErrorDebug(__FUNCTION__ ":" CHECK_GL_ERROR_HELPER(__LINE__))
#define CHECK_GL_ERROR() gpu::GLBackend::checkGLErrorDebug(__FUNCTION__)
#define CHECK_GL_STACK_STABLE(f) gpu::GLBackend::checkGLStackStable(f)
#endif

View file

@ -32,6 +32,7 @@ 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));
glViewport(_transform._viewport.x, _transform._viewport.y, _transform._viewport.z, _transform._viewport.w);
_transform._invalidViewport = true;
}

View file

@ -25,7 +25,6 @@
#define GPU_TRANSFORM_PROFILE GPU_LEGACY
#elif defined(WIN32)
#include <windowshacks.h>
#include <GL/glew.h>
#include <GL/wglew.h>

View file

@ -14,7 +14,6 @@
#include <assert.h>
#include <memory>
#include <vector>
#include "GPUConfig.h"
#include "Format.h"

View file

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

View file

@ -9,35 +9,50 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// include this before QOpenGLFramebufferObject, which includes an earlier version of OpenGL
#include <gpu/GPUConfig.h>
#include "AmbientOcclusionEffect.h"
#include <QFile>
#include <QTextStream>
#include <gpu/GLBackend.h>
#include <glm/gtc/random.hpp>
#include <PathUtils.h>
#include <SharedUtil.h>
#include "AbstractViewStateInterface.h"
#include "AmbientOcclusionEffect.h"
#include "ProgramObject.h"
#include "RenderUtil.h"
#include "TextureCache.h"
const int ROTATION_WIDTH = 4;
const int ROTATION_HEIGHT = 4;
static QString readFile(const QString& path) {
QFile file(path);
QString result;
if (file.open(QFile::ReadOnly | QFile::Text)) {
QTextStream in(&file);
result = in.readAll();
}
return result;
}
void AmbientOcclusionEffect::init(AbstractViewStateInterface* viewState) {
#if 0
_viewState = viewState; // we will use this for view state services
_occlusionProgram = new ProgramObject();
_occlusionProgram->addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath()
+ "shaders/ambient_occlusion.vert");
_occlusionProgram->addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath()
+ "shaders/ambient_occlusion.frag");
_occlusionProgram->link();
{
gpu::Shader::Source vertexSource = std::string(readFile(PathUtils::resourcesPath()
+ "shaders/ambient_occlusion.vert").toLocal8Bit().data());
gpu::Shader::Source fragmentSource = std::string(readFile(PathUtils::resourcesPath()
+ "shaders/ambient_occlusion.frag").toLocal8Bit().data());
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(vertexSource));
auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentSource));
_occlusionProgram = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs));
}
foreach(auto uniform, _occlusionProgram->getUniforms()) {
qDebug() << uniform._location;
}
// create the sample kernel: an array of hemispherically distributed offset vectors
const int SAMPLE_KERNEL_SIZE = 16;
QVector3D sampleKernel[SAMPLE_KERNEL_SIZE];
@ -51,20 +66,20 @@ void AmbientOcclusionEffect::init(AbstractViewStateInterface* viewState) {
sampleKernel[i] = QVector3D(vector.x, vector.y, vector.z);
}
_occlusionProgram->bind();
_occlusionProgram->setUniformValue("depthTexture", 0);
_occlusionProgram->setUniformValue("rotationTexture", 1);
_occlusionProgram->setUniformValueArray("sampleKernel", sampleKernel, SAMPLE_KERNEL_SIZE);
_occlusionProgram->setUniformValue("radius", 0.1f);
_occlusionProgram->release();
_nearLocation = _occlusionProgram->uniformLocation("near");
_farLocation = _occlusionProgram->uniformLocation("far");
_leftBottomLocation = _occlusionProgram->uniformLocation("leftBottom");
_rightTopLocation = _occlusionProgram->uniformLocation("rightTop");
_noiseScaleLocation = _occlusionProgram->uniformLocation("noiseScale");
_texCoordOffsetLocation = _occlusionProgram->uniformLocation("texCoordOffset");
_texCoordScaleLocation = _occlusionProgram->uniformLocation("texCoordScale");
glUseProgram(gpu::GLBackend::getShaderID(_occlusionProgram));
glUniform1i(_occlusionProgram->getUniforms().findLocation("depthTexture"), 0);
glUniform1i(_occlusionProgram->getUniforms().findLocation("rotationTexture"), 1);
glUniform1f(_occlusionProgram->getUniforms().findLocation("radius"), 0.1f);
//_occlusionProgram->setUniformValueArray("sampleKernel", sampleKernel, SAMPLE_KERNEL_SIZE);
glUseProgram(0);
_nearLocation = _occlusionProgram->getUniforms().findLocation("near");
_farLocation = _occlusionProgram->getUniforms().findLocation("far");
_leftBottomLocation = _occlusionProgram->getUniforms().findLocation("leftBottom");
_rightTopLocation = _occlusionProgram->getUniforms().findLocation("rightTop");
_noiseScaleLocation = _occlusionProgram->getUniforms().findLocation("noiseScale");
_texCoordOffsetLocation = _occlusionProgram->getUniforms().findLocation("texCoordOffset");
_texCoordScaleLocation = _occlusionProgram->getUniforms().findLocation("texCoordScale");
// generate the random rotation texture
glGenTextures(1, &_rotationTextureID);
@ -82,20 +97,29 @@ void AmbientOcclusionEffect::init(AbstractViewStateInterface* viewState) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glBindTexture(GL_TEXTURE_2D, 0);
_blurProgram = new ProgramObject();
_blurProgram->addShaderFromSourceFile(QGLShader::Vertex, PathUtils::resourcesPath() + "shaders/ambient_occlusion.vert");
_blurProgram->addShaderFromSourceFile(QGLShader::Fragment, PathUtils::resourcesPath() + "shaders/occlusion_blur.frag");
_blurProgram->link();
_blurProgram->bind();
_blurProgram->setUniformValue("originalTexture", 0);
_blurProgram->release();
_blurScaleLocation = _blurProgram->uniformLocation("blurScale");
{
gpu::Shader::Source vertexSource = std::string(readFile(PathUtils::resourcesPath()
+ "shaders/ambient_occlusion.vert").toLocal8Bit().data());
gpu::Shader::Source fragmentSource = std::string(readFile(PathUtils::resourcesPath()
+ "shaders/occlusion_blur.frag").toLocal8Bit().data());
auto vs = gpu::ShaderPointer(gpu::Shader::createVertex(vertexSource));
auto fs = gpu::ShaderPointer(gpu::Shader::createPixel(fragmentSource));
_blurProgram = gpu::ShaderPointer(gpu::Shader::createProgram(vs, fs));
}
glUseProgram(gpu::GLBackend::getShaderID(_blurProgram));
foreach(auto uniform, _blurProgram->getUniforms()) {
qDebug() << uniform._location;
}
glUniform1f(_blurProgram->getUniforms().findLocation("originalTexture"), 0);
glUseProgram(0);
_blurScaleLocation = _blurProgram->getUniforms().findLocation("blurScale");
#endif
}
void AmbientOcclusionEffect::render() {
#if 0
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glDepthMask(GL_FALSE);
@ -122,19 +146,19 @@ void AmbientOcclusionEffect::render() {
float sMin = viewport[VIEWPORT_X_INDEX] / (float)framebufferSize.width();
float sWidth = viewport[VIEWPORT_WIDTH_INDEX] / (float)framebufferSize.width();
_occlusionProgram->bind();
_occlusionProgram->setUniformValue(_nearLocation, nearVal);
_occlusionProgram->setUniformValue(_farLocation, farVal);
_occlusionProgram->setUniformValue(_leftBottomLocation, left, bottom);
_occlusionProgram->setUniformValue(_rightTopLocation, right, top);
_occlusionProgram->setUniformValue(_noiseScaleLocation, viewport[VIEWPORT_WIDTH_INDEX] / (float)ROTATION_WIDTH,
glUseProgram(gpu::GLBackend::getShaderID(_occlusionProgram));
glUniform1f(_nearLocation, nearVal);
glUniform1f(_farLocation, farVal);
glUniform2f(_leftBottomLocation, left, bottom);
glUniform2f(_rightTopLocation, right, top);
glUniform2f(_noiseScaleLocation, viewport[VIEWPORT_WIDTH_INDEX] / (float)ROTATION_WIDTH,
framebufferSize.height() / (float)ROTATION_HEIGHT);
_occlusionProgram->setUniformValue(_texCoordOffsetLocation, sMin, 0.0f);
_occlusionProgram->setUniformValue(_texCoordScaleLocation, sWidth, 1.0f);
glUniform2f(_texCoordOffsetLocation, sMin, 0.0f);
glUniform2f(_texCoordScaleLocation, sWidth, 1.0f);
renderFullscreenQuad();
_occlusionProgram->release();
glUseProgram(0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
@ -152,16 +176,17 @@ void AmbientOcclusionEffect::render() {
auto freeFramebufferTexture = nullptr; // freeFramebuffer->getRenderBuffer(0); // FIXME
glBindTexture(GL_TEXTURE_2D, gpu::GLBackend::getTextureID(freeFramebufferTexture));
_blurProgram->bind();
_blurProgram->setUniformValue(_blurScaleLocation, 1.0f / framebufferSize.width(), 1.0f / framebufferSize.height());
glUseProgram(gpu::GLBackend::getShaderID(_occlusionProgram));
glUniform2f(_blurScaleLocation, 1.0f / framebufferSize.width(), 1.0f / framebufferSize.height());
renderFullscreenQuad(sMin, sMin + sWidth);
_blurProgram->release();
glUseProgram(0);
glBindTexture(GL_TEXTURE_2D, 0);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_CONSTANT_ALPHA, GL_ONE);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
#endif
}

View file

@ -12,10 +12,11 @@
#ifndef hifi_AmbientOcclusionEffect_h
#define hifi_AmbientOcclusionEffect_h
#include <stdint.h>
#include <DependencyManager.h>
#include <gpu/Shader.h>
class AbstractViewStateInterface;
class ProgramObject;
/// A screen space ambient occlusion effect. See John Chapman's tutorial at
/// http://john-chapman-graphics.blogspot.co.uk/2013/01/ssao-tutorial.html for reference.
@ -31,7 +32,7 @@ private:
AmbientOcclusionEffect() {}
virtual ~AmbientOcclusionEffect() {}
ProgramObject* _occlusionProgram;
gpu::ShaderPointer _occlusionProgram;
int _nearLocation;
int _farLocation;
int _leftBottomLocation;
@ -40,10 +41,10 @@ private:
int _texCoordOffsetLocation;
int _texCoordScaleLocation;
ProgramObject* _blurProgram;
gpu::ShaderPointer _blurProgram;
int _blurScaleLocation;
GLuint _rotationTextureID;
uint32_t _rotationTextureID;
AbstractViewStateInterface* _viewState;
};

View file

@ -9,21 +9,21 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <gpu/GPUConfig.h>
#include "DeferredLightingEffect.h"
#include <GLMHelpers.h>
#include <gpu/GPUConfig.h>
#include <gpu/Batch.h>
#include <gpu/Context.h>
#include <gpu/StandardShaderLib.h>
#include <PathUtils.h>
#include <ViewFrustum.h>
#include "AbstractViewStateInterface.h"
#include "DeferredLightingEffect.h"
#include "GeometryCache.h"
#include "RenderUtil.h"
#include "TextureCache.h"
#include "gpu/Batch.h"
#include "gpu/Context.h"
#include "gpu/StandardShaderLib.h"
#include "simple_vert.h"
#include "simple_textured_frag.h"

Some files were not shown because too many files have changed in this diff Show more