some clean
This commit is contained in:
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
QGL GLRendererBase
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "glrendererbase.h"
|
||||
#include "globject.h"
|
||||
#include "qglview.h"
|
||||
|
||||
|
||||
GLRendererBase::GLRendererBase(QGLView * view_): view(view_) {
|
||||
white_image = QImage(1, 1, QImage::Format_ARGB32);
|
||||
white_image.fill(0xFFFFFFFF);
|
||||
white_image_id = 0;
|
||||
violent_image = QImage(1, 1, QImage::Format_ARGB32);
|
||||
violent_image.fill(QColor(127, 127, 255));
|
||||
violent_image_id = 0;
|
||||
}
|
||||
|
||||
|
||||
void GLRendererBase::setupLight(const Light & l, int inpass_index, int gl_index) {
|
||||
QVector3D lp = l.worldPos(), ld;
|
||||
GLfloat pos[] = {0.f, 0.f, 0.f, 0.f};
|
||||
GLfloat dir[] = {0.f, 0.f, 0.f};
|
||||
GLfloat col[] = {0.f, 0.f, 0.f};
|
||||
pos[0] = l.light_type == Light::Directional ? -l.direction().x() : lp.x();
|
||||
pos[1] = l.light_type == Light::Directional ? -l.direction().y() : lp.y();
|
||||
pos[2] = l.light_type == Light::Directional ? -l.direction().z() : lp.z();
|
||||
pos[3] = l.light_type == Light::Directional ? 0. : 1.;
|
||||
dir[0] = ld.x();
|
||||
dir[1] = ld.y();
|
||||
dir[2] = ld.z();
|
||||
glEnable(gl_index);
|
||||
glLightfv(gl_index, GL_DIFFUSE, col);
|
||||
glLightfv(gl_index, GL_SPECULAR, col);
|
||||
glLightfv(gl_index, GL_POSITION, pos);
|
||||
glLightf(gl_index, GL_CONSTANT_ATTENUATION, l.decay_const);
|
||||
glLightf(gl_index, GL_LINEAR_ATTENUATION, l.decay_linear);
|
||||
glLightf(gl_index, GL_QUADRATIC_ATTENUATION, l.decay_quadratic);
|
||||
if (l.light_type == Light::Cone) {
|
||||
glLightfv(gl_index, GL_SPOT_DIRECTION, dir);
|
||||
glLightf(gl_index, GL_SPOT_CUTOFF, l.angle_end / 2.f);
|
||||
glLightf(gl_index, GL_SPOT_EXPONENT, (1.f - piClamp<float>((l.angle_end - l.angle_start) / (l.angle_end + 0.001f), 0., 1.f)) * 128.f);
|
||||
} else {
|
||||
glLightf(gl_index, GL_SPOT_CUTOFF, 180.);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void GLRendererBase::setupAmbientLight(const QColor & a, bool first_pass) {
|
||||
GLfloat ambient[] = {0.0f, 0.0f, 0.0f, 1.f};
|
||||
if (first_pass) {
|
||||
ambient[0] = view->ambientColor().redF();
|
||||
ambient[1] = view->ambientColor().greenF();
|
||||
ambient[2] = view->ambientColor().blueF();
|
||||
}
|
||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define BIND_TEXTURE(ch, map) if (rp.prev_tex[ch] != mat.map.bitmap_id) { \
|
||||
rp.prev_tex[ch] = mat.map.bitmap_id; \
|
||||
glActiveTexture(GL_TEXTURE0 + ch); glBindTexture(GL_TEXTURE_2D, mat.map.bitmap_id); \
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, view->feature(QGLView::qglAnisotropicLevel).toInt());}
|
||||
|
||||
void GLRendererBase::setupTextures(ObjectBase & o, GLRendererBase::RenderingParameters & rp, bool first_object) {
|
||||
}
|
||||
|
||||
#undef BIND_TEXTURE
|
||||
|
||||
|
||||
void GLRendererBase::applyFilteringParameters() {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, view->feature(QGLView::qglAnisotropicLevel).toInt());
|
||||
}
|
||||
|
||||
|
||||
GLRendererBase::RenderingParameters::RenderingParameters() {
|
||||
}
|
||||
|
||||
|
||||
void GLRendererBase::RenderingParameters::prepare() {
|
||||
viewproj_matrix = proj_matrix * view_matrix;
|
||||
normal_matrix = view_matrix.normalMatrix();
|
||||
proj_matrix_i = proj_matrix.inverted();
|
||||
view_matrix_i = view_matrix.inverted();
|
||||
viewproj_matrix_i = viewproj_matrix.inverted();
|
||||
}
|
||||
|
||||
|
||||
void GLRendererBase::RenderingParameters::setUniform(QOpenGLShaderProgram * prog) {
|
||||
if (!prog) return;
|
||||
prog->setUniformValue("qgl_ModelViewMatrix", view_matrix);
|
||||
prog->setUniformValue("qgl_ProjectionMatrix", proj_matrix);
|
||||
prog->setUniformValue("qgl_ModelViewProjectionMatrix", viewproj_matrix);
|
||||
prog->setUniformValue("qgl_NormalMatrix", normal_matrix);
|
||||
prog->setUniformValue("qgl_ModelViewMatrixInverse", view_matrix_i);
|
||||
prog->setUniformValue("qgl_ProjectionMatrixInverse", proj_matrix_i);
|
||||
prog->setUniformValue("qgl_ModelViewProjectionMatrixInverse", viewproj_matrix_i);
|
||||
prog->setUniformValue("qgl_ModelViewMatrixTranspose", view_matrix.transposed());
|
||||
prog->setUniformValue("qgl_ProjectionMatrixTranspose", proj_matrix.transposed());
|
||||
prog->setUniformValue("qgl_ModelViewProjectionMatrixTranspose", viewproj_matrix.transposed());
|
||||
prog->setUniformValue("qgl_ModelViewMatrixInverseTranspose", view_matrix_i.transposed());
|
||||
prog->setUniformValue("qgl_ProjectionMatrixInverseTranspose", proj_matrix_i.transposed());
|
||||
prog->setUniformValue("qgl_ModelViewProjectionMatrixInverseTranspose", viewproj_matrix_i.transposed());
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
QGL GLRendererBase
|
||||
Ivan Pelipenko peri4ko@yandex.ru
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef GLRENDERERBASE_H
|
||||
#define GLRENDERERBASE_H
|
||||
|
||||
#include "glcamera.h"
|
||||
#include "glshaders.h"
|
||||
|
||||
|
||||
class GLRendererBase: public QObject , protected QOpenGLExtraFunctions
|
||||
{
|
||||
friend class QGLView;
|
||||
Q_OBJECT
|
||||
public:
|
||||
GLRendererBase(QGLView * view_);
|
||||
virtual void prepareScene() {;}
|
||||
virtual void renderScene() = 0;
|
||||
|
||||
struct RenderingParameters {
|
||||
RenderingParameters();
|
||||
void prepare();
|
||||
void setUniform(QOpenGLShaderProgram * prog);
|
||||
QMatrix4x4 view_matrix, view_matrix_i;
|
||||
QMatrix4x4 proj_matrix, proj_matrix_i;
|
||||
QMatrix4x4 viewproj_matrix, viewproj_matrix_i;
|
||||
QMatrix3x3 normal_matrix;
|
||||
};
|
||||
|
||||
RenderingParameters rp;
|
||||
|
||||
protected:
|
||||
virtual void setupLight(const Light & l, int inpass_index, int gl_index);
|
||||
virtual void setupAmbientLight(const QColor & a, bool first_pass);
|
||||
virtual void setupShadersLights(int lights_count) {}
|
||||
virtual void setupTextures(ObjectBase & object, GLRendererBase::RenderingParameters & rp, bool first_object = false);
|
||||
virtual void setupShadersTextures(ObjectBase & object, GLRendererBase::RenderingParameters & rp) {}
|
||||
virtual void reloadShaders() {}
|
||||
virtual void init(int width, int height) {}
|
||||
virtual void resize(int width, int height) {}
|
||||
|
||||
inline void applyFilteringParameters();
|
||||
|
||||
QGLView * view;
|
||||
QImage white_image, violent_image;
|
||||
GLuint white_image_id, violent_image_id;
|
||||
};
|
||||
|
||||
#endif // GLRENDERERBASE_H
|
||||
@@ -23,7 +23,6 @@
|
||||
#include "glframebuffer.h"
|
||||
#include "glprimitives.h"
|
||||
#include "glcamera.h"
|
||||
#include "glrendererbase.h"
|
||||
#include "glscene.h"
|
||||
#include "renderer.h"
|
||||
#include "mouse_controller.h"
|
||||
@@ -214,7 +213,6 @@ private:
|
||||
QElapsedTimer time, ktm_;
|
||||
GLint max_anisotropic, max_texture_chanels;
|
||||
ObjectBase::RenderMode rmode;
|
||||
GLRendererBase::RenderingParameters start_rp;
|
||||
QHash<int, QVariant> features_;
|
||||
QSize prev_size;
|
||||
float lineWidth_;
|
||||
|
||||
@@ -18,11 +18,13 @@
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <QOpenGLExtraFunctions>
|
||||
#include <qad_types.h>
|
||||
#include "renderer.h"
|
||||
#include "qglview.h"
|
||||
#include "glmesh.h"
|
||||
#include "gltexture_manager.h"
|
||||
#include <qad_types.h>
|
||||
#include "glshaders.h"
|
||||
|
||||
|
||||
using namespace QGLEngineShaders;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user