Example #1
0
        private TextureId ExportTexture(UnityEngine.Texture textureObj)
        {
            TextureId id = GetTextureId(_root, textureObj);

            if (id != null)
            {
                return(id);
            }

            var texture = new GLTF.Schema.Texture();

            if (ExportNames)
            {
                texture.Name = textureObj.name;
            }

            texture.Source  = ExportImage(textureObj);
            texture.Sampler = ExportSampler(textureObj);

            _textures.Add(textureObj);

            id = new TextureId {
                Id   = _root.Textures.Count,
                Root = _root
            };

            _root.Textures.Add(texture);

            return(id);
        }
Example #2
0
        private async Task LoadTexture(TextureId textureId)
        {
            try
            {
                _textures[textureId.Id].LoadState = LoadState.Loading;

                var data = await TextureLoader.Load(textureId.Name);

                if (data == null)
                {
                    await LoadTexture(TextureId.Missing);

                    _textures[textureId.Id].Slice     = _textures[TextureId.Missing.Id].Slice;
                    _textures[textureId.Id].LoadState = LoadState.Missing;
                    return;
                }

                _textures[textureId.Id].Slice     = CreateTexture(data);
                _textures[textureId.Id].LoadState = LoadState.Loaded;
            }
            catch
            {
                await LoadTexture(TextureId.Error);

                _textures[textureId.Id].Slice     = _textures[TextureId.Error.Id].Slice;
                _textures[textureId.Id].LoadState = LoadState.Failed;
            }
        }
        private async Task LoadTexture(TextureId textureId)
        {
            try
            {
                textures[textureId.Id].LoadState = LoadState.Loading;

                var data = await loader.Load(textureId.Name);
                if (data == null)
                {
                    await LoadTexture(TextureId.Missing);
                    textures[textureId.Id].Slice = textures[TextureId.Missing.Id].Slice;
                    textures[textureId.Id].LoadState = LoadState.Missing;
                    return;
                }

                textures[textureId.Id].Slice = PlatformCreateTexture(data);
                textures[textureId.Id].LoadState = LoadState.Loaded;
            }
            catch
            {
                await LoadTexture(TextureId.Error);
                textures[textureId.Id].Slice = textures[TextureId.Error.Id].Slice;
                textures[textureId.Id].LoadState = LoadState.Failed;
            }
        }
Example #4
0
 public void Reset()
 {
     origIndex = 0;
     destIndex = 0;
     location  = new RectInt();
     atlas     = TextureId.invalid;
 }
Example #5
0
        public Texture <T> GetTexture(TextureId textureId)
        {
            if (textureId.Id <= 0)
            {
                return(null);
            }

            if (_textures.Length <= textureId.Id)
            {
                Array.Resize(ref _textures, MathHelper.NextPowerOfTwo(TextureId.Count));
            }

            var entry = _textures[textureId.Id];

            if (entry.LoadState == LoadState.None)
            {
                LoadTexture(textureId);

                // Ensures the method returns a valid result when the
                // async load method succeeded synchroniously.
                entry = _textures[textureId.Id];
            }

            return(entry.LoadState != LoadState.None ? entry.Slice : null);
        }
        public MeshWriteData AddGradientsEntry(int vertexCount, int indexCount, TextureId texture, Material material, MeshGenerationContext.MeshFlags flags)
        {
            var mwd = GetPooledMeshWriteData();

            if (vertexCount == 0 || indexCount == 0)
            {
                mwd.Reset(new NativeSlice <Vertex>(), new NativeSlice <ushort>());
                return(mwd);
            }

            m_CurrentEntry = new Entry()
            {
                vertices         = m_VertsPool.Alloc((uint)vertexCount),
                indices          = m_IndicesPool.Alloc((uint)indexCount),
                material         = material,
                texture          = texture,
                clipRectID       = m_ClipRectID,
                isStencilClipped = m_StencilClip,
                addFlags         = VertexFlags.IsSvgGradients
            };

            Debug.Assert(m_CurrentEntry.vertices.Length == vertexCount);
            Debug.Assert(m_CurrentEntry.indices.Length == indexCount);

            mwd.Reset(m_CurrentEntry.vertices, m_CurrentEntry.indices, new Rect(0, 0, 1, 1));
            m_Entries.Add(m_CurrentEntry);
            totalVertices += m_CurrentEntry.vertices.Length;
            totalIndices  += m_CurrentEntry.indices.Length;
            m_CurrentEntry = new Entry();
            return(mwd);
        }
 public string GetString()
 {
     if (TextureId == 0 && NormalId == 0)
     {
         return($" {VertexId}");
     }
     return($" {VertexId}/{(TextureId != 0 ? TextureId.ToString() : "")}/{(NormalId != 0 ? NormalId.ToString() : "")}");
 }
Example #8
0
 public GameObjectState(TextureId textureId, ulong id, Coord pos, short angle, Size size)
 {
     TextureId = textureId;
     Id        = id;
     Pos       = pos;
     Angle     = angle;
     Size      = size;
 }
Example #9
0
        public void SetGpuData(int slotIndex, TextureId id, int textureWidth, int textureHeight, float sdfScale)
        {
            int   offset      = slotIndex * k_SlotSize;
            float texelWidth  = 1f / textureWidth;
            float texelHeight = 1f / textureHeight;

            m_GpuTextures[offset + 0] = new Vector4(id.ConvertToGpu(), texelWidth, texelHeight, sdfScale);
            m_GpuTextures[offset + 1] = new Vector4(textureWidth, textureHeight, 0, 0);
        }
Example #10
0
        public void AppendTexture(VisualElement ve, Texture src, TextureId id, bool isAtlas)
        {
            BasicNode <TextureEntry> node = m_TexturePool.Get();

            node.data.source   = src;
            node.data.actual   = id;
            node.data.replaced = isAtlas;
            node.AppendTo(ref ve.renderChainData.textures);
        }
            public override int GetHashCode()
            {
                int hashCode = 1910803454;

                hashCode = hashCode * -1521134295 + TextureId.GetHashCode();
                hashCode = hashCode * -1521134295 + WrapS.GetHashCode();
                hashCode = hashCode * -1521134295 + WrapT.GetHashCode();
                return(hashCode);
            }
Example #12
0
        public void Bind(TextureId id, int slot, MaterialPropertyBlock mat)
        {
            Texture tex = textureRegistry.GetTexture(id);

            m_Textures[slot] = id;
            MarkUsed(slot);
            m_GpuTextures[slot] = new Vector4(id.ConvertToGpu(), 1f / tex.width, 1f / tex.height, 0);
            mat.SetTexture(slotIds[slot], tex);
            mat.SetVectorArray(textureTableId, m_GpuTextures);
        }
Example #13
0
        // Returns the slot to which the texture is currently bound to.
        public int IndexOf(TextureId id)
        {
            for (int i = 0; i < k_SlotCount; ++i)
            {
                if (m_Textures[i].index == id.index)
                {
                    return(i);
                }
            }

            return(-1);
        }
Example #14
0
 public bool RecordFrame(RenderTexture texture)
 {
     if (recorder == null)
     {
         return(false);
     }
     using (var textureId = TextureId.fromInt(texture.GetNativeTexturePtr().ToInt32()))
     {
         recorder.updateFrame(textureId, texture.width, texture.height);
     }
     return(true);
 }
Example #15
0
        public override int GetHashCode()
        {
            int hash = 0;

            hash = (hash * 397) ^ TextureId.GetHashCode();

            if (PaletteChanges != null)
            {
                hash = (hash * 397) ^ PaletteChanges.GetHashCode();
            }

            return(hash);
        }
Example #16
0
        public void Bind(TextureId id, float sdfScale, int slot, MaterialPropertyBlock mat)
        {
            Texture tex = textureRegistry.GetTexture(id);

            if (tex == null) // Case 1364578: Texture may have been destroyed
            {
                tex = Texture2D.whiteTexture;
            }

            m_Textures[slot] = id;
            MarkUsed(slot);
            SetGpuData(slot, id, tex.width, tex.height, sdfScale);
            mat.SetTexture(slotIds[slot], tex);
            mat.SetVectorArray(textureTableId, m_GpuTextures);
        }
