16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 06:59:18 +02:00

merge, with tmj renderer

This commit is contained in:
milek7
2017-08-18 00:56:05 +02:00
85 changed files with 6815 additions and 3770 deletions

View File

@@ -7,7 +7,8 @@ obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#ifndef OPENGLMATRIXSTACK_INC
#define OPENGLMATRIXSTACK_INC
#include <stack>
#include <vector>
@@ -27,21 +28,27 @@ class opengl_stack {
public:
// constructors:
opengl_stack() { m_stack.emplace(1.0f); }
opengl_stack() { m_stack.emplace(1.f); }
// methods:
glm::mat4 const &
data() const { return m_stack.top(); }
data() const {
return m_stack.top(); }
void
push_matrix() { m_stack.emplace(m_stack.top()); }
push_matrix() {
m_stack.emplace( m_stack.top() ); }
void
pop_matrix() {
m_stack.pop();
if( m_stack.empty() ) { m_stack.emplace(1.0f); }
if( m_stack.empty() ) { m_stack.emplace( 1.f ); }
upload(); }
void
load_identity() {
m_stack.top() = glm::mat4( 1.0f );
m_stack.top() = glm::mat4( 1.f );
upload(); }
void
load_matrix( glm::mat4 const &Matrix ) {
m_stack.top() = Matrix;
upload(); }
void
rotate( float const Angle, glm::vec3 const &Axis ) {
@@ -59,6 +66,10 @@ public:
multiply( glm::mat4 const &Matrix ) {
m_stack.top() *= Matrix;
upload(); }
void
ortho( float const Left, float const Right, float const Bottom, float const Top, float const Znear, float const Zfar ) {
m_stack.top() *= glm::ortho( Left, Right, Bottom, Top, Znear, Zfar );
upload(); }
void
perspective( float const Fovy, float const Aspect, float const Znear, float const Zfar ) {
m_stack.top() *= glm::perspective( Fovy, Aspect, Znear, Zfar );
@@ -80,29 +91,32 @@ private:
mat4_stack m_stack;
};
enum stack_mode { gl_projection = 0, gl_modelview = 1 };
enum stack_mode { gl_modelview = 0, gl_projection = 1, gl_texture = 2 };
typedef std::vector<opengl_stack> openglstack_array;
public:
// constructors:
opengl_matrices() {
m_stacks.emplace_back(); // projection
m_stacks.emplace_back(); // modelview
m_stacks.emplace_back(); // projection
m_stacks.emplace_back(); // texture
}
// methods:
void
mode( GLuint const Mode ) {
switch( Mode ) {
case GL_PROJECTION: { m_mode = stack_mode::gl_projection; break; }
case GL_MODELVIEW: { m_mode = stack_mode::gl_modelview; break; }
case GL_PROJECTION: { m_mode = stack_mode::gl_projection; break; }
case GL_TEXTURE: { m_mode = stack_mode::gl_texture; break; }
default: { break; } }
glMatrixMode( Mode ); }
::glMatrixMode( Mode ); }
glm::mat4 const &
data( GLuint const Mode = -1 ) const {
switch( Mode ) {
case GL_PROJECTION: { return m_stacks[ stack_mode::gl_projection ].data(); }
case GL_MODELVIEW: { return m_stacks[ stack_mode::gl_modelview ].data(); }
case GL_PROJECTION: { return m_stacks[ stack_mode::gl_projection ].data(); }
case GL_TEXTURE: { return m_stacks[ stack_mode::gl_texture ].data(); }
default: { return m_stacks[ m_mode ].data(); } } }
float const *
data_array( GLuint const Mode = -1 ) const {
@@ -113,11 +127,16 @@ public:
pop_matrix() { m_stacks[ m_mode ].pop_matrix(); }
void
load_identity() { m_stacks[ m_mode ].load_identity(); }
void
load_matrix( glm::mat4 const &Matrix ) { m_stacks[ m_mode ].load_matrix( Matrix ); }
template <typename Type_>
void
load_matrix( Type_ const *Matrix ) { load_matrix( glm::make_mat4( Matrix ) ); }
template <typename Type_>
void
rotate( Type_ const Angle, Type_ const X, Type_ const Y, Type_ const Z ) {
m_stacks[ m_mode ].rotate(
static_cast<float>(Angle) * 0.0174532925f, // deg2rad
static_cast<float>(glm::radians(Angle)),
glm::vec3(
static_cast<float>(X),
static_cast<float>(Y),
@@ -141,10 +160,20 @@ public:
m_stacks[m_mode].load(
glm::make_mat4(Matrix)); }
template <typename Type_>
void
ortho( Type_ const Left, Type_ const Right, Type_ const Bottom, Type_ const Top, Type_ const Znear, Type_ const Zfar ) {
m_stacks[ m_mode ].ortho(
static_cast<float>( Left ),
static_cast<float>( Right ),
static_cast<float>( Bottom ),
static_cast<float>( Top ),
static_cast<float>( Znear ),
static_cast<float>( Zfar ) ); }
template <typename Type_>
void
perspective( Type_ const Fovy, Type_ const Aspect, Type_ const Znear, Type_ const Zfar ) {
m_stacks[ m_mode ].perspective(
static_cast<float>(Fovy) * 0.0174532925f, // deg2rad
static_cast<float>( glm::radians( Fovy ) ),
static_cast<float>( Aspect ),
static_cast<float>( Znear ),
static_cast<float>( Zfar ) ); }
@@ -179,6 +208,8 @@ extern opengl_matrices OpenGLMatrices;
#define glPushMatrix OpenGLMatrices.push_matrix
#define glPopMatrix OpenGLMatrices.pop_matrix
#define glLoadIdentity OpenGLMatrices.load_identity
#define glLoadMatrixf OpenGLMatrices.load_matrix
#define glLoadMatrixd OpenGLMatrices.load_matrix
#define glRotated OpenGLMatrices.rotate
#define glRotatef OpenGLMatrices.rotate
#define glTranslated OpenGLMatrices.translate
@@ -186,8 +217,9 @@ extern opengl_matrices OpenGLMatrices;
// NOTE: no scale override as we aren't using it anywhere
#define glMultMatrixd OpenGLMatrices.multiply
#define glMultMatrixf OpenGLMatrices.multiply
#define glOrtho OpenGLMatrices.ortho
#define gluPerspective OpenGLMatrices.perspective
#define gluLookAt OpenGLMatrices.look_at
#define glLoadMatrixf OpenGLMatrices.load
//---------------------------------------------------------------------------
#endif