Beispiel #1
0
        internal static ValueTypeDescriptor Create(Type type)
        {
            ValueTypeDescriptor descriptor;

            if (!s_descriptors.TryGetValue(type, out descriptor))
            {
                descriptor = new ValueTypeDescriptor(type, 0);
                s_descriptors.Add(type, descriptor);
            }
            return(descriptor);
        }
 public ValueTypeDescriptorField(int offset, ValueTypeDescriptor descriptor)
 {
     Offset = offset;
     Descriptor = descriptor;
 }
 public Field(int offset, string name, ValueTypeDescriptor descriptor)
 {
     m_offset = offset;
     m_name = name;
     m_descriptor = descriptor;
 }
 internal static ValueTypeDescriptor Create(Type type)
 {
     ValueTypeDescriptor descriptor;
     if (!s_descriptors.TryGetValue(type, out descriptor))
     {
         descriptor = new ValueTypeDescriptor(type, 0);
         s_descriptors.Add(type, descriptor);
     }
     return descriptor;
 }
Beispiel #5
0
 public Field(int offset, string name, ValueTypeDescriptor descriptor)
 {
     m_offset     = offset;
     m_name       = name;
     m_descriptor = descriptor;
 }
Beispiel #6
0
 public ValueTypeDescriptorField(int offset, ValueTypeDescriptor descriptor)
 {
     Offset     = offset;
     Descriptor = descriptor;
 }
Beispiel #7
0
        public void SetData <T>(int width, int height, T[] data) where T : struct
        {
            m_size = new Vector2i(width, height);

            var  descriptor = ValueTypeDescriptor.Create(typeof(T));
            uint format;

            if (descriptor.FlattenedCount == 1)
            {
                format = GL.RED;
            }
            else if (descriptor.FlattenedCount == 3)
            {
                format = GL.RGB;
            }
            else if (descriptor.FlattenedCount == 4)
            {
                format = GL.RGBA;
            }
            else
            {
                throw new ArgumentException("data");
            }

            GL.BindTexture(GL.TEXTURE_2D, m_name);

            GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, (int)GL.NEAREST);
            GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, (int)GL.NEAREST);
            //GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, (int)GL.LINEAR);
            //GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, (int)GL.LINEAR);
            GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, (int)GL.CLAMP_TO_EDGE);
            GL.TexParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, (int)GL.CLAMP_TO_EDGE);

            if (data == null)
            {
                GL.TexImage2D(
                    GL.TEXTURE_2D,
                    0,
                    (int)format,
                    width,
                    height,
                    0,
                    format,
                    descriptor.FlattenedType,
                    IntPtr.Zero
                    );
            }
            else
            {
                var handle = GCHandle.Alloc(data, GCHandleType.Pinned);

                try
                {
                    GL.TexImage2D(
                        GL.TEXTURE_2D,
                        0,
                        (int)format,
                        width,
                        height,
                        0,
                        format,
                        descriptor.FlattenedType,
                        handle.AddrOfPinnedObject()
                        );
                }
                finally
                {
                    handle.Free();
                }
            }

            GL.BindTexture(GL.TEXTURE_2D, 0);
        }