Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
Game Library
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Game Development
Game Library
Commits
e6bf18d3
Commit
e6bf18d3
authored
2 years ago
by
Joseph Walton-Rivers
Browse files
Options
Downloads
Patches
Plain Diff
reduce method complexity for renderer
parent
ebf1b235
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
demo/demo/main.cpp
+1
-7
1 addition, 7 deletions
demo/demo/main.cpp
fggl/debug/CMakeLists.txt
+3
-3
3 additions, 3 deletions
fggl/debug/CMakeLists.txt
fggl/gfx/ogl4/models.cpp
+119
-117
119 additions, 117 deletions
fggl/gfx/ogl4/models.cpp
with
123 additions
and
127 deletions
demo/demo/main.cpp
+
1
−
7
View file @
e6bf18d3
...
...
@@ -83,6 +83,7 @@ int main(int argc, const char* argv[]) {
moduleManager
.
use
<
fggl
::
display
::
GLFW
>
();
moduleManager
.
use
<
fggl
::
assets
::
AssetFolders
>
();
moduleManager
.
use
<
fggl
::
entity
::
ECS
>
();
#ifdef FGGL_MODULE_BULLET
moduleManager
.
use
<
fggl
::
phys
::
Bullet3
>
();
#else
...
...
@@ -101,13 +102,6 @@ int main(int argc, const char* argv[]) {
window
->
setFullscreen
(
true
);
app
.
setWindow
(
window
);
// load a bunch of modules to provide game functionality
//app.use<fggl::ecs3::ecsTypes>();
/*app.use<fggl::gfx::SceneUtils>();
#ifdef FGGL_MODULE_BULLET
app.use<FGGL_MODULE_BULLET>();
#endif*/
// our test states
setup_menu
(
app
);
app
.
addState
<
GameScene
>
(
"game"
);
...
...
This diff is collapsed.
Click to expand it.
fggl/debug/CMakeLists.txt
+
3
−
3
View file @
e6bf18d3
target_sources
(
fggl
PRIVATE
debug.cpp
debug_draw.cpp
logging.cpp
debug.cpp
debug_draw.cpp
logging.cpp
)
# spdlog for cleaner logging
...
...
This diff is collapsed.
Click to expand it.
fggl/gfx/ogl4/models.cpp
+
119
−
117
View file @
e6bf18d3
...
...
@@ -158,143 +158,145 @@ namespace fggl::gfx::ogl4 {
}
#endif
void
StaticModelRenderer
::
renderModelsForward
(
const
entity
::
EntityManager
&
world
)
{
// fetch cameras we will need to render with
auto
cameras
=
world
.
find
<
gfx
::
Camera
>
();
// if there are no cameras, we can't do anything...
if
(
cameras
.
empty
())
{
spdlog
::
warn
(
"asked to render static models, but there were no cameras"
);
return
;
}
// perform a rendering pass for each camera (will usually only be one...)
for
(
const
auto
&
cameraEnt
:
cameras
)
{
//TODO should be clipping this to only visible objects
static
void
forward_camera_pass
(
const
entity
::
EntityID
&
camera
,
const
fggl
::
entity
::
EntityManager
&
world
)
{
// enable required OpenGL state
glEnable
(
GL_CULL_FACE
);
glCullFace
(
GL_BACK
);
// enable required OpenGL state
glEnable
(
GL_CULL_FACE
);
glCullFace
(
GL_BACK
);
// enable depth testing
glEnable
(
GL_DEPTH_TEST
);
// enable depth testing
glEnable
(
GL_DEPTH_TEST
);
// set-up camera matrices
const
auto
&
camTransform
=
world
.
get
<
fggl
::
math
::
Transform
>
(
camera
);
const
auto
&
camComp
=
world
.
get
<
fggl
::
gfx
::
Camera
>
(
camera
);
// set-up camera m
atri
ces
const
auto
&
camTransform
=
world
.
get
<
math
::
Transform
>
(
cameraEnt
);
const
auto
&
camComp
=
world
.
get
<
gfx
::
C
am
e
ra
>
(
cameraEnt
);
const
math
::
mat4
projectionM
atri
x
=
glm
::
perspective
(
camComp
.
fov
,
camComp
.
aspectRatio
,
camComp
.
nearPlane
,
camComp
.
farPlane
);
const
math
::
mat4
viewMatrix
=
glm
::
lookAt
(
c
am
T
ra
nsform
.
origin
(),
camComp
.
target
,
camTransform
.
up
()
);
const
math
::
mat4
projectionMatrix
=
glm
::
perspective
(
camComp
.
fov
,
camComp
.
aspectRatio
,
camComp
.
nearPlane
,
camComp
.
farPlane
);
const
math
::
mat4
viewMatrix
=
glm
::
lookAt
(
camTransform
.
origin
(),
camComp
.
target
,
camTransform
.
up
());
// TODO lighting needs to not be this...
math
::
vec3
lightPos
{
0.0
f
,
10.0
f
,
0.0
f
};
// TODO lighting needs to not be this...
math
::
vec3
lightPos
{
0.0
f
,
10.0
f
,
0.0
f
};
std
::
shared_ptr
<
ogl
::
Shader
>
shader
=
nullptr
;
ogl
::
Location
mvpMatrixUniform
=
0
;
ogl
::
Location
mvMatrixUniform
=
0
;
std
::
shared_ptr
<
ogl
::
Shader
>
shader
=
nullptr
;
ogl
::
Location
mvpMatrixUniform
=
0
;
ogl
::
Location
mvMatrixUniform
=
0
;
auto
renderables
=
world
.
find
<
StaticModel
>
();
for
(
const
auto
&
entity
:
renderables
)
{
auto
renderables
=
world
.
find
<
StaticModel
>
();
for
(
const
auto
&
entity
:
renderables
)
{
// ensure that the model pipeline actually exists...
const
auto
&
model
=
world
.
get
<
StaticModel
>
(
entity
);
if
(
model
.
pipeline
==
nullptr
)
{
debug
::
warning
(
"shader was null, aborting render"
);
continue
;
}
// ensure that the model pipeline actually exists...
const
auto
&
model
=
world
.
get
<
StaticModel
>
(
entity
);
if
(
model
.
pipeline
==
nullptr
)
{
debug
::
warning
(
"shader was null, aborting render"
);
continue
;
// check if we switched shaders
if
(
shader
==
nullptr
||
shader
->
shaderID
()
!=
model
.
pipeline
->
shaderID
())
{
// new shader - need to re-send the view and projection matrices
shader
=
model
.
pipeline
;
shader
->
use
();
if
(
shader
->
hasUniform
(
"projection"
))
{
shader
->
setUniformMtx
(
shader
->
uniform
(
"view"
),
viewMatrix
);
shader
->
setUniformMtx
(
shader
->
uniform
(
"projection"
),
projectionMatrix
);
}
mvpMatrixUniform
=
shader
->
uniform
(
"MVPMatrix"
);
mvMatrixUniform
=
shader
->
uniform
(
"MVMatrix"
);
}
// check if we switched shaders
if
(
shader
==
nullptr
||
shader
->
shaderID
()
!=
model
.
pipeline
->
shaderID
())
{
// new shader - need to re-send the view and projection matrices
shader
=
model
.
pipeline
;
shader
->
use
();
if
(
shader
->
hasUniform
(
"projection"
))
{
shader
->
setUniformMtx
(
shader
->
uniform
(
"view"
),
viewMatrix
);
shader
->
setUniformMtx
(
shader
->
uniform
(
"projection"
),
projectionMatrix
);
}
mvpMatrixUniform
=
shader
->
uniform
(
"MVPMatrix"
);
mvMatrixUniform
=
shader
->
uniform
(
"MVMatrix"
);
// set model transform
const
auto
&
transform
=
world
.
get
<
math
::
Transform
>
(
entity
);
shader
->
setUniformMtx
(
mvpMatrixUniform
,
projectionMatrix
*
viewMatrix
*
transform
.
model
());
shader
->
setUniformMtx
(
mvMatrixUniform
,
viewMatrix
*
transform
.
model
());
auto
normalMatrix
=
glm
::
mat3
(
glm
::
transpose
(
inverse
(
transform
.
model
())));
shader
->
setUniformMtx
(
shader
->
uniform
(
"NormalMatrix"
),
normalMatrix
);
// setup lighting mode
if
(
shader
->
hasUniform
(
"lights[0].isEnabled"
))
{
bool
local
=
true
;
shader
->
setUniformI
(
shader
->
uniform
(
"lights[0].isEnabled"
),
1
);
shader
->
setUniformI
(
shader
->
uniform
(
"lights[0].isLocal"
),
local
);
shader
->
setUniformI
(
shader
->
uniform
(
"lights[0].isSpot"
),
0
);
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].constantAttenuation"
),
5.0
f
);
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].linearAttenuation"
),
0.0
f
);
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].quadraticAttenuation"
),
0.0
f
);
shader
->
setUniformF
(
shader
->
uniform
(
"Strength"
),
0.6
F
);
if
(
!
local
)
{
lightPos
=
glm
::
normalize
(
lightPos
);
auto
viewDir
=
glm
::
normalize
(
camTransform
.
origin
()
-
transform
.
origin
());
auto
halfVector
=
glm
::
normalize
(
lightPos
+
viewDir
);
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].halfVector"
),
halfVector
);
shader
->
setUniformF
(
shader
->
uniform
(
"EyeDirection"
),
viewDir
);
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].position"
),
lightPos
);
}
else
{
auto
camModelView
=
(
viewMatrix
*
camTransform
.
model
()
*
math
::
vec4
(
0.0
f
,
0.0
f
,
0.0
f
,
1.0
f
));
auto
modelModelView
=
(
viewMatrix
*
transform
.
model
()
*
math
::
vec4
(
0.0
f
,
0.0
f
,
0.0
f
,
1.0
f
));
math
::
vec3
viewDir
=
glm
::
normalize
(
camModelView
-
modelModelView
);
shader
->
setUniformF
(
shader
->
uniform
(
"EyeDirection"
),
viewDir
);
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].position"
),
math
::
vec3
(
viewMatrix
*
math
::
vec4
(
lightPos
,
1.0
f
)));
}
// set model transform
const
auto
&
transform
=
world
.
get
<
math
::
Transform
>
(
entity
);
shader
->
setUniformMtx
(
mvpMatrixUniform
,
projectionMatrix
*
viewMatrix
*
transform
.
model
());
shader
->
setUniformMtx
(
mvMatrixUniform
,
viewMatrix
*
transform
.
model
());
auto
normalMatrix
=
glm
::
mat3
(
glm
::
transpose
(
inverse
(
transform
.
model
())));
shader
->
setUniformMtx
(
shader
->
uniform
(
"NormalMatrix"
),
normalMatrix
);
// setup lighting mode
if
(
shader
->
hasUniform
(
"lights[0].isEnabled"
))
{
bool
local
=
true
;
shader
->
setUniformI
(
shader
->
uniform
(
"lights[0].isEnabled"
),
1
);
shader
->
setUniformI
(
shader
->
uniform
(
"lights[0].isLocal"
),
local
);
shader
->
setUniformI
(
shader
->
uniform
(
"lights[0].isSpot"
),
0
);
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].constantAttenuation"
),
5.0
f
);
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].linearAttenuation"
),
0.0
f
);
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].quadraticAttenuation"
),
0.0
f
);
shader
->
setUniformF
(
shader
->
uniform
(
"Strength"
),
0.6
F
);
if
(
!
local
)
{
lightPos
=
glm
::
normalize
(
lightPos
);
auto
viewDir
=
glm
::
normalize
(
camTransform
.
origin
()
-
transform
.
origin
());
auto
halfVector
=
glm
::
normalize
(
lightPos
+
viewDir
);
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].halfVector"
),
halfVector
);
shader
->
setUniformF
(
shader
->
uniform
(
"EyeDirection"
),
viewDir
);
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].position"
),
lightPos
);
}
else
{
auto
camModelView
=
(
viewMatrix
*
camTransform
.
model
()
*
math
::
vec4
(
0.0
f
,
0.0
f
,
0.0
f
,
1.0
f
));
auto
modelModelView
=
(
viewMatrix
*
transform
.
model
()
*
math
::
vec4
(
0.0
f
,
0.0
f
,
0.0
f
,
1.0
f
));
math
::
vec3
viewDir
=
glm
::
normalize
(
camModelView
-
modelModelView
);
shader
->
setUniformF
(
shader
->
uniform
(
"EyeDirection"
),
viewDir
);
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].position"
),
math
::
vec3
(
viewMatrix
*
math
::
vec4
(
lightPos
,
1.0
f
)));
}
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].ambient"
),
{
0.0
f
,
0.5
f
,
0.0
f
});
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].colour"
),
{
0.5
f
,
0.5
f
,
0.5
f
});
}
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].ambient"
),
{
0.0
f
,
0.5
f
,
0.0
f
});
shader
->
setUniformF
(
shader
->
uniform
(
"lights[0].colour"
),
{
0.5
f
,
0.5
f
,
0.5
f
});
}
// material detection with fallback
auto
*
material
=
world
.
tryGet
<
PhongMaterial
>
(
entity
);
if
(
material
==
nullptr
)
{
material
=
&
DEFAULT_MATERIAL
;
}
// material detection with fallback
auto
*
material
=
world
.
tryGet
<
PhongMaterial
>
(
entity
);
if
(
material
==
nullptr
)
{
material
=
&
DEFAULT_MATERIAL
;
}
if
(
shader
->
hasUniform
(
"materials[0].ambient"
)
)
{
shader
->
setUniformF
(
shader
->
uniform
(
"materials[0].emission"
),
material
->
emission
);
shader
->
setUniformF
(
shader
->
uniform
(
"materials[0].ambient"
),
material
->
ambient
);
shader
->
setUniformF
(
shader
->
uniform
(
"materials[0].diffuse"
),
material
->
diffuse
);
shader
->
setUniformF
(
shader
->
uniform
(
"materials[0].specular"
),
material
->
specular
);
shader
->
setUniformF
(
shader
->
uniform
(
"materials[0].shininess"
),
material
->
shininess
);
}
if
(
shader
->
hasUniform
(
"materials[0].ambient"
)
)
{
shader
->
setUniformF
(
shader
->
uniform
(
"materials[0].emission"
),
material
->
emission
);
shader
->
setUniformF
(
shader
->
uniform
(
"materials[0].ambient"
),
material
->
ambient
);
shader
->
setUniformF
(
shader
->
uniform
(
"materials[0].diffuse"
),
material
->
diffuse
);
shader
->
setUniformF
(
shader
->
uniform
(
"materials[0].specular"
),
material
->
specular
);
shader
->
setUniformF
(
shader
->
uniform
(
"materials[0].shininess"
),
material
->
shininess
);
}
if
(
shader
->
hasUniform
(
"lightPos"
))
{
shader
->
setUniformF
(
shader
->
uniform
(
"lightPos"
),
lightPos
);
}
if
(
shader
->
hasUniform
(
"lightPos"
))
{
shader
->
setUniformF
(
shader
->
uniform
(
"lightPos"
),
lightPos
);
}
auto
vao
=
model
.
vao
;
vao
->
bind
();
auto
vao
=
model
.
vao
;
vao
->
bind
();
model
.
vertexData
->
bind
();
if
(
model
.
restartIndex
!=
NO_RESTART_IDX
)
{
glEnable
(
GL_PRIMITIVE_RESTART
);
glPrimitiveRestartIndex
(
model
.
restartIndex
);
}
model
.
vertexData
->
bind
();
if
(
model
.
restartIndex
!=
NO_RESTART_IDX
)
{
glEnable
(
GL_PRIMITIVE_RESTART
);
glPrimitiveRestartIndex
(
model
.
restartIndex
);
}
auto
*
elements
=
model
.
elements
.
get
();
vao
->
drawElements
(
*
elements
,
model
.
drawType
,
model
.
elementCount
);
if
(
model
.
restartIndex
!=
NO_RESTART_IDX
)
{
glDisable
(
GL_PRIMITIVE_RESTART
);
}
auto
*
elements
=
model
.
elements
.
get
();
vao
->
drawElements
(
*
elements
,
model
.
drawType
,
model
.
elementCount
);
if
(
model
.
restartIndex
!=
NO_RESTART_IDX
)
{
glDisable
(
GL_PRIMITIVE_RESTART
);
}
}
}
void
StaticModelRenderer
::
renderModelsForward
(
const
entity
::
EntityManager
&
world
)
{
// fetch cameras we will need to render with
auto
cameras
=
world
.
find
<
gfx
::
Camera
>
();
// if there are no cameras, we can't do anything...
if
(
cameras
.
empty
())
{
spdlog
::
warn
(
"asked to render static models, but there were no cameras"
);
return
;
}
// perform a rendering pass for each camera (will usually only be one...)
for
(
const
auto
&
cameraEnt
:
cameras
)
{
//TODO should be clipping this to only visible objects
forward_camera_pass
(
cameraEnt
,
world
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment