/// <summary> /// Construct an ElementBufferObject. /// </summary> /// <param name="elementType"> /// The <see cref="DrawElementsType"/> that specify how vertices are interpreted. /// </param> /// <param name="hint"> /// An <see cref="BufferObjectHint"/> that specify the data buffer usage hints. /// </param> public ElementBufferObject(DrawElementsType elementType, BufferObjectHint hint) : base(BufferTargetARB.ElementArrayBuffer, hint) { try { // Determine ElementsType and default RestartIndexKey ElementsType = elementType; switch (elementType) { case DrawElementsType.UnsignedByte: ItemSize = 1; RestartIndexKey = 0x000000FF; break; case DrawElementsType.UnsignedShort: ItemSize = 2; RestartIndexKey = 0x0000FFFF; break; case DrawElementsType.UnsignedInt: ItemSize = 4; RestartIndexKey = 0xFFFFFFFF; break; default: throw new ArgumentException("type not supported", "elementType"); } } catch { // Avoid finalizer assertion failure (don't call dispose since it's virtual) GC.SuppressFinalize(this); throw; } }
public static VertexIndices FromBuffer(VertexBuffer indexBuffer, int count, DrawElementsType indexType) { return new VertexIndices((t) => { indexBuffer.Bind(BufferTarget.ElementArrayBuffer, (b) => GL.DrawElements(t, count, indexType, IntPtr.Zero)); }); }
public AttribType(String fn_in, bool bn_in, DrawElementsType egl_de_in, VertexAttribPointerType egl_dv_in, int inum_in) { strNameFromFile = fn_in; bNormalized = bn_in; eGLTypeDrawElement = egl_de_in; eGLTypeDrawVertex = egl_dv_in; iNumBytes = inum_in; }
public static void MultiModeDrawElementsIBM(Int32[] mode, Int32[] count, DrawElementsType type, IntPtr[] indices, Int32 primcount, Int32 modestride) { unsafe { fixed (Int32* p_mode = mode) fixed (Int32* p_count = count) fixed (IntPtr* p_indices = indices) { Debug.Assert(Delegates.pglMultiModeDrawElementsIBM != null, "pglMultiModeDrawElementsIBM not implemented"); Delegates.pglMultiModeDrawElementsIBM(p_mode, p_count, (Int32)type, p_indices, primcount, modestride); LogFunction("glMultiModeDrawElementsIBM({0}, {1}, {2}, {3}, {4}, {5})", LogEnumName(mode), LogValue(count), type, LogValue(indices), primcount, modestride); } } DebugCheckErrors(null); }
public static void EnablePrimitiveRestart(GraphicsContext ctx, DrawElementsType elementType) { switch (elementType) { case DrawElementsType.UnsignedInt: EnablePrimitiveRestart(ctx, UInt32.MaxValue); break; case DrawElementsType.UnsignedShort: EnablePrimitiveRestart(ctx, UInt16.MaxValue); break; case DrawElementsType.UnsignedByte: EnablePrimitiveRestart(ctx, Byte.MaxValue); break; default: throw new ArgumentException(String.Format("unknown element type {0}", elementType)); } }
public IndexBuffer(GraphicsDevice graphicsDevice, IndexElementSize indexElementSize, int indexCount, BufferUsage usage) : base(graphicsDevice, BufferTarget.ElementArrayBuffer, GetElementSizeInBytes(indexElementSize), indexCount, usage) { IndexElementSize = indexElementSize; switch (indexElementSize) { case IndexElementSize.EightBits: DrawElementsType = DrawElementsType.UnsignedByte; break; case IndexElementSize.SixteenBits: DrawElementsType = DrawElementsType.UnsignedShort; break; case IndexElementSize.ThirtyTwoBits: DrawElementsType = DrawElementsType.UnsignedInt; break; } }
/// <summary> /// Initializes a new <see cref="VertexArrayObject"/>. /// </summary> /// <param name="indexBuffer">The <see cref="IBuffer"/> containing the index data.</param> /// <param name="drawMode">The <see cref="BeginMode"/>.</param> /// <param name="indexBufferType">The type of the indices.</param> /// <param name="buffers">The buffers containing the actual vertex data.</param> public VertexArrayObject(IReadOnlyBuffer indexBuffer, BeginMode drawMode, DrawElementsType indexBufferType, params BufferDescription[] buffers) { Contract.Requires<ArgumentNullException>(buffers != null); Contract.Requires<ArgumentNullException>(indexBuffer != null); Contract.Requires<ArgumentException>(indexBuffer.Target == BufferTarget.ElementArrayBuffer); this.VerifyAccess(); this.DrawMode = drawMode; this.IndexBuffer = indexBuffer; this.IndexType = indexBufferType; this.VertexBuffers = buffers.ToImmutableArray(); this.Handle = GL.GenVertexArray(); // Can't use Binding and using clause here because it causes a stack overflow (Bindable.Bind -> Initialize) try { GL.BindVertexArray(this); foreach (BufferDescription desc in this.VertexBuffers) { if (desc.Buffer != null) { using (Binding vboBinding = desc.Buffer.Bind()) { foreach (VertexAttributePointer vertexPointer in desc.VertexAttributePointers.OrderBy(vap => vap.Index)) { vertexPointer.Enable(); vertexPointer.Apply(); } } } } this.IndexBuffer.Bind(); } finally { GL.BindVertexArray(0); } this.IndexBuffer.Unbind(); }
public void Elements(BeginMode mode, int indexCount, DrawElementsType indexType, int indexBufferOffset) { gl.DrawElements((int)mode, indexCount, (int)indexType, (IntPtr)indexBufferOffset); }
private void CreateAttributes() { int vertexAttribCount = 0; for (int i = 0; i < vertexBufferBindings.Length; ++i) { vertexAttribCount += vertexBufferBindings[i].Declaration.VertexElements.Length; } vertexAttribs = new VertexAttrib[vertexAttribCount]; int j = 0; for (int i = 0; i < vertexBufferBindings.Length; ++i) { var inputSlot = vertexBufferBindings[i]; var vertexBuffer = vertexBufferBindings[i].Buffer; foreach (var vertexElementAndOffset in inputSlot.Declaration.EnumerateWithOffsets()) { var vertexElement = vertexElementAndOffset.VertexElement; var attributeName = "a_" + vertexElement.SemanticName + vertexElement.SemanticIndex; var vertexElementFormat = ConvertVertexElementFormat(vertexElement.Format); #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES IntPtr bufferStart = vertexBuffer.ResourceId == 0 ? vertexBuffer.StagingData : (IntPtr)vertexBufferBindings[i].Offset; #else var bufferStart = (IntPtr)vertexBufferBindings[i].Offset; #endif vertexAttribs[j] = new VertexAttrib { VertexBufferId = vertexBuffer.ResourceId, Index = -1, IsInteger = IsInteger(vertexElementFormat.Type), Size = vertexElementFormat.Size, Type = vertexElementFormat.Type, Normalized = vertexElementFormat.Normalized, Stride = inputSlot.Declaration.VertexStride, Offset = bufferStart + vertexElementAndOffset.Offset, AttributeName = attributeName }; j++; } } if (indexBufferBinding != null) { indexBufferId = indexBufferBinding.Buffer.resourceId; #if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES if (GraphicsDevice.IsOpenGLES2 && indexBufferBinding.Is32Bit) throw new PlatformNotSupportedException("32 bits index buffer are not supported on OpenGL ES 2.0"); indexBufferOffset = (indexBufferId == 0 ? indexBufferBinding.Buffer.StagingData : IntPtr.Zero) + indexBufferBinding.Offset; #else indexBufferOffset = (IntPtr)indexBufferBinding.Offset; #endif drawElementsType = indexBufferBinding.Is32Bit ? DrawElementsType.UnsignedInt : DrawElementsType.UnsignedShort; indexElementSize = indexBufferBinding.Is32Bit ? 4 : 2; } // If we have a signature, we can already pre-create the instance if (preferredInputSignature != null) { preferredInstance = GetInstance(preferredInputSignature); } currentShaderSignature = preferredInputSignature; currentInstance = preferredInstance; }
public static void DrawRangeElementsBaseVertex(PrimitiveType mode, UInt32 start, UInt32 end, Int32 count, DrawElementsType type, Object indices, Int32 basevertex) { GCHandle pin_indices = GCHandle.Alloc(indices, GCHandleType.Pinned); try { DrawRangeElementsBaseVertex(mode, start, end, count, type, pin_indices.AddrOfPinnedObject(), basevertex); } finally { pin_indices.Free(); } }
public static void DrawElementsInstancedBaseVertex(PrimitiveType mode, Int32 count, DrawElementsType type, Object indices, Int32 instancecount, Int32 basevertex) { GCHandle pin_indices = GCHandle.Alloc(indices, GCHandleType.Pinned); try { DrawElementsInstancedBaseVertex(mode, count, type, pin_indices.AddrOfPinnedObject(), instancecount, basevertex); } finally { pin_indices.Free(); } }
public static void Draw(BeginMode mode, DrawElementsType type, int indcCount, int vertID, int indcID) { GL.BindBuffer(BufferTarget.ArrayBuffer, vertID); // 1(sphere), 4(cube) GL.BindBuffer(BufferTarget.ElementArrayBuffer, indcID); // 3(sphere), 6(cube) GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, Vector3.SizeInBytes, 0); GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, Vector3.SizeInBytes, 0); GL.DrawElements(mode, indcCount, type, IntPtr.Zero); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); Flush(); }
public static void MultiDrawElementsBaseVertex(Int32 mode, Int32[] count, DrawElementsType type, IntPtr[] indices, Int32 drawcount, Int32[] basevertex) { unsafe { fixed (Int32* p_count = count) fixed (IntPtr* p_indices = indices) fixed (Int32* p_basevertex = basevertex) { Debug.Assert(Delegates.pglMultiDrawElementsBaseVertex != null, "pglMultiDrawElementsBaseVertex not implemented"); Delegates.pglMultiDrawElementsBaseVertex(mode, p_count, (Int32)type, p_indices, drawcount, p_basevertex); LogFunction("glMultiDrawElementsBaseVertex({0}, {1}, {2}, {3}, {4}, {5})", LogEnumName(mode), LogValue(count), type, LogValue(indices), drawcount, LogValue(basevertex)); } } DebugCheckErrors(null); }
public abstract unsafe void MultiDrawElementsBaseVertex([Flow(FlowDirection.In)] PrimitiveType mode, [Count(Computed = "drawcount"), Flow(FlowDirection.In)] uint *count, [Flow(FlowDirection.In)] DrawElementsType type, [Count(Computed = "drawcount"), Flow(FlowDirection.In)] void **indices, [Flow(FlowDirection.In)] uint primcount, [Count(Computed = "drawcount"), Flow(FlowDirection.In)] int *basevertex);
public static void DrawRangeElements(BeginMode mode, int start, int end, int count, DrawElementsType type, IntPtr indices) { #if USE_OPENGL if (openGlHardwareAvailable) { if (glHasBufferObjects) { OpenTK.Graphics.OpenGL.GL.DrawRangeElements((OpenTK.Graphics.OpenGL.BeginMode)mode, start, end, count, (OpenTK.Graphics.OpenGL.DrawElementsType)type, indices); } else { unsafe { fixed (byte* buffer = bufferData[currentElementArrayBufferIndex]) { byte* passedBuffer = &buffer[(int)indices]; OpenTK.Graphics.OpenGL.GL.DrawElements((OpenTK.Graphics.OpenGL.BeginMode)mode, count, (OpenTK.Graphics.OpenGL.DrawElementsType)type, new IntPtr(passedBuffer)); } } } } #else if (glHasBufferObjects) { throw new NotImplementedException(); } else { unsafe { fixed (byte* buffer = bufferData[currentElementArrayBufferIndex]) { byte* passedBuffer = &buffer[(int)indices]; OpenTK.Graphics.ES11.GL.DrawElements((OpenTK.Graphics.ES11.All)mode, count, (OpenTK.Graphics.ES11.All)type, new IntPtr(passedBuffer)); } } } #endif }
public abstract unsafe void DrawRangeElementsBaseVertex([Flow(FlowDirection.In)] PrimitiveType mode, [Flow(FlowDirection.In)] uint start, [Flow(FlowDirection.In)] uint end, [Flow(FlowDirection.In)] uint count, [Flow(FlowDirection.In)] DrawElementsType type, [Count(Computed = "count, type"), Flow(FlowDirection.In)] void *indices, [Flow(FlowDirection.In)] int basevertex);
public abstract void DrawRangeElementsBaseVertex <T0>([Flow(FlowDirection.In)] PrimitiveType mode, [Flow(FlowDirection.In)] uint start, [Flow(FlowDirection.In)] uint end, [Flow(FlowDirection.In)] uint count, [Flow(FlowDirection.In)] DrawElementsType type, [Count(Computed = "count, type"), Flow(FlowDirection.In)] ref T0 indices, [Flow(FlowDirection.In)] int basevertex) where T0 : unmanaged;
public static unsafe void MultiDrawElementsIndirectCount <T0>(this ArbIndirectParameters thisApi, [Flow(FlowDirection.In)] PrimitiveType mode, [Flow(FlowDirection.In)] DrawElementsType type, [Flow(FlowDirection.In)] ReadOnlySpan <T0> indirect, [Flow(FlowDirection.In)] nint drawcount, [Flow(FlowDirection.In)] uint maxdrawcount, [Flow(FlowDirection.In)] uint stride) where T0 : unmanaged { // SpanOverloader thisApi.MultiDrawElementsIndirectCount(mode, type, in indirect.GetPinnableReference(), drawcount, maxdrawcount, stride); }
public static void DrawRangeElements(BeginMode mode, int start, int end, int count, DrawElementsType type, IntPtr indices) { Instance?.DrawRangeElements(mode, start, end, count, type, indices); }
public static unsafe void MultiDrawElementsIndirectBindles <T0>(this NVBindlessMultiDrawIndirect thisApi, [Flow(FlowDirection.In)] PrimitiveType mode, [Flow(FlowDirection.In)] DrawElementsType type, [Flow(FlowDirection.In)] ReadOnlySpan <T0> indirect, [Flow(FlowDirection.In)] uint drawCount, [Flow(FlowDirection.In)] uint stride, [Flow(FlowDirection.In)] int vertexBufferCount) where T0 : unmanaged { // SpanOverloader thisApi.MultiDrawElementsIndirectBindles(mode, type, in indirect.GetPinnableReference(), drawCount, stride, vertexBufferCount); }
public static void DrawElementsInstanced(PrimitiveType mode, Int32 count, DrawElementsType type, IntPtr indices, Int32 primcount) { Debug.Assert(Delegates.pglDrawElementsInstanced != null, "pglDrawElementsInstanced not implemented"); Delegates.pglDrawElementsInstanced((Int32)mode, count, (Int32)type, indices, primcount); LogFunction("glDrawElementsInstanced({0}, {1}, {2}, 0x{3}, {4})", mode, count, type, indices.ToString("X8"), primcount); DebugCheckErrors(null); }
public abstract unsafe void MultiDrawElementsBaseVertex <T0>([Flow(FlowDirection.In)] PrimitiveType mode, [Count(Computed = "drawcount"), Flow(FlowDirection.In)] ref uint count, [Flow(FlowDirection.In)] DrawElementsType type, [Count(Computed = "drawcount"), Flow(FlowDirection.In)] ref T0 *indices, [Flow(FlowDirection.In)] uint primcount, [Count(Computed = "drawcount"), Flow(FlowDirection.In)] ref int basevertex) where T0 : unmanaged;
private void DrawElements(DrawTarget mode, int count, DrawElementsType type, IntPtr indices) { if (!Enum.IsDefined(typeof(DrawTarget), mode) || !Enum.IsDefined(typeof(DrawElementsType), type)) { SetLastError(ErrorCode.InvalidEnum); return; } if (count < 0) { SetLastError(ErrorCode.InvalidValue); return; } // TODO: GL_INVALID_OPERATION is generated if a geometry shader is active and mode is incompatible with the input primitive type of the geometry shader in the currently installed program object. // TODO: GL_INVALID_OPERATION is generated if a non-zero buffer object name is bound to an enabled array or the element array and the buffer object's data store is currently mapped. VertexArrayObject vao = this.currentVertexArrayObject; // data structure. if (vao == null) { return; } ShaderProgram program = this.currentShaderProgram; // algorithm. if (program == null) { return; } GLBuffer indexBuffer = this.currentBufferDict[BindBufferTarget.ElementArrayBuffer]; if (indexBuffer == null) { return; } // execute vertex shader for each vertex! // This is a low effetient implementation. // passBuffers is input for the next stage: linear interpolation. // passBuffers[0] is gl_Position. // passBuffers[others] are attributes of vertexes. PassBuffer[] passBuffers = VertexShaderStage(count, type, indices, vao, program, indexBuffer); if (passBuffers == null) { return; } // this stage failed. Framebuffer framebuffer = this.currentFramebuffer; if (framebuffer == null) { throw new Exception("This should not happen!"); } ClipSpace2NormalDeviceSpace(passBuffers[0]); // linear interpolation. List <Fragment> fragmentList = LinearInterpolation(mode, count, type, indices, vao, program, indexBuffer, passBuffers); // execute fargment shader for each fragment! // This is a low effetient implementation. FragmentShaderStage(program, fragmentList); { int index = 0; while (index < fragmentList.Count) { if (fragmentList[index].discard) { fragmentList.RemoveAt(index); } else { index++; } } } // Scissor test // Multisampel fragment operations // Stencil test // Depth test DepthTest(fragmentList); //Blending // Dithering // Logical operations // write fragments to framebuffer's colorbuffer attachment(s). { uint[] drawBufferIndexes = framebuffer.DrawBuffers.ToArray(); foreach (var fragment in fragmentList) { if (fragment.depthTestFailed) { continue; } for (int i = 0; i < fragment.outVariables.Length && i < drawBufferIndexes.Length; i++) { PassBuffer outVar = fragment.outVariables[i]; IAttachable attachment = framebuffer.ColorbufferAttachments[drawBufferIndexes[i].ToIndex()]; attachment.Set((int)fragment.gl_FragCoord.x, (int)fragment.gl_FragCoord.y, outVar); } } } }
public static void DrawElements(BeginMode mode, int count, DrawElementsType type, int offset) { DrawElements(mode, count, type, new IntPtr(offset)); }
public abstract void MultiDrawElementsIndirect <T0>([Flow(FlowDirection.In)] PrimitiveType mode, [Flow(FlowDirection.In)] DrawElementsType type, [Count(Computed = "drawcount, stride"), Flow(FlowDirection.In)] ref T0 indirect, [Flow(FlowDirection.In)] uint drawcount, [Flow(FlowDirection.In)] uint stride) where T0 : unmanaged;
public void DrawElements(PrimitiveType mode, uint count, DrawElementsType type, IntPtr indices) { NativeMethods.DrawElements(mode, count, type, indices); CheckForError(); }
public void ElementsBaseVertex(BeginMode mode, int indexCount, DrawElementsType indexType, int indexBufferOffset, int baseVertex) { gl.DrawElementsBaseVertex((int)mode, indexCount, (int)indexType, (IntPtr)indexBufferOffset, baseVertex); }
public static unsafe void DrawElementsInstanced <T0>(this ArbDrawInstanced thisApi, [Flow(FlowDirection.In)] PrimitiveType mode, [Flow(FlowDirection.In)] uint count, [Flow(FlowDirection.In)] DrawElementsType type, [Count(Computed = "count, type"), Flow(FlowDirection.In)] ReadOnlySpan <T0> indices, [Flow(FlowDirection.In)] uint primcount) where T0 : unmanaged { // SpanOverloader thisApi.DrawElementsInstanced(mode, count, type, in indices.GetPinnableReference(), primcount); }
public static void DrawRangeElementsBaseVertex(PrimitiveType mode, UInt32 start, UInt32 end, Int32 count, DrawElementsType type, IntPtr indices, Int32 basevertex) { Debug.Assert(Delegates.pglDrawRangeElementsBaseVertex != null, "pglDrawRangeElementsBaseVertex not implemented"); Delegates.pglDrawRangeElementsBaseVertex((Int32)mode, start, end, count, (Int32)type, indices, basevertex); CallLog("glDrawRangeElementsBaseVertex({0}, {1}, {2}, {3}, {4}, 0x{5}, {6})", mode, start, end, count, type, indices.ToString("X8"), basevertex); DebugCheckErrors(); }
public static unsafe void MultiDrawElementsIndirect <T0>(this ExtMultiDrawIndirect thisApi, [Flow(FlowDirection.In)] EXT mode, [Flow(FlowDirection.In)] DrawElementsType type, [Count(Computed = "drawcount, stride"), Flow(FlowDirection.In)] ReadOnlySpan <T0> indirect, [Flow(FlowDirection.In)] uint drawcount, [Flow(FlowDirection.In)] uint stride) where T0 : unmanaged { // SpanOverloader thisApi.MultiDrawElementsIndirect(mode, type, in indirect.GetPinnableReference(), drawcount, stride); }
public static void DrawElementsInstancedBaseVertex(PrimitiveType mode, Int32 count, DrawElementsType type, IntPtr indices, Int32 instancecount, Int32 basevertex) { Debug.Assert(Delegates.pglDrawElementsInstancedBaseVertex != null, "pglDrawElementsInstancedBaseVertex not implemented"); Delegates.pglDrawElementsInstancedBaseVertex((Int32)mode, count, (Int32)type, indices, instancecount, basevertex); CallLog("glDrawElementsInstancedBaseVertex({0}, {1}, {2}, 0x{3}, {4}, {5})", mode, count, type, indices.ToString("X8"), instancecount, basevertex); DebugCheckErrors(); }
public void DrawElements(int elements, DrawElementsType type) { Bind(); Enable(); GL.DrawElements(BeginMode.Triangles, elements, type, 0); Disable(); Unbind(); }
public static void MultiDrawElementsBaseVertex(PrimitiveType mode, Int32[] count, DrawElementsType type, IntPtr[] indices, Int32 drawcount, Int32[] basevertex) { unsafe { fixed (Int32* p_count = count) fixed (IntPtr* p_indices = indices) fixed (Int32* p_basevertex = basevertex) { Debug.Assert(Delegates.pglMultiDrawElementsBaseVertex != null, "pglMultiDrawElementsBaseVertex not implemented"); Delegates.pglMultiDrawElementsBaseVertex((Int32)mode, p_count, (Int32)type, p_indices, drawcount, p_basevertex); CallLog("glMultiDrawElementsBaseVertex({0}, {1}, {2}, {3}, {4}, {5})", mode, count, type, indices, drawcount, basevertex); } } DebugCheckErrors(); }
public void ElementsInstancedBaseVertexBaseInstance(BeginMode mode, int indexCountPerInstance, DrawElementsType indexType, int indexBufferOffset, int instanceCount, int baseVertex, int baseInstance) { gl.DrawElementsInstancedBaseVertexBaseInstance((int)mode, indexCountPerInstance, (int)indexType, (IntPtr)indexBufferOffset, instanceCount, baseVertex, (uint)baseInstance); }
public static void DrawElements(BeginMode mode, int count, DrawElementsType type, int offset) { DrawElements(mode, count, type, offset); }
public void ElementsInstanced(BeginMode mode, int indexCountPerInstance, DrawElementsType indexType, int indexBufferOffset, int instanceCount) { gl.DrawElementsInstanced((int)mode, indexCountPerInstance, (int)indexType, (IntPtr)indexBufferOffset, instanceCount); }
protected void InitWithDefaultFBO(int defaultFBOName) { Console.WriteLine(string.Format("{0} {1}", GL.GetString(StringName.Renderer), GL.GetString(StringName.Version))); //////////////////////////////////////////////////// // Build all of our and setup initial state here // // Don't wait until our real time run loop begins // //////////////////////////////////////////////////// m_defaultFBOName = defaultFBOName; m_viewWidth = 100; m_viewHeight = 100; m_characterAngle = 0; #if USE_VERTEX_BUFFER_OBJECTS m_useVBOs = true; #else m_useVBOs = false; #endif var filePathName = string.Empty; ////////////////////////////// // Load our character model // ////////////////////////////// filePathName = NSBundle.MainBundle.PathForResource("GLData/demon", "model"); m_characterModel = DemoModel.LoadModel(filePathName); // Build Vertex uffer Objects (VBOs) and Vertex Array Objects (VAOs) with our model data m_characterVAOName = BuildVAO(m_characterModel); // Cache the number of element and primtType to use later in our GL.DrawElements calls m_characterNumElements = m_characterModel.NumElements; m_characterPrimType = m_characterModel.PrimType; m_characterElementType = m_characterModel.ElementType; if(m_useVBOs) { //If we're using VBOs we can destroy all this memory since buffers are // loaded into GL and we've saved anything else we need m_characterModel = null; } //////////////////////////////////// // Load texture for our character // //////////////////////////////////// filePathName = NSBundle.MainBundle.PathForResource("GLData/demon", "png"); var image = DemoImage.LoadImage(filePathName, false); // Build a texture object with our image data m_characterTexName = BuildTexture(image); //////////////////////////////////////////////////// // Load and Setup shaders for character rendering // //////////////////////////////////////////////////// DemoSource vtxSource = null; DemoSource frgSource = null; filePathName = NSBundle.MainBundle.PathForResource("Shaders/character", "vsh"); vtxSource = DemoSource.LoadSource(filePathName); filePathName = NSBundle.MainBundle.PathForResource("Shaders/character", "fsh"); frgSource = DemoSource.LoadSource(filePathName); // Build program m_characterPrgName = BuildProgramWithVertexSource(vtxSource, frgSource, false, true); m_characterMvpUniformIdx = GL.GetUniformLocation(m_characterPrgName, "modelViewProjectionMatrix"); if(m_characterMvpUniformIdx < 0) Console.WriteLine("No modelViewProjectionMatrix in character shader"); #if RENDER_REFLECTION m_reflectWidth = 512; m_reflectHeight = 512; //////////////////////////////////////////////// // Load a model for a quad for the reflection // //////////////////////////////////////////////// m_quadModel = DemoModel.LoadQuadModel(); // build Vertex Buffer Objects (VBOs) and Vertex Array Object (VAOs) with our model data m_reflectVAOName = BuildVAO(m_quadModel); // Cache the number of element and prim type to use later in our GL.DrawElements calls m_quadNumElements = m_quadModel.NumElements; m_quadPrimType = m_quadModel.PrimType; m_quadElementType = m_quadModel.ElementType; if(m_useVBOs) { // Release quad Model; m_quadModel = null; } ///////////////////////////////////////////////////// // Create texture and FBO for reflection rendering // ///////////////////////////////////////////////////// m_reflectFBOName = BuildFBOWithWidth(m_reflectWidth, m_reflectHeight); // Get the texture we created in buildReflectFBO by binding the // reflection FBO and getting the buffer attached to color 0 GL.BindFramebuffer(FramebufferTarget.Framebuffer, m_reflectFBOName); int iReflectTexName = 0; GL.GetFramebufferAttachmentParameter(FramebufferTarget.Framebuffer, FramebufferSlot.ColorAttachment0, FramebufferParameterName.FramebufferAttachmentObjectName, out iReflectTexName); m_reflectTexName = iReflectTexName; ///////////////////////////////////////////////////// // Load and setup shaders for reflection rendering // ///////////////////////////////////////////////////// filePathName = NSBundle.MainBundle.PathForResource("Shaders/reflect", "vsh"); vtxSource = DemoSource.LoadSource(filePathName); filePathName = NSBundle.MainBundle.PathForResource("Shaders/reflect", "fsh"); frgSource = DemoSource.LoadSource (filePathName); // Build Program m_reflectPrgName = BuildProgramWithVertexSource(vtxSource, frgSource, true, false); m_reflectModelViewUniformIdx = GL.GetUniformLocation(m_reflectPrgName, "modelViewMatrix"); if(m_reflectModelViewUniformIdx < 0) Console.WriteLine("No modelViewMatrix in reflection shader"); m_reflectProjectionuniformIdx = GL.GetUniformLocation(m_reflectPrgName, "modelViewProjectionMatrix"); if(m_reflectProjectionuniformIdx < 0) Console.WriteLine("No modelViewProjectionMatrix in reflection shader"); m_reflectNormalMatrixUniformIdx = GL.GetUniformLocation(m_reflectPrgName, "normalMatrix"); if(m_reflectNormalMatrixUniformIdx <0) Console.WriteLine("No normalMatrix in reflection shader"); #endif // RENDER_REFLECTION //////////////////////////////////////////////// // Set up OpenGL state that will never change // //////////////////////////////////////////////// // Depth test will always be enabled GL.Enable(EnableCap.DepthTest); // We will always cull back faces for better performance GL.Enable(EnableCap.CullFace); // Always use this clear color GL.ClearColor(.5f, .4f, .5f, 1.0f); // Draw our scene once without presenting the rendered image. // This is done in order to pre-warm OpenGL // We don't need to present the buffer since we don't actually want the // user to see this, we're only drawing as a pre-warm stage Render(); // Reset the m_characterAngle which is incremented in render m_characterAngle = 0; // Check for errors to make sure all of our setup went ok GetGLError(); }
public void ElementsIndirect(BeginMode mode, DrawElementsType indexType, int argsBufferOffset) { gl.DrawElementsIndirect((int)mode, (int)indexType, (IntPtr)argsBufferOffset); }
public static void DrawElementsInstanced(PrimitiveType mode, Int32 count, DrawElementsType type, Object indices, Int32 primcount) { GCHandle pin_indices = GCHandle.Alloc(indices, GCHandleType.Pinned); try { DrawElementsInstanced(mode, count, type, pin_indices.AddrOfPinnedObject(), primcount); } finally { pin_indices.Free(); } }
public void RangeElements(BeginMode mode, int minVertexIndex, int maxVertexIndex, int indexCount, DrawElementsType indexType, int indexBufferOffset) { gl.DrawRangeElements((int)mode, (uint)minVertexIndex, (uint)maxVertexIndex, indexCount, (int)indexType, (IntPtr)indexBufferOffset); }
/// <summary> /// Construct an ElementBufferObject, implictly used with <see cref="BufferObjectHint.StaticCpuDraw"/>. /// </summary> /// <param name="elementType"> /// The <see cref="DrawElementsType"/> that specify how vertices are interpreted. /// </param> public ElementBufferObject(DrawElementsType elementType) : this(elementType, BufferObjectHint.StaticCpuDraw) { }
public void DrawElements(BeginMode mode, int indiceCount, DrawElementsType elementType, int offset) { GraphicsContext.Assert(); GL.DrawElements(mode, indiceCount, elementType, offset); OpenGlErrorHelper.CheckGlError(); }
internal static extern void glDrawElements(BeginMode mode, Int32 count, DrawElementsType type, IntPtr indices);
public void ElementsInstancedBaseVertex(BeginMode mode, int indexCountPerInstance, DrawElementsType indexType, int indexBufferOffset, int instanceCount, int baseVertex) { gl.DrawElementsInstancedBaseVertex((int)mode, indexCountPerInstance, (int)indexType, (IntPtr)indexBufferOffset, instanceCount, baseVertex); }
public static void DrawElements(PrimitiveType mode, Int32 count, DrawElementsType type, IntPtr indices) { Debug.Assert(Delegates.pglDrawElements != null, "pglDrawElements not implemented"); Delegates.pglDrawElements((Int32)mode, count, (Int32)type, indices); CallLog("glDrawElements({0}, {1}, {2}, 0x{3})", mode, count, type, indices.ToString("X8")); DebugCheckErrors(); }
public IndexBufferView(Buffer buffer, int offset, bool is32Bits) { Buffer = buffer; Offset = offset; Type = is32Bits ? DrawElementsType.UnsignedInt : DrawElementsType.UnsignedShort; ElementSize = is32Bits ? 4 : 2; }
public static void DrawElements(BeginMode mode, int count, DrawElementsType type, int offset) { DrawElements((PrimitiveType)mode, count, type, new IntPtr(offset)); }
public abstract unsafe void MultiDrawElementsIndirect([Flow(FlowDirection.In)] PrimitiveType mode, [Flow(FlowDirection.In)] DrawElementsType type, [Count(Computed = "drawcount, stride"), Flow(FlowDirection.In)] void *indirect, [Flow(FlowDirection.In)] uint drawcount, [Flow(FlowDirection.In)] uint stride);