Ejemplo n.º 1
0
        public QVertexArrayObject(SharedState state)
        {
            QFontSharedState = state;

            Vertices = new List <QVertex>(InitialSize);
            _bufferMaxVertexCount = InitialSize;
            _bufferSize           = _bufferMaxVertexCount * QVertexStride;

#if !OPENGL_ES
            VAOID = GL.GenVertexArray();
#endif

            GL.UseProgram(QFontSharedState.ShaderVariables.ShaderProgram);

#if !OPENGL_ES
            GL.BindVertexArray(VAOID);
#endif

            GL.GenBuffers(1, out VBOID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, VBOID);
            EnableAttributes();

            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)_bufferSize, IntPtr.Zero, BufferUsageHint.StreamDraw);

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

#if !OPENGL_ES
            GL.BindVertexArray(0);
#endif
        }
Ejemplo n.º 2
0
        public QVertexArrayObject(SharedState state)
        {
            _qFontSharedState = state;
            _vertexCapacity   = 1000;
            _vertexArray      = new QVertex[_vertexCapacity];
            _vboDataCapacity  = 0;

            GL.UseProgram(_qFontSharedState.ShaderVariables.ShaderProgram);
            GL.GenBuffers(1, out _vboid);
        }
Ejemplo n.º 3
0
        public QVertexArrayObject(SharedState state)
        {
            QFontSharedState = state;

            Vertices = new List<QVertex>(InitialSize);
            _bufferMaxVertexCount = InitialSize;
            _bufferSize = _bufferMaxVertexCount * QVertexStride;

            GL.UseProgram(QFontSharedState.ShaderVariables.ShaderProgram);

            GL.GenBuffers(1, out VBOID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, VBOID);
            EnableAttributes();

            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)_bufferSize, IntPtr.Zero, BufferUsageHint.StreamDraw );

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///     Initializes the static shared render state
        /// </summary>
        private static void InitialiseStaticState()
        {
            GL.Enable(EnableCap.Texture2D);

            //Create vertex and fragment shaders
            int vert = GL.CreateShader(ShaderType.VertexShader);
            int frag = GL.CreateShader(ShaderType.FragmentShader);

            //Check shaders were created succesfully
            if (vert == -1 || frag == -1)
            {
                throw new Exception(string.Format("Error creating shader name for {0}", vert == -1 ? (frag == -1 ? "vert and frag shaders" : "vert shader") : "frag shader"));
            }

            //Compile default (simple) shaders
            int vertCompileStatus;
            int fragCompileStatus;

            GL.ShaderSource(vert, LoadShaderFromRessource("simple.vs"));
            GL.CompileShader(vert);
            GL.ShaderSource(frag, LoadShaderFromRessource("simple.fs"));
            GL.CompileShader(frag);

            GL.GetShader(vert, ShaderParameter.CompileStatus, out vertCompileStatus);
            GL.GetShader(frag, ShaderParameter.CompileStatus, out fragCompileStatus);

            //Check shaders were compiled correctly
            //TODO Worth doing this rather than just checking the total program error log?
            if (vertCompileStatus == 0 || fragCompileStatus == 0)
            {
                string vertInfo = GL.GetShaderInfoLog(vert);
                string fragInfo = GL.GetShaderInfoLog(frag);
                throw new Exception(String.Format("Shaders were not compiled correctly. Info logs are\nVert:\n{0}\nFrag:\n{1}", vertInfo, fragInfo));
            }

            int prog;
            int progLinkStatus;

            prog = GL.CreateProgram();
            GL.AttachShader(prog, vert);
            GL.AttachShader(prog, frag);
            GL.LinkProgram(prog);

            //Check program was linked without errors
            GL.GetProgram(prog, GetProgramParameterName.LinkStatus, out progLinkStatus);
            if (progLinkStatus == 0)
            {
                string programInfoLog = GL.GetProgramInfoLog(prog);
                throw new Exception(String.Format("Program was not linked correctly. Info log is\n{0}", programInfoLog));
            }

            //Detach then delete unneeded shaders
            GL.DetachShader(prog, vert);
            GL.DetachShader(prog, frag);
            GL.DeleteShader(vert);
            GL.DeleteShader(frag);

            //Retrieve shader attribute and uniform locations
            int mvpLoc     = GL.GetUniformLocation(prog, "proj_matrix");
            int samplerLoc = GL.GetUniformLocation(prog, "tex_object");
            int posLoc     = GL.GetAttribLocation(prog, "in_position");
            int tcLoc      = GL.GetAttribLocation(prog, "in_tc");
            int colLoc     = GL.GetAttribLocation(prog, "in_colour");

            //Now we have all the information, time to create the immutable shared state object
            var shaderVariables = new ShaderVariables(prog, mvpLoc, tcLoc, posLoc, samplerLoc, colLoc);
            var sharedState     = new SharedState(TextureUnit.Texture0, shaderVariables);

            _QFontSharedState = sharedState;
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Initializes the static shared render state
        /// </summary>
        private static void InitialiseStaticState()
        {
            GL.Enable(EnableCap.Texture2D);

            //Create vertex and fragment shaders
            int vert = GL.CreateShader(ShaderType.VertexShader);
            int frag = GL.CreateShader(ShaderType.FragmentShader);

            //Check shaders were created succesfully
            if (vert == -1 || frag == -1)
            {
                throw new Exception(string.Format("Error creating shader name for {0}", vert == -1 ? (frag == -1 ? "vert and frag shaders" : "vert shader") : "frag shader"));
            }

            // We try to compile the shaders with ever increasing version numbers (up to 1.50)
            // This fixes a bug on MaxOSX where the Core profile only supports shaders >= 1.50 (or sometimes 1.40)
            var versions = new string[] { shaderVersionString130, shaderVersionString140, shaderVersionString150 };

            // Holds the compilation status of the shaders
            int vertCompileStatus = 0;
            int fragCompileStatus = 0;

            foreach (var version in versions)
            {
                // These assignments are not needed
                vertCompileStatus = 0;
                fragCompileStatus = 0;

#if OPENGL_ES
                GL.ShaderSource(vert, LoadShaderFromResource("simple_es.vs"));
                GL.ShaderSource(frag, LoadShaderFromResource("simple_es.fs"));
#else
                GL.ShaderSource(vert, version + LoadShaderFromResource("simple.vs"));
                GL.ShaderSource(frag, version + LoadShaderFromResource("simple.fs"));
#endif

                GL.CompileShader(vert);
                GL.CompileShader(frag);

                GL.GetShader(vert, ShaderParameter.CompileStatus, out vertCompileStatus);
                GL.GetShader(frag, ShaderParameter.CompileStatus, out fragCompileStatus);

                // Check shaders were compiled correctly
                // If they have, we break out of the foreach loop as we have found the minimum supported glsl version
                if (vertCompileStatus != 0 && fragCompileStatus != 0)
                {
                    break;
                }

                // Otherwise continue with the loop
            }

            // Check that we ended up with a compiled shader at the end of all this
            // These will only be 0 if all compilations with different versions failed,
            // since we break out of the version loop as soon as one compiles
            if (vertCompileStatus == 0 || fragCompileStatus == 0)
            {
                string vertInfo = GL.GetShaderInfoLog(vert);
                string fragInfo = GL.GetShaderInfoLog(frag);
                throw new Exception(String.Format("Shaders were not compiled correctly. Info logs are\nVert:\n{0}\nFrag:\n{1}", vertInfo, fragInfo));
            }

            // I don't think we need to loop through versions for the linking step, as any compilation errors should be picked up
            // in the previous loop? TODO: Verify this assumption

            int prog;
            int progLinkStatus;

            prog = GL.CreateProgram();
            GL.AttachShader(prog, vert);
            GL.AttachShader(prog, frag);
            GL.LinkProgram(prog);

            //Check program was linked without errors
            GL.GetProgram(prog, GetProgramParameterName.LinkStatus, out progLinkStatus);
            if (progLinkStatus == 0)
            {
                string programInfoLog = GL.GetProgramInfoLog(prog);
                throw new Exception(String.Format("Program was not linked correctly. Info log is\n{0}", programInfoLog));
            }

            //Detach then delete unneeded shaders
            GL.DetachShader(prog, vert);
            GL.DetachShader(prog, frag);
            GL.DeleteShader(vert);
            GL.DeleteShader(frag);

            //Retrieve shader attribute and uniform locations
            int mvpLoc     = GL.GetUniformLocation(prog, "proj_matrix");
            int samplerLoc = GL.GetUniformLocation(prog, "tex_object");
            int posLoc     = GL.GetAttribLocation(prog, "in_position");
            int tcLoc      = GL.GetAttribLocation(prog, "in_tc");
            int colLoc     = GL.GetAttribLocation(prog, "in_colour");

            //Now we have all the information, time to create the immutable shared state object
            var shaderVariables = new ShaderVariables(prog, mvpLoc, tcLoc, posLoc, samplerLoc, colLoc);
            var sharedState     = new SharedState(TextureUnit.Texture0, shaderVariables);

            _QFontSharedState = sharedState;
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Initializes the static shared render state
        /// </summary>
        private static void InitialiseStaticState()
        {
            GL.Enable(EnableCap.Texture2D);

            //Create vertex and fragment shaders
            int vert = GL.CreateShader(ShaderType.VertexShader);
            int frag = GL.CreateShader(ShaderType.FragmentShader);

            //Check shaders were created succesfully
            if (vert == -1 || frag == -1)
                throw new Exception(string.Format("Error creating shader name for {0}", vert == -1 ? (frag == -1 ? "vert and frag shaders" : "vert shader") : "frag shader"));

            //Compile default (simple) shaders
            int vertCompileStatus;
            int fragCompileStatus;

            GL.ShaderSource(vert, LoadShaderFromRessource("simple.vs"));
            GL.CompileShader(vert);
            GL.ShaderSource(frag, LoadShaderFromRessource("simple.fs"));
            GL.CompileShader(frag);

            GL.GetShader(vert, ShaderParameter.CompileStatus, out vertCompileStatus);
            GL.GetShader(frag, ShaderParameter.CompileStatus, out fragCompileStatus);

            //Check shaders were compiled correctly
            //TODO Worth doing this rather than just checking the total program error log?
            if (vertCompileStatus == 0 || fragCompileStatus == 0)
            {
                string vertInfo = GL.GetShaderInfoLog(vert);
                string fragInfo = GL.GetShaderInfoLog(frag);
                throw new Exception(String.Format("Shaders were not compiled correctly. Info logs are\nVert:\n{0}\nFrag:\n{1}", vertInfo, fragInfo));
            }

            int prog;
            int progLinkStatus;

            prog = GL.CreateProgram();
            GL.AttachShader(prog, vert);
            GL.AttachShader(prog, frag);
            GL.LinkProgram(prog);

            //Check program was linked without errors
            GL.GetProgram(prog, GetProgramParameterName.LinkStatus, out progLinkStatus);
            if (progLinkStatus == 0)
            {
                string programInfoLog = GL.GetProgramInfoLog(prog);
                throw new Exception(String.Format("Program was not linked correctly. Info log is\n{0}", programInfoLog));
            }

            //Detach then delete unneeded shaders
            GL.DetachShader(prog, vert);
            GL.DetachShader(prog, frag);
            GL.DeleteShader(vert);
            GL.DeleteShader(frag);

            //Retrieve shader attribute and uniform locations
            int mvpLoc = GL.GetUniformLocation(prog, "proj_matrix");
            int samplerLoc = GL.GetUniformLocation(prog, "tex_object");
            int posLoc = GL.GetAttribLocation(prog, "in_position");
            int tcLoc = GL.GetAttribLocation(prog, "in_tc");
            int colLoc = GL.GetAttribLocation(prog, "in_colour");

            //Now we have all the information, time to create the immutable shared state object
            var shaderVariables = new ShaderVariables(prog, mvpLoc, tcLoc, posLoc, samplerLoc, colLoc);
            var sharedState = new SharedState(TextureUnit.Texture0, shaderVariables);

            _QFontSharedState = sharedState;
        }