Removing GL headers from most files, and some naked GL from application.cpp

This commit is contained in:
Brad Davis 2015-07-18 00:46:09 -07:00
parent 084a098420
commit d68618e206
77 changed files with 396 additions and 1451 deletions

View file

@ -84,7 +84,6 @@
#include <PathUtils.h>
#include <PerfStat.h>
#include <PhysicsEngine.h>
#include <ProgramObject.h>
#include <RenderDeferredTask.h>
#include <ResourceCache.h>
#include <SceneScriptingInterface.h>
@ -100,6 +99,7 @@
#include "Application.h"
#include "AudioClient.h"
#include "DiscoverabilityManager.h"
#include "GLCanvas.h"
#include "InterfaceVersion.h"
#include "LODManager.h"
#include "Menu.h"
@ -174,8 +174,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 +341,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
@ -976,39 +975,41 @@ 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();
{
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);
// 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);
}
displaySide(&renderArgs, _myCamera);
glPopMatrix();
renderArgs._renderMode = RenderArgs::MIRROR_RENDER_MODE;
if (Menu::getInstance()->isOptionChecked(MenuOption::Mirror)) {
renderRearViewMirror(&renderArgs, _mirrorViewRect);
}
renderArgs._renderMode = RenderArgs::NORMAL_RENDER_MODE;
auto finalFbo = DependencyManager::get<TextureCache>()->getPrimaryFramebuffer();
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);
}
@ -1078,11 +1079,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);
@ -1101,16 +1098,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);
}
void Application::controlledBroadcastToNodes(const QByteArray& packet, const NodeSet& destinationNodeTypes) {
@ -1954,7 +1945,6 @@ void Application::setEnableVRMode(bool enableVRMode) {
OculusManager::connect(_glWidget->context()->contextHandle());
_glWidget->setFocus();
_glWidget->makeCurrent();
glClear(GL_COLOR_BUFFER_BIT);
}
OculusManager::recalibrate();
} else {
@ -2157,12 +2147,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() {
@ -3322,9 +3306,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
@ -3372,7 +3353,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
@ -3416,14 +3397,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());
@ -3432,7 +3405,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);
@ -3442,8 +3415,6 @@ 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");

View file

@ -12,8 +12,6 @@
#ifndef hifi_Application_h
#define hifi_Application_h
#include <gpu/GPUConfig.h>
#include <QApplication>
#include <QHash>
#include <QImage>
@ -47,7 +45,6 @@
#include "DatagramProcessor.h"
#include "Environment.h"
#include "FileLogger.h"
#include "GLCanvas.h"
#include "Menu.h"
#include "PacketHeaders.h"
#include "Physics.h"
@ -84,10 +81,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";
@ -647,7 +644,7 @@ 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

