[client] added support for RGBA, BGRA and 10-bit RGBA

This commit is contained in:
Geoffrey McRae 2018-12-04 21:23:28 +11:00
parent 1beeac545d
commit 75ffcacfe4
7 changed files with 54 additions and 15 deletions

View File

@ -381,7 +381,9 @@ int frameThread(void * unused)
size_t dataSize; size_t dataSize;
switch(header.type) switch(header.type)
{ {
case FRAME_TYPE_ARGB: case FRAME_TYPE_RGBA:
case FRAME_TYPE_BGRA:
case FRAME_TYPE_RGBA10:
dataSize = lgrFormat.height * lgrFormat.pitch; dataSize = lgrFormat.height * lgrFormat.pitch;
lgrFormat.bpp = 32; lgrFormat.bpp = 32;
break; break;

View File

@ -278,12 +278,24 @@ bool egl_on_frame_event(void * opaque, const LG_RendererFormat format, const uin
switch(format.type) switch(format.type)
{ {
case FRAME_TYPE_ARGB: case FRAME_TYPE_BGRA:
this->pixFmt = EGL_PF_BGRA;
this->shader = this->shaders.bgra;
this->frameSize = format.height * format.pitch;
break;
case FRAME_TYPE_RGBA:
this->pixFmt = EGL_PF_RGBA; this->pixFmt = EGL_PF_RGBA;
this->shader = this->shaders.rgba; this->shader = this->shaders.rgba;
this->frameSize = format.height * format.pitch; this->frameSize = format.height * format.pitch;
break; break;
case FRAME_TYPE_RGBA10:
this->pixFmt = EGL_PF_RGBA10;
this->shader = this->shaders.rgba;
this->frameSize = format.height * format.pitch;
break;
case FRAME_TYPE_YUV420: case FRAME_TYPE_YUV420:
this->pixFmt = EGL_PF_YUV420; this->pixFmt = EGL_PF_YUV420;
this->shader = this->shaders.yuv; this->shader = this->shaders.yuv;
@ -291,6 +303,7 @@ bool egl_on_frame_event(void * opaque, const LG_RendererFormat format, const uin
break; break;
default: default:
DEBUG_ERROR("Unsupported frame format");
return false; return false;
} }

View File

@ -112,11 +112,7 @@ uniform sampler2D sampler1;\
\ \
void main()\ void main()\
{\ {\
highp vec4 tmp = texture(sampler1, uv);\ color = texture(sampler1, uv);\
color.r = tmp.b;\
color.g = tmp.g;\
color.b = tmp.r;\
color.a = tmp.a;\
}\ }\
"; ";

View File

@ -38,7 +38,9 @@ struct EGL_Texture
GLuint samplers[3]; GLuint samplers[3];
size_t planes[3][2]; size_t planes[3][2];
GLintptr offsets[3]; GLintptr offsets[3];
GLenum intFormat;
GLenum format; GLenum format;
GLenum dataType;
bool hasPBO; bool hasPBO;
GLuint pbo[2]; GLuint pbo[2];
@ -91,13 +93,34 @@ bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, size_
switch(pixFmt) switch(pixFmt)
{ {
case EGL_PF_RGBA:
case EGL_PF_BGRA: case EGL_PF_BGRA:
textureCount = 1; textureCount = 1;
texture->format = GL_BGRA; texture->format = GL_BGRA;
texture->planes[0][0] = width; texture->planes[0][0] = width;
texture->planes[0][1] = height; texture->planes[0][1] = height;
texture->offsets[0] = 0; texture->offsets[0] = 0;
texture->intFormat = GL_BGRA;
texture->dataType = GL_UNSIGNED_BYTE;
break;
case EGL_PF_RGBA:
textureCount = 1;
texture->format = GL_RGBA;
texture->planes[0][0] = width;
texture->planes[0][1] = height;
texture->offsets[0] = 0;
texture->intFormat = GL_BGRA;
texture->dataType = GL_UNSIGNED_BYTE;
break;
case EGL_PF_RGBA10:
textureCount = 1;
texture->format = GL_RGBA;
texture->planes[0][0] = width;
texture->planes[0][1] = height;
texture->offsets[0] = 0;
texture->intFormat = GL_RGB10_A2;
texture->dataType = GL_UNSIGNED_INT_2_10_10_10_REV;
break; break;
case EGL_PF_YUV420: case EGL_PF_YUV420:
@ -112,6 +135,7 @@ bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, size_
texture->offsets[0] = 0; texture->offsets[0] = 0;
texture->offsets[1] = width * height; texture->offsets[1] = width * height;
texture->offsets[2] = texture->offsets[1] + (texture->offsets[1] / 4); texture->offsets[2] = texture->offsets[1] + (texture->offsets[1] / 4);
texture->dataType = GL_UNSIGNED_BYTE;
break; break;
default: default:
@ -140,8 +164,8 @@ bool egl_texture_setup(EGL_Texture * texture, enum EGL_PixelFormat pixFmt, size_
glSamplerParameteri(texture->samplers[i], GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE); glSamplerParameteri(texture->samplers[i], GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE);
glBindTexture(GL_TEXTURE_2D, texture->textures[i]); glBindTexture(GL_TEXTURE_2D, texture->textures[i]);
glTexImage2D(GL_TEXTURE_2D, 0, texture->format, texture->planes[i][0], texture->planes[i][1], glTexImage2D(GL_TEXTURE_2D, 0, texture->intFormat, texture->planes[i][0], texture->planes[i][1],
0, texture->format, GL_UNSIGNED_BYTE, NULL); 0, texture->format, texture->dataType, NULL);
} }
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
@ -194,7 +218,7 @@ bool egl_texture_update(EGL_Texture * texture, const uint8_t * buffer)
{ {
glBindTexture(GL_TEXTURE_2D, texture->textures[i]); glBindTexture(GL_TEXTURE_2D, texture->textures[i]);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->planes[i][0], texture->planes[i][1], glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->planes[i][0], texture->planes[i][1],
texture->format, GL_UNSIGNED_BYTE, buffer + texture->offsets[i]); texture->format, texture->dataType, buffer + texture->offsets[i]);
} }
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
} }
@ -210,7 +234,7 @@ void egl_texture_bind(EGL_Texture * texture)
{ {
glBindTexture(GL_TEXTURE_2D, texture->textures[i]); glBindTexture(GL_TEXTURE_2D, texture->textures[i]);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->planes[i][0], texture->planes[i][1], glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture->planes[i][0], texture->planes[i][1],
texture->format, GL_UNSIGNED_BYTE, (const void *)texture->offsets[i]); texture->format, texture->dataType, (const void *)texture->offsets[i]);
} }
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);

