Ejemplo n.º 1
0
        public override void PrepareForRendering(ShaderParameterBindings shaderParameterBindings)
        {
            var shader_parameter_bindings = shaderParameterBindings.GetShaderParameterBindings();

            bool isTextured = false;

            //shaderParameterBinding
            foreach (var iter in shader_parameter_bindings)
            {
                var parameter = iter.Value;

                var parameterType = parameter.GetParamType();

                switch (parameterType)
                {
                case ShaderParamType.SPT_TEXTURE:
                    var parameterTexture = (ShaderParameterTexture)parameter;
                    var openglTexture    = (OpenGLTexture)parameterTexture.d_parameterValue;

                    OpenGL.GL.ActiveTexture(OpenGL.TextureUnit.Texture0);
                    OpenGL.GL.ClientActiveTexture(OpenGL.TextureUnit.Texture0);
                    OpenGL.GL.BindTexture(OpenGL.TextureTarget.Texture2D, openglTexture.GetOpenGLTexture());

                    isTextured = true;
                    break;
                }
            }

            if (isTextured)
            {
                OpenGL.GL.EnableClientState(OpenGL.ArrayCap.TextureCoordArray);
                OpenGL.GL.Enable(OpenGL.EnableCap.Texture2D);
            }
            else
            {
                OpenGL.GL.DisableClientState(OpenGL.ArrayCap.TextureCoordArray);
                OpenGL.GL.Disable(OpenGL.EnableCap.Texture2D);
            }
        }
Ejemplo n.º 2
0
        // TODO: ~OpenGLBaseShaderWrapper() {}

        // Implementation of ShaderWrapper interface
        public override void PrepareForRendering(ShaderParameterBindings shaderParameterBindings)
        {
            d_shader.Bind();

            var shader_parameter_bindings = shaderParameterBindings.GetShaderParameterBindings();

            foreach (var iter in shader_parameter_bindings)
            {
                var parameter = iter.Value;

                if (parameter.GetParamType() != ShaderParamType.SPT_TEXTURE)
                {
                    if (d_shaderParameterStates.ContainsKey(iter.Key))
                    {
                        var last_shader_parameter = d_shaderParameterStates[iter.Key];
                        if (parameter.Equal(last_shader_parameter))
                        {
                            continue;
                        }
                        else
                        {
                            if (parameter.GetParamType() == last_shader_parameter.GetParamType())
                            {
                                last_shader_parameter.TakeOverParameterValue(parameter);
                            }
                            else
                            {
                                // TODO: ... delete found_iterator->second;
                                d_shaderParameterStates[iter.Key] = parameter.Clone();
                            }
                        }
                    }
                    else
                    {
                        d_shaderParameterStates[iter.Key] = parameter.Clone();
                    }
                }

                var location = d_uniformVariables[iter.Key];


                var parameter_type = parameter.GetParamType();

                switch (parameter_type)
                {
                case ShaderParamType.SPT_INT:
                {
                    var parameterInt = (ShaderParameterInt)parameter;
                    OpenGL.GL.Uniform1i(location, parameterInt.d_parameterValue);
                }
                break;

                case ShaderParamType.SPT_FLOAT:
                {
                    var parameterFloat = (ShaderParameterFloat)parameter;
                    OpenGL.GL.Uniform1f(location, parameterFloat.d_parameterValue);
                }
                break;

                case ShaderParamType.SPT_MATRIX_4X4:
                {
                    var parameterMatrix = (ShaderParameterMatrix)parameter;
                    OpenGL.GL.UniformMatrix4(location, 1, false, ref parameterMatrix.d_parameterValue);
                }
                break;

                case ShaderParamType.SPT_TEXTURE:
                {
                    var parameterTexture = (ShaderParameterTexture)parameter;
                    var openglTexture    = (OpenGLTexture)parameterTexture.d_parameterValue;

                    d_glStateChangeWrapper.ActiveTexture(location);
                    d_glStateChangeWrapper.BindTexture(OpenGL.TextureTarget.Texture2D,
                                                       openglTexture.GetOpenGLTexture());
                }
                break;
                }
            }
        }
Ejemplo n.º 3
0
        // TODO: Destructor.
        //virtual ~ShaderWrapper();

        /// <summary>
        /// This function applies the shader parameters depending on their type,
        /// so that they will be used during rendering
        /// </summary>
        /// <param name="shaderParameterBindings">
        /// The ShaderParameterBindings that will be applied
        /// </param>
        public abstract void PrepareForRendering(ShaderParameterBindings shaderParameterBindings);
Ejemplo n.º 4
0
 public RenderMaterial(ShaderWrapper shaderWrapper)
 {
     d_shaderWrapper       = shaderWrapper;
     d_shaderParamBindings = new ShaderParameterBindings();
 }