1
git-svn-id: svn://db.shs.com.ru/libs@1 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
91
qglview/renderer_simple.cpp
Normal file
91
qglview/renderer_simple.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
QGLView
|
||||
Copyright (C) 2012 Ivan Pelipenko peri4ko@gmail.com
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "renderer_simple.h"
|
||||
|
||||
|
||||
RendererSimple::RendererSimple(QGLView * view_): GLRendererBase(view_), fbo(2) {
|
||||
shader_fxaa = 0;
|
||||
}
|
||||
|
||||
|
||||
void RendererSimple::renderScene() {
|
||||
int passes = (view.lightsCount() - 1) / 8 + 1;
|
||||
//QMatrix4x4 pm = getGLMatrix(GL_PROJECTION_MATRIX), mvm = getGLMatrix(GL_MODELVIEW_MATRIX), pmvm = pm * mvm, lpm, lmvm, lpmvm;
|
||||
glSetCapEnabled(GL_MULTISAMPLE, view.isMultisamplingEnabled());
|
||||
if (passes < 1) passes = 1;
|
||||
//glEnable(GL_FOG);
|
||||
if (view.isFXAAEnabled()) fbo.bind();
|
||||
//glEnable(GL_TEXTURE_2D);
|
||||
if (passes > 1) {
|
||||
fbo.bind();
|
||||
fbo.setWriteBuffer(0);
|
||||
glClearFramebuffer();
|
||||
}
|
||||
for (int l = 0; l < passes; ++l) {
|
||||
if (passes > 1) fbo.setWriteBuffer(1);
|
||||
if (l == 0) {
|
||||
glClearFramebuffer(view.backColor());
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_TRUE);
|
||||
} else {
|
||||
glClearFramebuffer(Qt::black, false);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
glDepthFunc(GL_EQUAL);
|
||||
}
|
||||
view.camera().apply(view.aspect);
|
||||
setupLights(l, 8);
|
||||
//glEnable(GL_MULTISAMPLE);
|
||||
renderObjects(GLObjectBase::Solid, l, 0, true, true, view.isFogEnabled());
|
||||
renderObjects(GLObjectBase::Transparent, l, 0, true, true, view.isFogEnabled());
|
||||
if (passes > 1) {
|
||||
glSetLightEnabled(false);
|
||||
glSetCapEnabled(GL_BLEND);
|
||||
glBlendFunc(GL_ONE, GL_ONE);
|
||||
glReleaseTextures();
|
||||
glBindTexture(GL_TEXTURE_2D, fbo.colorTexture(1));
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
glDepthMask(GL_FALSE);
|
||||
fbo.setWriteBuffer(0);
|
||||
glDrawQuad();
|
||||
}
|
||||
}
|
||||
if (view.isFXAAEnabled() || passes > 1) {
|
||||
fbo.release();
|
||||
//glClearFramebuffer();
|
||||
glActiveTextureChannel(0);
|
||||
glBindTexture(GL_TEXTURE_2D, fbo.colorTexture());
|
||||
glSetLightEnabled(false);
|
||||
glSetCapEnabled(GL_BLEND, false);
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
if (view.isFXAAEnabled()) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
shader_fxaa->bind();
|
||||
shader_fxaa->setUniformValue("dt", QVector2D(1. / view.viewport()->width(), 1. / view.viewport()->height()));
|
||||
glDrawQuad();
|
||||
shader_fxaa->release();
|
||||
} else {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
glDrawQuad();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user