Project import generated by Copybara.
GitOrigin-RevId: f4b1fe3f15810450fb6539e733f6a260d3ee082c
This commit is contained in:
@@ -99,6 +99,26 @@ const GLchar* const kScaledVertexShader = VERTEX_PREAMBLE _STRINGIFY(
|
||||
sample_coordinate = texture_coordinate.xy;
|
||||
});
|
||||
|
||||
const GLchar* const kTransformedVertexShader = VERTEX_PREAMBLE _STRINGIFY(
|
||||
in vec4 position; in mediump vec4 texture_coordinate;
|
||||
out mediump vec2 sample_coordinate; uniform mat3 transform;
|
||||
uniform vec2 viewport_size;
|
||||
|
||||
void main() {
|
||||
// switch from clip to viewport aspect ratio in order to properly
|
||||
// apply transformation
|
||||
vec2 half_viewport_size = viewport_size * 0.5;
|
||||
vec3 pos = vec3(position.xy * half_viewport_size, 1);
|
||||
|
||||
// apply transform
|
||||
pos = transform * pos;
|
||||
|
||||
// switch back to clip space
|
||||
gl_Position = vec4(pos.xy / half_viewport_size, 0, 1);
|
||||
|
||||
sample_coordinate = texture_coordinate.xy;
|
||||
});
|
||||
|
||||
const GLchar* const kBasicTexturedFragmentShader = FRAGMENT_PREAMBLE _STRINGIFY(
|
||||
DEFAULT_PRECISION(mediump, float)
|
||||
|
||||
|
||||
@@ -38,6 +38,17 @@ extern const GLchar* const kBasicVertexShader;
|
||||
// vec2 sample_coordinate - texture coordinate for shader
|
||||
extern const GLchar* const kScaledVertexShader;
|
||||
|
||||
// Applies an affine transformation to the vertex and leaves texture coordinates
|
||||
// as is. Input attributes:
|
||||
// vec4 position - vertex position
|
||||
// vec4 texture_coordinate - texture coordinate
|
||||
// Input uniform:
|
||||
// mat3 homogeneous affine transform - transformation matrix for vertices
|
||||
// vec2 viewport_size - size of the viewport
|
||||
// Output varying:
|
||||
// vec2 sample_coordinate - texture coordinate for shader
|
||||
extern const GLchar* const kTransformedVertexShader;
|
||||
|
||||
// Outputs the texture as it is.
|
||||
// Input varying:
|
||||
// vec2 sample_coordinate - texture coordinate
|
||||
|
||||
@@ -77,16 +77,24 @@ const GlTextureInfo& GlTextureInfoForGpuBufferFormat(GpuBufferFormat format,
|
||||
}},
|
||||
{GpuBufferFormat::kOneComponent8,
|
||||
{
|
||||
// This should be GL_RED, but it would change the output for existing
|
||||
// shaders. It would not be a good representation of a grayscale texture,
|
||||
// unless we use texture swizzling. We could add swizzle parameters (e.g.
|
||||
// GL_TEXTURE_SWIZZLE_R) in GLES 3 and desktop GL, and use GL_LUMINANCE
|
||||
// in GLES 2. Or we could just punt and make it a red texture.
|
||||
// {GL_R8, GL_RED, GL_UNSIGNED_BYTE, 1},
|
||||
// This format is like RGBA grayscale: GL_LUMINANCE replicates
|
||||
// the single channel texel values to RGB channels, and set alpha
|
||||
// to 1.0. If it is desired to see only the texel values in the R
|
||||
// channel, use kOneComponent8Red instead.
|
||||
#if !TARGET_OS_OSX
|
||||
{GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE, 1},
|
||||
#else
|
||||
{GL_R8, GL_RED, GL_UNSIGNED_BYTE, 1},
|
||||
#endif // TARGET_OS_OSX
|
||||
}},
|
||||
{GpuBufferFormat::kOneComponent8Red,
|
||||
{
|
||||
{GL_R8, GL_RED, GL_UNSIGNED_BYTE, 1},
|
||||
}},
|
||||
{GpuBufferFormat::kTwoComponent8,
|
||||
{
|
||||
{GL_RG8, GL_RG, GL_UNSIGNED_BYTE, 1},
|
||||
}},
|
||||
#ifdef __APPLE__
|
||||
// TODO: figure out GL_RED_EXT etc. on Android.
|
||||
{GpuBufferFormat::kBiPlanar420YpCbCr8VideoRange,
|
||||
@@ -195,6 +203,8 @@ ImageFormat::Format ImageFormatForGpuBufferFormat(GpuBufferFormat format) {
|
||||
case GpuBufferFormat::kTwoComponentFloat32:
|
||||
return ImageFormat::VEC32F2;
|
||||
case GpuBufferFormat::kGrayHalf16:
|
||||
case GpuBufferFormat::kOneComponent8Red:
|
||||
case GpuBufferFormat::kTwoComponent8:
|
||||
case GpuBufferFormat::kTwoComponentHalf16:
|
||||
case GpuBufferFormat::kRGBAHalf64:
|
||||
case GpuBufferFormat::kRGBAFloat128:
|
||||
|
||||
@@ -38,6 +38,8 @@ enum class GpuBufferFormat : uint32_t {
|
||||
kGrayFloat32 = MEDIAPIPE_FOURCC('L', '0', '0', 'f'),
|
||||
kGrayHalf16 = MEDIAPIPE_FOURCC('L', '0', '0', 'h'),
|
||||
kOneComponent8 = MEDIAPIPE_FOURCC('L', '0', '0', '8'),
|
||||
kOneComponent8Red = MEDIAPIPE_FOURCC('R', '0', '0', '8'),
|
||||
kTwoComponent8 = MEDIAPIPE_FOURCC('2', 'C', '0', '8'),
|
||||
kTwoComponentHalf16 = MEDIAPIPE_FOURCC('2', 'C', '0', 'h'),
|
||||
kTwoComponentFloat32 = MEDIAPIPE_FOURCC('2', 'C', '0', 'f'),
|
||||
kBiPlanar420YpCbCr8VideoRange = MEDIAPIPE_FOURCC('4', '2', '0', 'v'),
|
||||
@@ -82,6 +84,10 @@ inline OSType CVPixelFormatForGpuBufferFormat(GpuBufferFormat format) {
|
||||
return kCVPixelFormatType_OneComponent32Float;
|
||||
case GpuBufferFormat::kOneComponent8:
|
||||
return kCVPixelFormatType_OneComponent8;
|
||||
case GpuBufferFormat::kOneComponent8Red:
|
||||
return -1;
|
||||
case GpuBufferFormat::kTwoComponent8:
|
||||
return kCVPixelFormatType_TwoComponent8;
|
||||
case GpuBufferFormat::kTwoComponentHalf16:
|
||||
return kCVPixelFormatType_TwoComponent16Half;
|
||||
case GpuBufferFormat::kTwoComponentFloat32:
|
||||
@@ -114,6 +120,8 @@ inline GpuBufferFormat GpuBufferFormatForCVPixelFormat(OSType format) {
|
||||
return GpuBufferFormat::kGrayFloat32;
|
||||
case kCVPixelFormatType_OneComponent8:
|
||||
return GpuBufferFormat::kOneComponent8;
|
||||
case kCVPixelFormatType_TwoComponent8:
|
||||
return GpuBufferFormat::kTwoComponent8;
|
||||
case kCVPixelFormatType_TwoComponent16Half:
|
||||
return GpuBufferFormat::kTwoComponentHalf16;
|
||||
case kCVPixelFormatType_TwoComponent32Float:
|
||||
|
||||
Reference in New Issue
Block a user