Skip to content

Commit

Permalink
Merge pull request #78 from fallahn/golf-1.12
Browse files Browse the repository at this point in the history
Golf 1.12.5
  • Loading branch information
fallahn authored Jun 3, 2023
2 parents 6ed2d9d + e7010a5 commit 82acb07
Show file tree
Hide file tree
Showing 92 changed files with 17,534 additions and 645 deletions.
2 changes: 1 addition & 1 deletion crogine/include/crogine/audio/AudioBuffer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-----------------------------------------------------------------------
Matt Marchant 2017 - 2020
Matt Marchant 2017 - 2023
http://trederia.blogspot.com
crogine - Zlib license.
Expand Down
13 changes: 12 additions & 1 deletion crogine/include/crogine/audio/AudioSource.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-----------------------------------------------------------------------
Matt Marchant 2017 - 2020
Matt Marchant 2017 - 2023
http://trederia.blogspot.com
crogine - Zlib license.
Expand Down Expand Up @@ -33,9 +33,12 @@ source distribution.
#include <crogine/detail/Types.hpp>

#include <string>
#include <vector>

namespace cro
{
class AudioEmitter;

/*!
\brief Abstract base class for audio data sources.
AudioBuffers and AudioStreams are derived from this
Expand Down Expand Up @@ -68,7 +71,15 @@ namespace cro
protected:
void setID(std::int32_t id) { m_id = id; }

friend class AudioEmitter;

//reference counts users so derived classes can tidy up if destroyed while still in use
void addUser(AudioEmitter*) const;
void removeUser(AudioEmitter*) const;
void resetUsers();

private:
std::int32_t m_id;
mutable std::vector<AudioEmitter*> m_users; //! < emitters currently using this source
};
}
33 changes: 27 additions & 6 deletions crogine/include/crogine/core/FileSystem.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-----------------------------------------------------------------------
Matt Marchant 2017 - 2020
Matt Marchant 2017 - 2023
http://trederia.blogspot.com
crogine - Zlib license.
Expand Down Expand Up @@ -40,12 +40,17 @@ namespace cro
{
/*!
\brief Utilities for manipulating the current file system
Where possible these functions try to maintain utf8 file paths
using std::filesystem - although this isn't true on macOS < 10.15
*/
class CRO_EXPORT_API FileSystem final
{
public:
/*!
\brief Lists all the files in the given directory
Note that when concatinating string literals make sure
to include the utf-8 prefix
EG: path += u8"/subdir";
*/
static std::vector<std::string> listFiles(std::string path);
/*!
Expand All @@ -67,31 +72,47 @@ namespace cro
\brief Returns true if a file exists with the name at the given path
Note that when calling this from an app running in a macOS bundle
that the path should be prefixed with a call to getResourcePath()
Note that when concatinating string literals make sure
to include the utf-8 prefix
EG: path += u8"/subdir";
*/
static bool fileExists(const std::string&);
static bool fileExists(const std::string& path);
/*!
\brief Tries to create a directory relative to the executable
or via an absolute path.
\returns false if creation fails and attempts to log the reason,
else returns true.
\param std::string Path to create.
\param std::string path Path to create.
Note that when concatinating string literals make sure
to include the utf-8 prefix
EG: path += u8"/subdir";
*/
static bool createDirectory(const std::string&);
static bool createDirectory(const std::string& path);
/*!
\brief Attempts to determine if a directory at the given path exists.
Note that when calling this from an app running in a macOS bundle
that the path should be prefixed with a call to getResourcePath()
\returns true if the directory exists, else false. Attempts to log any
errors to the console.
Note that when concatinating string literals make sure
to include the utf-8 prefix
EG: path += u8"/subdir";
*/
static bool directoryExists(const std::string&);
static bool directoryExists(const std::string& path);
/*!
\brief Returns a vector of strings containing the names of directories
found in the given path.
Note that when calling this from an app running in a macOS bundle
that the path should be prefixed with a call to getResourcePath()
Note that when concatinating string literals make sure
to include the utf-8 prefix
EG: path += u8"/subdir";
*/
static std::vector<std::string> listDirectories(const std::string&);
static std::vector<std::string> listDirectories(const std::string& path);
/*!
\brief Returns the absolute path of the current working directory
*/
Expand Down
6 changes: 5 additions & 1 deletion crogine/include/crogine/ecs/components/AudioEmitter.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-----------------------------------------------------------------------
Matt Marchant 2017 - 2021
Matt Marchant 2017 - 2023
http://trederia.blogspot.com
crogine - Zlib license.
Expand Down Expand Up @@ -190,6 +190,7 @@ namespace cro

friend class AudioPlayerSystem;
friend class AudioSystem;
friend class AudioSource;

State m_state;

Expand All @@ -215,5 +216,8 @@ namespace cro
std::int32_t m_ID;
std::int32_t m_dataSourceID;
AudioSource::Type m_sourceType;

const AudioSource* m_audioSource; //! < used only for ref counting
void reset(const AudioSource* parent = nullptr);
};
}
34 changes: 33 additions & 1 deletion crogine/include/crogine/ecs/systems/ModelRenderer.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-----------------------------------------------------------------------
Matt Marchant 2017 - 2022
Matt Marchant 2017 - 2023
http://trederia.blogspot.com
crogine - Zlib license.
Expand Down Expand Up @@ -94,6 +94,38 @@ namespace cro
*/
std::size_t getVisibleCount(std::size_t cameraIndex, std::int32_t passIndex = 0) const;

