git-svn-id: svn://db.shs.com.ru/libs@656 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -68,8 +68,8 @@ void Framebuffer::resize(int width, int height, bool force) {
|
||||
for (int i = 0; i < colors.size(); ++i) {
|
||||
deleteGLTexture(f, colors[i]);
|
||||
createGLTexture(f, colors[i], width, height, color_formats[i], target_);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MAX_LEVEL, 4);
|
||||
@@ -102,8 +102,6 @@ void Framebuffer::resize(int width, int height, bool force) {
|
||||
|
||||
|
||||
QImage Framebuffer::grab() const {
|
||||
//glReadPixels(0, 0, wid, hei, GL_RGBA, );
|
||||
//QImage ret();
|
||||
return QImage();
|
||||
}
|
||||
|
||||
@@ -114,12 +112,10 @@ void Framebuffer::queryPoint(int index, QPoint p) {
|
||||
if (!rect().contains(p) || !pbo.isInit()) return;
|
||||
f->glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
||||
f->glReadBuffer(GL_COLOR_ATTACHMENT0 + index);
|
||||
//QTime tm; tm.restart();
|
||||
pbo.bind(f);
|
||||
f->glReadPixels(p.x(), height() - p.y(), 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
pbo_queried = 1;
|
||||
pbo.release(f);
|
||||
//qDebug() << tm.elapsed();
|
||||
}
|
||||
|
||||
|
||||
@@ -130,12 +126,10 @@ void Framebuffer::queryPoints(int index, QRect rect_) {
|
||||
if (rect_.isEmpty() || !pbo.isInit()) return;
|
||||
f->glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
|
||||
f->glReadBuffer(GL_COLOR_ATTACHMENT0 + index);
|
||||
//QTime tm; tm.restart();
|
||||
pbo.bind(f);
|
||||
f->glReadPixels(rect_.x(), height() - rect_.bottom(), rect_.width(), rect_.height(), GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
pbo_queried = rect_.width() * rect_.height();
|
||||
pbo.release(f);
|
||||
//qDebug() << tm.elapsed();
|
||||
}
|
||||
|
||||
|
||||
@@ -146,17 +140,13 @@ void Framebuffer::queryImage(int index) {
|
||||
|
||||
uint Framebuffer::getPoint() const {
|
||||
if (!pbo.isInit() || (pbo_queried == 0)) return 0;
|
||||
//QTime tm; tm.restart();
|
||||
uint ret = 0;
|
||||
pbo.bind(f);
|
||||
//glClearError();
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, sizeof(uint));
|
||||
//qDebug() << map << QString::number(glGetError(), 16);
|
||||
if (map)
|
||||
memcpy(&ret, map, sizeof(uint));
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
//qDebug() << tm.elapsed();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -165,16 +155,12 @@ QVector<uint> Framebuffer::getPoints() const {
|
||||
QVector<uint> ret;
|
||||
if (!pbo.isInit() || (pbo_queried == 0)) return ret;
|
||||
ret.resize(pbo_queried);
|
||||
//QTime tm; tm.restart();
|
||||
pbo.bind(f);
|
||||
//glClearError();
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, pbo_queried * sizeof(uint));
|
||||
//qDebug() << map << QString::number(glGetError(), 16);
|
||||
if (map)
|
||||
memcpy(ret.data(), map, pbo_queried * sizeof(uint));
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
//qDebug() << tm.elapsed();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -184,16 +170,12 @@ QImage Framebuffer::getImage() const {
|
||||
if (!pbo.isInit() || (pbo_queried == 0)) return ret;
|
||||
ret = QImage(size(), QImage::Format_RGBA8888);
|
||||
int bytes = width() * height() * 4;
|
||||
//QTime tm; tm.restart();
|
||||
pbo.bind(f);
|
||||
//glClearError();
|
||||
void * map = pbo.map(f, GL_MAP_READ_BIT, bytes);
|
||||
//qDebug() << map << QString::number(glGetError(), 16);
|
||||
if (map)
|
||||
memcpy(ret.bits(), map, bytes);
|
||||
pbo.unmap(f);
|
||||
pbo.release(f);
|
||||
//qDebug() << tm.elapsed();
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -279,6 +261,13 @@ void Framebuffer::enablePixelBuffer() {
|
||||
}
|
||||
|
||||
|
||||
void Framebuffer::setColorTextureFiltering(int index, GLenum filter) {
|
||||
bindColorTexture(index);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MIN_FILTER, filter);
|
||||
f->glTexParameteri(target_, GL_TEXTURE_MAG_FILTER, filter);
|
||||
}
|
||||
|
||||
|
||||
void Framebuffer::bindColorTexture(int index, int channel) {
|
||||
if (index < 0 || index >= colors.size()) return;
|
||||
f->glActiveTexture(GL_TEXTURE0 + channel);
|
||||
|
||||
Reference in New Issue
Block a user