QSharedPointer<QcTileTexture> QcFileTileCache::get(const QcTileSpec & tile_spec) { // Try texture cache QSharedPointer<QcTileTexture> tile_texture = m_texture_cache.object(tile_spec); if (tile_texture) return tile_texture; // Try memory cache QSharedPointer<QcCachedTileMemory> tile_memory = m_memory_cache.object(tile_spec); if (tile_memory) return load_from_memory(tile_memory); // Try disk cache QSharedPointer<QcCachedTileDisk> tile_directory = m_disk_cache.object(tile_spec); if (tile_directory) return load_from_disk(tile_directory->tile_spec, tile_directory->filename); // Try offline cache // QSharedPointer<QcOfflineCachedTileDisk> offline_tile = m_offline_cache->get(tile_spec); // if (offline_tile) { if (m_offline_cache->contains(tile_spec)) { QcOfflineCachedTileDisk offline_tile = m_offline_cache->get(tile_spec); // qInfo() << "In offline cache" << tile_spec; // return load_from_disk(offline_tile->tile_spec, offline_tile->filename); return load_from_disk(offline_tile.tile_spec, offline_tile.filename); } // else return QSharedPointer<QcTileTexture>(); }
model_renderer::model_renderer(const rtt::fbo* mesh_border_fbo, const rtt::fbo* mesh_push_fbo, const opencl::buffer_object* mb_cl_buffer, const opencl::buffer_object* mp_cl_buffer) : a2estatic(::e, ::s, ::sce) { unsigned int* index_count = new unsigned int[1]; index_count[0] = (unsigned int)bmodel->indices.size(); bindices = new index3*[1]; bindices[0] = (index3*)&bmodel->indices[0]; if(bmodel->indices_vbo == 0) { // model hasn't been loaded yet, do so now load_from_memory(1, (unsigned int)bmodel->vertices.size(), (float3*)&bmodel->vertices[0], (coord*)&bmodel->tex_coords[0], (unsigned int*)index_count, bindices); // set_position(0.0f, 0.0f, 0.0f); // create additional vbos/ubo const unsigned int bvertex_count = (unsigned int)bmodel->vertices.size(); glGenBuffers(1, &bmodel->weights_vbo); glBindBuffer(GL_ARRAY_BUFFER, bmodel->weights_vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(float4) * bvertex_count, &bmodel->bone_weights[0], GL_STATIC_DRAW); glGenBuffers(1, &bmodel->bone_indices_vbo); glBindBuffer(GL_ARRAY_BUFFER, bmodel->bone_indices_vbo); glBufferData(GL_ARRAY_BUFFER, sizeof(int4) * bvertex_count, &bmodel->bone_indices[0], GL_STATIC_DRAW); // update normals vbo (vbo has already been created) glBindBuffer(GL_ARRAY_BUFFER, vbo_normals_id); glBufferSubData(GL_ARRAY_BUFFER, 0, vertex_count * 3 * sizeof(float), &bmodel->normals[0]); glBindBuffer(GL_ARRAY_BUFFER, 0); // set bus_model vbos bmodel->indices_vbo = vbo_indices_ids[0]; bmodel->vertices_vbo = vbo_vertices_id; bmodel->tex_coords_vbo = vbo_tex_coords_id; bmodel->normals_vbo = vbo_normals_id; bmodel->binormals_vbo = vbo_binormals_id; bmodel->tangents_vbo = vbo_tangents_id; vbo_indices_ids[0] = 0; vbo_vertices_id = 0; vbo_tex_coords_id = 0; vbo_normals_id = 0; vbo_binormals_id = 0; vbo_tangents_id = 0; } // load a dummy material for now dummy_mat = new a2ematerial(e); dummy_mat->load_material(e->data_path("NI.a2mtl")); set_material(dummy_mat); // note: this will be updated dynamically glGenBuffers(1, &bones_ubo); glBindBuffer(GL_UNIFORM_BUFFER, bones_ubo); glBufferData(GL_UNIFORM_BUFFER, sizeof(bone_data), nullptr, GL_DYNAMIC_DRAW); glBindBuffer(GL_UNIFORM_BUFFER, 0); // create rtt buffers const int2 buffer_size(MESH_RTT_TEX_SIZE); mesh_fbo = r->add_buffer(buffer_size.x, buffer_size.y, GL_TEXTURE_2D, texture_object::TF_POINT, rtt::TAA_NONE, GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE, GL_RGBA32F, GL_RGBA, GL_FLOAT, 2, rtt::DT_NONE); cl_fbos[0] = ocl->create_ogl_image2d_buffer(opencl::BT_READ, mesh_fbo->tex_id[0]); cl_fbos[1] = ocl->create_ogl_image2d_buffer(opencl::BT_READ, mesh_fbo->tex_id[1]); cl_fbos[2] = (opencl::buffer_object*)mb_cl_buffer; cl_fbos[3] = (opencl::buffer_object*)mp_cl_buffer; // add particle systems particle_tex = t->add_texture(e->data_path("particle2.png"), e->get_filtering(), e->get_anisotropic(), GL_CLAMP_TO_EDGE, GL_CLAMP_TO_EDGE); aux_data.mesh_pos_tex = cl_fbos[0]; aux_data.mesh_normal_tex = cl_fbos[1]; aux_data.mesh_border_tex = cl_fbos[2]; aux_data.mesh_push_tex = cl_fbos[3]; aux_data.pos_normal_fbo = mesh_fbo; aux_data.border_fbo = (rtt::fbo*)mesh_border_fbo; aux_data.push_fbo = (rtt::fbo*)mesh_push_fbo; aux_data.ocl_aux_2 = nullptr; ps = pm->add_particle_system(particle_system::EMITTER_TYPE::BOX, particle_system::LIGHTING_TYPE::POINT_PP, particle_tex, 1024*32, 1000, 0.0f, // doesn't matter: <from here> float3(0.0f), float3(0.0f), float3(0.0f), float3(0.0f), float3(0.0f), float3(0.0f), // <to here> float4(1.0f, 1.0f, 1.0f, 1.0f), float2(0.075f), &aux_data); ps->set_sorting(false); // add a random player light static const float3 player_colors[] = { float3(1.0f, 0.0f, 0.0f), float3(0.0f, 1.0f, 0.0f), float3(0.0f, 0.0f, 1.0f), float3(1.0f, 1.0f, 0.0f), float3(0.0f, 0.4f, 0.8f), }; static const size_t player_color_count = A2E_ARRAY_LENGTH(player_colors); const size_t light_num = AtomicFetchThenIncrement(&color_cycle) % player_color_count; for(size_t i = 0; i < 1; i++) { light* l = new light(e, 0.0f, 8.0f, 0.0f); l->set_radius(24.0f); l->set_color(player_colors[light_num]); sce->add_light(l); lights.push_back(l); } ps->set_lights(lights); // draw setup (only needs to be done once) draw_vertices_vbo = bmodel->vertices_vbo; draw_tex_coords_vbo = bmodel->tex_coords_vbo; draw_normals_vbo = bmodel->normals_vbo; draw_binormals_vbo = bmodel->binormals_vbo; draw_tangents_vbo = bmodel->tangents_vbo; draw_indices_vbo = bmodel->indices_vbo; draw_index_count = index_count[0] * 3; // add to scene sce->add_model(this); }