[Bf-blender-cvs] [0ff79c8] decklink: Decklink: use floating point texture format when possible.

Benoit Bolsee noreply at git.blender.org
Sun Dec 20 11:32:48 CET 2015


Commit: 0ff79c87a440d886cbaed3f2753a7a8cb466ad60
Author: Benoit Bolsee
Date:   Sun Dec 20 11:08:47 2015 +0100
Branches: decklink
https://developer.blender.org/rB0ff79c87a440d886cbaed3f2753a7a8cb466ad60

Decklink: use floating point texture format when possible.

Previous implementation was using GL_RED_INTEGER texture format for
all non-RGBA pixel format. This isn't supported by intel GPU (although
the GL_texture_rg extension is declared supported).
Floating RGBA texture are now used for the following pixel formats:
8BitYUV: Cb->B, Y0->G, Cr->R, Y1->A
10BitYUV: no fixed mapping between CbCrY and RGB, a shader is required
8BitARGB: direct mapping
8BitBGRA: direct mapping
10BitRGBXLE: direct mapping (A is undefined)
Other pixel formats are mapped to GL_RED_INTEGER (GL_R32UI internal
format, usampler2D must be used in the shader).
Note: the 10BitYUV, 10BitRGBXLE and 8BitARGB mapping only works on little-
endian host CPU. For big endian CPU, other formats must be used (not yet
implemented).

The texture MIN/MAX_FILTER is now set to NEAREST. Previously it was set to
LINEAR, which was detremental on multibytes pixel format.

The sample shader in the documentation for the above formats will be
changed to reflect the new mapping.

===================================================================

M	source/gameengine/VideoTexture/VideoDeckLink.cpp
M	source/gameengine/VideoTexture/VideoDeckLink.h

===================================================================

diff --git a/source/gameengine/VideoTexture/VideoDeckLink.cpp b/source/gameengine/VideoTexture/VideoDeckLink.cpp
index 08ac1ef..b20242e 100644
--- a/source/gameengine/VideoTexture/VideoDeckLink.cpp
+++ b/source/gameengine/VideoTexture/VideoDeckLink.cpp
@@ -144,15 +144,32 @@ public:
 			sysMemBuffersDesc.width = pDesc->width;
 			sysMemBuffersDesc.height = pDesc->height;
 			sysMemBuffersDesc.stride = pDesc->stride;
-			if (pDesc->format == GL_RED_INTEGER)
+			switch (pDesc->format) 
 			{
+			case GL_RED_INTEGER:
 				sysMemBuffersDesc.format = DVP_RED_INTEGER;
-				sysMemBuffersDesc.type = DVP_UNSIGNED_INT;
+				break;
+			default:
+				sysMemBuffersDesc.format = DVP_BGRA;
+				break;
 			}
-			else
+			switch (pDesc->type)
 			{
-				sysMemBuffersDesc.format = DVP_BGRA;
-				sysMemBuffersDesc.type = (pDesc->type == GL_UNSIGNED_INT_8_8_8_8) ? DVP_UNSIGNED_INT_8_8_8_8 : DVP_UNSIGNED_INT_8_8_8_8_REV;
+			case GL_UNSIGNED_BYTE:
+				sysMemBuffersDesc.type = DVP_UNSIGNED_BYTE;
+				break;
+			case GL_UNSIGNED_INT_2_10_10_10_REV:
+				sysMemBuffersDesc.type = DVP_UNSIGNED_INT_2_10_10_10_REV;
+				break;
+			case GL_UNSIGNED_INT_8_8_8_8:
+				sysMemBuffersDesc.type = DVP_UNSIGNED_INT_8_8_8_8;
+				break;
+			case GL_UNSIGNED_INT_10_10_10_2:
+				sysMemBuffersDesc.type = DVP_UNSIGNED_INT_10_10_10_2;
+				break;
+			default:
+				sysMemBuffersDesc.type = DVP_UNSIGNED_INT;
+				break;
 			}
 			sysMemBuffersDesc.size = pDesc->width * pDesc->height * 4;
 			sysMemBuffersDesc.bufAddr = mBuffer;