Example #17
0
 public Sprite(
     TextureId texture,
     Vector2 position = default(Vector2),
     Vector2? scale = null,
     Vector2? size = null,
     float rotation = 0,
     Vector2 origin = default(Vector2),
     Color? color = null)
 {
     this.Texture = texture;
     this.Position = position;
     this.Scale = scale ?? Vector2.One;
     this.Rotation = rotation;
     this.Size = size ?? Vector2.Zero;
     this.Origin = origin;
     this.Color = color ?? Color.White;
 }
        public MeshWriteData DrawMesh(int vertexCount, int indexCount, Texture texture, Material material, MeshGenerationContext.MeshFlags flags)
        {
            var mwd = GetPooledMeshWriteData();

            if (vertexCount == 0 || indexCount == 0)
            {
                mwd.Reset(new NativeSlice <Vertex>(), new NativeSlice <ushort>());
                return(mwd);
            }

            m_CurrentEntry = new Entry()
            {
                vertices         = m_VertsPool.Alloc(vertexCount),
                indices          = m_IndicesPool.Alloc(indexCount),
                material         = material,
                uvIsDisplacement = (flags & MeshGenerationContext.MeshFlags.UVisDisplacement) == MeshGenerationContext.MeshFlags.UVisDisplacement,
                clipRectID       = m_ClipRectID,
                stencilRef       = m_StencilRef,
                maskDepth        = m_MaskDepth,
                addFlags         = VertexFlags.IsSolid
            };

            Debug.Assert(m_CurrentEntry.vertices.Length == vertexCount);
            Debug.Assert(m_CurrentEntry.indices.Length == indexCount);

            Rect uvRegion = new Rect(0, 0, 1, 1);

            if (texture != null)
            {
                // Attempt to override with an atlas.
                if (!((flags & MeshGenerationContext.MeshFlags.SkipDynamicAtlas) == MeshGenerationContext.MeshFlags.SkipDynamicAtlas) && m_Atlas != null && m_Atlas.TryGetAtlas(currentElement, texture as Texture2D, out TextureId atlas, out RectInt atlasRect))
                {
                    m_CurrentEntry.addFlags = VertexFlags.IsDynamic;
                    uvRegion = new Rect(atlasRect.x, atlasRect.y, atlasRect.width, atlasRect.height);
                    m_CurrentEntry.texture = atlas;
                    m_Owner.AppendTexture(currentElement, texture, atlas, true);
                }
                else
                {
                    TextureId id = TextureRegistry.instance.Acquire(texture);
                    m_CurrentEntry.addFlags = VertexFlags.IsTextured;
                    m_CurrentEntry.texture  = id;
                    m_Owner.AppendTexture(currentElement, texture, id, false);
                }
            }
Example #19
0
 private void ReadBinaryData(FileReader reader)
 {
     Width      = reader.ReadUInt16();
     Height     = reader.ReadUInt16();
     unknown1   = reader.ReadUInt32();
     CompSel    = reader.ReadUInt32();
     MipCount   = reader.ReadUInt32();
     unknown2   = reader.ReadUInt32();
     TileMode   = reader.ReadUInt32();
     unknown3   = reader.ReadUInt32();
     ImageSize  = reader.ReadUInt32();
     unknown4   = reader.ReadUInt32();
     TextureId  = reader.ReadUInt32();
     Text       = TextureId.ToString("X8");
     SurfFormat = reader.ReadEnum <SurfaceFormat>(false);
     unknown5   = reader.ReadByte();
     unknown6   = reader.ReadInt16();
     unknown7   = reader.ReadUInt32();
 }
        public static void AddSolidRectangle(this DynamicPrimitive dynamicPrimitive, Vector2 min, Vector2 max, Color color, TextureId? texture = null, Matrix4x4? world = null)
        {
            dynamicPrimitive.BeginPrimitive(PrimitiveType.Triangles, texture, world);
            {
                dynamicPrimitive.AddVertex(new Vector3(min.X, min.Y, 0), color, new Vector2(0, 0));
                dynamicPrimitive.AddVertex(new Vector3(min.X, max.Y, 0), color, new Vector2(0, 1));
                dynamicPrimitive.AddVertex(new Vector3(max.X, max.Y, 0), color, new Vector2(1, 1));
                dynamicPrimitive.AddVertex(new Vector3(max.X, min.Y, 0), color, new Vector2(1, 0));

                dynamicPrimitive.AddIndex(0);
                dynamicPrimitive.AddIndex(1);
                dynamicPrimitive.AddIndex(2);

                dynamicPrimitive.AddIndex(2);
                dynamicPrimitive.AddIndex(3);
                dynamicPrimitive.AddIndex(0);
            }
            dynamicPrimitive.EndPrimitive();
        }
        public Texture GetTexture(TextureId textureId)
        {
            if (textureId.Id <= 0) return null;

            if (textures.Length <= textureId.Id)
            {
                Array.Resize(ref textures, MathHelper.NextPowerOfTwo(TextureId.Count));
            }

            var entry = textures[textureId.Id];
            if (entry.LoadState == LoadState.None)
            {
                LoadTexture(textureId);

                // Ensures the method returns a valid result when the
                // async load method succeeded synchroniously.
                entry = textures[textureId.Id];
            }

            return entry.LoadState != LoadState.None ? entry.Slice : null;
        }
        public void BeginPrimitive(PrimitiveType primitiveType, TextureId? texture, Matrix4x4? world = null, float lineWidth = 1)
        {
            if (hasPrimitiveBegin)
                throw new InvalidOperationException("Begin cannot be called until End has been successfully called.");

            hasPrimitiveBegin = true;

            currentPrimitive = new PrimitiveGroupEntry();
            currentPrimitive.LineWidth = lineWidth;
            currentPrimitive.World = world;
            currentPrimitive.PrimitiveType = primitiveType;
            currentPrimitive.Texture = texture;
            currentPrimitive.StartVertex = currentVertex;
            currentPrimitive.StartIndex = currentIndex;

            currentBaseVertex = currentVertex;
            currentBaseIndex = currentIndex;

            beginSegment = currentSegment;

            isDirty = true;
        }
        private TextureId ExportTexture(UnityEngine.Texture textureObj)
        {
            TextureId id = GetTextureId(_root, textureObj);

            if (id != null)
            {
                return(id);
            }

            var texture = new GLTF.Schema.Texture();

            //If texture name not set give it a unique name using count
            if (textureObj.name == "")
            {
                textureObj.name = (_root.Textures.Count + 1).ToString();
            }

            if (ExportNames)
            {
                texture.Name = textureObj.name;
            }

            texture.Source  = ExportImage(textureObj);
            texture.Sampler = ExportSampler(textureObj);

            _textures.Add(textureObj);

            id = new TextureId {
                Id   = _root.Textures.Count,
                Root = _root
            };

            _root.Textures.Add(texture);

            return(id);
        }
        }                                                                                         // 0x01624E10-0x01624F50

        public void DrawRectSetDirectPriority(TextureId texId, int x, int y, int s, int t, int w, int h, Color32 color, int nPriority, bool vf = false /* Metadata: 0x00614705 */, bool hf = false /* Metadata: 0x00614706 */)
        {
        }                                                                                                                                                                                                                                 // 0x01624F50-0x01624F70
Example #25
0
        }                                                                                         // 0x00B0A9B0-0x00B0A9C0

        public void DrawRect(TextureId texId, int x, int y, int s, int t, int w, int h, Color32 color, int nPriority, bool vf = false /* Metadata: 0x00613F63 */, bool hf = false /* Metadata: 0x00613F64 */)
        {
        }                                                                                                                                                                                                                // 0x00B0A8F0-0x00B0A930
