minor improvements

pull/3471/head
kallaballa 3 years ago
parent 3ddf77c7b8
commit 943b55c1be
  1. 35
      src/tetra/subsystems.hpp
  2. 7
      src/tetra/tetra-demo.cpp

@ -268,7 +268,7 @@ void check_if_YUV420_available() {
attrib.type = VAConfigAttribRTFormat;
vaGetConfigAttributes(va::display, VAProfileVP9Profile0, VAEntrypointVLD, &attrib, 1);
if ((attrib.value & VA_RT_FORMAT_YUV420) == 0)
throw std::runtime_error("Desired YUV444 RT format not found");
throw std::runtime_error("Desired YUV420 RT format not found");
}
void init_va() {
@ -291,7 +291,7 @@ namespace x11 {
Display* xdisplay;
Window xroot;
Window xwin;
XSetWindowAttributes swa;
Atom wmDeleteMessage;
bool initialized = false;
@ -307,19 +307,41 @@ bool is_initialized() {
return initialized;
}
bool window_closed() {
if(XPending(xdisplay) == 0)
return false;
XEvent event;
XNextEvent(xdisplay, &event);
switch (event.type)
{
case ClientMessage:
if (event.xclient.data.l[0] == static_cast<long int>(wmDeleteMessage))
return true;
break;
default:
break;
}
return false;
}
void init_x11() {
xdisplay = XOpenDisplay(nullptr);
if (xdisplay == nullptr) {
cerr << "Unable to open X11 display" << endl;
exit(3);
}
xroot = DefaultRootWindow(xdisplay);
swa.event_mask = ExposureMask;
XSetWindowAttributes swa;
swa.event_mask = ClientMessage;
xwin = XCreateWindow(xdisplay, xroot, 0, 0, WIDTH, HEIGHT, 0,
CopyFromParent, InputOutput, CopyFromParent, CWEventMask, &swa);
XSetWindowAttributes xattr;
xattr.override_redirect = False;
XChangeWindowAttributes(xdisplay, xwin, CWOverrideRedirect, &xattr);
@ -337,6 +359,9 @@ void init_x11() {
XMapWindow(xdisplay, xwin);
XStoreName(xdisplay, xwin, "tetra-demo");
wmDeleteMessage = XInternAtom(xdisplay, "WM_DELETE_WINDOW", False);
XSetWMProtocols(xdisplay, xwin, &wmDeleteMessage, 1);
initialized = true;
}
}
@ -521,8 +546,6 @@ void init_gl() {
glCheck(glBindFramebuffer(GL_FRAMEBUFFER, frame_buf));
frame_buf_tex = new cv::ogl::Texture2D(cv::Size(WIDTH, HEIGHT), cv::ogl::Texture2D::RGBA, false);
frame_buf_tex->bind();
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glCheck(glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, frame_buf_tex->texId(), 0));
assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);

@ -43,7 +43,6 @@ void render(cv::UMat& frameBuffer) {
glColor3f(1, 0, 0);
glVertex3f(-1, 0, 1);
glEnd();
glFlush();
kb::gl::swapBuffers();
}
@ -94,7 +93,6 @@ int main(int argc, char **argv) {
int64 start = 0;
uint64_t cnt = 0;
while (true) {
start = cv::getTickCount();
@ -112,6 +110,8 @@ int main(int argc, char **argv) {
//Color-conversion from BGRA to RGB, also OpenCL.
cv::cvtColor(frameBuffer, videoFrame, cv::COLOR_BGRA2RGB);
cv::flip(videoFrame, videoFrame, 0);
VA_CONTEXT.bind();
//Encode the frame using VAAPI on the GPU.
video.write(videoFrame);
@ -124,6 +124,9 @@ int main(int argc, char **argv) {
//Blit the framebuffer we have been working on to screen
blitFrameBufferToScreen();
if(x11::window_closed())
break;
}
//Measure FPS

Loading…
Cancel
Save