0

我正在使用 Windows CE 7 上的 OMAP3530 开发板开发 Opengl ES 2.0。

我的任务是加载一个 24 位图像文件并在 z 轴上旋转一个角度并导出图像文件(缓冲区)。

对于此任务,我创建了一个用于屏幕外渲染的 FBO,并使用 glTexImage2D() 将此图像文件加载为纹理,并且我将此纹理应用于 Quad,并使用 PVRTMat4::RotationZ() API 旋转该 QUAD & 使用 ReadPixels() API 回读。由于它是一个单帧过程,我只制作了 1 个循环。

以下是我现在面临的问题。1)所有API在每次运行时都需要不同的处理时间。即有时当我运行我的应用程序时,所有API的处理时间都不同。

2) glDrawArrays() 花费了太多时间(~50 ms - 80 ms)

3) glReadPixels() 对于 Image(800x600) 也花费了太多时间~95 ms

4) 加载 32 位图像比 24 位图像快得多,因此需要转换。

我想问大家是否有人面临/解决了类似的问题,请给我任何建议

这是我的应用程序的代码片段。

[code]
[i]
void BindTexture(){
glGenTextures(1, &m_uiTexture);
glBindTexture(GL_TEXTURE_2D, m_uiTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ImageWidth, ImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pTexData);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR );
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, TCHAR *lpCmdLine, int nCmdShow)
{
// Fragment and vertex shaders code
char* pszFragShader = "Same as in RenderToTexture sample;
char* pszVertShader = "Same as in RenderToTexture sample;

CreateWindow(Imagewidth, ImageHeight);//For this i've referred OGLES2HelloTriangle_Windows.cpp example
LoadImageBuffers();
BindTexture();

Generate& BindFrame,Render Buffer();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_auiFbo, 0);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, ImageWidth, ImageHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_auiDepthBuffer);
BindTexture();

GLfloat Angle = 0.02f;
GLfloat afVertices[] = {Vertices to Draw a QUAD};

glGenBuffers(1, &ui32Vbo);
LoadVBO's();//Aps's to load VBO's refer

// Draws a triangle for 1 frames
while(g_bDemoDone==false)
{
glBindFramebuffer(GL_FRAMEBUFFER, m_auiFbo);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

PVRTMat4 mRot,mTrans, mMVP;
mTrans = PVRTMat4::Translation(0,0,0);
mRot = PVRTMat4::RotationZ(Angle);

glBindBuffer(GL_ARRAY_BUFFER, ui32Vbo);
glDisable(GL_CULL_FACE);

int i32Location = glGetUniformLocation(uiProgramObject, "myPMVMatrix");
mMVP = mTrans * mRot ;

glUniformMatrix4fv(i32Location, 1, GL_FALSE, mMVP.ptr());

// Pass the vertex data
glEnableVertexAttribArray(VERTEX_ARRAY);
glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, m_ui32VertexStride, 0);

// Pass the texture coordinates data
glEnableVertexAttribArray(TEXCOORD_ARRAY);
glVertexAttribPointer(TEXCOORD_ARRAY, 2, GL_FLOAT, GL_FALSE, m_ui32VertexStride, (void*) (3 * sizeof(GLfloat)));

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);//

glReadPixels(0,0,ImageWidth ,ImageHeight,GL_RGBA,GL_UNSIGNED_BYTE,pOutTexData) ;

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

eglSwapBuffers(eglDisplay, eglSurface);

}

DeInitAll();[/i][/code]
4

2 回答 2

0

PowerVR 架构不能渲染单个帧并允许 ARM 快速读取它。它只是没有设计成以这种方式快速工作 - 它是一种基于延迟渲染图块的架构。您看到的执行时间也是意料之中的,使用 FBO 也不会使其更快。此外,请注意 OMAP for Windows CE 上的 OpenGL ES 驱动程序质量确实很差。如果他们能正常工作,请认为自己很幸运。

更好的设计是将 OpenGL ES 渲染直接显示到 DSS 并完全避免使用 glReadPixels() 和 FBO。

于 2013-08-16T16:02:37.150 回答
0

我使用多个 FBO 和 PBO 旋转图像缓冲区的性能得到了改进。这是我的应用程序的伪代码片段。

InitGL()
GenerateShaders();
Generate3Textures();//Generate 3 Null Textures
Generate3FBO();//Generate 3 FBO & Attach each Texture to 1 FBO.
Generate3PBO();//Generate 3 PBO & to readback from FBO.

DrawGL()
{
 BindFBO1;
 BindTexture1;
 UploadtoTexture1;
 Do Some Processing & Draw it in FBO1;

 BindFBO2;
 BindTexture2;
 UploadtoTexture2;
 Do Some Processing & Draw it in FBO2;

 BindFBO3;
 BindTexture3;
 UploadtoTexture3;
 Do Some Processing & Draw it in FBO3;


 BindFBO1;
 ReadPixelfromFBO1;
 UnpackToPBO1;

 BindFBO2;
 ReadPixelfromFBO2;
 UnpackToPBO2;

 BindFBO3;
 ReadPixelfromFBO3;
 UnpackToPBO3;
}


DeinitGL();
DeallocateALL();

通过这种方式,我的整体处理性能提高了 50%。

于 2013-09-06T11:24:44.350 回答