VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
MeshInstance.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MESHINSTANCE_H
18 #define MESHINSTANCE_H
19 
20 #include "Mesh.h"
21 #include "RendererCommon.h"
22 #include "Shader.h"
23 #include <vector>
24 
35 class MeshInstance {
36 public:
40  MeshInstance();
47  MeshInstance(GLenum mode, const MeshPtr& mesh, const ShaderPtr& shader);
48  ~MeshInstance();
49 
53  GLenum getMode() const { return mMode; }
58  void setMode(GLenum value);
62  const MeshPtr& getMesh() const { return mMesh; }
67  void setMesh(const MeshPtr& mesh);
71  const ShaderPtr& getShader() const { return mShader; }
76  void setShader(const ShaderPtr& shader);
77 
86  void bind();
91  void unbind();
92 
101  static MeshInstancePtr createCompatibleMesh(int vertexCount, GLenum mode,
102  const ShaderPtr& shader);
103 private:
104  void invalidateAttributes();
105  bool checkAttributes();
106  bool areAttributesReady() const;
107 
108  MeshPtr mMesh;
109  ShaderPtr mShader;
110  GLenum mMode = GL_TRIANGLES;
111  bool mAttributesInvalid = true;
112  std::vector<int> mAttributeIndexes;
113 };
114 
115 #endif // MESHINSTANCE_H
const MeshPtr & getMesh() const
Returns the current Mesh.
Definition: MeshInstance.h:62
static MeshInstancePtr createCompatibleMesh(int vertexCount, GLenum mode, const ShaderPtr &shader)
Creates a Mesh that contains all of the vertex Attributes in a given Shader, also creating a MeshInst...
Header declaring and including types common to renderer classes such as Vector2. Also includes GL hea...
GLenum getMode() const
Returns the GL primitive type to draw (i.e. GL_TRIANGLES).
Definition: MeshInstance.h:53
void setMesh(const MeshPtr &mesh)
Sets the current Mesh, rebinding vertex Attribute locations.
void bind()
Binds the Mesh, and its vertex attribute arrays to the attribute locations in this instance's Shader...
Mesh bound to a specific Shader.
Definition: MeshInstance.h:35
const ShaderPtr & getShader() const
Returns the current Shader to which the current Mesh is bound to.
Definition: MeshInstance.h:71
void setMode(GLenum value)
Sets the kind of GL primitive to draw.
std::shared_ptr< Shader > ShaderPtr
Shared pointer typedef for Shader.
Definition: PointerDeclarations.h:143
std::shared_ptr< MeshInstance > MeshInstancePtr
Shared pointer typedef for MeshInstance.
Definition: PointerDeclarations.h:113
std::shared_ptr< Mesh > MeshPtr
Shared pointer typedef for Mesh.
Definition: PointerDeclarations.h:103
void unbind()
Reverses a call to bind(), unbinding the Mesh and disabling vertex attribute arrays.
MeshInstance()
Construct an empty MeshInstance.
void setShader(const ShaderPtr &shader)
Sets the current shader, rebinding vertex Attribute locations.