View File

@ -31,6 +31,7 @@ enum EGL_PixelFormat
{ {
EGL_PF_RGBA, EGL_PF_RGBA,
EGL_PF_BGRA, EGL_PF_BGRA,
EGL_PF_RGBA10,
EGL_PF_YUV420 EGL_PF_YUV420
}; };

View File

@ -878,7 +878,8 @@ static bool configure(struct Inst * this, SDL_Window *window)
switch(this->format.type) switch(this->format.type)
{ {
case FRAME_TYPE_ARGB: case FRAME_TYPE_BGRA:
case FRAME_TYPE_RGBA:
this->decoder = &LGD_NULL; this->decoder = &LGD_NULL;
break; break;

View File

@ -21,12 +21,14 @@ Place, Suite 330, Boston, MA 02111-1307 USA
#include <stdint.h> #include <stdint.h>
#define KVMFR_HEADER_MAGIC "[[KVMFR]]" #define KVMFR_HEADER_MAGIC "[[KVMFR]]"
#define KVMFR_HEADER_VERSION 7 #define KVMFR_HEADER_VERSION 8
typedef enum FrameType typedef enum FrameType
{ {
FRAME_TYPE_INVALID , FRAME_TYPE_INVALID ,
FRAME_TYPE_ARGB , // ABGR interleaved: A,R,G,B 32bpp FRAME_TYPE_BGRA , // BGRA interleaved: B,G,R,A 32bpp
FRAME_TYPE_RGBA , // RGBA interleaved: R,G,B,A 32bpp
FRAME_TYPE_RGBA10 , // RGBA interleaved: R,G,B,A 10,10,10,2 bpp
FRAME_TYPE_YUV420 , // YUV420 FRAME_TYPE_YUV420 , // YUV420
FRAME_TYPE_H264 , // H264 compressed FRAME_TYPE_H264 , // H264 compressed
FRAME_TYPE_MAX , // sentinel value FRAME_TYPE_MAX , // sentinel value