/**
         * @brief Constructs the data maps of this uniform buffer using the shader reflector
         * @param[in] name_prefix (const foundation::String&) The prefix to put in front of any newly created name
         * @param[in] shader_reflection_data (const foundation::Vector <foundation::ShaderResource>&) The reflection data used to create the data maps
         */
        private void ConstructDataMaps(string name_prefix, List <ShaderResource> shader_reflection_data)
        {
            name_map_ = new Dictionary <string, int>();
            data_map_ = new List <ShaderVariable>();

            foreach (ShaderResource buffer in shader_reflection_data)
            {
                // TODO:
                // properly handle structs
                // properly handle arrays

                if (buffer.concrete_type == ShaderResource.ConcreteTypes.kStruct)
                {
                    ConstructDataMaps(name_prefix + buffer.name + ".", buffer.members);
                    return;
                }

                ShaderVarType var_type = ConvertVariableType(buffer.concrete_type);

                name_map_.Add(buffer.name, data_map_.Count);
                data_map_.Add(new ShaderVariable(var_type));


                Size += GetTypeSize(var_type);
            }
        }
        public List <ShaderVariable> data_map_;    //<! Raw vector of all shader variables

        private Int32 GetTypeSize(ShaderVarType type)
        {
            switch (type)
            {
            case ShaderVarType.kBool: return(sizeof(bool));

            case ShaderVarType.kDouble: return(sizeof(double));

            case ShaderVarType.kFloat: return(sizeof(float));

            case ShaderVarType.kInt: return(sizeof(Int32));

            case ShaderVarType.kUint: return(sizeof(UInt32));

            case ShaderVarType.kUint8: return(sizeof(byte));

            case ShaderVarType.kVec2: return(sizeof(float) * 2);

            case ShaderVarType.kVec3: return(sizeof(float) * 3);

            case ShaderVarType.kVec4: return(sizeof(float) * 4);

            case ShaderVarType.kMat3: return(sizeof(float) * 3 * 3);

            case ShaderVarType.kMat4: return(sizeof(float) * 4 * 4);

            default: Debug.Assert(false, "unknown type"); return(0);
            }
        }
Example #3
0
        public void AddUniform( ShaderVarType type, String identifier )
        {
            if ( type == ShaderVarType.Sampler2DArray )
            {
                String ext = "GL_EXT_texture_array";
                if ( !myExtensions.Contains( ext ) )
                    myExtensions.Add( ext );
            }

            myUniforms.Add( new ShaderVariable { Type = type, Identifier = identifier } );
        }
Example #4
0
        public void AddUniform(ShaderVarType type, String identifier)
        {
            if (type == ShaderVarType.Sampler2DArray)
            {
                String ext = "GL_EXT_texture_array";
                if (!myExtensions.Contains(ext))
                {
                    myExtensions.Add(ext);
                }
            }

            myUniforms.Add(new ShaderVariable {
                Type = type, Identifier = identifier
            });
        }
Example #5
0
        /// <summary>
        /// Add a uniform of a specified type to the shader.
        /// </summary>
        /// <param name="type">GLSL type of the uniform</param>
        /// <param name="identifier">Identifier name of the uniform</param>
        public void AddUniform(ShaderVarType type, String identifier)
        {
            // If the type is a Sampler2DArray, include the
            // relevant extension
            if (type == ShaderVarType.Sampler2DArray)
            {
                String ext = "GL_EXT_texture_array";
                if (!_extensions.Contains(ext))
                {
                    _extensions.Add(ext);
                }
            }

            _uniforms.Add(new ShaderVariable {
                Type = type, Identifier = identifier
            });
        }
Example #6
0
            private static int GetAttributeSize(ShaderVarType type)
            {
                switch (type)
                {
                case ShaderVarType.Float:
                case ShaderVarType.Int:
                    return(1);

                case ShaderVarType.Vec2:
                    return(2);

                case ShaderVarType.Vec3:
                    return(3);

                case ShaderVarType.Vec4:
                    return(4);

                default:
                    throw new ArgumentException("Invalid attribute type (" + type + ").");
                }
            }
Example #7
0
 public void AddVarying( ShaderVarType type, String identifier )
 {
     myVaryings.Add( new ShaderVariable { Type = type, Identifier = identifier } );
 }
Example #8
0
 public void AddAttribute( ShaderVarType type, String identifier )
 {
     myAttribs.Add( new ShaderVariable { Type = type, Identifier = identifier } );
 }
Example #9
0
 public void AddVarying(ShaderVarType type, String identifier)
 {
     myVaryings.Add(new ShaderVariable {
         Type = type, Identifier = identifier
     });
 }
Example #10
0
 public void AddAttribute(ShaderVarType type, String identifier)
 {
     myAttribs.Add(new ShaderVariable {
         Type = type, Identifier = identifier
     });
 }
        /// <summary>
        /// Add a uniform of a specified type to the shader.
        /// </summary>
        /// <param name="type">GLSL type of the uniform</param>
        /// <param name="identifier">Identifier name of the uniform</param>
        public void AddUniform(ShaderVarType type, String identifier)
        {
            // If the type is a Sampler2DArray, include the
            // relevant extension
            if (type == ShaderVarType.Sampler2DArray) {
                String ext = "GL_EXT_texture_array";
                if (!_extensions.Contains(ext))
                    _extensions.Add(ext);
            }

            _uniforms.Add(new ShaderVariable { Type = type, Identifier = identifier });
        }
 /**
  * @brief Creates a shader variable with a certain value type and a default value
  */
 public ShaderVariable(ShaderVarType type, object default_value = null)
 {
     type_ = type;
     data_ = default_value;
 }