static VALUE fileIntForPath(const char *path, bool rubyExc) { SDL_RWops *ops = SDL_AllocRW(); try { shState->fileSystem().openRead(*ops, path); } catch (const Exception &e) { SDL_FreeRW(ops); if (rubyExc) raiseRbExc(e); else throw e; } VALUE klass = rb_const_get(rb_cObject, rb_intern("FileInt")); VALUE obj = rb_obj_alloc(klass); setPrivateData(obj, ops); return obj; }
static VALUE fileIntForPath(const char *path) { SDL_RWops *ops = SDL_AllocRW(); shState->fileSystem().openRead(*ops, path); VALUE klass = rb_const_get(rb_cObject, rb_intern("FileInt")); VALUE obj = rb_obj_alloc(klass); setPrivateData(obj, ops); return obj; }
bool D3D9texture::loadFile2D() { D3D9_SCOPELOCK; HRESULT hr; const byte_t* data; int flags = 0; if (!(m_initFlags.isSet(IF_NoMipmap))) flags |= Image::Mipmap; flags |= Image::ExpandAlpha; std::auto_ptr<Image> imagefile(new Image); if (!imagefile->loadFile(m_name, flags)) { // Debugf("D3D9texture::loadFile2D: can't find image file for %s\n", m_name.c_str()); return false; } m_width = imagefile->getWidth(); m_height = imagefile->getHeight(); // mDesc.format = imagefile->getFormat(); if (!Math::isPowerOfTwo(m_width) || !Math::isPowerOfTwo(m_height)) { // if (!(mDesc.flags & TexFlag_allowNPOT)) Errorf("GLtexture::loadFile2D: texture %s size isn't power of two", m_name.c_str()); // else // Debugf("GLtexture::loadFile2D: texture %s size isn't power of two\n", mDesc.name.c_str()); } m_format = imagefile->getFormat(); D3DFORMAT d3dformat; trTexFormat(imagefile->getFormat(), d3dformat); DWORD d3dusage = 0; int mipdown = image_mip->getInteger(); if (m_initFlags.isSet(IF_NoMipmap) || imagefile->getNumMipmapLevels() <= 1) { m_isMipmaped = false; mipdown = 0; } else { m_isMipmaped = true; mipdown = Math::clamp(mipdown, 0, imagefile->getNumMipmapLevels()-1); m_width >>= mipdown; m_height >>= mipdown; if (m_width < 1) m_width = 1; if (m_height < 1) m_height = 1; } // m_initFlags = 0; if (m_initFlags.isSet(Texture::IF_RenderTarget)) { Errorf("Can't load render target from a file"); } if (m_initFlags.isSet(Texture::IF_AutoGenMipmap)) { d3dusage |= D3DUSAGE_AUTOGENMIPMAP; m_isMipmaped = true; m_hardwareGenMipmap = checkIfSupportHardwareMipmapGeneration(d3dformat, d3dusage); if (!m_hardwareGenMipmap) { d3dusage &= ~D3DUSAGE_AUTOGENMIPMAP; } } if (m_object == 0) { V(d3d9Device->CreateTexture(m_width, m_height, !m_isMipmaped, d3dusage, d3dformat, D3DPOOL_MANAGED, &m_object, 0)); } int width, height; width = m_width; height = m_height; for (DWORD i = 0; i < m_object->GetLevelCount(); i++) { if (i + mipdown >= (DWORD)imagefile->getNumMipmapLevels()) { // if no image for this level, break break; } uint_t datasize = imagefile->getFormat().calculateDataSize(width, height); m_videoMemoryUsed += datasize; data = imagefile->getData(i + mipdown); #if 0 LPDIRECT3DSURFACE9 surface; V(m_object->GetSurfaceLevel(i, &surface)); D3DXLoadSurfaceFromMemory(surface, 0, 0, data, d3dformat, pitch, 0, rect, D3DX_FILTER_NONE, 0); #else D3DLOCKED_RECT lockedRect; V(m_object->LockRect(i, &lockedRect, 0, 0)); int mypitch = m_format.calculateDataSize(width, 1); if (mypitch != lockedRect.Pitch) { Errorf("mypitch != lockedRect.Pitch"); } memcpy(lockedRect.pBits, data, datasize); V(m_object->UnlockRect(i)); #endif width >>= 1; height >>= 1; if (width < 1) width = 1; if (height < 1) height = 1; if (m_initFlags.isSet(Texture::IF_AutoGenMipmap)) { // break; } } if (m_initFlags.isSet(Texture::IF_AutoGenMipmap)) { generateMipmap(); } if (m_isMipmaped) { setFilterMode(FM_Trilinear); } else { setFilterMode(FM_Linear); } setClampMode(CM_Repeat); setPrivateData(); g_statistic->addValue(stat_textureMemory, m_videoMemoryUsed); return true; }