Exemple #1
0
 public RenderTargetBinding(RenderTarget2D renderTarget)
 {
   if (renderTarget == null)
     throw new ArgumentNullException("renderTarget");
   this._renderTarget = (Texture) renderTarget;
   this._cubeMapFace = CubeMapFace.PositiveX;
 }
Exemple #2
0
 public RenderTargetBinding(RenderTargetCube renderTarget, CubeMapFace cubeMapFace)
 {
   if (renderTarget == null)
     throw new ArgumentNullException("renderTarget");
   if (cubeMapFace < CubeMapFace.PositiveX || cubeMapFace > CubeMapFace.NegativeZ)
     throw new ArgumentOutOfRangeException("cubeMapFace");
   this._renderTarget = (Texture) renderTarget;
   this._cubeMapFace = cubeMapFace;
 }
        public RenderTargetBinding(RenderTargetCube renderTarget, CubeMapFace cubeMapFace)
        {
            if (renderTarget == null)
                throw new ArgumentNullException("renderTarget");
            if (cubeMapFace < CubeMapFace.PositiveX || cubeMapFace > CubeMapFace.NegativeZ)
                throw new ArgumentOutOfRangeException("cubeMapFace");

            _renderTarget = renderTarget;
            _arraySlice = (int)cubeMapFace;
        }
Exemple #4
0
        public RenderTargetBinding(RenderTarget2D renderTarget)
        {
            if (renderTarget == null)
            {
                throw new ArgumentNullException("renderTarget");
            }

            this.renderTarget = renderTarget;
            cubeMapFace = CubeMapFace.PositiveX;
        }
 /// <summary>
 /// Converts a value from <see cref="CubeMapFace"/> to its associated GL_TEXTURE_CUBE_MAP_... enum value
 /// </summary>
 public static int GetGlCubeFaceEnum( CubeMapFace face )
 {
     switch ( face )
     {
         case CubeMapFace.NegativeX : return Gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_X;
         case CubeMapFace.PositiveX : return Gl.GL_TEXTURE_CUBE_MAP_POSITIVE_X;
         case CubeMapFace.NegativeY : return Gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
         case CubeMapFace.PositiveY : return Gl.GL_TEXTURE_CUBE_MAP_POSITIVE_Y;
         case CubeMapFace.NegativeZ : return Gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
         case CubeMapFace.PositiveZ : return Gl.GL_TEXTURE_CUBE_MAP_POSITIVE_Z;
     }
     throw new NotImplementedException( "Unsupported cube face enum value " + face );
 }
Exemple #6
0
    /// <summary>
    /// Returns a view matrix for rendering to a face of a cubemap.
    /// </summary>
    public static Matrix GetCubeMapViewMatrix(CubeMapFace face)
    {
        Vector3 vEyePt   = new Vector3(0.0f, 0.0f, 0.0f);
        Vector3 vLookDir = new Vector3();
        Vector3 vUpDir   = new Vector3();

        switch (face)
        {
        case CubeMapFace.PositiveX:
            vLookDir = new Vector3(1.0f, 0.0f, 0.0f);
            vUpDir   = new Vector3(0.0f, 1.0f, 0.0f);
            break;

        case CubeMapFace.NegativeX:
            vLookDir = new Vector3(-1.0f, 0.0f, 0.0f);
            vUpDir   = new Vector3(0.0f, 1.0f, 0.0f);
            break;

        case CubeMapFace.PositiveY:
            vLookDir = new Vector3(0.0f, 1.0f, 0.0f);
            vUpDir   = new Vector3(0.0f, 0.0f, -1.0f);
            break;

        case CubeMapFace.NegativeY:
            vLookDir = new Vector3(0.0f, -1.0f, 0.0f);
            vUpDir   = new Vector3(0.0f, 0.0f, 1.0f);
            break;

        case CubeMapFace.PositiveZ:
            vLookDir = new Vector3(0.0f, 0.0f, 1.0f);
            vUpDir   = new Vector3(0.0f, 1.0f, 0.0f);
            break;

        case CubeMapFace.NegativeZ:
            vLookDir = new Vector3(0.0f, 0.0f, -1.0f);
            vUpDir   = new Vector3(0.0f, 1.0f, 0.0f);
            break;
        }

        // Set the view transform for this cubemap surface
        Matrix matView = Matrix.LookAtLH(vEyePt, vLookDir, vUpDir);

        return(matView);
    }
Exemple #7
0
        public void SetDataPointerEXT(
            CubeMapFace cubeMapFace,
            int level,
            Rectangle?rect,
            IntPtr data,
            int dataLength
            )
        {
            if (data == IntPtr.Zero)
            {
                throw new ArgumentNullException("data");
            }

            int xOffset, yOffset, width, height;

            if (rect.HasValue)
            {
                xOffset = rect.Value.X;
                yOffset = rect.Value.Y;
                width   = rect.Value.Width;
                height  = rect.Value.Height;
            }
            else
            {
                xOffset = 0;
                yOffset = 0;
                width   = Math.Max(1, Size >> level);
                height  = Math.Max(1, Size >> level);
            }

            FNA3D.FNA3D_SetTextureDataCube(
                GraphicsDevice.GLDevice,
                texture,
                xOffset,
                yOffset,
                width,
                height,
                cubeMapFace,
                level,
                data,
                dataLength
                );
        }
Exemple #8
0
        public ImageData GetImageData(CubeMapFace cubeMapFace, int mipmapIndex)
        {
            if (!this.IsValid || mipmapIndex < 0)
            {
                return((ImageData)null);
            }
            int faceCount = this.FaceCount;

            for (int index = 0; index < faceCount; ++index)
            {
                this.Bind();
                IL.ActiveFace(index);
                if ((CubeMapFace)IL.ilGetInteger(3581U) == cubeMapFace)
                {
                    return(ImageData.Load(new Subimage(this.m_id, 0, index, 0, mipmapIndex)));
                }
            }
            return((ImageData)null);
        }
        private void PlatformSetData <T>(CubeMapFace face, int level, IntPtr dataPtr, int xOffset, int yOffset, int width, int height)
        {
            Threading.BlockOnUIThread(() =>
            {
                GL.BindTexture(TextureTarget.TextureCubeMap, this.glTexture);
                GraphicsExtensions.CheckGLError();

                TextureTarget target = GetGLCubeFace(face);
                if (glFormat == (PixelFormat)All.CompressedTextureFormats)
                {
                    throw new NotImplementedException();
                }
                else
                {
                    GL.TexSubImage2D(target, level, xOffset, yOffset, width, height, glFormat, glType, dataPtr);
                    GraphicsExtensions.CheckGLError();
                }
            });
        }
Exemple #10
0
        private Matrix GetViewMatrixForSide(CubeMapFace face)
        {
            Vector3 pos = teapotPos, look = new Vector3(1.0f, 0.0f, 0.0f), up = new Vector3(0.0f, 1.0f, 0.0f);

            switch (face)
            {
            case CubeMapFace.PositiveX:
                look = new Vector3(1.0f, 0.0f, 0.0f);
                up   = new Vector3(0.0f, 1.0f, 0.0f);
                break;

            case CubeMapFace.NegativeX:
                look = new Vector3(-1.0f, 0.0f, 0.0f);
                up   = new Vector3(0.0f, 1.0f, 0.0f);
                break;

            case CubeMapFace.PositiveY:
                look = new Vector3(0.0f, 1.0f, 0.0f);
                up   = new Vector3(0.0f, 0.0f, -1.0f);
                break;

            case CubeMapFace.NegativeY:
                look = new Vector3(0.0f, -1.0f, 0.0f);
                up   = new Vector3(0.0f, 0.0f, 1.0f);
                break;

            case CubeMapFace.PositiveZ:
                look = new Vector3(0.0f, 0.0f, 1.0f);
                up   = new Vector3(0.0f, 1.0f, 0.0f);
                break;

            case CubeMapFace.NegativeZ:
                look = new Vector3(1.0f, 0.0f, -1.0f);
                up   = new Vector3(0.0f, 1.0f, 0.0f);
                break;

            default:
                break;
            }

            return(Matrix.LookAtLH(pos, look, up));
        }
Exemple #11
0
        private void PlatformSetData <T>(CubeMapFace face, int level, Rectangle rect, T[] data, int startIndex, int elementCount)
        {
            var subarr = new Uint8Array(data.As <ArrayBuffer>(), startIndex.As <uint>(), elementCount.As <uint>());

            gl.bindTexture(gl.TEXTURE_CUBE_MAP, this.glTexture);
            GraphicsExtensions.CheckGLError();

            var target = GetGLCubeFace(face);

            if (glFormat == gl.COMPRESSED_TEXTURE_FORMATS)
            {
                gl.compressedTexSubImage2D(target, level, rect.X, rect.Y, rect.Width, rect.Height, glInternalFormat, subarr);
                GraphicsExtensions.CheckGLError();
            }
            else
            {
                gl.texSubImage2D(target, level, rect.X, rect.Y, rect.Width, rect.Height, glFormat, glType, subarr.As <ArrayBufferView>());
                GraphicsExtensions.CheckGLError();
            }
        }
        private void PlatformSetData <T>(CubeMapFace face, int level, IntPtr dataPtr, int xOffset, int yOffset, int width, int height)
        {
            var box = new DataBox(dataPtr, GetPitch(width), 0);

            int subresourceIndex = (int)face * _levelCount + level;

            var region = new ResourceRegion
            {
                Top    = yOffset,
                Front  = 0,
                Back   = 1,
                Bottom = yOffset + height,
                Left   = xOffset,
                Right  = xOffset + width
            };

            var d3dContext = GraphicsDevice._d3dContext;

            lock (d3dContext)
                d3dContext.UpdateSubresource(box, GetTexture(), subresourceIndex, region);
        }
        public void UpdateAmbient(int index)
        {
            CubeMapFace face        = (CubeMapFace)index;
            Surface     cubeSurface = m_ambientRT.GetCubeMapSurface(face, 0);

            MyRender.GraphicsDevice.SetRenderTarget(0, cubeSurface);
            BlendState.Opaque.Apply();

            MyEffectAmbientPrecalculation precalc = MyRender.GetEffect(MyEffects.AmbientMapPrecalculation) as MyEffectAmbientPrecalculation;

            precalc.SetEnvironmentMap(this.m_environmentRT);
            precalc.SetFaceMatrix((Matrix)CreateViewMatrix(face, Vector3D.Zero));
            precalc.SetRandomTexture(MyRender.GetRandomTexture());
            precalc.SetIterationCount(14);
            precalc.SetMainVectorWeight(1.0f);
            precalc.SetBacklightColorAndIntensity(new Vector3(MyRender.Sun.BackColor.X, MyRender.Sun.BackColor.Y, MyRender.Sun.BackColor.Z), MyRender.Sun.BackIntensity);
            MyRender.GetFullscreenQuad().Draw(precalc);

            MyRender.SetRenderTarget(null, null);
            cubeSurface.Dispose();
        }
        public void Bind(GraphicsDevice device, TextureCube cube, ushort face, ushort miplevel, bool update)
        {
            this.device = device;
            this.cube   = cube;
            this.face   = (CubeMapFace)face;
            mipLevel    = miplevel;

            width  = cube.Size / (int)Utility.Pow(2, mipLevel);
            height = cube.Size / (int)Utility.Pow(2, mipLevel);
            depth  = 1;
            format = XnaHelper.Convert(cube.Format);
            // Default
            rowPitch    = Width;
            slicePitch  = Height * Width;
            sizeInBytes = PixelUtil.GetMemorySize(Width, Height, Depth, Format);

            if (((int)usage & (int)TextureUsage.RenderTarget) != 0)
            {
                CreateRenderTextures(update);
            }
        }
        public void UpdateFace(Vector3D position, int faceIndex)
        {
            //SetRenderSetup();

            CubeMapFace face = (CubeMapFace)faceIndex;

            // New setup
            m_setup.CameraPosition   = position;
            m_setup.AspectRatio      = 1.0f;
            m_setup.Viewport         = new Viewport(0, 0, (int)m_environmentRT.GetLevelDescription(0).Width, (int)m_environmentRT.GetLevelDescription(0).Width);
            m_setup.ViewMatrix       = CreateViewMatrix(face, position);
            m_setup.Fov              = MathHelper.PiOver2;
            m_setup.ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(m_setup.Fov.Value, m_setup.AspectRatio.Value, NearClip, m_setup.LodTransitionBackgroundEnd.Value);
            m_setup.DepthToAlpha     = true;

            MyRender.GetRenderProfiler().StartProfilingBlock("Draw environmental maps");

            MyRender.PushRenderSetupAndApply(m_setup, ref m_backup);
            MyRender.Draw3D(false);

            MyRender.GetRenderProfiler().EndProfilingBlock();

            Surface cubeSurface = m_environmentRT.GetCubeMapSurface(face, 0);

            MyRender.GraphicsDevice.SetRenderTarget(0, cubeSurface);

            var screenEffect = MyRender.GetEffect(MyEffects.Screenshot) as MyEffectScreenshot;

            screenEffect.SetTechnique(MyEffectScreenshot.ScreenshotTechniqueEnum.Default);
            screenEffect.SetSourceTexture(m_fullSizeRT);
            screenEffect.SetScale(new Vector2(m_environmentRT.GetLevelDescription(0).Width / (float)m_fullSizeRT.GetLevelDescription(0).Width, m_environmentRT.GetLevelDescription(0).Height / (float)m_fullSizeRT.GetLevelDescription(0).Height));
            MyRender.GetFullscreenQuad().Draw(screenEffect);
            screenEffect.SetScale(new Vector2(1, 1));

            //Texture.ToFile(m_fullSizeRT, "C:\\fullSizeRT.dds", ImageFileFormat.Dds);

            cubeSurface.Dispose();

            MyRender.PopRenderSetupAndRevert(m_backup);
        }
        MatrixD CreateViewMatrix(CubeMapFace cubeMapFace, Vector3D position)
        {
            MatrixD  viewMatrix = MatrixD.Identity;
            Vector3D pos        = position;

            switch (cubeMapFace)
            {
            // Face index 0
            case CubeMapFace.PositiveX:
                viewMatrix = MatrixD.CreateLookAt(pos, pos + Vector3.Left, -Vector3.Up);
                break;

            // Face index 1
            case CubeMapFace.NegativeX:
                viewMatrix = MatrixD.CreateLookAt(pos, pos + Vector3.Right, -Vector3.Up);
                break;

            // Face index 2
            case CubeMapFace.PositiveY:
                viewMatrix = MatrixD.CreateLookAt(pos, pos + Vector3.Down, Vector3.Backward);
                break;

            // Face index 3
            case CubeMapFace.NegativeY:
                viewMatrix = MatrixD.CreateLookAt(pos, pos + Vector3.Up, Vector3.Forward);
                break;

            // Face index 4
            case CubeMapFace.PositiveZ:
                viewMatrix = MatrixD.CreateLookAt(pos, pos + Vector3.Forward, -Vector3.Up);
                break;

            // Face index 5
            case CubeMapFace.NegativeZ:
                viewMatrix = MatrixD.CreateLookAt(pos, pos + Vector3.Backward, -Vector3.Up);
                break;
            }
            return(viewMatrix);
        }
