public void CreateShaderProgramSequential()
        {
            using (var thread0Window = Device.CreateWindow(1, 1))
            using (var thread1Window = Device.CreateWindow(1, 1))
            using (var window = Device.CreateWindow(1, 1))
            using (ShaderProgramFactory factory0 = new ShaderProgramFactory(thread0Window.Context, ShaderSources.PassThroughVertexShader(), ShaderSources.PassThroughFragmentShader()))
            using (ShaderProgramFactory factory1 = new ShaderProgramFactory(thread1Window.Context, ShaderSources.PassThroughVertexShader(), ShaderSources.PassThroughFragmentShader()))
            {
                Thread t0 = new Thread(factory0.Create);
                t0.Start();
                t0.Join();

                Thread t1 = new Thread(factory1.Create);
                t1.Start();
                t1.Join();

                using (Framebuffer framebuffer = TestUtility.CreateFramebuffer(window.Context))
                using (VertexArray va = TestUtility.CreateVertexArray(window.Context, factory0.ShaderProgram.VertexAttributes["position"].Location))
                {
                    window.Context.Framebuffer = framebuffer;
                    window.Context.Draw(PrimitiveType.Points, 0, 1, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), factory0.ShaderProgram, va), new SceneState());
                    TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 255, 0, 0);

                    window.Context.Clear(new ClearState());
                    window.Context.Draw(PrimitiveType.Points, 0, 1, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), factory1.ShaderProgram, va), new SceneState());
                    TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 255, 0, 0);
                }
            }
        }
        public void CreateShaderProgramParallel()
        {
            using (var thread0Window = Device.CreateWindow(1, 1))
                using (var thread1Window = Device.CreateWindow(1, 1))
                    using (var window = Device.CreateWindow(1, 1))
                        using (ShaderProgramFactory factory0 = new ShaderProgramFactory(thread0Window.Context, ShaderSources.PassThroughVertexShader(), ShaderSources.PassThroughFragmentShader()))
                            using (ShaderProgramFactory factory1 = new ShaderProgramFactory(thread1Window.Context, ShaderSources.PassThroughVertexShader(), ShaderSources.PassThroughFragmentShader()))
                            {
                                Thread t0 = new Thread(factory0.Create);
                                t0.Start();

                                Thread t1 = new Thread(factory1.Create);
                                t1.Start();

                                t0.Join();
                                t1.Join();

                                using (Framebuffer framebuffer = TestUtility.CreateFramebuffer(window.Context))
                                    using (VertexArray va = TestUtility.CreateVertexArray(window.Context, factory0.ShaderProgram.VertexAttributes["position"].Location))
                                    {
                                        window.Context.Framebuffer = framebuffer;
                                        window.Context.Draw(PrimitiveType.Points, 0, 1, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), factory0.ShaderProgram, va), new SceneState());
                                        TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 255, 0, 0);

                                        window.Context.Clear(new ClearState());
                                        window.Context.Draw(PrimitiveType.Points, 0, 1, new DrawState(TestUtility.CreateRenderStateWithoutDepthTest(), factory1.ShaderProgram, va), new SceneState());
                                        TestUtility.ValidateColor(framebuffer.ColorAttachments[0], 255, 0, 0);
                                    }
                            }
        }
Beispiel #3
0
        /// <summary>
        /// Creates a default model with the given vertices. If no shader is provided, a default will be used assuming a position and color
        /// </summary>
        /// <typeparam name="TVertex">The vertex data type</typeparam>
        /// <param name="vertexData">the vertices to load to the associated VBO</param>
        /// <returns>A <see cref="Model"/> instance</returns>
        public static Model CreateModel <TVertex>(TVertex[] vertexData) where TVertex : struct
        {
            var vbo = VertexBuffer.CreateVertexBuffer();

            vbo.LoadData(vertexData);
            var vao = VertexArray.CreateVertexArray();

            vao.Bind();
            var shaderProgram = ShaderProgramFactory.CreateDefault2DShaderProgram();

            return(new Model(vao, vbo, shaderProgram));
        }
