Example #1
0
////////////////////////////////////////////////////////////////////////////////
//
//  Method: BindlessApp::draw()
//
//    Performs the actual rendering
//
////////////////////////////////////////////////////////////////////////////////
void BindlessApp::draw(void)
{
    nv::matrix4f modelviewMatrix;

    glClearColor( 0.5, 0.5, 0.5, 1.0);
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);

    // Enable the vertex and pixel shader
    m_shader->enable();

	if (m_useBindlessTextures) {
		GLuint samplersLocation(m_shader->getUniformLocation("samplers"));
		glUniform1ui64vNV(samplersLocation, m_numTextures, m_textureHandles);

	}

	GLuint bBindlessTexture(m_shader->getUniformLocation("useBindless"));
	glUniform1i(bBindlessTexture, m_useBindlessTextures);

	GLuint currentTexture(m_shader->getUniformLocation("currentFrame"));
	glUniform1i(currentTexture, m_currentFrame);

    // Set up the transformation matices up
    modelviewMatrix = m_transformer->getModelViewMat();
    m_transformUniformsData.ModelView = modelviewMatrix;
    m_transformUniformsData.ModelViewProjection= m_projectionMatrix * modelviewMatrix;
    m_transformUniformsData.UseBindlessUniforms = m_useBindlessUniforms;
    glBindBufferBase(GL_UNIFORM_BUFFER, 2, m_transformUniforms);
    glNamedBufferSubDataEXT(m_transformUniforms, 0, sizeof(TransformUniforms), &m_transformUniformsData);

    
    // If we are going to update the uniforms every frame, do it now
    if(m_updateUniformsEveryFrame == true)
    {
        float deltaTime;
        float dt;

        deltaTime = getFrameDeltaTime();

        if(deltaTime < m_minimumFrameDeltaTime)
        {
            m_minimumFrameDeltaTime = deltaTime;
        }

        dt = std::min(0.00005f / m_minimumFrameDeltaTime, .01f);
        m_t += dt * (float)Mesh::m_drawCallsPerState;

        updatePerMeshUniforms(m_t);
    }


    // Set up default per mesh uniforms. These may be changed on a per mesh basis in the rendering loop below 
    if(m_useBindlessUniforms == true)
    {
        // *** INTERESTING ***
        // Pass a GPU pointer to the vertex shader for the per mesh uniform data via a vertex attribute
        glVertexAttribI2i(m_bindlessPerMeshUniformsPtrAttribLocation, 
                             (int)(m_perMeshUniformsGPUPtr & 0xFFFFFFFF), 
                             (int)((m_perMeshUniformsGPUPtr >> 32) & 0xFFFFFFFF));
    }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_NVGPUShader5_nglUniform1ui64vNV__IIJ(JNIEnv *__env, jclass clazz, jint location, jint count, jlong valueAddress) {
    glUniform1ui64vNVPROC glUniform1ui64vNV = (glUniform1ui64vNVPROC)tlsGetFunction(1954);
    intptr_t value = (intptr_t)valueAddress;
    UNUSED_PARAM(clazz)
    glUniform1ui64vNV(location, count, value);
}