/// <summary> /// Draw the attributes of this vertex array. /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> used for rendering. /// </param> /// <param name="shader"> /// The <see cref="ShaderProgram"/> used for drawing the vertex arrays. /// </param> public virtual void Draw(GraphicsContext ctx, ShaderProgram shader) { CheckThisExistence(ctx); if (shader != null && shader.Exists(ctx) == false) throw new ArgumentException("not existing", "shader"); // If vertex was modified after creation, don't miss to create array buffers if (_VertexArrayDirty) CreateObject(ctx); // Set vertex arrays SetVertexArrayState(ctx, shader); // Fixed or programmable pipeline? if ((shader == null) && (ctx.Caps.GlExtensions.VertexShader_ARB == true)) ShaderProgram.Unbind(ctx); else if (shader != null) shader.Bind(ctx); // Issue rendering using shader foreach (Element attributeElement in DrawElements) { if (_FeedbackBuffer != null) _FeedbackBuffer.Begin(ctx, attributeElement.ElementsMode); attributeElement.Draw(ctx); if (_FeedbackBuffer != null) _FeedbackBuffer.End(ctx); } }
/// <summary> /// Render this vertex array. /// </summary> /// <param name="ctx"> /// The <see cref="GraphicsContext"/> used for rendering. /// </param> /// <param name="shaderProgram"> /// The <see cref="ShaderProgram"/> used for drawing this vertex array. /// </param> public override void Draw(GraphicsContext ctx, ShaderProgram shaderProgram) { if (ctx == null) throw new ArgumentNullException("ctx"); if (ctx.IsCurrent == false) throw new ArgumentException("not current", "ctx"); if (shaderProgram == null) throw new ArgumentNullException("shaderProgram"); if (shaderProgram.Exists(ctx) == false) throw new ArgumentException("not existing", "shaderProgram"); if (Exists(ctx) == false) throw new InvalidOperationException("not existing"); if (_Elements.Count == 0 && _PatchElement == null) throw new InvalidOperationException("no elements defined"); if (_PatchElement != null) { // Setup patch vertices Gl.PatchParameter(Gl.PATCH_VERTICES, (int)_PatchElement.PatchCount); // GL_PATCH_DEFAULT_OUTER_LEVEL | GL_PATCH_DEFAULT_INNER_LEVEL // Set vertex arrays SetVertexArrayState(ctx, shaderProgram); // Uses shader shaderProgram.Bind(ctx); // Draw patches _PatchElement.Draw(ctx); } // Based implementation if (_Elements.Count > 0) base.Draw(ctx, shaderProgram); }