aboutsummaryrefslogtreecommitdiff
path: root/libs/preview_nif/src/OpenGLShape.h
blob: b53e96da81a84346af33b45565e55808024ecd68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#pragma once

#include "ShaderManager.h"
#include "TextureManager.h"

#include <Geometry.hpp>
#include <NifFile.hpp>

#include <QOpenGLBuffer>
#include <QOpenGLShaderProgram>
#include <QOpenGLTexture>
#include <QOpenGLVertexArrayObject>
#include <QWidget>

enum TextureSlot
{
    BaseMap = 0,
    NormalMap = 1,
    GlowMap = 2,
    LightMask = 2,
    HeightMap = 3,
    DetailMask = 3,
    EnvironmentMap = 4,
    EnvironmentMask = 5,
    TintMask = 6,
    InnerMap = 6,
    BacklightMap = 7,
    SpecularMap = 7,
};

struct OpenGLShape
{
public:
    OpenGLShape(
        nifly::NifFile* nifFile,
        nifly::NiShape* niShape,
        TextureManager* textureManager);

    void destroy();
    void setupShaders(QOpenGLShaderProgram* program);

    static QVector2D convertVector2(nifly::Vector2 vector);
    static QVector3D convertVector3(nifly::Vector3 vector);
    static QColor convertColor(nifly::Color4 color);
    static QMatrix4x4 convertTransform(nifly::MatTransform transform);

    ShaderManager::ShaderType shaderType = ShaderManager::SKDefault;

    QOpenGLVertexArrayObject* vertexArray = nullptr;

    QOpenGLBuffer* vertexBuffers[ATTRIB_COUNT] { nullptr };

    QOpenGLBuffer* indexBuffer = nullptr;
    GLsizei elements = 0;

    std::array<QOpenGLTexture*, 13> textures { nullptr };

    QMatrix4x4 modelMatrix;
    QVector3D specColor{ 1.0f, 1.0f, 1.0f };
    float specStrength = 1.0f ;
    float specGlossiness = 1.0f;
    float fresnelPower;

    float paletteScale;

    bool hasGlowMap = false;
    QColor glowColor = QColorConstants::White;
    float glowMult = 1.0f;

    float alpha = 1.0f;
    QVector3D tintColor{ 1.0f, 1.0f, 1.0f };

    QVector2D uvScale{ 1.0f, 1.0f };
    QVector2D uvOffset{ 0.0f, 0.0f };

    bool hasEmit = false;
    bool hasSoftlight = false;
    bool hasBacklight = false;
    bool hasRimlight = false;
    bool hasTintColor = false;
    bool hasWeaponBlood = false;

    bool doubleSided = false;
    float softlight = 0.3f;
    float backlightPower = 0.0f;
    float rimPower = 2.0f;
    float subsurfaceRolloff;
    float envReflection = 1.0f;

    QVector2D innerScale;
    float innerThickness;
    float outerRefraction;
    float outerReflection;

    bool zBufferWrite = true;
    bool zBufferTest = true;
    bool isDecal = false;

    bool alphaBlendEnable = false;
    GLenum srcBlendMode = GL_ONE;
    GLenum dstBlendMode = GL_ONE;
    bool alphaTestEnable = false;
    GLenum alphaTestMode = GL_GREATER;
    float alphaThreshold = 0.0f;
};