CSEngine
Loading...
Searching...
No Matches
CSE::DrawableStaticMeshComponent Class Reference
Inheritance diagram for CSE::DrawableStaticMeshComponent:
CSE::SComponent CSE::SObject CSE::SISComponent CSE::VariableBinder CSE::DrawableSkinnedMeshComponent

Public Member Functions

 COMPONENT_DEFINE_CONSTRUCTOR (DrawableStaticMeshComponent)
 
void Init () override
 
void Tick (float elapsedTime) override
 
void Exterminate () override
 
SComponentClone (SGameObject *object) override
 
virtual bool SetMesh (const SISurface &meshSurface)
 
const GLMeshIDGetMeshID () const
 
- Public Member Functions inherited from CSE::SComponent
 SComponent (std::string classType, SGameObject *gameObject)
 
 SComponent (const SComponent &src)
 
void Start () override
 
virtual void CopyReference (SComponent *src, std::map< SGameObject *, SGameObject * > lists_obj, std::map< SComponent *, SComponent * > lists_comp)
 
virtual auto GetComponent () -> SObject *
 
void SetValue (std::string name_str, Arguments value) override
 
std::string PrintValue () const override
 
void SetGameObject (SGameObject *object)
 
virtual SGameObjectGetGameObject () const
 
virtual bool GetIsEnable () const
 
virtual void SetIsEnable (bool is_enable)
 
std::string GetClassType () const
 
void SetClassType (std::string type)
 
- Public Member Functions inherited from CSE::SObject
 SObject (bool isRegister)
 
virtual void SetUndestroyable (bool enable)
 
virtual void Destroy ()
 
virtual void __FORCE_DESTROY__ ()
 
virtual std::string GenerateMeta ()
 
std::string GetHash () const
 
virtual void SetHash (std::string &hash)
 
- Public Member Functions inherited from CSE::SISComponent
 SISComponent (const SISComponent &src)=default
 

Protected Member Functions

virtual void CreateMeshBuffers (const SISurface &surface)
 

Protected Attributes

GLMeshID m_meshId
 
- Protected Attributes inherited from CSE::SComponent
SGameObjectgameObject = nullptr
 
bool isEnable = true
 
std::string m_classType
 
- Protected Attributes inherited from CSE::SObject
std::string m_hash
 

Additional Inherited Members

- Protected Types inherited from CSE::VariableBinder
typedef std::vector< std::string > Arguments
 

Detailed Description

Definition at line 8 of file DrawableStaticMeshComponent.h.

Member Function Documentation

◆ Clone()

SComponent * DrawableStaticMeshComponent::Clone ( SGameObject object)
overridevirtual

Reimplemented from CSE::SComponent.

Definition at line 105 of file DrawableStaticMeshComponent.cpp.

105 {
106 INIT_COMPONENT_CLONE(DrawableStaticMeshComponent, comp);
107
108 comp->m_meshId = m_meshId;
109 return comp;
110}

◆ CreateMeshBuffers()

void DrawableStaticMeshComponent::CreateMeshBuffers ( const SISurface surface)
protectedvirtual

Definition at line 50 of file DrawableStaticMeshComponent.cpp.

50 {
51 // Create the VAO for the VBO
52 GLuint vertexArray;
53 glGenVertexArrays(1, &vertexArray);
54 glBindVertexArray(vertexArray);
55
56 // Create the VBO for the vertices.
57 std::vector<float> vertices;
58 surface.GenerateVertices(vertices);
59 GLuint vertexBuffer;
60 glGenBuffers(1, &vertexBuffer);
61 glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
62 glBufferData(GL_ARRAY_BUFFER,
63 vertices.size() * sizeof(vertices[0]),
64 &vertices[0],
65 GL_STATIC_DRAW);
66
67
68 // Create a new VBO for the indices if needed.
69 int vertexCount = surface.GetVertexCount();
70 int indexCount = surface.GetTriangleIndexCount();
71 GLuint indexBuffer;
72
73
74 // Set exception to not using indices when index count is 0 or lower.
75 if (indexCount < 0) {
76 indexBuffer = 0;
77 indexCount = -1;
78
79 } else {
80 std::vector<GLushort> indices(indexCount);
81 surface.GenerateTriangleIndices(indices);
82 glGenBuffers(1, &indexBuffer);
83 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
84 glBufferData(GL_ELEMENT_ARRAY_BUFFER,
85 indexCount * 3 * sizeof(GLushort),
86 &indices[0],
87 GL_STATIC_DRAW);
88 }
89
90
91 //Pulling data
92 surface.m_meshId.m_vertexBuffer = vertexBuffer;
93 surface.m_meshId.m_vertexSize = vertexCount;
94 surface.m_meshId.m_indexBuffer = indexBuffer;
95 surface.m_meshId.m_indexSize = indexCount;
96 surface.m_meshId.m_vertexArray = vertexArray;
97
98 m_meshId = surface.m_meshId;
99
100 //Unbinding
101 glBindBuffer(GL_ARRAY_BUFFER, 0);
102 glBindVertexArray(0);
103}

◆ Exterminate()

void DrawableStaticMeshComponent::Exterminate ( )
overridevirtual

Implements CSE::SObject.

Definition at line 23 of file DrawableStaticMeshComponent.cpp.

23 {
24
25 // const GLuint vertexBuffer = m_meshId.m_vertexBuffer;
26 // const GLuint indexBuffer = m_meshId.m_indexBuffer;
27
28 // glDeleteBuffers(1, &vertexBuffer);
29 // glDeleteBuffers(1, &indexBuffer);
30}

◆ GetMeshID()

const GLMeshID & CSE::DrawableStaticMeshComponent::GetMeshID ( ) const
inline

Definition at line 24 of file DrawableStaticMeshComponent.h.

24 {
25 return m_meshId;
26 }

◆ Init()

void DrawableStaticMeshComponent::Init ( )
overridevirtual

Implements CSE::SISComponent.

Definition at line 15 of file DrawableStaticMeshComponent.cpp.

15 {
16}

◆ SetMesh()

bool DrawableStaticMeshComponent::SetMesh ( const SISurface meshSurface)
virtual

Definition at line 33 of file DrawableStaticMeshComponent.cpp.

33 {
34
35 if (m_meshId.m_vertexSize != -1 || m_meshId.m_vertexBuffer != -1) return false;
36
37 if (meshSurface.m_meshId.m_vertexSize != -1
38 || meshSurface.m_meshId.m_vertexBuffer != -1) {
39 m_meshId = meshSurface.m_meshId;
40 return true;
41
42 }
43
44 CreateMeshBuffers(meshSurface);
45
46 return true;
47}

◆ Tick()

void DrawableStaticMeshComponent::Tick ( float  elapsedTime)
overridevirtual

Implements CSE::SISComponent.

Definition at line 19 of file DrawableStaticMeshComponent.cpp.

19 {
20}

Member Data Documentation

◆ m_meshId

GLMeshID CSE::DrawableStaticMeshComponent::m_meshId
protected

Definition at line 32 of file DrawableStaticMeshComponent.h.


The documentation for this class was generated from the following files: