Ejemplo n.º 1
0
void MeshTexturizer::Imp::allocateTextures(int groupIdx, const TRaster32P &ras, const TRaster32P &aux,
										   int x, int y, int textureLx, int textureLy,
										   bool premultiplied)
{
	TextureData *data = m_textureDatas[groupIdx].get();

	// Test the specified texture allocation
	if (testTextureAlloc(textureLx, textureLy)) {
		TPointD scale(data->m_geom.getLx() / (double)ras->getLx(),
					  data->m_geom.getLy() / (double)ras->getLy());
		TRectD tileGeom(
			TRectD(
				scale.x * (x - TOTAL_BORDER), scale.y * (y - TOTAL_BORDER),
				scale.x * (x + textureLx + TOTAL_BORDER), scale.y * (y + textureLy + TOTAL_BORDER)) +
			data->m_geom.getP00());

		GLuint texId = textureAlloc(ras, aux, x, y, textureLx, textureLy, premultiplied);

		TextureData::TileData td = {texId, tileGeom};
		data->m_tileDatas.push_back(td);

		return;
	}

	if (textureLx <= 1 && textureLy <= 1)
		return; // No texture can be allocated

	// The texture could not be allocated. Then, bisecate and branch.
	if (textureLx > textureLy) {
		int textureLx_2 = textureLx >> 1;
		allocateTextures(groupIdx, ras, aux, x, y, textureLx_2, textureLy, premultiplied);
		allocateTextures(groupIdx, ras, aux, x + textureLx_2, y, textureLx_2, textureLy, premultiplied);
	} else {
void TilesManager::setCurrentLayerTextureCount(int newTextureCount)
{
    int maxTextureAllocation = getMaxTextureAllocation();
    ALOGV("setCurrentLayerTextureCount: %d (current: %d, max:%d)",
         newTextureCount, m_currentLayerTextureCount, maxTextureAllocation);
    if (!newTextureCount && m_hasLayerTextures) {
        double secondsSinceLayersUsed = WTF::currentTime() - m_lastTimeLayersUsed;
        if (secondsSinceLayersUsed > LAYER_TEXTURES_DESTROY_TIMEOUT) {
            unsigned long long sparedDrawCount = ~0; // by default, spare no textures
            bool deleteGLTextures = true;
            discardTexturesVector(sparedDrawCount, m_tilesTextures, deleteGLTextures);
            m_hasLayerTextures = false;
        }
        return;
    }
    m_lastTimeLayersUsed = WTF::currentTime();
    if (m_currentLayerTextureCount == maxTextureAllocation ||
        newTextureCount <= m_currentLayerTextureCount)
        return;

    android::Mutex::Autolock lock(m_texturesLock);
    m_currentLayerTextureCount = std::min(newTextureCount, maxTextureAllocation);

    allocateTextures();
    m_hasLayerTextures = true;
}
Ejemplo n.º 3
0
    void apply(RenderDevice* rd) {
        rd->push2D();
            Rect2D screenRect = rd->getViewport();
            allocateTextures(screenRect);
            
            // Read back the depth buffer
            depth->copyFromScreen(screenRect, true);
            color->copyFromScreen(screenRect, true);

            rd->setShader(shader);
            Draw::rect2D(screenRect, rd);
        rd->pop2D();
    }
void TilesManager::setCurrentTextureCount(int newTextureCount)
{
    int maxTextureAllocation = getMaxTextureAllocation();
    ALOGV("setCurrentTextureCount: %d (current: %d, max:%d)",
         newTextureCount, m_currentTextureCount, maxTextureAllocation);
    if (m_currentTextureCount == maxTextureAllocation ||
        newTextureCount <= m_currentTextureCount)
        return;

    android::Mutex::Autolock lock(m_texturesLock);
    m_currentTextureCount = std::min(newTextureCount, maxTextureAllocation);

    allocateTextures();
}
Ejemplo n.º 5
0
void CMarchingCubes::InitMC(int _width, int _height, int _depth, ElemType* _pVolume)
{
	// Data Array A[:, :, 1], A[:, :, 2], ... , A[:, : , n]
	//m_GridSize = make_uint3(_depth, _width, _height);
	m_GridSize = make_uint3(_width, _height, _depth);
	m_NumVoxels = m_GridSize.x * m_GridSize.y * m_GridSize.z;
	m_MaxVerts = m_GridSize.x * m_GridSize.y * 30;					// Num of MaxVerts need change
#ifdef _DEBUG
	printf("grids: %d * %d * %d = %d voxels\n", m_GridSize.x, m_GridSize.y, m_GridSize.z, m_NumVoxels);
#endif // _DEBUG

	// needed change
	int size = m_GridSize.x * m_GridSize.y * m_GridSize.z * sizeof(float);
	//////////////////////////////////////////////////////////////////////////
	int len = m_GridSize.x * m_GridSize.y * m_GridSize.z * 3;
	float *pVolTemp = new float[len];
	for (int i = 0; i < len; i++)
		pVolTemp[i] = _pVolume[i];
	//////////////////////////////////////////////////////////////////////////
	cutilSafeCall(cudaMalloc((void**) &m_pdVolume, size * 3));
	cutilSafeCall(cudaMemcpy(m_pdVolume, pVolTemp, size * 3, cudaMemcpyHostToDevice) );
	bindVolumeTexture(m_pdVolume);				// map the coordinates to the texture directly
	delete []pVolTemp;

	// allocate textures
	allocateTextures( &m_pdEdgeTable, &m_pdTriTable, &m_pdNumVertsTable );

	// allocate device memory
	unsigned int memSize = sizeof(uint) * m_NumVoxels;
	cutilSafeCall(cudaMalloc((void**) &m_pdVoxelVerts, memSize));
	cutilSafeCall(cudaMalloc((void**) &m_pdVoxelVertsScan, memSize));
	cutilSafeCall(cudaMalloc((void**) &m_pdVoxelOccupied, memSize));
	cutilSafeCall(cudaMalloc((void**) &m_pdVoxelOccupiedScan, memSize));
	cutilSafeCall(cudaMalloc((void**) &m_pdCompactedVoxelArray, memSize));

	// initialize CUDPP scan
	CUDPPConfiguration config;
	config.algorithm = CUDPP_SCAN;
	config.datatype = CUDPP_UINT;
	config.op = CUDPP_ADD;
	config.options = CUDPP_OPTION_FORWARD | CUDPP_OPTION_EXCLUSIVE;
	cudppPlan(&m_Scanplan, config, m_NumVoxels, 1, 0);
}
Ejemplo n.º 6
0
////////////////////////////////////////////////////////////////////////////////
// initialize marching cubes
////////////////////////////////////////////////////////////////////////////////
void
initMC(int argc, char** argv)
{
    // parse command line arguments
    int n;
    if (cutGetCmdLineArgumenti( argc, (const char**) argv, "grid", &n)) {
        gridSizeLog2.x = gridSizeLog2.y = gridSizeLog2.z = n;
    }
    if (cutGetCmdLineArgumenti( argc, (const char**) argv, "gridx", &n)) {
        gridSizeLog2.x = n;
    }
    if (cutGetCmdLineArgumenti( argc, (const char**) argv, "gridy", &n)) {
        gridSizeLog2.y = n;
    }
    if (cutGetCmdLineArgumenti( argc, (const char**) argv, "gridz", &n)) {
        gridSizeLog2.z = n;
    }

    char *filename;
    if (cutGetCmdLineArgumentstr( argc, (const char**) argv, "file", &filename)) {
        volumeFilename = filename;
    }

    gridSize = make_uint3(1<<gridSizeLog2.x, 1<<gridSizeLog2.y, 1<<gridSizeLog2.z);
    gridSizeMask = make_uint3(gridSize.x-1, gridSize.y-1, gridSize.z-1);
    gridSizeShift = make_uint3(0, gridSizeLog2.x, gridSizeLog2.x+gridSizeLog2.y);

    numVoxels = gridSize.x*gridSize.y*gridSize.z;
    voxelSize = make_float3(2.0f / gridSize.x, 2.0f / gridSize.y, 2.0f / gridSize.z);
    maxVerts = gridSize.x*gridSize.y*100;

    printf("grid: %d x %d x %d = %d voxels\n", gridSize.x, gridSize.y, gridSize.z, numVoxels);
    printf("max verts = %d\n", maxVerts);

#if SAMPLE_VOLUME
    // load volume data
    char* path = cutFindFilePath(volumeFilename, argv[0]);
    if (path == 0) {
        fprintf(stderr, "Error finding file '%s'\n", volumeFilename);
        cudaThreadExit();
        exit(EXIT_FAILURE);
    }

    int size = gridSize.x*gridSize.y*gridSize.z*sizeof(uchar);
    uchar *volume = loadRawFile(path, size);
    cutilSafeCall(cudaMalloc((void**) &d_volume, size));
    cutilSafeCall(cudaMemcpy(d_volume, volume, size, cudaMemcpyHostToDevice) );
    free(volume);

	bindVolumeTexture(d_volume);
#endif

    if (g_bQAReadback) {
        cudaMalloc((void **)&(d_pos),    maxVerts*sizeof(float)*4);
        cudaMalloc((void **)&(d_normal), maxVerts*sizeof(float)*4);
    } else {
        // create VBOs
        createVBO(&posVbo, maxVerts*sizeof(float)*4);
		// DEPRECATED: cutilSafeCall( cudaGLRegisterBufferObject(posVbo) );
		cutilSafeCall(cudaGraphicsGLRegisterBuffer(&cuda_posvbo_resource, posVbo, 
							   cudaGraphicsMapFlagsWriteDiscard));

        createVBO(&normalVbo, maxVerts*sizeof(float)*4);
        // DEPRECATED: cutilSafeCall(cudaGLRegisterBufferObject(normalVbo));
		cutilSafeCall(cudaGraphicsGLRegisterBuffer(&cuda_normalvbo_resource, normalVbo, 
							   cudaGraphicsMapFlagsWriteDiscard));

    }

    // allocate textures
	allocateTextures(	&d_edgeTable, &d_triTable, &d_numVertsTable );

    // allocate device memory
    unsigned int memSize = sizeof(uint) * numVoxels;
    cutilSafeCall(cudaMalloc((void**) &d_voxelVerts,            memSize));
    cutilSafeCall(cudaMalloc((void**) &d_voxelVertsScan,        memSize));
    cutilSafeCall(cudaMalloc((void**) &d_voxelOccupied,         memSize));
    cutilSafeCall(cudaMalloc((void**) &d_voxelOccupiedScan,     memSize));
    cutilSafeCall(cudaMalloc((void**) &d_compVoxelArray,   memSize));

    // initialize CUDPP scan
    CUDPPConfiguration config;
    config.algorithm    = CUDPP_SCAN;
    config.datatype     = CUDPP_UINT;
    config.op           = CUDPP_ADD;
    config.options      = CUDPP_OPTION_FORWARD | CUDPP_OPTION_EXCLUSIVE;
    cudppPlan(&scanplan, config, numVoxels, 1, 0);
}