Example #26
0
        }                                                                                                                                                                                                                // 0x00B0A8F0-0x00B0A930

        public void DrawRectZoom(TextureId texId, int x, int y, int w, int h, int s, int t, int sw, int th, Color32 color, int nPriority)
        {
        }                                                // 0x00B0A930-0x00B0A980
        // TODO: Add with Nine.Geometry
        //public static void AddSolidRectangle(this DynamicPrimitive dynamicPrimitive, BoundingRectangle rectangle, Color color, TextureId? texture = null, Matrix4x4? world = null)
        //    => AddSolidRectangle(dynamicPrimitive, new Vector2(rectangle.Left, rectangle.Top), new Vector2(rectangle.Right, rectangle.Bottom), color, texture, world);

        public static void AddSolidRectangle(this DynamicPrimitive dynamicPrimitive, Rectangle rectangle, Color color, TextureId? texture = null, Matrix4x4? world = null)
            => AddSolidRectangle(dynamicPrimitive, new Vector2(rectangle.Left, rectangle.Top), new Vector2(rectangle.Right, rectangle.Bottom), color, texture, world);
Example #28
0
        public Cheetah.TextureId CreateCompressedCubeTexture(byte[] xpos, byte[] xneg, byte[] ypos, byte[] yneg, byte[] zpos, byte[] zneg, TextureFormat codec, int w, int h)
        {
            if(!supports_compressed_textures)
                throw new Exception("compressed textures not supported.");

            PixelInternalFormat format;
            switch (codec)
            {
                case TextureFormat.DXT1:
                    format = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
                    break;
                case TextureFormat.DXT2:
                    throw new Exception();
                case TextureFormat.DXT3:
                    format = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext;
                    break;
                case TextureFormat.DXT4:
                    throw new Exception();
                case TextureFormat.DXT5:
                    format = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
                    break;
                default:
                    throw new Exception();
            }

            int[] i = new int[1];
            CheckError();

            GL.GenTextures(1, i);
            CheckError();

            TextureId t = new TextureId(i[0], this, w, h, false, true);

            GL.BindTexture(TextureTarget.TextureCubeMap, t.id);
            CheckError();
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            CheckError();

            GL.CompressedTexImage2D<byte>(TextureTarget.TextureCubeMapPositiveX, 0, format, w, h, 0, xpos.Length, xpos);
            CheckError();
            GL.CompressedTexImage2D<byte>(TextureTarget.TextureCubeMapNegativeX, 0, format, w, h, 0, xneg.Length, xneg);
            CheckError();
            GL.CompressedTexImage2D<byte>(TextureTarget.TextureCubeMapPositiveY, 0, format, w, h, 0, ypos.Length, ypos);
            CheckError();
            GL.CompressedTexImage2D<byte>(TextureTarget.TextureCubeMapNegativeY, 0, format, w, h, 0, yneg.Length, yneg);
            CheckError();
            GL.CompressedTexImage2D<byte>(TextureTarget.TextureCubeMapPositiveZ, 0, format, w, h, 0, zpos.Length, zpos);
            CheckError();
            GL.CompressedTexImage2D<byte>(TextureTarget.TextureCubeMapNegativeZ, 0, format, w, h, 0, zneg.Length, zneg);
            CheckError();

            Textures[t.id] = t;

            return t;
        }
Example #29
0
        public Cheetah.TextureId CreateTexture(byte[] rgba, int w, int h, bool alpha)
        {
            CheckError();
            bool mipmap = IsPowerOf2(w) && IsPowerOf2(h);
            //if (!(IsPowerOf2(w) && IsPowerOf2(h)))
            //	throw new Exception("Texture sizes must be n^2.");
            int[] i = new int[1];
            byte[] data = rgba;
            GL.GenTextures(1, i);
            //if(GL.IsTexture(i[0])!=GL._TRUE)
            //	throw new Exception("OpenGL.CreateTexture: glGenTextures failed.");
            CheckError();

            TextureId t = new TextureId(i[0], this, w, h, alpha, false);
            t.LastBind = Root.Instance.Time;

            GL.BindTexture(TextureTarget.Texture2D, t.id);
            CheckError();

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            CheckError();
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);
            CheckError();

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            CheckError();

            if (mipmap)
            {
                if (!can_generate_mipmaps)
                {
                    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.GenerateMipmap, 1);
                    CheckError();
                }
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
            }
            else
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);

            CheckError();

            if (alpha)
            {
                GL.TexImage2D<byte>(TextureTarget.Texture2D, 0, PixelInternalFormat.Four, w, h, 0, global::OpenTK.Graphics.OpenGL.PixelFormat.Rgba, PixelType.UnsignedByte, data);
                CheckError();
            }
            else
            {
                GL.TexImage2D<byte>(TextureTarget.Texture2D, 0, PixelInternalFormat.Three, w, h, 0, global::OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedByte, data);
                CheckError();
            }

            if (can_generate_mipmaps && mipmap)
            {
                GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);
                CheckError();
            }
            //t.Width=w;
            //t.height=h;
            Textures[t.id] = t;

            return t;
        }
        private WindowUGuiGraphic GetOrAddUGuiObject_(UGuiObjKey_ key) => default; // 0x016242C0-0x01624940

        public void DrawRect(TextureId texId, int x, int y, int s, int t, int w, int h, Color32 color, int nPriority, bool vf = false /* Metadata: 0x00614700 */, bool hf = false /* Metadata: 0x00614701 */)
        {
        }                                                                                                                                                                                                                // 0x01624940-0x01624BA0
