Пример #1
0
        //Shader Compilation

        public static void issuemodifyShaderRequest(GLSLShaderConfig config, GLSLShaderText shaderText)
        {
            Console.WriteLine("Sending Shader Modification Request");
            ThreadRequest req = new ThreadRequest();

            req.type = THREAD_REQUEST_TYPE.GL_MODIFY_SHADER_REQUEST;
            req.arguments.Add(config);
            req.arguments.Add(shaderText);

            //Send request
            CallBacks.issueRequestToGLControl(ref req);
        }
Пример #2
0
        //GLPreparation
        public static GLSLShaderConfig compileShader(GLSLShaderText vs, GLSLShaderText fs, GLSLShaderText gs, GLSLShaderText tes, GLSLShaderText tcs, SHADER_TYPE type, ref string log)
        {
            GLSLShaderConfig shader_conf = new GLSLShaderConfig(vs, fs, gs, tcs, tes, type);

            //Set modify Shader delegate
            shader_conf.modifyShader = issuemodifyShaderRequest;

            compileShader(shader_conf);
            log += shader_conf.log; //Append log

            return(shader_conf);
        }
Пример #3
0
        public GLSLShaderConfig(GLSLShaderText vvs, GLSLShaderText ffs, GLSLShaderText ggs, GLSLShaderText ttcs, GLSLShaderText ttes, SHADER_TYPE type)
        {
            shader_type = type; //Set my custom shader type for recognition
            //Store objects
            fs_text  = ffs;
            gs_text  = ggs;
            vs_text  = vvs;
            tes_text = ttes;
            tcs_text = ttcs;

            //Set parents to the shader objects
            ffs?.parentShaders.Add(this);
            ggs?.parentShaders.Add(this);
            vvs?.parentShaders.Add(this);
            ttes?.parentShaders.Add(this);
            ttcs?.parentShaders.Add(this);
        }
Пример #4
0
        static public void modifyShader(GLSLShaderConfig shader_conf, GLSLShaderText shaderText)
        {
            Console.WriteLine("Actually Modifying Shader");

            int[] attached_shaders = new int[20];
            int   count;
            int   status_code;

            GL.GetAttachedShaders(shader_conf.program_id, 20, out count, attached_shaders);

            for (int i = 0; i < count; i++)
            {
                int[] shader_params = new int[10];
                GL.GetShader(attached_shaders[i], OpenTK.Graphics.OpenGL4.ShaderParameter.ShaderType, shader_params);

                if (shader_params[0] == (int)shaderText.shader_type)
                {
                    Console.WriteLine("Found modified shader");

                    //Trying to compile shader
                    shaderText.compile();

                    //Attach new shader back to program
                    GL.DetachShader(shader_conf.program_id, attached_shaders[i]);
                    GL.AttachShader(shader_conf.program_id, shaderText.shader_object_id);
                    GL.LinkProgram(shader_conf.program_id);

                    GL.GetProgram(shader_conf.program_id, GetProgramParameterName.LinkStatus, out status_code);
                    if (status_code != 1)
                    {
                        Console.WriteLine("Unable to link the new shader. Reverting to the old shader");
                        return;
                    }

                    //Delete old shader and reload uniforms
                    loadActiveUniforms(shader_conf); //Re-load active uniforms
                    Console.WriteLine("Shader was modified successfully");
                    break;
                }
            }
            Console.WriteLine("Shader was not found...");
        }
Пример #5
0
        public static GLSLShaderConfig compileShader(string vs_path, string fs_path, string gs_path, string tcs_path, string tes_path,
                                                     List <string> directives, List <string> includes, SHADER_TYPE type, ref string log)
        {
            List <string> defines = new List <string>();

            //General Directives are provided here
            foreach (string d in directives)
            {
                defines.Add(d);
            }

            //Material Flags are provided here
            foreach (string f in includes)
            {
                defines.Add("_" + f);
            }

            //Main Object Shader - Deferred Shading
            GLSLShaderText main_deferred_shader_vs = new GLSLShaderText(ShaderType.VertexShader);
            GLSLShaderText main_deferred_shader_fs = new GLSLShaderText(ShaderType.FragmentShader);

            foreach (string s in defines)
            {
                main_deferred_shader_vs.addString("#define " + s + "\n");
            }
            main_deferred_shader_vs.addStringFromFile(vs_path);
            foreach (string s in defines)
            {
                main_deferred_shader_fs.addString("#define " + s + "\n");
            }
            main_deferred_shader_fs.addStringFromFile(fs_path);

            GLSLShaderConfig conf = compileShader(main_deferred_shader_vs, main_deferred_shader_fs, null, null, null,
                                                  type, ref log);

            conf.shaderHash = calculateShaderHash(includes);

            return(conf);
        }