1
因此,我正在更新我的應用程序以使用OpenGLES 3.0來利用轉換反饋,但着色器未編譯。OpenGLES 3.0着色器在Android設備上編譯進出存儲限定符的錯誤
錯誤:
06-27 17:29:43.299 18593-18627/com.harmonicprocesses.penelopefree E/MyGLRenderer﹕ Could not compile shader 35633:
06-27 17:29:43.299 18593-18627/com.harmonicprocesses.penelopefree E/MyGLRenderer﹕ ERROR: 0:1: 'in' : Syntax error: syntax error
INTERNAL ERROR: no main() function!
ERROR: 1 compilation errors. No code generated.
這裏是頂點着色器代碼:
private final String vertexShaderSrc =
"in float inValue;" +
"out float outValue;" +
"void main() {" +
" outValue = sqrt(inValue);" +
"}";
以下是編譯代碼:
int vertexShader = MyGLRenderer.loadShader(GLES30.GL_VERTEX_SHADER,
vertexShaderSrc);
...
public static int loadShader(int shaderType, String source) {
int shader = GLES30.glCreateShader(shaderType);
if (shader != 0) {
GLES30.glShaderSource(shader, source);
GLES30.glCompileShader(shader);
int[] compiled = new int[1];
GLES30.glGetShaderiv(shader, GLES30.GL_COMPILE_STATUS, compiled, 0);
if (compiled[0] == 0) {
Log.e(TAG, "Could not compile shader " + shaderType + ":");
Log.e(TAG, GLES30.glGetShaderInfoLog(shader));
GLES30.glDeleteShader(shader);
shader = 0;
}
}
return shader;
}
有沒有人看到這有什麼問題?如果我分別更改in
和out
至attribute
varying
它不會引發錯誤,但glUseProgram會拋出gl錯誤1282「無效操作」。
這是我如何設置GL爲ES版本3.0:
public MyGLSurfaceViewLegacy(Context context) {
super(context);
setListenForTouchOnTouchListener();
NoteSpectrum = DSPEngine.staticCalcNoteBins(AudioConstants.defaultBufferSize*2,
AudioConstants.sampleRate);
// Create an OpenGL ES 2.0 context.
setEGLContextClientVersion(3);
// Set the Renderer for drawing on the GLSurfaceView
mRenderer = new MyGLRenderer(context,this);
setEGLConfigChooser(8, 8, 8, 8, 16, 0);
mContextFactory = new MyContextFactory();
setEGLContextFactory(mContextFactory);
//mEGLWindowSurfaceFactory = new MyEGLWindowSurfaceFactory();
//setEGLWindowSurfaceFactory(mEGLWindowSurfaceFactory);
setRenderer(mRenderer);
getHolder().setFormat(PixelFormat.TRANSLUCENT);
// Render the view only when there is a change in the drawing data
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
mContext = context;
drawOverlay = PreferenceManager.getDefaultSharedPreferences(mContext)
.getBoolean("turn_on_visualization_key",true);
}
class MyContextFactory implements EGLContextFactory {
private int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
private EGLContext mEGLContext;
private EGLDisplay mEGLDisplay;
private MyGLSurfaceView mMyGLSurfaceView;
private EGL10 mEGL;
@Override
public EGLContext createContext(EGL10 egl, EGLDisplay display,
EGLConfig eglConfig) {
int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 3,
EGL10.EGL_NONE };
mEGL = egl;
mEGLContext = egl.eglGetCurrentContext();
mEGLDisplay = display;
mEGLContext = egl.eglCreateContext(display, eglConfig,
egl.eglGetCurrentContext(), attrib_list);
return mEGLContext;
}
謝謝,但它會在該標題中引發「無效#version」錯誤。 – HPP
我在支持OpenGLES 3.1的Nexus 6上進行測試,並添加了我的EGL設置案例,在那裏還有其他缺失的東西。 – HPP
哦,我錯過了「#version 300 es」之後的換行符,即「#version 300 es \ n」。非常感謝! – HPP