Skip to content

Commit 5310305

Browse files
author
Cheng Xie
committed
Wrapped QGLShaderProgram to Shader for future extension.
1 parent 24dae0c commit 5310305

14 files changed

+29
-18
lines changed

src/camera.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "camera.h"
22
#include "drawcontext.h"
3-
#include <QGLShaderProgram>
3+
#include "Shader.h"
44

55
Camera::Camera()
66
{

src/common.h

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ class SceneObject;
3939
class Scene;
4040
class CameraController;
4141
class Texture;
42-
class QGLShaderProgram;
4342
class MeshRenderer;
4443

4544
inline float randf() {

src/directlight.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "directlight.h"
22
#include "drawcontext.h"
3-
#include <QGLShaderProgram>
3+
#include "shader.h"
44

55
DirectLight::DirectLight(const vec3 &direction, const Color &color)
66
: direction_(direction),

src/drawcontext.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,15 @@
44
#include "geometry.h"
55
#include "common.h"
66
#include "scene.h"
7-
8-
class QGLShaderProgram;
7+
#include "shader.h"
98

109
class DrawContext
1110
{
1211
public:
1312
Camera* camera = NULL;
1413

1514
// Currently enabled shader
16-
QGLShaderProgram* shader = NULL;
15+
Shader* shader = NULL;
1716

1817
// Time elapsed since last frame
1918
float deltaTime = 0;

src/final.pro

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ SOURCES += main.cpp \
3535
particlesystem.cpp \
3636
meshrenderer.cpp \
3737
phongmaterial.cpp \
38-
particlematerial.cpp
38+
particlematerial.cpp \
39+
shader.cpp
3940

4041
HEADERS += mainwindow.h \
4142
view.h \
@@ -59,6 +60,7 @@ HEADERS += mainwindow.h \
5960
particlesystem.h \
6061
meshrenderer.h \
6162
phongmaterial.h \
62-
particlematerial.h
63+
particlematerial.h \
64+
shader.h
6365

6466
FORMS += mainwindow.ui

src/material.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define MATERIAL_H
33

44
#include "common.h"
5+
#include "shader.h"
56

67
class Material
78
{
@@ -11,7 +12,7 @@ class Material
1112
virtual void endRender() {}
1213

1314
protected:
14-
QGLShaderProgram *shader_ = NULL;
15+
Shader *shader_ = NULL;
1516
};
1617

1718
#endif // MATERIAL_H

src/particlematerial.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "particlematerial.h"
2-
#include <QGLShaderProgram>
2+
#include "shader.h"
33
#include "shadercache.h"
44
#include "drawcontext.h"
55
#include "texture.h"

src/phongmaterial.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <GL/glew.h>
22
#include "PhongMaterial.h"
3-
#include <QGLShaderProgram>
3+
#include "shader.h"
44
#include "shadercache.h"
55
#include "drawcontext.h"
66
#include "texture.h"

src/sceneobject.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "drawcontext.h"
33
#include "camera.h"
44
#include "light.h"
5-
#include <QGLShaderProgram>
5+
#include "shader.h"
66

77
SceneObject::SceneObject()
88
{

src/shader.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "shader.h"
2+

src/shader.h

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef SHADER_H
2+
#define SHADER_H
3+
4+
#include <QGLShaderProgram>
5+
6+
typedef QGLShaderProgram Shader;
7+
8+
#endif // SHADER_H

src/shadercache.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ ShaderCache::~ShaderCache()
1717
delete g_instance;
1818
}
1919

20-
unique_ptr<QGLShaderProgram> ShaderCache::loadResource(string shader)
20+
unique_ptr<Shader> ShaderCache::loadResource(string shader)
2121
{
2222
string path = "shaders/";
2323

2424
string vertexShader = path + shader + ".vs";
2525
string geometryShader = path + shader + ".gs";
2626
string fragmentShader = path + shader + ".fs";
2727

28-
unique_ptr<QGLShaderProgram> p(new QGLShaderProgram);
28+
unique_ptr<Shader> p(new Shader);
2929

3030
bool result;
3131

src/shadercache.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
#define SHADERCACHE_H
33

44
#include <resourcecache.h>
5-
#include <QGLShaderProgram>
5+
#include "shader.h"
66

7-
class ShaderCache : public ResourceCache<QGLShaderProgram>
7+
class ShaderCache : public ResourceCache<Shader>
88
{
99
public:
1010
static ShaderCache* getInstance();
1111

1212
private:
1313
virtual ~ShaderCache();
14-
virtual unique_ptr<QGLShaderProgram> loadResource(string name) override;
14+
virtual unique_ptr<Shader> loadResource(string name) override;
1515
};
1616

1717
#endif // SHADERCACHE_H

src/texture.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <GL/glew.h>
22
#include "texture.h"
33
#include "drawcontext.h"
4-
#include <QGLShaderProgram>
4+
#include "shader.h"
55
#include <QImage>
66
#include <QFile>
77

0 commit comments

Comments
 (0)