Fillwave  10.0.0
Mesh.h
1 #pragma once
2 
3 /*
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2018 Filip Wasil and Fillwave community members
7  *
8  * Permission is hereby granted, free of charge, to any person
9  * obtaining a copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
12  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included
15  * in all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
18  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 
24 #include <flw/flc/texturing/Texture2D.h>
25 #include <flw/flc/buffers/IndexBuffer.h>
26 
27 #include <flw/flc/operations/TQuery.h>
28 #include <flw/flc/buffers/mVertexBufferBasic.h>
29 #include <flw/flf/models/Entity.h>
30 #include <flw/cmn/Material.h>
31 #include <flw/flf/models/base/IReloadable.h>
32 
33 #include <flw/flc/renderers/IRenderer.h>
34 
35 #include <flw/flc/extended/operations/ConditionalRender.h>
36 #include <flw/flc/extended/pipeline/Fence.h>
37 
38 namespace flw {
39 class Engine;
40 
41 namespace flf {
42 class Animator;
43 class LightSystem;
44 }
45 
46 namespace flf {
47 
51 class Mesh : public Entity, public IReloadable {
52 public:
53  Mesh(Engine *engine,
54  const Material& material,
55  flc::Texture2D* diffuseMap,
56  flc::Texture2D* normalMap,
57  flc::Texture2D* specularMap,
58  flc::Program* program,
59  flc::Program* ProgramShadow,
60  flc::Program* programShadowColor,
61  flc::Program* programOcclusion,
62  flc::Program* programAmbientOcclusionGeometry,
63  flc::Program* programAmbientOcclusionColor,
64  LightSystem &lights,
65  flc::VertexArray* vao,
66  bool isVAOInitialized,
67  flc::VertexBufferBasic* vbo = nullptr,
68  flc::IndexBuffer* ibo = nullptr,
69  ModelLoader::Animator* animator = nullptr,
70  GLenum renderMode = GL_TRIANGLES);
71 
72  ~Mesh() override;
73 
74  /* IDrawable */
75  void drawFR(ICamera &camera) override;
76 
77  void drawPBRP(ICamera &camera) override;
78 
79  void drawDR(ICamera &camera) override;
80 
81  void drawPicking(ICamera &camera) override;
82 
83  void drawDepth(ICamera &camera) override;
84 
85  void drawDepthColor(ICamera &camera, glm::vec3 &position) override;
86 
87  void drawAOG(ICamera &camera) override;
88 
89  void drawAOC(ICamera &camera) override;
90 
91  void drawOcclusionBox(ICamera &camera) override;
92 
93  /* IRenderable */
94  void updateRenderer(flc::IRenderer &renderer) override;
95  bool getRenderItem(flc::RenderItem &item) override;
96 
97  void log() const override;
98 
99  void drawFast(ICamera &camera);
100 
101  virtual void onDraw();
102 
103  protected:
104  Material mMaterial;
105  flc::Texture2D* mDiffuseMap;
106  flc::Texture2D* mNormalMap;
107  flc::Texture2D* mSpecularMap;
108  flc::Program* mProgram;
109  flc::Program* mProgramShadow;
110  flc::Program* mProgramShadowColor;
111  flc::Program* mProgramOQ;
112  flc::Program* mProgramAOGeometry;
113  flc::Program* mProgramAOColor;
114  GLenum mRenderMode;
115 
116  /* Buffers */
117  flc::IndexBuffer* mIBO;
119 
120  /* Light */
121  LightSystem &mLights;
122 
123  /* Animations */
124  ModelLoader::Animator* mAnimator;
125 
126  /* Occlusion cut off */
127  glm::mat4 mOcclusionMatrix;
128 
129 #if defined(FILLWAVE_BACKEND_OPENGL_ES_20)
130 #elif defined(FILLWAVE_BACKEND_OPENGL_ES_30)
131  flc::QueryIfAnySamplesPassed mOcclusionQuery;
132 #else
133  flc::QueryIfAnySamplesPassed mOcclusionQuery;
134 // flc::QueryTimeElapsed mTimeQuery;
135  flc::ConditionalRender mConditionalRendering;
136  // puFence mFence;
137 #endif
138 
139 private:
140 
141  /* ULC - Uniform location cache */
142  GLint mULCModelMatrix, mULCViewProjectionMatrix, mULCLightAmbientIntensity, mULCLightDiffuseIntensity, mULCLightSpecularIntensity, mULCCameraPosition, mULCColorPicking, mULCPainterColor;
143  GLint mULCMVPOcclusion;
144  GLint mULCMVPShadow;
145  GLint mULCMVPShadowColor, mULCModelMatrixShadowColor;
146  GLint mULCMVPAmbientOcclusion, mULCPositionAmbientOcclusion;
147  GLint mULCSampleRadius, mULCProjectionMatrix;
148 
149  void initBuffers() override;
150 
151  void initPipeline() override;
152 
153  void initUniformsCache() override;
154 
155  void initVAO() override;
156 
157  void initVBO() override;
158 
159  void bindTextures();
160 
161  void coreDraw();
162 
163  private:
164  const GLint VERTICES_CUBE_COUNT = 36;
165 };
166 
167 } /* flf */
168 } /* flw */
Definition: Aliases.h:30
Encapsulates reloadable objects.
Definition: IReloadable.h:35
Per mesh material info.
Definition: Material.h:32
Base for all renderers.
Definition: IRenderer.h:42
Basic drawable Entity.
Definition: Mesh.h:51
GLObject to ask OpenGL questions.
Definition: TQuery.h:34
Single GLSL 2D Texture object.
Definition: Texture2D.h:36
Fillwave engine core.
Definition: Engine.h:85
Base for all Scene nodes.
Definition: Entity.h:48
VertexArrayObject - VAO.
Definition: VertexArray.h:33
IndexBufferObject - IBO.
Definition: IndexBuffer.h:35
Operation of rendering only meshes passing the occlusion test.
Definition: ConditionalRender.h:33
Light system knows about all light related stuff.
Definition: LightSystem.h:40
Single GLSL program object.
Definition: Program.h:37
Single draw item structure.
Definition: RenderItem.h:33
Stores camera view parameters.
Definition: ICamera.h:32
Vertex buffer specialized with VertexBasic data structure.
Definition: mVertexBufferBasic.h:61