fix framebuffer read
This commit is contained in:
@@ -188,6 +188,7 @@ NSThread* lock_thread;
|
||||
t_count = 0;
|
||||
}
|
||||
|
||||
std::set<UITouch*> ignored_touch;
|
||||
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
|
||||
{
|
||||
UITouch *touch = [[event allTouches] anyObject];
|
||||
@@ -198,6 +199,10 @@ NSThread* lock_thread;
|
||||
kEventSource source = touch.type == UITouchType::UITouchTypeStylus ? kEventSource::Stylus : kEventSource::Touch;
|
||||
if (source == kEventSource::Stylus)
|
||||
pen_down = true;
|
||||
|
||||
if (touch.majorRadius > 25.f)
|
||||
ignored_touch.insert(touch);
|
||||
NSLog(@"touch down size %f", touch.majorRadius);
|
||||
[self async_lock];
|
||||
App::I.mouse_down(0, touchLocation.x * scale, touchLocation.y * scale, touch.force, source);
|
||||
[self async_unlock];
|
||||
@@ -209,16 +214,34 @@ NSThread* lock_thread;
|
||||
NSUInteger n = [[event allTouches] count];
|
||||
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* t1 = nullptr;
|
||||
|
||||
t0 = [[[event allTouches] allObjects] objectAtIndex:0];
|
||||
t0 = valid_touches[0];
|
||||
CGPoint tl0 = [t0 locationInView:self.view];
|
||||
glm::vec2 p0 = glm::vec2(tl0.x * scale, tl0.y * scale);
|
||||
glm::vec2 p1;
|
||||
if (n > 1)
|
||||
{
|
||||
t1 = [[[event allTouches] allObjects] objectAtIndex:1];
|
||||
t1 = valid_touches[1];
|
||||
CGPoint tl1 = [t1 locationInView:self.view];
|
||||
p1 = glm::vec2(tl1.x * scale, tl1.y * scale);
|
||||
}
|
||||
@@ -244,7 +267,7 @@ NSThread* lock_thread;
|
||||
}
|
||||
else if (n == 1)
|
||||
{
|
||||
UITouch *touch = [[event allTouches] anyObject];
|
||||
UITouch *touch = valid_touches[0];
|
||||
CGPoint touchLocation = [touch locationInView:self.view];
|
||||
//auto p = glm::vec2(touchLocation.x * scale, touchLocation.y * scale);
|
||||
float force = touch.type == UITouchType::UITouchTypeStylus ? touch.force : 1.0f;
|
||||
@@ -268,6 +291,12 @@ NSThread* lock_thread;
|
||||
CGPoint touchLocation = [touch locationInView:self.view];
|
||||
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;
|
||||
pen_down = false;
|
||||
|
||||
|
||||
@@ -359,7 +359,14 @@ void App::update(float dt)
|
||||
#else
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
#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);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(rec_mutex);
|
||||
|
||||
@@ -1761,7 +1761,7 @@ ui::Layer::Snapshot ui::Layer::snapshot(std::string data_path)
|
||||
static int counter = 0;
|
||||
LOG("errno = %d", errno);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
//glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
for (int i = 0; i < 6; 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]);
|
||||
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();
|
||||
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);
|
||||
static char name[128];
|
||||
|
||||
@@ -83,6 +83,7 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <array>
|
||||
#include <cmath>
|
||||
#include <stack>
|
||||
|
||||
@@ -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);
|
||||
// glBindRenderbuffer(GL_RENDERBUFFER, 0);
|
||||
|
||||
GLint oldFboID;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldFboID);
|
||||
|
||||
// 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
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, oldFboID);
|
||||
oldFboID = 0;
|
||||
oldRFboID = 0;
|
||||
oldDFboID = 0;
|
||||
|
||||
return status == GL_FRAMEBUFFER_COMPLETE;
|
||||
}
|
||||
@@ -123,14 +125,18 @@ void RTT::bindFramebuffer()
|
||||
}
|
||||
#endif // _DEBUG
|
||||
bound = true;
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldFboID);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fboID);
|
||||
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDFboID);
|
||||
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldRFboID);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fboID);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboID);
|
||||
}
|
||||
|
||||
void RTT::unbindFramebuffer()
|
||||
{
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, oldFboID);
|
||||
oldFboID = 0;
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDFboID);
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, oldRFboID);
|
||||
oldRFboID = 0;
|
||||
oldDFboID = 0;
|
||||
bound = false;
|
||||
}
|
||||
|
||||
@@ -147,7 +153,7 @@ void RTT::readTextureData(uint8_t* buffer)
|
||||
//glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer);
|
||||
glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
|
||||
unbindFramebuffer();
|
||||
glReadBuffer(GL_NONE);
|
||||
//glReadBuffer(GL_NONE);
|
||||
}
|
||||
|
||||
uint8_t* RTT::createBuffer()
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
class RTT
|
||||
{
|
||||
bool bound = false;
|
||||
GLint oldFboID = 0;
|
||||
GLint oldRFboID = 0;
|
||||
GLint oldDFboID = 0;
|
||||
GLuint fboID = 0;
|
||||
GLuint rboID = 0;
|
||||
GLuint texID = 0;
|
||||
|
||||
Reference in New Issue
Block a user