Beispiel #4
0
        public static Model CreateModel <TVertex>(Texture texture, TVertex[] vertexData, int[] indices) where TVertex : struct
        {
            var shader = ShaderProgramFactory.CreateDefault2DShaderProgramWithTexture();
            var vbo    = VertexBuffer.CreateVertexBuffer();

            vbo.LoadData(vertexData);
            var vao = VertexArray.CreateVertexArray();

            vao.Bind();
            shader.Use();
            shader.SetVertexAttributes();
            vbo.Bind();
            texture.Bind();
            var ebo   = ElementBuffer.CreateElementBuffer(indices);
            var model = new Model(vao, vbo, ebo, shader);

            return(model);
        }
Beispiel #5
0
        public override void Setup()
        {
            GL.Enable(EnableCap.DepthTest);
            GL.ClearColor(0.4f, 0.7f, 0.9f, 0.5f);

            var vertices = new ColoredTexturedVertex[] {
                new ColoredTexturedVertex(new Vector3(0.5f, 0.5f, 0.0f), Color4.Blue, new Vector2(1.0f, 1.0f)),
                new ColoredTexturedVertex(new Vector3(0.5f, -0.5f, 0.0f), Color4.Green, new Vector2(1.0f, 0.0f)),
                new ColoredTexturedVertex(new Vector3(-0.5f, -0.5f, 0.0f), Color4.Red, new Vector2(0.0f, 0.0f)),
                new ColoredTexturedVertex(new Vector3(-0.5f, 0.5f, 0.0f), Color4.Yellow, new Vector2(0.0f, 1.0f))
            };
            var indices = new int [] {
                0, 1, 3,
                1, 2, 3
            };
            var vao = VertexArray.CreateVertexArray();

            vao.Bind();
            _vao = vao;
            var vbo = VertexBuffer.CreateVertexBuffer();

            vbo.LoadData(vertices);
            _vbo = vbo;
            var ebo = ElementBuffer.CreateElementBuffer();

            ebo.LoadData(indices);
            _ebo = ebo;
            var shader = ShaderProgramFactory.CreateDefault3DShaderProgramWithTexture();

            _shader = shader;
            var texture0 = Texture.LoadTexture("Assets/Textures/container.png");

            texture0.Bind(0);
            var texture1 = Texture.LoadTexture("Assets/Textures/awesomeface.png");

            texture1.Bind(1);
            _shader.SetInt("texture1", 0);
            _shader.SetInt("texture2", 1);
            base.Setup();
        }
Beispiel #6
0
        /// <summary>
        /// Builds the shader(s) and passes required buffer array sizes.
        /// </summary>
        private void BuildShaders()
        {
#if (DEBUG)
            using (new DisposableStopwatch(MethodBase.GetCurrentMethod().Name, true))
#endif
            {
                Dictionary <int, EBufferTypes> bufferTypes = new();
                bufferTypes.Add(0, EBufferTypes.VertexArrayObject);
                bufferTypes.Add(1, EBufferTypes.VertexArrayObject);
                bufferTypes.Add(2, EBufferTypes.VertexArrayObject);
                triangleAndPointShader = ShaderProgramFactory.BuildTriangleAndPointShaderProgram("shaders/shader.vert", "shaders/shader.frag", bufferTypes);
                triangleAndPointShader.CurrentBuffer = 0;
                triangleAndPointShader.Vertexes      = new float[stars.StarVertexesCount];
                triangleAndPointShader.Indexes       = new uint[stars.StarIndexesCount];
                triangleAndPointShader.CurrentBuffer = 1;
                triangleAndPointShader.Vertexes      = new float[spectrumBars.SpectrumBarVertexesCount];
                triangleAndPointShader.Indexes       = new uint[spectrumBars.SpectrumBarIndexesCount];

                bufferTypes.Clear();
                bufferTypes.Add(0, EBufferTypes.VertexArrayObject);
                textureShader = ShaderProgramFactory.BuildTextureShaderProgram("shaders/textureShader.vert", "shaders/textureShader.frag", bufferTypes);
            }
        }