Exemple #17
0
        private void RenderToIrradianceCubeMapFace(CubeMapFace face)
        {
            var cubeMapFace = irradianceMap.GetCubeMapSurface(face, 0);

            D3DDevice.Instance.Device.SetRenderTarget(0, cubeMapFace);

            TGCMatrix lookAt = LookAtFromCubeMapFace(face, TGCVector3.Empty);

            D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            D3DDevice.Instance.Device.Transform.View = lookAt;

            D3DDevice.Instance.Device.BeginScene();

            unitCube.Render();

            D3DDevice.Instance.Device.EndScene();

            if (save)
            {
                SurfaceLoader.Save(ShadersDir + "irradiancemap_" + face.ToString() + ".bmp", ImageFileFormat.Bmp, cubeMapFace);
            }
        }
        public void DrawShadows()
        {
            Game1.graphicsDevice.BlendState        = BlendState.Opaque;
            Game1.graphicsDevice.DepthStencilState = DepthStencilState.Default;

            Transfer.LightPosition = Position.get();
            Transfer.LightDistance = Scale.get() / 2;

            for (int i = 0; i < 6; i++)
            {
                CubeMapFace CurrentFace = (CubeMapFace)(i);
                Game1.graphicsDevice.SetRenderTarget(ShadowCube.Value, CurrentFace);
                Game1.graphicsDevice.Clear(Color.White);

                foreach (GameObject g in ParentScene.GetList(GameObjectTag._3DShadow))
                {
                    g.Draw3D(ShadowCameras[i], GameObjectTag._3DShadow);
                }
            }

            Game1.graphicsDevice.SetRenderTarget(null);
        }
            public Slice2dArgs( OpsParsedStatement statement)
            {
                OpsParsedArgument nameArg = statement.FindArgument("dst");
                if( nameArg == null )
                {
                    nameArg = statement.FindArgument("");
                    if( nameArg == null )
                        throw OpsException.ArgRequired("dst");
                }
                Dst = nameArg.Value;


                OpsParsedArgument volumeArg = statement.FindArgument("Volume");
                if( volumeArg != null )
                    Volume = int.Parse( volumeArg.Value );

                OpsParsedArgument faceArg = statement.FindArgument("Face");
                if( faceArg != null )
                {
                    if(0==string.Compare( faceArg.Value, "+x", true)) 
                        Face = CubeMapFace.PositiveX;
                    else if(0==string.Compare( faceArg.Value, "+y", true)) 
                        Face = CubeMapFace.PositiveY;
                    else if(0==string.Compare( faceArg.Value, "+z", true)) 
                        Face = CubeMapFace.PositiveZ;
                    else if(0==string.Compare( faceArg.Value, "-x", true)) 
                        Face = CubeMapFace.NegativeX;
                    else if(0==string.Compare( faceArg.Value, "-y", true)) 
                        Face = CubeMapFace.NegativeY;
                    else if(0==string.Compare( faceArg.Value, "-z", true)) 
                        Face = CubeMapFace.NegativeZ;
                    else
                        throw new OpsException("Face Argument was not recognized.  must be '[+-][xyz]'");
                }

                OpsParsedArgument mipsArg = statement.FindArgument("mipmap");
                if( mipsArg != null )
                    Mips = int.Parse( mipsArg.Value );
            }
Exemple #20
0
        /// <summary>
        /// Gets a copy of cube texture data specifying a cubemap face.
        /// </summary>
        /// <typeparam name="T">Generic type for data array element.</typeparam>
        /// <param name="cubeMapFace">The cube map face.</param>
        /// <param name="data">The data.</param>
        public void GetData <T>(
            CubeMapFace cubeMapFace,
            T[] data
            ) where T : struct
        {
            // 4 bytes per pixel
            if (data.Length < Size * Size * 4)
            {
                throw new ArgumentException("data");
            }

            TextureTarget target = GetGLCubeFace(cubeMapFace);

            OpenGLDevice.Instance.BindTexture(texture);
            GL.GetTexImage <T>(
                target,
                0,
                PixelFormat.Bgra,
                PixelType.UnsignedByte,
                data
                );
        }
