Ejemplo n.º 1
0
        public void Dispose()
        {
            GLDebug.CheckAccess();

            GL.DeleteBuffer(vertexBufferId);
            GL.DeleteProgram(shaderProgramHandle);
        }
        protected override void Update8bppTexture(int texture, int width, int height, byte[] pixels)
        {
            GLDebug.CheckAccess();

            GL.BindTexture(TextureTarget.Texture2D, texture);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.R8, width, height, 0, PixelFormat.Red, PixelType.UnsignedByte, pixels);
        }
Ejemplo n.º 3
0
        public override unsafe Model CreateModel(ModelContent data)
        {
            GLDebug.CheckAccess();

            var meshes = new List <ModelMesh>();

            foreach (var mesh in data.Meshes)
            {
                var faces = new List <ModelFace>();
                foreach (var face in mesh.Faces)
                {
                    var indexBuffer = GL.GenBuffer();

                    GL.BindBuffer(BufferTarget.ArrayBuffer, indexBuffer);
                    GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)face.Indices.Length, face.Indices, BufferUsageHint.StaticDraw);

                    faces.Add(new ModelFace(indexBuffer, face.Indices));
                }

                var vertexBuffer = GL.GenBuffer();

                GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);
                GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(mesh.Vertices.Length * VertexPositionNormalTexture.SizeInBytes), mesh.Vertices, BufferUsageHint.StaticDraw);

                meshes.Add(new ModelMesh(vertexBuffer,
                                         mesh.Name, mesh.MaterialIndex, mesh.Vertices, faces.ToArray()));
            }

            return(new Model(meshes.ToArray()));
        }
Ejemplo n.º 4
0
        protected override void BeginFrame()
        {
            GLDebug.CheckAccess();

            GL.Viewport(0, 0, Width, Height);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
        }
Ejemplo n.º 5
0
        protected override void EndFrame(byte[] pixels)
        {
            GLDebug.CheckAccess();

            if (pixels != null)
            {
                GL.ReadPixels(0, 0, Width, Height, PixelFormat.Bgra, PixelType.UnsignedByte, pixels);

                // Flip Y
                for (int y = 0; y < Height / 2; y++)
                {
                    var a = y * Width * 4;
                    var b = (Height - y - 1) * Width * 4;

                    for (int x = 0; x < Width * 4; x++)
                    {
                        var tmp = pixels[a + x];
                        pixels[a + x] = pixels[b + x];
                        pixels[b + x] = tmp;
                    }
                }
            }

            _window.SwapBuffers();
        }
Ejemplo n.º 6
0
        private void CreateShaders()
        {
            GLDebug.CheckAccess();

            var vertexShaderHandle   = GL.CreateShader(ShaderType.VertexShader);
            var fragmentShaderHandle = GL.CreateShader(ShaderType.FragmentShader);

            GL.ShaderSource(vertexShaderHandle, vertexShaderSource);
            GL.ShaderSource(fragmentShaderHandle, fragmentShaderSource);

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

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

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

            GL.BindAttribLocation(shaderProgramHandle, 0, "in_position");
            GL.BindAttribLocation(shaderProgramHandle, 1, "in_color");
            GL.BindAttribLocation(shaderProgramHandle, 2, "in_uv");

            GL.LinkProgram(shaderProgramHandle);

            //Debug.WriteLine(GL.GetProgramInfoLog(shaderProgramHandle));
            GL.UseProgram(shaderProgramHandle);

            // Set uniforms
            transformLocation = GL.GetUniformLocation(shaderProgramHandle, "transform");
        }
Ejemplo n.º 7
0
        private void CreateBuffers()
        {
            GLDebug.CheckAccess();

            vertexBufferId = GL.GenBuffer();
            indexBufferId  = GL.GenBuffer();
        }
        public EmbeddedGraphicsHost(IntPtr windowHandle, GraphicsMode mode = null)
        {
            GLDebug.CheckAccess();

            GraphicsContext = new GraphicsContext(mode ?? GraphicsMode.Default, Utilities.CreateWindowsWindowInfo(windowHandle));

            GL.ClearColor(Color4.Transparent);
        }
        protected override Texture <int> Create8BppTexture(int width, int height, byte[] pixels)
        {
            GLDebug.CheckAccess();

            var texture = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, texture);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.R8, width, height, 0, PixelFormat.Red, PixelType.UnsignedByte, pixels);

            return(new Texture <int>(texture, width, height, true));
        }
