PDA

View Full Version : Why won't a simple tri-quad render with NV Token Buffers?



mrMatrix
05-23-2016, 05:22 AM
I'm attempting to use token buffers to draw according to the NV basic-nvcommandlist example (https://github.com/nvpro-samples/gl_commandlist_basic). I've been unable to merge it into my own code and render anything other than the default BG color. I've removed the code for sending VBO and UBO buffers and now I'm only trying to send a hardcoded screen aligned triangle quad with a green color. With traditional GL this will produce the expected results. What am I missing?


/* HEADER */
GLuint cmdlist.stateobj_draw;
NVcmdlist cmdlist;

/* MAIN */
//create RGBA fbo with depth stencil (finalN)
//create program pDrawBuffer
//GLuint pDrawBuffer = drawBufferV/F;

/* ---- initCmdListMin() --- */
init_NV_command_list(NVPWindow::sysGetProcAddress) ;
glCreateStatesNV(1, &cmdlist.stateobj_draw);

glGenBuffers(1, &cmdlist.tokenBuffer);
glCreateCommandListsNV(1, &cmdlist.tokenCmdList);
GLenum headerDraw = glGetCommandHeaderNV(GL_DRAW_ARRAYS_COMMAND_NV, sizeof(DrawArraysCommandNV));

//create actual token stream from the scene
{
NVTokenSequence &seq = cmdlist.tokenSequence;
string &stream = cmdlist.tokenData;
size_t offset = 0;

GLuint lastStateObj = 0;
GLuint usedStateobj = cmdlist.stateobj_draw;

DrawArraysCommandNV draw;
draw.header = headerDraw;
draw.first = 0;
draw.count = 4;

nvtokenEnqueue(stream, draw);

lastStateObj = usedStateobj;

seq.offsets.push_back(offset);
seq.sizes.push_back(GLsizei(stream.size() - offset));
seq.fbos.push_back(finalN.fbo1);
seq.states.push_back(lastStateObj);
}

glNamedBufferStorageEXT(cmdlist.tokenBuffer, cmdlist.tokenData.size(), &cmdlist.tokenData[0], 0); //up tokens 1x and then re-use
cmdlist.tokenSequenceList = cmdlist.tokenSequence; //for list gen convert offsets to ptrs

for (unsigned int i = 0; i < cmdlist.tokenSequenceList.offsets.size(); ++i)
cmdlist.tokenSequenceList.offsets[i] += (GLintptr)&cmdlist.tokenData[0];

/* --- updateCommandListStateMinimal() --- */
glUseProgram(pDrawBuffer);
glStateCaptureNV(cmdlist.stateobj_draw, GL_TRIANGLE_STRIP);


//hot loop
do(
glBindFramebuffer(GL_FRAMEBUFFER, finalN.fbo1);
glViewport(0, 0, finalN.width, finalN.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

//////
glDrawCommandsStatesNV(cmdlist.tokenBuffer,
&cmdlist.tokenSequence.offsets[0],
&cmdlist.tokenSequence.sizes[0],
&cmdlist.tokenSequence.states[0],
&cmdlist.tokenSequence.fbos[0],
GLuint(cmdlist.tokenSequence.offsets.size()));

//blit finalN to framebuffer 0
)
while()

/* drawBufferV.glsl */
void main()
{
const vec4 vertices[] = vec4[](
vec4(-1.f, -1.f, 0.f, 1.f),
vec4( 1.f, -1.f, 0.f, 1.f),
vec4(-1.f, 1.f, 0.f, 1.f),
vec4( 1.f, 1.f, 0.f, 1.f));

gl_Position = vertices[gl_VertexID];
}

/* drawBufferF.glsl */
void main()
{
out vec4 Ci;

void main()
{
Ci = vec4(0.f, 1.f, 0.f, 1.f);
}
}