Example #1
0
        public Mesh(IntPtr data, UInt64 numVertices, List <uint> indices, ulong numIndices,
                    Material material, Shader shader, VertexMode mode)
        {
            this.vertexMode = mode;
            this.material   = material;
            this.shader     = shader;
            this.numIndices = numIndices;

            IntPtr ptr = IntPtr.Zero;

            this.vertexBuffer = new VertexBuffer(data, numVertices, mode);

            PrintStatus('V', vertexBuffer.GET_BUFFER_ID(), ". vertexBuffer", 3, MESSAGE_COLOR);
            uint[] buffer = indices.ToArray();

            unsafe
            {
                fixed(uint *p = buffer)
                {
                    ptr = (IntPtr)p;
                    this.indexBuffer = new IndexBuffer(ptr, numIndices, sizeof(int));
                }
            }

            PrintStatus('I', indexBuffer.GET_BUFFER_ID(), ". indexBuffer", 5, MESSAGE_COLOR);

            this.diffuseLocation      = GL.GetUniformLocation(shader.GetShaderID(), "u_material.diffuse");
            this.specularLocation     = GL.GetUniformLocation(shader.GetShaderID(), "u_material.specular");
            this.emissiveLocation     = GL.GetUniformLocation(shader.GetShaderID(), "u_material.emissive");
            this.shininessLocation    = GL.GetUniformLocation(shader.GetShaderID(), "u_material.shininess");
            this.diffuseMapLocation   = GL.GetUniformLocation(shader.GetShaderID(), "u_diffuse_map");
            this.normalMapLocation    = GL.GetUniformLocation(shader.GetShaderID(), "u_normal_map");
            this.useNormalMapLocation = GL.GetUniformLocation(shader.GetShaderID(), "u_use_normal_map");
            this.useTexturesLocation  = GL.GetUniformLocation(shader.GetShaderID(), "u_use_textures");
        }
Example #2
0
        bool readFirstInfo()
        {
            if (this.fs == null)
            {
                return(false);
            }

            this.br = new BinaryReader(this.fs);
            this.bw = new BinaryWriter(this.fs);

            this.sizeOfVertex = this.br.ReadUInt64();
            this.numMaterials = this.br.ReadUInt64();
            this.sizeMaterial = System.Runtime.InteropServices.Marshal.SizeOf(typeof(BMFMaterial));

            if (this.sizeOfVertex == (ulong)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VertexTextureAndNormal)))
            {
                this.vm = VertexMode.TextureAndNormal;
            }
            else if (this.sizeOfVertex == (ulong)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VertexTextureOnly)))
            {
                this.vm = VertexMode.TextureOnly;
            }
            else if (this.sizeOfVertex == (ulong)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VertexMaterialOnly)))
            {
                this.vm = VertexMode.MaterialOnly;
            }
            else
            {
                return(false);

                throw new Exception("No EnumCode");
            }

            return(true);
        }
Example #3
0
        private void AssignMaterialSortIDs(RawList <SortItem> sortItems, RawList <VertexDrawItem> drawItems)
        {
            VertexDrawItem[] drawData = drawItems.Data;
            SortItem[]       sortData = sortItems.Data;
            int count = sortItems.Count;

            for (int i = 0; i < sortData.Length; i++)
            {
                if (i >= count)
                {
                    break;
                }

                int        drawIndex       = sortData[i].DrawItemIndex;
                int        vertexTypeIndex = drawData[drawIndex].TypeIndex;
                VertexMode vertexMode      = drawData[drawIndex].Mode;
                BatchInfo  material        = drawData[drawIndex].Material;

                int matHash;
                unchecked
                {
                    // Avoid just "cutting off" parts of the original hash,
                    // as this is likely to lead to collisions.
                    matHash = material.GetHashCode();
                    matHash = (13 * matHash + 17 * (matHash >> 9)) % (1 << 23);
                }

                // Bit significance is used to achieve sorting by multiple traits at once.
                // The higher a traits bit significance, the higher its priority when sorting.
                sortData[i].SortIndex =
                    (((int)vertexMode & 15) << 0) |                     //                           XXXX  4 Bit   Vertex Mode  Offset 4
                    ((matHash & 8388607) << 4) |                        //    XXXXXXXXXXXXXXXXXXXXXXXaaaa  23 Bit  Material     Offset 27
                    ((vertexTypeIndex & 15) << 27);                     // XXXbbbbbbbbbbbbbbbbbbbbbbbaaaa  4 Bit   Vertex Type  Offset 31
            }
        }
