示例#1
0
        private void GL_setupTargets(int width, int height)
        {
            // We're going to mess with sampler 0's texture.
            OpenGLDevice.OpenGLTexture prevTexture = currentDevice.GLDevice.Textures[0];

            // Attach the Texture2D to the framebuffer.
            uint prevReadFramebuffer = currentDevice.GLDevice.CurrentReadFramebuffer;
            uint prevDrawFramebuffer = currentDevice.GLDevice.CurrentDrawFramebuffer;

            currentDevice.GLDevice.BindFramebuffer(rgbaFramebuffer);
            currentDevice.GLDevice.glFramebufferTexture2D(
                OpenGLDevice.GLenum.GL_FRAMEBUFFER,
                OpenGLDevice.GLenum.GL_COLOR_ATTACHMENT0,
                OpenGLDevice.GLenum.GL_TEXTURE_2D,
                videoTexture.texture.Handle,
                0
                );
            currentDevice.GLDevice.BindReadFramebuffer(prevReadFramebuffer);
            currentDevice.GLDevice.BindDrawFramebuffer(prevDrawFramebuffer);

            // Be careful about non-2D textures currently bound...
            if (prevTexture.Target != OpenGLDevice.GLenum.GL_TEXTURE_2D)
            {
                currentDevice.GLDevice.glBindTexture(prevTexture.Target, 0);
            }

            // Allocate YUV GL textures
            GL_internal_genTexture(
                yuvTextures[0],
                width,
                height
                );
            GL_internal_genTexture(
                yuvTextures[1],
                width / 2,
                height / 2
                );
            GL_internal_genTexture(
                yuvTextures[2],
                width / 2,
                height / 2
                );

            // Aaand we should be set now.
            if (prevTexture.Target != OpenGLDevice.GLenum.GL_TEXTURE_2D)
            {
                currentDevice.GLDevice.glBindTexture(
                    OpenGLDevice.GLenum.GL_TEXTURE_2D,
                    0
                    );
            }
            currentDevice.GLDevice.glBindTexture(prevTexture.Target, prevTexture.Handle);
        }
示例#2
0
        private void GL_setupTargets(int width, int height)
        {
            // We're going to mess with sampler 0's texture.
            OpenGLDevice.OpenGLTexture prevTexture = currentDevice.GLDevice.Textures[0];

            // Attach the Texture2D to the framebuffer.
            int prevReadFramebuffer = OpenGLDevice.Framebuffer.CurrentReadFramebuffer;
            int prevDrawFramebuffer = OpenGLDevice.Framebuffer.CurrentDrawFramebuffer;

            OpenGLDevice.Framebuffer.BindFramebuffer(rgbaFramebuffer);
            OpenGLDevice.Framebuffer.AttachColor(videoTexture.texture.Handle, 0, TextureTarget.Texture2D);
            OpenGLDevice.Framebuffer.BindReadFramebuffer(prevReadFramebuffer);
            OpenGLDevice.Framebuffer.BindDrawFramebuffer(prevDrawFramebuffer);

            // Be careful about non-2D textures currently bound...
            if (prevTexture.Target != TextureTarget.Texture2D)
            {
                GL.BindTexture(prevTexture.Target, 0);
            }

            // Allocate YUV GL textures
            GL_internal_genTexture(
                yuvTextures[0],
                width,
                height,
                PixelInternalFormat.Luminance,
                PixelFormat.Luminance,
                PixelType.UnsignedByte
                );
            GL_internal_genTexture(
                yuvTextures[1],
                width / 2,
                height / 2,
                PixelInternalFormat.Luminance,
                PixelFormat.Luminance,
                PixelType.UnsignedByte
                );
            GL_internal_genTexture(
                yuvTextures[2],
                width / 2,
                height / 2,
                PixelInternalFormat.Luminance,
                PixelFormat.Luminance,
                PixelType.UnsignedByte
                );

            // Aaand we should be set now.
            if (prevTexture.Target != TextureTarget.Texture2D)
            {
                GL.BindTexture(TextureTarget.Texture2D, 0);
            }
            GL.BindTexture(prevTexture.Target, prevTexture.Handle);
        }
