Esempio n. 1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            Closed += ShaderTest_Closed;

            gl3dcontroller = new Controller3D();
            gl3dcontroller.PaintObjects = ControllerDraw;
            gl3dcontroller.MatrixCalc.PerspectiveNearZDistance = 1f;
            gl3dcontroller.MatrixCalc.PerspectiveFarZDistance  = 1000f;
            gl3dcontroller.ZoomDistance = 20F;
            gl3dcontroller.Start(glwfc, new Vector3(0, 0, 0), new Vector3(110f, 0, 0f), 1F);

            gl3dcontroller.KeyboardTravelSpeed = (ms, eyedist) =>
            {
                return((float)ms / 100.0f);
            };

            items.Add(new GLTexturedShaderObjectTranslation(), "TEXOT");
            items.Add(new GLTexturedShaderObjectTranslation(), "TEXOTNoRot");
            items.Add(new GLColorShaderWorld(), "COSW");
            items.Add(new GLColorShaderObjectTranslation(), "COSOT");
            items.Add(new GLFixedColorShaderObjectTranslation(Color.Goldenrod), "FCOSOT");
            items.Add(new GLTexturedShaderObjectCommonTranslation(), "TEXOCT");

            items.Add(new GLTexture2D(Properties.Resources.dotted2, SizedInternalFormat.Rgba8), "dotted");
            items.Add(new GLTexture2D(Properties.Resources.Logo8bpp, SizedInternalFormat.Rgba8), "logo8bpp");

            items.Add(new GLTexture2D(Properties.Resources.wooden, SizedInternalFormat.Rgba8), "wooden");
            items.Add(new GLTexture2D(Properties.Resources.shoppinglist, SizedInternalFormat.Rgba8), "shoppinglist");
            items.Add(new GLTexture2D(Properties.Resources.golden, SizedInternalFormat.Rgba8), "golden");
            items.Add(new GLTexture2D(Properties.Resources.smile5300_256x256x8, SizedInternalFormat.Rgba8), "smile");
            items.Add(new GLTexture2D(Properties.Resources.moonmap1k, SizedInternalFormat.Rgba8), "moon");


            ts1 = new GLOperationQueryTimeStamp();
            ts2 = new GLOperationQueryTimeStamp();

            rObjects.Add(ts1);

            #region coloured lines

            GLRenderState def = new GLRenderState()
            {
                DepthTest = true
            };                                                                 // set up default state for fixed values - no depth test, rely on stencil

            GLBuffer querybuffer = new GLBuffer(128, true);

            #region Coloured triangles
            if (true)
            {
                GLRenderState rc = GLRenderState.Tri(def);
                rc.CullFace = true;

                // Lets demo the query buffer!

                var q1 = new GLOperationQuery(OpenTK.Graphics.OpenGL4.QueryTarget.PrimitivesGenerated, 0, true, querybuffer);
                items.Add(q1);
                rObjects.Add(q1);

                var q2 = new GLOperationQuery(OpenTK.Graphics.OpenGL4.QueryTarget.SamplesPassed, 0, false, querybuffer);
                items.Add(q2);
                rObjects.Add(q2);

                rObjects.Add(items.Shader("COSOT"), "Tri1",
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Triangles, rc,
                                                                  GLCubeObjectFactory.CreateSolidCubeFromTriangles(5f),
                                                                  new Color4[] { Color4.Red, Color4.Red, Color4.Red, Color4.Red, Color4.Yellow, Color4.Yellow },
                                                                  new GLRenderDataTranslationRotation(new Vector3(10, 3, 20))
                                                                  ));

                rObjects.Add(new GLOperationEndQuery(q2, querycomplete: (t) =>
                {
                    //    int v = t.GetQuery(OpenTK.Graphics.OpenGL4.GetQueryObjectParam.QueryResult);
                    t.UpdateBuffer(0);
                    //System.Diagnostics.Debug.WriteLine($"Samples for first {v}");
                }));

                rObjects.Add(new GLOperationEndQuery(q1, querycomplete: (t) =>
                {
                    t.UpdateBuffer(16);
                    int[] ints = querybuffer.ReadInts(0, 8);
                    System.Diagnostics.Debug.WriteLine($"Samples {ints[0]} Prims {ints[4]}");
                }));

                rObjects.Add(new GLOperationEndQueryBuffer());      // must turn off otherwise it goes awol next loop
            }



            for (int i = 0; i < 1; i++)
            {
                GLRenderState lines = GLRenderState.Lines(def, 5);

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, -0, -100), new Vector3(-100, -0, 100), new Vector3(10, 0, 0), 21),
                                                                  new Color4[] { Color.White, Color.Red, Color.DarkRed, Color.DarkRed })
                             );

                GLRenderState lines2 = GLRenderState.Lines(def, 1);

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines2,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, -0, -100), new Vector3(100, -0, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Orange, Color.Blue, Color.DarkRed, Color.DarkRed }));

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines2,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 10, -100), new Vector3(-100, 10, 100), new Vector3(10, 0, 0), 21),
                                                                  new Color4[] { Color.Yellow, Color.Orange, Color.Yellow, Color.Orange })
                             );

                rObjects.Add(items.Shader("COSW"),
                             GLRenderableItem.CreateVector4Color4(items, PrimitiveType.Lines, lines2,
                                                                  GLShapeObjectFactory.CreateLines(new Vector3(-100, 10, -100), new Vector3(100, 10, -100), new Vector3(0, 0, 10), 21),
                                                                  new Color4[] { Color.Yellow, Color.Orange, Color.Yellow, Color.Orange })
                             );
            }

            rObjects.Add(ts2);

            #endregion


            #endregion

            #region Matrix Calc Uniform

            items.Add(new GLMatrixCalcUniformBlock(), "MCUB");     // def binding of 0

            #endregion
        }