This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/PROCESSOR-SDK-AM57X: OpenGL question

Part Number: PROCESSOR-SDK-AM57X

Tool/software: Linux


Hi,

I'm trying to stream a texture, using v4L2 (capture mode)

I can obtain a dma-buf file descriptors with omap_bo_dmabuf() (there are multiple omap_bo object. whenever dequeue frame, omap_bo(fd) is changed )

Calling eglCreateImageKHR() and glEGLImageTargetTexture2DOES() is a success(glGetError() returns 0), but nothing is drawn on screen

Please tell me if there's something wrong with my code

code_1:

{
	static const GLchar* VTexShaderStr =		// [TexProg] Vertex shader source
    "attribute vec4 vPosition;          \n"
    "attribute vec2 vTexCoord;          \n"
    "varying vec2 v_TexCoord;           \n"
    "                                   \n"
    "void main()                        \n"
    "{                                  \n"
    "    v_TexCoord = vTexCoord;        \n"
    "    gl_Position = vPosition;       \n"
    "}                                  \n";
	static const GLchar* FTexShaderStr =		// [TexProg] Fragment shader source
    "precision mediump float;           \n"
    "varying vec2 v_TexCoord;           \n"
    "uniform sampler2D s_Texture_0;     \n"
    "                                   \n"
    "void main()                        \n"
    "{                                  \n"
    "    gl_FragColor = texture2D(s_Texture_0, v_TexCoord);\n"
    "}                                  \n";
	
	if ( !(lpeglCreateImageKHR = (eglCreateImageKHR_t*)eglGetProcAddress("eglCreateImageKHR")) ) {                                 
       printf("[err:%s] failed to eglGetProcAddress(\"eglCreateImageKHR\")\n", __func__);                                               
       return -1;
	}
	if ( !(lpeglDestroyImageKHR = (eglDestroyImageKHR_t*)eglGetProcAddress("eglDestroyImageKHR")) ) {                              
       printf("[err:%s] failed to eglGetProcAddress(\"eglDestroyImageKHR\")\n", __func__);                                              
       return -1;
	}
	if ( !(lpglEGLImageTargetTexture2DOES = (glEGLImageTargetTexture2DOES_t*)eglGetProcAddress("glEGLImageTargetTexture2DOES")) ) {
       printf("[err:%s] failed to glEGLImageTargetTexture2DOES(\"glEGLImageTargetTexture2DOES\")\n", __func__);                         
       return -1;
	}                                                                                                                                   
	glGenTextures(1, &TbYUV);
	
	for (;;) {
		int BufIdx = DQueue();
		EGLint Fd = m_DmaFd[BufIdx];

		EGLint Attribs[30] = {0,};
		DWORD Idx = 0;
		
		// v4l2 Colorspace : V4L2_COLORSPACE_SMPTE170M (YUYV)
		Attribs[Idx++] = EGL_WIDTH;                     
		Attribs[Idx++] = Width;
		Attribs[Idx++] = EGL_HEIGHT;                    
		Attribs[Idx++] = Height;
		Attribs[Idx++] = EGL_LINUX_DRM_FOURCC_EXT;      
		Attribs[Idx++] = DRM_FORMAT_YUYV;
		Attribs[Idx++] = EGL_DMA_BUF_PLANE0_FD_EXT;     
		Attribs[Idx++] = Fd;
		Attribs[Idx++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT; 
		Attribs[Idx++] = 0;
		Attribs[Idx++] = EGL_DMA_BUF_PLANE0_PITCH_EXT;  
		Attribs[Idx++] = Width * 2;
		Attribs[Idx++] = EGL_YUV_COLOR_SPACE_HINT_EXT;  
		Attribs[Idx++] = EGL_ITU_REC709_EXT;
		Attribs[Idx++] = EGL_SAMPLE_RANGE_HINT_EXT;     
		Attribs[Idx++] = EGL_YUV_NARROW_RANGE_EXT;
		Attribs[Idx++] = EGL_NONE;

		EGLImageKHR Image = lpeglCreateImageKHR( Display, EGL_NO_CONTEXT, EGL_LINUX_DMA_BUF_EXT, NULL, Attribs );
		printf("eglCreateImageKHR() returned %d\n", glGetError());
		glBindTexture( GL_TEXTURE_2D, TbYUV );
		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
		lpglEGLImageTargetTexture2DOES( GL_TEXTURE_2D, Image );
		printf("EGLImageTargetTexture2DOES() returned %d\n", glGetError());
		
		static const GLfloat lpPos[] = { -1.0, -1.0, 0,
										 1.0, -1.0, 0,
										 -1.0, 1.0, 0,
										 1.0, 1.0, 0 };
		static const GLfloat lpTexUI[] = { 0.0, 1.0,
										   1.0, 1.0,
										   0.0, 0.0,
										   1.0, 0.0 };
		glUseProgram( TexProg );
		glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, lpPos );
		glEnableVertexAttribArray( 0 );

		glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 0, lpTexUI );
		glEnableVertexAttribArray( 1 );

		glActiveTexture( GL_TEXTURE0 + 0 );
		glBindTexture( GL_TEXTURE_2D, TbYUV );
		glUniform1i( SamplerLoc, 0 );

		glViewport( 0, 0, 800, 480 );
		glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
		
		lpeglDestroyImageKHR( Display, Image );
	}
}	


