Пример #1
0
        public override void Render(Shader shader)
        {
            Mesh tmpMesh = null;

            foreach(Component comp in components)
            {
                if(tmpMesh != comp.Mesh)
                    SetVBOs(comp.Mesh, shader);

                Matrix4 meshTransform = comp.Transform;
                Matrix4 rotationMatirx = Matrix4.Rotate(this.Orientation) * Matrix4.Rotate(comp.Orientation);

                shader.insertUniform(Shader.Uniform.mesh_matrix, ref meshTransform);
                shader.insertUniform(Shader.Uniform.rotation_matrix, ref rotationMatirx);
                shader.insertUniform(Shader.Uniform.model_matrix, ref transform);

                GL.DrawElements(BeginMode.Triangles, comp.Mesh.ElementsData.Length,
                                DrawElementsType.UnsignedInt, IntPtr.Zero);

                tmpMesh = comp.Mesh;
            }
        }
Пример #2
0
        public void loadShaderXml(ref Shader target)
        {
            XmlTextReader reader = new XmlTextReader(ContentDirectory + target.name);

            target.URL = new string[2];

            while (reader.Read())
            {
                // parsing data in material tag
                if (reader.Name == "shaderpair" && reader.HasAttributes)
                {
                    while (reader.MoveToNextAttribute())
                    {
                        if (reader.Name == "vertex")
                            target.URL[0] = ContentDirectory + reader.Value;

                        else if (reader.Name == "fragment")
                            target.URL[1] = ContentDirectory + reader.Value;
                    }
                    reader.MoveToElement();
                }
            }

            loadShaderFromFile(ref target);
        }
Пример #3
0
        public void loadShaderFromFile(ref Shader target)
        {
            string vfile = target.URL[0];
            string ffile = target.URL[1];

            target.vShader = readFile(vfile);
            target.fShader = readFile(ffile);

            loadShaderFromCache(ref target);
        }
Пример #4
0
        public void loadShaderFromCache(ref Shader target)
        {
            int shaderProgramHandle;

            int vertexShaderHandle,
            fragmentShaderHandle;

            vertexShaderHandle = GL.CreateShader(All.VertexShader);
            fragmentShaderHandle = GL.CreateShader(All.FragmentShader);

            GL.ShaderSource(vertexShaderHandle, target.vShader);
            GL.ShaderSource(fragmentShaderHandle, target.fShader);

            GL.CompileShader(vertexShaderHandle);
            GL.CompileShader(fragmentShaderHandle);

            Console.WriteLine(GL.GetShaderInfoLog(vertexShaderHandle));
            Console.WriteLine(GL.GetShaderInfoLog(fragmentShaderHandle));

            // Create program
            shaderProgramHandle = GL.CreateProgram();

            GL.AttachShader(shaderProgramHandle, vertexShaderHandle);
            GL.AttachShader(shaderProgramHandle, fragmentShaderHandle);

            GL.LinkProgram(shaderProgramHandle);

            Console.WriteLine(GL.GetProgramInfoLog(shaderProgramHandle));

            target.handle = shaderProgramHandle;

            getHandles(ref target);

            target.loaded = true;

            shaders.Add(target);
        }
Пример #5
0
 public Shader LoadShader(string name)
 {
     Shader shader = new Shader();
     shader.name = name;
     loadShaderXml(ref shader);
     return shader;
 }
Пример #6
0
        public void getHandles(ref Shader target)
        {
            //int shaderProgramHandle = target.handle;

            // Set uniforms
            target.generateLocations();
        }
Пример #7
0
        public static void Load()
        {
            ShadowPassShader = ShaderLoader.GetShader("Shadow.xsp");
            fbCreator = new FramebufferCreator();

            LightFramebuffer= fbCreator.createFrameBuffer("LightFramebuffer", SceneManager.Window.Width, SceneManager.Window.Height, PixelInternalFormat.Rgba16f, false);
            LightFramebuffer.clearColor = new OpenTK.Graphics.Color4(0f, 0f, 0f, 0f);

            Scene.Load();

            GL.MatrixMode(MatrixMode.Projection);
            GL.Ortho(0.0, (double)Window.Width, 0.0, (double)Window.Height, -10.0, 10.0);
            GL.MatrixMode(MatrixMode.Modelview);
        }