Skip to content

Commit

Permalink
fix: Enable to build SkyBoxAsset using OpenGL
Browse files Browse the repository at this point in the history
  • Loading branch information
Jklawreszuk committed Oct 24, 2024
1 parent 4c46fdc commit 8b448ac
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected override void Prepare(AssetCompilerContext context, AssetItem assetIte
var textureAssetItem = new AssetItem(textureUrl, textureAsset);

// Create and add the texture command.
var textureParameters = new TextureConvertParameters(assetSource, textureAsset, PlatformType.Windows, GraphicsPlatform.Direct3D11, graphicsProfile, gameSettingsAsset.GetOrCreate<TextureSettings>().TextureQuality, colorSpace);
var textureParameters = new TextureConvertParameters(assetSource, textureAsset, context.Platform, context.Platform.GetDefaultGraphicsPlatform(), graphicsProfile, gameSettingsAsset.GetOrCreate<TextureSettings>().TextureQuality, colorSpace);
var prereqStep = new AssetBuildStep(textureAssetItem);
prereqStep.Add(new TextureAssetCompiler.TextureConvertCommand(textureUrl, textureParameters, assetItem.Package));
result.BuildSteps.Add(prereqStep);
Expand Down
14 changes: 7 additions & 7 deletions sources/engine/Stride.Graphics/OpenGL/GraphicsDevice.OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,23 +658,23 @@ protected unsafe void InitializePlatformDevice(GraphicsProfile[] graphicsProfile
#endif

#if STRIDE_UI_SDL
gameWindow = (Stride.Graphics.SDL.Window)windowHandle.NativeWindow;
gameWindow = windowHandle?.NativeWindow as SDL.Window ?? new SDL.Window("");

var SDL = Graphics.SDL.Window.SDL;

#if STRIDE_GRAPHICS_API_OPENGLES
SDL.GLSetAttribute(GLattr.GLContextProfileMask, (int)GLprofile.GLContextProfileES);
SDL.GLSetAttribute(GLattr.ContextProfileMask, (int)GLprofile.ES);
#else
SDL.GLSetAttribute(GLattr.GLContextProfileMask, (int)GLprofile.GLContextProfileCore);
SDL.GLSetAttribute(GLattr.ContextProfileMask, (int)GLprofile.Core);
#endif


if (IsDebugMode)
SDL.GLSetAttribute(GLattr.GLContextFlags, (int)GLcontextFlag.GLContextDebugFlag);
SDL.GLSetAttribute(GLattr.ContextFlags, (int)GLcontextFlag.DebugFlag);

// Setup version
SDL.GLSetAttribute(GLattr.GLContextMajorVersion, currentVersion / 100);
SDL.GLSetAttribute(GLattr.GLContextMinorVersion, (currentVersion / 10) % 10);
SDL.GLSetAttribute(GLattr.ContextMajorVersion, currentVersion / 100);
SDL.GLSetAttribute(GLattr.ContextMinorVersion, (currentVersion / 10) % 10);

MainGraphicsContext = new SdlContext(SDL, (Silk.NET.SDL.Window*)gameWindow.SdlHandle);
((SdlContext)MainGraphicsContext).Create();
Expand All @@ -690,7 +690,7 @@ protected unsafe void InitializePlatformDevice(GraphicsProfile[] graphicsProfile
#endif

// Create shared context for creating graphics resources from other threads
SDL.GLSetAttribute(GLattr.GLShareWithCurrentContext, 1);
SDL.GLSetAttribute(GLattr.ShareWithCurrentContext, 1);
deviceCreationContext = new SdlContext(SDL, (Silk.NET.SDL.Window*)gameWindow.SdlHandle);
((SdlContext)deviceCreationContext).Create();

Expand Down
6 changes: 3 additions & 3 deletions sources/engine/Stride.Graphics/OpenGL/Texture.OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,11 @@ private void CreateTexture2DArray(bool compressed, int width, int height, int mi
{
if (compressed)
{
GL.CompressedTexImage3D(TextureTarget, mipLevel, TextureInternalFormat, (uint) width, (uint) height, (uint) ArraySize, border: 0, imageSize: 0, data: IntPtr.Zero);
GL.CompressedTexImage3D(TextureTarget, mipLevel, TextureInternalFormat, (uint) width, (uint) height, (uint) ArraySize, border: 0, imageSize: 0, data: null);
}
else
{
GL.TexImage3D(TextureTarget, mipLevel, TextureInternalFormat, (uint) width, (uint) height, (uint) ArraySize, border: 0, TextureFormat, TextureType, IntPtr.Zero);
GL.TexImage3D(TextureTarget, mipLevel, TextureInternalFormat, (uint) width, (uint) height, (uint) ArraySize, border: 0, TextureFormat, TextureType, null);
}
}

Expand Down Expand Up @@ -620,7 +620,7 @@ internal uint GeneratePixelBufferObject(BufferTargetARB target, PixelStoreParame
GL.BindBuffer(target, result);
if (RowPitch < 4)
GL.PixelStore(alignment, 1);
GL.BufferData(target, (UIntPtr) totalSize, IntPtr.Zero, bufferUsage);
GL.BufferData(target, (UIntPtr) totalSize, null, bufferUsage);
GL.BindBuffer(target, 0);

return result;
Expand Down
9 changes: 3 additions & 6 deletions sources/engine/Stride.Graphics/Texture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,7 @@ internal Texture InitializeFrom(Texture parentTexture, TextureViewDescription vi
internal Texture InitializeFrom(Texture parentTexture, TextureDescription description, TextureViewDescription viewDescription, DataBox[] textureDatas = null)
{
ParentTexture = parentTexture;
if (ParentTexture != null)
{
ParentTexture.AddReferenceInternal();
}
ParentTexture?.AddReferenceInternal();

textureDescription = description;
textureViewDescription = viewDescription;
Expand Down Expand Up @@ -1143,8 +1140,8 @@ public Image GetDataAsImage(CommandList commandList)
if (Usage == GraphicsResourceUsage.Staging)
return GetDataAsImage(commandList, this); // Directly if this is a staging resource

using (var stagingTexture = ToStaging())
return GetDataAsImage(commandList, stagingTexture);
using var stagingTexture = ToStaging();
return GetDataAsImage(commandList, stagingTexture);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace Stride.Rendering.Images
{
var u = 0.0;
var p = 0.5;
for (int kk=k; kk; p*=0.5, kk>>=1)
for (int kk=k; kk > 0; p *= 0.5, kk /= 2)
{
if (kk & 1) // kk mod 2 == 1
if (kk % 2 == 1)
u += p;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,41 +96,37 @@ protected override void DrawCore(RenderDrawContext context)
{
for (int faceIndex = 0; faceIndex < faceCount; faceIndex++)
{
using (var outputView = output.ToTextureView(ViewType.Single, faceIndex, mipLevel))
using var outputView = output.ToTextureView(ViewType.Single, faceIndex, mipLevel);
var inputLevel = MathUtil.Log2(input.Width / output.Width);
if (mipLevel == 0 && DoNotFilterHighestLevel)
{
var inputLevel = MathUtil.Log2(input.Width / output.Width);
if (mipLevel == 0 && DoNotFilterHighestLevel)
if (input.Width >= output.Width && inputLevel < input.MipLevels && input.Format == output.Format)
{
if (input.Width >= output.Width && inputLevel < input.MipLevels && input.Format == output.Format)
{
// Optimization: make a simple copy of the texture when possible
var inputSubresource = inputLevel + faceIndex * input.MipLevels;
var outputSubresource = 0 + faceIndex * output.MipLevels;
context.CommandList.CopyRegion(input, inputSubresource, null, output, outputSubresource);
}
else // otherwise rescale the closest mipmap
{
var inputMipmapLevel = Math.Min(inputLevel, input.MipLevels - 1);
using (var inputView = input.ToTextureView(ViewType.Single, faceIndex, inputMipmapLevel))
{
scaler.SetInput(inputView);
scaler.SetOutput(outputView);
scaler.Draw(context);
}
}
// Optimization: make a simple copy of the texture when possible
var inputSubresource = inputLevel + faceIndex * input.MipLevels;
var outputSubresource = 0 + faceIndex * output.MipLevels;
context.CommandList.CopyRegion(input, inputSubresource, null, output, outputSubresource);
}
else
else // otherwise rescale the closest mipmap
{
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.Face, faceIndex);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.Roughness, roughness);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.MipmapCount, input.MipLevels - 1);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.RadianceMap, input);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.RadianceMapSize, input.Width);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeParams.NbOfSamplings, SamplingsCount);
shader.SetOutput(outputView);
shader.Draw(context);
var inputMipmapLevel = Math.Min(inputLevel, input.MipLevels - 1);
using var inputView = input.ToTextureView(ViewType.Single, faceIndex, inputMipmapLevel);
scaler.SetInput(inputView);
scaler.SetOutput(outputView);
scaler.Draw(context);
}
}
else
{
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.Face, faceIndex);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.Roughness, roughness);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.MipmapCount, input.MipLevels - 1);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.RadianceMap, input);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeShaderKeys.RadianceMapSize, input.Width);
shader.Parameters.Set(RadiancePrefilteringGGXNoComputeParams.NbOfSamplings, SamplingsCount);
shader.SetOutput(outputView);
shader.Draw(context);
}
}

if (mipCount > 1)
Expand Down

0 comments on commit 8b448ac

Please sign in to comment.