JOCL v2.6.0-rc-20250722
JOCL, OpenCL® API Binding for Java™ (public API).
CLGLTexture2d.java
Go to the documentation of this file.
1/*
2 * Copyright 2009 - 2010 JogAmp Community. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification, are
5 * permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 *
24 * The views and conclusions contained in the software and documentation are those of the
25 * authors and should not be interpreted as representing official policies, either expressed
26 * or implied, of JogAmp Community.
27 */
28
29package com.jogamp.opencl.gl;
30
31import com.jogamp.opencl.llb.CL;
32import com.jogamp.opencl.CLContext;
33import com.jogamp.opencl.CLException;
34import com.jogamp.opencl.CLImageFormat;
35import com.jogamp.opencl.llb.impl.CLImageFormatImpl;
36
37import java.nio.Buffer;
38
39/**
40 * 2D OpenCL image representing an 2D OpenGL texture.
41 * @author Michael Bien, et.al.
42 */
43public class CLGLTexture2d<B extends Buffer> extends CLGLImage2d<B> implements CLGLTexture {
44
45 public final int target;
46
47 public final int mipMapLevel;
48
49 public CLGLTexture2d(final CLContext context, final B directBuffer, final CLImageFormat format, final CLImageInfoAccessor accessor, final int target, final int mipLevel, final int width, final int height, final long id, final int glid, final int flags) {
50 super(context, directBuffer, format, accessor, width, height, id, glid, flags);
51 this.target = target;
52 this.mipMapLevel = mipLevel;
53 }
54
55 static <B extends Buffer> CLGLTexture2d<B> createFromGLTexture2d(final CLContext context, final B directBuffer, final int target, final int texture, final int mipLevel, final int flags) {
56
57 CLGLBuffer.checkBuffer(directBuffer, flags);
58
59 final CL cl = getCL(context);
60 final int[] result = new int[1];
61
62 final long id = cl.clCreateFromGLTexture2D(context.ID, flags, target, mipLevel, texture, result, 0);
63 CLException.checkForError(result[0], "can not create CLGLTexture2d from texture #"+texture+".");
64
65 final CLImageInfoAccessor accessor = new CLImageInfoAccessor(cl, id);
66
67 final CLImageFormat format = createUninitializedImageFormat();
68 accessor.getInfo(CL.CL_IMAGE_FORMAT, CLImageFormatImpl.size(), format.getFormatImpl().getBuffer(), null);
69
70 final int width = (int)accessor.getLong(CL.CL_IMAGE_WIDTH);
71 final int height = (int)accessor.getLong(CL.CL_IMAGE_HEIGHT);
72
73 return new CLGLTexture2d<B>(context, directBuffer, format, accessor, target, mipLevel, width, height, id, texture, flags);
74
75 }
76
77 @Override
78 public int getTextureTarget() {
79 return target;
80 }
81
82 @Override
83 public int getMipMapLevel() {
84 return mipMapLevel;
85 }
86
87 @Override
90 }
91
92
93}
CLContext is responsible for managing objects such as command-queues, memory, program and kernel obje...
Definition: CLContext.java:79
Main Exception type for runtime OpenCL errors and failed function calls (e.g.
static void checkForError(final int status, final String message)
Throws a CLException when status != CL_SUCCESS.
Represents the OpenCL image format with its channeltype and order.
CLImageFormatImpl getFormatImpl()
Returns the struct accessor for the cl_image_format struct.
final long ID
The OpenCL object handle.
Definition: CLObject.java:41
Shared buffer between OpenGL and OpenCL contexts.
Definition: CLGLBuffer.java:45
2D OpenCL image representing an OpenGL renderbuffer.
2D OpenCL image representing an 2D OpenGL texture.
GLObjectType getGLObjectType()
Returns the OpenGL buffer type of this shared object.
CLGLTexture2d(final CLContext context, final B directBuffer, final CLImageFormat format, final CLImageInfoAccessor accessor, final int target, final int mipLevel, final int width, final int height, final long id, final int glid, final int flags)
Struct accessor for cl_image_format.
final java.nio.ByteBuffer getBuffer()
Return the underlying native direct ByteBuffer.
static int size()
Returns the aligned total size of a native instance.
Java bindings to OpenCL, the Open Computing Language.
Definition: CL.java:26
static final int CL_IMAGE_FORMAT
Define "CL_IMAGE_FORMAT" with expression '0x1110', CType: int.
Definition: CL.java:333
static final int CL_IMAGE_HEIGHT
Define "CL_IMAGE_HEIGHT" with expression '0x1115', CType: int.
Definition: CL.java:61
static final int CL_IMAGE_WIDTH
Define "CL_IMAGE_WIDTH" with expression '0x1114', CType: int.
Definition: CL.java:619
long clCreateFromGLTexture2D(long context, long flags, int target, int miplevel, int texture, IntBuffer errcode_ret)
Interface to C language function: cl_mem {@native clCreateFromGLTexture2D}(cl_context context,...