private SceneObjectGeometry CreateCubeGeometry() { SceneObjectGeometry cubeGeometry = new SceneObjectGeometry("Cube"); #region State cubeGeometry.ObjectState.DefineState(new CullFaceState(FrontFaceDirection.Ccw, CullFaceMode.Back)); cubeGeometry.ObjectState.DefineState(new TransformState()); MaterialState cubeMaterialState = new MaterialState(); cubeMaterialState.FrontMaterial = new MaterialState.Material(ColorRGBAF.ColorWhite * 0.5f); cubeMaterialState.FrontMaterial.Ambient = ColorRGBAF.ColorBlack; cubeMaterialState.FrontMaterial.Diffuse = ColorRGBAF.ColorWhite * 0.5f; cubeMaterialState.FrontMaterial.Specular = ColorRGBAF.ColorWhite * 0.5f; cubeMaterialState.FrontMaterial.Shininess = 10.0f; cubeGeometry.ObjectState.DefineState(cubeMaterialState); #endregion #region Vertex Arrays if (_CubeArrayPosition == null) { _CubeArrayPosition = new ArrayBuffer <Vertex3f>(); _CubeArrayPosition.Create(ArrayPosition); } if (_CubeArrayColor == null) { _CubeArrayColor = new ArrayBuffer <ColorRGBF>(); _CubeArrayColor.Create(ArrayColors); } if (_CubeArrayNormal == null) { _CubeArrayNormal = new ArrayBuffer <Vertex3f>(); _CubeArrayNormal.Create(ArrayNormals); } if (_CubeArrays == null) { _CubeArrays = new VertexArrays(); _CubeArrays.SetArray(_CubeArrayPosition, VertexArraySemantic.Position); _CubeArrays.SetArray(_CubeArrayColor, VertexArraySemantic.Color); _CubeArrays.SetArray(_CubeArrayNormal, VertexArraySemantic.Normal); _CubeArrays.SetElementArray(PrimitiveType.Triangles); } cubeGeometry.VertexArray = _CubeArrays; #endregion #region Program cubeGeometry.BoundingVolume = new BoundingBox(-Vertex3f.One * _CubeSize, Vertex3f.One * _CubeSize); #endregion return(cubeGeometry); }
private void LinkBoundingVolumeResources(GraphicsContext ctx) { string resourceClassId = "OpenGL.Objects.SceneObjectLightSpot.BoundingVolume"; #region Arrays string arrayId = resourceClassId + ".Array"; if ((_BoundingVolumeArrays = (VertexArrays)ctx.GetSharedResource(arrayId)) == null) { _BoundingVolumeArrays = VertexArrays.CreateCone(1.0f, 1.0f, 16); _BoundingVolumeArrays.Create(ctx); ctx.SetSharedResource(arrayId, _BoundingVolumeArrays); } LinkResource(_BoundingVolumeArrays); #endregion #region Program string programId = resourceClassId + ".Program"; if ((_BoundingVolumeProgram = (ShaderProgram)ctx.GetSharedResource(programId)) == null) { _BoundingVolumeProgram = ctx.CreateProgram("OpenGL.Standard"); ctx.SetSharedResource(programId, _BoundingVolumeProgram); } LinkResource(_BoundingVolumeArrays); #endregion }
private SceneObjectGeometry CreateSphere(string material) { SceneObjectGeometry sphereGeometry = new SceneObjectGeometry("Sphere"); sphereGeometry.ObjectState.DefineState(new CullFaceState(FrontFaceDirection.Ccw, CullFaceMode.Back)); sphereGeometry.ObjectState.DefineState(new TransformState()); sphereGeometry.LocalModelView = Matrix4x4f.Translated(0.0f, 4.0f, 0.0f); sphereGeometry.VertexArray = VertexArrays.CreateSphere(4.0f, 32, 32); ArrayBuffer <Vertex2f> texCoordBuffer = new ArrayBuffer <Vertex2f>(); texCoordBuffer.Create(sphereGeometry.VertexArray.ArrayLength); sphereGeometry.VertexArray.SetArray(texCoordBuffer, VertexArraySemantic.TexCoord); ArrayBuffer <Vertex3f> tanCoordBuffer = new ArrayBuffer <Vertex3f>(); tanCoordBuffer.Create(sphereGeometry.VertexArray.ArrayLength); sphereGeometry.VertexArray.SetArray(tanCoordBuffer, VertexArraySemantic.Tangent); ArrayBuffer <Vertex3f> bitanCoordBuffer = new ArrayBuffer <Vertex3f>(); bitanCoordBuffer.Create(sphereGeometry.VertexArray.ArrayLength); sphereGeometry.VertexArray.SetArray(bitanCoordBuffer, VertexArraySemantic.Bitangent); sphereGeometry.VertexArray.GenerateTexCoords(new VertexArrayTexGen.Sphere()); sphereGeometry.VertexArray.GenerateTangents(); sphereGeometry.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+PhongFragment"); SetSphereMaterial(sphereGeometry, material); return(sphereGeometry); }
private static SceneObject ProcessOBJ(ObjContext objContext) { if (objContext == null) { throw new ArgumentNullException("objContext"); } SceneObjectGeometry sceneObject = new SceneObjectGeometry(); // Program shader to all objects // sceneObject.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+LambertVertex", new ShaderCompilerContext("GLO_DEBUG_NORMAL")); sceneObject.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+PhongFragment"); // sceneObject.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+LambertVertex"); foreach (ObjGroup objGroup in objContext.Groups) { foreach (ObjGeometry objGeometry in objGroup.MergeGeometries()) { VertexArrays vertexArray = objGeometry.CreateArrays(objContext); GraphicsStateSet objectState = new GraphicsStateSet(); objectState.DefineState(objGeometry.CreateMaterialState()); sceneObject.AddGeometry(vertexArray, objectState); } } return(sceneObject); }
/// <summary> /// Create vertex arrays representing the bounding box, using lines delimiting the box volume. /// </summary> /// <returns> /// It returns a <see cref="VertexArrays"/> representing a normalized bounding box volume. /// </returns> private static VertexArrays CreateBoundingBoxArrays() { VertexArrays bboxArray = new VertexArrays(); ArrayBuffer <Vertex3f> bboxVPositionArray = new ArrayBuffer <Vertex3f>(); bboxVPositionArray.Create(new Vertex3f[] { // Lower new Vertex3f(-0.5f, -0.5f, -0.5f), new Vertex3f(+0.5f, -0.5f, -0.5f), new Vertex3f(+0.5f, -0.5f, -0.5f), new Vertex3f(+0.5f, -0.5f, +0.5f), new Vertex3f(+0.5f, -0.5f, +0.5f), new Vertex3f(-0.5f, -0.5f, +0.5f), new Vertex3f(-0.5f, -0.5f, +0.5f), new Vertex3f(-0.5f, -0.5f, -0.5f), // Upper new Vertex3f(-0.5f, +0.5f, -0.5f), new Vertex3f(+0.5f, +0.5f, -0.5f), new Vertex3f(+0.5f, +0.5f, -0.5f), new Vertex3f(+0.5f, +0.5f, +0.5f), new Vertex3f(+0.5f, +0.5f, +0.5f), new Vertex3f(-0.5f, +0.5f, +0.5f), new Vertex3f(-0.5f, +0.5f, +0.5f), new Vertex3f(-0.5f, +0.5f, -0.5f), // Verticals new Vertex3f(-0.5f, -0.5f, -0.5f), new Vertex3f(-0.5f, +0.5f, -0.5f), new Vertex3f(+0.5f, -0.5f, -0.5f), new Vertex3f(+0.5f, +0.5f, -0.5f), new Vertex3f(+0.5f, -0.5f, +0.5f), new Vertex3f(+0.5f, +0.5f, +0.5f), new Vertex3f(-0.5f, -0.5f, +0.5f), new Vertex3f(-0.5f, +0.5f, +0.5f), }); bboxArray.SetArray(bboxVPositionArray, VertexArraySemantic.Position); bboxArray.SetElementArray(PrimitiveType.Lines); return(bboxArray); }
internal SceneObjectBatch(VertexArrays vertexArray) { if (vertexArray == null) { throw new ArgumentNullException("vertexArray"); } VertexArray = vertexArray; }
/// <summary> /// Construct an Geometry. /// </summary> /// <param name="vertexArray"> /// /// </param> /// <param name="state"></param> /// <param name="program"></param> public Geometry(VertexArrays vertexArray, State.GraphicsStateSet state, ShaderProgram program) : base(vertexArray, state, program) { vertexArray.IncRef(); if (program != null) { program.IncRef(); } }
/// <summary> /// Construct a SceneObjectGeometry. /// </summary> /// <param name="id"> /// A <see cref="String"/> that specify the node identifier. It can be null for unnamed objects. /// </param> /// <param name="vertexArray"> /// A <see cref="Objects.VertexArrays"/> that specifies the geometry primitive arrays. /// </param> /// <param name="program"> /// A <see cref="ShaderProgram"/> that specifies the program used for shading <paramref name="vertexArray"/>. /// </param> /// <exception cref="ArgumentNullException"> /// Exception thrown if <paramref name="vertexArray"/> is null. /// </exception> public SceneObjectGeometry(string id, VertexArrays vertexArray, ShaderProgram program) : base(id) { if (vertexArray == null) { throw new ArgumentNullException("vertexArray"); } _VertexArray = vertexArray; _Program = program; }
private SceneObjectGeometry CreatePlane() { SceneObjectGeometry geometry = new SceneObjectGeometry("Plane"); geometry.VertexArray = VertexArrays.CreatePlane(1.0f, 1.0f, -1.0f, 1, 1); // geometry.ObjectState.DefineState(new CullFaceState(FrontFaceDirection.Ccw, CullFaceMode.Back) { Culling = false }); geometry.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard"); return(geometry); }
/// <summary> /// Construct an SceneObjectBatch. /// </summary> /// <param name="vertexArray"> /// /// </param> /// <param name="state"></param> /// <param name="program"></param> public SceneObjectBatch(VertexArrays vertexArray, State.GraphicsStateSet state, ShaderProgram program) { if (vertexArray == null) { throw new ArgumentNullException("vertexArray"); } if (state == null) { throw new ArgumentNullException("state"); } Program = program; // It may be null to support fixed pipeline VertexArray = vertexArray; State = state; }
/// <summary> /// Actually create this GraphicsResource resources. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> used for allocating resources. /// </param> /// <remarks> /// All resources linked with <see cref="LinkResource(IGraphicsResource)"/> will be automatically created. /// </remarks> protected override void CreateObject(GraphicsContext ctx) { // Bounding box - Shared program LinkResource(_BoundingVolumeProgram = ctx.CreateProgram("OpenGL.Standard")); // Bounding box - Shared arrays const string BoundBoxArraysId = "SceneObjectGeometry.BoundingVolumeArrays"; VertexArrays boundingBoxArrays = (VertexArrays)ctx.GetSharedResource(BoundBoxArraysId); if (_BoundingVolume != null && boundingBoxArrays == null) { boundingBoxArrays = CreateBoundingVolumeArrays(_BoundingVolume); ctx.SetSharedResource(BoundBoxArraysId, boundingBoxArrays); } if (boundingBoxArrays != null) { LinkResource(_BoundingVolumeArray = boundingBoxArrays); } // Create geometry state, if necessary if (VertexArray != null && VertexArray.Exists(ctx) == false) { VertexArray.Create(ctx); } // Define program, if necessary if (Program == null && ProgramTag != null) { Program = ctx.CreateProgram(ProgramTag); } // Create program, if necessary if (Program != null && Program.Exists(ctx) == false) { Program.Create(ctx); } // Create instance-only resources foreach (Geometry geometry in _GeometryInstances) { geometry.Create(ctx); } // Create object state, but associating state to program ObjectState.Create(ctx, Program); // Base implementation base.CreateObject(ctx); }
public void ExampleCreateVertexArrays(GraphicsContext ctx) { VertexArrays vao = new VertexArrays(); ArrayBuffer <Vertex3f> aboPosition = new ArrayBuffer <Vertex3f>(BufferUsage.StaticDraw); ArrayBuffer <ColorRGBAF> aboColor = new ArrayBuffer <ColorRGBAF>(BufferUsage.StaticDraw); // ... create buffers ... // Note: assumes that ShaderProgram has a semantic vao.SetArray(aboPosition, VertexArraySemantic.Position); // Note: uses raw variable name vao.SetArray(aboColor, "my_Color", null); // Note: default attribute value assigned to all shader invocation instances vao.SetArrayDefault(Vertex4d.One, "my_Offset", null); // ... continue ... }
private void LinkShadowMapResources(GraphicsContext ctx) { LinkResource(_ShadowMapQuad = new VertexArrays()); ArrayBuffer <Vertex2f> positionArray = new ArrayBuffer <Vertex2f>(BufferUsage.StaticDraw); positionArray.Create(new Vertex2f[] { new Vertex2f(0.0f, 0.0f), new Vertex2f(1.0f, 0.0f), new Vertex2f(1.0f, 1.0f), new Vertex2f(0.0f, 1.0f), new Vertex2f(0.0f, 0.0f), new Vertex2f(1.0f, 1.0f), }); positionArray.Create(ctx); _ShadowMapQuad.SetArray(positionArray, VertexArraySemantic.Position); _ShadowMapQuad.SetArray(positionArray, VertexArraySemantic.TexCoord); _ShadowMapQuad.SetElementArray(PrimitiveType.Triangles); _ShadowMapQuad.Create(ctx); LinkResource(_ShadowMapDebugProgram = ctx.CreateProgram("OpenGL.Specialized+Depth")); }
private void CreateResources(GraphicsContext ctx) { // Program library _Context.MergeShadersLibrary("HelloObjects.Shaders._ShadersLibrary.xml"); // Mass buffer _MassBuffer = new ArrayBufferInterleaved <Mass>(BufferUsage.StaticDraw); _Context.LinkResource(_MassBuffer); // _MassBuffer.Immutable = false; _MassBuffer.Create(_Size); // Map arrays _MassArrays = new VertexArrays(); _Context.LinkResource(_MassArrays); _MassArrays.SetArray(_MassBuffer, 0, VertexArraySemantic.Position); _MassArrays.SetElementArray(PrimitiveType.Points, 0, 1024); _MassArrays.Create(_Context); // Programs _ComputeEnergy = _Context.CreateProgram("HelloObjects.MassForceCompute"); _ComputePosition = _Context.CreateProgram("HelloObjects.MassPositionCompute"); _DrawMass = _Context.CreateProgram("OpenGL.Standard"); // Initiailize mass buffer Random random = new Random(); _MassBuffer.Map(_Context, BufferAccessMask.MapWriteBit); for (uint i = 0; i < _MassBuffer.ItemsCount; i++) { Mass mass; mass.Position = new Vertex4f((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), 1.0f) * 256.0f; mass.Velocity = new Vertex4f((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble(), 1.0f) * 0.000f; mass.Force = new Vertex4f(0.0f, 0.0f, 0.0f, (float)Math.Abs(random.NextDouble() * 100000.0)); _MassBuffer.SetElement(mass, i); } _MassBuffer.Unmap(_Context); }
private SceneObjectGeometry CreatePlane() { SceneObjectGeometry geometry = new SceneObjectGeometry("Plane"); geometry.VertexArray = VertexArrays.CreatePlane(50.0f, 50.0f, 0.0f, 1, 1); geometry.ObjectState.DefineState(new CullFaceState(FrontFaceDirection.Ccw, CullFaceMode.Back)); geometry.ObjectState.DefineState(new TransformState()); MaterialState cubeMaterialState = new MaterialState(); cubeMaterialState.FrontMaterial = new MaterialState.Material(ColorRGBAF.ColorWhite * 0.5f); cubeMaterialState.FrontMaterial.Ambient = ColorRGBAF.ColorBlack; cubeMaterialState.FrontMaterial.Diffuse = ColorRGBAF.ColorWhite * 0.5f; cubeMaterialState.FrontMaterial.Specular = ColorRGBAF.ColorBlack; geometry.ObjectState.DefineState(cubeMaterialState); geometry.LocalModel.RotateX(-90.0); geometry.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard+PhongFragment"); return(geometry); }
public void ExampleSetVertexArraysIndexedElements(GraphicsContext ctx, ShaderProgram shaderProgram) { VertexArrays vao = new VertexArrays(); // ... create and setup buffers ... ElementBuffer <int> indexBuffer = new ElementBuffer <int>(BufferUsage.StaticDraw); indexBuffer.Create(new int[] { 0, 1, 2, 3, 2, 1 }); // Draw the first 6 deferenced vertices as GL_TRIANGLES int idx1 = vao.SetElementArray(PrimitiveType.Triangles, indexBuffer); // Draw the first two deferenced vertices as GL_LINES int idx2 = vao.SetElementArray(PrimitiveType.Lines, indexBuffer, 0, 2); // Create/update all resources linked to this instance vao.Create(ctx); // Draw all elements vao.Draw(ctx, shaderProgram); // Draw only the triangles vao.Draw(ctx, shaderProgram, idx1); }
public void ExampleSetVertexArraysElements(GraphicsContext ctx, ShaderProgram shaderProgram) { VertexArrays vao = new VertexArrays(); // ... create and setup buffers ... // Draw the first 4 vertices as GL_LINES int idx1 = vao.SetElementArray(PrimitiveType.Lines, 0, 4); // Draw all other vertices using GL_TRIANGLES int idx2 = vao.SetElementArray(PrimitiveType.Triangles, 4, vao.ArrayLength); // Draw all vertices using GL_POINTS int idx3 = vao.SetElementArray(PrimitiveType.Points); // Create/update all resources linked to this instance vao.Create(ctx); // Draw all elements vao.Draw(ctx, shaderProgram); // Draw only the triangles vao.Draw(ctx, shaderProgram, idx2); // Draw using IElement interface (idx1 and idx3) vao.Draw(ctx, shaderProgram, vao.GetElementArray(idx1), vao.GetElementArray(idx3)); }
private void GlSurface_ContextCreated(object sender, GLSurfaceViewEventArgs e) { // Wrap GL context with GraphicsContext _Context = new GraphicsContext(e.DeviceContext, e.RenderContext); _CubeScene = new SceneGraph(SceneGraphFlags.None); _CubeScene.SceneRoot = new SceneObjectGeometry(); _CubeScene.SceneRoot.ObjectState.DefineState(new DepthTestState(DepthFunction.Less)); _CubeScene.CurrentView = new SceneObjectCamera(); _CubeScene.SceneRoot.Link(_CubeScene.CurrentView); SceneObjectGeometry geometry = new SceneObjectGeometry(); geometry.ProgramTag = ShadersLibrary.Instance.CreateProgramTag("OpenGL.Standard"); geometry.AddGeometry(VertexArrays.CreateSphere(3.0f, 8, 8)); _CubeScene.SceneRoot.Link(geometry); _CubeScene.Create(_Context); Gl.ClearColor(1.0f, 0.1f, 0.1f, 1.0f); }
/// <summary> /// Automatically computes bounding box for the specified vertex arrays. /// </summary> /// <param name="vertexArrayObject"> /// /// </param> /// <returns> /// It returns the <see cref="IBoundingVolume"/> for <paramref name="vertexArrayObject"/>, if possible. /// </returns> private static IBoundingVolume ComputeBoundingVolume(VertexArrays vertexArrayObject) { if (vertexArrayObject == null) { throw new ArgumentNullException("vertexArrayObject"); } VertexArrays.IVertexArray vertexArray = vertexArrayObject.GetVertexArray(VertexArraySemantic.Position); if (vertexArray == null) { return(null); } ArrayBufferBase positionArray = vertexArray.Array; Type positionArrayType = positionArray.GetType(); if (positionArrayType == typeof(ArrayBuffer <Vertex4f>)) { ArrayBuffer <Vertex4f> positionArray4f = (ArrayBuffer <Vertex4f>)positionArray; Vertex4f min = Vertex4f.Maximum, max = Vertex4f.Minimum; positionArray4f.MinMax(out min, out max); return(new BoundingBox((Vertex3f)min, (Vertex3f)max)); } else if (positionArrayType == typeof(ArrayBuffer <Vertex3f>)) { ArrayBuffer <Vertex3f> positionArray3f = (ArrayBuffer <Vertex3f>)positionArray; Vertex3f min = Vertex3f.Maximum, max = Vertex3f.Minimum; positionArray3f.MinMax(out min, out max); return(new BoundingBox(min, max)); } else { return(null); } }
public void AddGeometry(VertexArrays vertexArray) { _GeometryInstances.Add(new Geometry(vertexArray)); }
private void VisionControl_ContextCreated(object sender, OpenGL.GlControlEventArgs e) { // Create GL context abstraction _GraphicsContext = new GraphicsContext(e.DeviceContext, e.RenderContext); // Create texture _FramebufferTexture = new Texture2d(1024, 1024, PixelLayout.RGB24); _FramebufferTexture.SamplerParams.MagFilter = TextureMagFilter.Linear; _FramebufferTexture.SamplerParams.MinFilter = TextureMinFilter.Linear; _FramebufferTexture.Create(_GraphicsContext); // Create framebuffer _Framebuffer = new Framebuffer(); _Framebuffer.AttachColor(0, _FramebufferTexture); _Framebuffer.Create(_GraphicsContext); // Create shader (standard) _ProgramStd = _GraphicsContext.CreateProgram("OpenGL.Standard"); _ProgramStd.Create(_GraphicsContext); // Create program (standard + texture) _ProgramStdTex = _GraphicsContext.CreateProgram("OpenGL.Standard+Texture"); _ProgramStdTex.Create(_GraphicsContext); // Create vertex arrays (square) ArrayBuffer <Vertex2f> quadBuffer = new ArrayBuffer <Vertex2f>(BufferUsage.StaticDraw); quadBuffer.Create(new Vertex2f[] { new Vertex2f(-0.5f, +0.5f), new Vertex2f(-0.5f, -0.5f), new Vertex2f(+0.5f, +0.5f), new Vertex2f(+0.5f, -0.5f), }); _ArraysQuad = new VertexArrays(); _ArraysQuad.SetArray(quadBuffer, VertexArraySemantic.Position); _ArraysQuad.SetElementArray(PrimitiveType.TriangleStrip); _ArraysQuad.Create(_GraphicsContext); // Create vertex arrays (square) ArrayBuffer <Vertex2f> postquadBuffer = new ArrayBuffer <Vertex2f>(BufferUsage.StaticDraw); postquadBuffer.Create(new Vertex2f[] { new Vertex2f(0.0f, 1.0f), new Vertex2f(0.0f, 0.0f), new Vertex2f(1.0f, 1.0f), new Vertex2f(1.0f, 0.0f), }); _ArraysPostQuad = new VertexArrays(); _ArraysPostQuad.SetArray(postquadBuffer, VertexArraySemantic.Position); _ArraysPostQuad.SetArray(postquadBuffer, VertexArraySemantic.TexCoord); _ArraysPostQuad.SetElementArray(PrimitiveType.TriangleStrip); _ArraysPostQuad.Create(_GraphicsContext); // Create vertex arrays (optical markers) _BufferOpticalMarkers = new ArrayBuffer <Vertex2f>(BufferUsage.DynamicDraw); _BufferOpticalMarkers.Create(10000 * 2); _ArraysOpticalMarkers = new VertexArrays(); _ArraysOpticalMarkers.SetArray(_BufferOpticalMarkers, VertexArraySemantic.Position); _ArraysOpticalMarkers.SetElementArray(PrimitiveType.Lines); _ArraysOpticalMarkers.Create(_GraphicsContext); }
public VertexArrays CreateArrays(ObjContext objContext) { if (objContext == null) { throw new ArgumentNullException("objContext"); } VertexArrays vertexArray = new VertexArrays(); List <ObjFaceCoord> coords = new List <ObjFaceCoord>(); bool hasTexCoord = Material.DiffuseTexture != null; bool hasNormals = false; bool hasTanCoord = hasTexCoord && Material.NormalTexture != null; foreach (ObjFace f in Faces) { hasTexCoord |= f.HasTexCoord; hasNormals |= f.HasNormal; coords.AddRange(f.Triangulate()); } uint vertexCount = (uint)coords.Count; Vertex4f[] position = new Vertex4f[vertexCount]; Vertex3f[] normal = hasNormals ? new Vertex3f[vertexCount] : null; Vertex2f[] texcoord = new Vertex2f[vertexCount]; for (int i = 0; i < position.Length; i++) { Debug.Assert(coords[i].VertexIndex < objContext.Vertices.Count); position[i] = objContext.Vertices[coords[i].VertexIndex]; if (hasTexCoord) { Debug.Assert(coords[i].TexCoordIndex < objContext.TextureCoords.Count); texcoord[i] = objContext.TextureCoords[coords[i].TexCoordIndex]; } if (hasNormals) { Debug.Assert(coords[i].NormalIndex < objContext.Normals.Count); normal[i] = objContext.Normals[coords[i].NormalIndex]; } } // Position (mandatory) ArrayBuffer <Vertex4f> positionBuffer = new ArrayBuffer <Vertex4f>(); positionBuffer.Create(position); vertexArray.SetArray(positionBuffer, VertexArraySemantic.Position); // Layout (triangles) vertexArray.SetElementArray(PrimitiveType.Triangles); // Texture if (hasTexCoord) { ArrayBuffer <Vertex2f> texCoordBuffer = new ArrayBuffer <Vertex2f>(); texCoordBuffer.Create(texcoord); vertexArray.SetArray(texCoordBuffer, VertexArraySemantic.TexCoord); } // Normals if (hasNormals) { ArrayBuffer <Vertex3f> normalBuffer = new ArrayBuffer <Vertex3f>(); normalBuffer.Create(normal); vertexArray.SetArray(normalBuffer, VertexArraySemantic.Normal); } else { ArrayBuffer <Vertex3f> normalBuffer = new ArrayBuffer <Vertex3f>(); normalBuffer.Create(vertexCount); vertexArray.SetArray(normalBuffer, VertexArraySemantic.Normal); // XXX vertexArray.GenerateNormals(); } // Tangents if (hasTanCoord) { ArrayBuffer <Vertex3f> tanCoordBuffer = new ArrayBuffer <Vertex3f>(); tanCoordBuffer.Create(vertexCount); vertexArray.SetArray(tanCoordBuffer, VertexArraySemantic.Tangent); ArrayBuffer <Vertex3f> bitanCoordBuffer = new ArrayBuffer <Vertex3f>(); bitanCoordBuffer.Create(vertexCount); vertexArray.SetArray(bitanCoordBuffer, VertexArraySemantic.Bitangent); // XXX vertexArray.GenerateTangents(); } return(vertexArray); }
public Geometry(VertexArrays vertexArray) : base(vertexArray) { vertexArray.IncRef(); }
public void AddGeometry(VertexArrays vertexArray, State.GraphicsStateSet state) { _GeometryInstances.Add(new Geometry(vertexArray, state, null)); }