Which functions go with which targets in OpenGL / WebGL? - opengl-es

My apologies if I am phrasing this question poorly.
Is there anywhere I can find a list of OpenGL/WebGL functions along with the targets they are associated with? For example, in order to call glDrawElements(), a buffer must be bound to the GL_ELEMENT_ARRAY_BUFFER target. And to call glBufferData(), a buffer must be bound to one of several targets, including GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, GL_UNIFORM_BUFFER, etc...
An alternative way to approach this question would be, Is there a list of targets with the functions they enable?
I've downloaded the OpenGL 3.0 ES documentation files and I am pretty confident that all the information I need is contained there. But it is spread across ~280 files and I know I'm going to miss a lot of instances. I must be overlooking something because this seems like such an important aspect of OpenGL when trying to grasp the concept of "targets".

After waiting a while, I've decided to submit an answer to my own question using information I came up with from recursively grepping the reference manual.
This must surely be a partial list. Probably some mistakes. Please feel free to edit and correct if you spot any omissions or mistakes.
If anyone can submit a better, more accurate answer, I will gladly accept it with thanks.
Functions by target:
Target
Functions
ARRAY_BUFFER
bindBuffer, bufferData, bufferSubData, copyBufferSubData, getBufferParameter, vertexAttribPointer
COPY_READ_BUFFER
bindBuffer, bufferData, bufferSubData, copyBufferSubData, getBufferParameter
COPY_WRITE_BUFFER
bindBuffer, bufferData, bufferSubData, copyBufferSubData, getBufferParameter
ELEMENT_ARRAY_BUFFER
bindBuffer, bufferData, bufferSubData, copyBufferSubData, getBufferParameter, drawElements, drawElementsInstanced, drawRangeElements
PIXEL_PACK_BUFFER
bindBuffer, bufferData, bufferSubData, copyBufferSubData, getBufferParameter, readPixels
PIXEL_UNPACK_BUFFER
bindBuffer, bufferData, bufferSubData, copyBufferSubData, getBufferParameter, compressedTexImage2D, compressedTexImage3D, compressedTexSubImage2D, compressedTexSubImage3D, texImage2D, texImage3D, texSubImage2D, texSubImage3D
TRANSFORM_FEEDBACK_BUFFER
bindBuffer, bufferData, bufferSubData, copyBufferSubData, getBufferParameter, bindBufferBase, bindBufferRange
UNIFORM_BUFFER
bindBuffer, bufferData, bufferSubData, copyBufferSubData, getBufferParameter, bindBufferBase, bindBufferRange
TEXTURE_2D
compressedTexImage2D, compressedTexSubImage2D, texImage2D, texSubImage2D, framebufferTexture2D, bindTexture, copyTexImage2D, copyTexSubImage2D, generateMipmap, getTexParameter, texStorage2D
TEXTURE_3D
compressedTexImage3D, compressedTexSubImage3D, texImage3D, texSubImage3D, bindTexture, generateMipmap, getTexParameter, copyTexSubImage3D, texStorage3D
TEXTURE_2D_ARRAY
compressedTexImage3D, compressedTexSubImage3D, texImage3D, texSubImage3D, bindTexture, generateMipmap, getTexParameter, copyTexSubImage3D, texStorage3D
TEXTURE_CUBE_MAP
texImage2D, bindTexture, generateMipmap, getTexParameter, texStorage2D
GL_FRAMEBUFFER
framebufferTexture2D
READ_FRAMEBUFFER
framebufferTexture2D, bindFramebuffer, checkFramebufferStatus, framebufferRenderbuffer, framebufferTextureLayer, invalidateFramebuffer, invalidateSubFramebuffer
DRAW_FRAMEBUFFER
framebufferTexture2D, bindFramebuffer, checkFramebufferStatus, framebufferRenderbuffer, framebufferTextureLayer, invalidateFramebuffer, invalidateSubFramebuffer
RENDERBUFFER
framebufferRenderbuffer, bindRenderbuffer, renderbufferStorage, renderbufferStorageMultisample
TRANSFORM_FEEDBACK
bindTransformFeedback
Targets by function
Function
Targets
bindBuffer
ARRAY_BUFFER, COPY_READ_BUFFER, COPY_WRITE_BUFFER, ELEMENT_ARRAY_BUFFER, PIXEL_PACK_BUFFER, PIXEL_UNPACK_BUFFER, TRANSFORM_FEEDBACK_BUFFER, UNIFORM_BUFFER
bindBufferBase
TRANSFORM_FEEDBACK_BUFFER, UNIFORM_BUFFER
bindBufferRange
TRANSFORM_FEEDBACK_BUFFER, UNIFORM_BUFFER
bindFramebuffer
READ_FRAMEBUFFER, DRAW_FRAMEBUFFER
bindRenderbuffer
RENDERBUFFER
bindTexture
TEXTURE_2D, TEXTURE_3D, TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP
bindTransformFeedback
TRANSFORM_FEEDBACK
bufferData
ARRAY_BUFFER, COPY_READ_BUFFER, COPY_WRITE_BUFFER, ELEMENT_ARRAY_BUFFER, PIXEL_PACK_BUFFER, PIXEL_UNPACK_BUFFER, TRANSFORM_FEEDBACK_BUFFER, UNIFORM_BUFFER
bufferSubData
ARRAY_BUFFER, COPY_READ_BUFFER, COPY_WRITE_BUFFER, ELEMENT_ARRAY_BUFFER, PIXEL_PACK_BUFFER, PIXEL_UNPACK_BUFFER, TRANSFORM_FEEDBACK_BUFFER, UNIFORM_BUFFER
checkFramebufferStatus
READ_FRAMEBUFFER, DRAW_FRAMEBUFFER
compressedTexImage2D
PIXEL_UNPACK_BUFFER, TEXTURE_2D
compressedTexImage3D
PIXEL_UNPACK_BUFFER, TEXTURE_3D, TEXTURE_2D_ARRAY
compressedTexSubImage2D
PIXEL_UNPACK_BUFFER, TEXTURE_2D
compressedTexSubImage3D
PIXEL_UNPACK_BUFFER, TEXTURE_3D, TEXTURE_2D_ARRAY
copyBufferSubData
ARRAY_BUFFER, COPY_READ_BUFFER, COPY_WRITE_BUFFER, ELEMENT_ARRAY_BUFFER, PIXEL_PACK_BUFFER, PIXEL_UNPACK_BUFFER, TRANSFORM_FEEDBACK_BUFFER, UNIFORM_BUFFER
copyTexImage2D
TEXTURE_2D
copyTexSubImage2D
TEXTURE_2D
copyTexSubImage3D
TEXTURE_3D, TEXTURE_2D_ARRAY
drawElements
ELEMENT_ARRAY_BUFFER
drawElementsInstanced
ELEMENT_ARRAY_BUFFER
drawRangeElements
ELEMENT_ARRAY_BUFFER
framebufferRenderbuffer
READ_FRAMEBUFFER, DRAW_FRAMEBUFFER, RENDERBUFFER
framebufferTexture2D
GL_FRAMEBUFFER, READ_FRAMEBUFFER, DRAW_FRAMEBUFFER, TEXTURE_2D
framebufferTextureLayer
READ_FRAMEBUFFER, DRAW_FRAMEBUFFER
generateMipmap
TEXTURE_2D, TEXTURE_3D, TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP
getBufferParameter
ARRAY_BUFFER, COPY_READ_BUFFER, COPY_WRITE_BUFFER, ELEMENT_ARRAY_BUFFER, PIXEL_PACK_BUFFER, PIXEL_UNPACK_BUFFER, TRANSFORM_FEEDBACK_BUFFER, UNIFORM_BUFFER
getTexParameter
TEXTURE_2D, TEXTURE_3D, TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP
invalidateFramebuffer
READ_FRAMEBUFFER, DRAW_FRAMEBUFFER
invalidateSubFramebuffer
READ_FRAMEBUFFER, DRAW_FRAMEBUFFER
readPixels
PIXEL_PACK_BUFFER
renderbufferStorage
RENDERBUFFER
renderbufferStorageMultisample
RENDERBUFFER
texImage2D
PIXEL_UNPACK_BUFFER, TEXTURE_2D, TEXTURE_CUBE_MAP
texImage3D
PIXEL_UNPACK_BUFFER, TEXTURE_3D, TEXTURE_2D_ARRAY
texStorage2D
TEXTURE_2D, TEXTURE_CUBE_MAP
texStorage3D
TEXTURE_3D, TEXTURE_2D_ARRAY
texSubImage2D
PIXEL_UNPACK_BUFFER, TEXTURE_2D
texSubImage3D
PIXEL_UNPACK_BUFFER, TEXTURE_3D, TEXTURE_2D_ARRAY
vertexAttribPointer
ARRAY_BUFFER
Finally, these are all of the functions you call that do not require a target as an argument (i.e. a function that will throw if you haven't bound some object to some target):
vertexAttribPointer
drawElements
drawElementsInstanced
drawRangeElements
readPixels

Related

Does SceneKit work any more in macOS Catalyst apps?

I installed macOS Catalina Beta 6 and Xcode 11 Beta 6, and our SceneKit-based Catalyst app has completely stopped displaying nodes. It logs errors for most/all geometries. Does anyone know if there is a solution or workaround? Did I install Xcode wrong somehow?
2019-08-20 11:26:46.052986-0700 App[16236:879002] [SceneKit] Error: Compiler error while building render pipeline state for node <C3DNode:0x1021219a0 "Cube"
geometry: <C3DParametricGeometry<Box>:0x102121ad0 "box"
mesh: <C3DMesh 0x600003b27800 "(null)"
element0: <C3DMeshElement 0x600003b271e0 type:triangles primCount:12 channels:1 indexBytes:2 offset:0 acmr:2.000000 inst:1 dataSize:72 shared:0x0>
source position (channel:0) : <C3DMeshSource 0x6000029597a0(position) data:(0x600000d3d830) mut:0 count:24 type:float3 divisor:0 mtl:0 offset:0 stride:32>
source normal (channel:0) : <C3DMeshSource 0x600002959960(normal) data:(0x600000d3d830) mut:0 count:24 type:float3 divisor:0 mtl:0 offset:12 stride:32>
source texcoord (channel:0) : <C3DMeshSource 0x6000029598f0(texcoord) data:(0x600000d3d830) mut:0 count:24 type:float2 divisor:0 mtl:0 offset:24 stride:32>
renderable element0: <C3DMeshElement 0x600003b271e0 type:triangles primCount:12 channels:1 indexBytes:2 offset:0 acmr:2.000000 inst:1 dataSize:72 shared:0x0>
renderable source position: <C3DMeshSource 0x6000029597a0(position) data:(0x600000d3d830) mut:0 count:24 type:float3 divisor:0 mtl:0 offset:0 stride:32>
renderable source normal: <C3DMeshSource 0x600002959960(normal) data:(0x600000d3d830) mut:0 count:24 type:float3 divisor:0 mtl:0 offset:12 stride:32>
renderable source texcoord: <C3DMeshSource 0x6000029598f0(texcoord) data:(0x600000d3d830) mut:0 count:24 type:float2 divisor:0 mtl:0 offset:24 stride:32>
>
mat0: >
>
This is due to a Metal compiler issue in macOS Catalina 10.15 Beta 6.
It should be fixed in a future beta version.

Pitch transpose with AudioToolbox AudioUnit samplerUnit

This "Pitch Transposing" test code is not working with AudioUnit samplerUnit.
Sending the same MIDI messages thru MIDI Out to an external sound module, it works perfect. What do I wrong. I can't use "Pitch Bend" for this case. Is the controller "0x06" eventually not implemented in the API?
- (void) demoTranspose {
[at0 setInstrument :0x11 :0x00];
[at0 midiEvent :0xB0 :0x65 :0x00];
[at0 midiEvent :0xB0 :0x64 :0x02];
[at0 midiEvent :0x90 :0x3C :0x7F]; // Note ON
usleep(1000000);
[at0 midiEvent :0xB0 :0x06 :0x40+6]; // 40: center, +6 semi tones higher
usleep(1000000);
[at0 midiEvent :0xB0 :0x06 :0x40+12]; // 40: center, +12 semi tones higher
usleep(1000000);
[at0 midiEvent :0x90 :0x3C :0x00]; // Note OFF
[at0 midiEvent :0xB0 :0x06 :0x40]; // reset to center
}
- (void) midiEvent :(Byte)statusInfoA :(Byte)param1A :(Byte)param2A {
MusicDeviceMIDIEvent (self.samplerUnit, statusInfoA, param1A, param2A, 0);
}

Use of \tikzexternalize

I want to improve compiling speed of my latex thesis. I have read that using \tikzexternalize, only when there is a change in the tikz codes they are compiled.
The problem is that I can no use \tikzexternalize properly. This is my preamble:
\usepackage{circuitikz}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shadows, calc,positioning}
\tikzexternalize
And this is not working at all. I received next error:
Undefined control sequence. \tikzexternalize
If it is useful, I am using MikTex with TextStudio and TextLive with Textstudio also under Ubuntu. It doesn't work in any of these system.
Hope you can help me.
Didn't you forget to add
\usetikzlibrary{external}
? I just found it here : tex.stackexchange
I have done it.
Now I don't have any error messages, but no figures are saved into TikzFigures folder. This is my preamble:
\usepackage{circuitikz}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, shadows, calc,positioning,external}
\tikzexternalize[mode=graphics if exists,
figure list=true,
prefix=TikzFigures/]
This is how I add my tikz figures. First example is by using circuitikz.
\begin{figure}[h]
\centering
\tikzsetnextfilename{nonInverter}
\begin{circuitikz}[scale=1]\draw
(4,.5) node [op amp](opamp) {} % Amplificador Operacional
(0,0) node [ ground]{} to (0,1)
to [R=$Sensor A201$,-*] (opamp.-)
(opamp.out)|- (5,2.5) to [R=$R_{F}$](2.8,2.5) to (opamp.-)
(opamp.+) to [short,-o] (2.8,-1) node [right] {$V_{+}$}
(opamp.out) to [short, *-o] (6,.5) node[right] {$V_{ADC}$}
;\end{circuitikz}
\end{figure}
Next one, is by using the common tikz package:
\begin{figure}[h]
\begin{center}
\tikzsetnextfilename{masterFlowChart}
\begin{tikzpicture}[node distance = 2cm, auto]
% Colocamos los nodos
\node [cloud] (init) {Initialize System};
\node [block, below of=init] (connection) {Connection to the master};
\node [block, below of=connection] (wait) {Wait for master events};
\node [block, below of=wait] (measure) {Measure and send to master};
% invisible node helpful later
\node[right of=wait,scale=0.05](inv){};
% Colocamos las relaciones entre nodos
\path [line] (init) -- (connection);
\path [line] (connection) edge[loop left] node {No Network}();
\path [line] (connection) -- (wait);
\path[-,draw] (wait) -| node{} (inv.north);
\path[line]{} (inv.north) |- node[above]{Reconnect} (connection);
\path [line] (wait) edge[loop left] node {Sleep}();
\path [line] (wait) -- (measure);
\path [line] (measure) -- (wait);
\end{tikzpicture}
\end{center}
\label{fig:slave_flowchart}
\end{figure}
And last one is by using sequencediagram package, that if I am not wrong is also based on tikz.
\begin{figure}[h]
\begin{center}
\tikzsetnextfilename{sequenceDiagramaECnsole10}
\begin{sequencediagram}
\newthread{pc}{PC}
\newinst[2]{master}{Master}
\newinst[2]{slave}{Slave}{}
\node[below right of=master,font=\scriptsize](master_state){Idle};
\node[below right of=slave,font=\scriptsize](slave_state){Sleep};
\begin{sdblock}{Run Loop}{}
\begin{call}{pc}{Start Measurement}{master}{Master Data}
\begin{call}{master}{Data Request}{slave}{Slave Data}
\end{call}
\end{call}
\end{sdblock}
\node[below of=master_state,font=\scriptsize, node distance= 4cm]{Idle};
\node[below of=slave_state,font=\scriptsize, node distance= 4cm]{Sleep};
\end{sequencediagram}
\end{center}
\label{fig:ecnsole_sequence_diagram}
\end{figure}

