Author Topic: Color bug  (Read 2371 times)

Offline AeroShark333

  • long
  • ***
  • Posts: 149
    • View Profile
Re: Color bug
« Reply #15 on: October 20, 2015, 01:28:12 am »
Not sure, but could my EGLConfig be an issue?:
Code: [Select]
public class CustomEGLConfig implements EGLConfigChooser {
final private static int EGL_OPENGL_ES1_BIT = 0x01;
final private static int EGL_OPENGL_ES2_BIT = 0x04;

private static int[] mMinimumSpec2 = {
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,

EGL10.EGL_SURFACE_TYPE, EGL10.EGL_WINDOW_BIT,

EGL10.EGL_TRANSPARENT_TYPE, EGL10.EGL_NONE,

EGL10.EGL_NONE };
private static int[] mMinimumSpec1 = {
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES1_BIT,

EGL10.EGL_SURFACE_TYPE, EGL10.EGL_WINDOW_BIT,

EGL10.EGL_TRANSPARENT_TYPE, EGL10.EGL_NONE,

EGL10.EGL_NONE };

private int[] mValue = new int[1];
protected int mAlphaSize;
protected int mBlueSize;
protected int mDepthSize;
protected int mGreenSize;
protected int mRedSize;
protected int mStencilSize;
protected boolean openGL2;

@SuppressWarnings("deprecation")
public CustomEGLConfig(int depth, int stencil, boolean useOpenGl2,
Display display) {
int pixelFormatVal;
try {
pixelFormatVal = display.getPixelFormat();
} catch (NullPointerException e) {
e.printStackTrace();
pixelFormatVal = PixelFormat.RGBA_8888;
}
final int aBits, rBits, gBits, bBits;

if (pixelFormatVal > 0) {

PixelFormat info = new PixelFormat();
PixelFormat.getPixelFormatInfo(pixelFormatVal, info);

if (PixelFormat.formatHasAlpha(pixelFormatVal)) {

if (info.bitsPerPixel >= 24) {
aBits = 8;
} else {
aBits = 6; // total guess
}

} else {
aBits = 0;
}

if (info.bitsPerPixel >= 24) {
rBits = 8;
gBits = 8;
bBits = 8;
} else if (info.bitsPerPixel >= 16) {
rBits = 5;
gBits = 6;
bBits = 5;
} else {
rBits = 4;
gBits = 4;
bBits = 4;
}

} else {
rBits = 8;
gBits = 8;
bBits = 8;
aBits = 8;
}

mRedSize = rBits;
mGreenSize = gBits;
mBlueSize = bBits;
mAlphaSize = aBits;

mDepthSize = depth;
mStencilSize = stencil;
openGL2 = useOpenGl2;
}

@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
int[] arg = new int[1];
if (openGL2) {
egl.eglChooseConfig(display, mMinimumSpec2, null, 0, arg);
} else {
egl.eglChooseConfig(display, mMinimumSpec1, null, 0, arg);
}
int numConfigs = arg[0];

if (numConfigs <= 0) {
int[] attributes = new int[] { EGL10.EGL_DEPTH_SIZE, 16,
EGL10.EGL_NONE };
EGLConfig[] configs = new EGLConfig[1];
int[] result = new int[1];
egl.eglChooseConfig(display, attributes, configs, 1, result);
return configs[0];

}

EGLConfig[] configs = new EGLConfig[numConfigs];
if (openGL2) {
egl.eglChooseConfig(display, mMinimumSpec2, configs, numConfigs,
arg);
} else {
egl.eglChooseConfig(display, mMinimumSpec1, configs, numConfigs,
arg);
}

EGLConfig chosen = chooseConfig(egl, display, configs);

if (chosen == null) {
throw new RuntimeException(
"Could not find a matching configuration out of "
+ configs.length + " available.");
}

return chosen;
}

public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display,
EGLConfig[] configs) {
EGLConfig bestMatch = null;
int bestR = Integer.MAX_VALUE, bestG = Integer.MAX_VALUE, bestB = Integer.MAX_VALUE, bestA = Integer.MAX_VALUE, bestD = Integer.MAX_VALUE, bestS = Integer.MAX_VALUE;

for (EGLConfig config : configs) {
int r = findConfigAttrib(egl, display, config, EGL10.EGL_RED_SIZE,
0);
int g = findConfigAttrib(egl, display, config,
EGL10.EGL_GREEN_SIZE, 0);
int b = findConfigAttrib(egl, display, config, EGL10.EGL_BLUE_SIZE,
0);
int a = findConfigAttrib(egl, display, config,
EGL10.EGL_ALPHA_SIZE, 0);
int d = findConfigAttrib(egl, display, config,
EGL10.EGL_DEPTH_SIZE, 0);
int s = findConfigAttrib(egl, display, config,
EGL10.EGL_STENCIL_SIZE, 0);

if (r <= bestR && g <= bestG && b <= bestB && a <= bestA
&& d <= bestD && s <= bestS && r >= mRedSize
&& g >= mGreenSize && b >= mBlueSize && a >= mAlphaSize
&& d >= mDepthSize && s >= mStencilSize) {
bestR = r;
bestG = g;
bestB = b;
bestA = a;
bestD = d;
bestS = s;
bestMatch = config;
}
}

return bestMatch;
}

private int findConfigAttrib(EGL10 egl, EGLDisplay display,
EGLConfig config, int attribute, int defaultValue) {

if (egl.eglGetConfigAttrib(display, config, attribute, mValue)) {
return mValue[0];
}

return defaultValue;
}
}

Called like:
Code: [Select]
gLView.setEGLConfigChooser(new CustomEGLConfig(16, 0, true, this
.getWindowManager().getDefaultDisplay()));
'this' -> Activity context

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: Color bug
« Reply #16 on: October 20, 2015, 06:53:48 am »
I don't see why that should cause this....