Xavier agx & the picture of fault , use opengl to show rgb data

Hi!
when I use opengl to show 4k rgb data, the video will have the fault, like this.


which is very strange,
#########################################################
this is my code

#include <stdio.h>
#include "glew.h"
#include "glut.h"
#include <stdlib.h>
#include <malloc.h>
#include <string.h>

int screen_w=3840,screen_h=2160;
const int pixel_w = 3840, pixel_h = 2160;
FILE *fp = NULL;

unsigned char buffer[pixel_w * pixel_h * 3];
void display(void){
    fread(buffer, 1, pixel_w * pixel_h * 3, fp);

	glRasterPos3f(-1.0f,1.0f,0);
	glPixelZoom((float)screen_w/(float)pixel_w, -(float)screen_h/pixel_h);
	
	glDrawPixels(3840, 2160, GL_RGB, GL_UNSIGNED_BYTE, buffer);
	glutSwapBuffers();

}
void timeFunc(int value){
    display();
    glutTimerFunc(15, timeFunc, 0);
}
int main(int argc, char* argv[])
{

	fp=fopen("../v4l2_3840_2160.rgb","rb+");
	if(fp==NULL){
		printf("Cannot open this file.\n");
		return -1;
	}
    glutInit(&argc, argv);  
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB );
    glutInitWindowPosition(0,0);
    glutInitWindowSize(3840, 2160);
    glutCreateWindow("4K");
    glutDisplayFunc(&display);
    glutTimerFunc(15, timeFunc, 0); 
    glutMainLoop();
    return 0;
}

##############################################
The function of glDrawPixels take too much time around 50ms, but my timer is 15ms, Maybe which is the reason of fault.
Is there any other function?
Please give some advices,thank you very much!

Hi there!

I suppose the fault you mean is the tearing in the video, correct?
If so then yes, if the drawPixels is behind your timer than you will see tearing.

Not the OpenGL expert here, but are you certain that your platform is able to read 4k raw RGB data fast enough from memory to saturate the drawPixels call? And are you sure the drawPixels call is the bottleneck and not the fread call?
One approach would be to try a different color format which needs less bandwidth or try to use video memory instead of reading each frame from disk through system memory.

To get more visibility for your question I would suggest we move it to either the OpenGL category or to our dedicated AGX forums. This depends a bit on you, whether you think this is a platform related question or rather only GL specific. Let me know what you would prefer.

Thanks!

1 Like

Hi

I use the function of gettimeofday to calculate. the drawPixels call maybe take around 50ms, the fread call maybe table 5ms. At the same I will use the function of mmap to test.

I think this is a GL question, not a platform related question.
thank you !