-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLight.h
85 lines (74 loc) · 3.17 KB
/
Light.h
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
#ifndef LIGHT_H
#define LIGHT_H
#include <SDL2/SDL_opengl.h>
#include "Vec4.h"
#include "UBOUniform.h"
#include <map>
#include <string>
const static int numUniforms = 11;
class Light
{
public:
Light(int index, GLsizei offset, GLint bufferSize, GLint numElements, const char *uniformNames[numUniforms], GLuint *indices, GLint *sizes, GLint *offsets, GLint *types);
Light(const Light ©);
virtual ~Light();
Light &operator=(const Light &other);
void setIsEnabled(GLboolean enabled);
void enableDiffuse(GLboolean enabled);
void enableSpecular(GLboolean enabled);
void setIsSpotLight(GLboolean enabled);
void setIsPointLight(GLboolean enabled);
void setSpecularMode(GLboolean specularMode);
void setAmbientLight(Vec4<GLfloat> light);
void setDiffuseLight(Vec4<GLfloat> light);
void setSpecularLight(Vec4<GLfloat> light);
void setShininess(GLfloat shininess);
void setStrength(GLfloat strength);
void setPosition(Vec4<GLfloat> pos);
void setNormal(Vec4<GLfloat> normal);
void setAngle(GLfloat angle);
void setLinearAtten(GLfloat linearAtten);
void setQuadAtten(GLfloat quagAtten);
void setConstAttenuation(GLfloat constAtten);
void setSpotponent(GLfloat spotponent);
char *getLightData();
GLboolean getIsEnabled();
GLboolean getIsDiffuseEnabled();
GLboolean getIsSpecularEnabled();
GLboolean getIsSpotLight();
GLboolean getIsPointLight();
GLboolean getSpecularMode();
Vec4<GLfloat> getAmbientLight();
Vec4<GLfloat> getDiffuseLight();
Vec4<GLfloat> getSpecularLight();
GLfloat getShininess();
GLfloat getStrength();
GLfloat getLinearAtten();
GLfloat getQuadAtten();
GLfloat getConstAttenuation();
GLfloat getSpotponent();
int getIndex();
size_t getDataSize();
template <class T> void set(std::string uboname, T *data)
{
UBOUniform ubo = uniforms[uboname];
size_t size = ubo.getSize() * typeSize(ubo.getType());
memcpy(lightData + ubo.getOffset(), data, size);
}
template <class T> T get(std::string uboname)
{
T data;
UBOUniform ubo = uniforms[uboname];
size_t size = ubo.getSize() * typeSize(ubo.getType());
memcpy(&data, lightData + ubo.getOffset(), size);
return data;
}
size_t typeSize(GLenum type);
protected:
private:
size_t dataSize;
char *lightData;
std::map<std::string, UBOUniform> uniforms;
int index;
};
#endif // LIGHT_H