Exemple #1
0
        private ProgramDeprecated Load(string name)
        {
            ProgramDeprecated program = ProgramDeprecated.Load(name);

            programs[name] = program;
            return(program);
        }
Exemple #2
0
        protected override void InitializeService()
        {
            wheel = window.Mouse.WheelPrecise;

            textured = new ProgramDeprecated(renderer.Programs["Textured"]);

            layer      = new Layer(this, window);
            layer.Name = "Root layer";
#if true
            //AddStereoModes();

            MenuList test = new MenuList(renderer, Orientation.Horizontal);
            test.Name = "test";

            test.Add(Operations());
            test.Add(Scene());
            test.Add(Camera());
            test.Add(Lights());
            test.Add(Materials());

            test.OffsetFreeSizeRelative = new Vector2(0.0f, 0.0f);
            test.OffsetSelfSizeRelative = new Vector2(0.0f, 0.0f);
            test.OffsetPixels           = new Vector2(4.0f, 4.0f);

            Layer.Add(test);
#endif

            //  Not enabled yet - work in progress. This needs layout order support (top down instead of bottom up)
            //  Layer.Add(Menu());

            InstallInputEventHandlers();
        }
Exemple #3
0
 public State(State old)
 {
     Camera            = old.Camera;
     Viewport          = old.Viewport;
     Model             = old.Model;
     Frame             = old.Frame;
     Mesh              = old.Mesh;
     Material          = old.Material;
     Program           = old.Program;
     MeshMode          = old.MeshMode;
     VertexBuffer      = old.VertexBuffer;
     IndexBuffer       = old.IndexBuffer;
     AttributeBindings = old.AttributeBindings;
 }
Exemple #4
0
 void Application_Unload(object sender, EventArgs e)
 {
     BufferPool.Instance.Dispose();
     if (diffuseProgram != null)
     {
         diffuseProgram.Dispose();
         diffuseProgram = null;
     }
     if (texturedProgram != null)
     {
         texturedProgram.Dispose();
         texturedProgram = null;
     }
 }
Exemple #5
0
        void RenderToScreen()
        {
            Mesh mesh = quadMesh;
            ProgramDeprecated program  = texturedProgram;
            MeshMode          meshMode = MeshMode.PolygonFill;

            GL.ClearColor(0.5f, 0.5f, 0.5f, 1.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);

            UseViewport(windowViewport);
            program.Use();

            //  We animate one uniform every frame, so we also need to upload uniforms
            //  This covers changes to camera uniforms caused by resizes
            double time = (double)(System.Environment.TickCount);
            float  t    = (float)(System.Math.Sin(time * 0.01) * 0.5f + 0.5f);

            (parameters["t"] as Floats).Set(t);

            program.ApplyUniforms();

            var attributeBindings = mesh.AttributeBindings(program, meshMode);

            SetupAttributeBindings(attributeBindings);
            EnsureUploaded(mesh);

            BufferRange vertexBufferRange = mesh.VertexBufferRange;
            BufferRange indexBufferRange  = mesh.IndexBufferRange(MeshMode.PolygonFill);

            GL.DrawElementsBaseVertex(
                indexBufferRange.BeginMode,
                (int)indexBufferRange.Count,
                indexBufferRange.Buffer.DrawElementsType,
                (IntPtr)(indexBufferRange.OffsetBytes),
                vertexBufferRange.BaseVertex
                );

            DisableAttributeBindings(attributeBindings);
        }
