本文整理匯總了C#中SharpGL.OpenGL.BindVertexArray方法的典型用法代碼示例。如果您正苦於以下問題:C# OpenGL.BindVertexArray方法的具體用法?C# OpenGL.BindVertexArray怎麽用?C# OpenGL.BindVertexArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類SharpGL.OpenGL
的用法示例。
在下文中一共展示了OpenGL.BindVertexArray方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: InitShader
void IRenderable.Render(OpenGL gl, RenderMode renderMode)
{
if (positionBuffer != null && colorBuffer != null && radiusBuffer != null)
{
if (this.shaderProgram == null)
{
this.shaderProgram = InitShader(gl, renderMode);
}
if (this.vertexArrayObject == null)
{
CreateVertexArrayObject(gl, renderMode);
}
BeforeRendering(gl, renderMode);
if (this.RenderGrid && this.vertexArrayObject != null)
{
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);
gl.BindVertexArray(this.vertexArrayObject[0]);
gl.DrawArrays(OpenGL.GL_POINTS, 0, count);
gl.BindVertexArray(0);
gl.Disable(OpenGL.GL_BLEND);
}
AfterRendering(gl, renderMode);
}
}
示例2: BackgroundRenderer
public BackgroundRenderer(OpenGL gl)
{
_gl = gl;
_program = new BackgroundShader(gl);
_flat = new VAO(gl);
_flatBuffer = new VBO(gl);
using (new Bind(_flat))
using (new Bind(_flatBuffer))
{
var flatData = new float[] { -1, -1, 1, -1, -1, 1, 1, 1, };
_flatBuffer.Update(flatData, flatData.Length * sizeof(float));
gl.EnableVertexAttribArray(0);
gl.VertexAttribPointer(0, 2, OpenGL.GL_FLOAT, false, 0, new IntPtr(0));
gl.BindVertexArray(0);
}
}
示例3: PostProcesser
public PostProcesser(OpenGL gl,int width,int height)
{
_gl = gl;
_fbo = new FBO(gl, width, height);
_flatProgram = new FlatShader(gl);
_flat = new VAO(gl);
_flatBuffer = new VBO(gl);
using (new Bind(_flat))
using (new Bind(_flatBuffer))
{
var flatData = new float[] { -1, -1, 1, -1, -1, 1, 1, 1, };
_flatBuffer.Update(flatData, flatData.Length * sizeof(float));
gl.EnableVertexAttribArray(0);
gl.VertexAttribPointer(0, 2, OpenGL.GL_FLOAT, false, 0, new IntPtr(0));
gl.BindVertexArray(0);
}
}
示例4: OctreeRenderer
public OctreeRenderer(OctreeModel model, OpenGL gl)
{
_gl = gl;
_octreeProgram = new OctreeShader(gl);
_cubes = new VAO(gl);
_cubeBuffer = new VBO(gl);
var filled = model.Node.Flatten().Where(o => o.State == NodeState.Filled).ToArray();
_count = filled.Length;
var list = new List<float>();
foreach (var octreeNode in filled)
{
list.AddRange(octreeNode.Center.ToArray().Select(d => (float)d));
list.AddRange(new[]
{
(float)MathsHelper.Map(octreeNode.Color.R, 0, 255, 0, 1),
(float)MathsHelper.Map(octreeNode.Color.G, 0, 255, 0, 1),
(float)MathsHelper.Map(octreeNode.Color.B, 0, 255, 0, 1),
(float)MathsHelper.Map(octreeNode.Color.A, 0, 255, 0, 1),
(float)octreeNode.Size
});
}
var vertices = list.ToArray();
using (new Bind(_cubes))
using (new Bind(_cubeBuffer))
{
_cubeBuffer.Update(vertices, vertices.Length * sizeof(float));
const int stride = sizeof(float) * 8;
gl.EnableVertexAttribArray(0);
gl.VertexAttribPointer(0, 3, OpenGL.GL_FLOAT, false, stride, new IntPtr(0));
gl.EnableVertexAttribArray(1);
gl.VertexAttribPointer(1, 4, OpenGL.GL_FLOAT, false, stride, new IntPtr(sizeof(float) * 3));
gl.EnableVertexAttribArray(2);
gl.VertexAttribPointer(2, 1, OpenGL.GL_FLOAT, false, stride, new IntPtr(sizeof(float) * 7));
gl.BindVertexArray(0);
}
}
示例5: InitShader
void IRenderable.Render(OpenGL gl, RenderMode renderMode)
{
if (positionBuffer == null || colorBuffer == null) { return; }
if (this.shaderProgram == null)
{
this.shaderProgram = InitShader(gl, renderMode);
}
if (this.vertexArrayObject == null)
{
CreateVertexArrayObject(gl, renderMode);
}
BeforeRendering(gl, renderMode);
if (this.RenderGridWireframe && this.vertexArrayObject != null)
{
//if (wireframeIndexBuffer != null)
if (positionBuffer != null && colorBuffer != null && indexBuffer != null)
{
shaderProgram.SetUniform1(gl, "renderingWireframe", 1.0f);// shader一律上白色。
gl.Disable(OpenGL.GL_LINE_STIPPLE);
gl.Disable(OpenGL.GL_POLYGON_STIPPLE);
gl.Enable(OpenGL.GL_LINE_SMOOTH);
gl.Enable(OpenGL.GL_POLYGON_SMOOTH);
gl.ShadeModel(SharpGL.Enumerations.ShadeModel.Smooth);
gl.Hint(SharpGL.Enumerations.HintTarget.LineSmooth, SharpGL.Enumerations.HintMode.Nicest);
gl.Hint(SharpGL.Enumerations.HintTarget.PolygonSmooth, SharpGL.Enumerations.HintMode.Nicest);
gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Lines);
gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PrimitiveRestartIndex(uint.MaxValue);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);
gl.BindVertexArray(this.vertexArrayObject[0]);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer[0]);
gl.DrawElements(OpenGL.GL_QUAD_STRIP, this.indexBufferLength, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.BindVertexArray(0);
gl.Disable(OpenGL.GL_BLEND);
gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Filled);
gl.Disable(OpenGL.GL_POLYGON_SMOOTH);
}
}
if (this.RenderGrid && this.vertexArrayObject != null)
{
if (positionBuffer != null && colorBuffer != null && indexBuffer != null)
{
shaderProgram.SetUniform1(gl, "renderingWireframe", 0.0f);// shader根據uv buffer來上色。
gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PrimitiveRestartIndex(uint.MaxValue);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);
gl.BindVertexArray(this.vertexArrayObject[0]);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, indexBuffer[0]);
gl.DrawElements(OpenGL.GL_QUAD_STRIP, this.indexBufferLength, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.BindVertexArray(0);
gl.Disable(OpenGL.GL_BLEND);
gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
}
}
AfterRendering(gl, renderMode);
}
示例6: CreateVertexArrayObject
private void CreateVertexArrayObject(OpenGL gl, RenderMode renderMode)
{
if (this.positionBuffer == null || this.colorBuffer == null) { return; }
this.vertexArrayObject = new uint[1];
gl.GenVertexArrays(1, this.vertexArrayObject);
gl.BindVertexArray(this.vertexArrayObject[0]);
// prepare positions
{
int location = shaderProgram.GetAttributeLocation(gl, in_Position);
ATTRIB_INDEX_POSITION = (uint)location;
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, positionBuffer[0]);
gl.VertexAttribPointer(ATTRIB_INDEX_POSITION, 3, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
gl.EnableVertexAttribArray(ATTRIB_INDEX_POSITION);
}
// prepare colors
{
int location = shaderProgram.GetAttributeLocation(gl, in_uv);
ATTRIB_INDEX_UV = (uint)location;
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, colorBuffer[0]);
gl.VertexAttribPointer(ATTRIB_INDEX_UV, 1, OpenGL.GL_FLOAT, false, 0, IntPtr.Zero);
gl.EnableVertexAttribArray(ATTRIB_INDEX_UV);
}
gl.BindVertexArray(0);
}
示例7: BindHTVAO
public void BindHTVAO(OpenGL gl)
{
gl.BindVertexArray(VaoHT);
}
示例8: PrepareNMVAO
public void PrepareNMVAO(OpenGL gl, NormalMaterialProgram program)
{
var vertArrIds = new uint[1];
gl.GenVertexArrays(1, vertArrIds);
VaoNM = vertArrIds[0];
gl.BindVertexArray(VaoNM);
BindNMVBOs(gl, program);
gl.EnableVertexAttribArray(0);
gl.BindVertexArray(0);
}
示例9: PrepareHTVAO
public void PrepareHTVAO(OpenGL gl, HitTestProgram program)
{
var vertArrIds = new uint[1];
gl.GenVertexArrays(1, vertArrIds);
VaoHT = vertArrIds[0];
gl.BindVertexArray(VaoHT);
BindHTVBOs(gl, program);
gl.EnableVertexAttribArray(0);
gl.BindVertexArray(0);
}
示例10: BindNMVAO
public void BindNMVAO(OpenGL gl)
{
gl.BindVertexArray(VaoNM);
}
示例11: runGlThread
private void runGlThread(object args)
{
var inputs = (Tuple<CancellationToken>) args;
var cancelToken = inputs.Item1;
var gl = new OpenGL();
int localRenderWidth = 1;
int localRenderHeight = 1;
if (!createRenderContext(gl, localRenderWidth, localRenderHeight))
{
//TODO better error handling here
Console.WriteLine("*** Unable to create OpenGL Render Context");
return;
}
uint activeVaoHandle;
uint activeGlProgramHandle;
initGLObjects(gl, out activeVaoHandle, out activeGlProgramHandle);
ActiveProgramValues localActiveProgramValues = null;
while (!cancelToken.IsCancellationRequested)
{
bool resizeRenderContext;
lock (this)
{
if (!ReferenceEquals(localActiveProgramValues, activeProgramValues))
{
localActiveProgramValues = activeProgramValues;
if (localActiveProgramValues.Valid)
{
linkProgram(gl, localActiveProgramValues, activeGlProgramHandle);
} else
{
// Leave the old program running. This prevents the user from seeing
// a black screen while they are in the process of modifying a shader.
}
}
resizeRenderContext = localRenderWidth != renderWidth || localRenderHeight != renderHeight;
localRenderWidth = renderWidth;
localRenderHeight = renderHeight;
}
if (resizeRenderContext)
{
localActiveProgramValues = null;
deleteGlObjects(gl, activeVaoHandle, activeGlProgramHandle);
if (!createRenderContext(gl, localRenderWidth, localRenderHeight))
{
//TODO better error handling here
Console.WriteLine("*** Unable to resize OpenGL Render Context");
return;
}
initGLObjects(gl, out activeVaoHandle, out activeGlProgramHandle);
}
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT);
gl.BindVertexArray(activeVaoHandle);
gl.UseProgram(activeGlProgramHandle);
gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, 3);
// do some other stuff while the image is rendering, to give it a chance to finish
ShaderCompiler.ValidateShaders(gl);
var provider = gl.RenderContextProvider as FBORenderContextProvider;
Debug.Assert(provider != null, "Render context provider is not an FBO renderer");
//TODO this call to blit will probably block. Find a better way to copy the image to CPU memory.
gl.Blit(IntPtr.Zero);
var hBitmap = provider.InternalDIBSection.HBitmap;
if (hBitmap != IntPtr.Zero)
{
var bitmap = GetFormattedBitmapSource(hBitmap);
// the bitmap needs to be frozen in order to share it between threads
bitmap.Freeze();
ImageRendered(bitmap);
}
}
deleteGlObjects(gl, activeVaoHandle, activeGlProgramHandle);
}
示例12: BindAll
public void BindAll(OpenGL gl)
{
UseProgram(gl, () =>
{
// Update uniforms.
foreach (var action in ChangedUniforms)
{
action.Invoke(gl);
}
ChangedUniforms.Clear();
foreach (var group in BufferGroups)
{
group.BindVAO(gl);
gl.DrawElements(OpenGL.GL_TRIANGLES, group.IndicesCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.BindVertexArray(0);
}
});
}
示例13: PrepareVAO
public void PrepareVAO(OpenGL gl, LinesProgram program)
{
var vertArrIds = new uint[1];
gl.GenVertexArrays(1, vertArrIds);
Vao = vertArrIds[0];
gl.BindVertexArray(Vao);
BindVBOs(gl, program);
gl.EnableVertexAttribArray(0);
gl.BindVertexArray(0);
}
示例14: BindVAO
public void BindVAO(OpenGL gl)
{
var isBuffer = new bool[]
{
gl.IsBuffer(Vao),
gl.IsBuffer(Ibo),
gl.IsBuffer(Position),
gl.IsBuffer(Normal),
gl.IsBuffer(Vao),
gl.IsBuffer(Vao),
gl.IsBuffer(Vao),
gl.IsBuffer(Vao),
};
gl.BindVertexArray(Vao);
}
示例15: DoRenderMatrix
/// <summary>
/// 渲染基質
/// </summary>
/// <param name="gl"></param>
/// <param name="renderMode"></param>
private void DoRenderMatrix(OpenGL gl, RenderMode renderMode)
{
if (this.positionBuffer == null || this.colorBuffer == null) { return; }
if (this.RenderGrid && this.matrixVertexArrayObject != null)
{
shaderProgram.SetUniform1(gl, "renderingWireframe", 0.0f);
shaderProgram.SetUniform1(gl, "opacity", this.Opacity);
gl.Enable(OpenGL.GL_POLYGON_OFFSET_FILL);
gl.PolygonOffset(1.0f, 1.0f);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);
gl.BindVertexArray(matrixVertexArrayObject[0]);
switch (this.MatrixType)
{
case MatrixFormat.Triangle:
gl.DrawArrays(this.matrixRenderMode, 0, this.MatrixVertexOrIndexCount);
break;
case MatrixFormat.Tetrahedron:
gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PrimitiveRestartIndex(uint.MaxValue);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.matrixIndexBuffer[0]);
gl.DrawElements(this.matrixRenderMode, this.MatrixVertexOrIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
break;
case MatrixFormat.TriangularPrism:
// 先渲染三棱柱的上下三角形
gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, this.MatrixVertexOrIndexCount);
// 再渲染三棱柱的三個側麵
gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PrimitiveRestartIndex(uint.MaxValue);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.matrixIndexBuffer[0]);
gl.DrawElements(this.matrixRenderMode, this.MatrixVertexOrIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
break;
default:
break;
}
gl.BindVertexArray(0);
gl.Disable(OpenGL.GL_BLEND);
gl.Disable(OpenGL.GL_POLYGON_OFFSET_FILL);
}
if (this.RenderGridWireframe && this.matrixVertexArrayObject != null)
{
shaderProgram.SetUniform1(gl, "renderingWireframe", 1.0f);
shaderProgram.SetUniform1(gl, "opacity", this.Opacity);
gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Lines);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(SharpGL.Enumerations.BlendingSourceFactor.SourceAlpha, SharpGL.Enumerations.BlendingDestinationFactor.OneMinusSourceAlpha);
gl.BindVertexArray(matrixVertexArrayObject[0]);
switch (this.MatrixType)
{
case MatrixFormat.Triangle:
gl.DrawArrays(this.matrixRenderMode, 0, this.MatrixVertexOrIndexCount);
break;
case MatrixFormat.Tetrahedron:
gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PrimitiveRestartIndex(uint.MaxValue);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.matrixIndexBuffer[0]);
gl.DrawElements(this.matrixRenderMode, this.MatrixVertexOrIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
break;
case MatrixFormat.TriangularPrism:
// 先渲染三棱柱的上下三角形
gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, this.MatrixVertexOrIndexCount / 9 * 6);
// 再渲染三棱柱的三個側麵
gl.Enable(OpenGL.GL_PRIMITIVE_RESTART);
gl.PrimitiveRestartIndex(uint.MaxValue);
gl.BindBuffer(OpenGL.GL_ELEMENT_ARRAY_BUFFER, this.matrixIndexBuffer[0]);
gl.DrawElements(this.matrixRenderMode, this.MatrixVertexOrIndexCount, OpenGL.GL_UNSIGNED_INT, IntPtr.Zero);
gl.Disable(OpenGL.GL_PRIMITIVE_RESTART);
break;
default:
break;
}
gl.PolygonMode(SharpGL.Enumerations.FaceMode.FrontAndBack, SharpGL.Enumerations.PolygonMode.Filled);
gl.BindVertexArray(0);
gl.Disable(OpenGL.GL_BLEND);
}
}