-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2590beb
commit f84497e
Showing
9 changed files
with
247 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System.Numerics; | ||
|
||
namespace JAngine.Rendering.OpenGL; | ||
|
||
public sealed class Texture : IGlObject | ||
{ | ||
private uint _handle; | ||
private readonly Window _window; | ||
private readonly Vector4[,] _pixels; | ||
|
||
public Texture(Window window, string name, Vector4[,] pixels) | ||
{ | ||
_window = window; | ||
Name = name; | ||
Width = pixels.GetLength(0); | ||
Height = pixels.GetLength(1); | ||
|
||
window.QueueUpdate(this, CreateEvent.Singleton); | ||
window.QueueUpdate(this, UpdateDataEvent.Default); | ||
_pixels = pixels; | ||
} | ||
|
||
public int Width { get; } | ||
public int Height { get; } | ||
|
||
uint IGlObject.Handle => _handle; | ||
public string Name { get; } | ||
Window IGlObject.Window => _window; | ||
void IGlObject.DispatchEvent(IGlEvent glEvent) | ||
{ | ||
switch (glEvent) | ||
{ | ||
case CreateEvent: | ||
_handle = Gl.CreateTexture(Gl.TextureTarget.Texture2D); | ||
Gl.TextureStorage2D(_handle, 1, Gl.SizedInternalFormat.Rgba32F, Width, Height); | ||
break; | ||
case UpdateDataEvent: | ||
Gl.TextureSubImage2D(_handle, 0, 0, 0, Width, Height, Gl.PixelFormat.Rgba, Gl.PixelType.Float, ref _pixels[0, 0]); | ||
Gl.GenerateTextureMipmap(_handle); | ||
break; | ||
} | ||
} | ||
|
||
internal void Bind(uint unit) | ||
{ | ||
Gl.BindTextureUnit(unit, _handle); | ||
} | ||
} |
Oops, something went wrong.