protected override void WriteTexture(int id, OpenGLTexture texture)
        {
            var bmp  = (BitmapTexture)texture;
            var path = System.IO.Path.Combine(ShapeStorePath, "Texture" + id + ".png");

            bmp.WritePng(path);
        }
Beispiel #2
0
 public void SetTexture(ITexture texture)
 {
     //valid?
     if (!(texture is OpenGLTexture))
     {
         throw new Exception("OpenGL: Invalid texture!");
     }
     p_Texture = texture as OpenGLTexture;
 }
Beispiel #3
0
        public void StartDrawTextMeshToImage(int width, int height)
        {
            //create quadMesh
            if (quadMesh == null)
            {
                quadMesh = new QuadMesh();
            }

            //create textures
            {
                glyphOpenGLTexture = new OpenGLTexture();
                glyphOpenGLTexture.LoadImage(new byte[width * height * 4], width, height);
                glyphTexture = (uint)glyphOpenGLTexture.GetNativeTextureId();
            }
            {
                textOpenGLTexture = new OpenGLTexture();
                textOpenGLTexture.LoadImage(new byte[width * height * 4], width, height);
                textTexture = (uint)textOpenGLTexture.GetNativeTextureId();
            }

            //create frame buffer
            GL.GenFramebuffers(2, textMeshFrameBuffers);
            this.glyphFrameBuffer = textMeshFrameBuffers[0];
            this.textFrameBuffer = textMeshFrameBuffers[1];

            //attach textures to framebuffers
            GL.BindFramebuffer(GL.GL_FRAMEBUFFER_EXT, this.glyphFrameBuffer);
            GL.FramebufferTexture2D(GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT,
                GL.GL_TEXTURE_2D, glyphTexture, 0);
            if (GL.CheckFramebufferStatus(GL.GL_FRAMEBUFFER_EXT) != GL.GL_FRAMEBUFFER_COMPLETE_EXT)
            {
                throw new Exception("Framebuffer for glyph is not complete.");
            }
            
            GL.BindFramebuffer(GL.GL_FRAMEBUFFER_EXT, this.textFrameBuffer);
            GL.FramebufferTexture2D(GL.GL_FRAMEBUFFER_EXT, GL.GL_COLOR_ATTACHMENT0_EXT,
                GL.GL_TEXTURE_2D, textTexture, 0);
            if (GL.CheckFramebufferStatus(GL.GL_FRAMEBUFFER_EXT) != GL.GL_FRAMEBUFFER_COMPLETE_EXT)
            {
                throw new Exception("Framebuffer for text is not complete.");
            }
        }
Beispiel #4
0
        public ITexture GetTexture(string alias)
        {
            //generate a hash for the alias so
            //we can compare to other textures quickly
            int aliasHash = alias.GetHashCode();

            lock (p_Mutex) {
                //look for the hash
                int l = p_Textures.Length;
                for (int c = 0; c < l; c++)
                {
                    OpenGLTexture texture = p_Textures[c];
                    if (texture.HASH == aliasHash)
                    {
                        return(texture);
                    }
                }
            }

            //not found
            return(null);
        }
Beispiel #5
0
 public OpenGLTextureBinding(OpenGLTexture texture)
 {
     _texture = texture;
 }