Fiji (is just ImageJ) memory issue

Just a bit of background:
I have created a Fiji (is just ImageJ) macro that takes a folder of scanned images (of 6mm plates aligned in a 3 * 4 fashion) Identifies these ROI's (the plates) and separates them into individual images. These single images are then compared for difference image analysis and the results stored as excel spreadsheets. This is designed to be activated at the end of the day and be left overnight to process.
My issue is that the Fiji's memory slowly fills then throws an error, stopping the program. I have garbage collection in my code but it never fully clears the memory which is why is slowly fills to capacity.
I would really like this to work on most machines (so buying more RAM isnt really an option) I have on my current testing machine 8GB of RAM and 3/4 of that allocated to FIJI.
Below is the code where i believe the issue lies. (this is the last step of the macro where the individual images are compared) Any help is much appreciated :)
function jakero(startdir, enddir){
path = getFileList(startdir);
for(i=0; i<path.length; i++){
open(startdir+path[i]);
print(path[i]);
if(i%2){
run("Images to Stack", "name=stack1 title=[] use");
wait(1000);
//create the image difference between the sequential scans
selectWindow("stack1");
run("Image Stabilizer", "transformation=Affine maximum_pyramid_levels=4 template_update_coefficient=0.90 maximum_iterations=20000 error_tolerance=0.0000001");
run("Collect Garbage");
run("Z Project...", "start=1 stop=2 projection=[Max Intensity]");
imageCalculator("Difference create", "stack1","MAX_stack1");
selectWindow("MAX_stack1");
wait(2000);
run("Close");
run("Collect Garbage");
wait(100);
selectWindow("Result of stack1");
wait(2000);
run("Gaussian Blur...", "sigma=2 stack");
wait(2000);
//for tif was 5000 3500
run("Hysteresis...", "high=30 low=10");
wait(8000);
selectWindow("Result of stack1");
wait(100);
run("Close");
wait(100);
selectWindow("Hysteresis");
wait(100);
rename("Result of stack1");
wait(100);
run("Invert");
wait(2000);
run("Properties...", "channels=1 slices=1 frames=1 unit=mm pixel_width=0.0105834 pixel_height=0.0105834 voxel_depth=25.4000508 frame=[0 sec] origin=0,0");
wait(2000);
run("Analyze Particles...", "size=0.005-0.8 circularity=0.08-0.8 show=Nothing display exclude clear add");
selectWindow("stack1");
run("Select All");
roiManager("Combine");
//saveAs("Tiff", enddir);
selectWindow("Result of stack1");
close();
run("Collect Garbage");
close();
run("Collect Garbage");
fileName = split(path[i-1],".");
saveAs("Results", ""+enddir+""+fileName[0]+".xls");
k=1;
for (k=1; k<=5; k++) {
run("Collect Garbage");
call("CollectGarbage_.registerCloseListener");
};
}
}
}

