Example #1
0
        private Shader(GraphicsDevice device, ShaderStage shaderStage, byte[] shaderStageBytecode)
            : base(device)
        {
            this.stage = shaderStage;

            var shaderStageGl = ConvertShaderStage(shaderStage);

            // Decode shader StageBytecode
            var binarySerializationReader = new BinarySerializationReader(new MemoryStream(shaderStageBytecode));
            var shaderBytecodeData = new OpenGLShaderBytecodeData();
            shaderBytecodeData.Serialize(binarySerializationReader, ArchiveMode.Deserialize);

            using (GraphicsDevice.UseOpenGLCreationContext())
            {
                resourceId = GL.CreateShader(shaderStageGl);

                if (shaderBytecodeData.IsBinary)
                {
                    GL.ShaderBinary(1, ref resourceId, (BinaryFormat)shaderBytecodeData.BinaryFormat, shaderBytecodeData.Binary, shaderBytecodeData.Binary.Length);
                }
                else
                {
                    GL.ShaderSource(resourceId, shaderBytecodeData.Source);
                    GL.CompileShader(resourceId);

                    var log = GL.GetShaderInfoLog(resourceId);

                    int compileStatus;
                    GL.GetShader(resourceId, ShaderParameter.CompileStatus, out compileStatus);

                    if (compileStatus != 1)
                        throw new InvalidOperationException(string.Format("Error while compiling GLSL shader: {0}", log));
                }
            }
        }
Example #2
0
        private Shader(GraphicsDevice device, ShaderStage shaderStage, byte[] shaderBytecode)
            : base(device)
        {
            this.stage = shaderStage;

            switch (shaderStage)
            {
                case ShaderStage.Vertex:
                    NativeDeviceChild = new VertexShader(device.NativeDevice, shaderBytecode);
                    NativeInputSignature = shaderBytecode;
                    break;
                case ShaderStage.Hull:
                    NativeDeviceChild = new HullShader(device.NativeDevice, shaderBytecode);
                    break;
                case ShaderStage.Domain:
                    NativeDeviceChild = new DomainShader(device.NativeDevice, shaderBytecode);
                    break;
                case ShaderStage.Geometry:
                    NativeDeviceChild = new GeometryShader(device.NativeDevice, shaderBytecode);
                    break;
                case ShaderStage.Pixel:
                    NativeDeviceChild = new PixelShader(device.NativeDevice, shaderBytecode);
                    break;
                case ShaderStage.Compute:
                    NativeDeviceChild = new ComputeShader(device.NativeDevice, shaderBytecode);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("shaderStage");
            }
        }