Exemple #6
0
        void RenderToTexture()
        {
            Mesh mesh = sphereMesh;
            ProgramDeprecated program  = diffuseProgram;
            MeshMode          meshMode = MeshMode.PolygonFill;

            framebuffer.Begin();
            GL.ClearColor(0.72f, 0.72f, 0.72f, 1.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            UseViewport(framebuffer);
            program.Use();

            //  We do not change any uniforms for this program so no need to reapply them
            //bindings.Apply(program);

            var attributeBindings = mesh.AttributeBindings(program, meshMode);

            SetupAttributeBindings(attributeBindings);
            EnsureUploaded(mesh);

            BufferRange vertexBufferRange = mesh.VertexBufferRange;
            BufferRange indexBufferRange  = mesh.IndexBufferRange(MeshMode.PolygonFill);

            GL.DrawElementsBaseVertex(
                indexBufferRange.BeginMode,
                (int)indexBufferRange.Count,
                indexBufferRange.Buffer.DrawElementsType,
                (IntPtr)(indexBufferRange.OffsetBytes),
                vertexBufferRange.BaseVertex
                );

            DisableAttributeBindings(attributeBindings);

            framebuffer.End();
        }
Exemple #7
0
 public StereoMode(ProgramDeprecated program)
 {
     this.program = program;
 }
Exemple #8
0
        protected override void OnLoad(System.EventArgs e)
        {
            //  Check GL version and feature capabilities
            RenderStack.Graphics.Configuration.Initialize();
            if (RenderStack.Graphics.Configuration.canUseFramebufferObject == false)
            {
                throw new System.PlatformNotSupportedException(
                          "GL version 3.0 or GL_ARB_framebuffer_object extension is needed. Neither was found."
                          );
            }
            if (RenderStack.Graphics.Configuration.canUseBaseVertex == false)
            {
                throw new System.PlatformNotSupportedException(
                          "GL version 3.2 or GL_ARB_draw_elements_base_vertex extension is needed. Neither was found."
                          );
            }

            sphereMesh = new GeometryMesh(new Sphere(2.00f, 20, 20), NormalStyle.PointNormals).GetMesh;
            quadMesh   = new GeometryMesh(new QuadXY(1.0f, 1.0f, 0.0f), NormalStyle.PolygonNormals).GetMesh;

            //  Initialize shared resources
            attributeMappings.Add("_position", VertexUsage.Position, 0, 3);
            attributeMappings.Add("_normal", VertexUsage.Normal, 0, 3);
            attributeMappings.Add("_texcoord", VertexUsage.TexCoord, 0, 2);

            UniformMappings.Add("_model_to_world_matrix", LogicalUniform.ModelToWorld);
            UniformMappings.Add("_world_to_model_matrix", LogicalUniform.WorldToModel);
            UniformMappings.Add("_model_to_clip_matrix", LogicalUniform.ModelToClip);
            UniformMappings.Add("_clip_to_model_matrix", LogicalUniform.ClipToModel);
            UniformMappings.Add("_world_to_clip_matrix", LogicalUniform.WorldToClip);
            UniformMappings.Add("_clip_to_world_matrix", LogicalUniform.ClipToWorld);
            UniformMappings.Add("_view_position_in_world", LogicalUniform.ViewPositionInWorld);

            UniformMappings.Add <Floats>("_light_direction", "light_direction");
            UniformMappings.Add <Floats>("_light_color", "light_color");
            UniformMappings.Add <Floats>("_surface_color", "surface_color");

            UniformMappings.Add <Texture>("_texture", "texture");
            UniformMappings.Add <Floats> ("_t", "t");

            parameters["surface_color"]   = new Floats(1.0f, 1.0f, 1.0f);
            parameters["light_direction"] = new Floats(0.0f, 1.0f, 0.0f);
            parameters["light_color"]     = new Floats(1.0f, 1.0f, 1.0f);
            parameters["t"] = new Floats(0.5f);

            //  Initialize resources used by the first pass (render to texture)
            framebuffer = new Framebuffer(128, 128);
            framebuffer.AttachTexture(FramebufferAttachment.ColorAttachment0, PixelFormat.Rgb, PixelInternalFormat.Rgb8);
            framebuffer.AttachRenderBuffer(FramebufferAttachment.DepthAttachment, PixelFormat.DepthComponent, RenderbufferStorage.DepthComponent32, 0);
            framebuffer.Begin();
            framebuffer.Check();
            framebuffer.End();

            cameraOne.Frame.LocalToParent.Set(
                Matrix4.CreateLookAt(
                    new Vector3(0.0f, 0.0f, -4.0f),
                    new Vector3(0.0f, 0.0f, 0.0f),
                    new Vector3(0.0f, 1.0f, 0.0f)
                    )
                );
            cameraOne.FovYRadians    = RenderStack.Math.Conversions.DegreesToRadians(60.0f);
            cameraOne.ProjectionType = ProjectionType.PerspectiveVertical;

            ulong updateSerial = 1;

            cameraOne.Frame.UpdateHierarchical(updateSerial);
            quadFrame.UpdateHierarchical(updateSerial);

            cameraOne.UpdateFrame();
            cameraOne.UpdateViewport(framebuffer);
            cameraOne.UpdateModelFrame(quadFrame);

            if (RenderStack.Graphics.Configuration.glslVersion >= 330)
            {
                diffuseProgram = new ProgramDeprecated(vsDiffuse330, fsDiffuse330);
            }
            else
            {
                diffuseProgram = new ProgramDeprecated(vsDiffuse120, fsDiffuse120);
            }
            diffuseProgram.AttributeMappings = attributeMappings;

            diffuseProgram.Bind(cameraOne);
            diffuseProgram.Bind(parameters);

            //  Initialize resources used by the second pass (render to screen, using texture)
            windowViewport = new Viewport(base.Width, base.Height);

            cameraTwo.Frame.LocalToParent.Set(
                Matrix4.CreateLookAt(
                    new Vector3(0.0f, 0.0f, -2.0f),
                    new Vector3(0.0f, 0.0f, 0.0f),
                    new Vector3(0.0f, 1.0f, 0.0f)
                    )
                );

            cameraTwo.FovYRadians    = RenderStack.Math.Conversions.DegreesToRadians(60.0f);
            cameraTwo.ProjectionType = ProjectionType.PerspectiveVertical;

            cameraTwo.Frame.UpdateHierarchical(updateSerial);
            sphereFrame.UpdateHierarchical(updateSerial);
            cameraTwo.UpdateFrame();
            cameraTwo.UpdateViewport(windowViewport);
            cameraTwo.UpdateModelFrame(sphereFrame);

            parameters["texture"] = framebuffer[FramebufferAttachment.ColorAttachment0];

            if (RenderStack.Graphics.Configuration.glslVersion >= 330)
            {
                texturedProgram = new ProgramDeprecated(vsTextured330, fsTextured330);
            }
            else
            {
                texturedProgram = new ProgramDeprecated(vsTextured120, fsTextured120);
            }
            texturedProgram.AttributeMappings = attributeMappings;

            texturedProgram.Bind(cameraTwo);
            texturedProgram.Bind(parameters);

            diffuseProgram.Use();
            diffuseProgram.ApplyUniforms();

            texturedProgram.Use();
            texturedProgram.ApplyUniforms();

            EnsureUploaded(sphereMesh);
            EnsureUploaded(quadMesh);

            //  Setup some GL state
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.CullFace);

            Resize += new EventHandler <EventArgs>(Application_Resize);
            Unload += new EventHandler <EventArgs>(Application_Unload);

            GL.ClearColor(0.5f, 0.5f, 0.5f, 1.0f);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);
            SwapBuffers();
            Visible = true;
        }