Android设备上用于进出存储限定符的OpenGLES 3.0 Shader编译错误 [英] OpenGLES 3.0 Shader Compile error on Android Device for in and out storage qualifiers

查看:523
本文介绍了Android设备上用于进出存储限定符的OpenGLES 3.0 Shader编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在更新我的应用程序,以使用OpenGLES 3.0来利用变换反馈,但着色器未编译.

So I am updating my app to use OpenGLES 3.0 to take advantage of transform feedback, but the shader isn't compiling.

错误:

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;
}

有人看到这有什么问题吗?如果将inout分别更改为attribute varying,它不会引发错误,但是glUseProgram会引发gl错误1282无效操作".

Does anyone see anything wrong with this? If I change in and out to attribute varying respectively it doesn't throw an error, but glUseProgram throw gl error 1282 "Invalid Operation".

这是我为es 3.0版设置GL的方法:

This is how I set up GL for es version 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;
}

推荐答案

将OpenGLES 3.0版本说明符添加到着色器的开头:

Add the OpenGLES 3.0 version specifier to the start of your shader:

#version 300 es

还要确保您正在GLSurfaceView设置代码中调用setEGLContextClientVersion(3).

Also make sure you are calling setEGLContextClientVersion(3) in your GLSurfaceView setup code.

这篇关于Android设备上用于进出存储限定符的OpenGLES 3.0 Shader编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