/// <summary> /// Initializes a new instance of the <see cref="MappedResource"/> struct. /// </summary> /// <param name="resource">The resource.</param> /// <param name="subResourceIndex">Index of the sub resource.</param> /// <param name="dataBox">The data box.</param> /// <param name="offsetInBytes">Offset since the beginning of the buffer.</param> /// <param name="sizeInBytes">Size of the mapped resource.</param> internal MappedResource(GraphicsResource resource, int subResourceIndex, DataBox dataBox, int offsetInBytes, int sizeInBytes) { Resource = resource; SubResourceIndex = subResourceIndex; DataBox = dataBox; OffsetInBytes = offsetInBytes; SizeInBytes = sizeInBytes; }
/// <summary> /// Initializes a new instance of the <see cref="MappedResource"/> struct. /// </summary> /// <param name="resource">The resource.</param> /// <param name="subResourceIndex">Index of the sub resource.</param> /// <param name="dataBox">The data box.</param> internal MappedResource(GraphicsResource resource, int subResourceIndex, DataBox dataBox) { Resource = resource; SubResourceIndex = subResourceIndex; DataBox = dataBox; OffsetInBytes = 0; SizeInBytes = -1; }
public override void ApplyLayer(DeviceContext context, GraphicsResource output, OpticalProfile profile, SurfacePass pass, double time, double dt) { using (DataStream cbuffer = new DataStream(8, true, true)) { cbuffer.Write<float>((float)profile.Size); cbuffer.Write<float>((float)profile.Glare); cbuffer.Position = 0; pass.Pass(context, Encoding.ASCII.GetString(Resources.Structural), output.Dimensions, output.RTV, null, cbuffer); } }
/// <summary> /// Writes the specified external and returns the reference to it. /// </summary> /// <param name="name">Name of the value</param> /// <param name="value">External savable to write</param> public override ExternalReference Write(String name, ISavable value) { String filePath; if (_savables.TryGetValue(value, out filePath)) { return(new ExternalReference(filePath)); } String fileDir = GetFileDirectory(); String resourceName = GetPrimaryResourceName(); if (!Directory.Exists(fileDir)) { Directory.CreateDirectory(fileDir); } String extName; if (value is GraphicsResource) { GraphicsResource gfx = value as GraphicsResource; if (gfx.Name != null) { extName = gfx.Name; } else { if (_count > 0) { extName = String.Format("{0}_{1}_{2}", resourceName, name, _count); } else { extName = String.Format("{0}_{1}", resourceName, name); } } } else { if (_count > 0) { extName = String.Format("{0}_{1}_{2}", resourceName, name, _count); } else { extName = String.Format("{0}_{1}", resourceName, name); } } filePath = Path.Combine(fileDir, extName); filePath = Path.ChangeExtension(filePath, ".tebo"); //If we're not overwriting, try and come up with a unique file name several times before giving up if (!Overwrite) { int count = 0; while (File.Exists(filePath)) { filePath = Path.Combine(fileDir, String.Format("{0}-{1}", extName, count)); filePath = Path.ChangeExtension(filePath, ".tebo"); if (count > 5) { break; } count++; } } //Write to the file BinaryExporter exporter = new BinaryExporter(); exporter.Save(value, filePath); String relName; if (String.IsNullOrEmpty(OutputDirectory)) { relName = Path.GetFileName(filePath); } else { relName = Path.Combine(OutputDirectory, Path.GetFileName(filePath)); } _savables.Add(value, relName); _count++; return(new ExternalReference(relName)); }
public void Accept(ShaderGeneratorContext context) { isBlackAndWhiteBuffer ??= GraphicsResource.CreateBuffer(context.GraphicsDevice, IsBlackAndWhite, ResourceFlags.None, HeapType.Upload); context.ConstantBufferViews.Add(isBlackAndWhiteBuffer.DefaultConstantBufferView); }
/// <summary> /// Copies a memory region from one resource to another /// </summary> /// <param name="source">The source <see cref="GraphicsResource"/> to read from</param> /// <param name="sourceOffset">The starting offset to read the source resource from</param> /// <param name="destination">The destination <see cref="GraphicsResource"/> to write to</param> /// <param name="destinationOffset">The starting offset to write the destination resource from</param> /// <param name="numBytes">The total number of bytes to copy from one resource to another</param> public void CopyBufferRegion(GraphicsResource source, long sourceOffset, GraphicsResource destination, long destinationOffset, long numBytes) { NativeCommandList.CopyBufferRegion(destination.NativeResource, destinationOffset, source.NativeResource, sourceOffset, numBytes); }
public void SetDrawingResources(out GraphicsResource nose, out GraphicsResource core, out GraphicsResource engine) { nose = Nose.Resource; core = Core.Resource; engine = Engine.Resource; }
/// <summary> /// Sets an unordered access view descriptor. /// </summary> /// <param name="slot">The slot.</param> /// <param name="unorderedAccessView">The unordered access view.</param> public void SetUnorderedAccessView(int slot, GraphicsResource unorderedAccessView) { NullHelper.ToImplement(); }
private static void Finalize(GraphicsResource __instance) { FinalizePost(__instance); }
/// <summary>Initializes a new instance of the <see cref="GraphicsResourceObject" /> class.</summary> /// <param name="resource">The resource for which the object is being created.</param> /// <param name="name">The name of the object or <c>null</c> to use <see cref="MemberInfo.Name" />.</param> /// <exception cref="ArgumentNullException"><paramref name="resource" /> is <c>null</c>.</exception> protected GraphicsResourceObject(GraphicsResource resource, string?name = null) : base(resource.Device, name) { _resource = resource; }
public IndexBufferView(GraphicsResource resource, int sizeInBytes, PixelFormat format) : this(resource.NativeResource.GPUVirtualAddress, sizeInBytes, format) { }
public IndexBufferView(GraphicsResource resource, PixelFormat format) : this(resource, (int)resource.Width, format) { }
public IndexBufferView(GraphicsResource resource, int sizeInBytes, bool is32Bit = false) : this(resource.NativeResource.GPUVirtualAddress, sizeInBytes, is32Bit) { }
public IndexBufferView(GraphicsResource resource, bool is32Bit = false) : this(resource, (int)resource.Width, is32Bit) { }
/// <summary> /// Apply this TransformStateBase. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> which has defined the shader program <paramref name="shaderProgram"/>. /// </param> /// <param name="shaderProgram"> /// The <see cref="ShaderProgram"/> which has the state set. /// </param> public override void Apply(GraphicsContext ctx, ShaderProgram shaderProgram) { GraphicsResource.CheckCurrentContext(ctx); if (shaderProgram == null) { // Fixed pipeline rendering requires server state #if !MONODROID if (ctx.Extensions.DirectStateAccess_EXT) { // Set projection and model-view matrix Gl.MatrixLoadEXT(MatrixMode.Projection, Projection.ToArray()); Gl.MatrixLoadEXT(MatrixMode.Modelview, ModelView.ToArray()); } else { // Set projection matrix Gl.MatrixMode(MatrixMode.Projection); Gl.LoadMatrix(Projection.ToArray()); // Set model-view matrix Gl.MatrixMode(MatrixMode.Modelview); Gl.LoadMatrix(ModelView.ToArray()); } #else throw new NotSupportedException("fixed pipeline not supported"); #endif } else { // Shader implementation (TransformState.glsl) ctx.Bind(shaderProgram); // Usual matrices Debug.Assert(ModelViewProjection != null, "no model-view-projection matrix"); shaderProgram.SetUniform(ctx, "glo_ModelViewProjection", ModelViewProjection); if (shaderProgram.IsActiveUniform("glo_NormalMatrix")) { shaderProgram.SetUniform(ctx, "glo_NormalMatrix", NormalMatrix); } if (Projection != null) { shaderProgram.SetUniform(ctx, "glo_Projection", Projection); } if (shaderProgram.IsActiveUniform("glo_Model")) { shaderProgram.SetUniform(ctx, "glo_Model", Model); } if (shaderProgram.IsActiveUniform("glo_ModelView")) { shaderProgram.SetUniform(ctx, "glo_ModelView", ModelView); } if (shaderProgram.IsActiveUniform("glo_InverseProjection")) { shaderProgram.SetUniform(ctx, "glo_InverseProjection", InverseProjection); } if (shaderProgram.IsActiveUniform("glo_InverseModelView")) { shaderProgram.SetUniform(ctx, "glo_InverseModelView", InverseModelView); } if (shaderProgram.IsActiveUniform("glo_InverseModelViewProjection")) { shaderProgram.SetUniform(ctx, "glo_InverseModelViewProjection", InverseModelViewProjection); } if (Projection != null) { shaderProgram.SetUniform(ctx, "glo_DepthDistances", DepthDistances); } } }
protected T ReadAsset <T>(string assetName, Action <IDisposable> recordDisposableObject) { if (string.IsNullOrEmpty(assetName)) { throw new ArgumentNullException("assetName"); } if (disposed) { throw new ObjectDisposedException("ContentManager"); } string originalAssetName = assetName; object result = null; if (this.graphicsDeviceService == null) { this.graphicsDeviceService = serviceProvider.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService; if (this.graphicsDeviceService == null) { throw new InvalidOperationException("No Graphics Device Service"); } } Stream stream = null; try { // Try to load it traditionally stream = OpenStream(assetName); // Try to load as XNB file try { using (BinaryReader xnbReader = new BinaryReader(stream)) { using (ContentReader reader = GetContentReaderFromXnb(assetName, ref stream, xnbReader, recordDisposableObject)) { result = reader.ReadAsset <T>(); GraphicsResource resource = result as GraphicsResource; if (resource != null) { resource.Name = originalAssetName; } } } } finally { if (stream != null) { stream.Dispose(); } } } catch (ContentLoadException ex) { // Try to load as a non-content file assetName = FileHelpers.NormalizeFilePathSeparators( Path.Combine(RootDirectoryFullPath, assetName) ); assetName = Normalize <T>(assetName); if (string.IsNullOrEmpty(assetName)) { throw new ContentLoadException( "Could not load " + originalAssetName + " asset as a non-content file!", ex ); } result = ReadRawAsset <T>(assetName, originalAssetName); /* Because Raw Assets skip the ContentReader step, they need to have their * disposables recorded here. Doing it outside of this catch will * result in disposables being logged twice. */ IDisposable disposableResult = result as IDisposable; if (disposableResult != null) { if (recordDisposableObject != null) { recordDisposableObject(disposableResult); } else { disposableAssets.Add(disposableResult); } } } if (result == null) { throw new ContentLoadException("Could not load " + originalAssetName + " asset!"); } return((T)result); }
static void CreateThePixel(GraphicsResource spriteBatch) { pixel = new Texture2D(spriteBatch.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); pixel.SetData(new[] { Color.White }); }
/// <summary> /// Sets a shader resource view descriptor. /// </summary> /// <param name="slot">The slot.</param> /// <param name="shaderResourceView">The shader resource view.</param> public void SetShaderResourceView(int slot, GraphicsResource shaderResourceView) { NullHelper.ToImplement(); }
/// <summary> /// Apply this TransformState. /// </summary> /// <param name="ctx"> /// A <see cref="GraphicsContext"/> which has defined the shader program <paramref name="shaderProgram"/>. /// </param> /// <param name="shaderProgram"> /// The <see cref="ShaderProgram"/> which has the state set. /// </param> public override void Apply(GraphicsContext ctx, ShaderProgram shaderProgram) { GraphicsResource.CheckCurrentContext(ctx); if (!ctx.Extensions.UniformBufferObject_ARB) { if (shaderProgram == null) { // Fixed pipeline rendering requires server state throw new NotImplementedException(); } else { // Custom implementation ctx.Bind(shaderProgram); if (shaderProgram.IsActiveUniform("glo_LightModel")) { LightModel.ApplyState(ctx, shaderProgram, "glo_LightModel"); } for (int i = 0; i < Lights.Count; i++) { string uniformName = "glo_Light[" + i + "]"; if (shaderProgram.IsActiveUniform(uniformName) == false) { break; } Lights[i].ApplyState(ctx, shaderProgram, uniformName); } shaderProgram.SetUniform(ctx, "glo_LightsCount", LightsCount); } } else { base.Apply(ctx, shaderProgram); // Uniform block } // Dummy shadow map: Texture2D // Note: necessary to avoid undefined behavior on glo_ShadowMap2D samplers string resourceClassId = "OpenGL.Objects.ShadowMap.DummyTexture2d"; Texture2D dummyShadowMap = (Texture2D)ctx.GetSharedResource(resourceClassId); if (dummyShadowMap == null) { dummyShadowMap = new Texture2D(1, 1, PixelLayout.Depth16); dummyShadowMap.SamplerParams.CompareMode = true; dummyShadowMap.SamplerParams.CompareFunc = DepthFunction.Never; dummyShadowMap.Create(ctx); ctx.SetSharedResource(resourceClassId, dummyShadowMap); } // Dummy shadow map: TextureCube // Apply depth maps bool[] tex2dSet = new bool[4]; for (int i = 0; i < tex2dSet.Length; i++) { if (i >= Lights.Count || Lights[i].ShadowMap2D == null) { continue; } int shadowMapIndex = Lights[i].ShadowMapIndex; shaderProgram.SetUniform(ctx, "glo_ShadowMap2D[" + shadowMapIndex + "]", Lights[i].ShadowMap2D); tex2dSet[shadowMapIndex] = true; } // Avoid undefined behavior for (int i = 0; i < tex2dSet.Length; i++) { if (tex2dSet[i] == false) { shaderProgram.SetUniform(ctx, "glo_ShadowMap2D[" + i + "]", dummyShadowMap); } } }
protected T ReadAsset <T>(string assetName, Action <IDisposable> recordDisposableObject) { if (string.IsNullOrEmpty(assetName)) { throw new ArgumentNullException("assetName"); } if (disposed) { throw new ObjectDisposedException("ContentManager"); } object result = null; // FIXME: Should this block be here? -flibit if (graphicsDeviceService == null) { graphicsDeviceService = ServiceProvider.GetService(typeof(IGraphicsDeviceService)) as IGraphicsDeviceService; if (graphicsDeviceService == null) { throw new InvalidOperationException("No Graphics Device Service"); } } Stream stream = null; string modifiedAssetName = String.Empty; // Will be used if we have to guess a filename try { stream = OpenStream(assetName); } catch (Exception e) { // Okay, so we couldn't open it. Maybe it needs a different extension? // FIXME: This only works for files on the disk, what about custom streams? -flibit modifiedAssetName = FileHelpers.NormalizeFilePathSeparators( Path.Combine(RootDirectoryFullPath, assetName) ); if (typeof(T) == typeof(Texture2D) || typeof(T) == typeof(Texture)) { modifiedAssetName = Texture2DReader.Normalize(modifiedAssetName); } else if ((typeof(T) == typeof(SoundEffect))) { modifiedAssetName = SoundEffectReader.Normalize(modifiedAssetName); } else if ((typeof(T) == typeof(Effect))) { modifiedAssetName = EffectReader.Normalize(modifiedAssetName); } else if ((typeof(T) == typeof(Song))) { modifiedAssetName = SongReader.Normalize(modifiedAssetName); } else if ((typeof(T) == typeof(Video))) { modifiedAssetName = VideoReader.Normalize(modifiedAssetName); } // Did we get anything...? if (String.IsNullOrEmpty(modifiedAssetName)) { // Nope, nothing we're aware of! throw new ContentLoadException( "Could not load asset " + assetName + "! Error: " + e.Message, e ); } stream = TitleContainer.OpenStream(modifiedAssetName); } // Check for XNB header stream.Read(xnbHeader, 0, xnbHeader.Length); if (xnbHeader[0] == 'X' && xnbHeader[1] == 'N' && xnbHeader[2] == 'B' && targetPlatformIdentifiers.Contains((char)xnbHeader[3])) { using (BinaryReader xnbReader = new BinaryReader(stream)) using (ContentReader reader = GetContentReaderFromXnb(assetName, ref stream, xnbReader, recordDisposableObject)) { result = reader.ReadAsset <T>(); GraphicsResource resource = result as GraphicsResource; if (resource != null) { resource.Name = assetName; } } } else { // It's not an XNB file. Try to load as a raw asset instead. // FIXME: Assuming seekable streams! -flibit stream.Seek(0, SeekOrigin.Begin); if (typeof(T) == typeof(Texture2D) || typeof(T) == typeof(Texture)) { Texture2D texture = Texture2D.FromStream( graphicsDeviceService.GraphicsDevice, stream ); texture.Name = assetName; result = texture; } else if ((typeof(T) == typeof(SoundEffect))) { result = SoundEffect.FromStream(stream); } else if ((typeof(T) == typeof(Effect))) { byte[] data = new byte[stream.Length]; stream.Read(data, 0, (int)stream.Length); result = new Effect(graphicsDeviceService.GraphicsDevice, data); } else if ((typeof(T) == typeof(Song))) { // FIXME: Not using the stream! -flibit result = new Song(modifiedAssetName); } else if ((typeof(T) == typeof(Video))) { // FIXME: Not using the stream! -flibit result = new Video(modifiedAssetName, graphicsDeviceService.GraphicsDevice); } else { stream.Close(); throw new ContentLoadException("Could not load " + assetName + " asset!"); } /* Because Raw Assets skip the ContentReader step, they need to have their * disposables recorded here. Doing it outside of this catch will * result in disposables being logged twice. */ IDisposable disposableResult = result as IDisposable; if (disposableResult != null) { if (recordDisposableObject != null) { recordDisposableObject(disposableResult); } else { disposableAssets.Add(disposableResult); } } /* Because we're not using a BinaryReader for raw assets, we * need to close the stream ourselves. * -flibit */ stream.Close(); } return((T)result); }
/// <summary> /// Creates a new <see cref="GraphicsDeviceMismatchException"/> instance /// </summary> internal GraphicsDeviceMismatchException(GraphicsDevice device, GraphicsResource resource) : base(GetExceptionMessage(device, resource)) { }