Fix for windows
This commit is contained in:
+58
-5
@@ -105,7 +105,60 @@ public sealed unsafe class OpenGLTexture : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
public static OpenGLTexture FromBgra32(GL gl, nint pixels, int width, int height, int stride)
|
||||
{
|
||||
if (pixels == nint.Zero)
|
||||
{
|
||||
throw new ArgumentException("Pixels cannot be null.", nameof(pixels));
|
||||
}
|
||||
|
||||
uint texture = CreateTexture(gl, pixels, width, height, stride, GLPixelFormat.Bgra);
|
||||
return new OpenGLTexture(gl, texture, width, height);
|
||||
}
|
||||
|
||||
public static OpenGLTexture FromHandle(GL gl, uint handle, int width, int height)
|
||||
{
|
||||
if (handle == 0)
|
||||
{
|
||||
throw new ArgumentException("Texture handle cannot be zero.", nameof(handle));
|
||||
}
|
||||
|
||||
return new OpenGLTexture(gl, handle, width, height);
|
||||
}
|
||||
|
||||
public void UpdateBgra32(nint pixels, int stride)
|
||||
{
|
||||
if (pixels == nint.Zero)
|
||||
{
|
||||
throw new ArgumentException("Pixels cannot be null.", nameof(pixels));
|
||||
}
|
||||
|
||||
_gl.GetIntegerv(GLGetPName.TextureBinding2D, out int previousTexture);
|
||||
_gl.BindTexture(GLTextureTarget.Texture2D, Handle);
|
||||
|
||||
_gl.PixelStorei(GLPixelStoreParameter.UnpackAlignment, 1);
|
||||
_gl.PixelStorei(GLPixelStoreParameter.UnpackRowLength, stride / 4);
|
||||
_gl.TexSubImage2D(
|
||||
GLTextureTarget.Texture2D,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
Width,
|
||||
Height,
|
||||
GLPixelFormat.Bgra,
|
||||
GLPixelType.UnsignedByte,
|
||||
pixels);
|
||||
_gl.PixelStorei(GLPixelStoreParameter.UnpackRowLength, 0);
|
||||
|
||||
_gl.BindTexture(GLTextureTarget.Texture2D, (uint)previousTexture);
|
||||
}
|
||||
|
||||
private static uint UploadRgba32(GL gl, SDL.Surface* surface)
|
||||
{
|
||||
return CreateTexture(gl, surface->Pixels, surface->Width, surface->Height, surface->Pitch, GLPixelFormat.Rgba);
|
||||
}
|
||||
|
||||
private static uint CreateTexture(GL gl, nint pixels, int width, int height, int stride, GLPixelFormat pixelFormat)
|
||||
{
|
||||
uint texture = 0;
|
||||
gl.GenTextures(1, ref texture);
|
||||
@@ -119,17 +172,17 @@ public sealed unsafe class OpenGLTexture : IDisposable
|
||||
gl.TexParameteri(GLTextureTarget.Texture2D, GLTextureParameterName.WrapT, (int)GLEnum.ClampToEdge);
|
||||
|
||||
gl.PixelStorei(GLPixelStoreParameter.UnpackAlignment, 1);
|
||||
gl.PixelStorei(GLPixelStoreParameter.UnpackRowLength, surface->Pitch / 4);
|
||||
gl.PixelStorei(GLPixelStoreParameter.UnpackRowLength, stride / 4);
|
||||
gl.TexImage2D(
|
||||
GLTextureTarget.Texture2D,
|
||||
0,
|
||||
GLInternalFormat.Rgba,
|
||||
surface->Width,
|
||||
surface->Height,
|
||||
width,
|
||||
height,
|
||||
0,
|
||||
GLPixelFormat.Rgba,
|
||||
pixelFormat,
|
||||
GLPixelType.UnsignedByte,
|
||||
surface->Pixels);
|
||||
pixels);
|
||||
gl.PixelStorei(GLPixelStoreParameter.UnpackRowLength, 0);
|
||||
|
||||
gl.BindTexture(GLTextureTarget.Texture2D, (uint)previousTexture);
|
||||
|
||||
Reference in New Issue
Block a user