1
0
mirror of synced 2024-11-12 02:00:50 +01:00

Fix 3d cubemap preview

This commit is contained in:
KillzXGaming 2019-09-10 19:54:36 -04:00
parent 52bb137db5
commit f9d1a99431
4 changed files with 82 additions and 31 deletions

View File

@ -38,6 +38,7 @@ namespace Toolbox.Library.Forms
ActiveTexture = texture;
var skybox = new DrawableSkybox();
skybox.ForceDisplay = true;
skybox.LoadCustomTexture(ActiveTexture);
glControl.MainDrawable = skybox;

View File

@ -44,6 +44,20 @@ namespace Toolbox.Library
Platform_Ps1 = 9,
}
public enum STSurfaceType
{
Texture1D,
Texture2D,
Texture3D,
TextureCube,
Texture1D_Array,
Texture2D_Array,
Texture2D_Mulitsample,
Texture2D_Multisample_Array,
TextureCube_Array,
}
public class EditedBitmap
{
public int ArrayLevel = 0;
@ -74,6 +88,8 @@ namespace Toolbox.Library
}
}
public STSurfaceType SurfaceType = STSurfaceType.Texture2D;
/// <summary>
/// The swizzle method to use when decoding or encoding back a texture.
/// </summary>

View File

@ -14,15 +14,17 @@ namespace Toolbox.Library.Rendering
{
public class DrawableSkybox : AbstractGlDrawable
{
public bool ForceDisplay = false;
ShaderProgram defaultShaderProgram;
private RenderableTex CustomCubemap = null;
public void LoadCustomTexture(STGenericTexture GenericTexture)
{
CustomCubemap = GenericTexture.RenderableTex;
if (CustomCubemap == null || !CustomCubemap.GLInitialized)
if (GenericTexture.RenderableTex == null || !GenericTexture.RenderableTex.GLInitialized)
GenericTexture.LoadOpenGLTexture();
CustomCubemap = GenericTexture.RenderableTex;
}
public override void Prepare(GL_ControlModern control)
@ -56,7 +58,7 @@ namespace Toolbox.Library.Rendering
SFGraphics.GLObjects.Textures.TextureCubeMap specularPbr;
public override void Draw(GL_ControlModern control, Pass pass)
{
if (!Runtime.OpenTKInitialized || !Runtime.PBR.UseSkybox || pass == Pass.TRANSPARENT)
if (!Runtime.OpenTKInitialized || (!Runtime.PBR.UseSkybox && !ForceDisplay) || pass == Pass.TRANSPARENT)
return;
GL.Disable(EnableCap.CullFace);
@ -94,7 +96,6 @@ namespace Toolbox.Library.Rendering
if (RenderTools.diffusePbr != null)
{
GL.ActiveTexture(TextureUnit.Texture0);
RenderTools.diffusePbr.Bind();
}
}
@ -178,6 +179,8 @@ namespace Toolbox.Library.Rendering
GL.BindVertexArray(0);
GL.Enable(EnableCap.CullFace);
GL.BindTexture(TextureTarget.TextureCubeMap, 0);
}
}
}

View File

