FOR_EACH_COLLECTION(i, mNextStateNodes)
	{
		BaseRenderStateTreeNode* curStateNode = *i;
		IRenderState* curState = curStateNode->State();
		if (curState == state || (curState != nullptr&&curState->Equals(*state)))
		{
			return curStateNode;
		}
	}
Пример #2
0
void DepthStencilRenderState::CopyFrom(const IRenderState& other)
{
	MEDUSA_ASSERT(other.Type() == Type(), "Cannot copy render state with different type");
	DepthStencilRenderState& val = (DepthStencilRenderState&)other;

	mDepthTestEnabled = val.mDepthTestEnabled;
	mDepthWritable = val.mDepthWritable;
	mDepthFunc = val.mDepthFunc;
	mDepthClearValue = val.mDepthClearValue;

	mStencilTestEnabled = val.mStencilTestEnabled;
	mStencilClearValue = val.mStencilClearValue;

	mFrontStencilDepthFailOp = val.mFrontStencilDepthFailOp;
	mFrontStencilFailOp = val.mFrontStencilFailOp;
	mFrontStencilFunc = val.mFrontStencilFunc;
	mFrontStencilPassOp = val.mFrontStencilPassOp;
	mFrontReadMask = val.mFrontReadMask;
	mFrontWriteMask = val.mFrontWriteMask;
	mFrontRefValue = val.mFrontRefValue;

	mBackStencilDepthFailOp = val.mBackStencilDepthFailOp;
	mBackStencilFailOp = val.mBackStencilFailOp;
	mBackStencilFunc = val.mBackStencilFunc;
	mBackStencilPassOp = val.mBackStencilPassOp;
	mBackReadMask = val.mBackReadMask;
	mBackWriteMask = val.mBackWriteMask;
	mBackRefValue = val.mBackRefValue;

}
Пример #3
0
void RasterizerRenderState::CopyFrom(const IRenderState& other)
{
	MEDUSA_ASSERT(other.Type() == Type(), "Cannot copy render state with different type");
	RasterizerRenderState& val = (RasterizerRenderState&)other;
	mCullMode = val.mCullMode;
	mFrontFace = val.mFrontFace;
	mCullFaceEnabled = val.mCullFaceEnabled;
	mColorMask = val.mColorMask;
}
Пример #4
0
void SamplerRenderState::CopyFrom(const IRenderState& other)
{
	MEDUSA_ASSERT(other.Type() == Type(), "Cannot copy render state with different type");
	SamplerRenderState& val = (SamplerRenderState&)other;
	mTextureType = val.mTextureType;
	mTextureUnit = val.mTextureUnit;
	mTexture = val.mTexture;
	mMagFilter = val.mMagFilter;
	mMinFilter = val.mMinFilter;
	mWrapS = val.mWrapS;
	mWrapT = val.mWrapT;
}
Пример #5
0
bool CResourceLoader::loadPipeline(const std::string& fullpath, const IResourceXmlParser::SPipelineCreateParams& createParams) const
{
	/* if the pipeline with the same name has already been loaded,
	maybe some mistake has occurred. such as two pipeline file with the same
	pipeline name. */
	IPipeline* pipeline = mPipelineManager->get(createParams.Name);
	if (pipeline)
	{
		GF_PRINT_CONSOLE_INFO("Pipeline '%s' (in the file '%s') has already been loaded. It can't been loaded again. \
							  			Do you put the pipelines with same names in different files ?\n",
										createParams.Name, fullpath.c_str());
		return false;
	}


	u32 shaderCount = createParams.Shaders.size();
	IShader* shaders[5];
	IShader* vertexShader;
	for (u32 i = 0; i < shaderCount; i++)
	{
		const IResourceXmlParser::SShaderCreateParams shaderCreateParams = createParams.Shaders[i];
		std::string shaderName = shaderCreateParams.FileName + std::string("-") + shaderCreateParams.FunctionName;
		IShader* shader = mShaderManager->get(shaderName);

		/* if the shader has not been loaded. Load it first. */
		if (!shader)
		{
			std::string shaderFullPath;
			if (!mResourceGroupManager->getFullPath(shaderCreateParams.FileName, shaderFullPath))
			{
				GF_PRINT_CONSOLE_INFO("Pipeline '%s' creation failed. Because the shader file '%s' doesn't exist.\n",
					createParams.Name.c_str(), shaderCreateParams.FileName.c_str());
				return false;
			}

			shader = mShaderManager->load(shaderCreateParams.Type, shaderFullPath, shaderCreateParams.FunctionName, shaderName);
			if (shader == nullptr)
			{
				GF_PRINT_CONSOLE_INFO("Pipeline '%s' creation failed. Due to the '%s' function in '%s' shader file.\n",
					createParams.Name.c_str(), shaderCreateParams.FunctionName.c_str(), shaderFullPath.c_str());
				return false;
			}
		}

		shaders[i] = shader;

		/* find the vertex shader, which will be used to create input-layout soon.*/
		if (shader->getType() == EST_VERTEX_SHADER)
		{
			vertexShader = shader;
		}
	}

	/* create the input-layout. */
	/* if the input-layout with the same layout has been created before, just get it.*/
	IInputLayout* inputLayout = mInputlayoutManager->get(createParams.InputLayoutElements);
	// if there is no input-layout with the same vertex formats. just create it.
	if (!inputLayout)
	{
		inputLayout = mInputlayoutManager->create(createParams.InputLayoutElements, vertexShader);
		if (!inputLayout)
		{
			GF_PRINT_CONSOLE_INFO("Pipeline '%s' creation failed. Due to the input-layout create failure in file '%s'.\n",
				createParams.Name, fullpath.c_str());
			return false;
		}
	}


	/* create render state */
	std::string rsname = createParams.Name + ".rs";
	IRenderState* pRenderState = mRenderStateManager->get(rsname);
	if (!pRenderState)
	{
		pRenderState = mRenderStateManager->create(rsname);
		if (!pRenderState)
		{
			GF_PRINT_CONSOLE_INFO("Pipeline '%s' creation failed. Due to the render-state create failure in file '%s'.\n",
				createParams.Name, fullpath.c_str());
			return false;
		}
	}

	// set all the render states.
	for (u32 i = 0; i < createParams.RenderStates.size(); i++)
	{
		const IResourceXmlParser::SRenderStateCreateParams& rsCreateParam = createParams.RenderStates[i];
		switch (rsCreateParam.StateType)
		{
			/* if the render-state need a float value */
		case ERS_DEPTH_BIAS_CLAMP:
			pRenderState->setFloat(rsCreateParam.StateType, rsCreateParam.FloatValue);
			break;
			/* others are unsigned int. */
		default:
			pRenderState->set(rsCreateParam.StateType, rsCreateParam.DwordValue);
			break;
		}
	}

	pRenderState->confirm();

	// create the pipeline object
	pipeline = mPipelineManager->create(createParams.Name, shaders, shaderCount, inputLayout,
		createParams.PrimitiveType, pRenderState);
	if (!pipeline)
	{
		GF_PRINT_CONSOLE_INFO("Pipeline '%s' creation failed (in file '%s').\n",
			createParams.Name, fullpath.c_str());

		// TODO: should drop pRenderState object.
		return false;
	}

	/* set the shader auto-inject variables. */
	for (u32 i = 0; i < createParams.ShaderAutoVariables.size(); i++)
	{
		pipeline->addShaderAutoVariable(createParams.ShaderAutoVariables[i]);
	}

	return true;
}
Пример #6
0
void ProgramRenderState::CopyFrom(const IRenderState& other)
{
	MEDUSA_ASSERT(other.Type() == Type(), "Cannot copy render state with different type");
	ProgramRenderState& val = (ProgramRenderState&)other;
	mProgram = val.mProgram;
}