struct VertexShaderID final
{
enum
{
Unlit, VertexLit, PBR
};
};

/*!
\brief Returns the default Vertex shader for 3D models as a string
Use this when creating custom materials which only modify the fragment
shader.
\param type VertexShaderID type to return. Returns an empty string if this is invalid
*/
static const std::string& getDefaultVertexShader(std::int32_t type);

struct FragmentShaderID final
{
enum
{
Unlit, VertexLit, PBR
};
};
/*!
\brief Returns the requested default fragment shader as a string.
Use this to get the default fragment shader for a specific material
type when using custom vertex shaders.
\param type FragmentShaderID type, Unlit, VertexLit or PBR. Other
values will return an empty string.
*/
static const std::string& getDefaultFragmentShader(std::int32_t type);

void onEntityAdded(Entity) override;

void onEntityRemoved(Entity) override;
Expand Down
11 changes: 10 additions & 1 deletion crogine/include/crogine/ecs/systems/RenderSystem2D.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-----------------------------------------------------------------------
Matt Marchant 2017 - 2021
Matt Marchant 2017 - 2023
http://trederia.blogspot.com
crogine - Zlib license.
Expand Down Expand Up @@ -110,6 +110,15 @@ namespace cro
*/
void setSortOrder(DepthAxis order);

/*!
\brief Returns the default Vertex shader for Drawable2D components
Use the string returned by this function to create the vertex part
of custom shaders which don't use modified vertex properties. By
default this only forwards the colour property of vertices to the
fragment shader, add the define TEXTURED when compiling shaders to
include the texture coords of the sprite
*/
static const std::string& getDefaultVertexShader();

private:

