Ocular Engine
Ocular::Graphics::MaterialResourceLoader Class Reference

Creates Material objects from Ocular Material files (.omat) More...

#include <MaterialResourceLoader.hpp>

Inheritance diagram for Ocular::Graphics::MaterialResourceLoader:

Public Member Functions

virtual bool loadResource (Core::Resource *&resource, Core::File const &file, std::string const &mappingName) override
- Public Member Functions inherited from Ocular::Core::AResourceLoader
 AResourceLoader (std::string const &extension, ResourceType type)
virtual std::string getSupportedFileType () const
virtual bool loadSubResource (Resource *&resource, File const &file, std::string const &mappingName)
virtual bool exploreResource (File const &file)
ResourceType getResourceType () const

Additional Inherited Members

- Protected Member Functions inherited from Ocular::Core::AResourceLoader
bool isFileValid (Core::File const &file) const
- Protected Attributes inherited from Ocular::Core::AResourceLoader
std::string m_SupportedExtension
ResourceType m_Type

Detailed Description

Creates Material objects from Ocular Material files (.omat)


This loader is responsible for creating Material objects from the XML-based Ocular Material files (.omat). For a full description of the Ocular Material file format, see the Materials section of the manual.

But as the manual does not yet exist, here is an example of the XML:

            <Name>Grass Bump Map</Name>
            <Name>Grass Specular Map</Name>
            <Value>1.0 0.5 3.0 0.0</Value>
            <Value>1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 1.0</Value>
                0.38 1.0 0.0
                1.97 3.0 0.5
                0.01 0.9 1.0

The above XML can be broken into three major sections: ShaderProgram, Textures, and Uniforms.


The ShaderProgram is split into individual 'Shader' sections that simply specify which Shader resource file defines them. Note that these resource files may be uncompiled files (.hlsl, .glsl, etc.), pre-compiled binaries, or a mix of the two.

Internally, a request is done for the ShaderProgram that matches the specified file and then the specific shader is retrieved. For example, for the above Vertex shader we would:

ShaderProgram* program = OcularResources->getResource<ShaderProgram>("Shaders/OcularFlat");


The following are valid shader stage tags:

<Fragment> or <Pixel>
<PreTessellation> or <Hull>
<PostTessellation> or <Domain>


This defines all textures to be bound to in the Material.

The three required bits of information (path, name, and register) directly map to what the Material::setTexture method requires as input parameters.

Note that 'Name' is independent of the actual Resource's name. This is used for certain graphics APIs that bind based on name instead of register. So, we could have the following:

Resource Source: Texture/Grass Resource Name: "Grass" Material Binding Name: "GrassDiffuse"

In the Material file we are specifying the 'Material Binding Name' and not the 'Resource Name.' Of course, it is perfectly acceptable that these names match, but it is not required.


Here the individual Uniforms for the material are specified. Each Uniform is composed of three parts: Type, Name, and Value.

Valid types are:


Their values are specified in the following way:

    Float: <Value>#</Value>

  Vector4: <Value># # # #</Value>

Matrix3x3: <Value># # #  # # #  # # #</Value>


               # # #
               # # #
               # # #

Matrix4x4: <Value># # # #  # # # #  # # # #  # # # #</Value>


               # # # #
               # # # #
               # # # #
               # # # #

All numbers are converted to 32-bit floats.

Render State

Select parts of the Render State may be changed via Materials. Currently, the following fields may be specified:

PrimitiveStyle: unsigned integer corresponding to the PrimitiveStyle enum definitions

Member Function Documentation

bool Ocular::Graphics::MaterialResourceLoader::loadResource ( Core::Resource *&  resource,
Core::File const &  file,
std::string const &  mappingName 

Reimplemented from Ocular::Core::AResourceLoader.

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