/// <summary> /// Loads the content. /// </summary> public override void LoadContent() { MyRender.Log.WriteLine("TransparentGeometry.LoadContent() - START"); MyRender.Log.IncreaseIndent(); MyRender.GetRenderProfiler().StartProfilingBlock("TransparentGeometry.LoadContent"); MyRender.Log.WriteLine(string.Format("MyTransparentGeometry.LoadData - START")); m_sortedTransparentGeometry.Clear(); m_preparedTransparentGeometry.Clear(); m_lowresTransparentGeometry.Clear(); // Max count of all particles should be less or equal than max count of billboards MyDebug.AssertRelease(MyTransparentGeometryConstants.MAX_PARTICLES_COUNT <= MyTransparentGeometryConstants.MAX_TRANSPARENT_GEOMETRY_COUNT); MyDebug.AssertRelease(MyTransparentGeometryConstants.MAX_COCKPIT_PARTICLES_COUNT <= MyTransparentGeometryConstants.MAX_TRANSPARENT_GEOMETRY_COUNT); PrepareAtlasMaterials(); m_vertexBuffer = new VertexBuffer(MyRender.GraphicsDevice, MyVertexFormatTransparentGeometry.Stride * MyTransparentGeometryConstants.MAX_TRANSPARENT_GEOMETRY_COUNT * MyTransparentGeometryConstants.VERTICES_PER_TRANSPARENT_GEOMETRY, Usage.WriteOnly | Usage.Dynamic, VertexFormat.None, Pool.Default); m_startOffsetInVertexBuffer = 0; m_endOffsetInVertexBuffer = 0; m_vertexBuffer.DebugName = "TransparentGeometry"; m_indexBuffer = new IndexBuffer(MyRender.GraphicsDevice, MyTransparentGeometryConstants.MAX_TRANSPARENT_GEOMETRY_INDICES * sizeof(int), Usage.WriteOnly, Pool.Default, false); m_indexBuffer.SetData(m_indices); MyRender.GetRenderProfiler().EndProfilingBlock(); MyRender.Log.DecreaseIndent(); MyRender.Log.WriteLine("TransparentGeometry.LoadContent() - END"); }
public void LoadBuffers(MyModelData modelData, string assetName = null) { System.Diagnostics.Debug.Assert(modelData.Sections.Count > 0, "Invalid object"); if (modelData.Sections.Count == 0) return; // create index buffer { m_trianglesCount = modelData.Indices.Count / 3; m_Indices_16bit = new ushort[modelData.Indices.Count]; for (int i = 0; i < modelData.Indices.Count; ++i) m_Indices_16bit[i] = (ushort)modelData.Indices[i]; m_indexBuffer = new IndexBuffer(MyRender.GraphicsDevice, m_Indices_16bit.Length * sizeof(short), Usage.WriteOnly, Pool.Default, true); m_indexBuffer.SetData(m_Indices_16bit); m_indexBuffer.Tag = this; m_indexBufferSize = m_Indices_16bit.Length * sizeof(short); SignResource(m_indexBuffer); } // create vertex buffer { m_verticesCount = modelData.Positions.Count; m_vertices = new MyCompressedVertexNormal[m_verticesCount]; var vertexArray = new MyVertexFormatPositionNormalTextureTangent[m_verticesCount]; for (int i = 0; i < modelData.Positions.Count; ++i) { vertexArray[i].Position = modelData.Positions[i]; vertexArray[i].Normal = modelData.Normals[i]; vertexArray[i].Tangent = modelData.Tangents[i]; vertexArray[i].TexCoord = modelData.TexCoords[i]; m_vertices[i] = new MyCompressedVertexNormal() { Position = vertexArray[i].PositionPacked, Normal = vertexArray[i].NormalPacked }; } m_vertexDeclaration = MyVertexFormatPositionNormalTextureTangent.VertexDeclaration; m_vertexStride = MyVertexFormatPositionNormalTextureTangent.Stride; m_vertexBufferSize = vertexArray.Length * m_vertexStride; m_vertexBuffer = new VertexBuffer(MyRender.GraphicsDevice, m_vertexBufferSize, Usage.WriteOnly, VertexFormat.None, Pool.Default); m_vertexBuffer.SetData(vertexArray); m_vertexBuffer.Tag = this; SignResource(m_vertexBuffer); } m_meshContainer.Clear(); // apply materials here for (int s = 0; s < modelData.Sections.Count; ++s) { var mpi = new MyMeshPartInfo(); mpi.Technique = m_drawTechnique; // Disabled, because it assert always when models are loaded before materials //System.Diagnostics.Debug.Assert(MyRenderModels.Materials.ContainsKey(modelData.Sections[s].MaterialName), "Mesh material not present!"); if (MyRenderModels.Materials.ContainsKey(modelData.Sections[s].MaterialName)) mpi.m_MaterialDesc = MyRenderModels.Materials[modelData.Sections[s].MaterialName]; var start = modelData.Sections[s].IndexStart; var end = start + modelData.Sections[s].TriCount*3; for (int i = start; i < end; ++i) mpi.m_indices.Add(modelData.Indices[i]); m_meshContainer.Add(new MyRenderMesh(mpi, null) { IndexStart = modelData.Sections[s].IndexStart, TriCount = modelData.Sections[s].TriCount }); } // store properties of this model { BoundingBox = modelData.AABB; BoundingSphere = new BoundingSphere(modelData.AABB.Center, modelData.AABB.HalfExtents.Length()); BoundingBoxSize = BoundingBox.Size; BoundingBoxSizeHalf = BoundingBox.HalfExtents; ModelInfo = new MyModelInfo(m_trianglesCount, m_verticesCount, BoundingBoxSize); PreloadTextures(LoadingMode.Immediate); LoadState = Textures.LoadState.Loaded; m_loadedContent = true; m_loadedData = true; } }
void CreateIndexBuffer() { MyDebug.AssertDebug(m_indexBuffer == null); if (m_Indices != null) { m_indexBuffer = new IndexBuffer(MyRender.GraphicsDevice, m_Indices.Length * sizeof(int), Usage.WriteOnly, Pool.Default, false); m_indexBuffer.SetData(m_Indices); m_indexBuffer.Tag = this; m_indexBufferSize = m_Indices.Length * sizeof(int); } else if (m_Indices_16bit != null) { m_indexBuffer = new IndexBuffer(MyRender.GraphicsDevice, m_Indices_16bit.Length * sizeof(short), Usage.WriteOnly, Pool.Default, true); m_indexBuffer.SetData(m_Indices_16bit); m_indexBuffer.Tag = this; m_indexBufferSize = m_Indices_16bit.Length * sizeof(short); } MyPerformanceCounter.PerAppLifetime.ModelIndexBuffersSize += m_indexBufferSize; SignResource(m_indexBuffer); }
public override void LoadContent() { int vbSize; unsafe { vbSize = sizeof(MyVertexFormatPositionNormalTextureTangent) * m_vertices.Length; } int ibSize = sizeof(ushort) * m_indices.Length; m_vertexBuffer = new VertexBuffer(MyRender.Device, vbSize, Usage.Dynamic | Usage.WriteOnly, VertexFormat.None, Pool.Default); m_vertexBuffer.Tag = this; m_vertexBuffer.SetData(m_vertices, LockFlags.Discard); m_indexBuffer = new IndexBuffer(MyRender.Device, ibSize, Usage.Dynamic | Usage.WriteOnly, Pool.Default, true); m_indexBuffer.Tag = this; m_indexBuffer.SetData(m_indices, LockFlags.Discard); m_ropeMaterial.PreloadTexture(); base.LoadContent(); }