fix framebuffer read

This commit is contained in:
2018-05-09 12:04:29 +02:00
parent af0e588a94
commit f16adb8fcc
6 changed files with 57 additions and 13 deletions

View File

@@ -188,6 +188,7 @@ NSThread* lock_thread;
t_count = 0; t_count = 0;
} }
std::set<UITouch*> ignored_touch;
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{ {
UITouch *touch = [[event allTouches] anyObject]; UITouch *touch = [[event allTouches] anyObject];
@@ -198,6 +199,10 @@ NSThread* lock_thread;
kEventSource source = touch.type == UITouchType::UITouchTypeStylus ? kEventSource::Stylus : kEventSource::Touch; kEventSource source = touch.type == UITouchType::UITouchTypeStylus ? kEventSource::Stylus : kEventSource::Touch;
if (source == kEventSource::Stylus) if (source == kEventSource::Stylus)
pen_down = true; pen_down = true;
if (touch.majorRadius > 25.f)
ignored_touch.insert(touch);
NSLog(@"touch down size %f", touch.majorRadius);
[self async_lock]; [self async_lock];
App::I.mouse_down(0, touchLocation.x * scale, touchLocation.y * scale, touch.force, source); App::I.mouse_down(0, touchLocation.x * scale, touchLocation.y * scale, touch.force, source);
[self async_unlock]; [self async_unlock];
@@ -209,16 +214,34 @@ NSThread* lock_thread;
NSUInteger n = [[event allTouches] count]; NSUInteger n = [[event allTouches] count];
float scale = self.view.contentScaleFactor; float scale = self.view.contentScaleFactor;
std::vector<UITouch*> valid_touches;
for (int i = 0; i < n; i++)
{
auto t = [[[event allTouches] allObjects] objectAtIndex:i];
auto it = ignored_touch.find(t);
if (it == ignored_touch.end())
{
valid_touches.push_back(t);
}
else
{
NSLog(@"ignored moved");
}
}
n = valid_touches.size();
if (n == 0)
return;
UITouch* t0 = nullptr; UITouch* t0 = nullptr;
UITouch* t1 = nullptr; UITouch* t1 = nullptr;
t0 = [[[event allTouches] allObjects] objectAtIndex:0]; t0 = valid_touches[0];
CGPoint tl0 = [t0 locationInView:self.view]; CGPoint tl0 = [t0 locationInView:self.view];
glm::vec2 p0 = glm::vec2(tl0.x * scale, tl0.y * scale); glm::vec2 p0 = glm::vec2(tl0.x * scale, tl0.y * scale);
glm::vec2 p1; glm::vec2 p1;
if (n > 1) if (n > 1)
{ {
t1 = [[[event allTouches] allObjects] objectAtIndex:1]; t1 = valid_touches[1];
CGPoint tl1 = [t1 locationInView:self.view]; CGPoint tl1 = [t1 locationInView:self.view];
p1 = glm::vec2(tl1.x * scale, tl1.y * scale); p1 = glm::vec2(tl1.x * scale, tl1.y * scale);
} }
@@ -244,7 +267,7 @@ NSThread* lock_thread;
} }
else if (n == 1) else if (n == 1)
{ {
UITouch *touch = [[event allTouches] anyObject]; UITouch *touch = valid_touches[0];
CGPoint touchLocation = [touch locationInView:self.view]; CGPoint touchLocation = [touch locationInView:self.view];
//auto p = glm::vec2(touchLocation.x * scale, touchLocation.y * scale); //auto p = glm::vec2(touchLocation.x * scale, touchLocation.y * scale);
float force = touch.type == UITouchType::UITouchTypeStylus ? touch.force : 1.0f; float force = touch.type == UITouchType::UITouchTypeStylus ? touch.force : 1.0f;
@@ -267,6 +290,12 @@ NSThread* lock_thread;
UITouch *touch = [[event allTouches] anyObject]; UITouch *touch = [[event allTouches] anyObject];
CGPoint touchLocation = [touch locationInView:self.view]; CGPoint touchLocation = [touch locationInView:self.view];
float scale = self.view.contentScaleFactor; float scale = self.view.contentScaleFactor;
if (ignored_touch.count(touch))
{
ignored_touch.erase(touch);
NSLog(@"remove ignored");
}
kEventSource source = touch.type == UITouchType::UITouchTypeStylus ? kEventSource::Stylus : kEventSource::Touch; kEventSource source = touch.type == UITouchType::UITouchTypeStylus ? kEventSource::Stylus : kEventSource::Touch;
pen_down = false; pen_down = false;

View File

@@ -359,7 +359,14 @@ void App::update(float dt)
#else #else
glBindFramebuffer(GL_FRAMEBUFFER, 0); glBindFramebuffer(GL_FRAMEBUFFER, 0);
#endif #endif
glReadBuffer(GL_BACK);
GLint dfbo, rfbo;
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &rfbo);
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &dfbo);
if (dfbo != rfbo)
LOG("DIFFERENT FB");
glReadBuffer(GL_FRONT);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data); glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
{ {
std::lock_guard<std::mutex> lock(rec_mutex); std::lock_guard<std::mutex> lock(rec_mutex);

View File

@@ -1761,7 +1761,7 @@ ui::Layer::Snapshot ui::Layer::snapshot(std::string data_path)
static int counter = 0; static int counter = 0;
LOG("errno = %d", errno); LOG("errno = %d", errno);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0); //glBindFramebuffer(GL_FRAMEBUFFER, 0);
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{ {
snap.m_dirty_box[i] = m_dirty_box[i]; snap.m_dirty_box[i] = m_dirty_box[i];
@@ -1777,7 +1777,7 @@ ui::Layer::Snapshot ui::Layer::snapshot(std::string data_path)
glm::vec2 box_sz = zw(m_dirty_box[i]) - xy(m_dirty_box[i]); glm::vec2 box_sz = zw(m_dirty_box[i]) - xy(m_dirty_box[i]);
glReadPixels(m_dirty_box[i].x, m_dirty_box[i].y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, snap.image[i].get()); glReadPixels(m_dirty_box[i].x, m_dirty_box[i].y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, snap.image[i].get());
m_rtt[i].unbindFramebuffer(); m_rtt[i].unbindFramebuffer();
glReadBuffer(GL_NONE); //glReadBuffer(GL_NONE);
LOG("snapshot face %d - %d bytes (%dx%d)", i, (int)box_sz.x * (int)box_sz.y * 4, (int)box_sz.x, (int)box_sz.y); LOG("snapshot face %d - %d bytes (%dx%d)", i, (int)box_sz.x * (int)box_sz.y * 4, (int)box_sz.x, (int)box_sz.y);
static char name[128]; static char name[128];

View File

@@ -83,6 +83,7 @@
#ifdef __cplusplus #ifdef __cplusplus
#include <map> #include <map>
#include <set>
#include <array> #include <array>
#include <cmath> #include <cmath>
#include <stack> #include <stack>

View File

@@ -74,6 +74,7 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format)
// glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height); // glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, width, height);
// glBindRenderbuffer(GL_RENDERBUFFER, 0); // glBindRenderbuffer(GL_RENDERBUFFER, 0);
GLint oldFboID;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldFboID); glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldFboID);
// Create a framebuffer object // Create a framebuffer object
@@ -106,7 +107,8 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format)
// Switch back to window-system-provided framebuffer // Switch back to window-system-provided framebuffer
glBindFramebuffer(GL_FRAMEBUFFER, oldFboID); glBindFramebuffer(GL_FRAMEBUFFER, oldFboID);
oldFboID = 0; oldRFboID = 0;
oldDFboID = 0;
return status == GL_FRAMEBUFFER_COMPLETE; return status == GL_FRAMEBUFFER_COMPLETE;
} }
@@ -123,14 +125,18 @@ void RTT::bindFramebuffer()
} }
#endif // _DEBUG #endif // _DEBUG
bound = true; bound = true;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldFboID); glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDFboID);
glBindFramebuffer(GL_FRAMEBUFFER, fboID); glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldRFboID);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboID);
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboID);
} }
void RTT::unbindFramebuffer() void RTT::unbindFramebuffer()
{ {
glBindFramebuffer(GL_FRAMEBUFFER, oldFboID); glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDFboID);
oldFboID = 0; glBindFramebuffer(GL_READ_FRAMEBUFFER, oldRFboID);
oldRFboID = 0;
oldDFboID = 0;
bound = false; bound = false;
} }
@@ -147,7 +153,7 @@ void RTT::readTextureData(uint8_t* buffer)
//glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer); //glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buffer); glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
unbindFramebuffer(); unbindFramebuffer();
glReadBuffer(GL_NONE); //glReadBuffer(GL_NONE);
} }
uint8_t* RTT::createBuffer() uint8_t* RTT::createBuffer()

View File

@@ -3,7 +3,8 @@
class RTT class RTT
{ {
bool bound = false; bool bound = false;
GLint oldFboID = 0; GLint oldRFboID = 0;
GLint oldDFboID = 0;
GLuint fboID = 0; GLuint fboID = 0;
GLuint rboID = 0; GLuint rboID = 0;
GLuint texID = 0; GLuint texID = 0;