Exemple #21
0
        public void SetData <T>(CubeMapFace face, int level, Rectangle?rect, T[] data, int startIndex, int elementCount) where T : struct
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            int      num      = Marshal.SizeOf(typeof(T));
            GCHandle gcHandle = GCHandle.Alloc((object)data, GCHandleType.Pinned);
            IntPtr   pixels   = (IntPtr)(gcHandle.AddrOfPinnedObject().ToInt64() + (long)(startIndex * num));
            int      xoffset;
            int      yoffset;
            int      width;
            int      height;

            if (rect.HasValue)
            {
                xoffset = rect.Value.X;
                yoffset = rect.Value.Y;
                width   = rect.Value.Width;
                height  = rect.Value.Height;
            }
            else
            {
                xoffset = 0;
                yoffset = 0;
                width   = Math.Max(1, this.size >> level);
                height  = Math.Max(1, this.size >> level);
            }
            GL.BindTexture(TextureTarget.TextureCubeMap, this.glTexture);
            TextureTarget glCubeFace = this.GetGLCubeFace(face);

            if (this.glFormat == (PixelFormat)34467)
            {
                throw new NotImplementedException();
            }
            GL.TexSubImage2D(glCubeFace, level, xoffset, yoffset, width, height, this.glFormat, this.glType, pixels);
            gcHandle.Free();
        }
        MatrixD CreateViewMatrix(CubeMapFace cubeMapFace, Vector3D position)
        {
            MatrixD viewMatrix = MatrixD.Identity;
            Vector3D pos = position;
            switch (cubeMapFace)
            {
                // Face index 0
                case CubeMapFace.PositiveX:
                    viewMatrix = MatrixD.CreateLookAt(pos, pos + Vector3.Left, -Vector3.Up);
                    break;

                // Face index 1
                case CubeMapFace.NegativeX:
                    viewMatrix = MatrixD.CreateLookAt(pos, pos + Vector3.Right, -Vector3.Up);
                    break;

                // Face index 2
                case CubeMapFace.PositiveY:
                    viewMatrix = MatrixD.CreateLookAt(pos, pos + Vector3.Down, Vector3.Backward);
                    break;

                // Face index 3
                case CubeMapFace.NegativeY:
                    viewMatrix = MatrixD.CreateLookAt(pos, pos + Vector3.Up, Vector3.Forward);
                    break;

                // Face index 4
                case CubeMapFace.PositiveZ:
                    viewMatrix = MatrixD.CreateLookAt(pos, pos + Vector3.Forward, -Vector3.Up);
                    break;

                // Face index 5
                case CubeMapFace.NegativeZ:
                    viewMatrix = MatrixD.CreateLookAt(pos, pos + Vector3.Backward, -Vector3.Up);
                    break;
            }
            return viewMatrix;
        }
Exemple #23
0
        public ImageData GetImageData(CubeMapFace cubeMapFace, int mipmapIndex)
        {
            if (!IsValid || mipmapIndex < 0)
            {
                return(null);
            }

            int faceCount = FaceCount;

            for (int i = 0; i < faceCount; i++)
            {
                Bind();
                IL.ActiveFace(i);
                CubeMapFace face = (CubeMapFace)IL.ilGetInteger(ILDefines.IL_IMAGE_CUBEFLAGS);

                if (face == cubeMapFace)
                {
                    return(ImageData.Load(new Subimage(m_id, 0, i, 0, mipmapIndex)));
                }
            }

            return(null);
        }
Exemple #24
0
        private void RenderToCubeMapFace(CubeMapFace face, TGCVector3 position)
        {
            var cubeMapFace = cubeMap.GetCubeMapSurface(face, 0);

            D3DDevice.Instance.Device.SetRenderTarget(0, cubeMapFace);
            D3DDevice.Instance.Device.DepthStencilSurface = depthStencils[(int)face];

            TGCMatrix lookAt = LookAtFromCubeMapFace(face, position);

            D3DDevice.Instance.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);
            D3DDevice.Instance.Device.Transform.View = lookAt;

            D3DDevice.Instance.Device.BeginScene();

            RenderBaseScene();

            D3DDevice.Instance.Device.EndScene();

            if (save)
            {
                SurfaceLoader.Save(ShadersDir + "cubemap_" + face.ToString() + ".bmp", ImageFileFormat.Bmp, cubeMapFace);
            }
        }
Exemple #25
0
        public void GetData <T>(
            CubeMapFace cubeMapFace,
            int level,
            Rectangle?rect,
            T[] data,
            int startIndex,
            int elementCount
            ) where T : struct
        {
            if (data == null || data.Length == 0)
            {
                throw new ArgumentException("data cannot be null");
            }
            if (data.Length < startIndex + elementCount)
            {
                throw new ArgumentException(
                          "The data passed has a length of " + data.Length.ToString() +
                          " but " + elementCount.ToString() + " pixels have been requested."
                          );
            }

            GCHandle handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            GraphicsDevice.GLDevice.GetTextureDataCube(
                texture,
                Format,
                Size,
                cubeMapFace,
                level,
                rect,
                handle.AddrOfPinnedObject(),
                startIndex,
                elementCount,
                Marshal.SizeOf(typeof(T))
                );
            handle.Free();
        }
 /// <summary>
 /// Converts a (u,v) point to an (x,y,z) coordinate, depending on the value of face
 /// </summary>
 public static void ToXyz( CubeMapFace face, float u, float v, out float x, out float y, out float z )
 {
     switch ( face )
     {
         default:
         case CubeMapFace.NegativeX:
             x = -1;
             y = v;
             z = u;
             break;
         case CubeMapFace.PositiveX:
             x = 1;
             y = v;
             z = -u;
             break;
         case CubeMapFace.NegativeY:
             x = -u;
             y = -1;
             z = -v;
             break;
         case CubeMapFace.PositiveY:
             x = -u;
             y = 1;
             z = v;
             break;
         case CubeMapFace.NegativeZ:
             x = -u;
             y = v;
             z = -1;
             break;
         case CubeMapFace.PositiveZ:
             x = u;
             y = v;
             z = 1;
             break;
     }
 }
Exemple #27
0
        /// <summary>
        ///     Sets the camera orientation based on the cubemap face.
        /// </summary>
        private void SetCubemapCameraForOrientation(CubeMapFace face)
        {
            switch (face)
            {
            default:
            case CubeMapFace.PositiveX:
                CubeMapCamera.FrontDirection = -Vector3.UnitX;
                CubeMapCamera.UpDirection    = Vector3.Down;
                break;

            case CubeMapFace.NegativeX:
                CubeMapCamera.FrontDirection = Vector3.UnitX;
                CubeMapCamera.UpDirection    = Vector3.Down;
                break;

            case CubeMapFace.PositiveY:
                CubeMapCamera.FrontDirection = Vector3.Down;
                CubeMapCamera.UpDirection    = Vector3.UnitZ;
                break;

            case CubeMapFace.NegativeY:
                CubeMapCamera.FrontDirection = Vector3.Up;
                CubeMapCamera.UpDirection    = -Vector3.UnitZ;
                break;

            case CubeMapFace.PositiveZ:
                CubeMapCamera.FrontDirection = -Vector3.UnitZ;
                CubeMapCamera.UpDirection    = Vector3.Down;
                break;

            case CubeMapFace.NegativeZ:
                CubeMapCamera.FrontDirection = Vector3.UnitZ;
                CubeMapCamera.UpDirection    = Vector3.Down;
                break;
            }
        }