Beispiel #6
0
		private OpenGLTexture CreateTexture(
			GLenum target,
			int levelCount
		) {
			uint handle;
			glGenTextures(1, out handle);
			OpenGLTexture result = new OpenGLTexture(
				handle,
				target,
				levelCount
			);
			BindTexture(result);
			glTexParameteri(
				result.Target,
				GLenum.GL_TEXTURE_WRAP_S,
				XNAToGL.Wrap[(int) result.WrapS]
			);
			glTexParameteri(
				result.Target,
				GLenum.GL_TEXTURE_WRAP_T,
				XNAToGL.Wrap[(int) result.WrapT]
			);
			glTexParameteri(
				result.Target,
				GLenum.GL_TEXTURE_WRAP_R,
				XNAToGL.Wrap[(int) result.WrapR]
			);
			glTexParameteri(
				result.Target,
				GLenum.GL_TEXTURE_MAG_FILTER,
				XNAToGL.MagFilter[(int) result.Filter]
			);
			glTexParameteri(
				result.Target,
				GLenum.GL_TEXTURE_MIN_FILTER,
				result.HasMipmaps ?
					XNAToGL.MinMipFilter[(int) result.Filter] :
					XNAToGL.MinFilter[(int) result.Filter]
			);
			glTexParameterf(
				result.Target,
				GLenum.GL_TEXTURE_MAX_ANISOTROPY_EXT,
				(result.Filter == TextureFilter.Anisotropic) ? Math.Max(result.Anistropy, 1.0f) : 1.0f
			);
			glTexParameteri(
				result.Target,
				GLenum.GL_TEXTURE_BASE_LEVEL,
				result.MaxMipmapLevel
			);
			if (!useES2)
			{
				glTexParameterf(
					result.Target,
					GLenum.GL_TEXTURE_LOD_BIAS,
					result.LODBias
				);
			}
			return result;
		}
Beispiel #7
0
 public OpenGLTextureView(ref TextureViewDescription description)
     : base(description.Target)
 {
     Target = Util.AssertSubtype <Texture, OpenGLTexture>(description.Target);
 }
Beispiel #8
0
 public OpenGLTexture_JS_Wrapper(OpenGLTexture texToWrap)
 {
     this._tex = texToWrap;
 }
Beispiel #9
0
        public ITexture AllocateTexture(Bitmap bmp, string alias)
        {
            Monitor.Enter(p_Mutex);
            Size size = bmp.Size;

            //has the texture already been defined?
            ITexture exist = GetTexture(alias);

            if (exist != null)
            {
                Monitor.Exit(p_Mutex);
                return(exist);
            }

            //create the texture index
            int index;

            glGenTextures(1, out index);
            glBindTexture(TEXTURE_2D, index);

            //lock the bitmap so we can access its memory directly
            BitmapData bmpData = bmp.LockBits(
                new Rectangle(Point.Empty, size),
                ImageLockMode.ReadOnly,
                PixelFormat.Format32bppArgb);

            //copy bitmap data to the GPU
            glTexImage2D(
                TEXTURE_2D,
                0,
                RGBA,
                size.Width,
                size.Height,
                0,
                BGRA,
                UNSIGNED_BYTE,
                bmpData.Scan0);

            //clean up
            bmp.UnlockBits(bmpData);


            glTexParameteri(TEXTURE_2D, TEXTURE_MIN_FILTER, LINEAR);
            glTexParameteri(TEXTURE_2D, TEXTURE_MAG_FILTER, LINEAR);
            glTexParameteri(TEXTURE_2D, TEXTURE_WRAP_S, REPEAT);
            glTexParameteri(TEXTURE_2D, TEXTURE_WRAP_T, REPEAT);


            //add the texture
            OpenGLTexture buffer = new OpenGLTexture {
                Width  = size.Width,
                Height = size.Height,
                INDEX  = index,
                HASH   = alias.GetHashCode()
            };

            Array.Resize(ref p_Textures, p_Textures.Length + 1);
            p_Textures[p_Textures.Length - 1] = buffer;
            Monitor.Exit(p_Mutex);
            return(buffer);
        }
Beispiel #10
0
        private OpenGLTexture CreateTexture(
			GLenum target,
			int levelCount
		)
        {
            uint handle;
            glCreateTextures(target, 1, out handle);
            OpenGLTexture result = new OpenGLTexture(
                handle,
                target,
                levelCount
            );
            return result;
        }
Beispiel #11
0
 public OpenGLTextureBinding(OpenGLTexture texture)
 {
     BoundTexture = texture;
 }