SuzanneIsland: An island of Real-time rendering effects!
surface.h
1 #pragma once
2 
3 #include <vector>
4 #include <memory>
5 #include <stddef.h>
6 
7 #include <glm/gtc/type_ptr.hpp>
8 
9 #include "shader.h"
10 #include "texture.hpp"
11 
12 
14 struct Vertex {
15  glm::vec3 position;
16  glm::vec3 normal;
17  glm::vec2 uv;
18 };
19 
25 class Surface
26 {
27  // Mesh Data
28  std::vector<Vertex> vertices;
29  std::vector<GLuint> indices; // indices associate vertices to define mesh topology
30 
31  // Bounding Sphere
32  // for view frustum culling
33  glm::vec3 boundingSphereCenter;
34  glm::vec3 boundingSphereFarthestPoint;
35 
36  // Textures
37  std::shared_ptr<Texture> texDiffuse, texSpecular, texNormal;
38 
39  // handle for vertex array object (vao). the vao simply stores the bindings set when its active
40  // so that they can be reactived quickly later, instead of setting it up all over again.
41  GLuint vao;
42 
43  // handles for vram buffers.
44  GLuint vertexBuffer, indexBuffer;
45 
49  void initBuffers();
50 
51 public:
52  Surface(const std::vector<Vertex> &vertices_, const std::vector<GLuint> &indices_, const std::shared_ptr<Texture> &texDiffuse_, const std::shared_ptr<Texture> &texSpecular_, const std::shared_ptr<Texture> &texNormal_);
53  ~Surface();
54 
55  std::vector<Vertex> getVertices();
56  std::vector<GLuint> getIndices();
57 
63  void draw(Shader *shader, Texture::FilterType filterType);
64 
70  glm::vec3 getBoundingSphereCenter();
71 
78  glm::vec3 getBoundingSphereFarthestPoint();
79 
80 private:
85  void calculateBoundingSphere();
86 };
87 
A Surface holds mesh data (vertex data and indices) and textures.
Definition: surface.h:25
Shader class.
Definition: shader.h:15
Vertex struct for internal representation.
Definition: surface.h:14