的OpenGL ES API没有当前上下文 [英] opengl es api with no current context
问题描述
我已经通过解决方案看,并没有真正找到了一个。我收到此错误,因为它似乎是在执行发生在GL线程之外。但是我不知道如何解决这个问题。在code是如下:
I have looked through the solutions and haven't really found one. I am getting this error because it seems like the execution happens outside of the gl thread. However I am not sure how to fix this. The code is as follows:
public shape()
{
super();
vertexShader = Shader.loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode); //<============
fragmentShader = Shader.loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);
ByteBuffer buffer = ByteBuffer.allocateDirect(getCoordinates().length * 4);
buffer.order(ByteOrder.nativeOrder());
vertexBuffer = buffer.asFloatBuffer();
vertexBuffer.put(getCoordinates());
vertexBuffer.position(0);
ByteBuffer drawListBuffer = ByteBuffer.allocateDirect(getOrderOfDraw().length * 2);
drawListBuffer.order(ByteOrder.nativeOrder());
listBuffer = drawListBuffer.asShortBuffer();
listBuffer.put(getOrderOfDraw());
listBuffer.position(0);
mProgram = GLES20.glCreateProgram(); // create empty OpenGL Program
GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader to program
GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
GLES20.glLinkProgram(mProgram);
}
和呼叫渲染器
Square square = new Square(5, 5);
public void onDrawFrame(GL10 unused)
{
unused.glLoadIdentity();
unused.glClear(GLES20.GL_COLOR_BUFFER_BIT);
square.Draw();
}
广场的形状延伸
Square extends from shape
推荐答案
如果是新广场(5,5);
不是任何OpenGL的回调的一部分(我假设你使用的是glSurfaceView),那么我不认为它运行在OpenGL的线程上。创建您的glSurfaceView时,它会被执行,我相信这是主要的机器人线程。
If that new Square(5,5);
is not part of any of the opengl callbacks (I assume you're using a glSurfaceView), then I don't think it runs on the OpenGL thread. It will be executed when your glSurfaceView is created, which I believe is on the main android thread.
尝试移动新广场(5,5);
里面的 onSurfaceCreated
这篇关于的OpenGL ES API没有当前上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!