view dwt/internal/cocoa/NSOpenGLContext.d @ 1:8b48be5454ce

The internal cocoa classes compile now
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Tue, 19 Aug 2008 17:35:17 +0200
parents 380af2bdd8e5
children f565d3a95c0a
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *     
 * Port to the D Programming language:
 *     Jacob Carlborg <jacob.carlborg@gmail.com>
 *******************************************************************************/
module dwt.internal.cocoa.NSOpenGLContext;

import dwt.internal.cocoa.gl;
import dwt.internal.cocoa.NSObject;
import dwt.internal.cocoa.NSOpenGLPixelBuffer;
import dwt.internal.cocoa.NSOpenGLPixelFormat;
import dwt.internal.cocoa.NSView;
import dwt.internal.cocoa.OS;
import objc = dwt.internal.objc.runtime;

enum NSOpenGLContextParameter
{
    NSOpenGLCPSwapRectangle = 200,
    NSOpenGLCPSwapRectangleEnable = 201,
    NSOpenGLCPRasterizationEnable = 221,
    NSOpenGLCPSwapInterval = 222,
    NSOpenGLCPSurfaceOrder = 235,
    NSOpenGLCPSurfaceOpacity = 236,
    NSOpenGLCPStateValidation = 301
}

alias NSOpenGLContextParameter.NSOpenGLCPSwapRectangle NSOpenGLCPSwapRectangle;
alias NSOpenGLContextParameter.NSOpenGLCPSwapRectangleEnable NSOpenGLCPSwapRectangleEnable;
alias NSOpenGLContextParameter.NSOpenGLCPRasterizationEnable NSOpenGLCPRasterizationEnable;
alias NSOpenGLContextParameter.NSOpenGLCPSwapInterval NSOpenGLCPSwapInterval;
alias NSOpenGLContextParameter.NSOpenGLCPSurfaceOrder NSOpenGLCPSurfaceOrder;
alias NSOpenGLContextParameter.NSOpenGLCPSurfaceOpacity NSOpenGLCPSurfaceOpacity;
alias NSOpenGLContextParameter.NSOpenGLCPStateValidation NSOpenGLCPStateValidation;

public class NSOpenGLContext : NSObject
{

    public this ()
    {
        super();
    }

    public this (objc.id id)
    {
        super(id);
    }

    public void* CGLContextObj ()
    {
        return cast(void*) OS.objc_msgSend(this.id_, OS.sel_CGLContextObj);
    }

    public static void clearCurrentContext ()
    {
        OS.objc_msgSend(OS.class_NSOpenGLContext, OS.sel_clearCurrentContext);
    }

    public void clearDrawable ()
    {
        OS.objc_msgSend(this.id_, OS.sel_clearDrawable);
    }

    public void copyAttributesFromContext (NSOpenGLContext context, GLbitfield mask)
    {
        OS.objc_msgSend(this.id_, OS.sel_copyAttributesFromContext_1withMask_1, context !is null ? context.id_ : null, mask);
    }

    public void createTexture (GLenum target, NSView view, GLenum format)
    {
        OS.objc_msgSend(this.id_, OS.sel_createTexture_1fromView_1internalFormat_1, target, view !is null ? view.id_ : null, format);
    }

    public static NSOpenGLContext currentContext ()
    {
        objc.id result = OS.objc_msgSend(OS.class_NSOpenGLContext, OS.sel_currentContext);
        return result !is null ? new NSOpenGLContext(result) : null;
    }

    public GLint currentVirtualScreen ()
    {
        return cast(GLint) OS.objc_msgSend(this.id_, OS.sel_currentVirtualScreen);
    }

    public void flushBuffer ()
    {
        OS.objc_msgSend(this.id_, OS.sel_flushBuffer);
    }

    public void getValues (GLint* vals, NSOpenGLContextParameter param)
    {
        OS.objc_msgSend(this.id_, OS.sel_getValues_1forParameter_1, vals, param);
    }

    public NSOpenGLContext initWithFormat (NSOpenGLPixelFormat format, NSOpenGLContext share)
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_initWithFormat_1shareContext_1, format !is null ? format.id_ : null,
                share !is null ? share.id_ : null);
        return result !is null ? this : null;
    }

    public void makeCurrentContext ()
    {
        OS.objc_msgSend(this.id_, OS.sel_makeCurrentContext);
    }

    public NSOpenGLPixelBuffer pixelBuffer ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_pixelBuffer);
        return result !is null ? new NSOpenGLPixelBuffer(result) : null;
    }

    public GLenum pixelBufferCubeMapFace ()
    {
        return cast(GLenum) OS.objc_msgSend(this.id_, OS.sel_pixelBufferCubeMapFace);
    }

    public GLint pixelBufferMipMapLevel ()
    {
        return cast(GLint) OS.objc_msgSend(this.id_, OS.sel_pixelBufferMipMapLevel);
    }

    public void setCurrentVirtualScreen (GLint screen)
    {
        OS.objc_msgSend(this.id_, OS.sel_setCurrentVirtualScreen_1, screen);
    }

    public void setFullScreen ()
    {
        OS.objc_msgSend(this.id_, OS.sel_setFullScreen);
    }

    public void setOffScreen (void* baseaddr, GLsizei width, GLsizei height, GLint rowbytes)
    {
        OS.objc_msgSend(this.id_, OS.sel_setOffScreen_1width_1height_1rowbytes_1, baseaddr, width, height, rowbytes);
    }

    public void setPixelBuffer (NSOpenGLPixelBuffer pixelBuffer, GLenum face, GLint level, GLint screen)
    {
        OS.objc_msgSend(this.id_, OS.sel_setPixelBuffer_1cubeMapFace_1mipMapLevel_1currentVirtualScreen_1,
                pixelBuffer !is null ? pixelBuffer.id_ : null, face, level, screen);
    }

    public void setTextureImageToPixelBuffer (NSOpenGLPixelBuffer pixelBuffer, GLenum source)
    {
        OS.objc_msgSend(this.id_, OS.sel_setTextureImageToPixelBuffer_1colorBuffer_1, pixelBuffer !is null ? pixelBuffer.id_ : null, source);
    }

    public void setValues (/*const*/GLint* vals, NSOpenGLContextParameter param)
    {
        OS.objc_msgSend(this.id_, OS.sel_setValues_1forParameter_1, vals, param);
    }

    public void setView (NSView view)
    {
        OS.objc_msgSend(this.id_, OS.sel_setView_1, view !is null ? view.id_ : null);
    }

    public void update ()
    {
        OS.objc_msgSend(this.id_, OS.sel_update);
    }

    public NSView view ()
    {
        objc.id result = OS.objc_msgSend(this.id_, OS.sel_view);
        return result !is null ? new NSView(result) : null;
    }

}