Example #31
0
        public Cheetah.TextureId CreateCubeTexture(byte[] xpos,byte[] xneg,byte[] ypos,byte[] yneg,byte[] zpos,byte[] zneg, 
            int w, int h)
        {
            CheckError();
            int[] i = new int[1];

            GL.GenTextures(1, i);

            TextureId t = new TextureId(i[0], this, w, h, false, true);

            GL.BindTexture(TextureTarget.TextureCubeMap, t.id);
            CheckError();

            //GL.TexParameterf(GL._TEXTURE_CUBE_MAP, TextureParameterName.TextureWrapS, GL._REPEAT);
            //GL.TexParameterf(GL._TEXTURE_CUBE_MAP, TextureParameterName.TextureWrapT, GL._REPEAT);

            //GL.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, GL._CLAMP_TO_EDGE);
            //GL.TexParameteri(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, GL._CLAMP_TO_EDGE);

            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            CheckError();

            GL.TexImage2D<byte>(TextureTarget.TextureCubeMapPositiveX, 0, PixelInternalFormat.Three, w, h, 0, global::OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedByte, xpos);
            CheckError();
            GL.TexImage2D<byte>(TextureTarget.TextureCubeMapNegativeX, 0, PixelInternalFormat.Three, w, h, 0, global::OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedByte, xneg);
            CheckError();
            GL.TexImage2D<byte>(TextureTarget.TextureCubeMapPositiveY, 0, PixelInternalFormat.Three, w, h, 0, global::OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedByte, ypos);
            CheckError();
            GL.TexImage2D<byte>(TextureTarget.TextureCubeMapNegativeY, 0, PixelInternalFormat.Three, w, h, 0, global::OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedByte, yneg);
            CheckError();
            GL.TexImage2D<byte>(TextureTarget.TextureCubeMapPositiveZ, 0, PixelInternalFormat.Three, w, h, 0, global::OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedByte, zpos);
            CheckError();
            GL.TexImage2D<byte>(TextureTarget.TextureCubeMapNegativeZ, 0, PixelInternalFormat.Three, w, h, 0, global::OpenTK.Graphics.OpenGL.PixelFormat.Rgb, PixelType.UnsignedByte, zneg);

            Textures[t.id] = t;

            CheckError();
            return t;
        }
Example #32
0
        public Cheetah.TextureId CreateTexture(int w, int h, bool alpha, bool depth)
        {
            CheckError();
            bool mipmap = IsPowerOf2(w) && IsPowerOf2(h);
            //if (!(IsPowerOf2(w) && IsPowerOf2(h)))
            //	throw new Exception("Texture sizes must be n^2.");
            int[] i = new int[1];
            //byte[] data = rgba;
            GL.GenTextures(1, i);
            //if(GL.IsTexture(i[0])!=GL._TRUE)
            //	throw new Exception("OpenGL.CreateTexture: glGenTextures failed.");

            TextureId t = new TextureId(i[0], this, w, h, alpha, false);
            t.LastBind = Root.Instance.Time;

            GL.BindTexture(TextureTarget.Texture2D, t.id);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToEdge);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToEdge);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            if (mipmap)
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
            else
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);

            if (depth)
                GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent, w, h, 0, global::OpenTK.Graphics.OpenGL.PixelFormat.DepthComponent, PixelType.UnsignedShort, IntPtr.Zero);
            else
                //GL.TexImage2D(TextureTarget.Texture2D, 0, GL._COLOR, w, h, 0, GL._DEPTH_COMPONENT, GL._UNSIGNED_SHORT, IntPtr.Zero);
                throw new Exception();

            //t.Width=w;
            //t.height=h;
            Textures[t.id] = t;
            CheckError();

            return t;
        }