@@ -471,11 +488,11 @@ void PinnedMemoryAllocator::TransferBuffer(void* address, TextureDesc* texDesc,
 	{
 		// first time we try to send data to the GPU, allocate a buffer for the texture
 		glBindTexture(GL_TEXTURE_2D, texId);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
 		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-		glTexImage2D(GL_TEXTURE_2D, 0, ((texDesc->format == GL_RED_INTEGER) ? GL_R32UI : GL_RGBA), texDesc->width, texDesc->height, 0, texDesc->format, texDesc->type, NULL);
+		glTexImage2D(GL_TEXTURE_2D, 0, texDesc->internalFormat, texDesc->width, texDesc->height, 0, texDesc->format, texDesc->type, NULL);
 		glBindTexture(GL_TEXTURE_2D, 0);
 		mTexId = texId;
 	}
@@ -825,7 +842,7 @@ void VideoDeckLink::openCam (char *format, short camIdx)
 	inputFlags = (mUse3D) ? bmdVideoInputDualStream3D : bmdVideoInputFlagDefault;
 	while (pDLDisplayModeIterator->Next(&pDLDisplayMode) == S_OK) 
 	{
-		if (   pDLDisplayMode->GetDisplayMode() == mDisplayMode 
+		if (   pDLDisplayMode->GetDisplayMode() == mDisplayMode
 			&& (pDLDisplayMode->GetFlags() & displayFlags) == displayFlags
 			&& mDLInput->DoesSupportVideoMode(mDisplayMode, mPixelFormat, inputFlags, &modeSupport, NULL) == S_OK
 			&& modeSupport == bmdDisplayModeSupported)
@@ -854,33 +871,44 @@ void VideoDeckLink::openCam (char *format, short camIdx)
 		// 2 pixels per word
 		mTextureDesc.stride = mFrameWidth * 2;
 		mTextureDesc.width = mFrameWidth / 2;
-		mTextureDesc.format = GL_RED_INTEGER;
-		mTextureDesc.type = GL_UNSIGNED_INT;
+		mTextureDesc.internalFormat = GL_RGBA;
+		mTextureDesc.format = GL_BGRA;
+		mTextureDesc.type = GL_UNSIGNED_BYTE;
 		break;
 	case bmdFormat10BitYUV:
 		// 6 pixels in 4 words, rounded to 48 pixels
 		mTextureDesc.stride = ((mFrameWidth + 47) / 48) * 128;
 		mTextureDesc.width = ((mFrameWidth + 5) / 6) * 4;
-		mTextureDesc.format = GL_RED_INTEGER;
-		mTextureDesc.type = GL_UNSIGNED_INT;
+		mTextureDesc.internalFormat = GL_RGB10_A2;
+		mTextureDesc.format = GL_BGRA;
+		mTextureDesc.type = GL_UNSIGNED_INT_2_10_10_10_REV;
 		break;
 	case bmdFormat8BitARGB:
 		mTextureDesc.stride = mFrameWidth * 4;
 		mTextureDesc.width = mFrameWidth;
+		mTextureDesc.internalFormat = GL_RGBA;
 		mTextureDesc.format = GL_BGRA;
 		mTextureDesc.type = GL_UNSIGNED_INT_8_8_8_8;
 		break;
 	case bmdFormat8BitBGRA:
 		mTextureDesc.stride = mFrameWidth * 4;
 		mTextureDesc.width = mFrameWidth;
+		mTextureDesc.internalFormat = GL_RGBA;
 		mTextureDesc.format = GL_BGRA;
-		mTextureDesc.type = GL_UNSIGNED_INT_8_8_8_8_REV;
+		mTextureDesc.type = GL_UNSIGNED_BYTE;
 		break;
 	case bmdFormat10BitRGBXLE:
+		mTextureDesc.stride = ((mFrameWidth + 63) / 64) * 256;
+		mTextureDesc.width = mFrameWidth;
+		mTextureDesc.internalFormat = GL_RGB10_A2;
+		mTextureDesc.format = GL_RGBA;
+		mTextureDesc.type = GL_UNSIGNED_INT_10_10_10_2;
+		break;
 	case bmdFormat10BitRGBX:
 	case bmdFormat10BitRGB:
 		mTextureDesc.stride = ((mFrameWidth + 63) / 64) * 256;
 		mTextureDesc.width = mFrameWidth;
+		mTextureDesc.internalFormat = GL_R32UI;
 		mTextureDesc.format = GL_RED_INTEGER;
 		mTextureDesc.type = GL_UNSIGNED_INT;
 		break;
@@ -888,6 +916,7 @@ void VideoDeckLink::openCam (char *format, short camIdx)
 	case bmdFormat12BitRGBLE:
 		mTextureDesc.stride = (mFrameWidth * 36) / 8;
 		mTextureDesc.width = (mFrameWidth / 8) * 9;
+		mTextureDesc.internalFormat = GL_R32UI;
 		mTextureDesc.format = GL_RED_INTEGER;
 		mTextureDesc.type = GL_UNSIGNED_INT;
 		break;
diff --git a/source/gameengine/VideoTexture/VideoDeckLink.h b/source/gameengine/VideoTexture/VideoDeckLink.h
index fa9c6c1..5dc97bd 100644
--- a/source/gameengine/VideoTexture/VideoDeckLink.h
+++ b/source/gameengine/VideoTexture/VideoDeckLink.h
@@ -62,6 +62,7 @@ struct TextureDesc
 	u_int		height;
 	u_int		stride;
 	u_int		size;
+	GLenum		internalFormat;
 	GLenum		format;
 	GLenum		type;
 	TextureDesc()
@@ -70,6 +71,7 @@ struct TextureDesc
 		height = 0;
 		stride = 0;
 		size = 0;
+		internalFormat = 0;
 		format = 0;
 		type = 0;
 	}




More information about the Bf-blender-cvs mailing list