mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 10:47:11 +02:00
Merge pull request #322 from ey6es/master
Fix for glut reinitialization warning, Linux build fix, migrated to Qt shader classes.
This commit is contained in:
commit
ed3a94d3fc
12 changed files with 69 additions and 281 deletions
|
@ -6,6 +6,7 @@
|
||||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
//
|
//
|
||||||
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
||||||
//
|
//
|
||||||
|
@ -30,8 +32,6 @@
|
||||||
// Copyright (c) 2004 Sean O'Neil
|
// Copyright (c) 2004 Sean O'Neil
|
||||||
//
|
//
|
||||||
|
|
||||||
#version 120
|
|
||||||
|
|
||||||
uniform vec3 v3LightPos;
|
uniform vec3 v3LightPos;
|
||||||
uniform float g;
|
uniform float g;
|
||||||
uniform float g2;
|
uniform float g2;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
//
|
//
|
||||||
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
||||||
//
|
//
|
||||||
|
@ -30,8 +32,6 @@
|
||||||
// Copyright (c) 2004 Sean O'Neil
|
// Copyright (c) 2004 Sean O'Neil
|
||||||
//
|
//
|
||||||
|
|
||||||
#version 120
|
|
||||||
|
|
||||||
uniform vec3 v3CameraPos; // The camera's current position
|
uniform vec3 v3CameraPos; // The camera's current position
|
||||||
uniform vec3 v3LightPos; // The direction vector to the light source
|
uniform vec3 v3LightPos; // The direction vector to the light source
|
||||||
uniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels
|
uniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
//
|
//
|
||||||
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
||||||
//
|
//
|
||||||
|
@ -30,8 +32,6 @@
|
||||||
// Copyright (c) 2004 Sean O'Neil
|
// Copyright (c) 2004 Sean O'Neil
|
||||||
//
|
//
|
||||||
|
|
||||||
#version 120
|
|
||||||
|
|
||||||
uniform vec3 v3LightPos;
|
uniform vec3 v3LightPos;
|
||||||
uniform float g;
|
uniform float g;
|
||||||
uniform float g2;
|
uniform float g2;
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#version 120
|
||||||
|
|
||||||
//
|
//
|
||||||
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
// For licensing information, see http://http.developer.nvidia.com/GPUGems/gpugems_app01.html:
|
||||||
//
|
//
|
||||||
|
@ -30,8 +32,6 @@
|
||||||
// Copyright (c) 2004 Sean O'Neil
|
// Copyright (c) 2004 Sean O'Neil
|
||||||
//
|
//
|
||||||
|
|
||||||
#version 120
|
|
||||||
|
|
||||||
uniform vec3 v3CameraPos; // The camera's current position
|
uniform vec3 v3CameraPos; // The camera's current position
|
||||||
uniform vec3 v3LightPos; // The direction vector to the light source
|
uniform vec3 v3LightPos; // The direction vector to the light source
|
||||||
uniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels
|
uniform vec3 v3InvWavelength; // 1 / pow(wavelength, 4) for the red, green, and blue channels
|
||||||
|
|
|
@ -230,8 +230,11 @@ Application::Application(int& argc, char** argv) :
|
||||||
void Application::initializeGL() {
|
void Application::initializeGL() {
|
||||||
printLog( "Created Display Window.\n" );
|
printLog( "Created Display Window.\n" );
|
||||||
|
|
||||||
|
// initialize glut for shape drawing; Qt apparently initializes it on OS X
|
||||||
|
#ifndef __APPLE__
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
glutInit(&argc, 0);
|
glutInit(&argc, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
glewInit();
|
glewInit();
|
||||||
|
@ -1496,15 +1499,15 @@ void Application::displayOculus(Camera& whichCamera) {
|
||||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
_oculusProgram = new ProgramObject();
|
_oculusProgram = new ProgramObject();
|
||||||
_oculusProgram->attachFromSourceCode(GL_FRAGMENT_SHADER_ARB, DISTORTION_FRAGMENT_SHADER);
|
_oculusProgram->addShaderFromSourceCode(QGLShader::Fragment, DISTORTION_FRAGMENT_SHADER);
|
||||||
_oculusProgram->link();
|
_oculusProgram->link();
|
||||||
|
|
||||||
_textureLocation = _oculusProgram->getUniformLocation("texture");
|
_textureLocation = _oculusProgram->uniformLocation("texture");
|
||||||
_lensCenterLocation = _oculusProgram->getUniformLocation("lensCenter");
|
_lensCenterLocation = _oculusProgram->uniformLocation("lensCenter");
|
||||||
_screenCenterLocation = _oculusProgram->getUniformLocation("screenCenter");
|
_screenCenterLocation = _oculusProgram->uniformLocation("screenCenter");
|
||||||
_scaleLocation = _oculusProgram->getUniformLocation("scale");
|
_scaleLocation = _oculusProgram->uniformLocation("scale");
|
||||||
_scaleInLocation = _oculusProgram->getUniformLocation("scaleIn");
|
_scaleInLocation = _oculusProgram->uniformLocation("scaleIn");
|
||||||
_hmdWarpParamLocation = _oculusProgram->getUniformLocation("hmdWarpParam");
|
_hmdWarpParamLocation = _oculusProgram->uniformLocation("hmdWarpParam");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
glBindTexture(GL_TEXTURE_2D, _oculusTextureID);
|
glBindTexture(GL_TEXTURE_2D, _oculusTextureID);
|
||||||
|
@ -1525,12 +1528,12 @@ void Application::displayOculus(Camera& whichCamera) {
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
_oculusProgram->bind();
|
_oculusProgram->bind();
|
||||||
_oculusProgram->setUniform(_textureLocation, 0);
|
_oculusProgram->setUniformValue(_textureLocation, 0);
|
||||||
_oculusProgram->setUniform(_lensCenterLocation, 0.287994, 0.5); // see SDK docs, p. 29
|
_oculusProgram->setUniformValue(_lensCenterLocation, 0.287994, 0.5); // see SDK docs, p. 29
|
||||||
_oculusProgram->setUniform(_screenCenterLocation, 0.25, 0.5);
|
_oculusProgram->setUniformValue(_screenCenterLocation, 0.25, 0.5);
|
||||||
_oculusProgram->setUniform(_scaleLocation, 0.25 * scaleFactor, 0.5 * scaleFactor * aspectRatio);
|
_oculusProgram->setUniformValue(_scaleLocation, 0.25 * scaleFactor, 0.5 * scaleFactor * aspectRatio);
|
||||||
_oculusProgram->setUniform(_scaleInLocation, 4, 2 / aspectRatio);
|
_oculusProgram->setUniformValue(_scaleInLocation, 4, 2 / aspectRatio);
|
||||||
_oculusProgram->setUniform(_hmdWarpParamLocation, 1.0, 0.22, 0.24, 0);
|
_oculusProgram->setUniformValue(_hmdWarpParamLocation, 1.0, 0.22, 0.24, 0);
|
||||||
|
|
||||||
glColor3f(1, 0, 1);
|
glColor3f(1, 0, 1);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
|
@ -1544,8 +1547,8 @@ void Application::displayOculus(Camera& whichCamera) {
|
||||||
glVertex2f(0, _glWidget->height());
|
glVertex2f(0, _glWidget->height());
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
_oculusProgram->setUniform(_lensCenterLocation, 0.787994, 0.5);
|
_oculusProgram->setUniformValue(_lensCenterLocation, 0.787994, 0.5);
|
||||||
_oculusProgram->setUniform(_screenCenterLocation, 0.75, 0.5);
|
_oculusProgram->setUniformValue(_screenCenterLocation, 0.75, 0.5);
|
||||||
|
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glTexCoord2f(0.5, 0);
|
glTexCoord2f(0.5, 0);
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "Camera.h"
|
#include "Camera.h"
|
||||||
#include "Environment.h"
|
#include "Environment.h"
|
||||||
#include "renderer/ProgramObject.h"
|
#include "renderer/ProgramObject.h"
|
||||||
#include "renderer/ShaderObject.h"
|
|
||||||
#include "world.h"
|
#include "world.h"
|
||||||
|
|
||||||
void Environment::init() {
|
void Environment::init() {
|
||||||
|
@ -57,24 +56,24 @@ void Environment::renderAtmosphere(Camera& camera) {
|
||||||
program->setUniform(locations[CAMERA_POS_LOCATION], relativeCameraPos);
|
program->setUniform(locations[CAMERA_POS_LOCATION], relativeCameraPos);
|
||||||
glm::vec3 lightDirection = glm::normalize(getSunLocation());
|
glm::vec3 lightDirection = glm::normalize(getSunLocation());
|
||||||
program->setUniform(locations[LIGHT_POS_LOCATION], lightDirection);
|
program->setUniform(locations[LIGHT_POS_LOCATION], lightDirection);
|
||||||
program->setUniform(locations[INV_WAVELENGTH_LOCATION],
|
program->setUniformValue(locations[INV_WAVELENGTH_LOCATION],
|
||||||
1 / powf(getScatteringWavelengths().r, 4.0f),
|
1 / powf(getScatteringWavelengths().r, 4.0f),
|
||||||
1 / powf(getScatteringWavelengths().g, 4.0f),
|
1 / powf(getScatteringWavelengths().g, 4.0f),
|
||||||
1 / powf(getScatteringWavelengths().b, 4.0f));
|
1 / powf(getScatteringWavelengths().b, 4.0f));
|
||||||
program->setUniform(locations[CAMERA_HEIGHT2_LOCATION], height * height);
|
program->setUniformValue(locations[CAMERA_HEIGHT2_LOCATION], height * height);
|
||||||
program->setUniform(locations[OUTER_RADIUS_LOCATION], getAtmosphereOuterRadius());
|
program->setUniformValue(locations[OUTER_RADIUS_LOCATION], getAtmosphereOuterRadius());
|
||||||
program->setUniform(locations[OUTER_RADIUS2_LOCATION], getAtmosphereOuterRadius() * getAtmosphereOuterRadius());
|
program->setUniformValue(locations[OUTER_RADIUS2_LOCATION], getAtmosphereOuterRadius() * getAtmosphereOuterRadius());
|
||||||
program->setUniform(locations[INNER_RADIUS_LOCATION], getAtmosphereInnerRadius());
|
program->setUniformValue(locations[INNER_RADIUS_LOCATION], getAtmosphereInnerRadius());
|
||||||
program->setUniform(locations[KR_ESUN_LOCATION], getRayleighScattering() * getSunBrightness());
|
program->setUniformValue(locations[KR_ESUN_LOCATION], getRayleighScattering() * getSunBrightness());
|
||||||
program->setUniform(locations[KM_ESUN_LOCATION], getMieScattering() * getSunBrightness());
|
program->setUniformValue(locations[KM_ESUN_LOCATION], getMieScattering() * getSunBrightness());
|
||||||
program->setUniform(locations[KR_4PI_LOCATION], getRayleighScattering() * 4.0f * PIf);
|
program->setUniformValue(locations[KR_4PI_LOCATION], getRayleighScattering() * 4.0f * PIf);
|
||||||
program->setUniform(locations[KM_4PI_LOCATION], getMieScattering() * 4.0f * PIf);
|
program->setUniformValue(locations[KM_4PI_LOCATION], getMieScattering() * 4.0f * PIf);
|
||||||
program->setUniform(locations[SCALE_LOCATION], 1.0f / (getAtmosphereOuterRadius() - getAtmosphereInnerRadius()));
|
program->setUniformValue(locations[SCALE_LOCATION], 1.0f / (getAtmosphereOuterRadius() - getAtmosphereInnerRadius()));
|
||||||
program->setUniform(locations[SCALE_DEPTH_LOCATION], 0.25f);
|
program->setUniformValue(locations[SCALE_DEPTH_LOCATION], 0.25f);
|
||||||
program->setUniform(locations[SCALE_OVER_SCALE_DEPTH_LOCATION],
|
program->setUniformValue(locations[SCALE_OVER_SCALE_DEPTH_LOCATION],
|
||||||
(1.0f / (getAtmosphereOuterRadius() - getAtmosphereInnerRadius())) / 0.25f);
|
(1.0f / (getAtmosphereOuterRadius() - getAtmosphereInnerRadius())) / 0.25f);
|
||||||
program->setUniform(locations[G_LOCATION], -0.990f);
|
program->setUniformValue(locations[G_LOCATION], -0.990f);
|
||||||
program->setUniform(locations[G2_LOCATION], -0.990f * -0.990f);
|
program->setUniformValue(locations[G2_LOCATION], -0.990f * -0.990f);
|
||||||
|
|
||||||
glDepthMask(GL_FALSE);
|
glDepthMask(GL_FALSE);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
@ -92,26 +91,26 @@ void Environment::renderAtmosphere(Camera& camera) {
|
||||||
ProgramObject* Environment::createSkyProgram(const char* from, int* locations) {
|
ProgramObject* Environment::createSkyProgram(const char* from, int* locations) {
|
||||||
ProgramObject* program = new ProgramObject();
|
ProgramObject* program = new ProgramObject();
|
||||||
QByteArray prefix = QByteArray("resources/shaders/SkyFrom") + from;
|
QByteArray prefix = QByteArray("resources/shaders/SkyFrom") + from;
|
||||||
program->attachFromSourceFile(GL_VERTEX_SHADER_ARB, prefix + ".vert");
|
program->addShaderFromSourceFile(QGLShader::Vertex, prefix + ".vert");
|
||||||
program->attachFromSourceFile(GL_FRAGMENT_SHADER_ARB, prefix + ".frag");
|
program->addShaderFromSourceFile(QGLShader::Fragment, prefix + ".frag");
|
||||||
program->link();
|
program->link();
|
||||||
|
|
||||||
locations[CAMERA_POS_LOCATION] = program->getUniformLocation("v3CameraPos");
|
locations[CAMERA_POS_LOCATION] = program->uniformLocation("v3CameraPos");
|
||||||
locations[LIGHT_POS_LOCATION] = program->getUniformLocation("v3LightPos");
|
locations[LIGHT_POS_LOCATION] = program->uniformLocation("v3LightPos");
|
||||||
locations[INV_WAVELENGTH_LOCATION] = program->getUniformLocation("v3InvWavelength");
|
locations[INV_WAVELENGTH_LOCATION] = program->uniformLocation("v3InvWavelength");
|
||||||
locations[CAMERA_HEIGHT2_LOCATION] = program->getUniformLocation("fCameraHeight2");
|
locations[CAMERA_HEIGHT2_LOCATION] = program->uniformLocation("fCameraHeight2");
|
||||||
locations[OUTER_RADIUS_LOCATION] = program->getUniformLocation("fOuterRadius");
|
locations[OUTER_RADIUS_LOCATION] = program->uniformLocation("fOuterRadius");
|
||||||
locations[OUTER_RADIUS2_LOCATION] = program->getUniformLocation("fOuterRadius2");
|
locations[OUTER_RADIUS2_LOCATION] = program->uniformLocation("fOuterRadius2");
|
||||||
locations[INNER_RADIUS_LOCATION] = program->getUniformLocation("fInnerRadius");
|
locations[INNER_RADIUS_LOCATION] = program->uniformLocation("fInnerRadius");
|
||||||
locations[KR_ESUN_LOCATION] = program->getUniformLocation("fKrESun");
|
locations[KR_ESUN_LOCATION] = program->uniformLocation("fKrESun");
|
||||||
locations[KM_ESUN_LOCATION] = program->getUniformLocation("fKmESun");
|
locations[KM_ESUN_LOCATION] = program->uniformLocation("fKmESun");
|
||||||
locations[KR_4PI_LOCATION] = program->getUniformLocation("fKr4PI");
|
locations[KR_4PI_LOCATION] = program->uniformLocation("fKr4PI");
|
||||||
locations[KM_4PI_LOCATION] = program->getUniformLocation("fKm4PI");
|
locations[KM_4PI_LOCATION] = program->uniformLocation("fKm4PI");
|
||||||
locations[SCALE_LOCATION] = program->getUniformLocation("fScale");
|
locations[SCALE_LOCATION] = program->uniformLocation("fScale");
|
||||||
locations[SCALE_DEPTH_LOCATION] = program->getUniformLocation("fScaleDepth");
|
locations[SCALE_DEPTH_LOCATION] = program->uniformLocation("fScaleDepth");
|
||||||
locations[SCALE_OVER_SCALE_DEPTH_LOCATION] = program->getUniformLocation("fScaleOverScaleDepth");
|
locations[SCALE_OVER_SCALE_DEPTH_LOCATION] = program->uniformLocation("fScaleOverScaleDepth");
|
||||||
locations[G_LOCATION] = program->getUniformLocation("g");
|
locations[G_LOCATION] = program->uniformLocation("g");
|
||||||
locations[G2_LOCATION] = program->getUniformLocation("g2");
|
locations[G2_LOCATION] = program->uniformLocation("g2");
|
||||||
|
|
||||||
return program;
|
return program;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,114 +6,15 @@
|
||||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
||||||
|
|
||||||
#include "ProgramObject.h"
|
#include "ProgramObject.h"
|
||||||
#include "ShaderObject.h"
|
|
||||||
|
|
||||||
ProgramObject::ProgramObject() : _handle(glCreateProgramObjectARB()) {
|
ProgramObject::ProgramObject(QObject* parent) : QGLShaderProgram(parent) {
|
||||||
}
|
|
||||||
|
|
||||||
ProgramObject::~ProgramObject() {
|
|
||||||
glDeleteObjectARB(_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgramObject::attach(ShaderObject* shader) {
|
|
||||||
glAttachObjectARB(_handle, shader->getHandle());
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ProgramObject::attachFromSourceCode(int type, const char* source) {
|
|
||||||
ShaderObject* shader = new ShaderObject(type);
|
|
||||||
if (shader->compileSourceCode(source)) {
|
|
||||||
attach(shader);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
delete shader;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ProgramObject::attachFromSourceFile(int type, const char* filename) {
|
|
||||||
ShaderObject* shader = new ShaderObject(type);
|
|
||||||
if (shader->compileSourceFile(filename)) {
|
|
||||||
attach(shader);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
delete shader;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ProgramObject::link() {
|
|
||||||
glLinkProgramARB(_handle);
|
|
||||||
int status;
|
|
||||||
glGetObjectParameterivARB(_handle, GL_OBJECT_LINK_STATUS_ARB, &status);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray ProgramObject::getLog() const {
|
|
||||||
int length;
|
|
||||||
glGetObjectParameterivARB(_handle, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
|
|
||||||
QByteArray log(length, 0);
|
|
||||||
glGetInfoLogARB(_handle, length, 0, log.data());
|
|
||||||
return log;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgramObject::bind() const {
|
|
||||||
glUseProgramObjectARB(_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgramObject::release() const {
|
|
||||||
glUseProgramObjectARB(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int ProgramObject::getUniformLocation(const char* name) const {
|
|
||||||
return glGetUniformLocationARB(_handle, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgramObject::setUniform(int location, int value) {
|
|
||||||
glUniform1iARB(location, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgramObject::setUniform(const char* name, int value) {
|
|
||||||
setUniform(getUniformLocation(name), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgramObject::setUniform(int location, float value) {
|
|
||||||
glUniform1fARB(location, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgramObject::setUniform(const char* name, float value) {
|
|
||||||
setUniform(getUniformLocation(name), value);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgramObject::setUniform(int location, float x, float y) {
|
|
||||||
glUniform2fARB(location, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgramObject::setUniform(const char* name, float x, float y) {
|
|
||||||
setUniform(getUniformLocation(name), x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramObject::setUniform(int location, const glm::vec3& value) {
|
void ProgramObject::setUniform(int location, const glm::vec3& value) {
|
||||||
glUniform3fARB(location, value.x, value.y, value.z);
|
setUniformValue(location, value.x, value.y, value.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramObject::setUniform(const char* name, const glm::vec3& value) {
|
void ProgramObject::setUniform(const char* name, const glm::vec3& value) {
|
||||||
setUniform(getUniformLocation(name), value);
|
setUniformValue(name, value.x, value.y, value.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgramObject::setUniform(int location, float x, float y, float z) {
|
|
||||||
glUniform3fARB(location, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgramObject::setUniform(const char* name, float x, float y, float z) {
|
|
||||||
setUniform(getUniformLocation(name), x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgramObject::setUniform(int location, float x, float y, float z, float w) {
|
|
||||||
glUniform4fARB(location, x, y, z, w);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ProgramObject::setUniform(const char* name, float x, float y, float z, float w) {
|
|
||||||
setUniform(getUniformLocation(name), x, y, z, w);
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,58 +9,17 @@
|
||||||
#ifndef __interface__ProgramObject__
|
#ifndef __interface__ProgramObject__
|
||||||
#define __interface__ProgramObject__
|
#define __interface__ProgramObject__
|
||||||
|
|
||||||
#include <QObject>
|
#include <QGLShaderProgram>
|
||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "InterfaceConfig.h"
|
class ProgramObject : public QGLShaderProgram {
|
||||||
|
|
||||||
class ShaderObject;
|
|
||||||
|
|
||||||
class ProgramObject {
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ProgramObject();
|
ProgramObject(QObject* parent = 0);
|
||||||
~ProgramObject();
|
|
||||||
|
|
||||||
GLhandleARB getHandle() const { return _handle; }
|
|
||||||
|
|
||||||
void attach(ShaderObject* shader);
|
|
||||||
bool attachFromSourceCode(int type, const char* source);
|
|
||||||
bool attachFromSourceFile(int type, const char* filename);
|
|
||||||
|
|
||||||
bool link();
|
|
||||||
|
|
||||||
QByteArray getLog() const;
|
|
||||||
|
|
||||||
void bind() const;
|
|
||||||
void release() const;
|
|
||||||
|
|
||||||
int getUniformLocation(const char* name) const;
|
|
||||||
|
|
||||||
void setUniform(int location, int value);
|
|
||||||
void setUniform(const char* name, int value);
|
|
||||||
|
|
||||||
void setUniform(int location, float value);
|
|
||||||
void setUniform(const char* name, float value);
|
|
||||||
|
|
||||||
void setUniform(int location, float x, float y);
|
|
||||||
void setUniform(const char* name, float x, float y);
|
|
||||||
|
|
||||||
void setUniform(int location, const glm::vec3& value);
|
void setUniform(int location, const glm::vec3& value);
|
||||||
void setUniform(const char* name, const glm::vec3& value);
|
void setUniform(const char* name, const glm::vec3& value);
|
||||||
|
|
||||||
void setUniform(int location, float x, float y, float z);
|
|
||||||
void setUniform(const char* name, float x, float y, float z);
|
|
||||||
|
|
||||||
void setUniform(int location, float x, float y, float z, float w);
|
|
||||||
void setUniform(const char* name, float x, float y, float z, float w);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Q_DISABLE_COPY(ProgramObject)
|
|
||||||
|
|
||||||
GLhandleARB _handle;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__interface__ProgramObject__) */
|
#endif /* defined(__interface__ProgramObject__) */
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
//
|
|
||||||
// ShaderObject.cpp
|
|
||||||
// interface
|
|
||||||
//
|
|
||||||
// Created by Andrzej Kapolka on 5/7/13.
|
|
||||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
|
||||||
|
|
||||||
#include <QFile>
|
|
||||||
|
|
||||||
#include "ShaderObject.h"
|
|
||||||
|
|
||||||
ShaderObject::ShaderObject(int type)
|
|
||||||
: _handle(glCreateShaderObjectARB(type)) {
|
|
||||||
}
|
|
||||||
|
|
||||||
ShaderObject::~ShaderObject() {
|
|
||||||
glDeleteObjectARB(_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ShaderObject::compileSourceCode(const char* data) {
|
|
||||||
glShaderSourceARB(_handle, 1, &data, 0);
|
|
||||||
glCompileShaderARB(_handle);
|
|
||||||
int status;
|
|
||||||
glGetObjectParameterivARB(_handle, GL_OBJECT_COMPILE_STATUS_ARB, &status);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ShaderObject::compileSourceFile(const char* filename) {
|
|
||||||
QFile file(filename);
|
|
||||||
return file.open(QIODevice::ReadOnly) && compileSourceCode(file.readAll().constData());
|
|
||||||
}
|
|
||||||
|
|
||||||
QByteArray ShaderObject::getLog() const {
|
|
||||||
int length;
|
|
||||||
glGetObjectParameterivARB(_handle, GL_OBJECT_INFO_LOG_LENGTH_ARB, &length);
|
|
||||||
QByteArray log(length, 0);
|
|
||||||
glGetInfoLogARB(_handle, length, 0, log.data());
|
|
||||||
return log;
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
//
|
|
||||||
// ShaderObject.h
|
|
||||||
// interface
|
|
||||||
//
|
|
||||||
// Created by Andrzej Kapolka on 5/7/13.
|
|
||||||
// Copyright (c) 2013 High Fidelity, Inc. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef __interface__ShaderObject__
|
|
||||||
#define __interface__ShaderObject__
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
|
|
||||||
#include "InterfaceConfig.h"
|
|
||||||
|
|
||||||
class ShaderObject {
|
|
||||||
public:
|
|
||||||
|
|
||||||
ShaderObject(int type);
|
|
||||||
~ShaderObject();
|
|
||||||
|
|
||||||
GLhandleARB getHandle() const { return _handle; }
|
|
||||||
|
|
||||||
bool compileSourceCode(const char* data);
|
|
||||||
bool compileSourceFile(const char* filename);
|
|
||||||
|
|
||||||
QByteArray getLog() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
Q_DISABLE_COPY(ShaderObject)
|
|
||||||
|
|
||||||
GLhandleARB _handle;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* defined(__interface__ShaderObject__) */
|
|
|
@ -478,15 +478,15 @@ namespace starfield {
|
||||||
" gl_PointSize = s;\n"
|
" gl_PointSize = s;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
|
|
||||||
_objProgram.attachFromSourceCode(GL_VERTEX_SHADER, VERTEX_SHADER);
|
_objProgram.addShaderFromSourceCode(QGLShader::Vertex, VERTEX_SHADER);
|
||||||
GLchar const* const FRAGMENT_SHADER =
|
GLchar const* const FRAGMENT_SHADER =
|
||||||
"#version 120\n"
|
"#version 120\n"
|
||||||
"void main(void) {\n"
|
"void main(void) {\n"
|
||||||
" gl_FragColor = gl_Color;\n"
|
" gl_FragColor = gl_Color;\n"
|
||||||
"}\n";
|
"}\n";
|
||||||
_objProgram.attachFromSourceCode(GL_FRAGMENT_SHADER, FRAGMENT_SHADER);
|
_objProgram.addShaderFromSourceCode(QGLShader::Fragment, FRAGMENT_SHADER);
|
||||||
_objProgram.link();
|
_objProgram.link();
|
||||||
_alphaLocation = _objProgram.getUniformLocation("alpha");
|
_alphaLocation = _objProgram.uniformLocation("alpha");
|
||||||
|
|
||||||
glGenBuffersARB(1, & _hndVertexArray);
|
glGenBuffersARB(1, & _hndVertexArray);
|
||||||
}
|
}
|
||||||
|
@ -534,7 +534,7 @@ namespace starfield {
|
||||||
|
|
||||||
// select shader and vertex array
|
// select shader and vertex array
|
||||||
_objProgram.bind();
|
_objProgram.bind();
|
||||||
_objProgram.setUniform(_alphaLocation, alpha);
|
_objProgram.setUniformValue(_alphaLocation, alpha);
|
||||||
glBindBufferARB(GL_ARRAY_BUFFER, _hndVertexArray);
|
glBindBufferARB(GL_ARRAY_BUFFER, _hndVertexArray);
|
||||||
glInterleavedArrays(GL_C4UB_V3F, sizeof(GpuVertex), 0l);
|
glInterleavedArrays(GL_C4UB_V3F, sizeof(GpuVertex), 0l);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue