GameObject::~GameObject() { for (const_comp_it it = m_pComponents.begin(); it != m_pComponents.end(); it++) { if ((*it)->GetType() == "CameraComponent") FreeAlignedMemory((*it)); else delete (*it); } if (m_pTransform) FreeAlignedMemory(m_pTransform); }
void StreamBuffer::Shutdown() { switch(m_uploadtype) { case MAP_AND_SYNC: for(u32 i=0; i<SYNC_POINTS; i++) glDeleteSync(fences[i]); delete [] fences; break; case MAP_AND_RISK: case MAP_AND_ORPHAN: case BUFFERSUBDATA: case BUFFERDATA: break; case PINNED_MEMORY: for(u32 i=0; i<SYNC_POINTS; i++) glDeleteSync(fences[i]); delete [] fences; glBindBuffer(m_buffertype, 0); glFinish(); // ogl pipeline must be flushed, else this buffer can be in use FreeAlignedMemory(pointer); break; case STREAM_DETECT: case DETECT_MASK: // Just to shutup warnings break; } }
TextureCache::~TextureCache() { HiresTexture::Shutdown(); Invalidate(); FreeAlignedMemory(temp); temp = nullptr; }
PC_TexFormat TextureCache::LoadCustomTexture(u64 tex_hash, int texformat, unsigned int level, unsigned int& width, unsigned int& height) { char texPathTemp[MAX_PATH]; unsigned int newWidth = 0; unsigned int newHeight = 0; if (level == 0) sprintf(texPathTemp, "%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32) (tex_hash & 0x00000000FFFFFFFFLL), texformat); else sprintf(texPathTemp, "%s_%08x_%i_mip%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32) (tex_hash & 0x00000000FFFFFFFFLL), texformat, level); unsigned int required_size = 0; PC_TexFormat ret = HiresTextures::GetHiresTex(texPathTemp, &newWidth, &newHeight, &required_size, texformat, temp_size, temp); if (ret == PC_TEX_FMT_NONE && temp_size < required_size) { // Allocate more memory and try again // TODO: Should probably check if newWidth and newHeight are texture dimensions which are actually supported by the current video backend temp_size = required_size; FreeAlignedMemory(temp); temp = (u8*)AllocateAlignedMemory(temp_size, 16); ret = HiresTextures::GetHiresTex(texPathTemp, &newWidth, &newHeight, &required_size, texformat, temp_size, temp); } if (ret != PC_TEX_FMT_NONE) { width = newWidth; height = newHeight; } return ret; }
~PinnedMemory() { DeleteFences(); glBindBuffer(m_buffertype, 0); glFinish(); // ogl pipeline must be flushed, else this buffer can be in use FreeAlignedMemory(m_pointer); m_pointer = nullptr; }
void TextureCache::CheckTempSize(size_t required_size) { if (required_size <= temp_size) return; temp_size = required_size; FreeAlignedMemory(temp); temp = (u8*)AllocateAlignedMemory(temp_size, 16); }
TextureCache::~TextureCache() { Invalidate(); if (temp) { FreeAlignedMemory(temp); temp = NULL; } }
void TextureCacheBase::CheckTempSize(size_t required_size) { if (required_size <= temp_size) return; temp_size = required_size; FreeAlignedMemory(temp); temp = static_cast<u8*>(AllocateAlignedMemory(temp_size, 16)); }
TextureCacheBase::~TextureCacheBase() { HiresTexture::Shutdown(); UnbindTextures(); Invalidate(); InvalidateHiresCache(); for (auto& rt : texture_pool) { delete rt.second; } texture_pool.clear(); texture_pool_memory_usage = 0; if (TextureCacheBase::temp) { FreeAlignedMemory(TextureCacheBase::temp); TextureCacheBase::temp = nullptr; } }
PC_TexFormat TextureCache::LoadCustomTexture(u64 tex_hash, int texformat, unsigned int level, unsigned int* widthp, unsigned int* heightp) { std::string texPathTemp; unsigned int newWidth = 0; unsigned int newHeight = 0; u32 tex_hash_u32 = tex_hash & 0x00000000FFFFFFFFLL; if (level == 0) texPathTemp = StringFromFormat("%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), tex_hash_u32, texformat); else texPathTemp = StringFromFormat("%s_%08x_%i_mip%u", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), tex_hash_u32, texformat, level); unsigned int required_size = 0; PC_TexFormat ret = HiresTextures::GetHiresTex(texPathTemp, &newWidth, &newHeight, &required_size, texformat, temp_size, temp); if (ret == PC_TEX_FMT_NONE && temp_size < required_size) { // Allocate more memory and try again // TODO: Should probably check if newWidth and newHeight are texture dimensions which are actually supported by the current video backend temp_size = required_size; FreeAlignedMemory(temp); temp = (u8*)AllocateAlignedMemory(temp_size, 16); ret = HiresTextures::GetHiresTex(texPathTemp, &newWidth, &newHeight, &required_size, texformat, temp_size, temp); } if (ret != PC_TEX_FMT_NONE) { unsigned int width = *widthp, height = *heightp; if (level > 0 && (newWidth != width || newHeight != height)) ERROR_LOG(VIDEO, "Invalid custom texture size %dx%d for texture %s. This mipmap layer _must_ be %dx%d.", newWidth, newHeight, texPathTemp.c_str(), width, height); if (newWidth * height != newHeight * width) ERROR_LOG(VIDEO, "Invalid custom texture size %dx%d for texture %s. The aspect differs from the native size %dx%d.", newWidth, newHeight, texPathTemp.c_str(), width, height); if (newWidth % width || newHeight % height) WARN_LOG(VIDEO, "Invalid custom texture size %dx%d for texture %s. Please use an integer upscaling factor based on the native size %dx%d.", newWidth, newHeight, texPathTemp.c_str(), width, height); *widthp = newWidth; *heightp = newHeight; } return ret; }
TextureCache::~TextureCache() { Invalidate(); FreeAlignedMemory(temp); temp = nullptr; }
void TransformUnit::SubmitSpline(void* control_points, void* indices, int count_u, int count_v, int type_u, int type_v, GEPatchPrimType prim_type, u32 vertex_type) { VertexDecoder vdecoder; VertexDecoderOptions options; memset(&options, 0, sizeof(options)); options.expandAllUVtoFloat = false; vdecoder.SetVertexType(vertex_type, options); const DecVtxFormat& vtxfmt = vdecoder.GetDecVtxFmt(); static u8 buf[65536 * 48]; // yolo u16 index_lower_bound = 0; u16 index_upper_bound = count_u * count_v - 1; bool indices_16bit = (vertex_type & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_16BIT; bool indices_32bit = (vertex_type & GE_VTYPE_IDX_MASK) == GE_VTYPE_IDX_32BIT; u8 *indices8 = (u8 *)indices; u16 *indices16 = (u16 *)indices; u32 *indices32 = (u32 *)indices; if (indices) GetIndexBounds(indices, count_u*count_v, vertex_type, &index_lower_bound, &index_upper_bound); vdecoder.DecodeVerts(buf, control_points, index_lower_bound, index_upper_bound); VertexReader vreader(buf, vtxfmt, vertex_type); int num_patches_u = count_u - 3; int num_patches_v = count_v - 3; if (patchBufferSize_ < num_patches_u * num_patches_v) { if (patchBuffer_) { FreeAlignedMemory(patchBuffer_); } patchBuffer_ = (SplinePatch *)AllocateAlignedMemory(num_patches_u * num_patches_v, 16); patchBufferSize_ = num_patches_u * num_patches_v; } SplinePatch *patches = patchBuffer_; for (int patch_u = 0; patch_u < num_patches_u; ++patch_u) { for (int patch_v = 0; patch_v < num_patches_v; ++patch_v) { SplinePatch& patch = patches[patch_u + patch_v * num_patches_u]; for (int point = 0; point < 16; ++point) { int idx = (patch_u + point%4) + (patch_v + point/4) * count_u; if (indices) { if (indices_32bit) { vreader.Goto(indices32[idx]); } else if (indices_16bit) { vreader.Goto(indices16[idx]); } else { vreader.Goto(indices8[idx]); } } else { vreader.Goto(idx); } patch.points[point] = ReadVertex(vreader); } patch.type = (type_u | (type_v<<2)); if (patch_u != 0) patch.type &= ~START_OPEN_U; if (patch_v != 0) patch.type &= ~START_OPEN_V; if (patch_u != num_patches_u-1) patch.type &= ~END_OPEN_U; if (patch_v != num_patches_v-1) patch.type &= ~END_OPEN_V; } } for (int patch_idx = 0; patch_idx < num_patches_u*num_patches_v; ++patch_idx) { SplinePatch& patch = patches[patch_idx]; // TODO: Should do actual patch subdivision instead of just drawing the control points! const int tile_min_u = (patch.type & START_OPEN_U) ? 0 : 1; const int tile_min_v = (patch.type & START_OPEN_V) ? 0 : 1; const int tile_max_u = (patch.type & END_OPEN_U) ? 3 : 2; const int tile_max_v = (patch.type & END_OPEN_V) ? 3 : 2; for (int tile_u = tile_min_u; tile_u < tile_max_u; ++tile_u) { for (int tile_v = tile_min_v; tile_v < tile_max_v; ++tile_v) { int point_index = tile_u + tile_v*4; VertexData v0 = patch.points[point_index]; VertexData v1 = patch.points[point_index+1]; VertexData v2 = patch.points[point_index+4]; VertexData v3 = patch.points[point_index+5]; // TODO: Backface culling etc Clipper::ProcessTriangle(v0, v1, v2); Clipper::ProcessTriangle(v2, v1, v0); Clipper::ProcessTriangle(v2, v1, v3); Clipper::ProcessTriangle(v3, v1, v2); } } } host->GPUNotifyDraw(); }
~PrecomputedCurves() { FreeAlignedMemory(horiz1); }