示例#3
0
        public Texture3D(
            GraphicsDevice graphicsDevice,
            int width,
            int height,
            int depth,
            bool mipMap,
            SurfaceFormat format
            )
        {
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("graphicsDevice");
            }

            GraphicsDevice = graphicsDevice;
            Width          = width;
            Height         = height;
            Depth          = depth;
            LevelCount     = 1;

            if (mipMap)
            {
                throw new NotImplementedException("Texture3D does not yet support mipmaps.");
            }

            Format = format;
            GetGLSurfaceFormat();

            texture = new OpenGLDevice.OpenGLTexture(
                TextureTarget.Texture3D,
                Format,
                false
                );
            OpenGLDevice.Instance.BindTexture(texture);
            GL.TexImage3D(
                TextureTarget.Texture3D,
                0,
                glInternalFormat,
                width,
                height,
                depth,
                0,
                glFormat,
                glType,
                IntPtr.Zero
                );
            texture.Flush(true);
        }
示例#4
0
        public Texture2D(
            GraphicsDevice graphicsDevice,
            int width,
            int height,
            bool mipmap,
            SurfaceFormat format
            )
        {
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("graphicsDevice");
            }

            GraphicsDevice = graphicsDevice;
            Width          = width;
            Height         = height;
            LevelCount     = mipmap ? CalculateMipLevels(width, height) : 1;

            Format = format;
            GetGLSurfaceFormat();

            Threading.ForceToMainThread(() =>
            {
                texture = new OpenGLDevice.OpenGLTexture(
                    TextureTarget.Texture2D,
                    Format,
                    LevelCount > 1
                    );
                if (((Width & (Width - 1)) != 0) || ((Height & (Height - 1)) != 0))
                {
                    texture.WrapS.Set(TextureAddressMode.Clamp);
                    texture.WrapT.Set(TextureAddressMode.Clamp);
                }
                OpenGLDevice.Instance.BindTexture(texture);

                if (Format == SurfaceFormat.Dxt1 ||
                    Format == SurfaceFormat.Dxt3 ||
                    Format == SurfaceFormat.Dxt5)
                {
                    GL.CompressedTexImage2D(
                        TextureTarget.Texture2D,
                        0,
                        glInternalFormat,
                        Width,
                        Height,
                        0,
                        ((Width + 3) / 4) * ((Height + 3) / 4) * GetFormatSize(),
                        IntPtr.Zero
                        );
                }
                else
                {
                    GL.TexImage2D(
                        TextureTarget.Texture2D,
                        0,
                        glInternalFormat,
                        Width,
                        Height,
                        0,
                        glFormat,
                        glType,
                        IntPtr.Zero
                        );
                }
                texture.Flush(true);
            });
        }
示例#5
0
        public TextureCube(
            GraphicsDevice graphicsDevice,
            int size,
            bool mipMap,
            SurfaceFormat format
            )
        {
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("graphicsDevice");
            }

            GraphicsDevice = graphicsDevice;
            Size           = size;
            LevelCount     = mipMap ? CalculateMipLevels(size) : 1;
            Format         = format;
            GetGLSurfaceFormat();

            Threading.ForceToMainThread(() =>
            {
                texture = new OpenGLDevice.OpenGLTexture(
                    TextureTarget.TextureCubeMap,
                    Format,
                    LevelCount > 1
                    );
                texture.WrapS.Set(TextureAddressMode.Clamp);
                texture.WrapT.Set(TextureAddressMode.Clamp);

                OpenGLDevice.Instance.BindTexture(texture);
                for (int i = 0; i < 6; i += 1)
                {
                    TextureTarget target = GetGLCubeFace((CubeMapFace)i);

                    if (glFormat == (PixelFormat)All.CompressedTextureFormats)
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
                        GL.TexImage2D(
                            target,
                            0,
                            glInternalFormat,
                            size,
                            size,
                            0,
                            glFormat,
                            glType,
                            IntPtr.Zero
                            );
                    }
                }
                texture.Flush(true);

                if (mipMap)
                {
                    GL.TexParameter(
                        TextureTarget.TextureCubeMap,
                        TextureParameterName.GenerateMipmap,
                        1
                        );
                }
            });
        }