Expand Down
108 changes: 107 additions & 1 deletion crogine/include/crogine/graphics/ShaderResource.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-----------------------------------------------------------------------
Matt Marchant 2017 - 2022
Matt Marchant 2017 - 2023
http://trederia.blogspot.com
crogine - Zlib license.
Expand Down Expand Up @@ -41,6 +41,112 @@ namespace cro
{
/*!
\brief Manages the lifetime of shader programs.
The shader resource provides a range of pre-defined #include
directives which can be used with shaders that are loaded with
this resource manager.
Vertex Shader Includes:
-----------------------
#include WVP_UNIFORMS
provides:
uniform mat4 u_worldMatrix;
uniform mat4 u_projectionMatrix;
and
uniform mat4 u_worldViewMatrix;
uniform mat3 u_normalMatrix;
if INSTANCING is not defined, else
uniform mat4 u_viewMatrix;
#include INSTANCE_ATTRIBS
provides:
vertex attributes for instanced matrix data:
ATTRIBUTE mat4 a_instanceWorldMatrix;
ATTRIBUTE mat3 a_instanceNormalMatrix;
#include INSTANCE_MATRICES
provides:
mat4 worldMatrix
mat4 worldViewMatrix
mat3 normalMatrix
Matrices are created from the given WVP uniforms
and instance attributes.
requires:
WVP_UNIFORMS, INSTANCE_ATTRIBS
#include SKIN_UNIFORMS
provides:
ATTRIBUTE vec4 a_boneIndices;
ATTRIBUTE vec4 a_boneWeights;
uniform mat4 u_boneMatrices[MAX_BONES];
Adds both the vertex attributes and matrix uniform
required for vertex skinning.
#include SKIN_MATRIX
provides:
mat4 skinMatrix
The matrix is created from the bone matrices, weights
and indices provided by SKIN_UNIFORMS and is used to
multiply the vertex position and normal data.
requires:
SKIN_UNIFORMS
#include SHADOWMAP_UNIFORMS_VERT
provides:
#define MAX_CASCADES 4 if not otherwise defined
uniform mat4 u_lightViewProjectionMatrix[MAX_CASCADES];
uniform int u_cascadeCount = 1;
#include SHADOWMAP_OUTPUTS
provides:
VARYING_OUT LOW vec4 v_lightWorldPosition[MAX_CASCADES];
VARYING_OUT float v_viewDepth;
#include SHADOWMAP_VERTEX_PROC
provides:
processing for the vertex data, which should be performed
in main()
requires:
SHADOWMAP_UNIFORMS_VERT, SHADOWMAP_OUTPUTS
also requires mat4 worldMatrix, mat4 worldViewMatrix and vec4 position
Fragment Shader Includes:
-------------------------
#include SHADOWMAP_UNIFORMS_FRAG
provides:
#define MAX_CASCADES 4 if not already defined
uniform sampler2DArray u_shadowMap;
uniform int u_cascadeCount = 1;
uniform float u_frustumSplits[MAX_CASCADES];
#include SHADOWMAP_INPUTS
provides:
VARYING_IN LOW vec4 v_lightWorldPosition[MAX_CASCADES];
VARYING_IN float v_viewDepth;
#include PCF_SHADOWS
provides:
int getCascadeIndex()
float shadowAmount(int cascadeIndex)
or, if PBR is #defined
float shadowAmount(int cascadeIndex, SurfaceProperties surfProp)
requires:
SHADOWMAP_UNIFORMS_FRAG, SHADOWMAP_INPUTS (fragment shader)
\sa addInclude
*/
class CRO_EXPORT_API ShaderResource final : public Detail::SDLResource
{
Expand Down
7 changes: 7 additions & 0 deletions crogine/include/crogine/graphics/SimpleDrawable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ namespace cro
template <typename T>
void setUniform(const std::string& name, T value);

/*!
\brief Returns a string containing the default vertex shader
Use this to prevent re-writing code when creating shaders with
custom fragment code.
*/
static const std::string& getDefaultVertexShader();

protected:
/*!
\brief Sets the Texture to be used when rendering
Expand Down
1 change: 1 addition & 0 deletions crogine/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(PROJECT_SRC
${PROJECT_DIR}/audio/AudioResource.cpp
${PROJECT_DIR}/audio/AudioRenderer.cpp
${PROJECT_DIR}/audio/AudioScape.cpp
${PROJECT_DIR}/audio/AudioSource.cpp
${PROJECT_DIR}/audio/AudioStream.cpp
${PROJECT_DIR}/audio/stb_vorbis.c
${PROJECT_DIR}/audio/VorbisLoader.cpp
Expand Down
4 changes: 3 additions & 1 deletion crogine/src/audio/AudioBuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*-----------------------------------------------------------------------
Matt Marchant 2017 - 2020
Matt Marchant 2017 - 2023
http://trederia.blogspot.com
crogine - Zlib license.
Expand Down Expand Up @@ -44,6 +44,8 @@ AudioBuffer::~AudioBuffer()
{
if (getID() > 0)
{
resetUsers();

AudioRenderer::deleteBuffer(getID());
setID(-1);
}
Expand Down
Loading

0 comments on commit 82acb07

Please sign in to comment.