private void RenderCommandLists(ImDrawDataPtr drawData)
        {
            // TODO Pass in the game window to get the screen width and height
            var m_Ortho = Monorail.Mathlib.Matrix4.CreateOrthographicOffCenter(0, 1280, 800, 0, -1, 1);

            m_GraphicsDevice.BindVertexArrayObject(m_VertexArrayObject.VaoId);

            var drawcount = 0;
            int vtxOffset = 0;
            int idxOffset = 0;

            for (int n = 0; n < drawData.CmdListsCount; n++)
            {
                ImDrawListPtr cmdList = drawData.CmdListsRange[n];
                for (int cmdi = 0; cmdi < cmdList.CmdBuffer.Size; cmdi++)
                {
                    ImDrawCmdPtr drawCmd = cmdList.CmdBuffer[cmdi];
                    var          texId   = drawCmd.TextureId;


                    OpenGL.GlBindings.Enable(OpenGL.Enable.GL_SCISSOR_TEST);
                    OpenGL.GlBindings.glScissor((int)drawCmd.ClipRect.X, (int)drawCmd.ClipRect.Y, (uint)(drawCmd.ClipRect.Z - drawCmd.ClipRect.X), (uint)(drawCmd.ClipRect.W - drawCmd.ClipRect.Y));



                    // TODO If textureId not loaded?
                    //    m_GraphicsDevice.ScissorRect();
                    m_GraphicsDevice.BindShaderProgram(m_ShaderProgram.ShaderProgramId);

                    m_GraphicsDevice.BindVertexArrayObject(m_VertexArrayObject.VaoId);
                    m_GraphicsDevice.BindTexture(m_Texture.TextureId, OpenGL.TextureType.GL_TEXTURE_2D);


                    m_ShaderProgram.SetUniform("projection_matrix", m_Ortho);
                    m_ShaderProgram.SetUniform("FontTexture", 0);


                    m_GraphicsDevice.DrawElements(PrimitiveType.TriangleList, (int)drawCmd.ElemCount, DrawElementsType.UnsignedInt, idxOffset);


                    drawcount++;

                    idxOffset += (int)drawCmd.ElemCount;
                }
                vtxOffset += cmdList.VtxBuffer.Size;
            }

            OpenGL.GlBindings.Disable(OpenGL.Enable.GL_SCISSOR_TEST);
        }
Example #2
0
        public void Render(RenderableObject renderObject, GameCamera camera)
        {
            // TODO this should actually enqueue rather than render but hey!
            if (renderObject.IsWireframe)
            {
                m_Graphics.FillMode(OpenGL.Mode.GL_LINE);
            }

            if (renderObject.DepthBufferEnabled == false)
            {
                m_Graphics.Disable(OpenGL.Enable.GL_DEPTH_TEST);
            }

            // TODO This texture setting needs improving
            if (renderObject.CubemapTextureId > -1)
            {
                m_Graphics.BindTexture(renderObject.CubemapTextureId, OpenGL.TextureType.GL_TEXTURE_CUBE_MAP, OpenGL.TextureUnits.GL_TEXTURE0);
            }

            if (renderObject.TextureIdA > -1)
            {
                m_Graphics.BindTexture(renderObject.TextureIdA, OpenGL.TextureType.GL_TEXTURE_2D, OpenGL.TextureUnits.GL_TEXTURE0);
            }

            if (renderObject.TextureIdB > -1)
            {
                m_Graphics.BindTexture(renderObject.TextureIdB, OpenGL.TextureType.GL_TEXTURE_2D, OpenGL.TextureUnits.GL_TEXTURE1);
            }


            m_Graphics.BindShaderProgram(renderObject.ShaderId);

            renderObject.OnApplyUniforms(this, camera);

            if (renderObject.BlendMode == BlendModes.Alpha)
            {
                m_Graphics.Enable(OpenGL.Enable.GL_BLEND);
                m_Graphics.BlendFunc(OpenGL.BlendFunc.GL_SRC_ALPHA, OpenGL.BlendFunc.GL_ONE_MINUS_SRC_ALPHA);
            }

            m_Graphics.BindVertexArrayObject(renderObject.VaoId);

            if (renderObject.HasIndexBuffer)
            {
                m_Graphics.DrawElements(PrimitiveType.TriangleList, renderObject.VertexCount, DrawElementsType.UnsignedInt, 0);
            }
            else
            {
                m_Graphics.DrawArrays(PrimitiveType.TriangleList, 0, renderObject.VertexCount);
            }

            if (renderObject.DepthBufferEnabled == false)
            {
                m_Graphics.Enable(OpenGL.Enable.GL_DEPTH_TEST);
            }

            if (renderObject.IsWireframe)
            {
                m_Graphics.FillMode(OpenGL.Mode.GL_FILL);
            }

            if (renderObject.BlendMode == BlendModes.Alpha)
            {
                m_Graphics.Disable(OpenGL.Enable.GL_BLEND);
            }
        }