Example #4
0
        public DrawBatch(BatchInfo material, VertexMode vertexMode, T[] vertices, int vertexCount, float zSortIndex)
        {
            if (vertices == null || vertices.Length == 0)
            {
                throw new ArgumentException("A zero-vertex DrawBatch is invalid.");
            }

            // Assign data
            this.vertexCount = Math.Min(vertexCount, vertices.Length);
            this.vertices    = vertices;
            this.material    = material;
            this.vertexMode  = vertexMode;
            this.zSortIndex  = zSortIndex;

            // Determine sorting index for non-Z-Sort materials
            if (!this.material.Technique.Res.NeedsZSort)
            {
                int vTypeSI = vertices[0].TypeIndex;
                int matHash = this.material.GetHashCode() % (1 << 23);

                // Bit significancy is used to achieve sorting by multiple traits at once.
                // The higher a traits bit significancy, the higher its priority when sorting.
                this.sortIndex =
                    (((int)vertexMode & 15) << 0) |                             //							  XXXX	4 Bit	Vertex Mode		Offset 4
                    ((matHash & 8388607) << 4) |                                //	   XXXXXXXXXXXXXXXXXXXXXXXaaaa	23 Bit	Material		Offset 27
                    ((vTypeSI & 15) << 27);                                     //	XXXbbbbbbbbbbbbbbbbbbbbbbbaaaa	4 Bit	Vertex Type		Offset 31

                // Keep an eye on this. If for example two material hash codes randomly have the same 23 lower bits, they
                // will be sorted as if equal, resulting in blocking batch aggregation.
            }
        }
Example #5
0
 public Vertex(float x, float y, float u, float v)
 {
     Position = new Vector4(x, y, 0f, 1f);
     TexturePosition = new Vector2(u, v);
     BezierCoordinates = default(Vector2);
     Mode = VertexMode.Default;
 }
Example #6
0
 public DrawBatch(VertexBuffer buffer, RawList <VertexDrawRange> ranges, VertexMode mode, BatchInfo material)
 {
     this.vertexBuffer = buffer;
     this.vertexRanges = ranges;
     this.vertexMode   = mode;
     this.material     = material;
 }
Example #7
0
 public Vertex(Math.Vector2 position)
 {
     Position = new Vector4(position.X, position.Y, 0f, 1f);
     TexturePosition = default(Vector2);
     BezierCoordinates = default(Vector2);
     Mode = VertexMode.Default;
 }
        public void AddToVertexDisplacement(string value, VertexMode vertexMode)
        {
            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            if (!m_dirtyPerVertexData)
            {
                OpenPerVertexHeader(true);
            }

            switch (vertexMode)
            {
            default:
            case VertexMode.Relative:
            {
                m_vertexData += "\t\t\t" + Constants.VertexShaderInputStr + ".vertex.xyz += " + value + ";\n";
            } break;

            case VertexMode.Absolute:
            {
                m_vertexData += "\t\t\t" + Constants.VertexShaderInputStr + ".vertex.xyz = " + value + ";\n";
            } break;
            }
        }
Example #9
0
 public DrawBatch(VertexDeclaration type, RawList <VertexDrawRange> ranges, VertexMode mode, BatchInfo material)
 {
     this.vertexType   = type;
     this.vertexRanges = ranges;
     this.vertexMode   = mode;
     this.material     = material;
 }
