Commit 1e4bfd0d authored by Cyril Deguet's avatar Cyril Deguet

* all: now both GLX 1.2 and 1.3 are supported

parent 3a6efa71
......@@ -28,13 +28,16 @@
#include <GL/glx.h>
/* Local prototypes */
static void CreateWindow( galaktos_thread_t *p_thread, XVisualInfo *p_vi,
int i_width, int i_height, int b_fullscreen );
static int InitGLX12( galaktos_thread_t *p_thread );
static int InitGLX13( galaktos_thread_t *p_thread );
static void CreateWindow( galaktos_thread_t *p_thread, XVisualInfo *p_vi );
typedef struct
{
Display *p_display;
int b_glx13;
GLXContext gwctx;
Window wnd;
GLXWindow gwnd;
......@@ -46,28 +49,11 @@ glx_data_t;
#define OS_DATA ((glx_data_t*)(p_thread->p_os_data))
int galaktos_glx_init( galaktos_thread_t *p_thread, int i_width, int i_height,
int b_fullscreen )
int galaktos_glx_init( galaktos_thread_t *p_thread )
{
Display *p_display;
int i_opcode, i_evt, i_err;
int i_maj, i_min;
int i_nbelem;
GLXFBConfig *p_fbconfs, fbconf;
XSetWindowAttributes xattr;
XVisualInfo *p_vi;
GLXContext gwctx;
int i;
GLXPbuffer gpbuf;
#if 1
int p_attr[] = { GLX_RED_SIZE, 5, GLX_GREEN_SIZE, 5,
GLX_BLUE_SIZE, 5, GLX_DOUBLEBUFFER, True,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, 0 };
#else
int p_attr[] = { GLX_RGBA, GLX_RED_SIZE, 5, GLX_GREEN_SIZE, 5,
GLX_BLUE_SIZE, 5, GLX_DOUBLEBUFFER,
0 };
#endif
/* Initialize OS data */
p_thread->p_os_data = malloc( sizeof( glx_data_t ) );
......@@ -98,13 +84,171 @@ int galaktos_glx_init( galaktos_thread_t *p_thread, int i_width, int i_height,
msg_Err( p_thread, "glXQueryVersion failed" );
return -1;
}
#if 1
if( i_maj <= 0 || ((i_maj == 1) && (i_min < 3)) )
{
msg_Err( p_thread, "GLX 1.3 is needed" );
OS_DATA->b_glx13 = 0;
msg_Info( p_thread, "Using GLX 1.2 API" );
if( InitGLX12( p_thread ) == -1 )
{
return -1;
}
}
else
{
OS_DATA->b_glx13 = 1;
msg_Info( p_thread, "Using GLX 1.3 API" );
if( InitGLX13( p_thread ) == -1 )
{
return -1;
}
}
XMapWindow( p_display, OS_DATA->wnd );
if( p_thread->b_fullscreen )
{
//XXX
XMoveWindow( p_display, OS_DATA->wnd, 0, 0 );
}
XFlush( p_display );
return 0;
}
int galaktos_glx_handle_events( galaktos_thread_t *p_thread )
{
Display *p_display;
p_display = OS_DATA->p_display;
/* loop on X11 events */
while( XPending( p_display ) > 0 )
{
XEvent evt;
XNextEvent( p_display, &evt );
switch( evt.type )
{
case ClientMessage:
{
/* Delete notification */
if( (evt.xclient.format == 32) &&
((Atom)evt.xclient.data.l[0] == OS_DATA->wm_delete) )
{
return 1;
}
break;
}
}
}
return 0;
}
void galaktos_glx_activate_pbuffer( galaktos_thread_t *p_thread )
{
glXMakeContextCurrent( OS_DATA->p_display, OS_DATA->gpbuf, OS_DATA->gpbuf,
OS_DATA->gpctx );
}
void galaktos_glx_activate_window( galaktos_thread_t *p_thread )
{
if( OS_DATA->b_glx13 )
{
glXMakeContextCurrent( OS_DATA->p_display, OS_DATA->gwnd, OS_DATA->gwnd,
OS_DATA->gwctx );
}
else
{
glXMakeCurrent( OS_DATA->p_display, OS_DATA->wnd, OS_DATA->gwctx );
}
}
void galaktos_glx_swap( galaktos_thread_t *p_thread )
{
if( OS_DATA->b_glx13 )
{
glXSwapBuffers( OS_DATA->p_display, OS_DATA->gwnd );
}
else
{
glXSwapBuffers( OS_DATA->p_display, OS_DATA->wnd );
}
}
void galaktos_glx_done( galaktos_thread_t *p_thread )
{
Display *p_display;
p_display = OS_DATA->p_display;
if( OS_DATA->b_glx13 )
{
glXDestroyContext( p_display, OS_DATA->gpctx );
glXDestroyPbuffer( p_display, OS_DATA->gpbuf );
}
glXDestroyContext( p_display, OS_DATA->gwctx );
if( OS_DATA->b_glx13 )
{
glXDestroyWindow( p_display, OS_DATA->gwnd );
}
XDestroyWindow( p_display, OS_DATA->wnd );
XCloseDisplay( p_display );
}
int InitGLX12( galaktos_thread_t *p_thread )
{
Display *p_display;
XVisualInfo *p_vi;
GLXContext gwctx;
int p_attr[] = { GLX_RGBA, GLX_RED_SIZE, 5, GLX_GREEN_SIZE, 5,
GLX_BLUE_SIZE, 5, GLX_DOUBLEBUFFER,
0 };
p_display = OS_DATA->p_display;
p_vi = glXChooseVisual( p_display, DefaultScreen( p_display), p_attr );
if(! p_vi )
{
msg_Err( p_thread, "Cannot get GLX 1.2 visual" );
return -1;
}
/* Create the window */
CreateWindow( p_thread, p_vi );
/* Create an OpenGL context */
OS_DATA->gwctx = gwctx = glXCreateContext( p_display, p_vi, 0, True );
if( !gwctx )
{
msg_Err( p_thread, "Cannot create OpenGL context");
XFree( p_vi );
return -1;
}
XFree( p_vi );
return 0;
}
int InitGLX13( galaktos_thread_t *p_thread )
{
Display *p_display;
int i_nbelem;
GLXFBConfig *p_fbconfs, fbconf;
XVisualInfo *p_vi;
GLXContext gwctx;
int i;
GLXPbuffer gpbuf;
int p_attr[] = { GLX_RED_SIZE, 5, GLX_GREEN_SIZE, 5,
GLX_BLUE_SIZE, 5, GLX_DOUBLEBUFFER, True,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, 0 };
p_display = OS_DATA->p_display;
/* Get the FB configuration */
p_fbconfs = glXChooseFBConfig( p_display, 0, p_attr, &i_nbelem );
if( (i_nbelem <= 0) || !p_fbconfs )
......@@ -126,21 +270,12 @@ int galaktos_glx_init( galaktos_thread_t *p_thread, int i_width, int i_height,
XFree( p_fbconfs );
return -1;
}
#else
p_vi = glXChooseVisual( p_display, DefaultScreen( p_display), p_attr );
if(! p_vi )
{
msg_Err( p_thread, "Cannot get GLX 1.2 visual" );
return -1;
}
#endif
/* Create the window */
CreateWindow( p_thread, p_vi, i_width, i_height, b_fullscreen );
CreateWindow( p_thread, p_vi );
XFree( p_vi );
#if 1
/* Create the GLX window */
OS_DATA->gwnd = glXCreateWindow( p_display, fbconf, OS_DATA->wnd, NULL );
if( OS_DATA->gwnd == None )
......@@ -151,7 +286,7 @@ int galaktos_glx_init( galaktos_thread_t *p_thread, int i_width, int i_height,
/* Create an OpenGL context */
OS_DATA->gwctx = gwctx = glXCreateNewContext( p_display, fbconf,
GLX_RGBA_TYPE, NULL, True );
GLX_RGBA_TYPE, NULL, True );
if( !gwctx )
{
msg_Err( p_thread, "Cannot create OpenGL context");
......@@ -206,118 +341,42 @@ int galaktos_glx_init( galaktos_thread_t *p_thread, int i_width, int i_height,
}
XFree( p_fbconfs );
#else
/* Create an OpenGL context */
OS_DATA->gwctx = gwctx = glXCreateContext( p_display, p_vi, 0, True );
if( !gwctx )
{
msg_Err( p_thread, "Cannot create OpenGL context");
XFree( p_fbconfs );
return -1;
}
XFree( p_vi );
#endif
XMapWindow( p_display, OS_DATA->wnd );
if( b_fullscreen )
{
XMoveWindow( p_display, OS_DATA->wnd, 0, 0 );
}
XFlush( p_display );
// glXMakeContextCurrent( p_display, OS_DATA->gwnd, OS_DATA->gwnd, gwctx );
// glXMakeCurrent( p_display, OS_DATA->wnd, OS_DATA->gwctx );
return 0;
}
int galaktos_glx_handle_events( galaktos_thread_t *p_thread )
{
Display *p_display;
p_display = OS_DATA->p_display;
/* loop on X11 events */
while( XPending( p_display ) > 0 )
{
XEvent evt;
XNextEvent( p_display, &evt );
switch( evt.type )
{
case ClientMessage:
{
/* Delete notification */
if( (evt.xclient.format == 32) &&
((Atom)evt.xclient.data.l[0] == OS_DATA->wm_delete) )
{
return 1;
}
break;
}
}
}
return 0;
}
void galaktos_glx_activate_pbuffer( galaktos_thread_t *p_thread )
{
glXMakeContextCurrent( OS_DATA->p_display, OS_DATA->gpbuf, OS_DATA->gpbuf,
OS_DATA->gpctx );
}
void galaktos_glx_activate_window( galaktos_thread_t *p_thread )
{
glXMakeContextCurrent( OS_DATA->p_display, OS_DATA->gwnd, OS_DATA->gwnd,
OS_DATA->gwctx );
// glXMakeCurrent( OS_DATA->p_display, OS_DATA->wnd, OS_DATA->gwctx );
}
void galaktos_glx_swap( galaktos_thread_t *p_thread )
{
glXSwapBuffers( OS_DATA->p_display, OS_DATA->gwnd );
}
void galaktos_glx_done( galaktos_thread_t *p_thread )
{
Display *p_display;
p_display = OS_DATA->p_display;
glXDestroyContext( p_display, OS_DATA->gpctx );
glXDestroyPbuffer( p_display, OS_DATA->gpbuf );
glXDestroyContext( p_display, OS_DATA->gwctx );
glXDestroyWindow( p_display, OS_DATA->gwnd );
XDestroyWindow( p_display, OS_DATA->wnd );
XCloseDisplay( p_display );
}
void CreateWindow( galaktos_thread_t *p_thread, XVisualInfo *p_vi,
int i_width, int i_height, int b_fullscreen )
void CreateWindow( galaktos_thread_t *p_thread, XVisualInfo *p_vi )
{
Display *p_display;
XSetWindowAttributes xattr;
Window wnd;
Colormap cm;
XSizeHints* p_size_hints;
Atom prop;
mwmhints_t mwmhints;
p_display = OS_DATA->p_display;
/* Create a colormap */
cm = XCreateColormap( p_display, RootWindow( p_display, p_vi->screen ),
p_vi->visual, AllocNone );
/* Create the window */
xattr.background_pixel = BlackPixel( p_display, DefaultScreen(p_display) );
xattr.border_pixel = 0;
xattr.colormap = cm;
OS_DATA->wnd = wnd = XCreateWindow( p_display, DefaultRootWindow(p_display),
0, 0, i_width, i_height, 0, p_vi->depth, InputOutput, p_vi->visual,
CWBackPixel | CWBorderPixel, &xattr);
0, 0, p_thread->i_width, p_thread->i_height, 0, p_vi->depth,
InputOutput, p_vi->visual,
CWBackPixel | CWBorderPixel | CWColormap, &xattr);
/* Allow the window to be deleted by the window manager */
OS_DATA->wm_delete = XInternAtom( p_display, "WM_DELETE_WINDOW", False );
XSetWMProtocols( p_display, wnd, &OS_DATA->wm_delete, 1 );
if( b_fullscreen )
if( p_thread->b_fullscreen )
{
mwmhints.flags = MWM_HINTS_DECORATIONS;
mwmhints.decorations = False;
......@@ -331,10 +390,10 @@ void CreateWindow( galaktos_thread_t *p_thread, XVisualInfo *p_vi,
/* Prevent the window from being resized */
p_size_hints = XAllocSizeHints();
p_size_hints->flags = PMinSize | PMaxSize;
p_size_hints->min_width = i_width;
p_size_hints->min_height = i_height;
p_size_hints->max_width = i_width;
p_size_hints->max_height = i_height;
p_size_hints->min_width = p_thread->i_width;
p_size_hints->min_height = p_thread->i_height;
p_size_hints->max_width = p_thread->i_width;
p_size_hints->max_height = p_thread->i_height;
XSetWMNormalHints( p_display, wnd, p_size_hints );
XFree( p_size_hints );
}
......
......@@ -26,8 +26,7 @@
#include "plugin.h"
int galaktos_glx_init( galaktos_thread_t *p_thread, int i_width, int i_height,
int b_fullscreen );
int galaktos_glx_init( galaktos_thread_t *p_thread );
void galaktos_glx_done( galaktos_thread_t *p_thread );
int galaktos_glx_handle_events( galaktos_thread_t *p_thread );
void galaktos_glx_activate_pbuffer( galaktos_thread_t *p_thread );
......
......@@ -127,8 +127,8 @@ int galaktos_init( galaktos_thread_t *p_thread )
initPresetLoader();
/* Load default preset directory */
// loadPresetDir("/home/cyril/.vlc/galaktos");
loadPresetDir("/etc/projectM/presets");
loadPresetDir("/home/cyril/.vlc/galaktos");
// loadPresetDir("/etc/projectM/presets");
initPCM(maxsamples);
initBeatDetect();
......@@ -207,7 +207,7 @@ int galaktos_update( galaktos_thread_t *p_thread )
//and then we perform our manipulations on it
//in pass 2 we will copy the texture into texture memory
// galaktos_glx_activate_pbuffer( p_thread );
// galaktos_glx_activate_pbuffer( p_thread );
glPushAttrib( GL_ALL_ATTRIB_BITS ); /* Overkill, but safe */
......
......@@ -113,7 +113,10 @@ static int Open( vlc_object_t *p_this )
p_thread->i_cur_sample = 0;
bzero( p_thread->p_data, 2*2*512 );
galaktos_glx_init( p_thread, 600, 600, 0 );
p_thread->i_width = 600;
p_thread->i_height = 600;
p_thread->b_fullscreen = 0;
galaktos_glx_init( p_thread );
galaktos_init( p_thread );
p_thread->i_channels = aout_FormatNbChannels( &p_filter->input );
......@@ -199,10 +202,9 @@ static void Thread( vlc_object_t *p_this )
int timed=0;
int timestart=0;
int mspf=0;
int w = 600, h = 600;
galaktos_glx_activate_window( p_thread );
setup_opengl( w, h );
setup_opengl( p_thread->i_width, p_thread->i_height );
CreateRenderTarget(512, &RenderTargetTextureID, NULL);
timestart=mdate()/1000;
......
......@@ -35,9 +35,15 @@ typedef struct
char *psz_title;
/* Window properties */
int i_width;
int i_height;
int b_fullscreen;
/* Audio properties */
int i_channels;
/* Audio buffer */
int16_t p_data[2][512];
int i_cur_sample;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment