Skip to content

Commit 4451957

Browse files
committed
Implemented thread-safe queue.
Other general cleaning. Started making the Light class actually do something.
1 parent 931f0fb commit 4451957

17 files changed

+188
-77
lines changed

.gitattributes

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
7+
# Standard to msysgit
8+
*.doc diff=astextplain
9+
*.DOC diff=astextplain
10+
*.docx diff=astextplain
11+
*.DOCX diff=astextplain
12+
*.dot diff=astextplain
13+
*.DOT diff=astextplain
14+
*.pdf diff=astextplain
15+
*.PDF diff=astextplain
16+
*.rtf diff=astextplain
17+
*.RTF diff=astextplain

ShaderViewer/.vs/MP-APS/v15/.suo

5 KB
Binary file not shown.
0 Bytes
Binary file not shown.

ShaderViewer/GLRenderer.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@ void GLRenderer::Update(const double glfwTimer) {
164164
m_camera.ProcessKeyboard(Camera::DOWN, deltaTime);
165165
}
166166

167-
// Update Mouse
168-
169167

170168
// Update view matrix inside UBO
171169
const auto view = m_camera.GetViewMatrix();

ShaderViewer/IRenderer.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#pragma once
2-
#include <array>
2+
#include <vector>
33

44
#include "Timer.h"
5+
#include "Light.h"
56

67
#define KEY_PRESSED(KEY) (IRenderer::m_keys.at(KEY) = true, (void)0 )
78
#define KEY_RELEASED(KEY) (IRenderer::m_keys.at(KEY) = false, (void)0 )
89

910
class IRenderer {
10-
11+
typedef std::array<float, 3> Vec3;
1112
public:
1213
IRenderer(const size_t width, const size_t height) : m_width(width), m_height(height) {}
1314
virtual ~IRenderer() {}
@@ -23,14 +24,14 @@ class IRenderer {
2324
// Deferred Stuff
2425
virtual void BeginGeometryPass() const = 0;
2526
virtual void EndGeometryPass() const = 0;
26-
2727
virtual void BeginLightingPass() const = 0;
2828

29+
virtual void AddLight(const Vec3 Position, const Vec3 Color, const Light::LightType Type) { m_lights.emplace_back(Position, Color, Type); }
30+
2931
static std::array<bool, 1024> m_keys;
3032

3133
protected:
3234
size_t m_width, m_height;
33-
3435
Timer m_timer;
3536

3637
const std::array<float, 20> m_screenQuadVertices = {
@@ -40,5 +41,8 @@ class IRenderer {
4041
1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
4142
1.0f, -1.0f, 0.0f, 1.0f, 0.0f
4243
};
44+
45+
// Maybe private this later...
46+
std::vector<Light> m_lights;
4347
};
4448

ShaderViewer/Light.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <glm//gtc/matrix_transform.hpp>
77

88
/***********************************************************************************/
9-
Light::Light(const glm::vec3& Position, const glm::vec3& Color, const LightType lightType) : m_position(Position), m_color(Color) {
9+
Light::Light(const Vec3 Position, const Vec3 Color, const LightType lightType) : m_position(Position), m_color(Color) {
1010

1111
glGenVertexArrays(1, &m_vao);
1212
glGenBuffers(1, &m_vbo);
@@ -18,16 +18,14 @@ Light::Light(const glm::vec3& Position, const glm::vec3& Color, const LightType
1818

1919
// Vertex Positions
2020
glEnableVertexAttribArray(0);
21-
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, static_cast<GLvoid*>(0));
22-
23-
glBindVertexArray(0);
21+
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
2422
}
2523

2624
/***********************************************************************************/
2725
Light::~Light() {
2826
}
2927

30-
/***********************************************************************************/
28+
/***********************************************************************************
3129
void Light::Draw(GLShaderProgram& shader) {
3230
3331
shader.Bind();
@@ -42,3 +40,4 @@ void Light::Draw(GLShaderProgram& shader) {
4240
glDrawArrays(GL_TRIANGLES, 0, 36);
4341
glBindVertexArray(0);
4442
}
43+
*/

ShaderViewer/Light.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
#pragma once
22

33
#include <GL/glew.h>
4-
#include <glm/gtc/type_ptr.hpp>
4+
#include <array>
55

66
class GLShaderProgram;
77

88
class Light {
9+
typedef std::array<float, 3> Vec3;
910
public:
1011

1112
enum LightType {
@@ -14,14 +15,14 @@ class Light {
1415
DIRLIGHT
1516
};
1617

17-
Light(const glm::vec3& Position, const glm::vec3& Color, const LightType lightType);
18+
Light(const Vec3 Position, const Vec3 Color, const LightType lightType);
1819
~Light();
1920

20-
void Draw(GLShaderProgram& shader);
21+
//void Draw(GLShaderProgram& shader);
2122

2223
private:
23-
glm::vec3 m_position;
24-
glm::vec3 m_color;
24+
Vec3 m_position;
25+
Vec3 m_color;
2526

2627
GLuint m_vao, m_vbo;
2728
};

ShaderViewer/Material.h

-8
This file was deleted.

ShaderViewer/Mesh.cpp

-6
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ void Mesh::SetInstancing(const std::initializer_list<glm::vec3>& args) {
3636
glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), nullptr);
3737
glBindBuffer(GL_ARRAY_BUFFER, 0);
3838
glVertexAttribDivisor(3, 1); // Tell OpenGL this is an instanced vertex attribute.
39-
40-
glBindVertexArray(0);
4139
}
4240

4341
/***********************************************************************************/
@@ -48,7 +46,6 @@ void Mesh::Draw(GLShaderProgram& shader) {
4846
// Draw mesh
4947
glBindVertexArray(m_vao);
5048
glDrawElements(GL_TRIANGLES, m_indices.size(), GL_UNSIGNED_INT, nullptr);
51-
glBindVertexArray(0);
5249
}
5350

5451
/***********************************************************************************/
@@ -59,7 +56,6 @@ void Mesh::DrawInstanced(GLShaderProgram& shader) {
5956
// Draw instanced mesh
6057
glBindVertexArray(m_vao);
6158
glDrawElementsInstanced(GL_TRIANGLES, m_indices.size(), GL_UNSIGNED_INT, nullptr, m_instanceOffsets.size());
62-
glBindVertexArray(0);
6359
}
6460

6561
/***********************************************************************************/
@@ -121,6 +117,4 @@ void Mesh::setupMesh() {
121117
// Vertex Texture Coords
122118
glEnableVertexAttribArray(2);
123119
glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), reinterpret_cast<GLvoid*>(offsetof(Vertex, TexCoords)));
124-
125-
glBindVertexArray(0);
126120
}

