Commit 8f001903 authored by Pierre-Eric Pelloux-Prayer's avatar Pierre-Eric Pelloux-Prayer
Browse files

MacOS: GL video cleanups

parent d92b0ef0
......@@ -8,27 +8,15 @@
#include <OpenGL/glu.h>
#include "opengles_display.h"
static void drawAnObject ()
{
glColor3f(1.0f, 0.85f, 0.35f);
glBegin(GL_TRIANGLES);
{
glVertex3f( 0.0, 0.6, 0.0);
glVertex3f( -0.2, -0.3, 0.0);
glVertex3f( 0.2, -0.3 ,0.0);
}
glEnd();
}
@interface NsMsGLDisplay : NSOpenGLView
{
@public
struct opengles_display* display_helper;
int w, h;
}
- (void) drawRect: (NSRect) bounds;
-(void) reshape;
-(void) resizeWindow: (id) window;
@end
typedef struct GLOSXState {
......@@ -40,33 +28,24 @@ typedef struct GLOSXState {
-(void) reshape {
CGLContextObj obj = CGLGetCurrentContext();
ms_message("Current ctx: %p", obj);
ms_message("Set GL context");
CGLContextObj obj = CGLGetCurrentContext();
NSOpenGLContext* ctx = [self openGLContext];
[ctx makeCurrentContext];
ogl_display_init(display_helper, self.bounds.size.width, self.bounds.size.height);
[NSOpenGLContext clearCurrentContext];
[ctx makeCurrentContext];
ogl_display_init(display_helper, self.bounds.size.width, self.bounds.size.height);
[NSOpenGLContext clearCurrentContext];
}
-(void) drawRect: (NSRect) bounds
{
CGLContextObj obj = CGLGetCurrentContext();
ms_message("Current ctx: %p", obj);
NSOpenGLContext* ctx = [self openGLContext];
[ctx makeCurrentContext];
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
//drawAnObject();
ogl_display_render(display_helper);
glFlush();
[NSOpenGLContext clearCurrentContext];
}
-(void) resizeWindow: (id) window {
if (window == nil)
return;
[window setFrame:NSMakeRect(0, 0, w, h) display:YES];
}
......@@ -74,50 +53,41 @@ ms_message("Current ctx: %p", obj);
#include <OpenGL/CGLRenderers.h>
static void osx_gl_init(MSFilter* f) {
CGLContextObj obj = CGLGetCurrentContext();
ms_message("Current ctx: %p", obj);
GLOSXState* s = (GLOSXState*) ms_new0(GLOSXState, 1);
GLOSXState* s = (GLOSXState*) ms_new0(GLOSXState, 1);
f->data = s;
}
static void init_for_real(GLOSXState* s) {
NSWindow* window = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) styleMask:(NSTitledWindowMask | NSResizableWindowMask | NSClosableWindowMask) backing:NSBackingStoreBuffered defer:NO] autorelease];
[window setBackgroundColor: [NSColor blueColor]];
[window makeKeyAndOrderFront:NSApp];
[window setTitle: @"Mediastreamer"];
[window setMovable:YES];
[window setMovableByWindowBackground:YES];
s->window = [window retain];
NSWindow* window = [[[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 100, 100) styleMask:(NSTitledWindowMask | NSResizableWindowMask | NSClosableWindowMask) backing:NSBackingStoreBuffered defer:NO] autorelease];
[window setBackgroundColor: [NSColor blueColor]];
[window makeKeyAndOrderFront:NSApp];
[window setTitle: @"Video"];
[window setMovable:YES];
[window setMovableByWindowBackground:YES];
s->window = [window retain];
[s->window setReleasedWhenClosed:NO];
NSOpenGLPixelFormatAttribute attrs[] = {
//NSOpenGLPFARendererID, kCGLRendererGenericID,
NSOpenGLPFAAccelerated,
//NSOpenGLPFADoubleBuffer,
//NSOpenGLPFADepthSize, 32,
0
};
NSOpenGLPixelFormat * fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
s->disp = [[NsMsGLDisplay alloc] initWithFrame:[s->window frame] pixelFormat:fmt];
s->disp->display_helper = ogl_display_new();
s->disp->w = 100;
s->disp->h = 100;
NSOpenGLPixelFormat * fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attrs];
s->disp = [[[NsMsGLDisplay alloc] initWithFrame:[s->window frame] pixelFormat:fmt] retain];
s->disp->display_helper = ogl_display_new();
s->disp->w = 100;
s->disp->h = 100;
[s->window setContentView: s->disp];
}
static void osx_gl_preprocess(MSFilter* f) {
init_for_real((GLOSXState*) f->data);
}
static void osx_gl_process(MSFilter* f) {
GLOSXState* s = (GLOSXState*) f->data;
mblk_t* m = 0;
MSPicture pic;
if (!s->window)
init_for_real(s);
if ((m=ms_queue_peek_last(f->inputs[0]))!=NULL){
if (ms_yuv_buf_init_from_mblk (&pic,m)==0){
if (pic.w != s->disp->w || pic.h != s->disp->h) {
......@@ -126,39 +96,40 @@ static void osx_gl_process(MSFilter* f) {
id w = s->window;
[s->disp performSelectorOnMainThread:@selector(resizeWindow:) withObject:w waitUntilDone:NO];
}
ogl_display_set_yuv_to_display(s->disp->display_helper, m);
// ogl_display_set_preview_yuv_to_display(s->disp->display_helper, m);
[s->disp setNeedsDisplay:YES];
ms_queue_remove(f->inputs[0], m);
}
}
ms_queue_flush(f->inputs[0]);
if (f->inputs[1] != NULL) {
if (0 && (m=ms_queue_peek_last(f->inputs[1]))!=NULL){
if ((m=ms_queue_peek_last(f->inputs[1]))!=NULL){
if (ms_yuv_buf_init_from_mblk (&pic,m)==0){
ogl_display_set_preview_yuv_to_display(s->disp->display_helper, m);
[s->disp setNeedsDisplay:YES];
ms_queue_remove(f->inputs[1], m);
}
}
ms_queue_flush(f->inputs[1]);
ms_queue_flush(f->inputs[1]);
}
}
static void osx_gl_uninit(MSFilter* f) {
GLOSXState* s = (GLOSXState*) f->data;
NSLog(@"todo");
return;
if (s->disp) {
[s->disp dealloc];
s->disp = nil;
}
if (s->window) {
[s->window close];
[s->window release];
}
[s->window setContentView: nil];
if (s->disp) {
ogl_display_uninit(s->disp->display_helper, TRUE);
ogl_display_free(s->disp->display_helper);
[s->disp release];
s->disp = nil;
}
[s->window close];
[s->window release];
}
static int osx_gl_set_vsize(MSFilter* f, void* arg) {
......@@ -168,7 +139,7 @@ static int osx_gl_set_vsize(MSFilter* f, void* arg) {
static int osx_gl_get_native_window_id(MSFilter* f, void* arg) {
GLOSXState* s = (GLOSXState*) f->data;
unsigned long *winId=(unsigned long*)arg;
*winId = (unsigned long)0;//s->window;
*winId = (unsigned long)s->window;
return 0;
}
......@@ -204,7 +175,3 @@ MSFilterDesc ms_osx_gl_display_desc = {
};
MS_FILTER_DESC_EXPORT(ms_osx_gl_display_desc);
......@@ -89,7 +89,7 @@ struct opengles_display {
GLint backingHeight;
/* runtime data */
float uvx, uvy;
float uvx[2], uvy[2];
MSVideoSize yuv_size[2];
};
......@@ -228,10 +228,10 @@ static void ogl_display_render_type(struct opengles_display* gldisp, enum ImageT
ms_mutex_unlock(&gldisp->yuv_mutex);
GLfloat squareUvs[] = {
0.0f, gldisp->uvy,
gldisp->uvx, gldisp->uvy,
0.0f, gldisp->uvy[type],
gldisp->uvx[type], gldisp->uvy[type],
0.0f, 0.0f,
gldisp->uvx, 0.0f
gldisp->uvx[type], 0.0f
};
if (clear) {
......@@ -420,8 +420,8 @@ static bool_t update_textures_with_yuv(struct opengles_display* gldisp, enum Ima
aligned_yuv_h != gldisp->allocatedTexturesSize[type].height) {
allocate_gl_textures(gldisp, aligned_yuv_w, aligned_yuv_h, type);
}
gldisp->uvx = yuvbuf.w / (float)(gldisp->allocatedTexturesSize[type].width+1);
gldisp->uvy = yuvbuf.h / (float)(gldisp->allocatedTexturesSize[type].height+1);
gldisp->uvx[type] = yuvbuf.w / (float)(gldisp->allocatedTexturesSize[type].width+1);
gldisp->uvy[type] = yuvbuf.h / (float)(gldisp->allocatedTexturesSize[type].height+1);
/* upload Y plane */
GL_OPERATION(glActiveTexture(GL_TEXTURE0))
......
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