@ -13,37 +13,94 @@
#include <NumericalConstants.h>
#include "InterfaceConfig.h"
#include "starfield/Controller.h"
Stars::Stars() :
_controller(0l), _starsLoaded(false) {
_controller = new starfield::Controller;
Stars::Stars() {
}
Stars::~Stars() {
delete _controller;
}
bool Stars::generate(unsigned numStars, unsigned seed) {
_starsLoaded = _controller->computeStars(numStars, seed);
return _starsLoaded;
void Stars::render(RenderArgs* args, float alpha) {
}
bool Stars::setResolution(unsigned k) {
return _controller->setResolution(k);
/*
static unsigned STARFIELD_NUM_STARS = 50000;
static unsigned STARFIELD_SEED = 1;
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";
}
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);
// 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

@ -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

@ -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>
@ -708,6 +706,9 @@ Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, floa
// Compute pixel alignment offset
float clipToPix = 0.5f * windowSizeY / p1.w; // Got from clip to pixel coordinates
glm::vec4 screenPos = clipToPix * p1; // in pixels coords
// WTF?
#undef round
glm::vec4 screenOffset = (glm::round(screenPos) - screenPos) / clipToPix; // in clip coords
glm::vec3 worldOffset = glm::vec3(screenOffset.x, screenOffset.y, 0.0f) / (float)pixelHeight;

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

@ -30,7 +30,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

@ -26,7 +26,6 @@
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) {

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

@ -103,4 +103,3 @@ void OctreePacketProcessor::processPacket(const SharedNodePointer& sendingNode,
}
}
}

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

@ -11,9 +11,6 @@
#include "InterfaceConfig.h"
#include <QOpenGLFramebufferObject>
#include <QOpenGLTexture>
#include <glm/gtc/type_ptr.hpp>
#include <avatar/AvatarManager.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>

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

@ -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,6 +9,7 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "Batch.h"
#include "GPUConfig.h"
#include <QDebug>
@ -254,6 +255,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);

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),

View file

@ -394,6 +394,8 @@ protected:
// Output stage
void do_setFramebuffer(Batch& batch, uint32 paramOffset);
void do_blit(Batch& batch, uint32 paramOffset);
struct OutputStageState {

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

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

View file

@ -9,9 +9,6 @@
// 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 <gpu/GLBackend.h>
#include <glm/gtc/random.hpp>

View file

@ -12,6 +12,7 @@
#ifndef hifi_AmbientOcclusionEffect_h
#define hifi_AmbientOcclusionEffect_h
#include <stdint.h>
#include <DependencyManager.h>
class AbstractViewStateInterface;
@ -43,7 +44,7 @@ private:
ProgramObject* _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"

View file

@ -17,8 +17,6 @@
#include <DependencyManager.h>
#include <NumericalConstants.h>
#include "ProgramObject.h"
#include "model/Light.h"
#include "model/Stage.h"
#include "model/Geometry.h"

View file

@ -21,7 +21,6 @@
#include <EnvironmentData.h>
class ViewFrustum;
class ProgramObject;
class Environment {
public:

View file

@ -10,8 +10,6 @@
//
// include this before QOpenGLBuffer, which includes an earlier version of OpenGL
#include <gpu/GPUConfig.h>
#include <cmath>
#include <QNetworkReply>

View file

@ -12,11 +12,7 @@
#ifndef hifi_GeometryCache_h
#define hifi_GeometryCache_h
// include this before QOpenGLBuffer, which includes an earlier version of OpenGL
#include <gpu/GPUConfig.h>
#include <QMap>
#include <QOpenGLBuffer>
#include <DependencyManager.h>
#include <ResourceCache.h>
@ -264,12 +260,7 @@ private:
virtual ~GeometryCache();
typedef QPair<int, int> IntPair;
typedef QPair<GLuint, GLuint> VerticesIndices;
struct BufferDetails {
QOpenGLBuffer buffer;
int vertices;
int vertexSize;
};
typedef QPair<unsigned int, unsigned int> VerticesIndices;
gpu::PipelinePointer _standardDrawPipeline;
QHash<float, gpu::BufferPointer> _cubeVerticies;

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 <QMetaType>
#include <QRunnable>
#include <QThreadPool>

View file

@ -12,8 +12,6 @@
#ifndef hifi_Model_h
#define hifi_Model_h
#include <gpu/GPUConfig.h>
#include <QBitArray>
#include <QObject>
#include <QUrl>
@ -36,7 +34,6 @@
#include "AnimationHandle.h"
#include "GeometryCache.h"
#include "JointState.h"
#include "ProgramObject.h"
#include "TextureCache.h"
class AbstractViewStateInterface;

View file

@ -11,9 +11,12 @@
#include "OffscreenGlCanvas.h"
#include <QOpenGLDebugLogger>
OffscreenGlCanvas::OffscreenGlCanvas() {
#include <QOpenGLDebugLogger>
#include <QOpenGLContext>
#include <QOffscreenSurface>
OffscreenGlCanvas::OffscreenGlCanvas() : _context(new QOpenGLContext), _offscreenSurface(new QOffscreenSurface){
}
OffscreenGlCanvas::~OffscreenGlCanvas() {
@ -24,14 +27,14 @@ OffscreenGlCanvas::~OffscreenGlCanvas() {
_logger = nullptr;
}
#endif
_context.doneCurrent();
_context->doneCurrent();
}
void OffscreenGlCanvas::create(QOpenGLContext* sharedContext) {
if (nullptr != sharedContext) {
sharedContext->doneCurrent();
_context.setFormat(sharedContext->format());
_context.setShareContext(sharedContext);
_context->setFormat(sharedContext->format());
_context->setShareContext(sharedContext);
} else {
QSurfaceFormat format;
format.setDepthBufferSize(16);
@ -42,17 +45,17 @@ void OffscreenGlCanvas::create(QOpenGLContext* sharedContext) {
#ifdef DEBUG
format.setOption(QSurfaceFormat::DebugContext);
#endif
_context.setFormat(format);
_context->setFormat(format);
}
_context.create();
_context->create();
_offscreenSurface.setFormat(_context.format());
_offscreenSurface.create();
_offscreenSurface->setFormat(_context->format());
_offscreenSurface->create();
}
bool OffscreenGlCanvas::makeCurrent() {
bool result = _context.makeCurrent(&_offscreenSurface);
bool result = _context->makeCurrent(_offscreenSurface);
#ifdef DEBUG
if (result && !_logger) {
@ -71,6 +74,6 @@ bool OffscreenGlCanvas::makeCurrent() {
}
void OffscreenGlCanvas::doneCurrent() {
_context.doneCurrent();
_context->doneCurrent();
}

View file

@ -12,9 +12,10 @@
#ifndef hifi_OffscreenGlCanvas_h
#define hifi_OffscreenGlCanvas_h
#include <QOpenGLContext>
#include <QOffscreenSurface>
#include <QObject>
class QOpenGLContext;
class QOffscreenSurface;
class QOpenGLDebugLogger;
class OffscreenGlCanvas : public QObject {
@ -25,12 +26,12 @@ public:
bool makeCurrent();
void doneCurrent();
QOpenGLContext* getContext() {
return &_context;
return _context;
}
protected:
QOpenGLContext _context;
QOffscreenSurface _offscreenSurface;
QOpenGLContext* _context;
QOffscreenSurface* _offscreenSurface;
#ifdef DEBUG
QOpenGLDebugLogger* _logger{ nullptr };
#endif

View file

@ -11,9 +11,31 @@
#include <QOpenGLDebugLogger>
#include <QGLWidget>
#include <QtQml>
#include <QQmlEngine>
#include <QQmlComponent>
#include <QQuickItem>
#include <QQuickWindow>
#include <QQuickRenderControl>
#include "FboCache.h"
#include <PerfStat.h>
class QMyQuickRenderControl : public QQuickRenderControl {
protected:
QWindow* renderWindow(QPoint* offset) Q_DECL_OVERRIDE{
if (nullptr == _renderWindow) {
return QQuickRenderControl::renderWindow(offset);
}
if (nullptr != offset) {
offset->rx() = offset->ry() = 0;
}
return _renderWindow;
}
private:
QWindow* _renderWindow{ nullptr };
friend class OffscreenQmlSurface;
};
#include "AbstractViewStateInterface.h"
Q_DECLARE_LOGGING_CATEGORY(offscreenFocus)
@ -24,7 +46,8 @@ Q_LOGGING_CATEGORY(offscreenFocus, "hifi.offscreen.focus")
// achieve.
static const int SMALL_INTERVAL = 5;
OffscreenQmlSurface::OffscreenQmlSurface() {
OffscreenQmlSurface::OffscreenQmlSurface() :
_renderControl(new QMyQuickRenderControl), _fboCache(new FboCache) {
}
OffscreenQmlSurface::~OffscreenQmlSurface() {
@ -43,6 +66,7 @@ OffscreenQmlSurface::~OffscreenQmlSurface() {
delete _qmlEngine;
doneCurrent();
delete _fboCache;
}
void OffscreenQmlSurface::create(QOpenGLContext* shareContext) {
@ -87,7 +111,7 @@ void OffscreenQmlSurface::create(QOpenGLContext* shareContext) {
_qmlComponent = new QQmlComponent(_qmlEngine);
// Initialize the render control and our OpenGL resources.
makeCurrent();
_renderControl->initialize(&_context);
_renderControl->initialize(_context);
}
void OffscreenQmlSurface::resize(const QSize& newSize) {
@ -101,14 +125,14 @@ void OffscreenQmlSurface::resize(const QSize& newSize) {
pixelRatio = AbstractViewStateInterface::instance()->getDevicePixelRatio();
}
QSize newOffscreenSize = newSize * pixelRatio;
if (newOffscreenSize == _fboCache.getSize()) {
if (newOffscreenSize == _fboCache->getSize()) {
return;
}
// Clear out any fbos with the old size
makeCurrent();
qDebug() << "Offscreen UI resizing to " << newSize.width() << "x" << newSize.height() << " with pixel ratio " << pixelRatio;
_fboCache.setSize(newSize * pixelRatio);
_fboCache->setSize(newSize * pixelRatio);
if (_quickWindow) {
_quickWindow->setGeometry(QRect(QPoint(), newSize));
@ -233,7 +257,7 @@ void OffscreenQmlSurface::updateQuick() {
_polish = false;
}
QOpenGLFramebufferObject* fbo = _fboCache.getReadyFbo();
QOpenGLFramebufferObject* fbo = _fboCache->getReadyFbo();
_quickWindow->setRenderTarget(fbo);
fbo->bind();
@ -354,11 +378,11 @@ bool OffscreenQmlSurface::eventFilter(QObject* originalDestination, QEvent* even
}
void OffscreenQmlSurface::lockTexture(int texture) {
_fboCache.lockTexture(texture);
_fboCache->lockTexture(texture);
}
void OffscreenQmlSurface::releaseTexture(int texture) {
_fboCache.releaseTexture(texture);
_fboCache->releaseTexture(texture);
}
void OffscreenQmlSurface::pause() {

View file

@ -9,15 +9,8 @@
#ifndef hifi_OffscreenQmlSurface_h
#define hifi_OffscreenQmlSurface_h
#include <QQmlEngine>
#include <QQmlComponent>
#include <QQuickItem>
#include <QQuickWindow>
#include <QQuickRenderControl>
#include <QQuickImageProvider>
#include <QTimer>
#include <QMessageBox>
#include <QUrl>
#include <atomic>
#include <functional>
@ -25,27 +18,19 @@
#include <ThreadHelpers.h>
#include "OffscreenGlCanvas.h"
#include "FboCache.h"
class QWindow;
class QMyQuickRenderControl;
class QQmlEngine;
class QQmlContext;
class QQmlComponent;
class QQuickWindow;
class QQuickItem;
class FboCache;
class OffscreenQmlSurface : public OffscreenGlCanvas {
Q_OBJECT
protected:
class QMyQuickRenderControl : public QQuickRenderControl {
protected:
QWindow* renderWindow(QPoint* offset) Q_DECL_OVERRIDE{
if (nullptr == _renderWindow) {
return QQuickRenderControl::renderWindow(offset);
}
if (nullptr != offset) {
offset->rx() = offset->ry() = 0;
}
return _renderWindow;
}
private:
QWindow* _renderWindow{ nullptr };
friend class OffscreenQmlSurface;
};
public:
OffscreenQmlSurface();
virtual ~OffscreenQmlSurface();
@ -76,7 +61,7 @@ public:
virtual bool eventFilter(QObject* originalDestination, QEvent* event);
signals:
void textureUpdated(GLuint texture);
void textureUpdated(unsigned int texture);
public slots:
void requestUpdate();
@ -95,12 +80,12 @@ protected:
QQuickWindow* _quickWindow{ nullptr };
private:
QMyQuickRenderControl* _renderControl{ new QMyQuickRenderControl };
QMyQuickRenderControl* _renderControl{ nullptr };
QQmlEngine* _qmlEngine{ nullptr };
QQmlComponent* _qmlComponent{ nullptr };
QQuickItem* _rootItem{ nullptr };
QTimer _updateTimer;
FboCache _fboCache;
FboCache* _fboCache;
bool _polish{ true };
bool _paused{ true };
MouseTranslator _mouseTranslator{ [](const QPointF& p) { return p; } };

View file

@ -10,17 +10,18 @@
//
#include "RenderDeferredTask.h"
#include "gpu/Batch.h"
#include "gpu/Context.h"
#include <gpu/GPUConfig.h>
#include <gpu/Batch.h>
#include <gpu/Context.h>
#include <PerfStat.h>
#include <RenderArgs.h>
#include <ViewFrustum.h>
#include "DeferredLightingEffect.h"
#include "ViewFrustum.h"
#include "RenderArgs.h"
#include "TextureCache.h"
#include "render/DrawStatus.h"
#include <PerfStat.h>
#include "overlay3D_vert.h"
#include "overlay3D_frag.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 <DependencyManager.h>
#include "GeometryCache.h"

View file

@ -12,8 +12,6 @@
#include "TextRenderer3D.h"
#include <StreamHelpers.h>
#include <gpu/GPUConfig.h>
#include <gpu/GLBackend.h>
#include <gpu/Shader.h>
#include <QBuffer>

View file

@ -237,18 +237,6 @@ GLuint TextureCache::getPrimaryDepthTextureID() {
return gpu::GLBackend::getTextureID(getPrimaryDepthTexture());
}
GLuint TextureCache::getPrimaryColorTextureID() {
return gpu::GLBackend::getTextureID(getPrimaryColorTexture());
}
GLuint TextureCache::getPrimaryNormalTextureID() {
return gpu::GLBackend::getTextureID(getPrimaryNormalTexture());
}
GLuint TextureCache::getPrimarySpecularTextureID() {
return gpu::GLBackend::getTextureID(getPrimarySpecularTexture());
}
void TextureCache::setPrimaryDrawBuffers(bool color, bool normal, bool specular) {
gpu::Batch batch;
setPrimaryDrawBuffers(batch, color, normal, specular);
@ -284,7 +272,6 @@ gpu::FramebufferPointer TextureCache::getTertiaryFramebuffer() {
return _tertiaryFramebuffer;
}
gpu::FramebufferPointer TextureCache::getShadowFramebuffer() {
if (!_shadowFramebuffer) {
const int SHADOW_MAP_SIZE = 2048;
@ -295,12 +282,6 @@ gpu::FramebufferPointer TextureCache::getShadowFramebuffer() {
return _shadowFramebuffer;
}
GLuint TextureCache::getShadowDepthTextureID() {
// ensure that the shadow framebuffer object is initialized before returning the depth texture id
getShadowFramebuffer();
return gpu::GLBackend::getTextureID(_shadowTexture);
}
/// Returns a texture version of an image file
gpu::TexturePointer TextureCache::getImageTexture(const QString& path) {
QImage image = QImage(path).mirrored(false, true);
@ -331,10 +312,6 @@ Texture::Texture() {
Texture::~Texture() {
}
GLuint Texture::getID() const {
return gpu::GLBackend::getTextureID(_gpuTexture);
}
NetworkTexture::NetworkTexture(const QUrl& url, TextureType type, const QByteArray& content) :
Resource(url, !content.isEmpty()),
_type(type),

View file

@ -12,7 +12,6 @@
#ifndef hifi_TextureCache_h
#define hifi_TextureCache_h
#include <gpu/GPUConfig.h>
#include <gpu/Texture.h>
#include <gpu/Framebuffer.h>
@ -78,14 +77,7 @@ public:
gpu::TexturePointer getPrimarySpecularTexture();
/// Returns the ID of the primary framebuffer object's depth texture. This contains the Z buffer used in rendering.
GLuint getPrimaryDepthTextureID();
GLuint getPrimaryColorTextureID();
/// Returns the ID of the primary framebuffer object's normal texture.
GLuint getPrimaryNormalTextureID();
/// Returns the ID of the primary framebuffer object's specular texture.
GLuint getPrimarySpecularTextureID();
uint32_t getPrimaryDepthTextureID();
/// Enables or disables draw buffers on the primary framebuffer. Note: the primary framebuffer must be bound.
void setPrimaryDrawBuffers(bool color, bool normal = false, bool specular = false);
@ -102,10 +94,6 @@ public:
/// Returns the framebuffer object used to render shadow maps;
gpu::FramebufferPointer getShadowFramebuffer();
/// Returns the ID of the shadow framebuffer object's depth texture.
GLuint getShadowDepthTextureID();
protected:
virtual QSharedPointer<Resource> createResource(const QUrl& url,
@ -149,8 +137,6 @@ public:
Texture();
~Texture();
GLuint getID() const;
const gpu::TexturePointer& getGPUTexture() const { return _gpuTexture; }
protected:

View file

@ -314,7 +314,7 @@ void Font::drawString(gpu::Batch& batch, float x, float y, const QString& str, c
batch.setPipeline(_pipeline);
batch.setResourceTexture(_fontLoc, _texture);
batch._glUniform1i(_outlineLoc, (effectType == OUTLINE_EFFECT));
batch._glUniform4fv(_colorLoc, 1, (const GLfloat*)color);
batch._glUniform4fv(_colorLoc, 1, (const float*)color);
batch.setInputFormat(_format);
batch.setInputBuffer(0, _verticesBuffer, 0, _format->getChannels().at(0)._stride);

View file

@ -9,20 +9,20 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "DrawStatus.h"
#include <algorithm>
#include <assert.h>
#include "DrawStatus.h"
#include <PerfStat.h>
#include "gpu/GPULogging.h"
#include <gpu/Batch.h>
#include <gpu/Context.h>
#include <gpu/GPUConfig.h>
#include <gpu/GPULogging.h>
#include "gpu/Batch.h"
#include "gpu/Context.h"
#include "ViewFrustum.h"
#include "RenderArgs.h"
#include <ViewFrustum.h>
#include <RenderArgs.h>
#include "drawItemBounds_vert.h"
#include "drawItemBounds_frag.h"

View file

@ -9,18 +9,17 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "DrawTask.h"
#include <algorithm>
#include <assert.h>
#include "DrawTask.h"
#include <gpu/Batch.h>
#include <gpu/Context.h>
#include <gpu/GPUConfig.h>
#include <PerfStat.h>
#include "gpu/Batch.h"
#include "gpu/Context.h"
#include "ViewFrustum.h"
#include "RenderArgs.h"
#include <RenderArgs.h>
#include <ViewFrustum.h>
using namespace render;

View file

@ -14,6 +14,7 @@
#include <functional>
#include <memory>
#include "GLMHelpers.h"
class AABox;

View file

@ -54,6 +54,13 @@ inline int c99_snprintf(char* str, size_t size, const char* format, ...) {
#endif // SNPRINTF_FIX
#endif // _MSC_VER
#include <winsock2.h>
#include <WS2tcpip.h>
#else // WIN32
#include <netinet/in.h>
#endif // WIN32
#endif // hifi_windowshacks_h

View file

@ -0,0 +1,82 @@
//
// OffscreenUi.h
// interface/src/entities
//
// Created by Bradley Austin Davis on 2015-07-17
// Copyright 2015 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
//
#pragma once
#ifndef hifi_OffscreenQmlElement_h
#define hifi_OffscreenQmlElement_h
#include <QQuickItem>
class QQmlContext;
#define HIFI_QML_DECL \
private: \
static const QString NAME; \
static const QUrl QML; \
public: \
static void registerType(); \
static void show(std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {}); \
static void toggle(std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {}); \
static void load(std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {}); \
private:
#define HIFI_QML_DECL_LAMBDA \
protected: \
static const QString NAME; \
static const QUrl QML; \
public: \
static void registerType(); \
static void show(); \
static void toggle(); \
static void load(); \
private:
#define HIFI_QML_DEF(x) \
const QUrl x::QML = QUrl(#x ".qml"); \
const QString x::NAME = #x; \
\
void x::registerType() { \
qmlRegisterType<x>("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \
} \
\
void x::show(std::function<void(QQmlContext*, QObject*)> f) { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->show(QML, NAME, f); \
} \
\
void x::toggle(std::function<void(QQmlContext*, QObject*)> f) { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->toggle(QML, NAME, f); \
} \
void x::load(std::function<void(QQmlContext*, QObject*)> f) { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->load(QML, f); \
}
#define HIFI_QML_DEF_LAMBDA(x, f) \
const QUrl x::QML = QUrl(#x ".qml"); \
const QString x::NAME = #x; \
\
void x::registerType() { \
qmlRegisterType<x>("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \
} \
void x::show() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->show(QML, NAME, f); \
} \
void x::toggle() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->toggle(QML, NAME, f); \
} \
void x::load() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->load(QML, f); \
}
#endif

View file

@ -11,12 +11,12 @@
#include "OffscreenUi.h"
#include <QOpenGLFramebufferObject>
#include <QOpenGLDebugLogger>
#include <QQuickWindow>
#include <QGLWidget>
#include <QtQml>
#include "ErrorDialog.h"
#include "MessageDialog.h"
class OffscreenUiRoot : public QQuickItem {
Q_OBJECT
public:

View file

@ -14,72 +14,11 @@
#include "OffscreenQmlSurface.h"
#include <QMessageBox>
#include <DependencyManager.h>
#include "OffscreenQmlElement.h"
#define HIFI_QML_DECL \
private: \
static const QString NAME; \
static const QUrl QML; \
public: \
static void registerType(); \
static void show(std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {}); \
static void toggle(std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {}); \
static void load(std::function<void(QQmlContext*, QObject*)> f = [](QQmlContext*, QObject*) {}); \
private:
#define HIFI_QML_DECL_LAMBDA \
protected: \
static const QString NAME; \
static const QUrl QML; \
public: \
static void registerType(); \
static void show(); \
static void toggle(); \
static void load(); \
private:
#define HIFI_QML_DEF(x) \
const QUrl x::QML = QUrl(#x ".qml"); \
const QString x::NAME = #x; \
\
void x::registerType() { \
qmlRegisterType<x>("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \
} \
\
void x::show(std::function<void(QQmlContext*, QObject*)> f) { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->show(QML, NAME, f); \
} \
\
void x::toggle(std::function<void(QQmlContext*, QObject*)> f) { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->toggle(QML, NAME, f); \
} \
void x::load(std::function<void(QQmlContext*, QObject*)> f) { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->load(QML, f); \
}
#define HIFI_QML_DEF_LAMBDA(x, f) \
const QUrl x::QML = QUrl(#x ".qml"); \
const QString x::NAME = #x; \
\
void x::registerType() { \
qmlRegisterType<x>("Hifi", 1, 0, NAME.toLocal8Bit().constData()); \
} \
void x::show() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->show(QML, NAME, f); \
} \
void x::toggle() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->toggle(QML, NAME, f); \
} \
void x::load() { \
auto offscreenUi = DependencyManager::get<OffscreenUi>(); \
offscreenUi->load(QML, f); \
}
class OffscreenUi : public OffscreenQmlSurface, public Dependency {
Q_OBJECT