I’m trying to us the Unified Buffer Object gl::UboRef and to me, it looks incredibly simple, but I’ve been log jammed on this for hours.
I’m trying to setup a vector of a struct containing camera matrices… something like…
struct CameraParams {
mat4 camMats;
mat4 camprogmat;
mat4 camviewmat;
} ;
I declare my UboRef and a vector of Parameters in a utility class.
class utility_class(){
gl::UboRef mCameraParamsUbo;
std::vector<CameraParams > mCameraParams;
void updateParams(ci::CameraStereo *stcam);
}
Then I set it up…
utility_class::utility_class(){
blah blah blah
mCameraParams.resize(2);
mCameraParamsUbo = gl::Ubo::create(sizeof(CameraParams)*mCameraParams.size(), mCameraParams.data());
mCameraParamsUbo->bindBufferBase(UBO_CAM);
}
And update the Ubo with a function…
void utility_class::updateParams(ci::CameraStereo *stcam){
//update mCameraParams
mCameraParamsUbo->bufferSubData(0, sizeof(CameraParams) * mCameraParams.size(), mCameraParams.getData() );
}
in my shader in the geometry pass…
struct CameraParams{
mat4 camMats;
mat4 camprogmat;
mat4 camviewmat;
};
layout (std140) uniform CameraParam {
CameraParams uCameraParams[2];
};
main(){
//blah blah blah
gl_Position = uCameraParams[ gl_InvocationID ].camprogmat * uCameraParams[ gl_InvocationID ].camviewmat * gl_in[i].gl_Position;
}
and finally I have another class that builds a GlslProgRef and binds the Ubo bind location…
mGlslProgRef->uniformBlock("CameraParam", UBO_CAM);
I’m getting a proper read out when I print the Ubo info…
ActiveUniformBlocks
ub.getName() CameraParam
ub.getBlockBinding() 0
ub.getLocation() 0
ub.getDataSize() 384
ActiveUniforms size: 6
name: uCameraParams[0].camMats
name: uCameraParams[0].camprogmat
name: uCameraParams[0].camviewmat
name: uCameraParams[1].camMats
name: uCameraParams[1].camprogmat
name: uCameraParams[1].camviewmat
But I’m getting a blank screen… I know the mCameraParams are right because they were working as regular uniforms… but as a Ubo, I’m getting nothing. Something to do with bufferSubData maybe? Is there an order or scope that I’m missing?