Example #1
0
        private void LogDrawText(Vector2 dest, Color color, string text, params object[] parameters)
        {
            DrawCalls.Add(new FontDrawCall
            {
                Dest       = dest,
                Color      = color,
                Text       = text,
                Parameters = parameters
            });

            System.Console.WriteLine($"{Name} draw to ({dest}): {color}");
            System.Console.WriteLine(text);
            LogParameters(parameters);
        }
Example #2
0
        public void BuildModel(R_EnvCell envCell)
        {
            foreach (var cellStruct in envCell.Environment.R_CellStructs.Values)
            {
                var vertices = cellStruct.VertexArray;

                foreach (var polygon in cellStruct.Polygons)
                {
                    var surfaceIdx = polygon._polygon.PosSurface;
                    var surfaceID  = envCell.EnvCell._envCell.Surfaces[surfaceIdx];

                    var texture = TextureCache.Get(surfaceID);
                    //Console.WriteLine($"Texture: {surfaceID:X8} Size: {texture.Width}x{texture.Height}");
                    var textureFormat = new TextureFormat(texture.Format, texture.Width, texture.Height, cellStruct.HasWrappingUVs);

                    if (!DrawCalls.TryGetValue(textureFormat, out var batch))
                    {
                        batch = new InstanceBatchDraw(textureFormat);
                        DrawCalls.Add(textureFormat, batch);
                    }
                    batch.AddPolygon(vertices, polygon, surfaceID);
                }
            }
        }
Example #3
0
        /* Construct a mesh object from it's resource */
        public void LoadFromResource(MaterialLoader materialLoader)
        {
            if (Resource != null)
            {
                var block          = Resource.VBIB;
                var data           = (BinaryKV3)Resource.Blocks[BlockType.DATA];
                var modelArguments = (ArgumentDependencies)((ResourceEditInfo)Resource.Blocks[BlockType.REDI]).Structs[ResourceEditInfo.REDIStruct.ArgumentDependencies];

                var vertexBuffers = new uint[block.VertexBuffers.Count];
                var indexBuffers  = new uint[block.IndexBuffers.Count];

                GL.GenBuffers(block.VertexBuffers.Count, vertexBuffers);
                GL.GenBuffers(block.IndexBuffers.Count, indexBuffers);

                for (var i = 0; i < block.VertexBuffers.Count; i++)
                {
                    GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffers[i]);
                    GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(block.VertexBuffers[i].Count * block.VertexBuffers[i].Size), block.VertexBuffers[i].Buffer, BufferUsageHint.StaticDraw);

                    var verticeBufferSize = 0;
                    GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out verticeBufferSize);
                }

                for (var i = 0; i < block.IndexBuffers.Count; i++)
                {
                    GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffers[i]);
                    GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(block.IndexBuffers[i].Count * block.IndexBuffers[i].Size), block.IndexBuffers[i].Buffer, BufferUsageHint.StaticDraw);

                    var indiceBufferSize = 0;
                    GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out indiceBufferSize);
                }

                //Prepare drawcalls
                var a = (KVObject)data.Data.Properties["m_sceneObjects"].Value;

                for (var b = 0; b < a.Properties.Count; b++)
                {
                    var c = (KVObject)((KVObject)a.Properties[b.ToString()].Value).Properties["m_drawCalls"].Value;

                    for (var i = 0; i < c.Properties.Count; i++)
                    {
                        var d = (KVObject)c.Properties[i.ToString()].Value;

                        var materialName = d.Properties["m_material"].Value.ToString();

                        if (SkinMaterials.Any())
                        {
                            materialName = SkinMaterials[i];
                        }

                        var material = materialLoader.GetMaterial(materialName);

                        // TODO: Don't pass around so much shit
                        var drawCall = CreateDrawCall(d.Properties, vertexBuffers, indexBuffers, modelArguments, Resource.VBIB, material);
                        DrawCalls.Add(drawCall);
                    }
                }

                DrawCalls = DrawCalls.OrderBy(x => x.Material.Name).ToList();

                // No longer need the resource, we extracted all data
                Resource = null;
            }
        }