Пример #1
0
 public void Attach(Shader shader)
 {
     if (!Bind())
         return;
     GL.BindBuffer(BufferTarget.ArrayBuffer, VertexDataBufferObject);
     shader.Use();
     int off = 0;
     for (int i = 0; i < declarations.Count; i++)
     {
         int location = GL.GetAttribLocation(shader.Handle, declarations[i].name);
         if (location != -1)
         {
             GL.VertexAttribPointer(location, declarations[i].elements, VertexAttribPointerType.Float, false, stride * sizeof(float), off);
             GL.EnableVertexAttribArray(location);
         }
         off += declarations[i].elements * sizeof(float);
     }
     GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndexDataBufferObject);
 }
Пример #2
0
        public void BindShader(Shader shader, string positionAttrib, string colorAttrib, string texcoordAttrib, string projectionUniform, string viewUniform)
        {
            vbuffer.ClearAttributeDeclarations();

            vbuffer.DeclareNextAttribute(positionAttrib, 2);
            vbuffer.DeclareNextAttribute(colorAttrib, 4);
            vbuffer.DeclareNextAttribute(texcoordAttrib, 2);

            vbuffer.Attach(shader);

            proj_uniform_loc = GL.GetUniformLocation(shader.Program, projectionUniform);
            view_uniform_loc = GL.GetUniformLocation(shader.Program, viewUniform);

            shader.Use();
            current = shader;
        }
Пример #3
0
        public void End()
        {
            int pr;
            GL.GetInteger(GetPName.CurrentProgram,out pr);
            if(current == null)
            {
                current = defaultShader;
                current.Use();
            }
            if (current.Program != pr)
                current.Use();
            current.SetUniform(proj_uniform_loc, ref proj);
            current.SetUniform(view_uniform_loc, ref trans);

            // nothing to do
            if (_batchItemList.Count == 0)
                return;

            vbuffer.Bind();
            vbuffer.UpdateVertexBuffer();
            vbuffer.UpdateIndexBuffer();
            int texID = -1;
            BeginMode mode = BeginMode.Triangles;
            float lineWidth;
            float pointSize;
            GL.GetFloat(GetPName.LineWidth, out lineWidth);
            GL.GetFloat(GetPName.PointSize, out pointSize);
            int offset = 0, count = 0;

            foreach (BatchItem item in _batchItemList)
            {
                if (item.texture != texID || item.mode != mode || lineWidth != item.lineWidth || pointSize != item.pointSize)
                {
                    FlushBuffer(mode, offset, count);
                    offset += count;
                    count = 0;

                    texID = item.texture;
                    mode = item.mode;
                    lineWidth = item.lineWidth;
                    pointSize = item.pointSize;
                    GL.BindTexture(TextureTarget.Texture2D, texID);
                    GL.LineWidth(item.lineWidth);
                    GL.PointSize(item.pointSize);
                }
                count += item.count;
                _freeBatchItemQueue.Enqueue(item);
            }

            // flush the remaining vertexArray data
            FlushBuffer(mode, offset, count);
            vbuffer.ClearBuffer();
            _batchItemList.Clear();
        }
Пример #4
0
        public void BindShader(Shader shader, string positionAttrib, string colorAttrib, string texcoordAttrib)
        {
            vbuffer.ClearAttributeDeclarations();

            vbuffer.DeclareNextAttribute(positionAttrib, 2);
            vbuffer.DeclareNextAttribute(colorAttrib, 4);
            vbuffer.DeclareNextAttribute(texcoordAttrib, 2);

            vbuffer.Attach(shader);

            shader.Use();
        }