Beispiel #1
0
        public bool GenTexId()
        {
            if (m_Id != 0)
            {
                return(true);
            }
            m_Id = GL.GenTexture();
            if (m_Id == 0)
            {
                m_LastError = TextureLoadError.OutOfTextureHandles;
                return(false);
            }

            Bind();
            GL.TexParameter(m_TextureType, TextureParamName.TextureMinFilter, (int)m_MinFilter);
            GL.TexParameter(m_TextureType, TextureParamName.TextureMagFilter, (int)m_MagFilter);
            m_LastError = TextureLoadError.NoError;
            return(true);
        }
Beispiel #2
0
 public override bool Load(string filename)
 {
     m_LastError = TextureLoadError.NoError;
     if (File.Exists(filename))
     {
         BitmapFile bmpf;
         try {
             bmpf = GameFile.LoadFile <BitmapFile>(filename);
         }
         catch (OutOfMemoryException) {
             m_LastError = TextureLoadError.OutOfMemory;
             return(false);
         }
         catch (Exception ex) {
             throw new UserFriendlyException(String.Format("There was an error while trying to load a texture bitmap file: {0}", filename), "Error occured while trying to load a texture", ex);
         }
         return(Load(bmpf.Bitmap));
     }
     else
     {
         m_LastError = TextureLoadError.FileNotFound;
     }
     return(false);
 }
Beispiel #3
0
        public bool Load(int width, int height, byte[] pixels)
        {
            if (!GenTexId())
            {
                return(false);
            }

            m_LastError = TextureLoadError.NoError;

            m_Width      = width;
            m_Height     = height;
            m_PixelSizeS = 1.0f / (float)m_Width;
            m_PixelSizeT = 1.0f / (float)m_Height;

            Bind();

            if (pixels == null)
            {
                if (m_TextureType == TextureTarget.Texture2DMultisample)
                {
                    GL.TexImage2DMultisample(
                        m_TextureType,
                        m_MultisamplingSamples, InternalPixelFormat.Rgba8,
                        width, height,
                        true
                        );
                }
                else
                {
                    GL.TexImage2D(
                        m_TextureType,
                        0, InternalPixelFormat.Rgba8,
                        width, height,
                        0, PixelFormatEnum.Bgra,
                        IGE.Graphics.OpenGL.PixelType.UnsignedByte, IntPtr.Zero
                        );
                }
            }
            else
            {
                lock (pixels.SyncRoot) {
                    unsafe
                    {
                        fixed(byte *pix = &pixels[0])
                        {
                            GL.TexImage2D(
                                m_TextureType,
                                0, InternalPixelFormat.Rgba8,
                                width, height,
                                0, PixelFormatEnum.Bgra,
                                IGE.Graphics.OpenGL.PixelType.UnsignedByte, pix
                                );
                        }
                    }
                }
            }

            if (m_MinFilter != TextureMinFilter.Linear && m_MinFilter != TextureMinFilter.Nearest)
            {
                GL.GenerateMipmap(m_TextureType);
            }

            return(true);
        }