迫使OpenGL的缓冲区使用GL 1.0或1.1? [英] Forcing OpenGL Buffer to use GL 1.0 or 1.1?

查看:151
本文介绍了迫使OpenGL的缓冲区使用GL 1.0或1.1?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直工作在一个项目中,用户可以用 GLSurfaceView 在屏幕上绘制图形交互。这一切工作非常愉快,但现在我试图做两件事情:1)创建自己的绘图的缩略图,以及2)保存自己的绘图。重要的是要注意的是,用户可以绘制图像是大于屏幕

I've been working on a project in which a user can interact with a GLSurfaceView to draw shapes on a screen. This all works fine and dandy, but now I'm attempting to do two things: 1) create a thumbnail of their drawing, and 2) save their drawing. It's important to note that the user can draw an image which is larger than the screen.

据我的研究表明,这是最好的实现使用位图(可以是1)呈现为一个画布为缩略图,和2)被保存到文件系统,该系统实现了我的目标两者)。

As far as my research shows, this is best achieved using a Bitmap (which can be 1) rendered to a Canvas for a thumbnail, and 2) be saved to the file system, which achieves both of my goals).

起初,我试着读渲染 GLSurfaceView 通过 glReadPixels ,但事实证明,我无法从该屏幕外的数据。相反,我选择做一个离屏缓冲,以产生渲染图像,它可以被转换成一个位图

Initially, I tried to read the Renderer from the GLSurfaceView via glReadPixels, but it turns out I couldn't get the off-screen data from this. Instead, I opted to do an off-screen buffer to produce a render of the image, which could be converted to a Bitmap.

我发现href="http://www.anddev.org/post41662.html#p41662" rel="nofollow">这对于一类叫做提供了code可爱的帖子一个 PixelBuffer ,我现在用的。 (我做了一些调整,但说我已经把所有的问题发生或没有调整。)

I found a lovely post which provided a code for a class called PixelBuffer, which I am now using. (I've made a few tweaks, but all issues I've had occur with or without said tweaking.)

现在,当使用 getBitmap()的code(我将在下面张贴在事件的 PixelBuffer 论坛主题是不可读的),我收到了一堆称为未实现的OpenGL ES API 。这让我觉得奇怪,在第一,所以我做了一些调查。事实证明,由于某种原因,在 PixelBuffer 类是使用OpenGL ES 2.0,而GLSurfaceView正在使用的OpenGL ES 1.1。我正在使用的设备(Galaxy Nexus的)不支持2.0。 (而且,我想尽可能支持设备的最大范围内。)

Now, when using the getBitmap() of the code (which I will post below in the event the PixelBuffer forum thread is unreadable), I get a bunch of called unimplemented OpenGL ES API. This struck me as odd at first, so I did some investigating. It turns out that, for some reason, the PixelBuffer class is using OpenGL ES 2.0, while the GLSurfaceView is using OpenGL ES 1.1. The device I'm using (Galaxy Nexus) doesn't support 2.0. (And moreover, I'd like to support the largest range of devices possible.)

所以,这里是我的问题:我怎么能强迫我的 PixelBuffer 类使用的OpenGL ES 1.1 API?我已经加在我的清单如下:

So, here is my question: How can I force my PixelBuffer class to use the OpenGL ES 1.1 API? I have already added the following in my Manifest:

<uses-feature android:glEsVersion="0x00010001" />

此外,我试图用设置版本 INT []版本=新INT [] {1,1}; ,都无济于事。

Additionally, I have attempted to set the version using int[] version = new int[] { 1, 1 };, to no avail.

PixelBuffer code我使用:链接 。调用渲染上线91的版本$ C $,C是39行上下的以后有问题就行了。

The PixelBuffer code I'm using: Link. The line in question that calls the Renderer is on line 91. The version code is on line 39-ish onward.

这是在code我用它来创建 PixelBuffer ,从 GLSurfaceView 对象调用:

This is the code I use to create the PixelBuffer, called from the GLSurfaceView object:

    setEGLConfigChooser(8, 8, 8, 8, 0, 0);
    mRenderer = new MyRenderer(this);
    setRenderer(mRenderer);
    mPixelBuffer = new CPPixelBuffer(1440, 1280); // TODO Temporary hardcode for Galaxy Nexus wallpaper size
    mPixelBuffer.setRenderer(mRenderer);

如果这是不可能使用1.1​​版本的屏幕外渲染,什么是我的GL表面转换成最佳的方式位图使用版本1.1或更低?

If it is not possible to use version 1.1 for an offscreen render, what is the best way to convert my GL surface to a Bitmap using version 1.1 or lower?

修改:通过一些测试,我发现,使用下面的code使这些错误:

EDIT: Through some testing, I discovered that using the below code causes these errors:

// int[] version = new int[2];
int[] version = new int[] { // When using this line, as well as the other marked lines, instead of the line above, the errors are produced.
    1, 1 // Marked
}; // Marked
int[] attribList = new int[] {
    EGL_WIDTH, mWidth,
    EGL_HEIGHT, mHeight,
    EGL_VERSION, 1, // Marked
    EGL_NONE
};

06-11 15:41:52.316: E/libEGL(5618): eglMakeCurrent:674 error 3009 (EGL_BAD_MATCH)
06-11 15:41:52.316: E/libEGL(5618): call to OpenGL ES API with no current context (logged once per thread)

然而,无论这些设置手头缓解这个问题。他们只是两个present在我PasteBin'd code,所以我认为这将是很好的指出来。

However, neither of these setups alleviate the issue at hand. They are just both present in my PasteBin'd code, so I thought it would be good to point it out.

推荐答案

我没有找到某种原因发表评论,所以很抱歉张贴这作为一个答案的链接。关于GL线程,通常你是在GL线程仅在

I didnt find for some reason the link to post a comment, so sorry about posting this as an answer. About the GL thread, normally you are in GL thread only in

public void onDrawFrame(GL10 gl)

这是渲染器的方法。一切都必须在这个方法中完成。你可以把一个布尔值,可以说,到渲染器,当你想要的东西要在渲染器做了设置为true,仅此而已。如果你做任何调用这个方法之外,你会得到erorrs。

Which is a method of the Renderer. Everything must be done inside this method. You can just put a boolean, lets say, into the renderer, and set it to true when you want something to be done in the renderer, and that's it. If you do any call outside this method, you will get erorrs.

另外,看看下面这个例子: Android的OpenGL的截图 我已经用它和它的工作对我来说,但我并不需要保存屏幕外区域,所以我不知道这是否会工作,也许不是:)

Also, look at this example: Android OpenGL Screenshot I have used it and it worked for me, but I didn't need to save off-screen area, so I don't know if it will work, maybe not :)

该方法必须内onDrawFrame叫

The method must be called inside onDrawFrame

这篇关于迫使OpenGL的缓冲区使用GL 1.0或1.1?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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