2 #ifndef KJY_OBJECT_ORIENTED_OPENGL_GEOMETRY_HPP_ 3 #define KJY_OBJECT_ORIENTED_OPENGL_GEOMETRY_HPP_ 4 #include "../OOOGL_Core.hpp" 5 #include "../GLobjects/VertexArrayObject.hpp" 17 vertex_array_object.linkArrayBuffer(0, vertex_position_buffer);
18 sync_status_ = GpuSyncStatus::GPU_CURRENT;
21 VertexGeometry(
const std::vector<glm::vec3>& vertices,
const std::vector<GLuint> elements,
bool skip_gpu_upload =
false,
bool skip_measurement =
false) {
22 cpu_vertex_buffer_ = vertices;
23 cpu_element_buffers_.emplace_back(elements);
24 if(!skip_gpu_upload) uploadToGpu();
25 vertex_array_object.linkArrayBuffer(msPositionAttrIndex, vertex_position_buffer);
27 sync_status_ = GpuSyncStatus::GPU_CURRENT;
30 static const GLuint msPositionAttrIndex;
32 virtual void autoSetupForDraw();
33 virtual void autoCleanupAfterDraw();
35 virtual const glm::vec3& getMinPoint() {
return(min_point_);}
36 virtual const glm::vec3& getMaxPoint() {
return(max_point_);}
38 virtual void normalize();
39 virtual void uploadToGpu();
40 virtual GpuSyncStatus getSyncStatus()
const {
return(sync_status_);}
42 virtual const std::vector<glm::vec3>& getVertices()
const {
return(cpu_vertex_buffer_);}
43 virtual std::vector<glm::vec3>& getMutableVertices() {
return(cpu_vertex_buffer_); sync_status_ = GpuSyncStatus::GPU_STALE; measurement_current_ =
false;}
44 virtual void replaceVertices(
const std::vector<glm::vec3>& new_buffer) {cpu_vertex_buffer_ = new_buffer; sync_status_ = GpuSyncStatus::GPU_STALE; measurement_current_ =
false;}
46 virtual size_t numElementBuffers()
const {
return(cpu_element_buffers_.size());}
47 virtual const std::vector<GLuint>& getElements(
size_t index)
const {_assert_element_index_inbounds_(index);
return(cpu_element_buffers_[index]);}
48 virtual std::vector<GLuint>& getMutableElements(
size_t index) {_assert_element_index_inbounds_(index);
return(cpu_element_buffers_[index]); sync_status_ = GpuSyncStatus::GPU_STALE; measurement_current_ =
false;}
49 virtual void replaceElements(
size_t index,
const std::vector<GLuint>& new_buffer) {_assert_element_index_inbounds_(index); cpu_element_buffers_[index] = new_buffer; sync_status_ = GpuSyncStatus::GPU_STALE; measurement_current_ =
false;}
50 virtual void addElements(
const std::vector<GLuint>& new_buffer,
bool auto_add_element_array_buffer =
true) {
51 cpu_element_buffers_.emplace_back(new_buffer);
52 if(auto_add_element_array_buffer){
53 vertex_elements_buffers_.emplace_back();
55 sync_status_ = GpuSyncStatus::GPU_STALE; measurement_current_ =
false;
57 virtual ElementArrayBuffer getElementArrayBuffer(
size_t index) {_assert_element_index_inbounds_(index);
return(vertex_elements_buffers_[index]);}
58 virtual void replaceElementArrayBuffer(
size_t index,
const ElementArrayBuffer& buffer){_assert_element_index_inbounds_(index);vertex_elements_buffers_[index] = buffer;}
65 virtual void updateMeasurement();
66 virtual void linkElementBuffers();
68 virtual void _startGpuUpload();
69 virtual void _uploadData();
70 virtual void _finishGpuUpload();
72 void _measure_min_max_(
const std::vector<glm::vec3>& vertices, glm::vec3* min_point, glm::vec3* max_point);
73 void _normalize_vertices(std::vector<glm::vec3>& vertices,
const glm::vec3& min,
const glm::vec3& max);
75 bool measurement_current_ =
false;
76 GpuSyncStatus sync_status_ = GpuSyncStatus::GPU_UNINITIALIZED;
78 std::vector<glm::vec3> cpu_vertex_buffer_;
79 std::vector<std::vector<GLuint>> cpu_element_buffers_;
80 std::vector<ElementArrayBuffer> vertex_elements_buffers_;
82 glm::vec3 min_point_ = glm::vec3(0.0);
83 glm::vec3 max_point_ = glm::vec3(0.0);
86 inline void _assert_element_index_inbounds_(
size_t index)
const {
if(index >= cpu_element_buffers_.size())
throw GenericIndexOutOfBoundsException(index,
"VertexGeometry element buffers");}
94 const std::vector<glm::vec3>& vertices,
const std::vector<GLuint> elements,
95 const std::vector<glm::vec3>& normals,
const std::vector<glm::vec2>& texcoords,
96 bool skip_gpu_upload =
false);
98 static const GLuint msNormalAttrIndex;
99 static const GLuint msTexCoordAttrIndex;
101 virtual void autoSetupForDraw()
override;
102 virtual void autoCleanupAfterDraw()
override;
104 virtual const std::vector<glm::vec3>& getNormals()
const {
return(cpu_normals_buffer_);}
105 virtual std::vector<glm::vec3>& getMutableNormals() {
return(cpu_normals_buffer_); sync_status_ = GpuSyncStatus::GPU_STALE; }
106 virtual void replaceNormals(
const std::vector<glm::vec3>& new_buffer) {cpu_normals_buffer_ = new_buffer; sync_status_ = GpuSyncStatus::GPU_STALE; }
114 virtual const std::vector<glm::vec2>& getTextureCoords()
const {
return(cpu_texture_coords_);}
115 virtual std::vector<glm::vec2>& getMutableTextureCoords() {
return(cpu_texture_coords_); sync_status_ = GpuSyncStatus::GPU_STALE; }
116 virtual void replaceTextureCoords(
const std::vector<glm::vec2>& new_buffer) {cpu_texture_coords_ = new_buffer; sync_status_ = GpuSyncStatus::GPU_STALE; }
130 virtual void _uploadData()
override;
132 std::vector<glm::vec3> cpu_normals_buffer_;
133 bool mNormalsEnabled =
true;
134 std::vector<glm::vec2> cpu_texture_coords_;
135 bool mCoordsEnabled =
true;
141 using base_vector = std::vector<TriangleMesh>;
142 using size_type = base_vector::size_type;
143 using value_type = base_vector::value_type;
144 using allocator_type = base_vector::allocator_type;
146 TriangleMeshAggregate(size_type n,
const allocator_type& alloc = allocator_type()) : base_vector(n, alloc) {}
147 TriangleMeshAggregate(size_type n,
const value_type& value,
const allocator_type& alloc = allocator_type()) : base_vector(n, value, alloc) {}
148 TriangleMeshAggregate(std::initializer_list<TriangleMesh> init,
const allocator_type& alloc = allocator_type()) : base_vector(init, alloc) {}
Definition: Buffers.hpp:142
virtual bool areNormalsEnabled() const
Check if the vertex normals attribute is enabled.
Definition: Geometry.hpp:108
Definition: OOOGL_Core.hpp:133
Definition: Geometry.hpp:89
virtual void enableTextureCoords()
Disable the vertex normal attribute during auto setup.
Definition: Geometry.hpp:122
virtual bool areTextureCoordsEnabled() const
Check if the vertex normals attribute is enabled.
Definition: Geometry.hpp:118
virtual void disableTextureCoords()
Disable the vertex normal attribute during auto setup.
Definition: Geometry.hpp:120
Definition: OOOGL_Core.hpp:170
Definition: Geometry.hpp:140
virtual void enableNormals()
Disable the vertex normal attribute during auto setup.
Definition: Geometry.hpp:112
Definition: Core_Utilities.cpp:3
Definition: Buffers.hpp:106
virtual void disableNormals()
Disable the vertex normal attribute during auto setup.
Definition: Geometry.hpp:110
Definition: Geometry.hpp:14