@ -13,7 +13,7 @@ namespace Toolbox.Library.Rendering
public class RenderableTex
{
public int width, height;
public int TexID;
public int TexID = -1;
public PixelInternalFormat pixelInternalFormat;
public OpenTK.Graphics.OpenGL.PixelFormat pixelFormat;
public PixelType pixelType = PixelType.UnsignedByte;
@ -80,7 +80,8 @@ namespace Toolbox.Library.Rendering
public void Dispose()
{
GL.DeleteTexture(TexID);
if (TexID != -1)
GL.DeleteTexture(TexID);
}
public void SetTextureParameter(TextureParameterName param, int value)
@ -122,6 +123,34 @@ namespace Toolbox.Library.Rendering
return;
}
switch (GenericTexture.SurfaceType)
{
case STSurfaceType.Texture1D:
TextureTarget = TextureTarget.Texture1D;
break;
case STSurfaceType.Texture2D:
TextureTarget = TextureTarget.Texture2D;
break;
case STSurfaceType.Texture2D_Array:
TextureTarget = TextureTarget.Texture2DArray;
break;
case STSurfaceType.Texture2D_Mulitsample:
TextureTarget = TextureTarget.Texture2DMultisample;
break;
case STSurfaceType.Texture2D_Multisample_Array:
TextureTarget = TextureTarget.Texture2DMultisampleArray;
break;
case STSurfaceType.Texture3D:
TextureTarget = TextureTarget.Texture3D;
break;
case STSurfaceType.TextureCube:
TextureTarget = TextureTarget.TextureCubeMap;
break;
case STSurfaceType.TextureCube_Array:
TextureTarget = TextureTarget.TextureCubeMapArray;
break;
}
if (GenericTexture.ArrayCount == 0)
GenericTexture.ArrayCount = 1;
@ -153,14 +182,7 @@ namespace Toolbox.Library.Rendering
ImageSize = Surfaces[0].mipmaps[0].Length;
if (IsCubeMap)
{
TextureTarget = TextureTarget.TextureCubeMap;
TextureWrapS = TextureWrapMode.Clamp;
TextureWrapT = TextureWrapMode.Clamp;
TextureWrapR = TextureWrapMode.Clamp;
TextureMinFilter = TextureMinFilter.LinearMipmapLinear;
TextureMagFilter = TextureMagFilter.Linear;
}
//Force RGBA and use ST for decoding for weird width/heights
//Open GL decoder has issues with certain width/heights
@ -191,6 +213,15 @@ namespace Toolbox.Library.Rendering
TexID = GenerateOpenGLTexture(this, Surfaces);
if (IsCubeMap)
{
TextureWrapS = TextureWrapMode.Clamp;
TextureWrapT = TextureWrapMode.Clamp;
TextureWrapR = TextureWrapMode.Clamp;
TextureMinFilter = TextureMinFilter.LinearMipmapLinear;
TextureMagFilter = TextureMagFilter.Linear;
}
Surfaces.Clear();
}
@ -352,7 +383,6 @@ namespace Toolbox.Library.Rendering
return -1;
int texID = GL.GenTexture();
GL.BindTexture(t.TextureTarget, texID);
if (t.IsCubeMap)
{
@ -363,14 +393,10 @@ namespace Toolbox.Library.Rendering
int width = Math.Max(1, t.width >> mipLevel);
int height = Math.Max(1, t.height >> mipLevel);
t.LoadCompressedMips(TextureTarget.TextureCubeMapPositiveX, ImageData[0], width, height, mipLevel);
t.LoadCompressedMips(TextureTarget.TextureCubeMapNegativeX, ImageData[1], width, height, mipLevel);
for (int i = 0; i < 6; i++)
t.LoadCompressedMips(TextureTarget.TextureCubeMapPositiveX + i, ImageData[i], width, height, mipLevel);
t.LoadCompressedMips(TextureTarget.TextureCubeMapPositiveY, ImageData[2], width, height, mipLevel);
t.LoadCompressedMips(TextureTarget.TextureCubeMapNegativeY, ImageData[3], width, height, mipLevel);
t.LoadCompressedMips(TextureTarget.TextureCubeMapPositiveZ, ImageData[4], width, height, mipLevel);
t.LoadCompressedMips(TextureTarget.TextureCubeMapNegativeZ, ImageData[5], width, height, mipLevel);
break;
}
}
else
@ -380,19 +406,15 @@ namespace Toolbox.Library.Rendering
int width = Math.Max(1, t.width >> mipLevel);
int height = Math.Max(1, t.height >> mipLevel);
t.LoadUncompressedMips(TextureTarget.TextureCubeMapPositiveX, ImageData[0], width, height, mipLevel);
t.LoadUncompressedMips(TextureTarget.TextureCubeMapNegativeX, ImageData[1], width, height, mipLevel);
for (int i = 0; i < 6; i++)
t.LoadUncompressedMips(TextureTarget.TextureCubeMapPositiveX + i, ImageData[i], width, height, mipLevel);
t.LoadUncompressedMips(TextureTarget.TextureCubeMapPositiveY, ImageData[2], width, height, mipLevel);
t.LoadUncompressedMips(TextureTarget.TextureCubeMapNegativeY, ImageData[3], width, height, mipLevel);
t.LoadUncompressedMips(TextureTarget.TextureCubeMapPositiveZ, ImageData[4], width, height, mipLevel);
t.LoadUncompressedMips(TextureTarget.TextureCubeMapNegativeZ, ImageData[5], width, height, mipLevel);
break;
}
}
if (ImageData[0].mipmaps.Count == 1)
GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMap);
GL.GenerateMipmap(GenerateMipmapTarget.TextureCubeMap);
// if (ImageData[0].mipmaps.Count == 1)
}
else
{
@ -430,9 +452,18 @@ namespace Toolbox.Library.Rendering
// GL.GenerateMipmap((GenerateMipmapTarget)textureTarget);
}
public void LoadParameters()
{
}
public void Bind()
{
if (TexID == -1) return;
GL.BindTexture(TextureTarget, TexID);
Console.WriteLine($"binding {TextureTarget} {TexID}");
}
private static int getImageSize(RenderableTex t)