Example #10
0
        public void AddVertices <T>(BatchInfo material, VertexMode vertexMode, T[] vertexBuffer, int vertexCount) where T : struct, IVertexData
        {
            if (vertexCount == 0)
            {
                return;
            }
            if (vertexBuffer == null || vertexBuffer.Length == 0)
            {
                return;
            }
            if (vertexCount > vertexBuffer.Length)
            {
                vertexCount = vertexBuffer.Length;
            }
            if (material == null)
            {
                material = Material.Checkerboard.Res.InfoDirect;
            }

            if (this.pickingIndex != 0)
            {
                ColorRgba clr = new ColorRgba((this.pickingIndex << 8) | 0xFF);
                for (int i = 0; i < vertexCount; ++i)
                {
                    vertexBuffer[i].Color = clr;
                }

                material           = new BatchInfo(material);
                material.Technique = DrawTechnique.Picking;
                if (material.Textures == null)
                {
                    material.MainTexture = Texture.White;
                }
            }
            else if (material.Technique == null || !material.Technique.IsAvailable)
            {
                material           = new BatchInfo(material);
                material.Technique = DrawTechnique.Solid;
            }

            // When rendering without depth writing, use z sorting everywhere - there's no real depth buffering!
            bool zSort = !this.DepthWrite || material.Technique.Res.NeedsZSort;
            List <IDrawBatch> buffer     = zSort ? this.drawBufferZSort : this.drawBuffer;
            float             zSortIndex = zSort ? DrawBatch <T> .CalcZSortIndex(vertexBuffer, vertexCount) : 0.0f;

            if (buffer.Count > 0 && buffer[buffer.Count - 1].CanAppendJIT <T>(
                    zSort ? 1.0f / this.zSortAccuracy : 0.0f,
                    zSortIndex,
                    material,
                    vertexMode))
            {
                buffer[buffer.Count - 1].AppendJIT(vertexBuffer, vertexCount);
            }
            else
            {
                buffer.Add(new DrawBatch <T>(material, vertexMode, vertexBuffer, vertexCount, zSortIndex));
            }
            ++this.numRawBatches;
        }
Example #11
0
 public static bool IsBatchableMode(this VertexMode mode)
 {
     return
         (mode == VertexMode.Lines ||
          mode == VertexMode.Points ||
          mode == VertexMode.Quads ||
          mode == VertexMode.Triangles);
 }
Example #12
0
 public static bool IsVertexModeAppendable(VertexMode mode)
 {
     return
         (mode == VertexMode.Lines ||
          mode == VertexMode.Points ||
          mode == VertexMode.Quads ||
          mode == VertexMode.Triangles);
 }
Example #13
0
 public Element Mesh(Point[] points, Color[] colors, int[] indices, VertexMode vertexMode = VertexMode.Triangles)
 {
     points = Utils.ToImage(_viewport, points);
     return(new ElementMesh {
         Owner = this,
         Points = points,
         Colors = colors,
         Indices = indices,
         VertexMode = vertexMode,
     });
 }
Example #14
0
        public VertexBuffer(IntPtr data, ulong numVertices, VertexMode mode)
        {
            VAO_ = GL.GenVertexArray();
            GL.BindVertexArray(VAO_);

            int size = 0;

            unsafe {
                switch (mode)
                {
                case VertexMode.TextureAndNormal:
                    size = sizeof(VertexTextureAndNormal);
                    break;

                case VertexMode.TextureOnly:
                    size = sizeof(VertexTextureOnly);
                    break;

                case VertexMode.MaterialOnly:

                    size = sizeof(VertexMaterialOnly);
                    break;

                default: break;
                }
            }

            //bind all to vio **-
            BUFFER_ID_ = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, BUFFER_ID_);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(numVertices * (uint)size), data, BufferUsageHint.StaticDraw);
            GL.EnableVertexAttribArray(0);
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, size, Marshal.OffsetOf(typeof(VertexMaterialOnly), "position"));
            GL.EnableVertexAttribArray(1);
            GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, size, Marshal.OffsetOf(typeof(VertexMaterialOnly), "normal"));

            if (mode == VertexMode.TextureAndNormal)
            {
                GL.EnableVertexAttribArray(2);
                GL.VertexAttribPointer(2, 3, VertexAttribPointerType.Float, false, size, Marshal.OffsetOf(typeof(VertexTextureAndNormal), "tangent"));
                GL.EnableVertexAttribArray(3);
                GL.VertexAttribPointer(3, 3, VertexAttribPointerType.Float, false, size, Marshal.OffsetOf(typeof(VertexTextureAndNormal), "textureCord"));
            }
            else if (mode == VertexMode.TextureOnly)
            {
                GL.EnableVertexAttribArray(2);
                GL.VertexAttribPointer(3, 3, VertexAttribPointerType.Float, false, size, Marshal.OffsetOf(typeof(VertexTextureOnly), "textureCord"));
            }

            //bind all to vio -**
            GL.BindVertexArray(0);
        }