Example #3
0
        /// <summary>
        /// Creates a texture from an image file data (png, dds, ...).
        /// </summary>
        /// <param name="graphicsDevice">The graphics device in which to create the texture</param>
        /// <param name="data">The image file data</param>
        /// <returns>The texture</returns>
        public static Texture FromFileData(GraphicsDevice graphicsDevice, byte[] data)
        {
            Texture result;

            var loadAsSRgb = graphicsDevice.ColorSpace == ColorSpace.Linear;

            using (var imageStream = new MemoryStream(data))
            {
                using (var image = Image.Load(imageStream, loadAsSRgb))
                {
                    result = Texture.New(graphicsDevice, image);
                }
            }

            result.Reload = graphicsResource =>
            {
                using (var imageStream = new MemoryStream(data))
                {
                    using (var image = Image.Load(imageStream, loadAsSRgb))
                    {
                        ((Texture)graphicsResource).Recreate(image.ToDataBox());
                    }
                }
            };

            return result;
        }
        internal DepthStencilBuffer(GraphicsDevice device, Texture2D depthTexture, bool isReadOnly) : base(device)
        {
            DescriptionInternal = depthTexture.Description;
            depthTexture.AddReferenceInternal();
            Texture = depthTexture;

            resourceId = Texture.ResourceId;

            if (Description.Format == PixelFormat.D24_UNorm_S8_UInt ||
                Description.Format == PixelFormat.D32_Float_S8X24_UInt)
            {
                IsDepthBuffer = true;
                IsStencilBuffer = true;
            }
            else if (Description.Format == PixelFormat.D32_Float || 
                     Description.Format == PixelFormat.D16_UNorm)
            {
                IsDepthBuffer = true;
                IsStencilBuffer = false;
            }
            else 
                throw new NotSupportedException("The provided depth stencil format is currently not supported"); // implement composition for other formats


#if !SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
            if (isReadOnly)
            {
                if (device.versionMajor < 4)
                {
                    needReadOnlySynchronization = true;
                    throw new NotImplementedException();
                }
            }
#endif
        }
        public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters)
        {
            gameWindow = (iPhoneOSGameView)Description.DeviceWindowHandle.NativeHandle;
            device.InitDefaultRenderTarget(presentationParameters);

            backBuffer = Texture.New2D(device, Description.BackBufferWidth, Description.BackBufferHeight, presentationParameters.BackBufferFormat, TextureFlags.RenderTarget | TextureFlags.ShaderResource);
        }
        private DepthStencilState(GraphicsDevice device, DepthStencilStateDescription depthStencilStateDescription)
            : base(device)
        {
            Description = depthStencilStateDescription;

            depthFunction = Description.DepthBufferFunction.ToOpenGLDepthFunction();
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BlendStateFactory"/> class.
        /// </summary>
        /// <param name="device">The device.</param>
        internal BlendStateFactory(GraphicsDevice device)
        {
            var blendDescription = new BlendStateDescription(Blend.One, Blend.Zero);
            blendDescription.SetDefaults();
            Default = BlendState.New(device, blendDescription).DisposeBy(device);
            Default.Name = "Default";

            Additive = BlendState.New(device, new BlendStateDescription(Blend.SourceAlpha, Blend.One)).DisposeBy(device);
            Additive.Name = "Additive";

            AlphaBlend = BlendState.New(device, new BlendStateDescription(Blend.One, Blend.InverseSourceAlpha)).DisposeBy(device);
            AlphaBlend.Name = "AlphaBlend";

            NonPremultiplied = BlendState.New(device, new BlendStateDescription(Blend.SourceAlpha, Blend.InverseSourceAlpha)).DisposeBy(device);
            NonPremultiplied.Name = "NonPremultiplied";

            Opaque = BlendState.New(device, new BlendStateDescription(Blend.One, Blend.Zero)).DisposeBy(device);
            Opaque.Name = "Opaque";

            var colorDisabledDescription = new BlendStateDescription();
            colorDisabledDescription.SetDefaults();
            colorDisabledDescription.RenderTargets[0].ColorWriteChannels = ColorWriteChannels.None;
            ColorDisabled = BlendState.New(device, colorDisabledDescription).DisposeBy(device);
            ColorDisabled.Name = "ColorDisabled";
        }
 public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters)
 {
     gameWindow = (iPhoneOSGameView)Description.DeviceWindowHandle.NativeHandle;
     device.InitDefaultRenderTarget(presentationParameters);
     backBuffer = device.DefaultRenderTarget;
     DepthStencilBuffer = device.windowProvidedDepthTexture;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="DepthStencilState"/> class.
        /// </summary>
        /// <param name="depthEnable">if set to <c>true</c> [depth enable].</param>
        /// <param name="depthWriteEnable">if set to <c>true</c> [depth write enable].</param>
        /// <param name="name">The name.</param>
        private DepthStencilState(GraphicsDevice device, DepthStencilStateDescription depthStencilStateDescription)
            : base(device)
        {
            Description = depthStencilStateDescription;

            CreateNativeDeviceChild();
        }
Example #10
0
        public override MeshDraw CreateDebugPrimitive(GraphicsDevice device)
        {
            if (cachedDebugPrimitive != null) return cachedDebugPrimitive;

            var verts = new VertexPositionNormalTexture[pointsList.Count];
            for (var i = 0; i < pointsList.Count; i++)
            {
                verts[i].Position = pointsList[i];
                verts[i].TextureCoordinate = Vector2.Zero;
                verts[i].Normal = Vector3.Zero;
            }

            var intIndices = indicesList.Select(x => (int)x).ToArray();

            ////calculate basic normals
            ////todo verify, winding order might be wrong?
            for (var i = 0; i < indicesList.Count; i += 3)
            {
                var i1 = intIndices[i];
                var i2 = intIndices[i + 1];
                var i3 = intIndices[i + 2];
                var a = verts[i1];
                var b = verts[i2];
                var c = verts[i3];
                var n = Vector3.Cross((b.Position - a.Position), (c.Position - a.Position));
                n.Normalize();
                verts[i1].Normal = verts[i2].Normal = verts[i3].Normal = n;
            }

            var meshData = new GeometricMeshData<VertexPositionNormalTexture>(verts, intIndices, false);

            cachedDebugPrimitive = new GeometricPrimitive(device, meshData).ToMeshDraw();

            return cachedDebugPrimitive;
        }
        internal GraphicsDeviceFeatures(GraphicsDevice deviceRoot)
        {
            mapFeaturesPerFormat = new FeaturesPerFormat[256];

            IsProfiled = false;

            using (deviceRoot.UseOpenGLCreationContext())
            {
                Vendor = GL.GetString(StringName.Vendor);
                Renderer = GL.GetString(StringName.Renderer);
#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
                SupportedExtensions = GL.GetString(StringName.Extensions).Split(' ');
#else
                int numExtensions;
                GL.GetInteger(GetPName.NumExtensions, out numExtensions);
                SupportedExtensions = new string[numExtensions];
                for (int extensionIndex = 0; extensionIndex < numExtensions; ++extensionIndex)
                {
                    SupportedExtensions[extensionIndex] = GL.GetString(StringName.Extensions, extensionIndex);
                }
#endif
            }

#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
            var isOpenGLES3 = deviceRoot.versionMajor >= 3;

            deviceRoot.HasDepth24 = isOpenGLES3 || SupportedExtensions.Contains("GL_OES_depth24");
            deviceRoot.HasPackedDepthStencilExtension = SupportedExtensions.Contains("GL_OES_packed_depth_stencil");
            deviceRoot.HasExtTextureFormatBGRA8888 = SupportedExtensions.Contains("GL_EXT_texture_format_BGRA8888")
                                       || SupportedExtensions.Contains("GL_APPLE_texture_format_BGRA8888");
            deviceRoot.HasRenderTargetFloat = SupportedExtensions.Contains("GL_EXT_color_buffer_float");
            deviceRoot.HasRenderTargetHalf = SupportedExtensions.Contains("GL_EXT_color_buffer_half_float");
            deviceRoot.HasVAO = isOpenGLES3 || SupportedExtensions.Contains("GL_OES_vertex_array_object");

            // Compute shaders available in OpenGL ES 3.1
            HasComputeShaders = isOpenGLES3 && deviceRoot.versionMinor >= 1;
            HasDoublePrecision = false;
            
            // TODO: from 3.1: draw indirect, separate shader object
            // TODO: check tessellation & geometry shaders: GL_ANDROID_extension_pack_es31a
#else
            deviceRoot.HasVAO = true;

            // Compute shaders available in OpenGL 4.3
            HasComputeShaders = deviceRoot.versionMajor >= 4 && deviceRoot.versionMinor >= 3;
            HasDoublePrecision = SupportedExtensions.Contains("GL_ARB_vertex_attrib_64bit");

            // TODO: from 4.0: tessellation, draw indirect
            // TODO: from 4.1: separate shader object
#endif
            
            HasDriverCommandLists = false;
            HasMultiThreadingConcurrentResources = false;

            // TODO: Enum supported formats in mapFeaturesPerFormat

            // Find shader model based on OpenGL version (might need to check extensions more carefully)
            Profile = OpenGLUtils.GetFeatureLevel(deviceRoot.versionMajor, deviceRoot.versionMinor);
        }
Example #12
0
        protected internal Texture3D(GraphicsDevice device, TextureDescription description3D, DataBox[] dataBoxes = null) : base(device, description3D, ViewType.Full, 0, 0)
        {
#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
            throw new NotImplementedException();
#else
            Target = TextureTarget.Texture3D;
#endif
        }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Buffer" /> class.
 /// </summary>
 /// <param name="device">The <see cref="GraphicsDevice"/>.</param>
 /// <param name="description">The description.</param>
 /// <param name="bufferFlags">Type of the buffer.</param>
 /// <param name="viewFormat">The view format.</param>
 /// <param name="dataPointer">The data pointer.</param>
 protected Buffer(GraphicsDevice device, BufferDescription description, BufferFlags bufferFlags, PixelFormat viewFormat, IntPtr dataPointer) : base(device)
 {
     Description = description;
     BufferFlags = bufferFlags;
     ViewFormat = viewFormat;
     //InitCountAndViewFormat(out this.elementCount, ref ViewFormat);
     //Initialize(device.RootDevice, null);
 }
Example #14
0
        protected internal Texture3D(GraphicsDevice device, Texture3D texture) : base(device, texture, ViewType.Full, 0, 0)
        {
#if SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
            throw new NotImplementedException();
#else
            Target = TextureTarget.Texture3D;
#endif
        }
Example #15
0
 public PhysicsDebugEffect(GraphicsDevice graphicsDevice)
     : base(graphicsDevice, bytecode ?? (bytecode = EffectBytecode.FromBytesSafe(binaryBytecode)))
 {
     parameters = new ParameterCollection();
     Color = new Color4(1.0f);
     WorldViewProj = Matrix.Identity;
     UseUv = true;
 }
        public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters) : base(device, presentationParameters)
        {
            device.InitDefaultRenderTarget(Description);
            //backBuffer = device.DefaultRenderTarget;
            // TODO: Review Depth buffer creation for both Android and iOS
            //DepthStencilBuffer = device.windowProvidedDepthTexture;

            backBuffer = Texture.New2D(device, Description.BackBufferWidth, Description.BackBufferHeight, presentationParameters.BackBufferFormat, TextureFlags.RenderTarget | TextureFlags.ShaderResource);
        }
        private static Texture CreateWhiteTexture(GraphicsDevice device)
        {
            const int Size = 2;
            var whiteData = new Color[Size * Size];
            for (int i = 0; i < Size*Size; i++)
                whiteData[i] = Color.White;

            return Texture.New2D(device, Size, Size, PixelFormat.R8G8B8A8_UNorm, whiteData);
        }