Example #33
0
        public virtual bool Inspect()
        {
            if (!PainterCamera.Inst)
            {
                "No Painter Camera found".writeWarning();

                if ("Refresh".Click())
                {
                    PainterSystem.applicationIsQuitting = false;
                }

                return(false);
            }


            ("Works with PaintWithoutComponent script. This lets you configure how painting will be received." +
             " PaintWithoutComponent.cs is usually attached to a main camera (if painting in first person). Current Texture: " + TextureId.ToString())
            .fullWindowDocumentationClickOpen("About Painting Receiver");

            var changes = false;

            if (icon.Refresh.Click("Find Components automatically"))
            {
                Refresh();
            }

            if ("Renderer GetBrushType:".editEnum(90, ref type).nl())
            {
                if (type == RendererType.Skinned && !skinnedMeshRenderer)
                {
                    skinnedMeshRenderer = GetComponentInChildren <SkinnedMeshRenderer>();
                }

                if (type == RendererType.Regular && !meshFilter)
                {
                    meshFilter   = GetComponent <MeshFilter>();
                    meshRenderer = GetComponent <MeshRenderer>();
                }
            }

            switch (type)
            {
            case RendererType.Skinned:
                "   Skinned Mesh Renderer".edit(90, ref skinnedMeshRenderer).nl(ref changes);
                break;

            case RendererType.Regular:
                "   Mesh Filter".edit(90, ref meshFilter).nl(ref changes);
                "   Renderer".edit(90, ref meshRenderer).nl(ref changes);
                break;
            }

            var r = Renderer;

            if ((r && r.sharedMaterials.Length > 1) || materialIndex != 0)
            {
                "   Material".select_Index(80, ref materialIndex, r.sharedMaterials).nl();
            }

            if (Material)
            {
                var lst = Material.MyGetTextureProperties_Editor();

                if ("   Property".select(80, ref _textureProperty, lst).nl())
                {
                    TexturePropertyName = _textureProperty.NameForDisplayPEGI();
                }
            }

            if (gameObject.isStatic && !originalMesh)
            {
                "For STATIC Game Objects original mesh is needed:".writeHint();

                pegi.nl();

                if (meshFilter && icon.Search.Click("Find mesh"))
                {
                    originalMesh = meshFilter.sharedMesh;
                }
            }

            if (gameObject.isStatic)
            {
                "  Original Mesh".edit("Static objects use Combined mesh, so original one will be needed for painting", 50, ref originalMesh).nl();
            }

            if ("  Use second texture coordinates".toggleIcon("If shader uses texcoord2 (Baked Light) to display damage, turn this ON.", ref useTexcoord2).nl() && texture)
            {
                texture.GetTextureMeta().useTexCoord2 = useTexcoord2;
            }

            if (Material)
            {
                if (!Material.Has(TextureId) && !Material.mainTexture)
                {
                    "No Material Property Selected and no MainTex on Material".nl();
                }
                else
                {
                    var current = Material.Get(TextureId);

                    if (current)
                    {
                    }


                    if (texture)
                    {
                        var t2D = texture as Texture2D;

                        if (t2D)
                        {
                            icon.Done.write();
                            "CPU brush will work if object has MeshCollider".nl();

                            if (originalTexture)
                            {
                                var ot2D = originalTexture as Texture2D;

                                if (ot2D)
                                {
                                    if ((ot2D.width == t2D.width) && (ot2D.height == t2D.height))
                                    {
                                        if (("Undo Changes".Click()).nl())
                                        {
                                            Restore();
                                        }
                                    }
                                    else
                                    {
                                        "Original and edited texture are not of the same size".nl();
                                    }
                                }
                                else
                                {
                                    "Original Texture is not a Texture 2D".nl();
                                }
                            }
                        }
                        else
                        {
                            if (Renderer)
                            {
                                icon.Done.write();
                                "Will paint if object has any collider".nl();
                                if (skinnedMeshRenderer)
                                {
                                    "Colliders should be placed close to actual mesh".nl();
                                    "Otherwise brush size may be too small to reach the mesh".nl();
                                }
                            }
                            else
                            {
                                "Render Texture Painting needs Skinned Mesh or Mesh Filter to work".nl();
                            }

                            if ((originalTexture) && ("Undo Changes".Click().nl()))
                            {
                                Restore();
                            }
                        }
                    }
                    else
                    {
                        var rtm = TexturesPool.inst;

                        if (rtm)
                        {
                            "Render Texture Pool will be used to get texture".nl();
                            if (!Renderer)
                            {
                                "! Renderer needs to be Assigned.".nl();
                            }
                            else
                            {
                                icon.Done.write();
                                "COMPONENT SET UP CORRECTLY".write();
                                if (fromRtManager && "Restore".Click())
                                {
                                    Restore();
                                }
                                pegi.nl();
                            }
                        }
                        else
                        {
                            "No Render Texture Pool found".write();
                            if ("Create".Click().nl())
                            {
                                (TexturesPool.GetOrCreateInstance.gameObject.name + " created").showNotificationIn3D_Views();
                            }
                        }
                    }
                }
            }
            else
            {
                "No material found".nl();
            }

            if ("Advanced".foldout(ref _showOptional).nl())
            {
                if (texture || !MatTex)
                {
                    "Start Texture:".edit("Copy of this texture will be modified.", 110, ref originalTexture).nl(ref changes);
                }

                "Target Texture".edit("If not using Render Textures Pool", 120, ref texture);
                if (Renderer && Material && "Find".Click().nl())
                {
                    texture = MatTex;
                }

                if (!texture || texture.GetType() == typeof(RenderTexture))
                {
                    "Mesh UV Offset".edit("Some Meshes have UV coordinates with displacement for some reason. " +
                                          "If your object doesn't use a mesh collider to provide a UV offset, this will be used.", 80, ref meshUvOffset).nl();
                    if (Mesh && "Offset from Mesh".Click().nl())
                    {
                        var firstVertInSubmeshIndex = Mesh.GetTriangles(materialIndex)[0];
                        meshUvOffset = useTexcoord2 ? Mesh.uv2[firstVertInSubmeshIndex] : Mesh.uv[firstVertInSubmeshIndex];

                        meshUvOffset = new Vector2((int)meshUvOffset.x, (int)meshUvOffset.y);

                        ("Mesh Offset is " + meshUvOffset.ToString()).showNotificationIn3D_Views();
                    }
                }
            }


            return(changes);
        }
        static RenderChainCommand InjectClosingMeshDrawCommand(RenderChain renderChain, VisualElement ve, ref RenderChainCommand cmdPrev, ref RenderChainCommand cmdNext, MeshHandle mesh, int indexCount, int indexOffset, Material material, TextureId texture, int stencilRef)
        {
            var cmd = renderChain.AllocCommand();

            cmd.type    = CommandType.Draw;
            cmd.closing = true;
            cmd.state   = new State {
                material = material, texture = texture, stencilRef = stencilRef
            };
            cmd.mesh        = mesh;
            cmd.indexOffset = indexOffset;
            cmd.indexCount  = indexCount;
            cmd.owner       = ve;
            InjectClosingCommandInBetween(renderChain, cmd, ref cmdPrev, ref cmdNext);
            return(cmd);
        }