What is the difference between creating a buffer object with clCreateBuffer + CL_MEM_COPY_HOST_PTR vs. clCreateBuffer + clEnqueueWriteBuffer?

I have seen both versions in tutorials, but I could not find out, what their advantages and disadvantages are. Which one is the proper one?
cl_mem input = clCreateBuffer(context,CL_MEM_READ_ONLY,sizeof(float) * DATA_SIZE, NULL, NULL);
clEnqueueWriteBuffer(command_queue, input, CL_TRUE, 0, sizeof(float) * DATA_SIZE, inputdata, 0, NULL, NULL);
vs.
cl_mem input = clCreateBuffer(context,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, ,sizeof(float) * DATA_SIZE, inputdata, NULL);
Thanks.
[Update]
I added CL_MEM_COPY_HOST_PTR, to the second example to make it correct.
During my working with OpenCL I found a very important difference between
cl_mem CT = clCreateImage3DContext, CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR , Volume_format, X, Y, Z, rowPitch, slicePitch, sourceData, &error);
and
cl_mem CT = clCreateImage3D(Context, CL_MEM_READ_ONLY , Volume_format, X, Y, Z, 0, 0, 0, &error);
error = clEnqueueWriteImage(CommandQue, CT, CL_TRUE, origin, region, rowPitch, slicePitch, sourceData, 0, 0, 0);
For the first approach OpenCL will copy the host pointer not direct to the GPU. First it will allocate a second temporary buffer on the host which can cause problems if you load big stuff like a CT to the GPU. For a short time the needed memory is twice the CT size. Also the data is not copied during this function. It is copied during the argument setting to the kernel function which uses the 3D image object.
The second approach direct copies the data to the GPU. There are no additional allocations done by OpenCL. I think this is probably the same for normal buffer objects.
I assume that inputdata is not NULL.
In that case the second approach should not work at all, since the specifications says, that clCreateBuffer returns NULL and an error, if:
CL_INVALID_HOST_PTR if host_ptr is NULL and CL_MEM_USE_HOST_PTR or CL_MEM_COPY_HOST_PTR are set in flags or if host_ptr is not NULL but CL_MEM_COPY_HOST_PTR or CL_MEM_USE_HOST_PTR are not set in flags.
so you mean either
clCreateBuffer(context,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,sizeof(float) * DATA_SIZE, inputdata, NULL);
or
clCreateBuffer(context,CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR,sizeof(float) * DATA_SIZE, inputdata, NULL);
The first one should be more or less the same as the first approach you showed, while the second one won't actually copy the data, but instead use the supplied memory location for buffer storage (caching portions or all of it in device memory). Which of those two is better depends on the usage scenario obviously.
Personaly I prefer using the two step approach of first allocating the buffer and afterwards filling it with a writeToBuffer, since I find it easier to see what happens (of course one step might be faster (or it might not, thats just a guess))
The nice aspect of the first approach, is that "clEnqueueWriteBuffer" allows you to assign an event to the copy of a buffer. So, let's say you want to measure the time it takes to copy data to the GPU using the GPU_Profiling options, you will be able to do so with the first approach, but not with the second one.
The second approach is more compact, easier to read, and requires less lines to code.
One major difference that I've run into:
cl_mem input = clCreateBuffer(context,CL_MEM_READ_ONLY,sizeof(float) * DATA_SIZE, NULL, NULL);
clEnqueueWriteBuffer(command_queue, input, CL_TRUE, 0, sizeof(float) * DATA_SIZE, inputdata, 0, NULL, NULL);
This first set of commands will create an empty buffer and enqueue a command in your command queue to fill the buffer.
cl_mem input = clCreateBuffer(context,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR, ,sizeof(float) * DATA_SIZE, inputdata, NULL)
This second command will create the buffer and fill it immediately. Note that there's no command queue in this argument list, so it uses the contents of input data as it is right now.
If you've already been running CL code and your source pointer is dependent upon a previous command in the command queue completing (e.g. an enqueued read of a prior output buffer), you definitely want to use the 1st method. If you try to create and fill the buffer in a single command, you'll end up with a race condition in which the buffer contents will not properly wait on the completion of your prior buffer read.
Well the main difference between these two is that the first one allocates memory on the device and then copies data to that memory. The second one only allocates.
Or did you mean clCreateBuffer(context,CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR,sizeof(float) * DATA_SIZE, inputdata, NULL);?

Resources