示例#1
0
status_t
BPrinter::SetTo(const node_ref& nodeRef)
{
	SetTo(BDirectory(&nodeRef));
	return InitCheck();
}
示例#2
0
void
DecorInfo::_Init(bool isUpdate)
{
	if (!isUpdate && InitCheck() != B_NO_INIT) {
		// TODO: remove after validation
		fprintf(stderr, "DecorInfo::_Init()\tImproper init state\n");
		return;
	}

	BEntry entry;

	if (fPath == "Default") {
		if (isUpdate) {
			// should never happen
			fprintf(stderr, "DecorInfo::_Init(true)\tBUG BUG updating default"
				"decorator!?!?!\n");
			return;
		}

		fAuthors = "DarkWyrm, Stephan Aßmus, Clemens Zeidler, Ingo Weinhold";
		fLongDescription = fShortDescription;
		fLicenseURL = "http://";
		fLicenseName = "MIT";
		fSupportURL = "http://www.haiku-os.org/";
		fVersion = 0.5;
		fInitStatus = B_OK;

		fName = gSystemCatalog.GetString(B_TRANSLATE_MARK("Default"),
			B_TRANSLATION_CONTEXT);
		fShortDescription = gSystemCatalog.GetString(B_TRANSLATE_MARK(
				"Default Haiku window decorator."),
			B_TRANSLATION_CONTEXT);

		// The following is to get the modification time of the app_server
		// and, thusly, the Default decorator...
		// If you can make it more simple, please do!
		BPath path;
		find_directory(B_SYSTEM_SERVERS_DIRECTORY, &path);
		path.Append("app_server");
		entry.SetTo(path.Path(), true);
		if (!entry.Exists()) {
			fprintf(stderr, "Server MIA the world has become its slave! "
				"Call the CIA!\n");
			return;
		}

		entry.GetModificationTime(&fModificationTime);
		return;
	}

	// Is a file system object...

	entry.SetTo(&fRef, true);	// follow link
	if (entry.InitCheck() != B_OK) {
		fInitStatus = entry.InitCheck();
		return;
	}

	if (!entry.Exists()) {
		if (isUpdate) {
			fprintf(stderr, "DecorInfo::_Init()\tERROR: decorator deleted"
					" after CheckForChanges() found it!\n");
			fprintf(stderr, "DecorInfo::_Init()\tERROR: DecorInfo will "
					"Unset\n");
			Unset();
		}
		return;
	}

	// update fRef to match file system object
	entry.GetRef(&fRef);
	entry.GetModificationTime(&fModificationTime);

	BResources resources(&fRef);
	if (resources.InitCheck() != B_OK) {
		fprintf(stderr, "DecorInfo::_Init()\t BResource InitCheck() failure\n");
		return;
	}

	size_t infoSize = 0;
	const void* infoData = resources.LoadResource(B_MESSAGE_TYPE,
		"be:decor:info", &infoSize);
	BMessage infoMessage;

	if (infoData == NULL || infoSize == 0
		|| infoMessage.Unflatten((const char*)infoData) != B_OK) {
		fprintf(stderr, "DecorInfo::_init()\tNo extended information found for"
			" \"%s\"\n", fRef.name);
	} else {
		infoMessage.FindString("name", &fName);
		infoMessage.FindString("authors", &fAuthors);
		infoMessage.FindString("short_descr", &fShortDescription);
		infoMessage.FindString("long_descr", &fLongDescription);
		infoMessage.FindString("lic_url", &fLicenseURL);
		infoMessage.FindString("lic_name", &fLicenseName);
		infoMessage.FindString("support_url", &fSupportURL);
		infoMessage.FindFloat ("version", &fVersion);
	}

	fInitStatus = B_OK;
	fName = fRef.name;
}
示例#3
0
SmallResourceData::~SmallResourceData()
{
	if (InitCheck() == B_OK)
		free(fBuffer);
}
示例#4
0
// DefaultFractionDigits
int32
BCurrency::DefaultFractionDigits() const
{
	return (InitCheck() == B_OK ? fDefaultFractionDigits : 0);
}
示例#5
0
/*! \brief Allocates the next available extent of given length.

	\param length The desired length (in bytes) of the extent.
	\param contiguous If false, signals that an extent of shorter length will
	                  be accepted. This allows for small chunks of
	                  unallocated space to be consumed, provided a
	                  contiguous chunk is not needed.
	\param extent Output parameter into which the extent as allocated
	              is stored. Note that the length field of the extent
	              may be shorter than the length parameter passed
	              to this function is \a contiguous is false.
	\param minimumStartingBlock The minimum acceptable starting block
	                            for the extent (used by the physical
	                            partition allocator).

	\return
	- B_OK: Success.
	- error code: Failure.
*/
status_t
Allocator::GetNextExtent(uint32 _length, bool contiguous,
                         Udf::extent_address &extent,
                         uint32 minimumStartingBlock)
{
    DEBUG_INIT_ETC("Allocator", ("length: %lld, contiguous: %d", _length, contiguous));
    uint32 length = BlocksFor(_length);
    bool isPartial = false;
    status_t error = InitCheck();
    PRINT(("allocation length: %lu\n", Length()));
    if (!error) {
        for (list<Udf::extent_address>::iterator i = fChunkList.begin();
                i != fChunkList.end();
                i++)
        {
            uint32 chunkOffset = i->location();
            uint32 chunkLength = BlocksFor(i->length());
            if (chunkOffset < minimumStartingBlock)
            {
                if (minimumStartingBlock < chunkOffset+chunkLength) {
                    // Start of chunk is below min starting block. See if
                    // any part of the chunk would make for an acceptable
                    // allocation
                    uint32 difference = minimumStartingBlock - chunkOffset;
                    uint32 newOffset = minimumStartingBlock;
                    uint32 newLength = chunkLength-difference;
                    if (length <= newLength) {
                        // new chunk is still long enough
                        Udf::extent_address newExtent(newOffset, _length);
                        if (GetExtent(newExtent) == B_OK) {
                            extent = newExtent;
                            return B_OK;
                        }
                    } else if (!contiguous) {
                        // new chunk is too short, but we're allowed to
                        // allocate a shorter extent, so we'll do it.
                        Udf::extent_address newExtent(newOffset, newLength<<BlockShift());
                        if (GetExtent(newExtent) == B_OK) {
                            extent = newExtent;
                            return B_OK;
                        }
                    }
                }
            } else if (length <= chunkLength) {
                // Chunk is larger than necessary. Allocate first
                // length blocks, and resize the chunk appropriately.
                extent.set_location(chunkOffset);
                extent.set_length(_length);
                if (length != chunkLength) {
                    i->set_location(chunkOffset+length);
                    i->set_length((chunkLength-length)<<BlockShift());
                } else {
                    fChunkList.erase(i);
                }
                return B_OK;
            } else if (!contiguous) {
                extent.set_location(chunkOffset);
                extent.set_length(chunkLength<<BlockShift());
                fChunkList.erase(i);
                return B_OK;
            }
        }
        // No sufficient chunk found, so try to allocate from the tail
        PRINT(("ULONG_MAX: %lu\n", ULONG_MAX));
        uint32 maxLength = ULONG_MAX-Length();
        PRINT(("maxLength: %lu\n", maxLength));
        error = maxLength > 0 ? B_OK : B_DEVICE_FULL;
        if (!error) {
            if (minimumStartingBlock > Tail())
                maxLength -= minimumStartingBlock - Tail();
            uint32 tail = minimumStartingBlock > Tail() ? minimumStartingBlock : Tail();
            if (length > maxLength) {
                if (contiguous)
                    error = B_DEVICE_FULL;
                else {
                    isPartial = true;
                    length = maxLength;
                }
            }
            if (!error) {
                Udf::extent_address newExtent(tail, isPartial ? length<<BlockShift() : _length);
                if (GetExtent(newExtent) == B_OK) {
                    extent = newExtent;
                    return B_OK;
                }
            }
        }
    }
    return error;
}
示例#6
0
// CurrencyCode
const char *
BCurrency::CurrencyCode() const
{
	return (InitCheck() == B_OK ? fCurrencyCode.String() : NULL);
}
示例#7
0
// DefaultSymbol
const char *
BCurrency::DefaultSymbol() const
{
	return (InitCheck() == B_OK ? fDefaultSymbol.String() : NULL);
}
示例#8
0
status_t
AudioVolumeConverter::Read(void* buffer, int64 pos, int64 frames)
{
	TRACE("AudioVolumeConverter::Read(%p, %lld, %lld)\n", buffer, pos, frames);
	status_t error = InitCheck();
	if (error != B_OK) {
		TRACE("AudioVolumeConverter::Read() done 1\n");
		return error;
	}
	pos += fOutOffset;

	status_t ret = fSource->Read(buffer, pos, frames);
	if (fPreviousVolume == 1.0 && fVolume == 1.0) {
		TRACE("AudioVolumeConverter::Read() done 2\n");
		return ret;
	}

	int32 channelCount = fFormat.u.raw_audio.channel_count;
	int32 samples = frames * channelCount;

	// apply volume
	switch (fSource->Format().u.raw_audio.format) {
		case media_raw_audio_format::B_AUDIO_FLOAT:
			if (fVolume != fPreviousVolume) {
				convert((float*)buffer, frames, channelCount,
					fPreviousVolume, fVolume, 0.0);
			} else
				convert((float*)buffer, samples, fVolume, 0.0);
			break;
		case media_raw_audio_format::B_AUDIO_INT:
			if (fVolume != fPreviousVolume) {
				convert((int32*)buffer, frames, channelCount,
					fPreviousVolume, fVolume, 0.5);
			} else
				convert((int32*)buffer, samples, fVolume, 0.5);
			break;
		case media_raw_audio_format::B_AUDIO_SHORT:
			if (fVolume != fPreviousVolume) {
				convert((int16*)buffer, frames, channelCount,
					fPreviousVolume, fVolume, 0.5);
			} else
				convert((int16*)buffer, samples, fVolume, 0.5);
			break;
		case media_raw_audio_format::B_AUDIO_UCHAR: {
			// handle this extra, because center != 0
			// (also ignores ramping the volume)
			uchar* b = (uchar*)buffer;
			for (int32 i = 0; i < samples; i++) {
				*b = (uchar)(((float)*b - 128) * fVolume + 128.5);
				b++;
			}
			break;
		}
		case media_raw_audio_format::B_AUDIO_CHAR:
			if (fVolume != fPreviousVolume) {
				convert((int8*)buffer, frames, channelCount,
					fPreviousVolume, fVolume, 0.0);
			} else
				convert((int8*)buffer, samples, fVolume, 0.5);
			break;
	}

	fPreviousVolume = fVolume;

	TRACE("AudioVolumeConverter::Read() done\n");
	return B_OK;
}
示例#9
0
文件: File.cpp 项目: mmanley/Antares
/*!	\brief Returns whether the file is writable.
	\return
	- \c true, if the BFile has been initialized properly and the file has
	  been opened for writing,
	- \c false, otherwise.
*/
bool
BFile::IsWritable() const
{
	return InitCheck() == B_OK
		&& ((fMode & O_RWMASK) == O_WRONLY || (fMode & O_RWMASK) == O_RDWR);
}
示例#10
0
status_t
AudioResampler::Read(void* buffer, int64 pos, int64 frames)
{
	TRACE("AudioResampler::Read(%p, %Ld, %Ld)\n", buffer, pos, frames);

	status_t error = InitCheck();
	if (error != B_OK) {
		TRACE("AudioResampler::Read() done1\n");
		return error;
	}
	// calculate position and frames in the source data
	int64 sourcePos = ConvertToSource(pos);
	int64 sourceFrames = ConvertToSource(pos + frames) - sourcePos;
	// check the frame counts
	if (sourceFrames == frames) {
		TRACE("AudioResampler::Read() done2\n");
		return fSource->Read(buffer, sourcePos, sourceFrames);
	}
	if (sourceFrames == 0) {
		ReadSilence(buffer, frames);
		TRACE("AudioResampler::Read() done3\n");
		return B_OK;
	}
	// check, if playing backwards
	bool backward = false;
	if (sourceFrames < 0) {
		sourceFrames = -sourceFrames;
		sourcePos -= sourceFrames;
		backward = true;
	}

	// we need at least two frames to interpolate
	sourceFrames += 2;
	int32 sampleSize = media_raw_audio_format::B_AUDIO_SIZE_MASK;
	uint32 channelCount = fFormat.u.raw_audio.channel_count;
	char* inBuffer = new char[sourceFrames * channelCount * sampleSize];
	error = fSource->Read(inBuffer, sourcePos, sourceFrames);
	if (error != B_OK) {
		TRACE("AudioResampler::_ReadLinear() done4\n");
		return error;
	}
	double inFrameRate = fSource->Format().u.raw_audio.frame_rate;
	double outFrameRate = (double)fFormat.u.raw_audio.frame_rate
		/ (double)fTimeScale;
	// choose the sample buffer to be used
	switch (fFormat.u.raw_audio.format) {
		case media_raw_audio_format::B_AUDIO_FLOAT:
			resample_linear< FloatSampleBuffer<double> >(inBuffer, buffer,
				channelCount, inFrameRate, outFrameRate, (int32)frames);
			break;
		case media_raw_audio_format::B_AUDIO_INT:
			resample_linear< IntSampleBuffer<double> >(inBuffer, buffer,
				channelCount, inFrameRate, outFrameRate, (int32)frames);
			break;
		case media_raw_audio_format::B_AUDIO_SHORT:
			resample_linear< ShortSampleBuffer<double> >(inBuffer, buffer,
				channelCount, inFrameRate, outFrameRate, (int32)frames);
			break;
		case media_raw_audio_format::B_AUDIO_UCHAR:
			resample_linear< UCharSampleBuffer<double> >(inBuffer, buffer,
				channelCount, inFrameRate, outFrameRate, (int32)frames);
			break;
		case media_raw_audio_format::B_AUDIO_CHAR:
			resample_linear< CharSampleBuffer<double> >(inBuffer, buffer,
				channelCount, inFrameRate, outFrameRate, (int32)frames);
			break;
	}
	// reverse the frame order if reading backwards
	if (backward)
		ReverseFrames(buffer, frames);
	delete[] inBuffer;
	TRACE("AudioResampler::Read() done\n");
	return B_OK;
}
//	ファイルから読み込み
//	カラーキーはアルファ未使用のときのみ有効
//	カラーキーを使用したくない場合はcolorKeyを0に
//	カラーキーを有効にしたい場合は0xff******にする
void CMglImage::CreateFromFile( LPCSTR szFileName, BOOL bRenderTarget, D3DCOLOR colorKey )
{
	_MGL_DEBUGLOG( "+ CMglImage::CreateFromFile( \"%s\", %d, 0x%08X )", szFileName, bRenderTarget, colorKey );

	InitCheck();	//	初期化チェック

	//	二回目以降の呼び出しを考慮し一端Release
	Release();

	//////////////////////////////////////////////////////////////////////////////
	//
	//	D3DXGetImageInfoFromFile()が無いので無理矢理サイズ取得です。あほくせぇ(´Д`)
	//

	IDirect3DTexture8* m_pTexture2;	//	テクスチャ
	D3DXIMAGE_INFO imgInfo;

	MyuAssert( D3DXCreateTextureFromFileEx( d3d, szFileName, 256, 256, D3DX_DEFAULT,
		0, /* m_myudg->backBufferDesc.Format */ m_myudg->GetFormat(), D3DPOOL_SYSTEMMEM,
		D3DX_FILTER_POINT, D3DX_FILTER_POINT, colorKey, &imgInfo, NULL, &m_pTexture2 ),
		D3D_OK, "CMglImage::CreateFromFile()  %s のイメージ情報取得に失敗。", szFileName );

	int x = imgInfo.Width;
	int y = imgInfo.Height;

	SAFE_RELEASE( m_pTexture2 );

	///////////////////////////////////////////////////////////////////
	//
	//	テクスチャを作成する
	//
	//	D3DXCreateTextureFromFileEx()にて作成を行うが、
	//	これはあくまでカラーキーを設定するためだけ。
	//	なお、画像は引き伸ばされて飲まれるので、後々再読み込みする
	//

	if ( bRenderTarget == TRUE ) {
		DWORD r = D3DXCreateTextureFromFileEx( d3d, szFileName, x, y, D3DX_DEFAULT,
			D3DUSAGE_RENDERTARGET, /* m_myudg->backBufferDesc.Format */ m_myudg->GetFormat(), D3DPOOL_DEFAULT,
			D3DX_FILTER_POINT, D3DX_FILTER_POINT, colorKey, &imgInfo, NULL, &m_pTexture );

		if ( r == E_OUTOFMEMORY )
			MyuThrow2( r, 0x0201, "%s の読み込みに失敗。VRAMまたはメモリが不足しています。", szFileName );
		else if ( r == D3DERR_OUTOFVIDEOMEMORY )
			MyuThrow2( r, 0x0202, "%s の読み込みに失敗。VRAMが不足しています。", szFileName );
		else if ( r != S_OK ) 
			MyuThrow2( r, 0x0203, "CMglImage::CreateFromFile()  D3DXCreateTextureFromFileEx(VRAM,%s)に失敗", szFileName );
	}
	else {
		DWORD r = D3DXCreateTextureFromFileEx( d3d, szFileName, x, y, D3DX_DEFAULT,
			0, /* m_myudg->backBufferDesc.Format */ m_myudg->GetFormat(), D3DPOOL_MANAGED,
			D3DX_FILTER_POINT, D3DX_FILTER_POINT, colorKey, &imgInfo, NULL, &m_pTexture );

		if ( r == E_OUTOFMEMORY )
			MyuThrow( r, "%s の読み込みに失敗。メモリが足りません。", szFileName );
		else if ( r != S_OK ) 
			MyuThrow( r, "CMglImage::CreateFromFile()  D3DXCreateTextureFromFileEx(MANAGED,%s)に失敗", szFileName );
	}

	m_nBmpSizeX = x;
	m_nBmpSizeY = y;

	int i;
	ZeroMemory( m_vertices, sizeof(MYU_VERTEX)*4 );

	//	実サイズを算出(GetRealTexSizeを使う方法もあるが、一応テクスチャから取ってくる)
	D3DSURFACE_DESC texDesc;
	m_pTexture->GetLevelDesc( 0, &texDesc );
	nRealSizeX = texDesc.Width;
	nRealSizeY = texDesc.Height;

	//	比率設定
	fRealTexTu = (float)x / (float)nRealSizeX;
	fRealTexTv = (float)y / (float)nRealSizeY;

	//	消そうとも思ったが一応デフォルト値として入れておくか…
	//	X,Yをまずは
	m_vertices[VERTEXNO_LT].x = m_vertices[VERTEXNO_LB].x = 0+X_ADJ;
	m_vertices[VERTEXNO_LT].y = m_vertices[VERTEXNO_RT].y = 0+Y_ADJ;
	m_vertices[VERTEXNO_RB].x = m_vertices[VERTEXNO_RT].x = x+X_ADJ;
	m_vertices[VERTEXNO_RB].y = m_vertices[VERTEXNO_LB].y = y+Y_ADJ;

	//	U,Vを
	m_vertices[VERTEXNO_LT].tu = m_vertices[VERTEXNO_LB].tu = 0.0f;
	m_vertices[VERTEXNO_LT].tv = m_vertices[VERTEXNO_RT].tv = 0.0f;
	//m_vertices[VERTEXNO_RB].tu = m_vertices[VERTEXNO_RT].tu = 1.0f;
	//m_vertices[VERTEXNO_RB].tv = m_vertices[VERTEXNO_LB].tv = 1.0f;
	m_vertices[VERTEXNO_RT].tu = m_vertices[VERTEXNO_RB].tu = fRealTexTu;
	m_vertices[VERTEXNO_LB].tv = m_vertices[VERTEXNO_RB].tv = fRealTexTv;


	//	その他共通
	for ( i=0; i<4; i++ )
	{
		m_vertices[i].z = 0.0f;
		m_vertices[i].rhw = 1.0f;
		m_vertices[i].color = 0xffffffff;
	}
	//SetGradation();

	//	テクスチャのサーフェスを取得する
	MyuAssert( m_pTexture->GetSurfaceLevel(0, &m_pSurface), D3D_OK,
		"CMglImage::Create()  GetSurfaceLevel()に失敗" );

	m_colorKey = colorKey;
	if ( m_colorKey != 0 )	//	カラーキーを使用する場合は0xffを念のためつけておく
		m_colorKey |= 0xff000000;

	//	スプライト作成
	MyuAssert( D3DXCreateSprite( d3d, &this->m_pSprite ), D3D_OK,
		"CMglImage::Init  D3DXCreateSprite()に失敗" );

	/////////////////////////////////////////////////////////////////////////
	//
	//	イメージを再読み込みする
	//

	IDirect3DSurface8* m_pTempSurface;	//	一時サーフェス
	MyuAssert( d3d->CreateImageSurface( x, y, m_myudg->GetFormat(), &m_pTempSurface ),
		D3D_OK, "CMglImage::CreateFromFile()  CreateImageSurface()に失敗" );

	MyuAssert( D3DXLoadSurfaceFromFile( m_pTempSurface, NULL, NULL, szFileName, NULL, D3DX_FILTER_POINT, 0xffff00ff, NULL ),
		D3D_OK, "CMglImage::CreateFromFile()  D3DXLoadSurfaceFromFile()に失敗" );

	//MyuAssert( d3d->CopyRects(m_pTempSurface, NULL, 0, m_pSurface, NULL),
	MyuAssert( d3d->CopyRects(m_pTempSurface, NULL, 0, m_pSurface, NULL),
		D3D_OK, "CMglImage::CreateFromFile()  CopyRects()に失敗" );

	SAFE_RELEASE( m_pTempSurface );

	m_bRenderTarget = bRenderTarget;
	createFlg = TRUE;

	_MGL_DEBUGLOG( "- CMglImage::CreateFromFile( \"%s\" )", szFileName );
}
//	サーフェイスの生成
void CMglImage::Create( int x, int y, BOOL bRenderTarget )
{
	_MGL_DEBUGLOG( "+ CMglImage::Create()" );

	InitCheck();	//	初期化チェック

	if ( x == 0 )	x = m_myudg->GetDispX();
	if ( y == 0 )	y = m_myudg->GetDispY();
	m_nBmpSizeX = x;
	m_nBmpSizeY = y;

	int i;
	ZeroMemory( m_vertices, sizeof(MYU_VERTEX)*4 );

	//	m_myudg->backBufferDesc.Format
	if ( bRenderTarget == TRUE ) {
		MyuAssert( D3DXCreateTexture( d3d, x, y, D3DX_DEFAULT, D3DUSAGE_RENDERTARGET, m_myudg->GetFormat(), D3DPOOL_DEFAULT, &m_pTexture ), D3D_OK,
			"CMglImage::Create()  D3DXCreateTexture(VRAM)に失敗" );
	}
	else {
		MyuAssert( D3DXCreateTexture( d3d, x, y, D3DX_DEFAULT, 0, m_myudg->GetFormat(), D3DPOOL_MANAGED, &m_pTexture ), D3D_OK,
			"CMglImage::Create()  D3DXCreateTexture(SYSMEM)に失敗" );
	}

	//	実サイズを算出(GetRealTexSizeを使う方法もあるが、一応テクスチャから取ってくる)
	D3DSURFACE_DESC texDesc;
	m_pTexture->GetLevelDesc( 0, &texDesc );
	nRealSizeX = texDesc.Width;
	nRealSizeY = texDesc.Height;

	//	比率設定
	fRealTexTu = (float)x / (float)nRealSizeX;
	fRealTexTv = (float)y / (float)nRealSizeY;

	//	消そうとも思ったが一応デフォルト値として入れておくか…
	//	X,Yをまずは
	m_vertices[VERTEXNO_LT].x = m_vertices[VERTEXNO_LB].x = 0+X_ADJ;
	m_vertices[VERTEXNO_LT].y = m_vertices[VERTEXNO_RT].y = 0+Y_ADJ;
	m_vertices[VERTEXNO_RB].x = m_vertices[VERTEXNO_RT].x = x+X_ADJ;
	m_vertices[VERTEXNO_RB].y = m_vertices[VERTEXNO_LB].y = y+Y_ADJ;

	//	U,Vを
	m_vertices[VERTEXNO_LT].tu = m_vertices[VERTEXNO_LB].tu = 0.0f;
	m_vertices[VERTEXNO_LT].tv = m_vertices[VERTEXNO_RT].tv = 0.0f;
	//m_vertices[VERTEXNO_RB].tu = m_vertices[VERTEXNO_RT].tu = 1.0f;
	//m_vertices[VERTEXNO_RB].tv = m_vertices[VERTEXNO_LB].tv = 1.0f;
	m_vertices[VERTEXNO_RT].tu = m_vertices[VERTEXNO_RB].tu = fRealTexTu;
	m_vertices[VERTEXNO_LB].tv = m_vertices[VERTEXNO_RB].tv = fRealTexTv;

	//	その他共通
	for ( i=0; i<4; i++ )
	{
		m_vertices[i].z = 0.0f;
		m_vertices[i].rhw = 1.0f;
		m_vertices[i].color = 0xffffffff;
	}
	//SetGradation();

	//	テクスチャのサーフェスを取得する
	MyuAssert( m_pTexture->GetSurfaceLevel(0, &m_pSurface), D3D_OK,
		"CMglImage::Create()  GetSurfaceLevel()に失敗" );

	//	スプライト作成
	MyuAssert( D3DXCreateSprite( d3d, &this->m_pSprite ), D3D_OK,
		"CMglImage::Init  D3DXCreateSprite()に失敗" );

	//	クリアする
	//Clear();

	m_bRenderTarget = bRenderTarget;

	createFlg = TRUE;

	_MGL_DEBUGLOG( "- CMglImage::Create()" );
}
示例#13
0
//	ファイルから読み込み
//	bRenderTargetをTRUEにした場合はPOOLも D3DPOOL_MANAGED として読み込まれる。
//void CMglTexture::CreateTextureFromFile( LPCSTR szFileName, BOOL bRenderTarget, D3DCOLOR colorKey )
void CMglTexture::CreateTextureFromFileEx( LPCSTR szFileName, int nForceBmpWidth, int nForceBmpHeight,
	BOOL bRenderTarget, D3DCOLOR colorKey, DWORD dwFilter, DWORD dwMapFilter )
{
	InitCheck();	//	初期化チェック

	//	二回目以降の呼び出しを考慮し一端Release
	Release();

	//	2009/09/27  ファイルの存在チェックをここでしよう
	//	(ファイルが存在しない場合、D3DXERR_INVALIDDATA を返すっぽいが、
	//	 ファイルが壊れてる場合とか、その他の場合でも返す可能性があるしね。)
	if ( exist_file( szFileName ) != true )
	{
		MyuThrow( MGLMSGNO_IMAGE_FILE_NOT_FOUND, "%s の読み込みに失敗。ファイルが存在しません。", szFileName );
	}

	/////////////////////////////////////////////////////////////////

	//	bRenderTargetの反映
	DWORD usage;
	D3DPOOL pool;
	if ( bRenderTarget ){
		usage = D3DUSAGE_RENDERTARGET;
		pool = D3DPOOL_DEFAULT; // D3DPOOL_MANAGED; <= 逆…?
	}
	else{
		usage = 0;
		pool = D3DPOOL_MANAGED; // D3DPOOL_DEFAULT; <= 逆…?
	}

	//	記憶しておく
	m_colorKey = colorKey;
	m_bRenderTarget = bRenderTarget;

	/*	2007/01/10  D3DX_FILTER_NONE にしたら要らなくなる系じゃない系みたいな系?
	m_imgInfo.Width = nForceBmpWidth;
	m_imgInfo.Height = nForceBmpHeight;*/

	//	作成
	//DWORD r = D3DXCreateTextureFromFileEx( d3d, szFileName, x, y, D3DX_DEFAULT,
	DWORD r = D3DXCreateTextureFromFileEx(
		d3d, szFileName,
/*		D3DX_DEFAULT,	//	Width -  この値が 0 または D3DX_DEFAULT の場合、ディメンジョンはファイルから取得される。
		D3DX_DEFAULT,	//	Height - この値が 0 または D3DX_DEFAULT の場合、ディメンジョンはファイルから取得される。*/
		nForceBmpWidth,	//	Width -  この値が 0 または D3DX_DEFAULT の場合、ディメンジョンはファイルから取得される。
		nForceBmpHeight,//	Height - この値が 0 または D3DX_DEFAULT の場合、ディメンジョンはファイルから取得される。
		D3DX_DEFAULT,	//	MipLevels
		usage,			//	Usage - 0 または D3DUSAGE_RENDERTARGET。このフラグに D3DUSAGE_RENDERTARGET を設定すると、そのサーフェスはレンダリング ターゲットとして使用されることを示す。
		m_myudg->GetFormat(),//	Format - テクスチャに対して要求されたピクセル フォーマットを記述する、D3DFORMAT 列挙型のメンバ。
		pool,			//	Pool - テクスチャの配置先となるメモリ クラスを記述する、D3DPOOL 列挙型のメンバ。
		dwFilter, dwMapFilter, colorKey, &m_imgInfo, NULL, &m_pTexture );
//		D3DX_FILTER_NONE, D3DX_FILTER_NONE, colorKey, &m_imgInfo, NULL, &m_pTexture );
//		D3DX_FILTER_POINT, D3DX_FILTER_POINT, colorKey, &m_imgInfo, NULL, &m_pTexture );

	//	エラーコードによってメッセージを変更する
	if ( r == E_OUTOFMEMORY )
		MyuThrow2( r, 0x0201, "%s の読み込みに失敗。VRAMまたはメモリが不足しています。", szFileName );
	else if ( r == D3DERR_OUTOFVIDEOMEMORY )
		MyuThrow2( r, 0x0202, "%s の読み込みに失敗。VRAMが不足しています。", szFileName );
	else if ( r == D3DERR_NOTAVAILABLE ) 
		MyuThrow2( r, 0x0202, "%s の読み込みに失敗。(DxErr=D3DERR_NOTAVAILABLE)", szFileName );
	else if ( r == D3DERR_INVALIDCALL ) 
		MyuThrow2( r, 0x0202, "%s の読み込みに失敗。(DxErr=D3DERR_INVALIDCALL)", szFileName );
	else if ( r == D3DXERR_INVALIDDATA ) 
		MyuThrow2( r, 0x0202, "%s の読み込みに失敗。(DxErr=D3DXERR_INVALIDDATA)", szFileName );
	else if ( r != S_OK ) 
		MyuThrow2( r, 0x0203, "CMglImage::CreateFromFile()  D3DXCreateTextureFromFileEx(%s)に失敗", szFileName );

	//	SetRenderとかで必要なのでサーフェス取得しておく
	_GetSurface();
}
//	デバイスへのアクセス権限を破棄
void CMglDirectInputDeviceBase::Unacquire()
{
	InitCheck();
	m_pDevice->Unacquire();
}