Game of Ur 0.3.3
This is a computer adaptation of Game of Ur, written in C++ mainly using SDL and OpenGL.
Loading...
Searching...
No Matches
ToyMaker::ShaderProgramFromFile Class Reference

Constructs a ShaderProgram from its shader program header, found at a particular path. More...

#include <shader_program.hpp>

Inheritance diagram for ToyMaker::ShaderProgramFromFile:
ToyMaker::ResourceConstructor< ShaderProgram, ShaderProgramFromFile > ToyMaker::IResourceConstructor

Static Public Member Functions

static std::string getResourceConstructorName ()
 

Private Member Functions

std::shared_ptr< IResourcecreateResource (const nlohmann::json &methodParameters) override
 Creates a resource object using the parameters specified in methodParameters.
 

Additional Inherited Members

- Public Member Functions inherited from ToyMaker::ResourceConstructor< ShaderProgram, ShaderProgramFromFile >
std::string getResourceConstructorName_ () const override
 Gets the resource constructor type string of the constructor.
 
- Public Member Functions inherited from ToyMaker::IResourceConstructor
virtual ~IResourceConstructor ()=default
 Destroys this resource constructor (when the application is terminated.)
 
- Protected Member Functions inherited from ToyMaker::ResourceConstructor< ShaderProgram, ShaderProgramFromFile >
 ResourceConstructor (int explicitlyInitializeMe)
 Construct a new ResourceConstructor object.
 
- Protected Member Functions inherited from ToyMaker::IResourceConstructor
 IResourceConstructor ()=default
 Construct a new IResourceConstructor object.
 
- Static Protected Member Functions inherited from ToyMaker::IResourceConstructor
template<typename TResource, typename TResourceConstructor>
static void RegisterResourceConstructor ()
 Registers this resource constructor against its respective ResourceFactory during static initialization.
 

Detailed Description

Constructs a ShaderProgram from its shader program header, found at a particular path.

The resource description for a shader program:

nlohmann::json shaderDescription {
{"name", shaderFilepath},
{"method", ShaderProgramFromFile::getResourceConstructorName()},
{"parameters", {
{"path", shaderFilepath}
}}
}
static std::string getResourceTypeName()
The resource type string associated with this class.
Definition shader_program.hpp:37

The shader program json header itself:

{
"name": "basicShader",
"type": "shader/program",
"vertexShader": "basicVS.json",
"fragmentShader": "basicFS.json"
}

Fragment shader header:

{
"name": "basicFS",
"type": "shader/fragment",
"sources": [
"common/versionHeader.glsl",
"common/fragmentAttributes.fs",
"common/genericSampler.fs",
"basic/basic.fs"
]
}

Vertex shader header:

{
"name": "basicVS",
"type": "shader/vertex",
"sources": [
"common/versionHeader.glsl",
"common/fragmentAttributes.vs",
"common/vertexAttributes.vs",
"basic/basic.vs"
]
}

Vertex shader source (concatenated from shader header sources list)

// "common/versionHeader.glsl"
#version 330 core
// "common/vertexAttributes.vs"
layout(location=0) in vec4 attrPosition;
layout(location=1) in vec4 attrNormal;
layout(location=2) in vec4 attrTangent;
layout(location=3) in vec4 attrColor;
layout(location=4) in vec2 attrUV1;
layout(location=5) in vec2 attrUV2;
layout(location=6) in vec2 attrUV3;
// "common/fragmentAttributes.vs"
out FRAGMENT_ATTRIBUTES {
// world position of the associated fragment
vec4 position;
// normal vector for the associated fragment
vec4 normal;
// tangent vector for the associated fragment
vec4 tangent;
// color of the associated fragment
vec4 color;
// first texture sampling coordinates
vec2 UV1;
// second (ditto)
vec2 UV2;
// third (ditto)
vec2 UV3;
} fragAttr;
// "basic/basic.vs"
void main() {
fragAttr.position = attrPosition;
fragAttr.UV1 = attrUV1;
gl_Position = fragAttr.position;
}

Source files may be perused for further examples.

Member Function Documentation

◆ createResource()

std::shared_ptr< IResource > ShaderProgramFromFile::createResource ( const nlohmann::json & methodParameters)
overrideprivatevirtual

Creates a resource object using the parameters specified in methodParameters.

Parameters
methodParametersThe parameters used to construct an object via this constructor.
Returns
std::shared_ptr<IResource> A reference to the created resource.

Implements ToyMaker::IResourceConstructor.


The documentation for this class was generated from the following files: