OpenGL ES 2.0升級到3.0配置win32環境以及編譯所遇bug

安裝win32平臺的OpenGL ES 3.0模擬器

一,安裝3.0模擬器,一般用32位的(https://developer.arm.com/products/software-development-tools/graphics-development-tools/opengl-es-emulator

二,測試模擬器

在安裝目錄點擊mali-cube.exe,如果出現立方體轉動說明模擬器安裝成功。

三,配置環境

將安裝目錄中的libEGL.dll libGLESv2.dll文件和openglessl文件夾拷貝到C:\Windows\System32以及\Visual Studio\VC\bin 裏面,libEGL.lib和libGLESv2.lib文件拷到\Visual Studio\VC\lib中,如果項目中需要也得拷貝一份。

編譯所遇bug

一,Compilation error in shader: Error: 0:4: L0003: Keyword ‘attribute’ is reserved, Keyword ‘varying’ is reserved

OpenGL ES 3.0中將2.0的attribute改成了in,頂點着色器的varying改成out,片段着色器的varying改成了in,也就是說頂點着色器的輸出就是片段着色器的輸入,另外uniform跟2.0用法一樣

二,0:11: S0001: Type mismatch in arithmetic operation between ‘int’ and ‘float’

float和int不能做操作,必須轉成相同類型,也就是說算術操作中不能同時有1和1.0相加這種情況。

三,設備不支持下述擴展

Compilation error in shader: 0:2: P0003: Warning: Extension 'GL_OES_EGL_image_external' not supported
0:3: P0003: Warning: Extension 'GL_OES_EGL_image_external_essl3' not supported

查看設備所支持的擴展:

String str= GLES20.glGetString(GLES20.GL_EXTENSIONS);

注意:這句代碼必須在OpenGL ES環境配置好才能調用,如可以在onSurfaceChanged中調用

四,Expected token ‘{‘, found ‘identifier’

這種錯誤一般是語法錯誤,比如使用samplerExternalOES,但是沒加#extension GL_OES_EGL_image_external : require

五,1,0:1: Warning: GL_OES_EGL_image_external is deprecated in ESSL 3 and later versions

這個警告可以忽視,因爲不加#extension GL_OES_EGL_image_external : require,當使用samplerExternalOES時就會報這個錯誤,ERROR: 0:6: ‘samplerExternalOES’ : requires extension GL_OES_EGL_image_external_essl3 to be enabled

六,D/MALI: gles_state_set_error_internal:70: [MALI] GLES error info:currently bound framebuffer is not valid for this operation

當前操作不需要幀緩衝區,取消掉即可

七,GLES error info: , and are not a valid combination

當使用glTexImage3D(GLES30.GL_TEXTURE_3D, 0, GLES30.GL_RGB, size, size, size, 0, GLES30.GL_RGB, GLES30.GL_FLOAT, buffer);時,buffer的類型使用ByteBuffer代替FloatBuffer,GLES30.GL_FLOAT類型也要改變成GL_UNSIGNED_BYTE,這裏buffer的大小必須是size * size * size * 3

八,No matching function for call to ‘texture2D’,No matching function for call to ‘texture3D’

OpenGL ES 3.0的shader中沒有texture2D和texture3D等了,全部使用texture替換

九,0:14: L0002: Undeclared variable ‘gl_FragColor’

OpenGL ES 2.0的gl_FragColor和gl_FragData在3.0中取消掉了,需要自己定義out變量作爲片段着色器的輸出顏色,如 out vec4 fragColor;

gl_Position還存在

十,0:13: S0047: Output variable declared inside a function

in或者out變量等不能在函數內(如main函數內)聲明

十一,MALI: gles_state_set_error_internal:70: [MALI] GLES error info: is not an accepted value

應該這樣使用glActiveTexture(GL_TEXTURE0 + n); //n爲0,1,2……

不要因爲使用GL_TEXTURE_3D或GLES11Ext.GL_TEXTURE_EXTERNAL_OES等紋理類型,而使用glActiveTexture(GL_TEXTURE_EXTERNAL_OES);或glActiveTexture(GL_TEXTURE_3D );,這樣是錯誤的。

十二,#version must be the first directive/statement in a program

Compilation error in shader: Error: 0:2: P0005: #version must be on the first line in a program and only whitespace are allowed in the declaration

“#version 300 es”此類語句放在第一行,並且shader中不能有Tab鍵,只能用空格替換

十三,glCompileShader -> No shader compiler found.

將3.0模擬器中的openglessl放在C:\Windows\System32或C:\Windows\SysWOW64中

十四,win32運行有下述錯誤

error LNK2001: unresolved external symbol __imp__glTexImage3D@40

找不到glTexImage3D函數,libEGL.lib和libGLESv2.lib庫版本不對,換成3.0的即可

十五,Compilation error in shader: Error: 0:4: L0001: Storage qualifier not allowed

這是因爲使用3.0的語法,卻沒有加上#version 300 es

作者:lb377463323
出處:http://blog.csdn.net/lb377463323
原文鏈接:http://blog.csdn.net/lb377463323/article/details/77047221
轉載請註明出處!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章