Exemplo n.º 1
0
// This pass takes a photon buffer (computed above).  It runs through each
//    pixel in the buffer, treating the pixel as a photon position, and
//    splatting the resulting photon into the specificed caustic map
//    (using the viewing matrices for the specified light).
void CreateCausticMap( FrameBuffer *cMap, int lightNum )
{
	/* setup the texture we'll draw to */
	cMap->BindBuffer();
	cMap->ClearBuffers();
	SetLightMatrices( lightNum, cMap->GetAspectRatio() );

	/* set some necessary GL state. */
	glDisable( GL_CULL_FACE );
	glDisable( GL_DEPTH_TEST );

	/* the photon buffer vertex array already contains light-space coordinates!   */
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

	/* Draw the photons... */
	glBindBuffer( GL_ARRAY_BUFFER, data->vbo->genericTraversalBuffer[0] ); // Buffer containing garbage...  Needed b/c
	glVertexPointer( 2, GL_SHORT, 0, BUFFER_OFFSET( 0 ) );				   //   OpenGL *requires* vertex positions, even 
	glEnableClientState( GL_VERTEX_ARRAY );								   //   if we read positions from a texture.

	// Enable our shader, set up all the parameters we need to specify.
	data->shader->caustic_SimplePhotonSplat->EnableShader();
	data->shader->caustic_SimplePhotonSplat->BindAndEnableTexture( "photonPositions", 
					data->fbo->caustic_PhotonBuffer->GetColorTextureID(), GL_TEXTURE0, GL_TEXTURE_2D );
	data->shader->caustic_SimplePhotonSplat->BindAndEnableTexture( "lightColor", 
					data->tex->spotlight->TextureID(), GL_TEXTURE1, GL_TEXTURE_2D );
	data->shader->caustic_SimplePhotonSplat->SetParameter( "photonBufferResolution", 
					data->fbo->caustic_PhotonBuffer->GetWidth() );
	data->shader->caustic_SimplePhotonSplat->SetParameter( "causticMapResolution", 
					cMap->GetWidth() );
	data->shader->caustic_SimplePhotonSplat->SetParameter( "photonResolutionMultiplier", 
					sqr( cMap->GetWidth()/(float)data->fbo->caustic_PhotonBuffer->GetWidth() ) );

	// OK.  We enabled the shader, now start drawing.
	glEnable(GL_BLEND);                                        // We're drawing "splats" so enable blending
	glBlendFuncSeparate(GL_ONE, GL_ONE, GL_ONE, GL_ONE);       //   in order to correctly combine their 
	glBlendEquation(GL_FUNC_ADD);                              //   contributions.
	glPointSize( 3.0 );                                        // What size are the splats?	
	glDrawArraysInstancedEXT( GL_POINTS, 0,					   // Command to actually draw
							  data->fbo->caustic_PhotonBuffer->GetWidth(), 	
							  data->fbo->caustic_PhotonBuffer->GetWidth() ); 

	// Clean up point & blend state, disable shader
	glPointSize( 1.0 );                                        
    glDisable(GL_BLEND);                                       
	data->shader->caustic_SimplePhotonSplat->DisableTexture( GL_TEXTURE0, GL_TEXTURE_2D );
	data->shader->caustic_SimplePhotonSplat->DisableShader();

	// Stop rendering from a vertex array
    glDisableClientState( GL_VERTEX_ARRAY );
    glBindBuffer( GL_ARRAY_BUFFER, 0 );
	
	// Disable other miscellaneous GL state & unbind the draw buffer
	glEnable( GL_CULL_FACE );
	glEnable( GL_DEPTH_TEST );
	PopLightMatrices();
	cMap->UnbindBuffer(); 
}
 inline void VL_glDrawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei primcount)
 {
   if (glDrawArraysInstanced)
     glDrawArraysInstanced(mode, first, count, primcount);
   else
   if (glDrawArraysInstancedARB)
     glDrawArraysInstancedARB(mode, first, count, primcount);
   else
   if (glDrawArraysInstancedEXT)
     glDrawArraysInstancedEXT(mode, first, count, primcount);
   else
     VL_UNSUPPORTED_FUNC();
 }
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_EXTDrawInstanced_nglDrawArraysInstancedEXT(JNIEnv *env, jclass clazz, jint mode, jint first, jint count, jint primcount, jlong function_pointer) {
	glDrawArraysInstancedEXTPROC glDrawArraysInstancedEXT = (glDrawArraysInstancedEXTPROC)((intptr_t)function_pointer);
	glDrawArraysInstancedEXT(mode, first, count, primcount);
}