fixed on-screen rendering

pull/3471/head
kallaballa 3 years ago
parent fc59ea333d
commit 31a27216bc
  1. 35
      src/camera/camera-demo.cpp
  2. 7
      src/tetra/tetra-demo.cpp

@ -2,6 +2,7 @@
constexpr long unsigned int WIDTH = 1920; constexpr long unsigned int WIDTH = 1920;
constexpr long unsigned int HEIGHT = 1080; constexpr long unsigned int HEIGHT = 1080;
constexpr bool OFFSCREEN = false;
constexpr const char* INPUT_FILENAME = "example.mp4"; constexpr const char* INPUT_FILENAME = "example.mp4";
constexpr const char* OUTPUT_FILENAME = "camera-demo.mkv"; constexpr const char* OUTPUT_FILENAME = "camera-demo.mkv";
constexpr const int VA_HW_DEVICE_INDEX = 0; constexpr const int VA_HW_DEVICE_INDEX = 0;
@ -47,7 +48,6 @@ void render() {
glVertex3f(-1, 0, 1); glVertex3f(-1, 0, 1);
glEnd(); glEnd();
glFlush(); glFlush();
kb::gl::swapBuffers();
} }
void glow(cv::UMat &src, int ksize = WIDTH / 85 % 2 == 0 ? WIDTH / 85 + 1 : WIDTH / 85) { void glow(cv::UMat &src, int ksize = WIDTH / 85 % 2 == 0 ? WIDTH / 85 + 1 : WIDTH / 85) {
@ -103,6 +103,10 @@ int main(int argc, char **argv) {
cv::VIDEOWRITER_PROP_HW_ACCELERATION_USE_OPENCL, 1 cv::VIDEOWRITER_PROP_HW_ACCELERATION_USE_OPENCL, 1
}); });
//If we are rendering offscreen we don't need x11
if(!OFFSCREEN)
x11::init_x11();
//Passing true to init_egl will create a OpenGL debug context //Passing true to init_egl will create a OpenGL debug context
egl::init_egl(); egl::init_egl();
//Initialize OpenCL Context for OpenGL //Initialize OpenCL Context for OpenGL
@ -120,13 +124,20 @@ int main(int argc, char **argv) {
cv::UMat frameBuffer; cv::UMat frameBuffer;
cv::UMat videoFrame; cv::UMat videoFrame;
cv::UMat videoOutFrame;
cv::UMat videoFrameRGBA; cv::UMat videoFrameRGBA;
render();
uint64_t cnt = 1; uint64_t cnt = 1;
int64 start = cv::getTickCount(); int64 start = cv::getTickCount();
double tickFreq = cv::getTickFrequency(); double tickFreq = cv::getTickFrequency();
while (true) { while (true) {
GL_CONTEXT.bind();
gl::fetch_frame_buffer(frameBuffer);
//Activate the OpenCL context for VAAPI //Activate the OpenCL context for VAAPI
VA_CONTEXT.bind(); VA_CONTEXT.bind();
//Decode a frame using HW acceleration into a cv::UMat //Decode a frame using HW acceleration into a cv::UMat
@ -143,7 +154,6 @@ int main(int argc, char **argv) {
//Resize the frame. (OpenCL) //Resize the frame. (OpenCL)
cv::resize(videoFrameRGBA, frameBuffer, cv::Size(WIDTH, HEIGHT)); cv::resize(videoFrameRGBA, frameBuffer, cv::Size(WIDTH, HEIGHT));
//Activate the OpenCL context for OpenGL
GL_CONTEXT.bind(); GL_CONTEXT.bind();
//Transfer buffer ownership to OpenGL //Transfer buffer ownership to OpenGL
gl::return_frame_buffer(frameBuffer); gl::return_frame_buffer(frameBuffer);
@ -155,13 +165,28 @@ int main(int argc, char **argv) {
glow(frameBuffer); glow(frameBuffer);
//Color-conversion from BGRA to RGB. (OpenCL) //Color-conversion from BGRA to RGB. (OpenCL)
cv::cvtColor(frameBuffer, videoFrame, cv::COLOR_BGRA2RGB); cv::cvtColor(frameBuffer, videoOutFrame, cv::COLOR_BGRA2RGB);
cv::flip(videoFrame, videoFrame, 0); cv::flip(videoOutFrame, videoOutFrame, 0);
//Activate the OpenCL context for VAAPI //Activate the OpenCL context for VAAPI
VA_CONTEXT.bind(); VA_CONTEXT.bind();
//Encode the frame using VAAPI on the GPU. //Encode the frame using VAAPI on the GPU.
video.write(videoFrame); video.write(videoOutFrame);
if(x11::is_initialized()) {
//Yet again activate the OpenCL context for OpenGL
GL_CONTEXT.bind();
//Transfer buffer ownership back to OpenGL
gl::return_frame_buffer(frameBuffer);
//Blit the framebuffer we have been working on to the screen
gl::blit_frame_buffer_to_screen();
//Check if the x11 window was closed
if(x11::window_closed())
break;
gl::swapBuffers();
}
//Measure FPS //Measure FPS
if (cnt % uint64(FPS) == 0) { if (cnt % uint64(FPS) == 0) {

@ -2,10 +2,10 @@
constexpr long unsigned int WIDTH = 1920; constexpr long unsigned int WIDTH = 1920;
constexpr long unsigned int HEIGHT = 1080; constexpr long unsigned int HEIGHT = 1080;
constexpr bool OFFSCREEN = true; constexpr double FPS = 60;
constexpr bool OFFSCREEN = false;
constexpr const char* OUTPUT_FILENAME = "tetra-demo.mkv"; constexpr const char* OUTPUT_FILENAME = "tetra-demo.mkv";
constexpr const int VA_HW_DEVICE_INDEX = 0; constexpr const int VA_HW_DEVICE_INDEX = 0;
constexpr double FPS = 60;
#include "../common/subsystems.hpp" #include "../common/subsystems.hpp"
@ -48,7 +48,6 @@ void render() {
glVertex3f(-1, 0, 1); glVertex3f(-1, 0, 1);
glEnd(); glEnd();
glFlush(); glFlush();
kb::gl::swapBuffers();
} }
void glow(cv::UMat &src, int ksize = WIDTH / 85 % 2 == 0 ? WIDTH / 85 + 1 : WIDTH / 85) { void glow(cv::UMat &src, int ksize = WIDTH / 85 % 2 == 0 ? WIDTH / 85 + 1 : WIDTH / 85) {
@ -147,6 +146,8 @@ int main(int argc, char **argv) {
//Check if the x11 window was closed //Check if the x11 window was closed
if(x11::window_closed()) if(x11::window_closed())
break; break;
gl::swapBuffers();
} }
//Measure FPS //Measure FPS

Loading…
Cancel
Save