Is this even possible on AMD hardware? (Radeon Pro WX7100)
"Matlab's opengl info is still only reporting version 3.0 with the open-source amdgpu driver & Radeon Pro WX 7100 though. This seems like its probably a separate issue, so I'll dig a little more to confirm & document, then post a new topic here shortly.-> That's expected. Both PTB and (i assume) jogl want an OpenGL context that is backwards compatible with OpenGL 2.1, so you get the highest OpenGL core version that is backwards compatible. With the Mesa drivers that maximum is 3.0 or 3.1 iirc. This doesn't really matter, as e.g., PTB still uses > OpenGL 3.1 features as needed via the OpenGL extension mechanism. If an app doesn't require backwards compat with GL-2, it gets whatever the maximum supported by hardware + drivers is, ie. up to OpenGL 4.6 atm. PTB only needs OpenGL 2.1 + a few extensions for full functionality. I assume Matlab's plotting doesn't need any more advanced stuff either.-mario"---
Instanced drawing snippet:
%% inputs are xyz positions, dotsz, etc... global structure glB for buffer info storage
% ...code snippet... %
%% Draw as 3D geodesic spheres (soo nice, but needs Linux atm.)
% Dot size gets tacked onto xyz buffer data
xyz(4,:) = dotsz(:);
% Initialize buffers (only once!)
if ~isfield(glB,'glsl')
% Load the speedy shader
shaderpath = {fullfile(glslshader, 'geosphere.vert'), fullfile(glslshader, 'geosphere.frag')};
glB.glsl = LoadGLSLProgramFromFiles(shaderpath,1);
[vv,ff] = glDraw.icosphere(dotType-3);
% convert vv into direct triangles (...would be better if indexed vectors, but whatever)
ff = ff';
vv = 0.5*vv(ff(:),:)'; % expand indexing & convert to unit diameter (size == [3, ntriangles]);
glB.ntris = size(vv,2);
% vertex buffer
% jnk = whos('vv'); glB.vert.mem=jnk.bytes; % gets memory size of var
glB.vert.mem = numel(vv)*4; % will become GL.FLOAT, 4 bytes/el.
glB.vert.h = glGenBuffers(1);
glB.vert.i = 0; % attribute index (must correspond to init order inside shader)
glBindBuffer(GL.ARRAY_BUFFER, glB.vert.h);
glBufferData(GL.ARRAY_BUFFER, glB.vert.mem, single(vv(:)), GL.STATIC_DRAW);
% position buffer: [x, y, z, size]
% Data will stream to this buffer for each frame
%jnk = whos('xyz'); glB.pos.mem = jnk.bytes; % gets memory size of var
glB.pos.mem = numel(xyz)*4; % 4 bytes/el.
glB.pos.h = glGenBuffers(1);
glB.pos.i = 1; % attribute index
glBindBuffer(GL.ARRAY_BUFFER, glB.pos.h);
glBufferData(GL.ARRAY_BUFFER, glB.pos.mem, single(xyz(:)), GL.STREAM_DRAW);
% color buffer: [r, g, b, a]
% Data will stream to this buffer for each frame
% jnk = whos('col'); glB.col.mem = jnk.bytes; % gets memory size of var
glB.col.mem = numel(dotcolor)*4; % 4 bytes/el.
glB.col.h = glGenBuffers(1);
glB.col.i = 2; % attribute index
glBindBuffer(GL.ARRAY_BUFFER, glB.col.h);
glBufferData(GL.ARRAY_BUFFER, glB.col.mem, single(dotcolor(:)), GL.STREAM_DRAW);
else
% Update position buffer (via "orphaning")
glBindBuffer(GL.ARRAY_BUFFER, glB.pos.h);
glBufferData(GL.ARRAY_BUFFER, glB.pos.mem, 0, GL.STREAM_DRAW);
glBufferSubData(GL.ARRAY_BUFFER, 0, glB.pos.mem, single(xyz(:)));
% Update color buffer
glBindBuffer(GL.ARRAY_BUFFER, glB.col.h);
glBufferData(GL.ARRAY_BUFFER, glB.col.mem, 0, GL.STREAM_DRAW);
glBufferSubData(GL.ARRAY_BUFFER, 0, glB.col.mem, single(dotcolor(:)));
end
% Backup old shader binding:
oldShader = glGetIntegerv(GL.CURRENT_PROGRAM);
% Set new one:
glUseProgram(glB.glsl);
% vertex buffer
glEnableVertexAttribArray(glB.vert.i); %(GL attribute index starts at zero)
glBindBuffer(GL.ARRAY_BUFFER, glB.vert.h);
glVertexAttribPointer(glB.vert.i, 3, GL.FLOAT, GL.FALSE, 0, 0);
% pos & size buffer
glEnableVertexAttribArray(glB.pos.i);
glBindBuffer(GL.ARRAY_BUFFER, glB.pos.h);
glVertexAttribPointer(glB.pos.i, 4, GL.FLOAT, GL.FALSE, 0, 0);
% color buffer
glEnableVertexAttribArray(glB.col.i);
glBindBuffer(GL.ARRAY_BUFFER, glB.col.h);
glVertexAttribPointer(glB.col.i, 4, GL.FLOAT, GL.TRUE, 0, 0);
% Assign buffer usage (!!specific to glDrawArrays*Instanced*!!)
% // The first parameter is the attribute buffer #
% // The second parameter is the "rate at which generic vertex attributes advance when rendering multiple instances"
glVertexAttribDivisor(0, 0); % particles vertices : always reuse the same n vertices -> 0
glVertexAttribDivisor(1, 1); % positions : one per element (its center) -> 1
glVertexAttribDivisor(2, 1); % color : one per element -> 1
% % % % % %
% DRAW IT!!
% % % % % %
glDrawArraysInstanced(GL.TRIANGLES, 0, glB.ntris, ndots);
% disable dot attribute buffers & clean up
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
% Reset old shader binding:
glUseProgram(oldShader);