mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 23:29:39 +02:00
replacing the glTransform pipeline for model rendering
This commit is contained in:
parent
cc3cc4f96f
commit
23354da828
7 changed files with 48 additions and 39 deletions
|
@ -156,7 +156,7 @@ void Batch::setViewTransform(const Transform& view) {
|
||||||
void Batch::setProjectionTransform(const Mat4& proj) {
|
void Batch::setProjectionTransform(const Mat4& proj) {
|
||||||
ADD_COMMAND(setProjectionTransform);
|
ADD_COMMAND(setProjectionTransform);
|
||||||
|
|
||||||
_params.push_back(cacheData(sizeof(Mat4), &proj);
|
_params.push_back(cacheData(sizeof(Mat4), &proj));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch::setUniformBuffer(uint32 slot, const BufferPointer& buffer, Offset offset, Offset size) {
|
void Batch::setUniformBuffer(uint32 slot, const BufferPointer& buffer, Offset offset, Offset size) {
|
||||||
|
|
|
@ -80,21 +80,25 @@ GLBackend::~GLBackend() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLBackend::renderBatch(Batch& batch) {
|
void GLBackend::render(Batch& batch) {
|
||||||
|
|
||||||
uint32 numCommands = batch.getCommands().size();
|
uint32 numCommands = batch.getCommands().size();
|
||||||
const Batch::Commands::value_type* command = batch.getCommands().data();
|
const Batch::Commands::value_type* command = batch.getCommands().data();
|
||||||
const Batch::CommandOffsets::value_type* offset = batch.getCommandOffsets().data();
|
const Batch::CommandOffsets::value_type* offset = batch.getCommandOffsets().data();
|
||||||
|
|
||||||
GLBackend backend;
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < numCommands; i++) {
|
for (unsigned int i = 0; i < numCommands; i++) {
|
||||||
CommandCall call = _commandCalls[(*command)];
|
CommandCall call = _commandCalls[(*command)];
|
||||||
(backend.*(call))(batch, *offset);
|
(this->*(call))(batch, *offset);
|
||||||
command++;
|
command++;
|
||||||
offset++;
|
offset++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GLBackend::renderBatch(Batch& batch) {
|
||||||
|
GLBackend backend;
|
||||||
|
backend.render(batch);
|
||||||
|
}
|
||||||
|
|
||||||
void GLBackend::checkGLError() {
|
void GLBackend::checkGLError() {
|
||||||
GLenum error = glGetError();
|
GLenum error = glGetError();
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
@ -416,9 +420,9 @@ void GLBackend::killTransform() {
|
||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#define LEGACY_TRANSFORM_PIPELINE 1
|
||||||
void GLBackend::updateTransform() {
|
void GLBackend::updateTransform() {
|
||||||
#define LEGACY_TRANSFORM_PIPELINE
|
|
||||||
#ifdef LEGACY_TRANSFORM_PIPELINE
|
#ifdef LEGACY_TRANSFORM_PIPELINE
|
||||||
if (_transform._invalidProj) {
|
if (_transform._invalidProj) {
|
||||||
// TODO: implement the projection matrix assignment to gl state
|
// TODO: implement the projection matrix assignment to gl state
|
||||||
|
|
|
@ -27,11 +27,14 @@ public:
|
||||||
GLBackend();
|
GLBackend();
|
||||||
~GLBackend();
|
~GLBackend();
|
||||||
|
|
||||||
|
void render(Batch& batch);
|
||||||
|
|
||||||
static void renderBatch(Batch& batch);
|
static void renderBatch(Batch& batch);
|
||||||
|
|
||||||
static void checkGLError();
|
static void checkGLError();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class GLBuffer {
|
class GLBuffer {
|
||||||
public:
|
public:
|
||||||
Stamp _stamp;
|
Stamp _stamp;
|
||||||
|
@ -138,7 +141,7 @@ protected:
|
||||||
_projection(),
|
_projection(),
|
||||||
_invalidModel(true),
|
_invalidModel(true),
|
||||||
_invalidView(true),
|
_invalidView(true),
|
||||||
_invalidProj(true),
|
_invalidProj(false),
|
||||||
_lastMode(GL_TEXTURE) {}
|
_lastMode(GL_TEXTURE) {}
|
||||||
} _transform;
|
} _transform;
|
||||||
|
|
||||||
|
|
|
@ -870,7 +870,11 @@ void ViewFrustum::evalProjectionMatrix(glm::mat4& proj) const {
|
||||||
if (isOrthographic()) {
|
if (isOrthographic()) {
|
||||||
proj = glm::ortho(getWidth() * -0.5, getWidth() * +0.5, getHeight() * -0.5, getHeight() * 0.5);
|
proj = glm::ortho(getWidth() * -0.5, getWidth() * +0.5, getHeight() * -0.5, getHeight() * 0.5);
|
||||||
} else {
|
} else {
|
||||||
proj = glm::perspective(getFieldOfView(), getAspectRatio(), getNearClip(), getFarClip());
|
float left, right, bottom, top, near, far;
|
||||||
|
glm::vec4 clip0, clip1;
|
||||||
|
computeOffAxisFrustum(left, right, bottom, top, near, far, clip0, clip1);
|
||||||
|
proj = glm::perspective(glm::radians(getFieldOfView()), getAspectRatio(), getNearClip(), getFarClip());
|
||||||
|
// proj = glm::perspective(getFieldOfView() * 0.5f, getAspectRatio(), getNearClip(), getFarClip());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,10 @@ vec3 evalAmbienSphereGlobalColor(float shadowAttenuation, vec3 position, vec3 no
|
||||||
vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, vec3 lightmap) {
|
vec3 evalLightmappedColor(float shadowAttenuation, vec3 normal, vec3 diffuse, vec3 lightmap) {
|
||||||
|
|
||||||
Light light = getLight();
|
Light light = getLight();
|
||||||
float diffuseDot = dot(normal, getLightDirection(light));
|
|
||||||
|
vec3 fragNormal = vec3(invViewMat * vec4(normal, 0.0));
|
||||||
|
|
||||||
|
float diffuseDot = dot(fragNormal, getLightDirection(light));
|
||||||
|
|
||||||
// need to catch normals perpendicular to the projection plane hence the magic number for the threshold
|
// 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
|
// it should be just 0, but we have innacurracy so we need to overshoot
|
||||||
|
|
|
@ -687,6 +687,12 @@ bool Model::renderCore(float alpha, RenderMode mode, RenderArgs* args) {
|
||||||
_renderBatch.clear();
|
_renderBatch.clear();
|
||||||
gpu::Batch& batch = _renderBatch;
|
gpu::Batch& batch = _renderBatch;
|
||||||
|
|
||||||
|
if (args) {
|
||||||
|
glm::mat4 proj;
|
||||||
|
args->_viewFrustum->evalProjectionMatrix(proj);
|
||||||
|
batch.setProjectionTransform(proj);
|
||||||
|
}
|
||||||
|
|
||||||
// Capture the view matrix once for the rendering of this model
|
// Capture the view matrix once for the rendering of this model
|
||||||
if (_transforms.empty()) {
|
if (_transforms.empty()) {
|
||||||
_transforms.push_back(Transform());
|
_transforms.push_back(Transform());
|
||||||
|
@ -1659,26 +1665,26 @@ void Model::setupBatchTransform(gpu::Batch& batch) {
|
||||||
void Model::endScene(RenderMode mode, RenderArgs* args) {
|
void Model::endScene(RenderMode mode, RenderArgs* args) {
|
||||||
PROFILE_RANGE(__FUNCTION__);
|
PROFILE_RANGE(__FUNCTION__);
|
||||||
|
|
||||||
|
#if defined(ANDROID)
|
||||||
|
#else
|
||||||
|
glPushMatrix();
|
||||||
|
#endif
|
||||||
|
|
||||||
RenderArgs::RenderSide renderSide = RenderArgs::MONO;
|
RenderArgs::RenderSide renderSide = RenderArgs::MONO;
|
||||||
if (args) {
|
if (args) {
|
||||||
renderSide = args->_renderSide;
|
renderSide = args->_renderSide;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gpu::GLBackend backend;
|
||||||
|
|
||||||
if (args) {
|
if (args) {
|
||||||
glm::mat4 proj;
|
glm::mat4 proj;
|
||||||
args->_viewFrustum->evalProjectionMatrix(proj);
|
args->_viewFrustum->evalProjectionMatrix(proj);
|
||||||
gpu::Batch batch;
|
gpu::Batch batch;
|
||||||
batch.setProjectionTransform(proj);
|
batch.setProjectionTransform(proj);
|
||||||
::gpu::GLBackend::renderBatch(batch);
|
backend.render(batch);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_viewState->getViewTransform();
|
|
||||||
// apply entity translation offset to the viewTransform in one go (it's a preTranslate because viewTransform goes from world to eye space)
|
|
||||||
_transforms[0].preTranslate(-_translation);
|
|
||||||
|
|
||||||
|
|
||||||
// Do the rendering batch creation for mono or left eye, not for right eye
|
// Do the rendering batch creation for mono or left eye, not for right eye
|
||||||
if (renderSide != RenderArgs::STEREO_RIGHT) {
|
if (renderSide != RenderArgs::STEREO_RIGHT) {
|
||||||
// Let's introduce a gpu::Batch to capture all the calls to the graphics api
|
// Let's introduce a gpu::Batch to capture all the calls to the graphics api
|
||||||
|
@ -1833,18 +1839,14 @@ void Model::endScene(RenderMode mode, RenderArgs* args) {
|
||||||
// Render!
|
// Render!
|
||||||
{
|
{
|
||||||
PROFILE_RANGE("render Batch");
|
PROFILE_RANGE("render Batch");
|
||||||
#if defined(ANDROID)
|
backend.render(_sceneRenderBatch);
|
||||||
#else
|
}
|
||||||
glPushMatrix();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
::gpu::GLBackend::renderBatch(_sceneRenderBatch);
|
|
||||||
|
|
||||||
#if defined(ANDROID)
|
#if defined(ANDROID)
|
||||||
#else
|
#else
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
#endif
|
#endif
|
||||||
}
|
|
||||||
|
|
||||||
// restore all the default material settings
|
// restore all the default material settings
|
||||||
_viewState->setupWorldLight();
|
_viewState->setupWorldLight();
|
||||||
|
|
|
@ -11,19 +11,14 @@
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// 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;
|
const int MAX_TEXCOORDS = 2;
|
||||||
|
|
||||||
<$inputPosition(vin_position)$>
|
|
||||||
<$inputNormal(vin_normal)$>
|
|
||||||
<$inputTexcoord(vin_texcoord)$>
|
|
||||||
<$inputColor(vin_color)$>
|
|
||||||
|
|
||||||
uniform mat4 texcoordMatrices[MAX_TEXCOORDS];
|
uniform mat4 texcoordMatrices[MAX_TEXCOORDS];
|
||||||
|
|
||||||
// the interpolated normal
|
// the interpolated normal
|
||||||
varying vec4 normal;
|
varying vec4 normal;
|
||||||
|
/*
|
||||||
void main(void) {
|
void main(void) {
|
||||||
// transform and store the normal for interpolation
|
// transform and store the normal for interpolation
|
||||||
normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));
|
normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));
|
||||||
|
@ -37,10 +32,9 @@ void main(void) {
|
||||||
// use standard pipeline transform
|
// use standard pipeline transform
|
||||||
gl_Position = gl_ModelViewProjectionMatrix * vec4(vin_position, 1.0);
|
gl_Position = gl_ModelViewProjectionMatrix * vec4(vin_position, 1.0);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
// transform and store the normal for interpolation
|
// transform and store the normal for interpolation
|
||||||
normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));
|
normal = normalize(gl_ModelViewMatrix * vec4(gl_Normal, 0.0));
|
||||||
|
@ -54,4 +48,3 @@ void main(void) {
|
||||||
// use standard pipeline transform
|
// use standard pipeline transform
|
||||||
gl_Position = ftransform();
|
gl_Position = ftransform();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
Loading…
Reference in a new issue