mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 11:33:44 +02:00
Clean up on the GPU Profile defines in order to control features
This commit is contained in:
parent
d33d3afb52
commit
03da3aeab4
13 changed files with 64 additions and 131 deletions
|
@ -12,10 +12,16 @@
|
|||
<@def GPU_CONFIG_SLH@>
|
||||
|
||||
<@if GLPROFILE == PC_GL @>
|
||||
<@def GPU_FEATURE_PROFILE Core@>
|
||||
<@def GPU_TRANSFORM_PROFILE Core@>
|
||||
<@def VERSION_HEADER #version 330 compatibility@>
|
||||
<@elif GLPROFILE == MAC_GL @>
|
||||
<@def GPU_FEATURE_PROFILE Legacy@>
|
||||
<@def GPU_TRANSFORM_PROFILE Legacy@>
|
||||
<@def VERSION_HEADER #version 120@>
|
||||
<@else@>
|
||||
<@def GPU_FEATURE_PROFILE Legacy@>
|
||||
<@def GPU_TRANSFORM_PROFILE Legacy@>
|
||||
<@def VERSION_HEADER #version 120@>
|
||||
<@endif@>
|
||||
|
||||
|
|
|
@ -55,19 +55,17 @@ void GLBackend::do_setUniformBuffer(Batch& batch, uint32 paramOffset) {
|
|||
BufferPointer uniformBuffer = batch._buffers.get(batch._params[paramOffset + 2]._uint);
|
||||
GLintptr rangeStart = batch._params[paramOffset + 1]._uint;
|
||||
GLsizeiptr rangeSize = batch._params[paramOffset + 0]._uint;
|
||||
#if defined(Q_OS_MAC)
|
||||
|
||||
#if (GPU_FEATURE_PROFILE == Core)
|
||||
GLuint bo = getBufferID(*uniformBuffer);
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, slot, bo, rangeStart, rangeSize);
|
||||
#else
|
||||
GLfloat* data = (GLfloat*) (uniformBuffer->getData() + rangeStart);
|
||||
glUniform4fv(slot, rangeSize / sizeof(GLfloat[4]), data);
|
||||
|
||||
// NOT working so we ll stick to the uniform float array until we move to core profile
|
||||
// GLuint bo = getBufferID(*uniformBuffer);
|
||||
//glUniformBufferEXT(_shader._program, slot, bo);
|
||||
#elif defined(Q_OS_WIN)
|
||||
GLuint bo = getBufferID(*uniformBuffer);
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, slot, bo, rangeStart, rangeSize);
|
||||
#else
|
||||
GLfloat* data = (GLfloat*) (uniformBuffer->getData() + rangeStart);
|
||||
glUniform4fv(slot, rangeSize / sizeof(GLfloat[4]), data);
|
||||
#endif
|
||||
CHECK_GL_ERROR();
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ void makeBindings(GLBackend::GLShader* shader) {
|
|||
// now assign the ubo binding, then DON't relink!
|
||||
|
||||
//Check for gpu specific uniform slotBindings
|
||||
#if defined(Q_OS_WIN)
|
||||
#if (GPU_TRANSFORM_PROFILE == Core)
|
||||
loc = glGetUniformBlockIndex(glprogram, "transformObjectBuffer");
|
||||
if (loc >= 0) {
|
||||
glUniformBlockBinding(glprogram, loc, gpu::TRANSFORM_OBJECT_SLOT);
|
||||
|
@ -551,7 +551,9 @@ bool isUnusedSlot(GLint binding) {
|
|||
|
||||
int makeUniformBlockSlots(GLuint glprogram, const Shader::BindingSet& slotBindings, Shader::SlotSet& buffers) {
|
||||
GLint buffersCount = 0;
|
||||
#if defined(Q_OS_WIN)
|
||||
|
||||
#if (GPU_FEATURE_PROFILE == Core)
|
||||
|
||||
glGetProgramiv(glprogram, GL_ACTIVE_UNIFORM_BLOCKS, &buffersCount);
|
||||
|
||||
// fast exit
|
||||
|
|
|
@ -32,7 +32,7 @@ void GLBackend::do_setProjectionTransform(Batch& batch, uint32 paramOffset) {
|
|||
}
|
||||
|
||||
void GLBackend::initTransform() {
|
||||
#if defined(Q_OS_WIN)
|
||||
#if (GPU_TRANSFORM_PROFILE == Core)
|
||||
glGenBuffers(1, &_transform._transformObjectBuffer);
|
||||
glGenBuffers(1, &_transform._transformCameraBuffer);
|
||||
|
||||
|
@ -49,7 +49,7 @@ void GLBackend::initTransform() {
|
|||
}
|
||||
|
||||
void GLBackend::killTransform() {
|
||||
#if defined(Q_OS_WIN)
|
||||
#if (GPU_TRANSFORM_PROFILE == Core)
|
||||
glDeleteBuffers(1, &_transform._transformObjectBuffer);
|
||||
glDeleteBuffers(1, &_transform._transformCameraBuffer);
|
||||
#else
|
||||
|
@ -77,34 +77,30 @@ void GLBackend::updateTransform() {
|
|||
_transform._transformCamera._projectionViewUntranslated = _transform._transformCamera._projection * viewUntranslated;
|
||||
}
|
||||
|
||||
#if (GPU_TRANSFORM_PROFILE == Core)
|
||||
if (_transform._invalidView || _transform._invalidProj) {
|
||||
#if defined(Q_OS_WIN)
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, TRANSFORM_CAMERA_SLOT, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _transform._transformCameraBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_transform._transformCamera), (const void*) &_transform._transformCamera, GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
CHECK_GL_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (_transform._invalidModel) {
|
||||
#if defined(Q_OS_WIN)
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, TRANSFORM_OBJECT_SLOT, 0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, _transform._transformObjectBuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(_transform._transformObject), (const void*) &_transform._transformObject, GL_DYNAMIC_DRAW);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
CHECK_GL_ERROR();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, TRANSFORM_OBJECT_SLOT, _transform._transformObjectBuffer);
|
||||
glBindBufferBase(GL_UNIFORM_BUFFER, TRANSFORM_CAMERA_SLOT, _transform._transformCameraBuffer);
|
||||
CHECK_GL_ERROR();
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(Q_OS_MAC) || defined(Q_OS_LINUX)
|
||||
#if (GPU_TRANSFORM_PROFILE == Legacy)
|
||||
// Do it again for fixed pipeline until we can get rid of it
|
||||
if (_transform._invalidProj) {
|
||||
if (_transform._lastMode != GL_PROJECTION) {
|
||||
|
|
|
@ -18,17 +18,25 @@
|
|||
#include <OpenGL/gl.h>
|
||||
#include <OpenGL/glext.h>
|
||||
|
||||
#define GPU_FEATURE_PROFILE Core
|
||||
#define GPU_TRANSFORM_PROFILE Core
|
||||
|
||||
#elif defined(WIN32)
|
||||
#include <windowshacks.h>
|
||||
#include <GL/glew.h>
|
||||
#include <GL/wglew.h>
|
||||
|
||||
#define GPU_FEATURE_PROFILE Legacy
|
||||
#define GPU_TRANSFORM_PROFILE Legacy
|
||||
|
||||
#elif defined(ANDROID)
|
||||
|
||||
#else
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
#define GPU_FEATURE_PROFILE Legacy
|
||||
#define GPU_TRANSFORM_PROFILE Legacy
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -24,9 +24,7 @@ struct TransformCamera {
|
|||
};
|
||||
|
||||
vec4 transformModelToClipPos(TransformCamera camera, TransformObject object, vec4 pos) {
|
||||
<@if GLPROFILE == MAC_GL@>
|
||||
return gl_ModelViewProjectionMatrix * pos;
|
||||
<@elif GLPROFILE == PC_GL@>
|
||||
<@if GPU_TRANSFORM_PROFILE == GPUCore@>
|
||||
vec4 epos = (object._model * pos) + vec4(-pos.w * camera._viewInverse[3].xyz, 0.0);
|
||||
return camera._projectionViewUntranslated * epos;
|
||||
// Equivalent to the following but hoppefully a bit more accurate
|
||||
|
@ -37,9 +35,7 @@ vec4 transformModelToClipPos(TransformCamera camera, TransformObject object, vec
|
|||
}
|
||||
|
||||
vec3 transformModelToEyeDir(TransformCamera camera, TransformObject object, vec3 dir) {
|
||||
<@if GLPROFILE == MAC_GL@>
|
||||
return gl_NormalMatrix * dir;
|
||||
<@elif GLPROFILE == PC_GL@>
|
||||
<@if GPU_TRANSFORM_PROFILE == GPUCore@>
|
||||
vec3 mr0 = vec3(object._modelInverse[0].x, object._modelInverse[1].x, object._modelInverse[2].x);
|
||||
vec3 mr1 = vec3(object._modelInverse[0].y, object._modelInverse[1].y, object._modelInverse[2].y);
|
||||
vec3 mr2 = vec3(object._modelInverse[0].z, object._modelInverse[1].z, object._modelInverse[2].z);
|
||||
|
@ -56,7 +52,7 @@ vec3 transformModelToEyeDir(TransformCamera camera, TransformObject object, vec3
|
|||
<@endif@>
|
||||
}
|
||||
|
||||
<@if GLPROFILE == PC_GL@>
|
||||
<@if GPU_TRANSFORM_PROFILE == GPUCore@>
|
||||
uniform transformObjectBuffer {
|
||||
TransformObject object;
|
||||
};
|
||||
|
@ -70,16 +66,7 @@ uniform transformCameraBuffer {
|
|||
TransformCamera getTransformCamera() {
|
||||
return camera;
|
||||
}
|
||||
<@elif GLPROFILE == MAC_GL@>
|
||||
TransformObject getTransformObject() {
|
||||
TransformObject object;
|
||||
return object;
|
||||
}
|
||||
|
||||
TransformCamera getTransformCamera() {
|
||||
TransformCamera camera;
|
||||
return camera;
|
||||
}
|
||||
<@else@>
|
||||
|
||||
TransformObject getTransformObject() {
|
||||
|
|
|
@ -252,27 +252,18 @@ public:
|
|||
// Schema to access the attribute values of the light
|
||||
class Schema {
|
||||
public:
|
||||
Vec4 _position;
|
||||
Vec3 _direction;
|
||||
float _spare0;
|
||||
Color _color;
|
||||
float _intensity;
|
||||
Vec4 _attenuation;
|
||||
Vec4 _spot;
|
||||
Vec4 _shadow;
|
||||
Vec4 _position = Vec4(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
Vec3 _direction = Vec3(0.0f, 0.0f, -1.0f);
|
||||
float _spare0 = 0.0f;
|
||||
Color _color = Color(1.0f);
|
||||
float _intensity = 1.0f;
|
||||
Vec4 _attenuation = Vec4(1.0f);
|
||||
Vec4 _spot = Vec4(0.0f, 0.0f, 0.0f, 3.0f);
|
||||
Vec4 _shadow = Vec4(0.0f);
|
||||
|
||||
Vec4 _control;
|
||||
Vec4 _control = Vec4(0.0f);
|
||||
|
||||
Schema() :
|
||||
_position(0.0f, 0.0f, 0.0f, 1.0f),
|
||||
_direction(0.0f, 0.0f, -1.0f),
|
||||
_spare0(0.f),
|
||||
_color(1.0f),
|
||||
_intensity(1.0f),
|
||||
_attenuation(1.0f, 1.0f, 1.0f, 1.0f),
|
||||
_spot(0.0f, 0.0f, 0.0f, 3.0f),
|
||||
_control(0.0f)
|
||||
{}
|
||||
Schema() {}
|
||||
};
|
||||
|
||||
const UniformBufferView& getSchemaBuffer() const { return _schemaBuffer; }
|
||||
|
|
|
@ -19,7 +19,6 @@ struct Light {
|
|||
vec4 _spot;
|
||||
|
||||
vec4 _shadow;
|
||||
|
||||
vec4 _control;
|
||||
};
|
||||
|
||||
|
@ -65,29 +64,15 @@ float getLightShowContour(Light l) {
|
|||
return l._control.w;
|
||||
}
|
||||
|
||||
<@if GLPROFILE == PC_GL@>
|
||||
<@if GPU_FEATURE_PROFILE == Core @>
|
||||
uniform lightBuffer {
|
||||
Light light;
|
||||
};
|
||||
Light getLight() {
|
||||
return light;
|
||||
}
|
||||
<@elif GLPROFILE == MAC_GL@>
|
||||
uniform vec4 lightBuffer[9];
|
||||
Light getLight() {
|
||||
Light light;
|
||||
light._position = lightBuffer[0];
|
||||
light._direction = lightBuffer[1];
|
||||
light._color = lightBuffer[2];
|
||||
light._attenuation = lightBuffer[3];
|
||||
light._spot = lightBuffer[4];
|
||||
light._shadow = lightBuffer[5];
|
||||
light._control = lightBuffer[6];
|
||||
|
||||
return light;
|
||||
}
|
||||
<@else@>
|
||||
uniform vec4 lightBuffer[9];
|
||||
uniform vec4 lightBuffer[7];
|
||||
Light getLight() {
|
||||
Light light;
|
||||
light._position = lightBuffer[0];
|
||||
|
|
|
@ -79,20 +79,15 @@ public:
|
|||
class Schema {
|
||||
public:
|
||||
|
||||
Color _diffuse;
|
||||
float _opacity;
|
||||
Color _specular;
|
||||
float _shininess;
|
||||
Color _emissive;
|
||||
float _spare0;
|
||||
Color _diffuse = Color(0.5f);
|
||||
float _opacity = 1.f;
|
||||
Color _specular = Color(0.03f);
|
||||
float _shininess = 0.1f;
|
||||
Color _emissive = Color(0.0f);
|
||||
float _spare0 = 0.0f;
|
||||
glm::vec4 _spareVec4 = glm::vec4(0.0f); // for alignment beauty, Mat size == Mat4x4
|
||||
|
||||
Schema() :
|
||||
_diffuse(0.5f),
|
||||
_opacity(1.0f),
|
||||
_specular(0.03f),
|
||||
_shininess(0.1f),
|
||||
_emissive(0.0f)
|
||||
{}
|
||||
Schema() {}
|
||||
};
|
||||
|
||||
const UniformBufferView& getSchemaBuffer() const { return _schemaBuffer; }
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
struct Material {
|
||||
vec4 _diffuse;
|
||||
vec4 _specular;
|
||||
|
||||
vec4 _emissive;
|
||||
vec4 _spare;
|
||||
};
|
||||
|
||||
float getMaterialOpacity(Material m) { return m._diffuse.a; }
|
||||
|
@ -24,36 +25,21 @@ float getMaterialShininess(Material m) { return m._specular.a; }
|
|||
|
||||
|
||||
|
||||
<@if GLPROFILE == PC_GL@>
|
||||
<@if GPU_FEATURE_PROFILE == Core@>
|
||||
uniform materialBuffer {
|
||||
Material _mat;
|
||||
};
|
||||
Material getMaterial() {
|
||||
return _mat;
|
||||
}
|
||||
<@elif GLPROFILE == MAC_GL@>
|
||||
uniform vec4 materialBuffer[2];
|
||||
Material getMaterial() {
|
||||
Material mat;
|
||||
mat._diffuse = materialBuffer[0];
|
||||
mat._specular = materialBuffer[1];
|
||||
return mat;
|
||||
}
|
||||
<!/* tryed and failed...
|
||||
bindable uniform struct {
|
||||
Material mat;
|
||||
} materialBuffer;
|
||||
|
||||
Material getMaterial() {
|
||||
return materialBuffer.mat;
|
||||
}
|
||||
*/!>
|
||||
<@else@>
|
||||
uniform vec4 materialBuffer[2];
|
||||
uniform vec4 materialBuffer[4];
|
||||
Material getMaterial() {
|
||||
Material mat;
|
||||
mat._diffuse = materialBuffer[0];
|
||||
mat._specular = materialBuffer[1];
|
||||
mat._emissive = materialBuffer[2];
|
||||
mat._spare = materialBuffer[3];
|
||||
return mat;
|
||||
}
|
||||
<@endif@>
|
||||
|
|
|
@ -494,14 +494,8 @@ void DeferredLightingEffect::loadLightProgram(const char* fragSource, bool limit
|
|||
locations.invViewMat = program.uniformLocation("invViewMat");
|
||||
|
||||
GLint loc = -1;
|
||||
#if defined(Q_OS_MAC)
|
||||
loc = program.uniformLocation("lightBuffer");
|
||||
if (loc >= 0) {
|
||||
locations.lightBufferUnit = loc;
|
||||
} else {
|
||||
locations.lightBufferUnit = -1;
|
||||
}
|
||||
#elif defined(Q_OS_WIN)
|
||||
|
||||
#if (GPU_FEATURE_PROFILE == Core)
|
||||
loc = glGetUniformBlockIndex(program.programId(), "lightBuffer");
|
||||
if (loc >= 0) {
|
||||
glUniformBlockBinding(program.programId(), loc, 0);
|
||||
|
@ -518,14 +512,7 @@ void DeferredLightingEffect::loadLightProgram(const char* fragSource, bool limit
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
loc = program.uniformLocation("atmosphereBufferUnit");
|
||||
if (loc >= 0) {
|
||||
locations.atmosphereBufferUnit = loc;
|
||||
} else {
|
||||
locations.atmosphereBufferUnit = -1;
|
||||
}
|
||||
#elif defined(Q_OS_WIN)
|
||||
#if (GPU_FEATURE_PROFILE == Core)
|
||||
loc = glGetUniformBlockIndex(program.programId(), "atmosphereBufferUnit");
|
||||
if (loc >= 0) {
|
||||
glUniformBlockBinding(program.programId(), loc, 1);
|
||||
|
|
|
@ -199,14 +199,8 @@ void Model::initProgram(ProgramObject& program, Model::Locations& locations, boo
|
|||
}
|
||||
|
||||
// bindable uniform version
|
||||
#if defined(Q_OS_MAC)
|
||||
loc = program.uniformLocation("materialBuffer");
|
||||
if (loc >= 0) {
|
||||
locations.materialBufferUnit = loc;
|
||||
} else {
|
||||
locations.materialBufferUnit = -1;
|
||||
}
|
||||
#elif defined(Q_OS_WIN)
|
||||
|
||||
#if (GPU_FEATURE_PROFILE == Core)
|
||||
loc = glGetUniformBlockIndex(program.programId(), "materialBuffer");
|
||||
if (loc >= 0) {
|
||||
glUniformBlockBinding(program.programId(), loc, 1);
|
||||
|
@ -223,7 +217,7 @@ void Model::initProgram(ProgramObject& program, Model::Locations& locations, boo
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
#if (GPU_FEATURE_PROFILE == Core)
|
||||
loc = glGetUniformBlockIndex(program.programId(), "transformObjectBuffer");
|
||||
if (loc >= 0) {
|
||||
glUniformBlockBinding(program.programId(), loc, gpu::TRANSFORM_OBJECT_SLOT);
|
||||
|
@ -231,7 +225,7 @@ void Model::initProgram(ProgramObject& program, Model::Locations& locations, boo
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
#if (GPU_FEATURE_PROFILE == Core)
|
||||
loc = glGetUniformBlockIndex(program.programId(), "transformCameraBuffer");
|
||||
if (loc >= 0) {
|
||||
glUniformBlockBinding(program.programId(), loc, gpu::TRANSFORM_CAMERA_SLOT);
|
||||
|
|
|
@ -16,10 +16,8 @@ uniform sampler2DShadow shadowMap;
|
|||
|
||||
// Fetching it
|
||||
float fetchShadow(vec3 texcoord) {
|
||||
<@if GLPROFILE == PC_GL @>
|
||||
<@if GPU_FEATURE_PROFILE == Core @>
|
||||
return texture(shadowMap, texcoord);
|
||||
<@elif GLPROFILE == MAC_GL@>
|
||||
return shadow2D(shadowMap, texcoord).r;
|
||||
<@else@>
|
||||
return shadow2D(shadowMap, texcoord).r;
|
||||
<@endif@>
|
||||
|
|
Loading…
Reference in a new issue