Example #15
0
        void ProcessNode(Node node, Scene scene, VertexMode mode)
        {
            for (int i = 0; i < node.MeshCount; i++)
            {
                Assimp.Mesh mesh = scene.Meshes[node.MeshIndices[i]];
                ProcessMesh(mesh, scene, mode);
            }

            for (int i = 0; i < node.ChildCount; i++)
            {
                ProcessNode(node.Children[i], scene, mode);
            }
        }
Example #16
0
        public void DataToVBO(Vertex[] verts, int[] indices)
        {
            vertexFlags = VertexMode.UV1; // normaalit + uv

            AllocVBO(verts.Length, indices.Length);

            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID);
            GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)0, (IntPtr)(verts.Length * vertexSize), verts);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID);
            GL.BufferSubData(BufferTarget.ElementArrayBuffer, (IntPtr)0, (IntPtr)(indices.Length * sizeof(int)), indices);

            Util.CheckGLError("VBO");
        }
Example #17
0
File: VBO.cs Project: Keilerr/csat
        public void DataToVBO(Vertex[] vertices, ushort[] indices, VertexMode mode)
        {
            if (numOfIndices > 0)
            {
                Dispose();
            }
            int size;

            vertexFlags  = mode;
            numOfIndices = indices.Length;
            Vertex.Size  = BlittableValueType.StrideOf(vertices);

            GL.GenBuffers(1, out vertexID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * Vertex.Size), vertices, usage);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (vertices.Length * BlittableValueType.StrideOf(vertices) != size)
            {
                Log.Error("DataToVBO: Vertex data not uploaded correctly");
            }

            GL.GenBuffers(1, out indexID);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(ushort)), indices, usage);
            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (indices.Length * sizeof(short) != size)
            {
                throw new ApplicationException("DataToVBO: Element data not uploaded correctly");
            }

            Shader = GLSLShader.Load();

            if (Shader != null)
            {
                if (Settings.UseGL3)
                {
                    GL.GenVertexArrays(1, out vaoID);
                    GL.BindVertexArray(vaoID);
                }
                GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID);
                Shader.SetAttributes();
                if (Settings.UseGL3)
                {
                    GL.BindVertexArray(0);
                }
            }

            GLExt.CheckGLError("DataToVBO");
        }
Example #18
0
 public MeshPreview()
 {
     _previewblock  = new MaterialPropertyBlock();
     _meshvertex    = new List <Vector3>();
     _meshnormals   = new List <Vector3>();
     _meshuvs       = new List <Vector2>();
     _meshtriangles = new List <int>();
     _mesh          = new Mesh();
     _mesh.MarkDynamic();
     _mesh.UploadMeshData(false);
     _vertexmode    = VertexMode.None;
     _primarylist   = new List <int>();
     _secondarylist = new List <int>();
     _primarytset   = new HashSet <int>();
     _secondarytset = new HashSet <int>();
     _display       = new PreviewAxiDisplay();
 }
Example #19
0
        private static PrimitiveType GetOpenTKVertexMode(VertexMode mode)
        {
            switch (mode)
            {
            default:
            case VertexMode.Points:                 return(PrimitiveType.Points);

            case VertexMode.Lines:                  return(PrimitiveType.Lines);

            case VertexMode.LineStrip:              return(PrimitiveType.LineStrip);

            case VertexMode.LineLoop:               return(PrimitiveType.LineLoop);

            case VertexMode.Triangles:              return(PrimitiveType.Triangles);

            case VertexMode.TriangleStrip:  return(PrimitiveType.TriangleStrip);

            case VertexMode.TriangleFan:    return(PrimitiveType.TriangleFan);
            }
        }
Example #20
0
 public override void Enable()
 {
     _vertexmode = VertexMode.None;
     InitializePreviewUtility();
     _previewblock.Clear();
     _meshvertex.Clear();
     _meshnormals.Clear();
     _meshuvs.Clear();
     _meshtriangles.Clear();
     _mesh.Clear();
     _mesh.UploadMeshData(false);
     _primarylist.Clear();
     _secondarylist.Clear();
     _primarytset.Clear();
     _secondarytset.Clear();
     _display.Enable();
     //mark dirty for update and repaint
     _update_mesh  = true;
     _render_mesh  = true;
     _repaint_menu = true;
 }
