use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class ALC11 method initialize.
/**
* Initializes ALC11, including any extensions
* @return true if initialization was successfull
*/
static boolean initialize() {
try {
IntBuffer ib = BufferUtils.createIntBuffer(2);
ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MAJOR_VERSION, ib);
ib.position(1);
ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MINOR_VERSION, ib);
int major = ib.get(0);
int minor = ib.get(1);
// checking for version 1.x+
if (major >= 1) {
// checking for version 1.1+
if (major > 1 || minor >= 1) {
ALC11.initNativeStubs();
AL11.initNativeStubs();
}
}
} catch (LWJGLException le) {
LWJGLUtil.log("failed to initialize ALC11: " + le);
return false;
}
return true;
}
use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class HelloOpenCL method execute.
protected static void execute() {
try {
CL.create();
final List<CLPlatform> platforms = CLPlatform.getPlatforms();
if (platforms == null)
throw new RuntimeException("No OpenCL platforms found.");
for (CLPlatform platform : platforms) {
System.out.println("\n-------------------------");
System.out.println("NEW PLATFORM: " + platform.getPointer());
System.out.println(CLCapabilities.getPlatformCapabilities(platform));
System.out.println("-------------------------");
printPlatformInfo(platform, "CL_PLATFORM_PROFILE", CL_PLATFORM_PROFILE);
printPlatformInfo(platform, "CL_PLATFORM_VERSION", CL_PLATFORM_VERSION);
printPlatformInfo(platform, "CL_PLATFORM_NAME", CL_PLATFORM_NAME);
printPlatformInfo(platform, "CL_PLATFORM_VENDOR", CL_PLATFORM_VENDOR);
printPlatformInfo(platform, "CL_PLATFORM_EXTENSIONS", CL_PLATFORM_EXTENSIONS);
System.out.println("");
final PointerBuffer ctxProps = BufferUtils.createPointerBuffer(3);
ctxProps.put(CL_CONTEXT_PLATFORM).put(platform.getPointer()).put(0).flip();
final List<CLDevice> devices = platform.getDevices(CL_DEVICE_TYPE_ALL);
for (CLDevice device : devices) {
final CLDeviceCapabilities caps = CLCapabilities.getDeviceCapabilities(device);
System.out.println("\n\tNEW DEVICE: " + device.getPointer());
System.out.println(caps);
System.out.println("\t-------------------------");
System.out.println("\tCL_DEVICE_TYPE = " + device.getInfoLong(CL_DEVICE_TYPE));
System.out.println("\tCL_DEVICE_VENDOR_ID = " + device.getInfoInt(CL_DEVICE_VENDOR_ID));
System.out.println("\tCL_DEVICE_MAX_COMPUTE_UNITS = " + device.getInfoInt(CL_DEVICE_MAX_COMPUTE_UNITS));
System.out.println("\tCL_DEVICE_MAX_WORK_ITEM_DIMENSIONS = " + device.getInfoInt(CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS));
//CL10.clGetDeviceInfo(device, CL10.CL_DEVICE_MAX_WORK_ITEM_SIZES, info, size_ret);
//System.out.println("\tCL_DEVICE_MAX_WORK_ITEM_SIZES = " + info.getInt(0));
System.out.println("\tCL_DEVICE_MAX_WORK_GROUP_SIZE = " + device.getInfoSize(CL_DEVICE_MAX_WORK_GROUP_SIZE));
System.out.println("\tCL_DEVICE_MAX_CLOCK_FREQUENCY = " + device.getInfoInt(CL_DEVICE_MAX_CLOCK_FREQUENCY));
System.out.println("\tCL_DEVICE_ADDRESS_BITS = " + device.getInfoInt(CL_DEVICE_ADDRESS_BITS));
System.out.println("\tCL_DEVICE_AVAILABLE = " + device.getInfoBoolean(CL_DEVICE_AVAILABLE));
System.out.println("\tCL_DEVICE_COMPILER_AVAILABLE = " + device.getInfoBoolean(CL_DEVICE_COMPILER_AVAILABLE));
printDeviceInfo(device, "CL_DEVICE_NAME", CL_DEVICE_NAME);
printDeviceInfo(device, "CL_DEVICE_VENDOR", CL_DEVICE_VENDOR);
printDeviceInfo(device, "CL_DRIVER_VERSION", CL_DRIVER_VERSION);
printDeviceInfo(device, "CL_DEVICE_PROFILE", CL_DEVICE_PROFILE);
printDeviceInfo(device, "CL_DEVICE_VERSION", CL_DEVICE_VERSION);
printDeviceInfo(device, "CL_DEVICE_EXTENSIONS", CL_DEVICE_EXTENSIONS);
if (caps.OpenCL11)
printDeviceInfo(device, "CL_DEVICE_OPENCL_C_VERSION", CL_DEVICE_OPENCL_C_VERSION);
CLContext context = clCreateContext(ctxProps, device, new CLContextCallback() {
protected void handleMessage(final String errinfo, final ByteBuffer private_info) {
System.out.println("IN CLContextCallback :: " + errinfo);
}
}, null);
CLMem buffer = clCreateBuffer(context, CL_MEM_READ_ONLY, 128, null);
if (caps.OpenCL11) {
clSetMemObjectDestructorCallback(buffer, new CLMemObjectDestructorCallback() {
protected void handleMessage(final long memobj) {
System.out.println("FIRST Buffer destructed: " + memobj);
}
});
clSetMemObjectDestructorCallback(buffer, new CLMemObjectDestructorCallback() {
protected void handleMessage(final long memobj) {
System.out.println("SECOND Buffer destructed: " + memobj);
}
});
}
if (caps.OpenCL11) {
CLMem subbuffer = buffer.createSubBuffer(CL_MEM_READ_ONLY, CL_BUFFER_CREATE_TYPE_REGION, new CLBufferRegion(0, 64), null);
clSetMemObjectDestructorCallback(subbuffer, new CLMemObjectDestructorCallback() {
protected void handleMessage(final long memobj) {
System.out.println("Sub Buffer destructed: " + memobj);
}
});
}
clRetainMemObject(buffer);
if (LWJGLUtil.getPlatform() != LWJGLUtil.PLATFORM_MACOSX) {
// TODO: Native kernels crash on MacOSX, disable this until we can debug properly.
final long exec_caps = device.getInfoLong(CL_DEVICE_EXECUTION_CAPABILITIES);
if ((exec_caps & CL_EXEC_NATIVE_KERNEL) == CL_EXEC_NATIVE_KERNEL) {
System.out.println("-TRYING TO EXEC NATIVE KERNEL-");
final CLCommandQueue queue = clCreateCommandQueue(context, device, 0, null);
final PointerBuffer ev = BufferUtils.createPointerBuffer(1);
clEnqueueNativeKernel(queue, new CLNativeKernel() {
protected void execute(final ByteBuffer[] memobjs) {
System.out.println("\tmemobjs.length = " + memobjs.length);
for (int k = 0; k < memobjs.length; k++) {
System.out.println("\tmemobjs[" + k + "].remaining() = " + memobjs[k].remaining());
for (int l = memobjs[k].position(); l < memobjs[k].limit(); l++) {
memobjs[k].put(l, (byte) l);
}
}
System.out.println("\tNative kernel done.");
}
}, new CLMem[] { buffer }, new long[] { 128 }, null, ev);
final CLEvent e = queue.getCLEvent(ev.get(0));
clSetEventCallback(e, CL_COMPLETE, new CLEventCallback() {
protected void handleMessage(final CLEvent event, final int event_command_exec_status) {
System.out.println("\t\tEvent callback status: " + getEventStatusName(event_command_exec_status));
}
});
int status = e.getInfoInt(CL_EVENT_COMMAND_EXECUTION_STATUS);
System.out.println("NATIVE KERNEL STATUS: " + getEventStatusName(status));
clFlush(queue);
do {
int newStatus = e.getInfoInt(CL_EVENT_COMMAND_EXECUTION_STATUS);
if (newStatus != status) {
status = newStatus;
System.out.println("NATIVE KERNEL STATUS: " + getEventStatusName(status));
}
} while (// Busy-spin until we're done
status != CL_SUCCESS);
clReleaseEvent(e);
}
}
clReleaseMemObject(buffer);
clReleaseContext(context);
}
}
} catch (LWJGLException le) {
die("Init", le.getMessage());
}
CL.destroy();
}
use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class LWJGLInfoView method createPartControl.
/**
* {@inheritDoc}
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite i_parent) {
Text info = new Text(i_parent, SWT.READ_ONLY | SWT.LEFT | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
GLCanvas canvas = new GLCanvas(i_parent, SWT.NONE, new GLData());
canvas.setCurrent();
try {
GLContext.useContext(canvas);
} catch (LWJGLException ex) {
// TODO Implement catch block for LWJGLException
ex.printStackTrace();
}
String infoString = gatherInformation();
info.setText(infoString);
}
use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class LWJGLTestView method createPartControl.
/**
* {@inheritDoc}
* @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
*/
@Override
public void createPartControl(Composite parent) {
String strVersion = getFeatureVersion("org.lwjgl");
this.setPartName("org.lwjgl " + strVersion);
IStatusLineManager statusLine = this.getViewSite().getActionBars().getStatusLineManager();
fpsstatuslineitem = new FpsStatusLineItem();
statusLine.add(fpsstatuslineitem);
GLData data = new GLData();
data.doubleBuffer = true;
canvas = new GLCanvas(parent, SWT.NONE, data);
canvas.setCurrent();
try {
GLContext.useContext(canvas);
} catch (LWJGLException e) {
e.printStackTrace();
}
canvas.addListener(SWT.Resize, new Listener() {
public void handleEvent(Event event) {
Rectangle bounds = canvas.getBounds();
float fAspect = (float) bounds.width / (float) bounds.height;
canvas.setCurrent();
try {
GLContext.useContext(canvas);
} catch (LWJGLException e) {
e.printStackTrace();
}
GL11.glViewport(0, 0, bounds.width, bounds.height);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
}
});
GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
GL11.glColor3f(1.0f, 0.0f, 0.0f);
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
GL11.glClearDepth(1.0);
GL11.glLineWidth(2);
GL11.glEnable(GL11.GL_DEPTH_TEST);
Display.getCurrent().asyncExec(initRunnable());
}
use of org.lwjgl.LWJGLException in project lwjgl by LWJGL.
the class DemoBox method initialize.
/**
* @return
*/
public boolean initialize() {
setTitle("LWJGL - Demo Box");
setSize(640, 480);
setLayout(new GridBagLayout());
// Setup selection panel
// =================================
selectionPanel = new Panel();
selectionPanel.setLayout(new BorderLayout());
selectionPanel.add(new Label("Demo", Label.CENTER), BorderLayout.NORTH);
Button fullScreen = new Button("Fullscreen");
fullScreen.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
toggleFullscreen();
}
});
selectionPanel.add(fullScreen, BorderLayout.SOUTH);
final List demos = new List();
for (Enumeration e = selectableDemos.keys(); e.hasMoreElements(); ) {
demos.add(e.nextElement().toString());
}
selectionPanel.add(demos, BorderLayout.CENTER);
demos.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent event) {
demoSelected(event.getItemSelectable().getSelectedObjects()[0].toString());
}
});
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.weightx = 0.05;
gbc.weighty = 1.0;
add(selectionPanel, gbc);
// =================================
try {
demoCanvas = new DemoBoxGLCanvas(this);
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.weightx = 0.95;
gbc.weighty = 1.0;
add(demoCanvas, gbc);
} catch (LWJGLException le) {
le.printStackTrace();
return false;
}
// ---------------------------------
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
demoCanvas.destroyCanvas();
dispose();
System.exit(0);
}
});
//demoSelected(demos.getSelectedItem());
return true;
}
Aggregations