Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement OpenGL default texture #526

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/main/java/net/vulkanmod/gl/GlTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class GlTexture {
private static int ID_COUNTER = 1;
private static final Int2ReferenceOpenHashMap<GlTexture> map = new Int2ReferenceOpenHashMap<>();
private static int boundTextureId = 0;
private static GlTexture defaultTexture;
private static GlTexture boundTexture;
private static int activeTexture = 0;

Expand All @@ -35,11 +36,26 @@ public static int genTextureId() {
return id;
}

// Default texture can vary depending on graphic drivers,
// but it's usually a square that is either white or black
private static GlTexture getDefaultTexture() {
if (GlTexture.defaultTexture != null)
return GlTexture.defaultTexture;
GlTexture defaultTexture = new GlTexture(0);
defaultTexture.vulkanImage = VulkanImage.createWhiteTexture();
GlTexture.defaultTexture = defaultTexture;
return defaultTexture;
}

public static void bindTexture(int id) {
boundTextureId = id;
boundTexture = map.get(id);
if (id == 0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not adding it directly to the map instead of doing that check?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that, but I would have to add a direct if () statement for glDeleteTextures, as the documentations says for ID deleting texture should be a noop.

Also, I cannot move image initialization to the static initializer as VulkanImage need the static initialize of GlTexture for some reason.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boundTexture = getDefaultTexture();
} else {
boundTexture = map.get(id);
}

if (id <= 0)
if (id < 0)
return;

if (boundTexture == null)
Expand Down