Esempio n. 1
0
        public void Update(Bitmap bm)
        {
            if (bm != null)
            {
                BitmapData bd = bm.LockBits(new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

                if (bd.Stride != bd.Width * 4)
                {
                    throw new ApplicationException("Stride not a multiple of width");
                }

                unsafe
                {
                    uint tex = m_texture;
                    if (tex == 0)
                    {
                        OpenGL.glGenTextures(1, &tex);
                    }
                    m_texture = tex;

                    OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, m_texture);
                    OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, (int)OpenGL.GL_LINEAR_MIPMAP_LINEAR);
                    OpenGL.glTexParameteri(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, (int)OpenGL.GL_LINEAR_MIPMAP_LINEAR);
                    OpenGL.glPixelStorei(OpenGL.GL_UNPACK_ALIGNMENT, 1);

                    //OpenGL.glTexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA8, (int)m_atlasWidth, (int)m_atlasHeight, 0, OpenGL.GL_BGRA_EXT, OpenGL.GL_UNSIGNED_BYTE, bd.Scan0.ToPointer());
                    GLU.gluBuild2DMipmaps(OpenGL.GL_TEXTURE_2D, (int)OpenGL.GL_RGBA8, (int)bm.Width, (int)bm.Height, OpenGL.GL_BGRA_EXT, OpenGL.GL_UNSIGNED_BYTE, bd.Scan0.ToPointer());
                }

                bm.UnlockBits(bd);
            }
        }
Esempio n. 2
0
        private void SyncTexture()
        {
            OpenGL.glBindTexture(OpenGL.GL_TEXTURE_2D, m_texture);

            unsafe
            {
                BitmapData bd = m_bitmap.LockBits(new Rectangle(0, 0, m_bitmap.Width, m_bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);

                if (bd.Stride != bd.Width * 4)
                {
                    throw new ApplicationException("Stride not a multiple of width");
                }

                //OpenGL.glTexImage2D(OpenGL.GL_TEXTURE_2D, 0, (int)OpenGL.GL_RGBA8, (int)m_atlasWidth, (int)m_atlasHeight, 0, OpenGL.GL_BGRA_EXT, OpenGL.GL_UNSIGNED_BYTE, bd.Scan0.ToPointer());
                GLU.gluBuild2DMipmaps(OpenGL.GL_TEXTURE_2D, (int)OpenGL.GL_ALPHA, (int)m_atlasWidth, (int)m_atlasHeight, OpenGL.GL_BGRA_EXT, OpenGL.GL_UNSIGNED_BYTE, bd.Scan0.ToPointer());

                m_bitmap.UnlockBits(bd);
            }

            m_dirty = false;
        }
Esempio n. 3
0
        public unsafe void LoadOpenGL()
        {
            //Debug.Assert( this.ParentTextures != null );
            Debug.Assert(this.IsBitmapLoaded == true);
            Debug.Assert(this.IsOpenGLLoaded == false);

            // load opengl texture
            GL.glEnable(GL.Option.Texture2D);

            // create new OpenGL texture handle if needed.
            if (_handle == -1)
            {
                uint[] handles = new uint[1];
                GL.glGenTextures(1, handles);
                _handle = (int)handles[0];
                //OpenGLTextureCount ++;
                GL.glErrorCheck();
            }

            GL.glBindTexture(GL.Texture.Texture2D, (uint)_handle);
            GL.glErrorCheck();

            if (this.Clamp)
            {
                GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
                GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);
            }
            else
            {
                GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT);
                GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT);
            }
            GL.glErrorCheck();

            if (this.Mipmap == false)
            {
                Debug.Assert(this.MinFilter != GL.TextureFilter.LinearMipmapLinear, this.Mipmap + "  " + this.MinFilter);
                Debug.Assert(this.MinFilter != GL.TextureFilter.LinearMipmapNearest, this.Mipmap + "  " + this.MinFilter);
                Debug.Assert(this.MinFilter != GL.TextureFilter.NearestMipmapLinear, this.Mipmap + "  " + this.MinFilter);
                Debug.Assert(this.MinFilter != GL.TextureFilter.NearestMipmapNearest, this.Mipmap + "  " + this.MinFilter);
            }
            Debug.Assert(this.MaxFilter != GL.TextureFilter.LinearMipmapLinear, this.Mipmap + "  " + this.MaxFilter);
            Debug.Assert(this.MaxFilter != GL.TextureFilter.LinearMipmapNearest, this.Mipmap + "  " + this.MaxFilter);
            Debug.Assert(this.MaxFilter != GL.TextureFilter.NearestMipmapLinear, this.Mipmap + "  " + this.MaxFilter);
            Debug.Assert(this.MaxFilter != GL.TextureFilter.NearestMipmapNearest, this.Mipmap + "  " + this.MaxFilter);

            GL.glTexParameteri(GL.Texture.Texture2D, GL.TexParamPName.TextureMinFilter, this.MinFilter);
            GL.glErrorCheck();
            GL.glTexParameteri(GL.Texture.Texture2D, GL.TexParamPName.TextureMagFilter, this.MaxFilter);
            GL.glErrorCheck();

            fixed(uint *pData = & (_data[0]))
            {
                if (this.Mipmap == true)
                {
                    GLU.gluBuild2DMipmaps(GL.GL_TEXTURE_2D, (int)GL.GL_RGBA8, _width, _height,
                                          GL.GL_BGRA_EXT, GL.GL_UNSIGNED_BYTE, (void *)pData);
                    GL.glErrorCheck();
                }
                else
                {
                    GL.glTexImage2D(GL.Texture.Texture2D, 0, GL.InternalFormat.RGBA8, _width, _height, 0,
                                    GL.PixelFormat.BGRAExt, GL.DataType.UnsignedByte, (void *)pData);
                    GL.glErrorCheck();
                }
            }

            _threadParent = Thread.CurrentThread;

            Debug.Assert(this.IsOpenGLLoaded == true);
        }