const unsigned int ResourceManagerDX9::CreateVertexFormat(
	const unsigned int attributeCount, const VertexAttributeUsage usage,
	const VertexAttributeType type, const unsigned int usageIdx, ...)
{
	VertexFormat* vf = new VertexFormatDX9(attributeCount);
	unsigned int offset = 0;

	vf->SetAttribute(0, offset, usage, type, usageIdx);
	offset += VertexFormat::GetAttributeTypeSize(type);

	va_list args;
	va_start(args, usageIdx);
	for (unsigned int i = 1, n = vf->GetAttributeCount(); i < n; i++)
	{
		VertexAttributeUsage tempUsage = va_arg(args, VertexAttributeUsage);
		VertexAttributeType tempType = va_arg(args, VertexAttributeType);
		unsigned int tempUsageIdx = va_arg(args, unsigned int);
		vf->SetAttribute(i, offset, tempUsage, tempType, tempUsageIdx);
		offset += VertexFormat::GetAttributeTypeSize(tempType);
	}
	va_end(args);

	vf->SetStride(offset);

	m_arrVertexFormat.push_back(vf);
	return (unsigned int)m_arrVertexFormat.size() - 1;
}
Exemple #2
0
//----------------------------------------------------------------------------
VertexFormat* Visual::LoadVertexFormat (FileIO& inFile)
{
    int numAttributes;
    inFile.Read(sizeof(int), &numAttributes);

    VertexFormat* vformat = new0 VertexFormat(numAttributes);
    for (int i = 0; i < numAttributes; ++i)
    {
        unsigned int streamIndex, offset, usageIndex;
        int type, usage;

        inFile.Read(sizeof(unsigned int), &streamIndex);
        inFile.Read(sizeof(unsigned int), &offset);
        inFile.Read(sizeof(int), &type);
        inFile.Read(sizeof(int), &usage);
        inFile.Read(sizeof(unsigned int), &usageIndex);

        vformat->SetAttribute(i, streamIndex, offset,
                              (VertexFormat::AttributeType)type,
                              (VertexFormat::AttributeUsage)usage, usageIndex);
    }

    int stride;
    inFile.Read(sizeof(int), &stride);
    vformat->SetStride(stride);

    return vformat;
}
//----------------------------------------------------------------------------
VertexFormat* VertexFormat::Create (int numAttributes, ...)
{
    VertexFormat* vformat = new0 VertexFormat(numAttributes);

    va_list arguments;
    va_start(arguments, numAttributes);

    unsigned int offset = 0;
    for (int i = 0; i < numAttributes; ++i)
    {
        int usage = va_arg(arguments, int);
        int type = va_arg(arguments, int);
        unsigned int usageIndex = va_arg(arguments, unsigned int);
        vformat->SetAttribute(i, 0, offset, (AttributeType)type,
            (AttributeUsage)usage, usageIndex);
        offset += msTypeSize[type];
    }
    vformat->SetStride((int)offset);

    va_end(arguments);

    return vformat;
}
//----------------------------------------------------------------------------
ImageProcessing::ImageProcessing (int numCols, int numRows, int numTargets)
:
mNumCols(numCols),
mNumRows(numRows),
mNumTargets(numTargets)
{
	assertion(mNumCols > 1 && mNumRows > 0, "Invalid bound.\n");
	assertion(mNumTargets > 0, "Invalid number of targets.\n");

	mColSpacing = 1.0f/(float)(mNumCols - 1);
	mRowSpacing = 1.0f/(float)(mNumRows - 1);

	// 将相机从[-1,-1]^2 x [0,1]匹配到[0,1]^3
	mCamera = new0 Camera(false);
	mCamera->SetFrustum(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f);
	mCamera->SetFrame(APoint::ORIGIN, AVector::UNIT_Z, AVector::UNIT_Y,
		AVector::UNIT_X);

	// 创建顶点格式
	VertexFormat* vformat = new0 VertexFormat(2);
	vformat->SetAttribute(0, 0, 0, VertexFormat::AT_FLOAT3,
		VertexFormat::AU_POSITION, 0);
	vformat->SetAttribute(1, 0, 3*sizeof(float), VertexFormat::AT_FLOAT2,
		VertexFormat::AU_TEXCOORD, 0);
	vformat->SetStride(5*sizeof(float));

	// 创建顶点缓冲区
	int vstride = vformat->GetStride();
	VertexBuffer* vbuffer = new0 VertexBuffer(4, vstride);
	VertexBufferAccessor vba(vformat, vbuffer);

	float xmin, xmax, ymin, ymax;
	Float2 tc0, tc1, tc2, tc3;
	if (VertexShader::GetProfile() == VertexShader::VP_ARBVP1)
	{
		xmin = 0.0f;
		xmax = 1.0f;
		ymin = 0.0f;
		ymax = 1.0f;
		tc0 = Float2(0.0f, 0.0f);
		tc1 = Float2(1.0f, 0.0f);
		tc2 = Float2(1.0f, 1.0f);
		tc3 = Float2(0.0f, 1.0f);
	}
	else
	{
		xmin = -0.5f*mColSpacing;
		xmax = 1.0f - 0.5f*mColSpacing;
		ymin = +0.5f*mRowSpacing;
		ymax = 1.0f + 0.5f*mRowSpacing;
		tc0 = Float2(0.0f, 1.0f);
		tc1 = Float2(1.0f, 1.0f);
		tc2 = Float2(1.0f, 0.0f);
		tc3 = Float2(0.0f, 0.0f);
	}

	vba.Position<Float3>(0) = Float3(xmin, ymin, 0.0f);
	vba.Position<Float3>(1) = Float3(xmax, ymin, 0.0f);
	vba.Position<Float3>(2) = Float3(xmax, ymax, 0.0f);
	vba.Position<Float3>(3) = Float3(xmin, ymax, 0.0f);
	vba.TCoord<Float2>(0, 0) = tc0;
	vba.TCoord<Float2>(0, 1) = tc1;
	vba.TCoord<Float2>(0, 2) = tc2;
	vba.TCoord<Float2>(0, 3) = tc3;

	// 创建顶点索引缓冲区
	IndexBuffer* ibuffer = new0 IndexBuffer(6, sizeof(int));
	int* indices = (int*)ibuffer->GetData();
	indices[0] = 0;  indices[1] = 1;  indices[2] = 2;
	indices[3] = 0;  indices[4] = 2;  indices[5] = 3;

	// 创建网格
	mRectangle = new0 TriMesh(vformat, vbuffer, ibuffer);

	// 创建顶点着色器
	CreateVertexShader();

	// 创建RT
	mTargets = new1<RenderTargetPtr>(mNumTargets);
	for (int i = 0; i < mNumTargets; ++i)
	{
		mTargets[i] = new0 RenderTarget(1, Texture::TF_A32B32G32R32F,
			mNumCols, mNumRows, false, false, false);
	}
}