Example #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PrimitiveQuad" /> class with a particular effect.
 /// </summary>
 /// <param name="graphicsDevice">The graphics device.</param>
 /// <param name="effect">The effect.</param>
 public PrimitiveQuad(GraphicsDevice graphicsDevice, Effect effect)
 {
     GraphicsDevice = graphicsDevice;
     simpleEffect = effect;
     parameters = new ParameterCollection();
     parameters.Set(SpriteBaseKeys.MatrixTransform, Matrix.Identity);
     parameterCollectionGroup = new EffectParameterCollectionGroup(graphicsDevice, simpleEffect, new[] { parameters });
     sharedData = GraphicsDevice.GetOrCreateSharedData(GraphicsDeviceSharedDataType.PerDevice, "PrimitiveQuad::VertexBuffer", d => new SharedData(GraphicsDevice, simpleEffect.InputSignature));
 }
        private VertexArrayObject(GraphicsDevice graphicsDevice, EffectInputSignature shaderSignature, IndexBufferBinding indexBufferBinding, VertexBufferBinding[] vertexBufferBindings)
            : base(graphicsDevice)
        {
            this.vertexBufferBindings = vertexBufferBindings;
            this.indexBufferBinding = indexBufferBinding;
            this.preferredInputSignature = shaderSignature;

            CreateAttributes();
        }