Exemple #28
0
        public void SetData <T>(CubeMapFace face, int level, Rectangle?rect, T[] data, int start, int count) where T : struct
        {
            int x, y, w, h;

            if (rect.HasValue)
            {
                x = rect.Value.X;
                y = rect.Value.Y;
                w = rect.Value.Width;
                h = rect.Value.Height;
            }
            else
            {
                x = 0;
                y = 0;
                w = Math.Max(1, Size >> level);
                h = Math.Max(1, Size >> level);
            }
            GL.BindTexture(GL.GL_TEXTURE_CUBE_MAP, ID);
            var handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            GL.TexSubImage2D(face.ToGL(), level, x, y, w, h, glFormat, glType, handle.AddrOfPinnedObject());
            handle.Free();
        }
Exemple #29
0
        private unsafe void PlatformSetData <T>(
            CubeMapFace face, int level, Rectangle rect, ReadOnlySpan <T> data)
            where T : unmanaged
        {
            var subresourceIndex = CalculateSubresourceIndex(face, level);
            int pitch            = GetPitch(rect.Width);
            var region           = new ResourceRegion
            {
                Top    = rect.Top,
                Front  = 0,
                Back   = 1,
                Bottom = rect.Bottom,
                Left   = rect.Left,
                Right  = rect.Right
            };

            var d3dContext = GraphicsDevice._d3dContext;

            lock (d3dContext)
            {
                var     texture     = GetTexture();
                ref var mutableData = ref MemoryMarshal.GetReference(data);
                d3dContext.UpdateSubresource(ref mutableData, texture, subresourceIndex, pitch, 0, region);
            }
Exemple #30
0
        private double GetGLCubeFace(CubeMapFace face)
        {
            switch (face)
            {
            case CubeMapFace.PositiveX:
                return(gl.TEXTURE_CUBE_MAP_POSITIVE_X);

            case CubeMapFace.NegativeX:
                return(gl.TEXTURE_CUBE_MAP_NEGATIVE_X);

            case CubeMapFace.PositiveY:
                return(gl.TEXTURE_CUBE_MAP_POSITIVE_Y);

            case CubeMapFace.NegativeY:
                return(gl.TEXTURE_CUBE_MAP_NEGATIVE_Y);

            case CubeMapFace.PositiveZ:
                return(gl.TEXTURE_CUBE_MAP_POSITIVE_Z);

            case CubeMapFace.NegativeZ:
                return(gl.TEXTURE_CUBE_MAP_NEGATIVE_Z);
            }
            throw new ArgumentException();
        }
Exemple #31
0
 public static extern void bgfx_update_texture_cube(ushort handle, CubeMapFace side, byte mip, ushort x, ushort y, ushort width, ushort height, MemoryBlock.DataPtr* memory, ushort pitch);
 public void Render(RenderTargetCube activeRT, CubeMapFace activeFace)
 {
     targetToRenderToCube = activeRT;
     faceToRenderOn = activeFace;
     this.Render();
 }
 /// <summary>
 /// Creates a face for the marble texture cube map
 /// </summary>
 public unsafe Bitmap CreateMarbleTextureFace( CubeMapFace face, int width, int height )
 {
     if ( !ReadyToUse )
     {
         throw new InvalidOperationException( "Planet terrain model has not yet been set up - can't generate marble cube map" );
     }
     Bitmap bmp = new Bitmap( width, height, PixelFormat.Format24bppRgb );
     BitmapData bmpData = bmp.LockBits( new Rectangle( 0, 0, width, height ), ImageLockMode.WriteOnly, bmp.PixelFormat );
     byte* pixels = ( byte* )bmpData.Scan0;
     m_Gen.GenerateTerrainPropertyCubeMapFace( face, width, height, bmpData.Stride, pixels );
     bmp.UnlockBits( bmpData );
     return bmp;
 }
        //Write texture data to stream if the texture is a 2d texture the face is ignored.
        private static void WriteTexture(BinaryWriter writer, CubeMapFace face, Texture texture, int mipLevel, int depth, int width, int height, bool isCompressed, FourCC fourCC, int rgbBitCount)
        {
            int size = MipMapSizeInBytes(mipLevel, width, height, isCompressed, fourCC, rgbBitCount);
            byte[] data = mipData;
            if (data == null || data.Length < size)
            {
                data = new byte[size];
            }

            if (texture is TextureCube)
            {
                (texture as TextureCube).GetData<byte>(face, mipLevel, null, data, 0, size);
            }
            if (texture is Texture2D)
            {
                (texture as Texture2D).GetData<byte>(mipLevel, null, data, 0, size);
            }
            if (texture is Texture3D)
            {
                Texture3D tex = (texture as Texture3D);
                int localWidth = MipMapSize(mipLevel, width);
                int localHeight = MipMapSize(mipLevel, height);

                tex.GetData<byte>(mipLevel, 0, 0, localWidth, localHeight, depth, depth + 1, data, 0, size);
            }


#if COLOR_SAVE_TO_ARGB
            if (texture.Format == SurfaceFormat.Color)
            {
                byte g, b;
                for (int k = 0; k < size - 3; k += 4)
                {
                    g = data[k];
                    b = data[k + 2];
                    data[k] = b;
                    data[k + 2] = g;
                }
            }
#endif

            writer.Write(data, 0, size);
            //for (int j = 0; j < size; j++)
            //{
            //    writer.Write(data[j]);
            //}
            mipData = data;


        }
Exemple #35
0
 public void GetData <T>(CubeMapFace cubeMapFace, T[] data) where T : struct
 {
     throw new NotImplementedException();
 }
		/// <summary>
		/// Gets if rendering to a cube face is enabled
		/// </summary>
		/// <param name="face"></param>
		/// <returns></returns>
		public bool GetFaceRenderEnabled(CubeMapFace face)
		{
			return facesEnabled[(int)face];
		}
Exemple #37
0
 /// <summary>
 /// Adds a dirty region to a cube texture resource.
 /// </summary>
 /// <param name="faceType">Type of the face.</param>
 public void AddDirtyRect(CubeMapFace faceType)
 {
     AddDirtyRect(faceType, null);
 }
Exemple #38
0
		public void SetTextureDataCube(
			IGLTexture texture,
			SurfaceFormat format,
			int xOffset,
			int yOffset,
			int width,
			int height,
			CubeMapFace cubeMapFace,
			int level,
			IntPtr data,
			int startIndex,
			int elementCount,
			int elementSizeInBytes
		) {
#if !DISABLE_THREADING
			ForceToMainThread(() => {
#endif
			BindTexture(texture);

			GLenum glFormat = XNAToGL.TextureFormat[(int) format];
			if (glFormat == GLenum.GL_COMPRESSED_TEXTURE_FORMATS)
			{
				/* Note that we're using glInternalFormat, not glFormat.
				 * In this case, they should actually be the same thing,
				 * but we use glFormat somewhat differently for
				 * compressed textures.
				 * -flibit
				 */
				glCompressedTexSubImage2D(
					GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
					level,
					xOffset,
					yOffset,
					width,
					height,
					XNAToGL.TextureInternalFormat[(int) format],
					elementCount * elementSizeInBytes,
					data + (startIndex * elementSizeInBytes)
				);
			}
			else
			{
				glTexSubImage2D(
					GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
					level,
					xOffset,
					yOffset,
					width,
					height,
					glFormat,
					XNAToGL.TextureDataType[(int) format],
					data + (startIndex * elementSizeInBytes)
				);
			}

#if !DISABLE_THREADING
			});
#endif
		}
Exemple #39
0
		public void GetTextureDataCube(
			IGLTexture texture,
			SurfaceFormat format,
			int size,
			CubeMapFace cubeMapFace,
			int level,
			Rectangle? rect,
			IntPtr data,
			int startIndex,
			int elementCount,
			int elementSizeInBytes
		) {
#if !DISABLE_THREADING
			ForceToMainThread(() => {
#endif

			BindTexture(texture);
			GLenum glFormat = XNAToGL.TextureFormat[(int) format];
			if (glFormat == GLenum.GL_COMPRESSED_TEXTURE_FORMATS)
			{
				throw new NotImplementedException("GetData, CompressedTexture");
			}
			else if (rect == null)
			{
				// Just throw the whole texture into the user array.
				glGetTexImage(
					GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
					0,
					glFormat,
					XNAToGL.TextureDataType[(int) format],
					data
				);
			}
			else
			{
				// Get the whole texture...
				IntPtr texData = Marshal.AllocHGlobal(size * size * elementSizeInBytes);
				glGetTexImage(
					GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int) cubeMapFace,
					0,
					glFormat,
					XNAToGL.TextureDataType[(int) format],
					texData
				);

				// Now, blit the rect region into the user array.
				Rectangle region = rect.Value;
				int curPixel = -1;
				for (int row = region.Y; row < region.Y + region.Height; row += 1)
				{
					for (int col = region.X; col < region.X + region.Width; col += 1)
					{
						curPixel += 1;
						if (curPixel < startIndex)
						{
							// If we're not at the start yet, just keep going...
							continue;
						}
						if (curPixel > elementCount)
						{
							// If we're past the end, we're done!
							return;
						}
						// FIXME: Can we copy via pitch instead, or something? -flibit
						memcpy(
							data + ((curPixel - startIndex) * elementSizeInBytes),
							texData + (((row * size) + col) * elementSizeInBytes),
							(IntPtr) elementSizeInBytes
						);
					}
				}
				Marshal.FreeHGlobal(texData);
			}

#if !DISABLE_THREADING
			});
#endif
		}
        private void GetCubeHeights()
        {
            CubeMapFace[] orients = new CubeMapFace[] {
                CubeMapFace.PositiveY,
                CubeMapFace.NegativeY,
                CubeMapFace.PositiveZ,
                CubeMapFace.NegativeZ,
                CubeMapFace.NegativeX,
                CubeMapFace.PositiveX
            };
            cubeHeights = new float[6][,];

            for (int orientation = 0; orientation < 6; orientation++) {
                /*// Extract pixel data
                Color[] heightMapData = new Color[width * length];
                heightMap.GetData<Color>(heightMapData);
                // Create heights[,] array
                heights = new float[width, length];
                // For each pixel
                for (int y = 0; y < length; y++) {
                    for (int x = 0; x < width; x++) {
                        // Get color value (0 - 255)
                        float amt = heightMapData[y * width + x].R;
                        // Scale to (0 - 1)
                        amt /= 255.0f;
                        // Multiply by max height to get final height
                        heights[x, y] = amt * height + BaseHeight;// 指定された高さからのheightにしたver
                        //heights[x, y] = amt * height;
                    }
                }*/

                Color[] heightMapData = new Color[width * length];
                heightMapCube.GetData<Color>(orients[orientation], heightMapData);

                // Create heights[,] array
                cubeHeights[orientation] = new float[width, length];

                // For each pixel
                for (int y = 0; y < length; y++) {
                    for (int x = 0; x < width; x++) {
                        // Get color value (0 - 255)
                        float amt = heightMapData[y * width + x].R;
                        // Scale to (0 - 1)
                        amt /= 255.0f;
                        // Multiply by max height to get final height
                        cubeHeights[orientation][x, y] = amt * height + BaseHeight;// 指定された高さからのheightにしたver
                        //heights[x, y] = amt * height;
                    }
                }
            }
        }
 internal static void DrawSprite(BaseTexture texture, CubeMapFace? face, ref RectangleF destination, bool scaleDestination, ref Rectangle? sourceRectangle, Color color, Vector2 rightVector, ref Vector2 origin, VRageRender.Graphics.SpriteEffects effects, float depth)
 {
     DrawSpriteMain(texture, face, ref destination, scaleDestination, sourceRectangle, color, rightVector, ref origin, effects, depth);
 }
        private static void DrawSpriteMain(BaseTexture texture, CubeMapFace? face, ref RectangleF destination, bool scaleDestination, Rectangle? sourceRectangle, Color color, Vector2 rightVector, ref Vector2 origin, SpriteEffects effects, float depth)
        {
            if (m_screenshot != null && m_screenshot.IgnoreSprites)
                return;

            m_spriteBatch.DrawSprite(
                texture,
                face,
                ref destination,
                scaleDestination,
                sourceRectangle,
                color,
                rightVector,
                ref origin,
                effects,
                depth);
        }
 Vector3 GetCubeMapDir(CubeMapFace face)
 {
     switch (face)
     {
         case CubeMapFace.PositiveX:
             return Vector3.Right;
         case CubeMapFace.NegativeX:
             return Vector3.Left;
         case CubeMapFace.PositiveY:
             return Vector3.Up;
         case CubeMapFace.NegativeY:
             return Vector3.Down;
         case CubeMapFace.PositiveZ:
             return Vector3.Forward;
         case CubeMapFace.NegativeZ:
             return Vector3.Backward;
     }
     return Vector3.Forward;
 }
		/// <summary>
		/// Gets the matrix that represents the rotation of a cubemap face
		/// </summary>
		/// <param name="face"></param>
		/// <param name="matrix"></param>
		public static void GetCubeMapFaceMatrix(CubeMapFace face, out Matrix matrix)
		{
			matrix = CubeMapFaceMatrices[(int)face];
		}
        Vector3 GetCubeMapUp(CubeMapFace face)
        {
            switch (face)
            {
                case CubeMapFace.PositiveY:
                    return Vector3.Backward;
                case CubeMapFace.NegativeY:
                    return Vector3.Forward;
            }

            return Vector3.Up;
        }
        public static void CopyToCubeSide(OpsContext context, CubeTexture newTexture, string srcArg, CubeMapFace face, Filter filter)
        {
            if(srcArg == null || srcArg.Length == 0)
                return;

            OpsTexture src = context.GetTexture(srcArg);
                
            if(src == null)
                throw new OpsException("Could not find source texture: "+srcArg );

            if(src.Texture is CubeTexture)
            {
                SurfaceLoader.FromSurface(newTexture.GetCubeMapSurface(face, 0), ((CubeTexture)src.Texture).GetCubeMapSurface(face,0), filter| (src.SRGB?Filter.SrgbIn:0), 0);             
            }
            else if (src.Texture is Texture)
            {
                SurfaceLoader.FromSurface(newTexture.GetCubeMapSurface(face, 0), ((Texture)src.Texture).GetSurfaceLevel(0), filter| (src.SRGB?Filter.SrgbIn:0), 0);             
            }
            else
                throw new OpsException("Source texture is not a texture2D: "+srcArg);

        }