Example #21
0
 public override void Disable()
 {
     _vertexmode = VertexMode.None;
     _previewutility.Cleanup();
     _previewutility = null;
     _previewblock.Clear();
     _meshvertex.Clear();
     _meshnormals.Clear();
     _meshuvs.Clear();
     _meshtriangles.Clear();
     _mesh.Clear();
     _mesh.UploadMeshData(false);
     _primarylist.Clear();
     _secondarylist.Clear();
     _primarytset.Clear();
     _secondarytset.Clear();
     _display.Disable();
     _update_mesh  = false;
     _render_mesh  = false;
     _repaint_menu = false;
 }
Example #22
0
        private static BeginMode GetOpenTKVertexMode(VertexMode mode)
        {
            switch (mode)
            {
            default:
            case VertexMode.Points: return(BeginMode.Points);

            case VertexMode.Lines: return(BeginMode.Lines);

            case VertexMode.LineStrip: return(BeginMode.LineStrip);

            case VertexMode.LineLoop: return(BeginMode.LineLoop);

            case VertexMode.Quads:
            case VertexMode.Triangles: return(BeginMode.Triangles);

            case VertexMode.TriangleStrip: return(BeginMode.TriangleStrip);

            case VertexMode.TriangleFan: return(BeginMode.TriangleFan);
            }
        }
Example #23
0
 public bool CanAppendJIT <U>(float invZSortAccuracy, float zSortIndex, BatchInfo material, VertexMode vertexMode) where U : struct, IVertexData
 {
     if (invZSortAccuracy > 0.0f && this.material.Technique.Res.NeedsZSort)
     {
         if (Math.Abs(zSortIndex - this.ZSortIndex) > invZSortAccuracy)
         {
             return(false);
         }
     }
     return
         (vertexMode == this.vertexMode &&
          this is DrawBatch <U> &&
          IsVertexModeAppendable(this.VertexMode) &&
          material == this.material);
 }
Example #24
0
        public void DataToVBO(Vertex[] verts, int[] indices)
        {
            vertexFlags = VertexMode.UV1; // normaalit + uv

            AllocVBO(verts.Length, indices.Length);

            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID);
            GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)0, (IntPtr)(verts.Length * vertexSize), verts);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID);
            GL.BufferSubData(BufferTarget.ElementArrayBuffer, (IntPtr)0, (IntPtr)(indices.Length * sizeof(int)), indices);

            Util.CheckGLError("VBO");
        }
Example #25
0
 /// <summary>
 /// Performs a preprocessing operation for incoming vertices. Does nothing by default but may be overloaded, if needed.
 /// </summary>
 /// <typeparam name="T">The incoming vertex type</typeparam>
 /// <param name="device"></param>
 /// <param name="material"><see cref="Duality.Resources.Material"/> information for the current batch.</param>
 /// <param name="vertexMode">The mode of incoming vertex data.</param>
 /// <param name="vertexBuffer">A buffer storing incoming vertex data.</param>
 /// <param name="vertexCount">The number of vertices to preprocess, beginning at the start of the specified buffer.</param>
 public virtual void PreprocessBatch <T>(IDrawDevice device, BatchInfo material, ref VertexMode vertexMode, ref T[] vertexBuffer, ref int vertexCount)
 {
 }
Example #26
0
File: VBO.cs Project: bosoni/csat
        public void DataToVBO(Vertex[] vertices, ushort[] indices, VertexMode mode)
        {
            if (numOfIndices > 0) Dispose();
            int size;
            vertexFlags = mode;
            numOfIndices = indices.Length;
            Vertex.Size = BlittableValueType.StrideOf(vertices);

            GL.GenBuffers(1, out vertexID);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID);
            GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * Vertex.Size), vertices, usage);
            GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size);
            if (vertices.Length * BlittableValueType.StrideOf(vertices) != size) Log.Error("DataToVBO: Vertex data not uploaded correctly");

            GL.GenBuffers(1, out indexID);
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID);
            GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(ushort)), indices, usage);
            GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size);
            if (indices.Length * sizeof(short) != size) throw new ApplicationException("DataToVBO: Element data not uploaded correctly");

            Shader = GLSLShader.Load();

            if (Shader != null)
            {
                if (Settings.UseGL3)
                {
                    GL.GenVertexArrays(1, out vaoID);
                    GL.BindVertexArray(vaoID);
                }
                GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID);
                GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID);
                Shader.SetAttributes();
                if (Settings.UseGL3) GL.BindVertexArray(0);
            }

            GLExt.CheckGLError("DataToVBO");
        }