Example #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BlendState"/> class.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="name">The name.</param>
        /// <param name="blendStateDescription">The blend state description.</param>
        internal BlendState(GraphicsDevice device, BlendStateDescription blendStateDescription)
            : base(device)
        {
            BlendFactor = SiliconStudio.Core.Mathematics.Color4.White;
            MultiSampleMask = -1;

            Description = blendStateDescription;

            CreateNativeDeviceChild();
        }
        public LightShadowProcessorWithBudget(GraphicsDevice device, bool manageShadows)
            : base(device, manageShadows)
        {
            shadowMapDefaultTextures = new List<ShadowMapTexture>();
            shadowMapVsmTextures = new List<ShadowMapTexture>();
            texturesDefault = new Dictionary<ShadowMapTexture, int>();
            texturesVsm = new Dictionary<ShadowMapTexture, int>();

            activeLightShadowMaps = new List<EntityLightShadow>();
        }
        private RasterizerState(GraphicsDevice device, RasterizerStateDescription rasterizerStateDescription) : base(device)
        {
            Description = rasterizerStateDescription;

#if !SILICONSTUDIO_PARADOX_GRAPHICS_API_OPENGLES
            polygonMode = Description.FillMode == FillMode.Solid ? PolygonMode.Fill : PolygonMode.Line;
#endif
            
            // TODO: DepthBiasClamp and various other properties are not fully supported yet
            if (Description.DepthBiasClamp != 0.0f) throw new NotSupportedException();
        }
