mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
replacing the glTransform pipeline for model rendering
This commit is contained in:
parent
11247734d4
commit
d8aa0e0138
8 changed files with 95 additions and 23 deletions
|
@ -12,7 +12,8 @@
|
|||
<@def GPU_CONFIG_SLH@>
|
||||
|
||||
<@if GLPROFILE == PC_GL @>
|
||||
<@def VERSION_HEADER #version 330 compatibility@>
|
||||
<@def VERSION_HEADER #version 410 compatibility
|
||||
#@>
|
||||
|
||||
<@func inputPosition name@>
|
||||
layout(location = 0) in vec3 <$name$>;
|
||||
|
|
|
@ -39,9 +39,9 @@ public:
|
|||
|
||||
class TransformCamera {
|
||||
public:
|
||||
Mat4 _projection;
|
||||
Mat4 _view;
|
||||
Mat4 _viewInverse;
|
||||
Mat4 _projection;
|
||||
};
|
||||
|
||||
template< typename T >
|
||||
|
|
|
@ -73,11 +73,11 @@ GLBackend::GLBackend() :
|
|||
_input(),
|
||||
_transform()
|
||||
{
|
||||
|
||||
initTransform();
|
||||
}
|
||||
|
||||
GLBackend::~GLBackend() {
|
||||
|
||||
killTransform();
|
||||
}
|
||||
|
||||
void GLBackend::render(Batch& batch) {
|
||||
|
@ -420,7 +420,6 @@ void GLBackend::killTransform() {
|
|||
#else
|
||||
#endif
|
||||
}
|
||||
#define LEGACY_TRANSFORM_PIPELINE 1
|
||||
void GLBackend::updateTransform() {
|
||||
|
||||
#ifdef LEGACY_TRANSFORM_PIPELINE
|
||||
|
@ -496,16 +495,62 @@ void GLBackend::updateTransform() {
|
|||
glBindBuffer(GL_UNIFORM_BUFFER, _transform._transformCameraBuffer);
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(_transform._transformCamera), (const void*) &_transform._transformCamera);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||
CHECK_GL_ERROR();
|
||||
}
|
||||
|
||||
if (_transform._invalidView || _transform._invalidModel) {
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, _transform._transformObjectBuffer);
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(_transform._transformObject), (const void*) &_transform._transformObject);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||
CHECK_GL_ERROR();
|
||||
}
|
||||
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, 0, _transform._transformCameraBuffer, 0, sizeof(TransformCamera));
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, 1, _transform._transformObjectBuffer, 0, sizeof(TransformObject));
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, 6, _transform._transformObjectBuffer, 0, sizeof(TransformObject));
|
||||
glBindBufferRange(GL_UNIFORM_BUFFER, 7, _transform._transformCameraBuffer, 0, sizeof(TransformCamera));
|
||||
CHECK_GL_ERROR();
|
||||
|
||||
// Do it again for fixed pipeline unitl we can get rid of it
|
||||
if (_transform._invalidProj) {
|
||||
if (_transform._lastMode != GL_PROJECTION) {
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
_transform._lastMode = GL_PROJECTION;
|
||||
}
|
||||
glLoadMatrixf(reinterpret_cast< const GLfloat* >(&_transform._projection));
|
||||
|
||||
CHECK_GL_ERROR();
|
||||
}
|
||||
|
||||
if (_transform._invalidModel || _transform._invalidView) {
|
||||
if (!_transform._model.isIdentity()) {
|
||||
if (_transform._lastMode != GL_MODELVIEW) {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
_transform._lastMode = GL_MODELVIEW;
|
||||
}
|
||||
Transform::Mat4 modelView;
|
||||
if (!_transform._view.isIdentity()) {
|
||||
Transform mvx;
|
||||
Transform::inverseMult(mvx, _transform._view, _transform._model);
|
||||
mvx.getMatrix(modelView);
|
||||
} else {
|
||||
_transform._model.getMatrix(modelView);
|
||||
}
|
||||
glLoadMatrixf(reinterpret_cast< const GLfloat* >(&modelView));
|
||||
} else {
|
||||
if (!_transform._view.isIdentity()) {
|
||||
if (_transform._lastMode != GL_MODELVIEW) {
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
_transform._lastMode = GL_MODELVIEW;
|
||||
}
|
||||
Transform::Mat4 modelView;
|
||||
_transform._view.getInverseMatrix(modelView);
|
||||
glLoadMatrixf(reinterpret_cast< const GLfloat* >(&modelView));
|
||||
} else {
|
||||
// TODO: eventually do something about the matrix when neither view nor model is specified?
|
||||
// glLoadIdentity();
|
||||
}
|
||||
}
|
||||
CHECK_GL_ERROR();
|
||||
}
|
||||
|
||||
_transform._invalidView = _transform._invalidProj = _transform._invalidModel = false;
|
||||
#endif
|
||||
|
|
|
@ -49,7 +49,7 @@ static const GLenum _elementTypeToGLType[NUM_TYPES]= {
|
|||
GL_UNSIGNED_BYTE
|
||||
};
|
||||
|
||||
//#define CHECK_GL_ERROR() ::gpu::GLBackend::checkGLError()
|
||||
#define CHECK_GL_ERROR()
|
||||
#define CHECK_GL_ERROR() ::gpu::GLBackend::checkGLError()
|
||||
//#define CHECK_GL_ERROR()
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,10 +18,9 @@ struct TransformObject {
|
|||
};
|
||||
|
||||
struct TransformCamera {
|
||||
mat4 _projection;
|
||||
mat4 _view;
|
||||
mat4 _viewInverse;
|
||||
mat4 _projection;
|
||||
|
||||
};
|
||||
|
||||
vec4 transform(TransformCamera camera, TransformObject object, vec4 pos) {
|
||||
|
@ -29,13 +28,20 @@ vec4 transform(TransformCamera camera, TransformObject object, vec4 pos) {
|
|||
}
|
||||
|
||||
|
||||
<!
|
||||
|
||||
<@if GLPROFILE == PC_GL@>
|
||||
uniform transformStateBuffer {
|
||||
TransformState xform;
|
||||
uniform transformObjectBuffer {
|
||||
TransformObject object;
|
||||
};
|
||||
TransformState getTransformState() {
|
||||
return xform;
|
||||
TransformObject getTransformObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
uniform transformCameraBuffer {
|
||||
TransformCamera camera;
|
||||
};
|
||||
TransformCamera getTransformCamera() {
|
||||
return camera;
|
||||
}
|
||||
<@elif GLPROFILE == MAC_GL@>
|
||||
uniform vec4 transformStateBuffer[2];
|
||||
|
@ -54,7 +60,6 @@ TransformState getMaterial() {
|
|||
return xform;
|
||||
}
|
||||
<@endif@>
|
||||
!>
|
||||
|
||||
|
||||
<@endif@>
|
||||
|
|
|
@ -96,10 +96,11 @@ vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, ve
|
|||
|
||||
Light light = getLight();
|
||||
|
||||
vec3 fragNormal = vec3(invViewMat * vec4(normal, 0.0));
|
||||
//vec3 fragNormal = vec3(invViewMat * vec4(normal, 0.0));
|
||||
|
||||
// float diffuseDot = dot(fragNormal, getLightDirection(light));
|
||||
float diffuseDot = dot(normal, getLightDirection(light));
|
||||
|
||||
float diffuseDot = dot(fragNormal, getLightDirection(light));
|
||||
|
||||
// need to catch normals perpendicular to the projection plane hence the magic number for the threshold
|
||||
// it should be just 0, but we have innacurracy so we need to overshoot
|
||||
const float PERPENDICULAR_THRESHOLD = -0.005;
|
||||
|
|
|
@ -223,6 +223,19 @@ void Model::initProgram(ProgramObject& program, Model::Locations& locations, boo
|
|||
}
|
||||
#endif
|
||||
|
||||
loc = glGetUniformBlockIndex(program.programId(), "transformObjectBuffer");
|
||||
if (loc >= 0) {
|
||||
glUniformBlockBinding(program.programId(), loc, 6);
|
||||
// locations.materialBufferUnit = 1;
|
||||
}
|
||||
|
||||
loc = glGetUniformBlockIndex(program.programId(), "transformCameraBuffer");
|
||||
if (loc >= 0) {
|
||||
glUniformBlockBinding(program.programId(), loc, 7);
|
||||
// locations.materialBufferUnit = 1;
|
||||
}
|
||||
|
||||
program.link();
|
||||
if (!program.isLinked()) {
|
||||
program.release();
|
||||
}
|
||||
|
|
|
@ -11,14 +11,14 @@
|
|||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
//include gpu/Transform.slh
|
||||
<@include gpu/Transform.slh@>
|
||||
const int MAX_TEXCOORDS = 2;
|
||||
|
||||
uniform mat4 texcoordMatrices[MAX_TEXCOORDS];
|
||||
|
||||
// the interpolated normal
|
||||
varying vec4 normal;
|
||||
/*
|
||||
/*
|
||||
void main(void) {
|
||||
// transform and store the normal for interpolation
|
||||
normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));
|
||||
|
@ -46,5 +46,12 @@ void main(void) {
|
|||
gl_TexCoord[0] = texcoordMatrices[0] * vec4(gl_MultiTexCoord0.xy, 0.0, 1.0);
|
||||
|
||||
// use standard pipeline transform
|
||||
gl_Position = ftransform();
|
||||
//gl_Position = ftransform();
|
||||
//gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
// TransformObject obj = getTransformObject();
|
||||
TransformCamera cam = getTransformCamera();
|
||||
// gl_Position = transform(cam, obj, gl_Vertex);
|
||||
|
||||
vec4 vPos = gl_ModelViewMatrix * gl_Vertex;
|
||||
gl_Position = cam._projection * vPos;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue