有没有比使用glReadPixels更快的方式来访问帧缓冲区?我需要对帧缓冲区中的小矩形渲染区域进行只读访问,以便在CPU中进一步处理数据.性能很重要因为我必须重复执行此操作.我在网上搜索并发现了一些方法,比如使用像素缓冲区对象和glMapBuffer,但似乎OpenGL ES 2.0不支持它们.
我正在尝试仅使用glTexCoord2f()和glVertex2f()实现OpenGL中的图像缩放.
让我解释一下:在加载a QImage并将其发送到gpu后,glTexImage2D()我必须根据Qt的规范执行图像缩放操作.Qt定义了这3个操作(见下图):

我认为这是唯一的方法,因为我的应用程序是一个Qt插件,这个任务需要paint()在类的方法内完成.这项IgnoreAspectRatio操作非常简单,现在正在运作.在KeepAspectRatio最初给了我一些麻烦,但现在它也在努力.不幸的是,KeepAspectRatioByExpanding让我很头疼.
我正在分享到目前为止我所做的事情,感谢您对此问题的帮助:
main.cpp中:
#include "oglWindow.h"
#include <QtGui/QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
oglWindow w;
w.show();
return a.exec();
}
Run Code Online (Sandbox Code Playgroud)
oglWindow.cpp:
#include "oglWindow.h"
#include "glwidget.h"
#include <QGridLayout>
oglWindow::oglWindow(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
GLWidget *openGL = new GLWidget(this);
QGridLayout *layout = new QGridLayout;
setLayout(layout);
}
oglWindow::~oglWindow()
{
}
Run Code Online (Sandbox Code Playgroud)
oglWindow.h:
#ifndef oglWindow_H …Run Code Online (Sandbox Code Playgroud) 我试图完成YV12到RGB转换提到在这个岗位与GLSL着色器.
我的应用程序从磁盘加载原始YV12帧并尝试使用GLSL着色器执行转换.但是,生成的图像会垂直翻转并出现一些颜色问题.我认为问题可能是图像被读取为char(1字节)的数组,然后转换为GLushort(2字节)的数组.你怎么看?
这是原始YUV框架的样子:

这是我得到的输出:

我正在分享以下应用程序的源代码:
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/glu.h>
#include <iostream>
#include <fstream>
#ifndef SEEK_SET
# define SEEK_SET 0
#endif
static GLfloat Xrot = 0, Yrot = 0, Zrot = 0;
static GLint ImgWidth, ImgHeight;
static GLushort *ImageYUV = NULL;
static void DrawObject(void)
{
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2f(-1.0, -1.0);
glTexCoord2f(ImgWidth, 0);
glVertex2f(1.0, -1.0);
glTexCoord2f(ImgWidth, ImgHeight);
glVertex2f(1.0, 1.0);
glTexCoord2f(0, …Run Code Online (Sandbox Code Playgroud)