Example #35
0
 public RenderTarget(int _id, TextureId tex)
 {
     id = _id;
     Texture = tex;
 }
        private TextureId GenerateTexture(Texture2D texture, ImageId imageId)
        {
            if (root.Textures == null)
            {
                root.Textures = new List<GLTF.Schema.Texture>();
            }

            if (root.Samplers == null)
            {
                root.Samplers = new List<GLTF.Schema.Sampler>();
            }

            var hasMipMap = texture.mipmapCount > 0;
            MagFilterMode magFilter = MagFilterMode.None;
            MinFilterMode minFilter = MinFilterMode.None;
            GLTF.Schema.WrapMode wrap = GLTF.Schema.WrapMode.None;

            switch (texture.filterMode)
            {
                case FilterMode.Point:
                    magFilter = MagFilterMode.Nearest;
                    if (hasMipMap)
                    {
                        minFilter = MinFilterMode.NearestMipmapNearest;
                    }
                    else
                    {
                        minFilter = MinFilterMode.Nearest;
                    }
                    break;

                case FilterMode.Bilinear:
                    magFilter = MagFilterMode.Linear;
                    if (hasMipMap)
                    {
                        minFilter = MinFilterMode.LinearMipmapNearest;
                    }
                    else
                    {
                        minFilter = MinFilterMode.Linear;
                    }
                    break;

                case FilterMode.Trilinear:
                    magFilter = MagFilterMode.Linear;
                    if (hasMipMap)
                    {
                        minFilter = MinFilterMode.Linear;
                    }
                    else
                    {
                        minFilter = MinFilterMode.LinearMipmapLinear;
                    }
                    break;
            }

            switch (texture.wrapMode)
            {
                case TextureWrapMode.Clamp:
                    wrap = GLTF.Schema.WrapMode.ClampToEdge;
                    break;
                case TextureWrapMode.Repeat:
                    wrap = GLTF.Schema.WrapMode.Repeat;
                    break;
            }

            var sampler = new Sampler
            {
                MagFilter = magFilter,
                MinFilter = minFilter,
                WrapS = wrap,
                WrapT = wrap
            };
            root.Samplers.Add(sampler);
            var samplerId = new SamplerId { Id = root.Samplers.Count - 1, Root = root };

            var gltfTexture = new GLTF.Schema.Texture { Source = imageId, Sampler = samplerId };
            root.Textures.Add(gltfTexture);

            var id = new TextureId { Id = root.Textures.Count - 1, Root = root };
            _texture2d2ID[texture] = id;

            return id;
        }
Example #37
0
 public TextureComponent(BaseGameObject owner, TextureId textureId) : base(owner)
 {
     TextureId = textureId;
 }
        }                                                                                                                                                                                                                // 0x01624940-0x01624BA0

        public void DrawRectZoom(TextureId texId, int x, int y, int w, int h, int s, int t, int sw, int th, Color32 color, int nPriority, bool vf = false /* Metadata: 0x00614702 */, bool hf = false /* Metadata: 0x00614703 */, bool bBlendMul = false /* Metadata: 0x00614704 */)
        {
        }                                                                                                                                                                                                                                                                                       // 0x01624BB0-0x01624E10
Example #39
0
 public TexturedBody(GameObject.BaseGameObject owner, Coord pos, Size size, short angle, TextureId textureId)
     : base(owner)
 {
     this.Pos        = pos;
     PrevPos         = new Coord(pos.x, pos.y);
     this.Size       = size;
     this.Angle      = angle;
     this.TextureId  = textureId;
     Owner.IsUpdated = true;
 }