Example #27
0
 /// <summary>
 /// Adds a parameterized set of vertices to the drawing devices rendering schedule.
 /// </summary>
 /// <typeparam name="T">The type of vertex data to add.</typeparam>
 /// <param name="device"></param>
 /// <param name="material">The <see cref="Duality.Drawing.BatchInfo"/> to use for rendering the vertices.</param>
 /// <param name="vertexMode">The vertices drawing mode.</param>
 /// <param name="vertices">
 /// A vertex data buffer that stores the vertices to add. Ownership of the buffer
 /// remains at the callsite, while the <see cref="IDrawDevice"/> copies the required
 /// data into internal storage.
 /// </param>
 public static void AddVertices <T>(this IDrawDevice device, BatchInfo material, VertexMode vertexMode, params T[] vertices) where T : struct, IVertexData
 {
     device.AddVertices <T>(
         material,
         vertexMode,
         vertices,
         vertices.Length);
 }
Example #28
0
 public void AddVertices <T>(ContentRef <Material> material, VertexMode vertexMode, params T[] vertices) where T : struct, IVertexData
 {
     this.AddVertices <T>(material.IsAvailable ? material.Res.InfoDirect : Material.Checkerboard.Res.InfoDirect, vertexMode, vertices, vertices.Length);
 }
Example #29
0
        /// <summary>
        /// kopioi objekti vbo:hon.
        /// jos käytetään uvs (tai +uvs2) tai colors, normals pitää myös löytyä.
        /// </summary>
        /// <param name="vertices"></param>
        /// <param name="indices"></param>
        /// <param name="normals"></param>
        /// <param name="uvs"></param>
        public void DataToVBO(Vector3[] vertices, int[] indices, Vector3[] normals, Vector2[] uvs, Vector2[] uvs2, Vector2[] colors)
        {
            Vertex[] verts = new Vertex[vertices.Length];

            if (normals != null) vertexFlags = VertexMode.Normal;
            if (uvs != null) vertexFlags = VertexMode.UV1;
            if (uvs2 != null) vertexFlags = VertexMode.UV2;
            if (colors != null) vertexFlags = VertexMode.Color;

            // koppaa vertex infot Vertexiin
            switch (vertexFlags)
            {
                case VertexMode.OnlyVertex:
                    for (int q = 0; q < vertices.Length; q++)
                    {
                        verts[q] = new Vertex(vertices[q]);
                    }
                    break;

                case VertexMode.Normal:
                    for (int q = 0; q < vertices.Length; q++)
                    {
                        verts[q] = new Vertex(vertices[q], normals[q]);
                    }
                    break;

                case VertexMode.UV1:
                    for (int q = 0; q < vertices.Length; q++)
                    {
                        verts[q] = new Vertex(vertices[q], normals[q], uvs[q]);
                    }
                    break;

                case VertexMode.UV2:
                    for (int q = 0; q < vertices.Length; q++)
                    {
                        verts[q] = new Vertex(vertices[q], normals[q], uvs[q], uvs2[q]);
                    }
                    break;

                case VertexMode.Color:
                    for (int q = 0; q < vertices.Length; q++)
                    {
                        verts[q] = new Vertex(vertices[q], normals[q], colors[q]);
                    }
                    break;

            }

            AllocVBO(verts.Length, indices.Length);

            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID);
            GL.BufferSubData(BufferTarget.ArrayBuffer, (IntPtr)0, (IntPtr)(verts.Length * vertexSize), verts);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID);
            GL.BufferSubData(BufferTarget.ElementArrayBuffer, (IntPtr)0, (IntPtr)(indices.Length * sizeof(int)), indices);

            Util.CheckGLError("VBO");
        }
Example #30
0
 public void AddVertices <T>(ContentRef <Material> material, VertexMode vertexMode, T[] vertexBuffer, int vertexCount) where T : struct, IVertexData
 {
     this.AddVertices <T>(material.IsAvailable ? material.Res.InfoDirect : Material.Checkerboard.Res.InfoDirect, vertexMode, vertexBuffer, vertexCount);
 }
Example #31
0
 public void AddVertices <T>(BatchInfo material, VertexMode vertexMode, params T[] vertices) where T : struct, IVertexData
 {
     this.AddVertices <T>(material, vertexMode, vertices, vertices.Length);
 }