Exemple #47
0
 /// <summary>
 /// Adds a dirty region to a cube texture resource.
 /// </summary>
 /// <param name="faceType">Type of the face.</param>
 /// <param name="dirtyRect">The dirty rectangle.</param>
 public void AddDirtyRect(CubeMapFace faceType, in RectI dirtyRect)
Exemple #48
0
 public static extern void bgfx_update_texture_cube(ushort handle, CubeMapFace side, ushort layer, byte mip, ushort x, ushort y, ushort width, ushort height, MemoryBlock.DataPtr *memory, ushort pitch);
		/// <summary>
		/// Set enabled/disabled rendering to a cubemap face
		/// </summary>
		/// <param name="face"></param>
		/// <param name="enabled"></param>
		public void SetFaceRenderEnabled(CubeMapFace face, bool enabled)
		{
			if (facesEnabled[(int)face] != enabled)
			{
				facesEnabled[(int)face] = enabled;
				ComputeEnabledFaces();
			}
		}
Exemple #50
0
 //Stripped from the internet.
 public Matrix GetViewMatrix(CubeMapFace face) {
     Vector3 pos = new Vector3(this.Position.X, this.Position.Y, this.Position.Z);
     Matrix viewMatrix = Matrix.Identity;
     switch (face) {
         case CubeMapFace.NegativeX: {
                 viewMatrix = Matrix.CreateLookAt(pos, Vector3.Left, Vector3.Up);
                 break;
             }
         case CubeMapFace.NegativeY: {
                 viewMatrix = Matrix.CreateLookAt(pos, Vector3.Down, Vector3.Forward);
                 break;
             }
         case CubeMapFace.NegativeZ: {
                 viewMatrix = Matrix.CreateLookAt(pos, Vector3.Backward, Vector3.Up);
                 break;
             }
         case CubeMapFace.PositiveX: {
                 viewMatrix = Matrix.CreateLookAt(pos, Vector3.Right, Vector3.Up);
                 break;
             }
         case CubeMapFace.PositiveY: {
                 viewMatrix = Matrix.CreateLookAt(pos, Vector3.Up, Vector3.Backward);
                 break;
             }
         case CubeMapFace.PositiveZ: {
                 viewMatrix = Matrix.CreateLookAt(pos, Vector3.Forward, Vector3.Up);
                 break;
             }
     }
     return viewMatrix;
 }
