bool CBitmapClass::initialize(ID3D11Device* device, int screenWidth, int screenHeight, WCHAR* textureFilename, int bitmapWidth, int bitmapHeight) { bool result; //Guardamos el tamaño de la pantalla m_screenWidth = screenWidth; m_screenHeight = screenHeight; //Colocamos el tamaño del bitmap m_bitmapWidth = bitmapWidth; m_bitmapHeight = bitmapHeight; //y colocamos la ultima posicion de la imagen m_previousPosX = -1; m_previousPosY = -1; //Inicializamos los buffers para colocar informacion en ellos result = initializeBuffers(device); if (!result) { return false; } //Cargamos las texturas result = LoadTexture(device, textureFilename); if (!result) { return false; } return true; }
/** Reset simulation method * * This Method reset all simulation. It's reiniting all buffers with * new start configuration and restart simulation. * NOTE: this method reiniting only buffers not a kernels an so one. * * @param position_cpp * initial position buffer * @param velocity_cpp * initial velocity buffer * @param config * Contain information about simulating configuration * @param elasticConnectionData_cpp * buffer with info about elastic connections * @param membraneData_cpp * buffer with info about membranes * @param particleMembranesList_cpp * buffer with info about sets of membranes in which particular particle is including */ void owOpenCLSolver::reset(const float * position_cpp, const float * velocity_cpp, owConfigProperty * config, const float * elasticConnectionsData_cpp, const int * membraneData_cpp, const int * particleMembranesList_cpp){ // Reinitializing all data buffer // First freed data for buffer _particleIndex and gridNextNonEmptyCellBuffer destroy(); // Clear buffers before relocate it again this is needed because simulation can run different configuration initializeBuffers(position_cpp,velocity_cpp, config, elasticConnectionsData_cpp, membraneData_cpp, particleMembranesList_cpp); }
/** Constructor of class owOpenCLSolver * * @param position_cpp * initial position buffer * @param velocity_cpp * initial velocity buffer * @param config * Contain information about simulating configuration * @param elasticConnectionData_cpp * buffer with info about elastic connections * @param membraneData_cpp * buffer with info about membranes * @param particleMembranesList_cpp * buffer with info about sets of membranes in which particular particle is including */ owOpenCLSolver::owOpenCLSolver(const float * position_cpp, const float * velocity_cpp, owConfigProperty * config, const float * elasticConnectionsData_cpp, const int * membraneData_cpp, const int * particleMembranesList_cpp) { try{ initializeOpenCL(config); // Create OpenCL buffers initializeBuffers(position_cpp, velocity_cpp, config, elasticConnectionsData_cpp, membraneData_cpp, particleMembranesList_cpp); // Create OpenCL kernels create_ocl_kernel("clearBuffers", clearBuffers); create_ocl_kernel("findNeighbors", findNeighbors); create_ocl_kernel("hashParticles", hashParticles); create_ocl_kernel("indexx", indexx); create_ocl_kernel("sortPostPass", sortPostPass); // Additional PCISPH-related kernels create_ocl_kernel("pcisph_computeForcesAndInitPressure", pcisph_computeForcesAndInitPressure); create_ocl_kernel("pcisph_integrate", pcisph_integrate); create_ocl_kernel("pcisph_predictPositions", pcisph_predictPositions); create_ocl_kernel("pcisph_predictDensity", pcisph_predictDensity); create_ocl_kernel("pcisph_correctPressure", pcisph_correctPressure); create_ocl_kernel("pcisph_computePressureForceAcceleration", pcisph_computePressureForceAcceleration); create_ocl_kernel("pcisph_computeDensity", pcisph_computeDensity); create_ocl_kernel("pcisph_computeElasticForces", pcisph_computeElasticForces); // membrane handling kernels create_ocl_kernel("clearMembraneBuffers",clearMembraneBuffers); create_ocl_kernel("computeInteractionWithMembranes",computeInteractionWithMembranes); create_ocl_kernel("computeInteractionWithMembranes_finalize",computeInteractionWithMembranes_finalize); }catch(std::runtime_error & ex){ destroy(); throw ex; } }
/** * @brief Default constructor. * @param shader_dir Given directory containing trackball shaders, optional, otherwise uses default shaders. */ Trackball (string shader_dir = "") { // creates the mesh that will be used to represent the trackball's sphere. createTrackballRepresentation(); // initialize the shader used for trackball rendering: if (shader_dir.empty()) { trackball_shader.setShaderName("trackballShader"); use_default_shaders = true; } else { trackball_shader.load("trackballShader", shader_dir); use_default_shaders = false; } // initialize buffers used for trackball rendering: bufferIDs = new GLuint[3]; defaultTranslation << 0.0, 0.0, -4.0; zoom = 1.0; drawTrackball = true; radius = 0.8f; initGL(); initOpenGLMatrices(); initializeBuffers(); loadShader(); reset(); }
bool BitmapClass::initialize( ID3D11Device *aD3DDevice, int aWidth, int aHeight, WCHAR *aTextureFileName, int aBitmapWidth, int aBitmapHeight ) { bool result; m_screenWidth = aWidth; m_screenHeight = aHeight; m_bitmapWidth = aBitmapWidth; m_bitmapHeight = aBitmapHeight; m_previousPosX = -1; m_previousPosY = -1; result = initializeBuffers(aD3DDevice); if (!result) { return false; } result = loadTexture(aD3DDevice, aTextureFileName); if (!result) { return false; } return true; }
VboMesh::VboMesh( size_t numVertices, size_t numIndices, Layout layout, GLenum primitiveType, Vbo *indexBuffer, Vbo *staticBuffer, Vbo *dynamicBuffer ) : mObj( shared_ptr<Obj>( new Obj ) ) { mObj->mLayout = layout; mObj->mPrimitiveType = primitiveType; mObj->mNumIndices = numIndices; mObj->mNumVertices = numVertices; if( indexBuffer ) { mObj->mBuffers[INDEX_BUFFER] = *indexBuffer; if( indexBuffer->getTarget() != GL_ELEMENT_ARRAY_BUFFER ) throw VboInvalidTargetExc(); } if( staticBuffer ) { mObj->mBuffers[STATIC_BUFFER] = *staticBuffer; if( staticBuffer->getTarget() != GL_ARRAY_BUFFER ) throw VboInvalidTargetExc(); } if( dynamicBuffer ) { mObj->mBuffers[DYNAMIC_BUFFER] = *dynamicBuffer; if( dynamicBuffer->getTarget() != GL_ARRAY_BUFFER ) throw VboInvalidTargetExc(); } initializeBuffers( true ); unbindBuffers(); }
bool CResultObject::initialize(ID3D11Device* device, HWND hWnd) { if (pTemp_Device != device) { pTemp_Device = device; IsInit = false; } if (textureFilename.empty() == true) { //char *playernum = textureFilename = resultTextureDefault; textureFilename += std::to_wstring(winPlayerNum); textureFilename += L".png"; } if (IsInit == true) return true; createObject(); loadTexture(); createShader(); bool result = initializeBuffers(device); if (result == true) IsInit = true; return result; }
void SpriteBatch::initialize() { initializeShader(); initializeBuffers(); //initializeProjectionTransform(); initializeSprites(); }
GLuint Mesh::getIBO(){ if(ibo_name_ != 0){ return ibo_name_; } if(vertices_ == nullptr || indices_ == nullptr){ return 0; } initializeBuffers(); return ibo_name_; }
// Shaded OpenGL drawing: only draw spheres void Scene_polylines_item::draw(CGAL::Three::Viewer_interface* viewer) const { if(!are_buffers_filled) { computeElements(); initializeBuffers(viewer); } if(d->draw_extremities) { Scene_group_item::draw(viewer); } }
bool ModelClass::initialize( ID3D11Device *aD3DDevice, WCHAR *aFileName ) { bool result; result = initializeBuffers(aD3DDevice); result = loadTexture(aD3DDevice, aFileName); if (!result) { return false; } return result; }
VboMesh::VboMesh( size_t numVertices, size_t numIndices, Layout layout, GLenum primitiveType ) : mObj( shared_ptr<Obj>( new Obj ) ) { mObj->mLayout = layout; mObj->mPrimitiveType = primitiveType; mObj->mNumIndices = numIndices; mObj->mNumVertices = numVertices; initializeBuffers( true ); // allocate buffer for indices if( mObj->mLayout.hasIndices() ) mObj->mBuffers[INDEX_BUFFER].bufferData( sizeof(uint32_t) * mObj->mNumIndices, NULL, (mObj->mLayout.hasStaticIndices()) ? GL_STATIC_DRAW : GL_STREAM_DRAW ); unbindBuffers(); }
bool Model_TexturedNM::Initialize( const PrimitiveFactory & PrimMaker, const Graphics & Gfx ) { // Set the stride for this model type m_Stride = sizeof( VertexBufferTypeAllInOneNMap ); // Create the vertex array. auto vertPosition = PrimMaker.GetVertices(); // Set the number of verticex indices in the vertex array. m_vertexCount = vertPosition.size(); m_indexCount = vertPosition.size(); // Get the color auto color = PrimMaker.GetColor(); // Get the texture coordinates auto uvs = PrimMaker.GetUVs(); // Get normals auto normals = PrimMaker.GetNormals(); // Get precalculated Tangent, biTangent and CoNormal auto tangent = PrimMaker.GetTangent(); auto binormal = PrimMaker.GetBiTangent(); // TODO: later add functionality to deal w files w NO normals // Load the vertex buffer array with data. std::vector<VertexBufferTypeAllInOneNMap> pVertices( m_vertexCount ); for( UINT idx = 0; idx < m_vertexCount; ++idx ) { pVertices[ idx ].color = color; pVertices[ idx ].position = vertPosition[ idx ]; pVertices[ idx ].uv = uvs[ idx ]; pVertices[ idx ].tangent = tangent[ idx ]; pVertices[ idx ].binormal = binormal[ idx ]; pVertices[ idx ].normal = normals[ idx ]; } // Load the index array with data. auto indices = PrimMaker.GetIndices(); // Set the number of indices in the index array. m_indexCount = indices.size(); // use vertex and index arrays to create the vertex and index buffers. bool result = initializeBuffers( pVertices.data(), indices.data(), Gfx ); RETURN_MESSAGE_IF_FALSE( result, L"Could not initialize the model's buffers." ); return true; }
bool DiffuseModel::initialize(const char * i_textureFileName) { bool result; // Initialize the vertex and index buffers. result = initializeBuffers(); if (!result) { return false; } // Load the texture for this model. result = loadTexture( i_textureFileName); if (!result) { return false; } return true; }
// Wireframe OpenGL drawing void Scene_polylines_item::drawEdges(CGAL::Three::Viewer_interface* viewer) const { if(!are_buffers_filled) { computeElements(); initializeBuffers(viewer); } vaos[Edges]->bind(); attribBuffers(viewer, PROGRAM_NO_SELECTION); QOpenGLShaderProgram *program = getShaderProgram(PROGRAM_NO_SELECTION); program->bind(); program->setAttributeValue("colors", this->color()); viewer->glDrawArrays(GL_LINES, 0, static_cast<GLsizei>(nb_lines/4)); program->release(); vaos[Edges]->release(); if(d->draw_extremities) { Scene_group_item::drawEdges(viewer); } }
void module_video_camera::worker() { CvCapture* capture = cvCreateCameraCapture(0);//cvCaptureFromCAM(0); if(!capture || currentTask() != INITIALIZE_CAPTURE){ message = "module||ERROR! Cannot initialize camera!!"; addTask(CLEANUP_CAPTURE); return; } else message = ""; IplImage *frame; Tasks task = INITIALIZE_CAPTURE; while( task != TERMINATE_CAPTURE ){ // Fetch a frame if its asked for / couldnt fetch a previous frame / is the first time. if( task == FETCH_FRAME || task == IGNORE_FRAME || task == INITIALIZE_CAPTURE ){ frame = cvQueryFrame(capture); if(frame){ if( !m_bufferReady ) initializeBuffers(frame->width,frame->height, frame->depth, frame->nChannels); cvConvertImage(frame,m_buffer[nextPage()], CV_CVTIMG_SWAP_RB); addTask(CONSUME_FRAME); } else addTask(IGNORE_FRAME); } usleep(10); task = currentTask(); } //Cleanup cvReleaseCapture(&capture); freeBuffers(); addTask(CLEANUP_CAPTURE); }
VboMesh::VboMesh( const TriMesh2d &triMesh, Layout layout ) : mObj( shared_ptr<Obj>( new Obj ) ) { if( layout.isDefaults() ) { // we need to start by preparing our layout if( triMesh.hasColorsRgb() ) mObj->mLayout.setStaticColorsRGB(); if( triMesh.hasColorsRgba() ) mObj->mLayout.setStaticColorsRGBA(); if( triMesh.hasTexCoords() ) mObj->mLayout.setStaticTexCoords2d(); mObj->mLayout.setStaticIndices(); mObj->mLayout.setStaticPositions(); } else mObj->mLayout = layout; mObj->mPrimitiveType = GL_TRIANGLES; mObj->mNumIndices = triMesh.getNumIndices(); mObj->mNumVertices = triMesh.getNumVertices(); initializeBuffers( false ); // upload the indices getIndexVbo().bufferData( sizeof(uint32_t) * triMesh.getNumIndices(), &(triMesh.getIndices()[0]), (mObj->mLayout.hasStaticIndices()) ? GL_STATIC_DRAW : GL_STREAM_DRAW ); // upload the verts for( int buffer = STATIC_BUFFER; buffer <= DYNAMIC_BUFFER; ++buffer ) { if( ! mObj->mBuffers[buffer] ) continue; uint8_t *ptr = mObj->mBuffers[buffer].map( GL_WRITE_ONLY ); bool copyPosition = ( buffer == STATIC_BUFFER ) ? mObj->mLayout.hasStaticPositions() : mObj->mLayout.hasDynamicPositions(); bool copyColorRGB = ( ( buffer == STATIC_BUFFER ) ? mObj->mLayout.hasStaticColorsRGB() : mObj->mLayout.hasDynamicColorsRGB() ) && triMesh.hasColorsRgb(); bool copyColorRGBA = ( ( buffer == STATIC_BUFFER ) ? mObj->mLayout.hasStaticColorsRGBA() : mObj->mLayout.hasDynamicColorsRGBA() ) && triMesh.hasColorsRgba(); bool copyTexCoord2D = ( ( buffer == STATIC_BUFFER ) ? mObj->mLayout.hasStaticTexCoords2d() : mObj->mLayout.hasDynamicTexCoords2d() ) && triMesh.hasTexCoords(); for( size_t v = 0; v < mObj->mNumVertices; ++v ) { if( copyPosition ) { const Vec2f &p = triMesh.getVertices()[v]; *(reinterpret_cast<Vec3f*>(ptr)) = Vec3f( p.x, p.y, 0 ); ptr += sizeof( Vec3f ); } if( copyColorRGB ) { *(reinterpret_cast<Color*>(ptr)) = triMesh.getColorsRGB()[v]; ptr += sizeof( Color ); } if( copyColorRGBA ) { *(reinterpret_cast<ColorA*>(ptr)) = triMesh.getColorsRGBA()[v]; ptr += sizeof( Color ); } if( copyTexCoord2D ) { *(reinterpret_cast<Vec2f*>(ptr)) = triMesh.getTexCoords()[v]; ptr += sizeof( Vec2f ); } } mObj->mBuffers[buffer].unmap(); } unbindBuffers(); }