Example #32
0
 /// <summary>
 /// Adds a parameterized set of vertices to the drawing devices rendering schedule.
 /// </summary>
 /// <typeparam name="T">The type of vertex data to add.</typeparam>
 /// <param name="device"></param>
 /// <param name="material">The <see cref="Duality.Resources.Material"/> to use for rendering the vertices.</param>
 /// <param name="vertexMode">The vertices drawing mode.</param>
 /// <param name="vertexBuffer">
 /// A vertex data buffer that stores the vertices to add. Ownership of the buffer
 /// remains at the callsite, while the <see cref="IDrawDevice"/> copies the required
 /// data into internal storage.
 /// </param>
 /// <param name="vertexCount">The number of vertices to add, from the beginning of the buffer.</param>
 public static void AddVertices <T>(this IDrawDevice device, ContentRef <Material> material, VertexMode vertexMode, T[] vertexBuffer, int vertexCount) where T : struct, IVertexData
 {
     device.AddVertices <T>(
         material.IsAvailable ? material.Res.Info : Material.Checkerboard.Res.Info,
         vertexMode,
         vertexBuffer,
         vertexCount);
 }
Example #33
0
        //public void OnDestroy(){this.OnDisable();}
        //==================
        // Interface
        //==================
        public void OnGUI()
        {
            EditorUI.Reset();
            EditorUI.SetFieldSize(-1, 175, false);
            var width        = (Screen.width * 0.25f).Clamp(100, 250).ToInt();
            var mergeStyle   = EditorStyles.miniButtonLeft.FixedHeight(0);
            var flattenStyle = EditorStyles.miniButtonRight.FixedHeight(0);

            if (this.operationMode == OperationMode.Merge)
            {
                mergeStyle = mergeStyle.UseState("onNormal", "*");
            }
            if (this.operationMode == OperationMode.Flatten)
            {
                flattenStyle = flattenStyle.UseState("onNormal", "*");
            }
            EditorGUILayout.BeginVertical(new GUIStyle().Margin(8, 8, 15, 8));
            EditorGUILayout.BeginHorizontal(new GUIStyle().Margin(0, 0, 0, 10).Center(width * 2));
            if ("Merge".ToLabel().Layout(width, 20).DrawButton(mergeStyle))
            {
                this.operationMode = OperationMode.Merge;
            }
            if ("Flatten".ToLabel().Layout(width, 20).DrawButton(flattenStyle))
            {
                this.operationMode = OperationMode.Flatten;
            }
            EditorGUILayout.EndHorizontal();
            if (this.operationMode.Has("Merge"))
            {
                EditorWindowExtensions.SetTitle(this, "Mesh");
                //"Vertex".DrawLabel(EditorStyles.boldLabel);
                this.vertexMode          = this.vertexMode.Draw("Vertex Mode").As <VertexMode>();
                this.vertexDisplay       = this.vertexDisplay.DrawMask("Vertex Display").As <VertexDisplay>();
                this.vertexColor         = this.vertexColor.Draw("Vertex Color");
                this.vertexDistanceColor = this.vertexDistanceColor.Draw("Vertex Distance Color");
                this.vertexOverlapColor  = this.vertexOverlapColor.Draw("Vertex Overlap Color");
                this.distance            = this.distance.DrawSlider(0, 1f, "Vertex Overlap Distance");
                this.size          = this.size.DrawSlider(0, 1, "Vertex Size");
                this.scaleFactor   = this.scaleFactor.DrawSlider(1, 10, "Vertex Display Scale");
                this.scale         = (0.0625f * Mathf.Pow(2, this.scaleFactor - 1));
                this.alwaysDisplay = this.alwaysDisplay.Draw("Always Display");
                var lockText = this.lockSelection ? "Unlock Selection" : "Lock Selection";
                GUI.enabled = this.lockSelection || this.cached.Count > 0;
                if (lockText.ToLabel().Layout(150, 25).DrawButton() && (this.lockSelection || this.cached.Count > 0))
                {
                    this.lockSelection = !this.lockSelection;
                }
                GUI.enabled = true;
            }
            else if (this.operationMode.Has("Flatten"))
            {
            }
            if (EditorUI.anyChanged)
            {
                ProxyEditor.RegisterUndo(this, "Mesh Operation Changes");
                this.Repaint();
                this.RefreshSceneView();
            }
            EditorGUILayout.EndVertical();
            this.visible = true;
        }