ShaderViewer/Mesh.h

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
#include "Texture.h"
88
#include "GLShaderProgram.h"
99

10+
/***********************************************************************************/
11+
struct Material {
12+
Material(const std::string_view Name) : name(Name) {};
13+
14+
const std::string name;
15+
16+
17+
bool wireframe = false;
18+
};
19+
1020
/***********************************************************************************/
1121
struct Vertex {
1222
glm::vec3 Position;

ShaderViewer/Model.cpp

+14-25
Original file line numberDiff line numberDiff line change
@@ -106,43 +106,33 @@ Mesh Model::processMesh(aiMesh* mesh, const aiScene* scene) {
106106

107107
for (GLuint i = 0; i < mesh->mNumVertices; ++i) {
108108
Vertex vertex;
109-
glm::vec3 vector; // We declare a placeholder vector since assimp uses its own vector class that doesn't directly convert to glm's vec3 class so we transfer the data to this placeholder glm::vec3 first.
110-
111-
// Positions
109+
112110
if (mesh->HasPositions()) {
113-
vector.x = mesh->mVertices[i].x;
114-
vector.y = mesh->mVertices[i].y;
115-
vector.z = mesh->mVertices[i].z;
116-
vertex.Position = vector;
111+
vertex.Position.x = mesh->mVertices[i].x;
112+
vertex.Position.y = mesh->mVertices[i].y;
113+
vertex.Position.z = mesh->mVertices[i].z;
117114
}
118115

119-
// Normals
120116
if (mesh->HasNormals()) {
121-
vector.x = mesh->mNormals[i].x;
122-
vector.y = mesh->mNormals[i].y;
123-
vector.z = mesh->mNormals[i].z;
124-
vertex.Normal = vector;
117+
vertex.Normal.x = mesh->mNormals[i].x;
118+
vertex.Normal.y = mesh->mNormals[i].y;
119+
vertex.Normal.z = mesh->mNormals[i].z;
125120
}
126121

127-
// Tangents
128122
if (mesh->HasTangentsAndBitangents()) {
129-
vector.x = mesh->mTangents[i].x;
130-
vector.y = mesh->mTangents[i].y;
131-
vector.z = mesh->mTangents[i].z;
132-
vertex.Tangent = vector;
123+
vertex.Tangent.x = mesh->mTangents[i].x;
124+
vertex.Tangent.y = mesh->mTangents[i].y;
125+
vertex.Tangent.z = mesh->mTangents[i].z;
133126
}
134127

135-
// Texture Coordinates
136-
if (mesh->mTextureCoords[0]) { // Does the mesh contain texture coordinates?
137-
glm::vec2 vec;
128+
if (mesh->HasTextureCoords(0)) {
138129
// A vertex can contain up to 8 different texture coordinates. We thus make the assumption that we won't
139130
// use models where a vertex can have multiple texture coordinates so we always take the first set (0).
140-
vec.x = mesh->mTextureCoords[0][i].x;
141-
vec.y = mesh->mTextureCoords[0][i].y;
142-
vertex.TexCoords = vec;
131+
vertex.TexCoords.x = mesh->mTextureCoords[0][i].x;
132+
vertex.TexCoords.y = mesh->mTextureCoords[0][i].y;
143133
}
144134
else {
145-
vertex.TexCoords = glm::vec2(0.0f, 0.0f);
135+
vertex.TexCoords = glm::vec2(0.0f);
146136
}
147137
vertices.push_back(vertex);
148138
}
@@ -169,7 +159,6 @@ Mesh Model::processMesh(aiMesh* mesh, const aiScene* scene) {
169159

170160
// 1. Diffuse maps
171161
const auto diffuseMaps = loadMatTextures(material, aiTextureType_DIFFUSE, "texture_diffuse");
172-
173162
textures.insert(textures.end(), diffuseMaps.begin(), diffuseMaps.end());
174163

175164
// 2. Specular maps

ShaderViewer/ShaderViewer.vcxproj

+1-2
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@
162162
<ClCompile Include="HUDText.cpp" />
163163
<ClCompile Include="Light.cpp" />
164164
<ClCompile Include="main.cpp" />
165-
<ClCompile Include="Material.cpp" />
166165
<ClCompile Include="Mesh.cpp" />
167166
<ClCompile Include="Model.cpp" />
168167
<ClCompile Include="GLRenderer.cpp" />
@@ -182,7 +181,6 @@
182181
<ClInclude Include="HUDText.h" />
183182
<ClInclude Include="IRenderer.h" />
184183
<ClInclude Include="Light.h" />
185-
<ClInclude Include="Material.h" />
186184
<ClInclude Include="Mesh.h" />
187185
<ClInclude Include="Model.h" />
188186
<ClInclude Include="GLRenderer.h" />
@@ -194,6 +192,7 @@
194192
<ClInclude Include="Texture.h" />
195193
<ClInclude Include="Timer.h" />
196194
<ClInclude Include="Utils.h" />
195+
<ClInclude Include="Utils\Queue.h" />
197196
</ItemGroup>
198197
<ItemGroup>
199198
<None Include="..\README.md" />

ShaderViewer/ShaderViewer.vcxproj.filters

+1-4
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@
5959
<ClCompile Include="GLShaderProgram.cpp">
6060
<Filter>Source Files</Filter>
6161
</ClCompile>
62-
<ClCompile Include="Material.cpp">
63-
<Filter>Source Files</Filter>
64-
</ClCompile>
6562
</ItemGroup>
6663
<ItemGroup>
6764
<ClInclude Include="Shader.h">
@@ -118,7 +115,7 @@
118115
<ClInclude Include="Utils.h">
119116
<Filter>Header Files</Filter>
120117
</ClInclude>
121-
<ClInclude Include="Material.h">
118+
<ClInclude Include="Utils\Queue.h">
122119
<Filter>Header Files</Filter>
123120
</ClInclude>
124121
</ItemGroup>

ShaderViewer/Skybox.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ Skybox::Skybox(const std::string& TextureDirectory) {
1515
glBufferData(GL_ARRAY_BUFFER, sizeof(m_skyboxVertices), &m_skyboxVertices, GL_STATIC_DRAW);
1616
glEnableVertexAttribArray(0);
1717
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), nullptr);
18-
// Cleanup
19-
glBindVertexArray(0);
2018

2119
// Iterate through given directory and find files (labeled 1-6 for proper load order)
2220
int i = 0; // Index for the loop
@@ -34,7 +32,7 @@ Skybox::Skybox(const std::string& TextureDirectory) {
3432
int n = 0;
3533
i = 0; // Index for the loop
3634
for (auto& face : m_faces) {
37-
image = ResourceLoader::LoadSTBImage(face.c_str(), &x, &y, &n, ResourceLoader::RGB); // 3 = STB_rgb
35+
image = ResourceLoader::LoadSTBImage(face.c_str(), &x, &y, &n, ResourceLoader::RGB);
3836

3937
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, x, y, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
4038
glGenerateMipmap(GL_TEXTURE_2D);
@@ -83,7 +81,5 @@ void Skybox::Draw(GLShaderProgram& shader, const glm::mat4& CameraMatrix, const
8381
glBindTexture(GL_TEXTURE_CUBE_MAP, m_textureID);
8482
glDrawArrays(GL_TRIANGLES, 0, 36);
8583

86-
// Cleanup
87-
glBindVertexArray(0);
8884
glDepthFunc(GL_LESS); // Set depth function back to default
8985
}

ShaderViewer/Texture.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ Texture::Texture(const std::string_view ModelPath, const std::string_view Textur
1212
glGenTextures(1, &m_texture);
1313
glBindTexture(GL_TEXTURE_2D, m_texture);
1414
// Set texture parameters
15-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrapMode);
16-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrapMode);
15+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
16+
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
1717
// Texture filtering
1818
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // linearly interpolates between the two closest mipmaps and samples the texture via linear interpolation.
1919
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Mipmaps do not apply to magnification.

0 commit comments

Comments
 (0)