glTexImage2D() works well. Get dma-buf address using omap_bo_map()
code_2:

{	// test code
	...
	for (;;) {
		int BufIdx = DQueue();
		unsigned char* Buf = omap_bo_map(m_DmaBo[BufIdx]);
		
		// v4l2 Colorspace : V4L2_COLORSPACE_SMPTE170M (YUYV)

		glBindTexture( GL_TEXTURE_2D, TbYUV );
		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
		glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, Buf ); // may be segfault(read 32 bpp)
		
		static const GLfloat lpPos[] = { -1.0, -1.0, 0,
										 1.0, -1.0, 0,
										 -1.0, 1.0, 0,
										 1.0, 1.0, 0 };
		static const GLfloat lpTexUI[] = { 0.0, 1.0,
										   1.0, 1.0,
										   0.0, 0.0,
										   1.0, 0.0 };
		glUseProgram( TexProg );
		glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, 0, lpPos );
		glEnableVertexAttribArray( 0 );

		glVertexAttribPointer( 1, 2, GL_FLOAT, GL_FALSE, 0, lpTexUI );
		glEnableVertexAttribArray( 1 );

		glActiveTexture( GL_TEXTURE0 + 0 );
		glBindTexture( GL_TEXTURE_2D, TbYUV );
		glUniform1i( SamplerLoc, 0 );

		glViewport( 0, 0, 800, 480 );
		glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 );
		
	}
}

I can stream a texture even tough It is too slow(~400ms FullHD) and has weird color(read rgba from yuyv buffer)

- Development Kit version

SGX DDK
https://git.ti.com/graphics/omap5-sgx-ddk-um-linux/commit/d184140aa5c17e13e1bf21151f1a7bc068bdf8bf

PSDK
am57xx-evm-linux-sdk-arago-src-03.01.00.06

Thanks and regards

  • The software team have been notified. They will respond here.
  • Hi aupers,
    This is tested with a sample application from omapdrmtest repository git://git.ti.com/glsdk/omapdrmtest.git
    filevpedisplay which demonstrates vpe and creats yuyv texture on kmscube egl image.

    Usage: filevpedisplay /usr/share/ti/video/airshow_p352x288.yuv 352 288 nv12 720 480 yuyv 0 0 352 288 0 1 --kmscube --connector 32 --fps 1

    filevpedisplay application is expecting exactly 16 arguments, so if you execute this command, it will fail.
    You need to modify filevpedisplay.c as shown below

    - if (argc != 16) {
    + if (argc < 16) {

    Can you try this?

    Ramprasad