コード例 #1
0
void OpenGLRenderer::renderPoints(const glm::vec3* positions, const Color256* colors, const int num, const Camera &camera) {
  //always use the point shaders to render points
  glUseProgram(points_program_);
  GLuint mvp_location = glGetUniformLocation(points_program_, "u_mvpMatrix");

  //Declare CUDA device pointers for it to use
  float3* dptr_pos;
  float3* dptr_col;

  //Setup position buffer
  glBindBuffer(GL_ARRAY_BUFFER, buffers_[0]);
  glBufferData(GL_ARRAY_BUFFER, 3 * num*sizeof(float), NULL, GL_DYNAMIC_DRAW);
  glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, NULL);
  glEnableVertexAttribArray(0);

  //Setup color buffer
  glBindBuffer(GL_ARRAY_BUFFER, buffers_[1]);
  glBufferData(GL_ARRAY_BUFFER, 3 * num*sizeof(float), NULL, GL_DYNAMIC_DRAW);
  glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 0, NULL);
  glEnableVertexAttribArray(1);

  //Register position and normal buffers with CUDA
  cudaGLRegisterBufferObject(buffers_[0]);
  cudaGLRegisterBufferObject(buffers_[1]);

  //Map buffers to CUDA
  cudaGLMapBufferObject((void**)&dptr_pos, buffers_[0]);
  cudaGLMapBufferObject((void**)&dptr_col, buffers_[1]);

  //Copy data to buffer with CUDA
  copyPointsToGL(positions, colors, dptr_pos, dptr_col, num);

  //Unmap buffers from CUDA
  cudaGLUnmapBufferObject(buffers_[0]);
  cudaGLUnmapBufferObject(buffers_[1]);

  //Unregister position and normal buffers with CUDA
  cudaGLUnregisterBufferObject(buffers_[0]);
  cudaGLUnregisterBufferObject(buffers_[1]);

  //Send the MVP Matrix
  glUniformMatrix4fv(mvp_location, 1, GL_FALSE, glm::value_ptr(camera.mvp));

  //Draw
  glPointSize(1.0f);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glDrawArrays(GL_POINTS, 0, 3 * num);
}
コード例 #2
0
////////////////////////////////////////////////////////////////////////////////
//! Check if the result is correct or write data to file for external
//! regression testing
////////////////////////////////////////////////////////////////////////////////
void checkResultCuda(int argc, char** argv, const GLuint& vbo)
{
    cutilSafeCall(cudaGLUnregisterBufferObject(vbo));

    // map buffer object
    glBindBuffer(GL_ARRAY_BUFFER_ARB, vbo );
    float* data = (float*) glMapBuffer(GL_ARRAY_BUFFER, GL_READ_ONLY);

    // check result
    if(cutCheckCmdLineFlag(argc, (const char**) argv, "regression")) {
        // write file for regression test
        cutilCheckError(cutWriteFilef("./data/regression.dat",
            data, mesh_width * mesh_height * 3, 0.0));
    }

    // unmap GL buffer object
    if(! glUnmapBuffer(GL_ARRAY_BUFFER)) {
        fprintf(stderr, "Unmap buffer failed.\n");
        fflush(stderr);
    }

    cutilSafeCall(cudaGLRegisterBufferObject(vbo));

    CUT_CHECK_ERROR_GL();
}
コード例 #3
0
void cleanup()
{
    sdkDeleteTimer(&timer);

    checkCudaErrors(cudaFree(d_img));
    checkCudaErrors(cudaFree(d_temp));

    if (!runBenchmark)
    {
        if (pbo)
        {
            checkCudaErrors(cudaGLUnregisterBufferObject(pbo));
            glDeleteBuffersARB(1, &pbo);
        }

        if (texid)
        {
            glDeleteTextures(1, &texid);
        }
    }
	
    // cudaDeviceReset causes the driver to clean up all state. While
    // not mandatory in normal operation, it is good practice.  It is also
    // needed to ensure correct operation when the application is being
    // profiled. Calling cudaDeviceReset causes all profile data to be
    // flushed before the application exits
    cudaDeviceReset();
}
コード例 #4
0
ファイル: mandelbrot.cpp プロジェクト: CPutz/Mandelbrot
void Mandelbrot::Resize(int width, int height) {

	while( !this->bIsFinished );

	this->iWidth = width;
	this->iHeight = height;
	this->iSize = this->iWidth * this->iHeight * this->iDepth * sizeof(GLubyte);

	cudaFree( ( void** ) &this->devArray );
	cudaFree( ( void** ) &this->devCalcArray );
	cudaFree( ( void** ) &this->devCounts );
	cudaFree( ( void** ) &this->devData );
	cudaFree( ( void** ) &this->devHistogram );

	checkCudaErrors( cudaGLUnregisterBufferObject( this->buffer ), __LINE__, true );
	glDeleteBuffers( 1, &this->buffer );
    glDeleteTextures( 1, &this->tex );

	
	createBuffer( &this->buffer, this->iSize);
	createTexture( &this->tex, this->iWidth, this->iHeight );

	cudaMalloc( ( void** ) &this->devCounts, this->iWidth * this->iHeight * sizeof( int ) );
	cudaMalloc( ( void** ) &this->devData,   this->iWidth * this->iHeight * sizeof( double ) * 2 );
	cudaMalloc( ( void** ) &this->devArray,  this->iWidth * this->iHeight * this->iDepth * sizeof( GLubyte ) );
	cudaMalloc( ( void** ) &this->devCalcArray, this->iWidth * this->iHeight * this->iDepth * sizeof( GLubyte ) );
}
コード例 #5
0
ファイル: LiGL2Dwidget.cpp プロジェクト: dongmingdmdm/camnavi
void
LiGL2D::setVbo(int spaceVect)
{
	GLuint oldVbo = 0;
	GLuint newVbo = 0;
	if(vbo != 0){
		oldVbo = vbo;
		vbo = 0;
	}
	if(iw != 0 && ih !=0){
		GLint bsize;
		// create buffer object
		unsigned int size = ((int)iw/(spaceVect+1))*((int)ih/(spaceVect+1)) * 6 *  sizeof(float2);
		glGenBuffers( 1, &newVbo);
		glBindBuffer( GL_ARRAY_BUFFER, newVbo);
		// initialize buffer object
		glBufferData( GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW);
		glGetBufferParameterivARB(GL_ARRAY_BUFFER_ARB, GL_BUFFER_SIZE_ARB, &bsize); 
		glBindBuffer( GL_ARRAY_BUFFER, 0);
		// register buffer object with CUDA
		CUDA_SAFE_CALL(cudaGLRegisterBufferObject(newVbo));
		sVbo = ((int)iw/(spaceVect+1))*((int)ih/(spaceVect+1))*6;
		vbo = newVbo;
		emit sendVbo(vbo);
	}
	if(oldVbo != 0){
		CUDA_SAFE_CALL(cudaGLUnregisterBufferObject(oldVbo));
		glDeleteBuffers(1, &oldVbo);
	}
}
コード例 #6
0
ファイル: LiGL2Dwidget.cpp プロジェクト: dongmingdmdm/camnavi
void
LiGL2D::setPbo(int image_width, int image_height)
{
	makeCurrent();
	iw = image_width;
	ih = image_height;
	GLuint oldPbo = 0;
	GLuint newPbo = 0;
	GLuint oldTex = 0;

	if(pbo != 0){
		oldPbo = pbo;
		pbo = 0;
		oldTex = tex;
	}
	if(iw != 0 && ih !=0){
		glGenBuffers(1, &newPbo);
		glBindBuffer(GL_ARRAY_BUFFER, newPbo);
		glBufferData(GL_ARRAY_BUFFER, image_height*image_width* 4*sizeof(GLubyte),NULL, GL_DYNAMIC_DRAW);
		glBindBuffer(GL_ARRAY_BUFFER, 0);
		CUDA_SAFE_CALL(cudaGLRegisterBufferObject(newPbo));
		createTexture(&tex, iw, ih);
		glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);	
		pbo = newPbo;
		emit sendPbo(pbo);
	}
	if(oldPbo != 0){
		CUDA_SAFE_CALL(cudaGLUnregisterBufferObject(oldPbo));
		glDeleteBuffers(1, &oldPbo);
	}
	if(oldTex != 0){
		glDeleteTextures(1, &oldTex);
	}
}
コード例 #7
0
ファイル: cu2_viewer.c プロジェクト: E-LLP/QuIP
void cleanup_cu2_viewer(Cuda_Viewer *ovp)
{
	cutilSafeCall(cudaGLUnregisterBufferObject(ovp->ov_pbo_buffer));

	glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
	glDeleteBuffers(1, &ovp->ov_pbo_buffer);
	glDeleteTextures(1, &ovp->ov_texid);
	//deleteTexture();
}
コード例 #8
0
////////////////////////////////////////////////////////////////////////////////
//! Delete VBO
////////////////////////////////////////////////////////////////////////////////
void deleteVBO(GLuint* vbo)
{
    glBindBuffer(1, *vbo);
    glDeleteBuffers(1, vbo);

    cutilSafeCall(cudaGLUnregisterBufferObject(*vbo));

    *vbo = 0;
}
コード例 #9
0
ファイル: Glue.cpp プロジェクト: yyzreal/asvo_cuda
Glue::~Glue()
{
    // delete pbo
    glBindBuffer( GL_ARRAY_BUFFER, m_pbo );
    glDeleteBuffers( 1, & m_pbo );
    cudaGLUnregisterBufferObject( m_pbo );

    // delete texture
    glDeleteTextures( 1, & m_texture );
}
コード例 #10
0
ファイル: main.cpp プロジェクト: uriahjb/Project4-Rasterizer
void deletePBO(GLuint* pbo){
  if (pbo) {
    // unregister this buffer object with CUDA
    cudaGLUnregisterBufferObject(*pbo);
    
    glBindBuffer(GL_ARRAY_BUFFER, *pbo);
    glDeleteBuffers(1, pbo);
    
    *pbo = (GLuint)NULL;
  }
}
コード例 #11
0
ファイル: mandelbrot.cpp プロジェクト: CPutz/Mandelbrot
Mandelbrot::~Mandelbrot() {
	cudaFree( ( void** ) &this->devArray );
	cudaFree( ( void** ) &this->devCalcArray );
	cudaFree( ( void** ) &this->devCounts );
	cudaFree( ( void** ) &this->devData );
	cudaFree( ( void** ) &this->devHistogram );
	
	checkCudaErrors( cudaGLUnregisterBufferObject( this->buffer ), __LINE__, true );
	glDeleteBuffers( 1, &this->buffer );
    glDeleteTextures( 1, &this->tex );
}
コード例 #12
0
ファイル: main.cpp プロジェクト: zvonkok/masterthesis
void cleanup(void) {
    cutilSafeCall(cudaGLUnregisterBufferObject(pbo_buffer));

    glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
    glDeleteBuffers(1, &pbo_buffer);
    glDeleteTextures(1, &texid);
    deleteTexture();

    if (g_CheckRender) {
        delete g_CheckRender; g_CheckRender = NULL;
    }

    cutilCheckError(cutDeleteTimer(timer));  
}
コード例 #13
0
ファイル: vbo.cpp プロジェクト: davidhesselbom/freq
void Vbo::
        clear()
{
    if (_vbo)
    {
        TIME_VBO TaskTimer tt("Vbo::clear %u, size %s", _vbo,
                              DataStorageVoid::getMemorySizeText(_sz).c_str());

#ifdef USE_CUDA
        cudaError_t e = cudaSuccess;
        if (_registered)
        {
            e = cudaGLUnregisterBufferObject(_vbo);
            _registered = false;
        }
#endif
        glDeleteBuffers(1, &_vbo);
        _vbo = 0;
        _sz = 0;
    }
}
コード例 #14
0
void cleanup()
{
    cutilCheckError( cutDeleteTimer( timer));
    if (!h_img) {
	    free(h_img);
	}

    cutilSafeCall(cudaFree(d_img));
    cutilSafeCall(cudaFree(d_temp));

    if (!runBenchmark) {
        if (pbo) {
            cutilSafeCall(cudaGLUnregisterBufferObject(pbo));    
            glDeleteBuffersARB(1, &pbo);
        }
        if (texid) {
            glDeleteTextures(1, &texid);
        }
    }

    if (g_CheckRender) {
        delete g_CheckRender; g_CheckRender = NULL;
    }
}
コード例 #15
0
void OpenGLRenderer::rasterizeVoxels(const VoxelGrid& geometry, const Camera& camera, const glm::vec3& light) {
  //startTiming();

  //always use the voxel shaders to rasterize voxels with instancing
  glUseProgram(voxel_program_);
  GLuint mvp_location = glGetUniformLocation(voxel_program_, "u_mvpMatrix");
  GLuint norm_location = glGetUniformLocation(voxel_program_, "u_normMatrix");
  GLuint light_location = glGetUniformLocation(voxel_program_, "u_light");
  GLuint scale_location = glGetUniformLocation(voxel_program_, "u_scale");

  //Declare CUDA device pointers for it to use
  glm::vec4* dptr_centers;
  glm::vec4* dptr_colors;

  //Setup position buffer
  glBindBuffer(GL_ARRAY_BUFFER, buffers_[0]);
  glBufferData(GL_ARRAY_BUFFER, 4*geometry.size*sizeof(float), NULL, GL_DYNAMIC_DRAW);
  glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, NULL);
  glEnableVertexAttribArray(0);

  //Setup color buffer
  glBindBuffer(GL_ARRAY_BUFFER, buffers_[1]);
  glBufferData(GL_ARRAY_BUFFER, 4 * geometry.size*sizeof(float), NULL, GL_DYNAMIC_DRAW);
  glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, NULL);
  glEnableVertexAttribArray(1);

  //Register position and normal buffers with CUDA
  cudaGLRegisterBufferObject(buffers_[0]);
  cudaGLRegisterBufferObject(buffers_[1]);

  //Map buffers to CUDA
  cudaGLMapBufferObject((void**)&dptr_centers, buffers_[0]);
  cudaGLMapBufferObject((void**)&dptr_colors, buffers_[1]);

  //Copy data to buffer
  cudaMemcpy(dptr_centers, geometry.centers, 4*geometry.size*sizeof(float), cudaMemcpyDeviceToDevice);
  cudaMemcpy(dptr_colors, geometry.colors, 4*geometry.size*sizeof(float), cudaMemcpyDeviceToDevice);

  //Unmap buffers from CUDA
  cudaGLUnmapBufferObject(buffers_[0]);
  cudaGLUnmapBufferObject(buffers_[1]);

  //Unregister position and normal buffers with CUDA
  cudaGLUnregisterBufferObject(buffers_[0]);
  cudaGLUnregisterBufferObject(buffers_[1]);

  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_BUFFER, textures_[0]);
  glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, buffers_[0]);
  glActiveTexture(GL_TEXTURE1);
  glBindTexture(GL_TEXTURE_BUFFER, textures_[1]);
  glTexBuffer(GL_TEXTURE_BUFFER, GL_RGBA32F, buffers_[1]);

  //Send the MVP Matrix
  glUniformMatrix4fv(mvp_location, 1, GL_FALSE, glm::value_ptr(camera.mvp));
  glm::mat3 norm_mat = glm::mat3(glm::transpose(glm::inverse(camera.model)));
  glUniformMatrix3fv(norm_location, 1, GL_FALSE, glm::value_ptr(norm_mat));

  //Send the light position
  glUniform3fv(light_location, 1, glm::value_ptr(light));

  //Send the scale
  glUniform1f(scale_location, geometry.scale);

  //Draw
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glDrawArraysInstanced(GL_TRIANGLES, 0, 36, geometry.size);

  //float t = stopTiming();
  //std::cout << "Draw took: " << t << std::endl;

}
コード例 #16
0
ファイル: cudart.c プロジェクト: Shelnutt2/cuda-wine-wrapper
cudaError_t WINAPI wine_cudaGLUnregisterBufferObject( GLuint bufObj ) {
    WINE_TRACE("\n");
    return cudaGLUnregisterBufferObject( bufObj );
}
コード例 #17
0
ファイル: SimCudaHelper.cpp プロジェクト: nixz/covise
cudaError_t SimCudaHelper::UnregisterGLBuffer(GLuint vbo)
{
    return cudaGLUnregisterBufferObject(vbo);
}