Exemplo n.º 1
0
        public IControlRenderer CreateControlRenderer(IView view)
        {
            var dimensions = new RenderDimensionReference();

            dimensions.SetDimensions(view.Size.Width, view.Size.Height);
            return(new ControlRenderer(dimensions));
        }
Exemplo n.º 2
0
        public Context(RenderDimensionReference dimensions)
        {
            // We need at least OpenGL 3.1 for instancing, shaders and primitive restart.
            if (State.OpenGLVersionMajor < 3 || (State.OpenGLVersionMajor == 3 && State.OpenGLVersionMinor < 1))
            {
                throw new NotSupportedException($"OpenGL version 3.1 is required for rendering. Your version is {State.OpenGLVersionMajor}.{State.OpenGLVersionMinor}.");
            }

            State.Gl.ClearColor(_backgroundColor);

            State.Gl.Enable(EnableCap.DepthTest);
            State.Gl.DepthFunc(DepthFunction.Lequal);

            State.Gl.Disable(EnableCap.Blend); // will be enabled later
            State.Gl.BlendEquationSeparate(GLEnum.FuncAdd, GLEnum.FuncAdd);
            State.Gl.BlendFuncSeparate(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha, BlendingFactor.One, BlendingFactor.Zero);

            Resize(dimensions.Width, dimensions.Height);

            dimensions.DimensionsChanged += () => Resize(dimensions.Width, dimensions.Height);
        }
Exemplo n.º 3
0
        public void Render(RenderDimensionReference renderDimensionReference, Color?colorKey = null)
        {
            State.Gl.Enable(GLEnum.PrimitiveRestart);
            State.Gl.PrimitiveRestartIndex(IndexBuffer.PrimitiveRestartIndex);

            foreach (var vertexArrayObject in _vertexArrayObjects)
            {
                var vao = vertexArrayObject.Value;

                vao.Bind();

                unsafe
                {
                    vao.Lock();

                    try
                    {
                        if (vao.Shader is IShaderWithScreenHeight shader)
                        {
                            shader.SetScreenHeight((uint)renderDimensionReference.Height);
                        }
                        vao.Shader.UpdateMatrices(false); // TODO: later support zoom?
                        vao.ColorKey = colorKey;
                        State.Gl.DrawElements(PrimitiveType.TriangleFan,
                                              (uint)vao.IndexBuffer.Size, DrawElementsType.UnsignedInt, (void *)0);
                    }
                    catch
                    {
                        // ignore for now
                    }
                    finally
                    {
                        vao.Unlock();
                    }
                }
            }

            State.Gl.Disable(GLEnum.PrimitiveRestart);
        }
Exemplo n.º 4
0
 public ControlRenderer(RenderDimensionReference renderDimensionReference)
 {
     _renderDimensionReference = renderDimensionReference;
     _context = new Context(renderDimensionReference);
 }