public int SetVertexAttributes(int vertexBufferSlot, OpenGLVertexBuffer vb, int previousAttributesBound) { // TODO: Related to OpenGLRenderContext.PlatformSetVertexBuffer() // These attributes should be lazily set on a draw call or something. if (vertexBufferSlot <= VBLayoutsBySlot.Length) { return(previousAttributesBound); } int baseSlot = GetSlotBaseIndex(vertexBufferSlot); OpenGLMaterialVertexInput input = VBLayoutsBySlot[vertexBufferSlot]; vb.Apply(); for (int i = 0; i < input.Elements.Length; i++) { OpenGLMaterialVertexInputElement element = input.Elements[i]; int slot = baseSlot + i; GL.EnableVertexAttribArray(slot); GL.VertexAttribPointer(slot, element.ElementCount, element.Type, element.Normalized, input.VertexSizeInBytes, element.Offset); } for (int extraSlot = input.Elements.Length; extraSlot < previousAttributesBound; extraSlot++) { GL.DisableVertexAttribArray(extraSlot); } return(input.Elements.Length); }
public int SetVertexAttributes(VertexBuffer[] vertexBuffers, int previousAttributesBound) { int totalSlotsBound = 0; for (int i = 0; i < VBLayoutsBySlot.Length; i++) { OpenGLMaterialVertexInput input = VBLayoutsBySlot[i]; ((OpenGLVertexBuffer)vertexBuffers[i]).Apply(); for (int slot = 0; slot < input.Elements.Length; slot++) { OpenGLMaterialVertexInputElement element = input.Elements[slot]; int actualSlot = totalSlotsBound + slot; GL.EnableVertexAttribArray(actualSlot); GL.VertexAttribPointer(actualSlot, element.ElementCount, element.Type, element.Normalized, input.VertexSizeInBytes, element.Offset); GL.VertexAttribDivisor(actualSlot, element.InstanceStepRate); } totalSlotsBound += input.Elements.Length; } for (int extraSlot = totalSlotsBound; extraSlot < previousAttributesBound; extraSlot++) { GL.DisableVertexAttribArray(extraSlot); } return(totalSlotsBound); }
public OpenGLMaterialVertexInput(MaterialVertexInput genericInput) { VertexSizeInBytes = genericInput.VertexSizeInBytes; Elements = new OpenGLMaterialVertexInputElement[genericInput.Elements.Length]; int offset = 0; for (int i = 0; i < Elements.Length; i++) { var genericElement = genericInput.Elements[i]; Elements[i] = new OpenGLMaterialVertexInputElement(genericElement, offset); offset += genericElement.SizeInBytes; } }