Fillwave  10.0.0
RendererDR.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/renderers/IRenderer.h>
25 #include <flw/flc/extended/rendering/FramebufferGeometry.h>
26 #include <flw/flf/models/Mesh.h>
27 #include <flw/Math.h>
28 #include <flw/flc/rendering/Texture2DRenderable.h>
29 
30 #if defined(FILLWAVE_BACKEND_OPENGL_ES_30)
31 #else
32 
33 namespace flw {
34 namespace flf {
35 class ProgramLoader;
36 }
37 namespace flc {
38 
43 class RendererDR : public IRenderer {
44 public:
45  RendererDR(Engine *engine, flf::ProgramLoader &loader);
46 
47  ~RendererDR() override = default;
48 
49  void update(IRenderable *renderable) override;
50 
51  void draw(ICamera &camera) override;
52 
53  void reset(GLuint width, GLuint height) override;
54 
55  void clear() override;
56 
57  /* Init */
58  void initGeometryBuffer();
59 
60  void initGeometryShading();
61 
62  void initUniforms();
63 
64  void initUniformsCache();
65 
66  /* Passes */
67  void drawSceneCoreDR();
68 
69  void drawGeometryPass(ICamera &camera);
70 
71  void drawDepthlessPass();
72 
73  void drawAmbientPass();
74 
75  void drawAOPass(ICamera &camera);
76 
77  void drawColorPass(ICamera &camera);
78 
79  void drawLightsSpotPass(ICamera &camera, GLint &textureUnit);
80 
81  void drawLightsDirectionalPass(ICamera &camera, GLint &textureUnit);
82 
83  void drawLightsPointPass(ICamera &camera, GLint &textureUnit);
84 
85  void drawColorPassBegin();
86 
87  void drawColorPassEnd();
88 
89  void drawDebug();
90 
91 private:
92  glm::ivec2 mScreenSize;
93 
94  flf::LightSystem &mLights;
95  flf::TextureSystem &mTextures;
96 
97  flc::Program* mProgramMain;
98  flc::Program* mProgramMainAnimated;
99  flc::Program* mProgramDirectionalLight;
100  flc::Program* mProgramSpotLight;
101  flc::Program* mProgramPointLight;
102  flc::Program* mProgramDepthless;
103  flc::Program* mProgramAmbient;
104  flc::Program* mProgramAOGeometry;
105  flc::Program* mProgramAOColor;
106 
107  pu<flc::Texture2DRenderable> mAOGeometryBuffer;
108  pu<flc::Texture2DRenderable> mAOColorBuffer;
109 
110  pu<flf::Mesh> mDeferredPointLight;
111 
112  GLint mULCDRDepthlesDiffuseTexel;
113  GLint mULCDRDepthlessPositionTexel;
114  GLint mULCDRScreenSize;
115  GLint mULCDRAScreenSize;
116  GLint mULCDRADiffuseAttachment;
117  GLint mULCAmbient;
118 
119  GLint mULCCameraPositionDirectional;
120  GLint mULCAmbientIntensityDirectional;
121  GLint mULCScreenSizeDirectional;
122  GLint mULCShadowUnitDirectional;
123  GLint mULCIsAODirectional;
124  GLint mULCCameraPositionPoint;
125  GLint mULCAmbientIntensityPoint;
126  GLint mULCMVPPoint;
127  GLint mULCScreenSizePoint;
128  GLint mULCShadowUnitPoint;
129  GLint mULCIsAOPoint;
130 
131  /* ULC - Uniform location cache */
132  GLint mULCCameraPositionSpot;
133  GLint mULCAmbientIntensitySpot;
134  GLint mULCScreenSizeSpot;
135  GLint mULCShadowUnitSpot;
136  GLint mULCIsAOSpot;
137 
138  GLboolean mIsAO;
139 
140  const GLuint mDeferredColorAttachments;
141 
142  pu<flc::FramebufferGeometry> mGBuffer;
143 
144  std::vector<IRenderable*> mNodes; /* true -> animated, false -> not animated */
145  std::vector<IRenderable*> mAnimatedNodes; /* true -> animated, false -> not animated */
146 };
147 
148 } /* flc */
149 } /* flw */
150 
151 #endif /* defined(FILLWAVE_BACKEND_OPENGL_ES_30) */
Definition: Aliases.h:30
Manager to handle TextureObject1D, TextureObject2D and TextureObject3D objects.
Definition: TextureSystem.h:38
Deferred IRenderer. Not ready (Rev.4.2.1).
Definition: RendererDR.h:43
Base for all renderers.
Definition: IRenderer.h:42
Loads programs.
Definition: ProgramLoader.h:37
Fillwave engine core.
Definition: Engine.h:85
Encapsulates renderable objects. To be used with IRenderer.
Definition: IRenderable.h:36
Light system knows about all light related stuff.
Definition: LightSystem.h:40
Single GLSL program object.
Definition: Program.h:37
Stores camera view parameters.
Definition: ICamera.h:32