mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 15:40:21 +00:00
Mac - enable DXT
This commit is contained in:
@@ -1,13 +1,7 @@
|
||||
#version 130
|
||||
|
||||
#extension GL_EXT_gpu_shader4 : enable
|
||||
|
||||
#define lerp mix
|
||||
|
||||
// Image formats
|
||||
const int FORMAT_RGB = 0;
|
||||
const int FORMAT_YUV = 1;
|
||||
|
||||
// Covert YUV to RGB
|
||||
vec3 ConvertYUVToRGB(vec3 color)
|
||||
{
|
||||
@@ -34,24 +28,24 @@ float colorDistance(vec2 c0, vec2 c1)
|
||||
|
||||
void ExtractColorBlockRGB(out vec3 col[16], sampler2D image, vec4 texcoord, vec2 imageSize)
|
||||
{
|
||||
vec2 texelSize = (1.0f / imageSize);
|
||||
vec2 texelSize = (1.0 / imageSize);
|
||||
vec2 tex = vec2(texcoord.x, texcoord.y);
|
||||
tex -= texelSize * vec2(1.5);
|
||||
for ( int i = 0; i < 4; i++ ) {
|
||||
for ( int j = 0; j < 4; j++ ) {
|
||||
col[i * 4 + j] = texture(image, tex + vec2(j, i) * texelSize).rgb;
|
||||
col[i * 4 + j] = texture2D(image, tex + vec2(j, i) * texelSize).rgb;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExtractColorBlockYUV(out vec3 col[16], sampler2D image, vec4 texcoord, vec2 imageSize)
|
||||
{
|
||||
vec2 texelSize = (1.0f / imageSize);
|
||||
vec2 texelSize = (1.0 / imageSize);
|
||||
vec2 tex = vec2(texcoord.x, texcoord.y);
|
||||
tex -= texelSize * vec2(2);
|
||||
for ( int i = 0; i < 4; i++ ) {
|
||||
for ( int j = 0; j < 4; j++ ) {
|
||||
col[i * 4 + j] = ConvertYUVToRGB(texture(image, tex + vec2(j, i) * texelSize).rgb);
|
||||
col[i * 4 + j] = ConvertYUVToRGB(texture2D(image, tex + vec2(j, i) * texelSize).rgb);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -78,12 +72,12 @@ void SelectDiagonal(vec3 block[16], inout vec3 mincol, inout vec3 maxcol)
|
||||
cov.y += t.y * t.z;
|
||||
}
|
||||
|
||||
if (cov.x < 0) {
|
||||
if (cov.x < 0.0) {
|
||||
float temp = maxcol.x;
|
||||
maxcol.x = mincol.x;
|
||||
mincol.x = temp;
|
||||
}
|
||||
if (cov.y < 0) {
|
||||
if (cov.y < 0.0) {
|
||||
float temp = maxcol.y;
|
||||
maxcol.y = mincol.y;
|
||||
mincol.y = temp;
|
||||
@@ -92,12 +86,12 @@ void SelectDiagonal(vec3 block[16], inout vec3 mincol, inout vec3 maxcol)
|
||||
|
||||
void InsetBBox(inout vec3 mincol, inout vec3 maxcol)
|
||||
{
|
||||
vec3 inset = (maxcol - mincol) / 16.0 - (8.0 / 255.0) / 16;
|
||||
vec3 inset = (maxcol - mincol) / 16.0 - (8.0 / 255.0) / 16.0;
|
||||
mincol = clamp(mincol + inset, 0.0, 1.0);
|
||||
maxcol = clamp(maxcol - inset, 0.0, 1.0);
|
||||
}
|
||||
|
||||
vec3 RoundAndExpand(vec3 v, out uint w)
|
||||
vec3 RoundAndExpand(vec3 v, out unsigned int w)
|
||||
{
|
||||
uvec3 c = uvec3(round(v * vec3(31, 63, 31)));
|
||||
w = (c.r << 11u) | (c.g << 5u) | c.b;
|
||||
@@ -108,7 +102,7 @@ vec3 RoundAndExpand(vec3 v, out uint w)
|
||||
return vec3(c) * (1.0 / 255.0);
|
||||
}
|
||||
|
||||
uint EmitEndPointsDXT1(inout vec3 mincol, inout vec3 maxcol)
|
||||
unsigned int EmitEndPointsDXT1(inout vec3 mincol, inout vec3 maxcol)
|
||||
{
|
||||
uvec2 outp;
|
||||
maxcol = RoundAndExpand(maxcol, outp.x);
|
||||
@@ -126,7 +120,7 @@ uint EmitEndPointsDXT1(inout vec3 mincol, inout vec3 maxcol)
|
||||
return outp.x | (outp.y << 16u);
|
||||
}
|
||||
|
||||
uint EmitIndicesDXT1(vec3 col[16], vec3 mincol, vec3 maxcol)
|
||||
unsigned int EmitIndicesDXT1(vec3 col[16], vec3 mincol, vec3 maxcol)
|
||||
{
|
||||
// Compute palette
|
||||
vec3 c[4];
|
||||
@@ -136,7 +130,7 @@ uint EmitIndicesDXT1(vec3 col[16], vec3 mincol, vec3 maxcol)
|
||||
c[3] = lerp(c[0], c[1], 2.0/3.0);
|
||||
|
||||
// Compute indices
|
||||
uint indices = 0u;
|
||||
unsigned int indices = 0u;
|
||||
for ( int i = 0; i < 16; i++ ) {
|
||||
|
||||
// find index of closest color
|
||||
@@ -151,29 +145,29 @@ uint EmitIndicesDXT1(vec3 col[16], vec3 mincol, vec3 maxcol)
|
||||
b.y = dist.y > dist.z ? 1u : 0u;
|
||||
b.z = dist.x > dist.z ? 1u : 0u;
|
||||
b.w = dist.y > dist.w ? 1u : 0u;
|
||||
uint b4 = dist.z > dist.w ? 1u : 0u;
|
||||
unsigned int b4 = dist.z > dist.w ? 1u : 0u;
|
||||
|
||||
uint index = (b.x & b4) | (((b.y & b.z) | (b.x & b.w)) << 1u);
|
||||
indices |= index << (uint(i) * 2u);
|
||||
unsigned int index = (b.x & b4) | (((b.y & b.z) | (b.x & b.w)) << 1u);
|
||||
indices |= index << (unsigned int(i) * 2u);
|
||||
}
|
||||
|
||||
// Output indices
|
||||
return indices;
|
||||
}
|
||||
|
||||
in vec4 TEX0;
|
||||
vec4 TEX0;
|
||||
uniform sampler2D image;
|
||||
uniform int imageFormat = FORMAT_RGB;
|
||||
//uniform int imageFormat = FORMAT_RGB;
|
||||
uniform vec2 imageSize;
|
||||
out uvec4 colorInt;
|
||||
//out uvec4 colorInt;
|
||||
|
||||
void main()
|
||||
{
|
||||
// Read block
|
||||
vec3 block[16];
|
||||
if ( int(imageFormat) == FORMAT_YUV )
|
||||
ExtractColorBlockYUV(block, image, TEX0, imageSize);
|
||||
else
|
||||
//if ( int(imageFormat) == FORMAT_YUV )
|
||||
// ExtractColorBlockYUV(block, image, TEX0, imageSize);
|
||||
//else
|
||||
ExtractColorBlockRGB(block, image, TEX0, imageSize);
|
||||
|
||||
// Find min and max colors
|
||||
@@ -190,5 +184,5 @@ void main()
|
||||
outp.y = 0u;
|
||||
outp.z = 0u;
|
||||
|
||||
colorInt = outp;
|
||||
//colorInt = outp;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ void ExtractColorBlockRGB(out vec3 col[16], sampler2D image, vec4 texcoord, vec2
|
||||
|
||||
void ExtractColorBlockYUV(out vec3 col[16], sampler2D image, vec4 texcoord, vec2 imageSize)
|
||||
{
|
||||
vec2 texelSize = (1.0f / imageSize);
|
||||
vec2 texelSize = (1.0 / imageSize);
|
||||
vec2 tex = vec2(texcoord.x, texcoord.y);
|
||||
tex -= texelSize * vec2(2);
|
||||
for ( int i = 0; i < 4; i++ ) {
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
#if GL_compatibility_profile
|
||||
varying out vec4 TEX0;
|
||||
#else
|
||||
out vec4 TEX0;
|
||||
#endif
|
||||
|
||||
void main() {
|
||||
gl_Position = gl_Vertex;
|
||||
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||
TEX0 = gl_TexCoord[0];
|
||||
}
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
#version 130
|
||||
|
||||
#extension GL_EXT_gpu_shader4 : enable
|
||||
|
||||
#define lerp mix
|
||||
|
||||
in vec4 TEX0;
|
||||
//in vec4 TEX0;
|
||||
uniform sampler2D image;
|
||||
uniform float imageWidth;
|
||||
out vec4 color;
|
||||
//out vec4 color;
|
||||
|
||||
void main()
|
||||
{
|
||||
color.rgba = texture(image, TEX0.xy).grba; // store Y0UVY1 ro rgba
|
||||
if(TEX0.x * imageWidth / 2.0f - floor(TEX0.x * imageWidth / 2.0f) > 0.5f) // 'odd' pixel
|
||||
color.r = color.a; // use Y1 instead of Y0
|
||||
//color.rgba = texture(image, TEX0.xy).grba; // store Y0UVY1 ro rgba
|
||||
//if(TEX0.x * imageWidth / 2.0f - floor(TEX0.x * imageWidth / 2.0f) > 0.5f) // 'odd' pixel
|
||||
// color.r = color.a; // use Y1 instead of Y0
|
||||
}
|
||||
|
||||
@@ -821,8 +821,7 @@ AC_CHECK_HEADER(GL/gl.h, FOUND_GL_H=yes)
|
||||
AC_CHECK_LIB(GL, glXCreateNewContext, FOUND_GLX_L=yes)
|
||||
|
||||
if test $rtdxt_req = yes -a "$HAVE_X11" = yes -a "$FOUND_GLEW_L" = yes -a "$FOUND_GLEW_H" = yes -a "$FOUND_GLX_L" = yes -a "$FOUND_GLX_H" = yes \
|
||||
-a "$FOUND_GL_H" = yes \
|
||||
-a `expr "$host_os" : ".*darwin.*"` -eq 0 # not mac, just for now
|
||||
-a "$FOUND_GL_H" = yes -a `expr "$host_os" : ".*darwin.*"` -eq 0
|
||||
then
|
||||
LIBS+=" -lGLEW -lGL -lX11"
|
||||
AC_DEFINE([HAVE_DXT_GLSL], [1], [Build with DXT_GLSL support])
|
||||
@@ -830,11 +829,23 @@ then
|
||||
../dxt_compress/dxt_common.o ../dxt_compress/dxt_util.o src/video_compress/dxt_glsl.o src/video_decompress/dxt_glsl.o"
|
||||
DXT_GLSL_CFLAGS="-std=gnu99"
|
||||
rtdxt=yes
|
||||
else
|
||||
else # not found or mac, for which we don't need it
|
||||
CFLAGS=$SAVED_CFLAGS
|
||||
CPPFLAGS=$SAVED_CPPFLAGS
|
||||
LIBS=$SAVED_LIBS
|
||||
fi
|
||||
|
||||
if test $rtdxt_req = yes -a "$FOUND_GLEW_L" = yes -a "$FOUND_GLEW_H" = yes -a `expr "$host_os" : ".*darwin.*"` -gt 0
|
||||
then
|
||||
LIBS+=" -lGLEW"
|
||||
AC_DEFINE([HAVE_DXT_GLSL], [1], [Build with DXT_GLSL support])
|
||||
DXT_GLSL_OBJS="../dxt_compress/dxt_encoder.o ../dxt_compress/dxt_decoder.o \
|
||||
../dxt_compress/dxt_common.o ../dxt_compress/dxt_util.o src/video_compress/dxt_glsl.o src/video_decompress/dxt_glsl.o"
|
||||
DXT_GLSL_CFLAGS="-std=gnu99"
|
||||
rtdxt=yes
|
||||
fi
|
||||
|
||||
|
||||
AC_SUBST(DXT_GLSL_OBJS)
|
||||
AC_SUBST(DXT_GLSL_CFLAGS)
|
||||
|
||||
|
||||
@@ -60,8 +60,12 @@
|
||||
#include <GL/glew.h>
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glx.h>
|
||||
#ifdef HAVE_MACOSX
|
||||
#include <GLUT/glut.h>
|
||||
#else
|
||||
#include "x11_common.h"
|
||||
|
||||
#endif
|
||||
|
||||
struct video_compress {
|
||||
struct dxt_encoder *encoder;
|
||||
|
||||
@@ -73,8 +77,9 @@ struct video_compress {
|
||||
codec_t color_spec;
|
||||
|
||||
int dxt_height;
|
||||
|
||||
#ifndef HAVE_MACOSX
|
||||
void *glx_context;
|
||||
#endif
|
||||
};
|
||||
|
||||
static int configure_with(struct video_compress *s, struct video_frame *frame);
|
||||
@@ -195,7 +200,8 @@ void * dxt_glsl_compress_init(char * opts)
|
||||
s = (struct video_compress *) malloc(sizeof(struct video_compress));
|
||||
s->out = NULL;
|
||||
s->decoded = NULL;
|
||||
|
||||
|
||||
#ifndef HAVE_MACOSX
|
||||
x11_enter_thread();
|
||||
s->glx_context = glx_init();
|
||||
if(!s->glx_context) {
|
||||
@@ -203,6 +209,14 @@ void * dxt_glsl_compress_init(char * opts)
|
||||
exit_uv(128);
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
int argc = 0;
|
||||
glutInit(&argc, NULL);
|
||||
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
|
||||
glutCreateWindow("DXT");
|
||||
glutHideWindow();
|
||||
glewInit();
|
||||
#endif
|
||||
|
||||
if(opts && strcmp(opts, "help") == 0) {
|
||||
printf("DXT GLSL comperssion usage:\n");
|
||||
@@ -291,7 +305,9 @@ void dxt_glsl_compress_done(void *arg)
|
||||
if(s->out)
|
||||
free(s->out->tiles[0].data);
|
||||
vf_free(s->out);
|
||||
|
||||
|
||||
#ifndef HAVE_MACOSX
|
||||
glx_free(s->glx_context);
|
||||
#endif
|
||||
free(s);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,11 @@
|
||||
#include <stdlib.h>
|
||||
#include "video_decompress/dxt_glsl.h"
|
||||
#include <GL/glew.h>
|
||||
#ifdef HAVE_MACOSX
|
||||
#include <GLUT/glut.h>
|
||||
#else
|
||||
#include "x11_common.h"
|
||||
#endif
|
||||
|
||||
struct state_decompress {
|
||||
struct dxt_decoder *decoder;
|
||||
@@ -70,14 +74,16 @@ struct state_decompress {
|
||||
unsigned int configured:1;
|
||||
|
||||
int dxt_height; /* dxt_height is alligned height to 4 lines boundry */
|
||||
|
||||
#ifndef HAVE_MACOSX
|
||||
void *glx_context;
|
||||
#endif
|
||||
};
|
||||
|
||||
static void configure_with(struct state_decompress *decompressor, struct video_desc desc)
|
||||
{
|
||||
enum dxt_type type;
|
||||
|
||||
|
||||
#ifndef HAVE_MACOSX
|
||||
decompressor->glx_context = glx_init();
|
||||
if(!decompressor->glx_context) {
|
||||
fprintf(stderr, "Failed to create GLX context.");
|
||||
@@ -85,6 +91,14 @@ static void configure_with(struct state_decompress *decompressor, struct video_d
|
||||
decompressor->compressed_len = 0;
|
||||
return;
|
||||
}
|
||||
#else
|
||||
int argc = 0;
|
||||
glutInit(&argc, NULL);
|
||||
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
|
||||
glutCreateWindow("DXT");
|
||||
glutHideWindow();
|
||||
glewInit();
|
||||
#endif
|
||||
|
||||
if(desc.color_spec == DXT5) {
|
||||
type = DXT_TYPE_DXT5_YCOCG;
|
||||
@@ -115,8 +129,9 @@ void * dxt_glsl_decompress_init(void)
|
||||
|
||||
s = (struct state_decompress *) malloc(sizeof(struct state_decompress));
|
||||
s->configured = FALSE;
|
||||
#ifndef HAVE_MACOSX
|
||||
x11_enter_thread();
|
||||
|
||||
#endif
|
||||
return s;
|
||||
}
|
||||
|
||||
@@ -185,7 +200,9 @@ void dxt_glsl_decompress_done(void *state)
|
||||
|
||||
if(s->configured) {
|
||||
dxt_decoder_destroy(s->decoder);
|
||||
#ifndef HAVE_MACOSX
|
||||
glx_free(s->glx_context);
|
||||
#endif
|
||||
}
|
||||
free(s);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user