Exemple #51
0
            public void UpdateShadow()
            {
                if (shadowMap == null)
                {
                    shadowMap = new RenderTargetCube(Game1.instance.GraphicsDevice, 64, false, SurfaceFormat.Rg32, DepthFormat.Depth16);
                }
                needUpdate = false;

                Effect effect = Game1.instance.fxShadowPass;

                effect.CurrentTechnique = effect.Techniques[0];

                // We need to render the whole shabam 6 times
                Matrix projMatrix = Matrix.CreatePerspectiveFieldOfView(
                    MathHelper.PiOver2, 1, 1, mo.infol.light.radius);
                Matrix viewMatrix = Matrix.Identity;

                int lump;

                r_local.spritedef_t   sprdef;
                r_local.spriteframe_t sprframe;
                sprdef   = r_thing.sprites[(int)mo.sprite];
                sprframe = sprdef.spriteframes[mo.frame & DoomDef.FF_FRAMEMASK];
                lump     = sprframe.lump[0];
                Texture2D texture = w_wad.W_CacheLumpNum(lump + r_data.firstspritelump, DoomDef.PU_CACHE).cache as Texture2D;

                lightPos = new Vector3(
                    mo.x >> DoomDef.FRACBITS,
                    mo.y >> DoomDef.FRACBITS,
                    ((mo.z + r_data.spritetopoffset[lump]) >> DoomDef.FRACBITS) - texture.Height / 2);
                effect.Parameters["lightPos"].SetValue(lightPos);
                effect.Parameters["radius"].SetValue(mo.infol.light.radius);

                for (int i = 0; i < 6; i++)
                {
                    // render the scene to all cubemap faces
                    CubeMapFace cubeMapFace = (CubeMapFace)i;

                    switch (cubeMapFace)
                    {
                    case CubeMapFace.NegativeX:
                    {
                        viewMatrix = Matrix.CreateLookAt(lightPos, lightPos + Vector3.Left, Vector3.Up);
                        break;
                    }

                    case CubeMapFace.NegativeY:
                    {
                        viewMatrix = Matrix.CreateLookAt(lightPos, lightPos + Vector3.Down, Vector3.Forward);
                        break;
                    }

                    case CubeMapFace.NegativeZ:
                    {
                        viewMatrix = Matrix.CreateLookAt(lightPos, lightPos + Vector3.Backward, Vector3.Up);
                        break;
                    }

                    case CubeMapFace.PositiveX:
                    {
                        viewMatrix = Matrix.CreateLookAt(lightPos, lightPos + Vector3.Right, Vector3.Up);
                        break;
                    }

                    case CubeMapFace.PositiveY:
                    {
                        viewMatrix = Matrix.CreateLookAt(lightPos, lightPos + Vector3.Up, Vector3.Backward);
                        break;
                    }

                    case CubeMapFace.PositiveZ:
                    {
                        viewMatrix = Matrix.CreateLookAt(lightPos, lightPos + Vector3.Forward, Vector3.Up);
                        break;
                    }
                    }

                    effect.Parameters["matWorldViewProj"].SetValue(viewMatrix * projMatrix);
                    effect.CurrentTechnique.Passes[0].Apply();

                    // Set the cubemap render target, using the selected face
                    Game1.instance.GraphicsDevice.SetRenderTarget(shadowMap, cubeMapFace);
                    Game1.instance.GraphicsDevice.Clear(Color.White);
                    Game1.instance.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

                    DrawScene();
                }
            }
