JOCL v2.6.0-rc-20250722
JOCL, OpenCL® API Binding for Java™ (public API).
CLSampler.java
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009 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;
30
31import com.jogamp.common.nio.PointerBuffer;
32import com.jogamp.opencl.impl.CLTLInfoAccessor;
33import com.jogamp.opencl.llb.CL;
34
35import java.nio.Buffer;
36
37import static com.jogamp.opencl.CLException.*;
38import static com.jogamp.opencl.llb.CL.*;
39import static com.jogamp.opencl.util.CLUtil.*;
40
41/**
42 * Object representing an OpenCL sampler.
43 * @see CLContext#createSampler(com.jogamp.opencl.CLSampler.AddressingMode, com.jogamp.opencl.CLSampler.FilteringMode, boolean)
44 * @author Michael Bien, et al.
45 */
46public class CLSampler extends CLObjectResource {
47
48 private final CLSamplerInfoAccessor samplerInfo;
49 private final CL binding;
50
51 private CLSampler(final CLContext context, final long id, final AddressingMode addrMode, final FilteringMode filtMode, final boolean normalizedCoords) {
52 super(context, id);
53 this.binding = context.getPlatform().getCLBinding();
54 this.samplerInfo = new CLSamplerInfoAccessor();
55 }
56
57 static CLSampler create(final CLContext context, final AddressingMode addrMode, final FilteringMode filtMode, final boolean normalizedCoords) {
58 final int[] error = new int[1];
59
60 final CL binding = context.getPlatform().getCLBinding();
61 final long id = binding.clCreateSampler(context.ID, clBoolean(normalizedCoords), addrMode.MODE, filtMode.MODE, error, 0);
62
63 checkForError(error[0], "can not create sampler");
64 return new CLSampler(context, id, addrMode, filtMode, normalizedCoords);
65 }
66
68 final int info = (int)samplerInfo.getLong(CL_SAMPLER_FILTER_MODE);
69 return FilteringMode.valueOf(info);
70 }
71
73 final int info = (int)samplerInfo.getLong(CL_SAMPLER_ADDRESSING_MODE);
74 return AddressingMode.valueOf(info);
75 }
76
77 public boolean hasNormalizedCoords() {
78 return samplerInfo.getLong(CL_SAMPLER_NORMALIZED_COORDS) == CL_TRUE;
79 }
80
81 @Override
82 public void release() {
83 super.release();
84 final int ret = binding.clReleaseSampler(ID);
85 context.onSamplerReleased(this);
86 if(ret != CL_SUCCESS) {
87 throw newException(ret, "can not release "+this);
88 }
89 }
90
91 private class CLSamplerInfoAccessor extends CLTLInfoAccessor {
92
93 @Override
94 protected int getInfo(final int name, final long valueSize, final Buffer value, final PointerBuffer valueSizeRet) {
95 return binding.clGetSamplerInfo(ID, name, valueSize, value, valueSizeRet);
96 }
97
98 }
99
100 public enum FilteringMode {
101
102 NEAREST(CL_FILTER_NEAREST),
103 LINEAR(CL_FILTER_LINEAR);
104
105 /**
106 * Value of wrapped OpenCL sampler filtering mode type.
107 */
108 public final int MODE;
109
110 private FilteringMode(final int mode) {
111 this.MODE = mode;
112 }
113
114 public static FilteringMode valueOf(final int mode) {
115 switch(mode) {
116 case(CL_FILTER_NEAREST):
117 return NEAREST;
118 case(CL_FILTER_LINEAR):
119 return LINEAR;
120 }
121 return null;
122 }
123 }
124
125 public enum AddressingMode {
126
127 REPEAT(CL_ADDRESS_REPEAT),
128 CLAMP_TO_EDGE(CL_ADDRESS_CLAMP_TO_EDGE),
129 CLAMP(CL_ADDRESS_CLAMP),
130 NONE(CL_ADDRESS_NONE);
131
132 /**
133 * Value of wrapped OpenCL sampler addressing mode type.
134 */
135 public final int MODE;
136
137 private AddressingMode(final int mode) {
138 this.MODE = mode;
139 }
140
141 public static AddressingMode valueOf(final int mode) {
142 switch(mode) {
143 case(CL_ADDRESS_REPEAT):
144 return REPEAT;
145 case(CL_ADDRESS_CLAMP_TO_EDGE):
146 return CLAMP_TO_EDGE;
147 case(CL_ADDRESS_CLAMP):
148 return CLAMP;
149 case(CL_ADDRESS_NONE):
150 return NONE;
151 }
152 return null;
153 }
154 }
155
156}
CLContext is responsible for managing objects such as command-queues, memory, program and kernel obje...
Definition: CLContext.java:79
CLPlatform getPlatform()
Returns the CLPlatform this context is running on.
Definition: CLContext.java:569
final long ID
The OpenCL object handle.
Definition: CLObject.java:41
Object representing an OpenCL sampler.
Definition: CLSampler.java:46
AddressingMode getAddressingMode()
Definition: CLSampler.java:72
void release()
Releases the OpenCL resource.
Definition: CLSampler.java:82
FilteringMode getFilteringMode()
Definition: CLSampler.java:67
Internal utility for common OpenCL clGetFooInfo calls.
final int MODE
Value of wrapped OpenCL sampler addressing mode type.
Definition: CLSampler.java:135
static AddressingMode valueOf(final int mode)
Definition: CLSampler.java:141
static FilteringMode valueOf(final int mode)
Definition: CLSampler.java:114
final int MODE
Value of wrapped OpenCL sampler filtering mode type.
Definition: CLSampler.java:108
Java bindings to OpenCL, the Open Computing Language.
Definition: CL.java:26
int clReleaseSampler(long sampler)
Interface to C language function: cl_int {@native clReleaseSampler}(cl_sampler sampler)
long clCreateSampler(long context, int normalized_coords, int addressing_mode, int filter_mode, IntBuffer errcode_ret)
Interface to C language function: cl_sampler {@native clCreateSampler}(cl_context context,...
int clGetSamplerInfo(long sampler, int param_name, long param_value_size, Buffer param_value, PointerBuffer param_value_size_ret)
Interface to C language function: cl_int {@native clGetSamplerInfo}(cl_sampler sampler,...