Ejemplo n.º 10
0
        public override Texture <int> CreateTexture(TextureContent data)
        {
            GLDebug.CheckAccess();

            var texture = GL.GenTexture();

            GL.BindTexture(TextureTarget.Texture2D, texture);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, data.Pixels);

            return(new Texture <int>(texture, data.Width, data.Height, data.Left, data.Right, data.Top, data.Bottom, data.IsTransparent));
        }
        public bool DrawFrame(Action <int, int> draw, [CallerMemberName] string frameName = null)
        {
            GLDebug.CheckAccess();

            GL.Viewport(0, 0, 100, 100); // TODO:
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            draw(100, 100);

            GraphicsContext.SwapBuffers();

            return(true);
        }
Ejemplo n.º 12
0
        public GLTestGraphicsHost(
            int width, int height, GraphicsMode mode = null,
            int testDuration = 1000, float epsilon = 0.001f, string outputPath = null)
            : base("gl", width, height, testDuration, epsilon, outputPath)
        {
            GLDebug.CheckAccess();

            _window = new GameWindow(width, height, mode)
            {
                VSync = VSyncMode.Off
            };

            GL.ClearColor(Color4.Transparent);
        }
Ejemplo n.º 13
0
        public GLGraphicsHost(GameWindow window)
        {
            if (window == null)
            {
                throw new ArgumentNullException(nameof(window));
            }

            Window = window;

            SynchronizationContext.SetSynchronizationContext(s_syncContext);

            GLDebug.CheckAccess();

            GL.ClearColor(Color.Transparent);
        }
Ejemplo n.º 14
0
        protected override unsafe void Draw(Vertex2D *pVertex, int vertexCount, int texture, bool isTransparent)
        {
            GLDebug.CheckAccess();

            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertexCount * Vertex2D.SizeInBytes), (IntPtr)pVertex, BufferUsageHint.StaticDraw);
            GL.BindTexture(TextureTarget.Texture2D, texture);

            if (isTransparent)
            {
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha);
            }
            else
            {
                GL.Disable(EnableCap.Blend);
            }

            GL.DrawElements(BeginMode.Triangles, vertexCount / 4 * 6, DrawElementsType.UnsignedShort, 0);
        }
Ejemplo n.º 15
0
        public bool DrawFrame(Action <int, int> draw, [CallerMemberName] string frameName = null)
        {
            GLDebug.CheckAccess();

            Window.ProcessEvents();
            s_syncContext.DrainQueue();

            if (Window.IsExiting)
            {
                return(false);
            }

            GL.Viewport(0, 0, Window.Width, Window.Height);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            draw(Window.Width, Window.Height);

            Window.SwapBuffers();

            return(true);
        }
Ejemplo n.º 16
0
        protected override unsafe void BeginDraw(ref Matrix4x4 projection, ushort *pIndex, int indexCount)
        {
            GLDebug.CheckAccess();

            GL.UseProgram(shaderProgramHandle);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBufferId);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indexCount * sizeof(ushort)), (IntPtr)pIndex, BufferUsageHint.StaticDraw);

            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBufferId);

            GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, Vertex2D.SizeInBytes, 0);
            GL.VertexAttribPointer(1, 4, VertexAttribPointerType.UnsignedByte, true, Vertex2D.SizeInBytes, 8);
            GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, Vertex2D.SizeInBytes, 8 + 4);

            GL.EnableVertexAttribArray(0);
            GL.EnableVertexAttribArray(1);
            GL.EnableVertexAttribArray(2);

            fixed(float *ptr = &projection.M11)
            {
                GL.UniformMatrix4(transformLocation, 1, false, ptr);
            }
        }
        public void Dispose()
        {
            GLDebug.CheckAccess();

            GraphicsContext.Dispose();
        }
Ejemplo n.º 18
0
        public void Dispose()
        {
            GLDebug.CheckAccess();

            Window.Dispose();
        }