//-------------------------------------------------------------- // destructor Tower::~Tower() { delete m_floorDists; m_floorDists = NULL; deleteBuffers(); }
///Assignment operator (deep-copies the src kernel) const DKernel2D& DKernel2D::operator=(const DKernel2D &src){ int w, h; if(this != &src){ fSep = src.fSep; radiusX = src.radiusX; radiusY = src.radiusY; numSigsX = src.numSigsX; numSigsY = src.numSigsY; w = 2*radiusX+1; h = 2*radiusY+1; deleteBuffers(); if((w < 1) || (h < 1)){ rgData_flt = NULL; rgData_dbl = NULL; rgSep_flt = NULL; rgSep_dbl = NULL; } else{ allocBuffers(w, h); memcpy(rgData_flt, src.rgData_flt, sizeof(float)*w*h); memcpy(rgData_dbl, src.rgData_dbl, sizeof(double)*w*h); memcpy(rgSep_flt, src.rgSep_flt, sizeof(float)*(w+h)); memcpy(rgSep_dbl, src.rgSep_dbl, sizeof(double)*(w+h)); } } return *this; }
void FaceGeometry::createGLBuffers() const { if (_buffersDirty) { deleteBuffers(); try { _verticesBuffer = new cgt::BufferObject(cgt::BufferObject::ARRAY_BUFFER, cgt::BufferObject::USAGE_STATIC_DRAW); _verticesBuffer->data(&_vertices.front(), _vertices.size() * sizeof(cgt::vec3), cgt::BufferObject::FLOAT, 3); if (! _textureCoordinates.empty()) { _texCoordsBuffer = new cgt::BufferObject(cgt::BufferObject::ARRAY_BUFFER, cgt::BufferObject::USAGE_STATIC_DRAW); _texCoordsBuffer->data(&_textureCoordinates.front(), _textureCoordinates.size() * sizeof(cgt::vec3), cgt::BufferObject::FLOAT, 3); } if (! _colors.empty()) { _colorsBuffer = new cgt::BufferObject(cgt::BufferObject::ARRAY_BUFFER, cgt::BufferObject::USAGE_STATIC_DRAW); _colorsBuffer->data(&_colors.front(), _colors.size() * sizeof(cgt::vec4), cgt::BufferObject::FLOAT, 4); } if (! _normals.empty()) { _normalsBuffer = new cgt::BufferObject(cgt::BufferObject::ARRAY_BUFFER, cgt::BufferObject::USAGE_STATIC_DRAW); _normalsBuffer->data(&_normals.front(), _normals.size() * sizeof(cgt::vec3), cgt::BufferObject::FLOAT, 3); } if (! _pickingInformation.empty()) { _pickingBuffer = new cgt::BufferObject(cgt::BufferObject::ARRAY_BUFFER, cgt::BufferObject::USAGE_STATIC_DRAW); _pickingBuffer->data(&_pickingInformation.front(), _pickingInformation.size() * sizeof(cgt::col4), cgt::BufferObject::UNSIGNED_BYTE, 4); } } catch (cgt::Exception& e) { LERROR("Error creating OpenGL Buffer objects: " << e.what()); _buffersDirty = true; return; } LGL_ERROR; _buffersDirty = false; } }
void D3D10App::exitAPI(){ delete renderer; deleteBuffers(); if (swapChain){ // Reset display mode to default if (fullscreen) swapChain->SetFullscreenState(false, NULL); swapChain->Release(); } if (device){ ULONG count = device->Release(); #ifdef _DEBUG if (count){ char str[512]; sprintf(str, "There are %d unreleased references left on the D3D device!\n", count); outputDebugString(str); } #endif device = NULL; } DestroyWindow(hwnd); }
/**radiusX and radiusY specify how far the kernel extends from the central pixel. Circular kernels cannot be separable. The value of each pixel of the kernel within the elliptical area is scaled equally so that the entire filter sums to 1. Areas outside the ellipse are set to zero. */ void DKernel2D::setCirc(int radiusX, int radiusY){ int w, h; double dblSum; double rx2,ry2; w = radiusX*2+1; h = radiusY*2+1; this->radiusX = radiusX; this->radiusY = radiusY; fSep = false; deleteBuffers(); allocBuffers(w,h); dblSum = 0.; rx2=(0.5+radiusX)*(0.5+radiusX); ry2=(0.5+radiusY)*(0.5+radiusY); for(int y = -radiusY, idx = 0; y <= radiusY; ++y){ for(int x = -radiusX; x <= radiusX; ++x, ++idx){ if(((x*x/rx2)+(y*y/ry2)) <= 1.){ rgData_dbl[idx] = 1.; dblSum += 1.; } else rgData_dbl[idx] = 0.; } } for(int y = -radiusY, idx = 0; y <= radiusY; ++y){ for(int x = -radiusX; x <= radiusX; ++x, ++idx){ rgData_dbl[idx] /= dblSum; rgData_flt[idx] = rgData_dbl[idx]; } } }
void ParticleSystem::setBufferSize(uint32 size) { if (size == 0 || size > MAX_PARTICLES) throw love::Exception("Invalid buffer size"); deleteBuffers(); createBuffers(size); reset(); }
///Set the kernel to a Laplacian of Gaussian (2nd derivative of the Gaussian) void DKernel2D::setLoG(int radiusX, int radiusY, bool fSeparable){ int w, h; double xp, yp; double one_2piSigXsigY; double sigmaX, sigmaY; double sigmaX2, sigmaY2; double sigmaX4, sigmaY4; double ksum = 0.; sigmaX = radiusX / numSigsX; sigmaY = radiusY / numSigsY; sigmaX2 = sigmaX * sigmaX; sigmaY2 = sigmaY * sigmaY; sigmaX4 = sigmaX2 * sigmaX2; sigmaY4 = sigmaY2 * sigmaY2; w = radiusX*2+1; h = radiusY*2+1; this->radiusX = radiusX; this->radiusY = radiusY; fSep = fSeparable; deleteBuffers(); allocBuffers(w,h); one_2piSigXsigY = 1. / (2* M_PI * sigmaX * sigmaY); if(fSeparable){ fprintf(stderr, "DKernel2D::setLoG() separable kernel not implemented\n"); exit(1); } else{ one_2piSigXsigY = 1. / (2* M_PI * sigmaX * sigmaY); for(int y = 0, idx = 0; y < h; ++y){ yp = y-radiusY; for(int x = 0; x < w; ++x, ++idx){ xp = x-radiusX; rgData_dbl[idx] = one_2piSigXsigY * exp(-0.5*(xp*xp/sigmaX2 + yp*yp/sigmaY2)) * ((xp*xp/sigmaX4 - 1./sigmaX2) + (yp*yp/sigmaY4 - 1./sigmaY2)); rgData_flt[idx] = (float)(rgData_dbl[idx]); ksum += rgData_dbl[idx]; } } } printf("LoG ksum=%f\n", ksum); // // get rid of the bias (ksum) // ksum /= (w*h); // for(int i = 0; i < w*h; ++i){ // rgData_dbl[i] -= ksum; // rgData_flt[i] -= ksum; // } // ksum = 0.; // for(int i = 0; i < w*h; ++i){ // ksum += rgData_dbl[i]; // } // printf("after adjusting, ksum=%f\n", ksum); }
void D3D10App::onSize(const int w, const int h){ BaseApp::onSize(w, h); if (device != NULL){ deleteBuffers(); swapChain->ResizeBuffers(1, width, height, backBufferFormat, 0); createBuffers(); ((Direct3D10Renderer *) renderer)->setFrameBuffer(backBufferRTV, depthBufferDSV); } }
//-------------------------------------------------------------- // destructor Wreck::~Wreck() { deleteBuffers(); for (int i = 0; i < m_towers.length(); i++) { Tower* tower = (Tower*) m_towers[i]; delete tower; } m_towers.removeAll(); }
///Set the kernel to a fake LaplacianOfGaussian void DKernel2D::setFakeLoG(int radiusX, int radiusY){ int w, h; double xp, yp; double one_2piSigXsigY; double sigmaX, sigmaY; double sigmaX2, sigmaY2; double sigmaX4, sigmaY4; double XoverY; double ksum = 0.; XoverY = (double)radiusX / (double)radiusY; sigmaX = radiusX / numSigsX; sigmaY = sigmaX; // sigmaY = radiusY / numSigsY; sigmaX2 = sigmaX * sigmaX; sigmaY2 = sigmaY * sigmaY; sigmaX4 = sigmaX2 * sigmaX2; sigmaY4 = sigmaY2 * sigmaY2; w = radiusX*2+1; h = radiusY*2+1; this->radiusX = radiusX; this->radiusY = radiusY; fSep = false; deleteBuffers(); allocBuffers(w,h); one_2piSigXsigY = 1. / (2* M_PI * sigmaX * sigmaY); one_2piSigXsigY = 1. / (2* M_PI * sigmaX * sigmaY); for(int y = 0, idx = 0; y < h; ++y){ yp = (y-radiusY)*XoverY; for(int x = 0; x < w; ++x, ++idx){ xp = x-radiusX; rgData_dbl[idx] = one_2piSigXsigY * exp(-0.5*(xp*xp/sigmaX2 + yp*yp/sigmaY2)) * ((xp*xp/sigmaX4 - 1./sigmaX2) + (yp*yp/sigmaY4 - 1./sigmaY2)); rgData_flt[idx] = (float)(rgData_dbl[idx]); ksum += rgData_dbl[idx]; } } printf("Fake LoG ksum=%f\n", ksum); // // get rid of the bias (ksum) // ksum /= (w*h); // for(int i = 0; i < w*h; ++i){ // rgData_dbl[i] -= ksum; // rgData_flt[i] -= ksum; // } // ksum = 0.; // for(int i = 0; i < w*h; ++i){ // ksum += rgData_dbl[i]; // } // printf("after adjusting, ksum=%f\n", ksum); }
void PolygonalGeometry::initialize(const Program & program) { if(!m_arrayBOsByAttribute.empty() && !m_elementArrayBOs.empty()) return; deleteBuffers(); glGenVertexArrays(1, &m_vao); glError(); glBindVertexArray(m_vao); glError(); { VertexReuse vertexReuse; VertexCacheOptimizer vertexCacheOptimizer; applyOptimizer(&vertexReuse); applyOptimizer(&vertexCacheOptimizer); } // setup element array buffers BufferObject * indexBO = new BufferObject(GL_ELEMENT_ARRAY_BUFFER, GL_STATIC_DRAW); indexBO->data<GLuint>(indices(), GL_UNSIGNED_INT, 1); m_elementArrayBOs.push_back(indexBO); // setup array buffers BufferObject * vertexBO = new BufferObject(GL_ARRAY_BUFFER, GL_STATIC_DRAW); vertexBO->data<glm::vec3>(copyVertices(), GL_FLOAT, 3); m_arrayBOsByAttribute["a_vertex"] = vertexBO; // TODO: the geometry should provide this information. if( !normals().isEmpty() ) { BufferObject * normalBO = new BufferObject(GL_ARRAY_BUFFER, GL_STATIC_DRAW); normalBO->data<glm::vec3>(normals(), GL_FLOAT, 3); m_arrayBOsByAttribute["a_normal"] = normalBO; } // bind all buffers to their attributes t_bufferObjectsByAttribute::const_iterator i(m_arrayBOsByAttribute.begin()); const t_bufferObjectsByAttribute::const_iterator iEnd(m_arrayBOsByAttribute.end()); for( ; i != iEnd; ++i ) i.value()->bind(program.attributeLocation(i.key())); glBindVertexArray(0); glError(); }
GeometryData& GeometryData::operator=(const GeometryData& rhs) { if (this == &rhs) return *this; AbstractData::operator=(rhs); // delete old VBOs and null pointers deleteBuffers(); return *this; }
//-------------------------------------------------------------- // destructor BrickBlob::~BrickBlob() { delete m_bricks; m_bricks = NULL; delete m_lights; m_lights = NULL; m_selectedTexture = NULL; deleteBuffers(); }
//-------------------------------------------------------------- // destructor Intro::~Intro() { deleteBuffers(); delete m_tube; m_tube = NULL; delete m_wall; m_wall = NULL; delete m_saucer; m_saucer = NULL; }
void D3D11App::onSize(const int w, const int h) { BaseApp::onSize(w, h); if (device != NULL) { const bool sampleBackBuffer = (backBufferTexture != TEXTURE_NONE); deleteBuffers(); HRESULT hr = swapChain->ResizeBuffers(1, width, height, backBufferFormat, 0); createBuffers(sampleBackBuffer); } }
void filter::init() { deleteBuffers(); nZeroes=0; nPoles=0; gain=1; avgVolume=0; volumeAttackIntegrator=1; volumeDecayIntegrator=1; prevTemp=0; angleToFc=SAMPLERATE/(2*M_PI); frCenter=0; }
void ParticleSystem::createBuffers(size_t size) { try { pFree = pMem = new Particle[size]; maxParticles = (uint32) size; } catch (std::bad_alloc &) { deleteBuffers(); throw love::Exception("Out of memory"); } }
//-------------------------------------------------------------- // reset the display void mgDX9Display::displayReset() { mgDebug("reset display"); // reset the D3D Device, losing all graphics state deleteBuffers(); // set current size of window m_state->m_presentParms.BackBufferWidth = m_graphicsWidth; m_state->m_presentParms.BackBufferHeight = m_graphicsHeight; HRESULT hr = mg_d3dDevice->Reset(&m_state->m_presentParms); if (hr == S_OK) createBuffers(); }
/* Safely disposes graphics subsystem */ int gDispose(GContext *context) { deleteBuffers (&(context->buffers)); deletePrograms(&(context->programs)); deleteShaders (&(context->shaders)); //printInfo("disposeGraphics()\n"); #ifdef DEBUG checkError(); #endif return 0; }
RendererGL::~RendererGL() { wglMakeCurrent( nullptr, nullptr ); wglDeleteContext( m_renderingContext ); m_renderingContext = nullptr; for (auto it = m_layoutVec.begin() ;it!=m_layoutVec.end();) { delete (*it); it = m_layoutVec.erase(it); } deleteBuffers(m_vbuffVec); deleteBuffers(m_ibuffVec); std::for_each(begin(m_programVec),end(m_programVec),[](uint& n){ glDeleteProgram(n); }); delete m_pRendererInfo; }
//-------------------------------------------------------------- // destructor SolarSystem::~SolarSystem() { deleteBuffers(); delete m_planet; m_planet = NULL; // delete m_belt; // m_belt = NULL; delete m_moon; m_moon = NULL; delete m_ring; m_ring = NULL; }
void PolygonalDrawable::setGeometry(PolygonalGeometry * geometry) { if(m_geometry) { m_geometry->parents().remove(this); if(m_geometry->parents().empty()) delete m_geometry; deleteBuffers(); } m_geometry = geometry; if(m_geometry) m_geometry->parents().insert(this); }
///Set the kernel to a 3x3 Laplace (-8 in the center, 1 everywhere else) void DKernel2D::setLaplace(){ int w, h; w = 3; h = 3; this->radiusX = 1; this->radiusY = 1; fSep = false; deleteBuffers(); allocBuffers(w,h); for(int idx = 0; idx < 9; ++idx){ rgData_dbl[idx] = 1.; rgData_flt[idx] = 1.; } rgData_dbl[4] = -8.; rgData_flt[4] = -8.; }
/**The internal data arrays are allocated and the values from rgData * are copied into the internal data arrays. The size of the buffers * depends on whether fIsSeparable is true or false. If fIsSeparable * is false, then the buffers hold w*h floats/doubles (multiply). If * fIsSeparable is true, then the buffers only hold w+h floats/doubles * (add). Not all kernels can be made separable, but if you use separable * kernels when possible, convolution is typically much faster. When * calling either setData function, the internal arrays for both float and * double values are allocated and initialized to the proper values. Both * functions are provided as a convenience to the caller so the data being * copied can be either float or double. * * For separable kernels, the horizontal component of the kernel is * first (w values), followed by the vertical component (h values). */ void DKernel2D::setData_dbl(double *rgData, int w, int h, bool fIsSeparable){ if((0 == (w & 1)) || (0 == (h & 1))){ fprintf(stderr, "DKernel2D::setData_dbl() w,h must be odd\n"); exit(1); } this->radiusX = w/2; this->radiusY = h/2; this->fSep = fIsSeparable; deleteBuffers(); allocBuffers(w,h); for(int y =0, idx=0; y < h; ++y){ for(int x = 0; x < w; ++x, ++idx){ rgData_flt[idx] = (float)(rgData[idx]); rgData_dbl[idx] = rgData[idx]; } } }
///Assignment from a DImage object (creates a kernel based on srcImg contents) const DKernel2D& DKernel2D::operator=(const DImage &srcImg){ int w, h; DImage imgDbl; double *pDataDbl; double *pDataDst; float *pDataFlt; if((0 == (srcImg.width() & 1)) || (0 == (srcImg.height() & 1))){ fprintf(stderr, "DKernel2D::operator=() source image w,h must be odd\n"); exit(1); } if(1 != srcImg.numChannels()){ fprintf(stderr, "DKernel2D::operator=() source image numChannels != 1\n"); exit(1); } if(srcImg.getImageType() == DImage::DImage_cmplx){ fprintf(stderr, "DKernel2D::operator=() DImage_cmplx not supported\n"); exit(1); } srcImg.convertedImgType_(imgDbl, DImage::DImage_dbl_multi, 1); pDataDbl = imgDbl.dataPointer_dbl(); fSep = false; radiusX = srcImg.width() / 2; radiusY = srcImg.height() / 2; numSigsX = DEFAULT_NUM_SIGMAS; numSigsY = DEFAULT_NUM_SIGMAS; w = 2*radiusX+1; h = 2*radiusY+1; deleteBuffers(); allocBuffers(w, h); pDataDst = rgData_dbl; pDataFlt = rgData_flt; for(int y = 0; y < h; ++y){ memcpy(pDataDst, pDataDbl, sizeof(double) * w); for(int x = 0; x < w; ++x) pDataFlt[x] = (float)(pDataDst[x]); pDataDst += w; pDataDbl += w; pDataFlt += w; } return *this; }
/**radiusX and radiusY specify how far the kernel extends from the central pixel. fSeparable specifies whether this should be a separable kernel, which allows dconvolver to perform convolution faster than standard non-separable convolution. The value of each pixel of the kernel is scaled equally so that the entire filter sums to 1. */ void DKernel2D::setRect(int radiusX, int radiusY, bool fSeparable){ int w, h; float fltVal; double dblVal; w = radiusX*2+1; h = radiusY*2+1; this->radiusX = radiusX; this->radiusY = radiusY; fSep = fSeparable; deleteBuffers(); allocBuffers(w,h); if(fSeparable){ dblVal = 1./w; fltVal = (float)dblVal; for(int x = 0; x < w; ++x){ rgSep_flt[x] = fltVal; rgSep_dbl[x] = dblVal; } dblVal = 1./h; fltVal = (float)dblVal; for(int y = 0; y < h; ++y){ rgSep_flt[w+y] = fltVal; rgSep_dbl[w+y] = dblVal; } } else{ dblVal = 1./(w*h); fltVal = (float)dblVal; for(int y = 0, idx = 0; y < h; ++y){ for(int x = 0; x < w; ++x, ++idx){ rgData_flt[idx] = fltVal; rgData_dbl[idx] = dblVal; } } } }
//-------------------------------------------------------------- // destructor Planet::~Planet() { deleteBuffers(); }
GeometryData::~GeometryData() { deleteBuffers(); }
PolygonalGeometry::~PolygonalGeometry() { DataBlock::destroyDataBlock<VertexList>(m_datablock); deleteBuffers(); }
//-------------------------------------------------------------- // destructor BrickBuffers::~BrickBuffers() { deleteBuffers(); }