libgdx / libgdx/libgdx

Feature request: add sRGB internal format of texture

Open
#5,354 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement GL
Dominant language
Java
Stars
25.4k
Forks
6.5k
Avg merge
1d 16h
Merged PRs (30d)
5

Description

Internal format sRGB is same as RGB, but openGL automatically does gamma-correction when reading colors from texture. This is used in HDR rendering.

Way to add this:

code in GLTexure.uploadImageData:

Gdx.gl.glTexImage2D(target, miplevel, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels());

So, getGLInternalFormat is returned by Pixmap:

public int getGLInternalFormat () {
	return toGlFormat(format);
}

but toGlFormat never returns sRGB:

public static int toGlFormat (int format) {
	switch (format) {
	case GDX2D_FORMAT_ALPHA:
		return GL20.GL_ALPHA;
	case GDX2D_FORMAT_LUMINANCE_ALPHA:
		return GL20.GL_LUMINANCE_ALPHA;
	case GDX2D_FORMAT_RGB888:
	case GDX2D_FORMAT_RGB565:
		return GL20.GL_RGB;
	case GDX2D_FORMAT_RGBA8888:
	case GDX2D_FORMAT_RGBA4444:
		return GL20.GL_RGBA;
	default:
		throw new GdxRuntimeException("unknown format: " + format);
	}
}

As I think, one can add a few new formats or/and special flag to the Texture constructor.

P.S. Now I am achieving this by overriding Pixmap.getGLInternalFormat() method and returning something like GL30.GL_SRGB8_ALPHA8 or GL30.GL_SRGB8

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with GLTexture.uploadImageData in gdx/src/com/badlogic/gdx/graphics/GLTexture.java and Pixmap.getGLInternalFormat and toGlFormat in Pixmap.java. Review how the Texture constructor and GL20/GL30 formats are exposed, then define a compatible way to request sRGB internal formats. Done means texture uploads can use sRGB formats without breaking the existing RGB and RGBA paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
computer-graphics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
39/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.