Exemple #52
0
 public void SetData <T>(CubeMapFace face, T[] data, int startIndex, int elementCount) where T : struct
 {
     this.SetData <T>(face, 0, new Rectangle?(), data, startIndex, elementCount);
 }
Exemple #53
0
            public Splice2dArgs(OpsParsedStatement statement)
            {
                OpsParsedArgument dstArg = statement.FindArgument("dst");

                if (dstArg == null)
                {
                    dstArg = statement.FindArgument("");
                    if (dstArg == null)
                    {
                        throw OpsException.ArgRequired("dst");
                    }
                }
                Dst = dstArg.Value;

                OpsParsedArgument volumeArg = statement.FindArgument("Volume");

                if (volumeArg != null)
                {
                    Volume = int.Parse(volumeArg.Value);
                }

                OpsParsedArgument faceArg = statement.FindArgument("Face");

                if (faceArg != null)
                {
                    if (0 == string.Compare(faceArg.Value, "+x", true))
                    {
                        Face = CubeMapFace.PositiveX;
                    }
                    else if (0 == string.Compare(faceArg.Value, "+y", true))
                    {
                        Face = CubeMapFace.PositiveY;
                    }
                    else if (0 == string.Compare(faceArg.Value, "+z", true))
                    {
                        Face = CubeMapFace.PositiveZ;
                    }
                    else if (0 == string.Compare(faceArg.Value, "-x", true))
                    {
                        Face = CubeMapFace.NegativeX;
                    }
                    else if (0 == string.Compare(faceArg.Value, "-y", true))
                    {
                        Face = CubeMapFace.NegativeY;
                    }
                    else if (0 == string.Compare(faceArg.Value, "-z", true))
                    {
                        Face = CubeMapFace.NegativeZ;
                    }
                    else
                    {
                        throw new OpsException("Face Argument was not recognized.  must be '[+-][xyz]'");
                    }
                }

                OpsParsedArgument mipsArg = statement.FindArgument("mipmap");

                if (mipsArg != null)
                {
                    Mips = int.Parse(mipsArg.Value);
                }
            }
        /// <summary>
        /// Converts a given cube map face to a bitmap
        /// </summary>
        public Bitmap ToBitmap( CubeMapFace face )
        {
            if ( m_Handle == -1 )
            {
                GraphicsLog.Warning( "COuld not convert cube map texture to images - handle was invalid" );
                return null;
            }

            Gl.glEnable( Gl.GL_TEXTURE_CUBE_MAP );
            Gl.glBindTexture( Gl.GL_TEXTURE_CUBE_MAP, m_Handle );

            Bitmap result = GetFaceBitmap( GetGlCubeFaceEnum( face ) );

            Gl.glDisable( Gl.GL_TEXTURE_CUBE_MAP );

            return result;
        }
Exemple #55
0
 public void SetData <T>(CubeMapFace face, T[] data) where T : struct
 {
     this.SetData <T>(face, 0, new Rectangle?(), data, 0, data.Length);
 }
        //Write texture data to stream if the texture is a 2d texture the face is ignored.
        private static void WriteTexture(BinaryWriter writer, CubeMapFace face, Texture texture, bool saveMipMaps, int width, int height, bool isCompressed, FourCC fourCC, int rgbBitCount)
        {
            int numMip = texture.LevelCount;
            numMip = saveMipMaps ? numMip : 1;

            for (int i = 0; i < numMip; i++)
            {
                int size = MipMapSizeInBytes(i, width, height, isCompressed, fourCC, rgbBitCount);
                byte[] data = mipData;
                if (data == null || data.Length < size)
                {
                    data = new byte[size];
                }

                if (texture is TextureCube)
                {
                    (texture as TextureCube).GetData<byte>(face, i, null, data, 0, size);
                }
                if (texture is Texture2D)
                {
                    (texture as Texture2D).GetData<byte>(i, null, data, 0, size);
                }


#if COLOR_SAVE_TO_ARGB
                if (texture.Format == SurfaceFormat.Color)
                {
                    byte g, b;
                    for (int k = 0; k < size - 3; k += 4)
                    {
                        g = data[k];
                        b = data[k + 2];
                        data[k] = b;
                        data[k + 2] = g;
                    }
                }
#endif

                writer.Write(data, 0, size);
                //for (int j = 0; j < size; j++)
                //{
                //    writer.Write(data[j]);
                //}
                mipData = data;
            }

        }
 /// <summary>
 /// Gets the camera up direction for rendering into a cube map face.
 /// </summary>
 /// <param name="cubeMapFace">The cube map face.</param>
 /// <returns>
 /// The camera up direction required to render the content of the
 /// given cube map face.
 /// </returns>
 public static Vector3F GetCubeMapUpDirection(CubeMapFace cubeMapFace)
 {
     return CubeMapUpDirections[(int)cubeMapFace];
 }
Exemple #58
0
 /// <summary>
 /// Loads a texture from Content and asign it to the cubemaps face.
 /// </summary>
 /// <param name="cubeMap"></param>
 /// <param name="filepath"></param>
 /// <param name="face"></param>
 private void LoadCubemapFace(TextureCube cubeMap, string filepath, CubeMapFace face)
 {
     Texture2D texture = content.Load<Texture2D>(filepath);
     byte[] data = new byte[texture.Width * texture.Height * 4];
     texture.GetData<byte>(data);
     cubeMap.SetData<byte>(face, data);
 }
 public void SetCubeMapTarget(RenderTargetCube cubemap, CubeMapFace faceMode)
 {
     this.cubeMapRef = cubemap;
     this.cubeMapFace = faceMode;
     this.ReflectionMap.Dispose();
     this.ReflectionMap = null;
 }
        public void Bind( GraphicsDevice device, TextureCube cube, ushort face, ushort miplevel, bool update )
        {
            this.device = device;
            this.cube = cube;
            this.face = (CubeMapFace)face;
            mipLevel = miplevel;

            width = cube.Size/(int)Utility.Pow( 2, mipLevel );
            height = cube.Size/(int)Utility.Pow( 2, mipLevel );
            depth = 1;
            format = XnaHelper.Convert( cube.Format );
            // Default
            rowPitch = Width;
            slicePitch = Height*Width;
            sizeInBytes = PixelUtil.GetMemorySize( Width, Height, Depth, Format );

            if ( ( (int)usage & (int)TextureUsage.RenderTarget ) != 0 )
            {
                CreateRenderTextures( update );
            }
        }