Example #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GraphicsPresenter" /> class.
        /// </summary>
        /// <param name="device">The device.</param>
        /// <param name="presentationParameters"> </param>
        protected GraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters)
        {
            GraphicsDevice = device.RootDevice;
            Description = presentationParameters.Clone();

            ProcessPresentationParameters();

            DefaultViewport = new Viewport(0, 0, Description.BackBufferWidth, Description.BackBufferHeight);

            // Creates a default DepthStencilBuffer.
            CreateDepthStencilBuffer();
        }
Example #24
0
 public EffectProgram GetOrCreateShader(GraphicsDevice graphicsDevice, EffectBytecode bytecode)
 {
     lock (ShaderLibrary)
     {
         EffectProgram effectProgram;
         if (!ShaderLibrary.TryGetValue(bytecode, out effectProgram))
         {
             effectProgram = new EffectProgram(graphicsDevice, bytecode);
             ShaderLibrary.Add(bytecode, effectProgram);
         }
         return effectProgram;
     }
 }
        public SwapChainGraphicsPresenter(GraphicsDevice device, PresentationParameters presentationParameters)
            : base(device, presentationParameters)
        {
            PresentInterval = presentationParameters.PresentationInterval;

            // Initialize the swap chain
            swapChain = CreateSwapChain();

            backBuffer = new Texture(device).InitializeFrom(swapChain.GetBackBuffer<SharpDX.Direct3D11.Texture2D>(0), Description.BackBufferFormat.IsSRgb());

            // Reload should get backbuffer from swapchain as well
            //backBufferTexture.Reload = graphicsResource => ((Texture)graphicsResource).Recreate(swapChain.GetBackBuffer<SharpDX.Direct3D11.Texture>(0));
        }
        public void Update(GraphicsDevice graphicsDevice, EffectParameterCollectionGroup parameterCollectionGroup)
        {
            var threadIndex = graphicsDevice.ThreadIndex;
            bool dataChanged = constantBufferDatas[threadIndex].Update(parameterCollectionGroup);

            // Check if update is really needed
            if (forceDataChanged)
                forceDataChanged = false;
            else if (!dataChanged)
                return;

            // Upload data to constant buffer
            Buffer.SetData(graphicsDevice, dataStreams[threadIndex]);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DepthStencilStateFactory"/> class.
        /// </summary>
        /// <param name="device">The device.</param>
        internal DepthStencilStateFactory(GraphicsDevice device) : base(device)
        {
            Default = DepthStencilState.New(device, new DepthStencilStateDescription(true, true)).KeepAliveBy(this);
            Default.Name = "DepthStencilState.Default";

            DefaultInverse = DepthStencilState.New(device, new DepthStencilStateDescription(true, true) { DepthBufferFunction = CompareFunction.GreaterEqual }).KeepAliveBy(this);
            DefaultInverse.Name = "DepthStencilState.DefaultInverse";

            DepthRead = DepthStencilState.New(device, new DepthStencilStateDescription(true, false)).KeepAliveBy(this);
            DepthRead.Name = "DepthStencilState.DepthRead";

            None = DepthStencilState.New(device, new DepthStencilStateDescription(false, false)).KeepAliveBy(this);
            None.Name = "DepthStencilState.None";
        }
        public UseOpenGLCreationContext(GraphicsDevice graphicsDevice)
            : this()
        {
#if SILICONSTUDIO_PLATFORM_ANDROID
            // Unfortunately, android seems to not use GraphicsContext.CurrentContext to register its AndroidGraphicsContext,
            // so let's query EGL directly.
            if (GraphicsDevice.EglGetCurrentContext() == IntPtr.Zero)
#elif SILICONSTUDIO_PLATFORM_IOS
            if (OpenGLES.EAGLContext.CurrentContext == null)
#else
            if (GraphicsContext.CurrentContext == null)
#endif
            {
                needUnbindContext = true;
                useDeviceCreationContext = true;

#if SILICONSTUDIO_PLATFORM_ANDROID
                tegraWorkaround = graphicsDevice.Workaround_Context_Tegra2_Tegra3;

                // Notify main rendering thread there is some pending async work to do
                if (tegraWorkaround)
                {
                    useDeviceCreationContext = false; // We actually use real main context, so states will be kept
                    graphicsDevice.AsyncPendingTaskWaiting = true;
                }
#endif

                // Lock, since there is only one deviceCreationContext.
                // TODO: Support multiple deviceCreationContext (TLS creation of context was crashing, need to investigate why)
                asyncCreationLockObject = graphicsDevice.asyncCreationLockObject;
                Monitor.Enter(graphicsDevice.asyncCreationLockObject, ref asyncCreationLockTaken);

#if SILICONSTUDIO_PLATFORM_ANDROID
                if (tegraWorkaround)
                    graphicsDevice.AsyncPendingTaskWaiting = false;

                // On android, bind the actual android context
                // The deviceCreationContext is a dummy one, so that CurrentContext works.
                androidDeviceCreationContext = graphicsDevice.androidAsyncDeviceCreationContext;
                if (androidDeviceCreationContext != null)
                    androidDeviceCreationContext.MakeCurrent(graphicsDevice.deviceCreationWindowInfo);
#endif

                // Bind the context
                deviceCreationContext = graphicsDevice.deviceCreationContext;
                deviceCreationContext.MakeCurrent(graphicsDevice.deviceCreationWindowInfo);
            }
        }
        private VertexArrayObject(GraphicsDevice graphicsDevice, EffectInputSignature shaderSignature, IndexBufferBinding indexBufferBinding, VertexBufferBinding[] vertexBufferBindings)
            : base(graphicsDevice)
        {
            this.vertexBufferBindings = vertexBufferBindings;
            this.indexBufferBinding = indexBufferBinding;
            this.preferredInputSignature = shaderSignature;
            
            // Increase the reference count on the provided buffers -> we do not want to take the ownership
            foreach (VertexBufferBinding vertexBufferBinding in vertexBufferBindings)
                vertexBufferBinding.Buffer.AddReferenceInternal();

            if (indexBufferBinding != null)
                indexBufferBinding.Buffer.AddReferenceInternal();

            CreateAttributes();
        }
        internal void AttachToGraphicsDevice(GraphicsDevice device)
        {
            GraphicsDevice = device;

            if (device != null)
            {
                // Add GraphicsResourceBase to device resources
                var resources = device.Resources;
                lock (resources)
                {
                    resources.Add(this);
                }
            }

            Initialize();
        }
 /// <summary>
 /// Creates a cylinder primitive.
 /// </summary>
 /// <param name="device">The device.</param>
 /// <param name="height">The height.</param>
 /// <param name="diameter">The diameter.</param>
 /// <param name="tessellation">The tessellation.</param>
 /// <param name="textureTiling">The texture tiling.</param>
 /// <param name="toLeftHanded">if set to <c>true</c> vertices and indices will be transformed to left handed. Default is false.</param>
 /// <returns>A cylinder primitive.</returns>
 /// <exception cref="System.ArgumentOutOfRangeException">tessellation;tessellation must be &gt;= 3</exception>
 public static GeometricPrimitive New(GraphicsDevice device, float height = 1.0f, float diameter = 1.0f, int tessellation = 32, float textureTiling = 1, bool toLeftHanded = false)
 {
     // Create the primitive object.
     return(new GeometricPrimitive(device, New(height, diameter, tessellation, textureTiling, toLeftHanded)));
 }
Example #32
0
 protected internal Texture2D(GraphicsDevice device, TextureDescription description2D, DataBox[] dataBoxes = null, bool initialize = true) : base(device, description2D, TextureTarget.Texture2D, dataBoxes, initialize)
 {
 }
Example #33
0
 protected internal Texture2D(GraphicsDevice device, Texture2D texture) : base(device, texture)
 {
 }
        protected static Texture2DDescription ConvertToNativeDescription(GraphicsDevice device, TextureDescription description)
        {
            var format = (Format)description.Format;
            var flags  = description.Flags;

            // If the texture is going to be bound on the depth stencil, for to use TypeLess format
            if ((flags & TextureFlags.DepthStencil) != 0)
            {
                if (device.Features.Profile < GraphicsProfile.Level_10_0)
                {
                    flags &= ~TextureFlags.ShaderResource;
                }
                else
                {
                    // Determine TypeLess Format and ShaderResourceView Format
                    switch (description.Format)
                    {
                    case PixelFormat.D16_UNorm:
                        format = SharpDX.DXGI.Format.R16_Typeless;
                        break;

                    case PixelFormat.D32_Float:
                        format = SharpDX.DXGI.Format.R32_Typeless;
                        break;

                    case PixelFormat.D24_UNorm_S8_UInt:
                        format = SharpDX.DXGI.Format.R24G8_Typeless;
                        break;

                    case PixelFormat.D32_Float_S8X24_UInt:
                        format = SharpDX.DXGI.Format.R32G8X24_Typeless;
                        break;

                    default:
                        throw new InvalidOperationException(string.Format("Unsupported DepthFormat [{0}] for depth buffer", description.Format));
                    }
                }
            }

            var desc = new Texture2DDescription()
            {
                Width     = description.Width,
                Height    = description.Height,
                ArraySize = description.ArraySize,
                // TODO calculate appropriate MultiSamples
                SampleDescription = new SampleDescription(1, 0),
                BindFlags         = GetBindFlagsFromTextureFlags(flags),
                Format            = format,
                MipLevels         = description.MipLevels,
                Usage             = (ResourceUsage)description.Usage,
                CpuAccessFlags    = GetCpuAccessFlagsFromUsage(description.Usage),
                OptionFlags       = ResourceOptionFlags.None
            };

            if (description.Dimension == TextureDimension.TextureCube)
            {
                desc.OptionFlags = ResourceOptionFlags.TextureCube;
            }

            return(desc);
        }