Ejemplo n.º 1
0
        public GlRenderTarget(OpenGLRenderer renderer, int width, int height)
        {
            // generate the FBO
            GL.GenFramebuffers(1, out _fbo);
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, _fbo);

            // generate a depth buffer
            GL.GenRenderbuffers(1, out _depthBuffer);
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, _depthBuffer);
            GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferStorage.DepthComponent16, width, height);
            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, _depthBuffer);

            // generate a color buffer
            GL.GenTextures(1, out _colorBuffer);
            GL.BindTexture(TextureTarget.Texture2D, _colorBuffer);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 0);
            GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, TextureTarget.Texture2D, _colorBuffer, 0);

            // all done... or are we...?
            FramebufferErrorCode status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

            if (status != FramebufferErrorCode.FramebufferComplete)
            {
                throw new Exception("Unable to create RenderTarget: " + status.ToString());
            }

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);

            _width  = width;
            _height = height;
        }
Ejemplo n.º 2
0
        public GlTexture(OpenGLRenderer renderer, string name, BitmapSurface surface, bool mipmapped, bool premultiplyAlpha)
            : base(name, surface)
        {
            _renderer = renderer;

            if (premultiplyAlpha)
            {
                this.premultiplyAlpha();
            }

            convertToOpenGlTexture(true, false, mipmapped);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates a 1x1 white texture
        /// </summary>
        internal GlTexture(OpenGLRenderer renderer, bool loaded)
            : base("default_white", loaded)
        {
            _renderer = renderer;

            // create a 1x1 white pixel
            _pixels = new byte[] { 255, 255, 255, 255 };
            _width  = 1;
            _height = 1;

            convertToOpenGlTexture(false, true, true);
        }
Ejemplo n.º 4
0
        public GlUpdatableTexture(OpenGLRenderer renderer, string name, int width, int height)
            : base(name, width, height)
        {
            if (Gk3Main.Utils.IsPowerOfTwo(width) == false ||
                Gk3Main.Utils.IsPowerOfTwo(height) == false)
            {
                throw new ArgumentException("Width and height must be power-of-two");
            }

            _renderer = renderer;

            GL.Enable(EnableCap.Texture2D);
            GL.GenTextures(1, out _glTexture);

            GL.BindTexture(TextureTarget.Texture2D, _glTexture);
            //GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.Linear);
            // GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)All.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMaxLevel, 0);
        }
Ejemplo n.º 5
0
        internal GlTexture(OpenGLRenderer renderer, string name, int glTexture, int width, int height, bool loaded)
            : base(name, loaded)
        {
            _renderer = renderer;

            _glTexture = glTexture;

            _width             = width;
            _height            = height;
            _actualPixelWidth  = width;
            _actualPixelHeight = height;
            _actualWidth       = 1.0f;
            _actualHeight      = 1.0f;

            _pixels = new byte[_width * _height * 4];

            GL.BindTexture(TextureTarget.Texture2D, _glTexture);
            GL.GetTexImage(TextureTarget.Texture2D, 0, PixelFormat.Rgba, PixelType.UnsignedByte, _pixels);

            //Gl.glTexImage2D(TextureTarget.Texture2D, 0, Gl.GL_RGBA, width, height, 0, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, _pixels);
        }
Ejemplo n.º 6
0
        public GlCubeMap(OpenGLRenderer renderer, string name, BitmapSurface front, BitmapSurface back, BitmapSurface left, BitmapSurface right,
                         BitmapSurface up, BitmapSurface down)
            : base(name)
        {
            _renderer = renderer;

            GL.GetError();

            GL.GenTextures(1, out _glTexture);
            GL.BindTexture(TextureTarget.TextureCubeMap, _glTexture);

            const PixelFormat format = PixelFormat.Rgba;

            GL.TexImage2D(TextureTarget.TextureCubeMapPositiveX, 0, PixelInternalFormat.Rgba, front.Width, front.Height, 0, format, PixelType.UnsignedByte, front.Pixels);
            GL.TexImage2D(TextureTarget.TextureCubeMapNegativeX, 0, PixelInternalFormat.Rgba, back.Width, back.Height, 0, format, PixelType.UnsignedByte, back.Pixels);
            GL.TexImage2D(TextureTarget.TextureCubeMapPositiveZ, 0, PixelInternalFormat.Rgba, right.Width, right.Height, 0, format, PixelType.UnsignedByte, right.Pixels);
            GL.TexImage2D(TextureTarget.TextureCubeMapNegativeZ, 0, PixelInternalFormat.Rgba, left.Width, left.Height, 0, format, PixelType.UnsignedByte, left.Pixels);
            GL.TexImage2D(TextureTarget.TextureCubeMapPositiveY, 0, PixelInternalFormat.Rgba, up.Width, up.Height, 0, format, PixelType.UnsignedByte, up.Pixels);

            if (down != null)
            {
                GL.TexImage2D(TextureTarget.TextureCubeMapNegativeY, 0, PixelInternalFormat.Rgba, down.Width, down.Height, 0, format, PixelType.UnsignedByte, down.Pixels);
            }
            else
            {
                // apparently the "down" face isn't needed. we'll just reuse the top.
                GL.TexImage2D(TextureTarget.TextureCubeMapNegativeY, 0, PixelInternalFormat.Rgba, up.Width, up.Height, 0, format, PixelType.UnsignedByte, up.Pixels);
            }

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

            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, (int)All.ClampToEdge);
            GL.TexParameter(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, (int)All.ClampToEdge);

            if (GL.GetError() != ErrorCode.NoError)
            {
                throw new InvalidOperationException();
            }
        }