Example #40
0
    protected override async Task ConstructMaterial(GLTFMaterial def, int materialIndex)
    {
        var material = UnityEngine.Object.Instantiate(_templateMaterial);

        if (def.PbrMetallicRoughness != null)
        {
            var pbr = def.PbrMetallicRoughness;

            material.color = pbr.BaseColorFactor.ToUnityColorRaw();

            if (pbr.BaseColorTexture != null)
            {
                TextureId textureId = pbr.BaseColorTexture.Index;
                await ConstructTexture(textureId.Value, textureId.Id, false, false);

                material.mainTexture = _assetCache.TextureCache[textureId.Id].Texture;

                var ext = GetTextureTransform(pbr.BaseColorTexture);
                if (ext != null)
                {
                    material.mainTextureOffset = new Vector2(ext.Offset.X, 1 - ext.Scale.Y - ext.Offset.Y);
                    material.mainTextureScale  = new Vector2(ext.Scale.X, ext.Scale.Y);
                }
            }
        }
        else
        {
            IExtension sgExt = null;
            def.Extensions?.TryGetValue(KHR_materials_pbrSpecularGlossinessExtensionFactory.EXTENSION_NAME, out sgExt);
            var sg = sgExt as KHR_materials_pbrSpecularGlossinessExtension;
            if (sg != null)
            {
                material.color = sg.DiffuseFactor.ToUnityColorRaw();

                if (sg.DiffuseTexture != null)
                {
                    var textureId = sg.DiffuseTexture.Index;
                    await ConstructTexture(textureId.Value, textureId.Id, false, false);

                    material.mainTexture = _assetCache.TextureCache[textureId.Id].Texture;

                    var ext = GetTextureTransform(sg.DiffuseTexture);
                    if (ext != null)
                    {
                        material.mainTextureOffset = new Vector2(ext.Offset.X, 1 - ext.Scale.Y - ext.Offset.Y);
                        material.mainTextureScale  = new Vector2(ext.Scale.X, ext.Scale.Y);
                    }
                }
            }
        }

        material.SetFloat("_AlphaCutoff", (float)def.AlphaCutoff);
        switch (def.AlphaMode)
        {
        case AlphaMode.OPAQUE:
            material.renderQueue = (int)RenderQueue.Geometry;
            material.SetOverrideTag("RenderMode", "Opaque");
            material.SetInt("_ZWrite", 1);
            material.SetInt("_SrcBlend", (int)BlendMode.One);
            material.SetInt("_DstBlend", (int)BlendMode.Zero);
            material.SetInt("_ShouldCutout", 0);
            break;

        case AlphaMode.MASK:
            material.renderQueue = (int)RenderQueue.AlphaTest;
            material.SetOverrideTag("RenderMode", "TransparentCutout");
            material.SetInt("_ZWrite", 1);
            material.SetInt("_SrcBlend", (int)BlendMode.One);
            material.SetInt("_DstBlend", (int)BlendMode.Zero);
            material.SetInt("_ShouldCutout", 1);
            break;

        case AlphaMode.BLEND:
            material.renderQueue = (int)RenderQueue.Transparent;
            material.SetOverrideTag("RenderMode", "Transparent");
            material.SetInt("_ZWrite", 0);
            material.SetInt("_SrcBlend", (int)BlendMode.SrcAlpha);
            material.SetInt("_DstBlend", (int)BlendMode.OneMinusSrcAlpha);
            material.SetInt("_ShouldCutout", 0);
            break;
        }

        MaterialCacheData materialWrapper = new MaterialCacheData
        {
            UnityMaterial = material,
            UnityMaterialWithVertexColor = material,
            GLTFMaterial = def
        };

        if (materialIndex >= 0)
        {
            _assetCache.MaterialCache[materialIndex] = materialWrapper;
        }
        else
        {
            _defaultLoadedMaterial = materialWrapper;
        }
    }
Example #41
0
 public SolidBody(GameObject.BaseGameObject owner, Coord pos, Size size, short angle, bool isSemisolid, TextureId textureId, IGameObject _IgnoreCollide)
     : base(owner, pos, size, angle, textureId)
 {
     IsSemisolid     = isSemisolid;
     Owner.IsUpdated = true;
     IgnoreCollide   = _IgnoreCollide;
 }
Example #42
0
        public Cheetah.TextureId CreateDepthTexture(int w, int h)
        {
            int[] i = new int[1];
            CheckError();
            GL.GenTextures(1, i);
            GL.BindTexture(TextureTarget.Texture2D, i[0]);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);

            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent32, w, h, 0, global::OpenTK.Graphics.OpenGL.PixelFormat.DepthComponent, PixelType.Float, IntPtr.Zero);
            TextureId t = new TextureId(i[0], this, w, h, false, false);
            Textures[t.id] = t;
            CheckError();
            return t;
        }
Example #43
0
        public Cheetah.TextureId CreateCompressedTexture(byte[][] mipmaps, TextureFormat codec,int w, int h)
        {
            if(!supports_compressed_textures)
                throw new Exception("compressed textures not supported.");

            CheckError();
            int[] i = new int[1];
            GL.GenTextures(1, i);
            TextureId t = new TextureId(i[0], this, w, h, true, false);
            t.LastBind = Root.Instance.Time;

            GL.BindTexture(TextureTarget.Texture2D, t.id);

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

            if (mipmaps.Length > 1)
            {
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapLinear);
            }
            else
            {
                //disable mipmapping
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
                GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            }

            PixelInternalFormat format;
            switch (codec)
            {
                case TextureFormat.DXT1:
                    format = PixelInternalFormat.CompressedRgbaS3tcDxt1Ext;
                    break;
                case TextureFormat.DXT2:
                    throw new Exception();
                case TextureFormat.DXT3:
                    format = PixelInternalFormat.CompressedRgbaS3tcDxt3Ext;
                    break;
                case TextureFormat.DXT4:
                    throw new Exception();
                case TextureFormat.DXT5:
                    format = PixelInternalFormat.CompressedRgbaS3tcDxt5Ext;
                    break;
                default:
                    throw new Exception();
            }

            for (int m = 0; m < mipmaps.Length; ++m)
            {
                GL.CompressedTexImage2D<byte>(TextureTarget.Texture2D, m, format, w, h, 0, mipmaps[m].Length, mipmaps[m]);
                w /= 2;
                h /= 2;
            }

            Textures[t.id] = t;

            CheckError();
            return t;
        }