Exemplo n.º 1
0
///=====================================================
/// 
///=====================================================
void EngineAndrew::Material::SetTexture(Texture* texture, const std::string& uniformName){
	UniformInt* textureUniform = (UniformInt*)CreateUniform(uniformName);
	if (textureUniform == nullptr) return;
	textureUniform->m_data.push_back((int)m_textures.size());

	IndexedTexture indexedTexture;
	indexedTexture.m_texture = texture;
	indexedTexture.m_textureIndex = (int)m_textures.size();

	m_textures.push_back(indexedTexture);
}
Exemplo n.º 2
0
///=====================================================
/// 
///=====================================================
void EngineAndrew::Material::CreateTexture(const std::string& texturePath, const std::string& uniformName, TextureType type /*= TextureType::Undefined*/){
	Texture* texture = Texture::CreateOrGetTexture(texturePath, type);

	UniformInt* textureUniform = (UniformInt*)CreateUniform(uniformName);
	if (textureUniform == nullptr) return;
	textureUniform->m_data.push_back((int)m_textures.size());

	IndexedTexture indexedTexture;
	indexedTexture.m_texture = texture;
	indexedTexture.m_textureIndex = (int)m_textures.size();

	m_textures.push_back(indexedTexture);
}
Exemplo n.º 3
0
	UINT ShaderGL::CreateFromMemory(char* source)
	{
		mSource = source;

		mProgram = glCreateProgram();

		if (mProgram < 0)
		{
			Debug::ShowError(
				"Could not create shader program.",
				"Shader Loader Error");
		}

		
		if (strstr(mSource, "VERTEX_SHADER") != nullptr)
		{
			const char *vshader[2] = { "#version 330\n#define VERSION_GL\n#define VERTEX_SHADER\n\0", mSource };

			if (!Compile(vshader, mVertexShader, GL_VERTEX_SHADER, 2))
				return S_FALSE;

			glAttachShader(mProgram, mVertexShader);
		}

		
		if (strstr(mSource, "GEOMETRY_SHADER") != nullptr)
		{
			const char *gshader[2] = { "#version 330\n#define VERSION_GL\n#define GEOMETRY_SHADER\n\0", mSource };

			if (!Compile(gshader, mGeometryShader, GL_GEOMETRY_SHADER, 2))
				return S_FALSE;

			glAttachShader(mProgram, mGeometryShader);
		}

		
		if (strstr(mSource, "FRAGMENT_SHADER") != nullptr)
		{
			const char *fshader[2] = { "#version 330\n#define VERSION_GL\n#define FRAGMENT_SHADER\n\0", mSource };

			if (!Compile(fshader, mFragmentShader, GL_FRAGMENT_SHADER, 2))
				return S_FALSE;

			glAttachShader(mProgram, mFragmentShader);
		}

		Debug::Log("Shader Compiled Successfully!");

		
		int didCompile;

		glLinkProgram(mProgram);
		glGetProgramiv(mProgram, GL_LINK_STATUS, &didCompile);

		if (didCompile == GL_FALSE)
		{
			char* compileLog;
			int length;

			glGetProgramiv(mProgram, GL_INFO_LOG_LENGTH, &length);

			compileLog = (char*)malloc(length);

			glGetProgramInfoLog(mProgram, length, &length, compileLog);

			Debug::Log("\nLink Shader Log");
			Debug::Log(compileLog);

			free(compileLog);

			Release();

			return S_FALSE;
		}

		CreateAttribute("Position", VertexAttribute::POSITION);
		CreateAttribute("TexCoord0", VertexAttribute::TEXCOORD0);
		CreateAttribute("TexCoord1", VertexAttribute::TEXCOORD1);
		CreateAttribute("TexCoord2", VertexAttribute::TEXCOORD2);
		CreateAttribute("QuadCoord0", VertexAttribute::QUADCOORD0);
		CreateAttribute("QuadCoord1", VertexAttribute::QUADCOORD1);
		CreateAttribute("QuadCoord2", VertexAttribute::QUADCOORD2);
		CreateAttribute("Normal", VertexAttribute::NORMAL);
		CreateAttribute("Color", VertexAttribute::COLOR);
		CreateAttribute("Tangent", VertexAttribute::TANGENT);
		CreateAttribute("BoneCount", VertexAttribute::BONE_COUNT);
		CreateAttribute("BoneMatrix", VertexAttribute::BONE_INDEX);
		CreateAttribute("BoneWeight", VertexAttribute::BONE_WEIGHT);

		if (CreateAttribute("Matrix", VertexAttribute::MATRIX))
			mAttributeSize += 3;

		VertexLayoutGL* layout = new VertexLayoutGL();

		UINT size = (UINT)mAttributes.size();
		for (UINT x = 0; x < size; ++x)
		{
			layout->AddAttribute(mAttributes[x]);
		}

		mLayout = std::shared_ptr< VertexLayout >(layout);

		CreateUniform("_WorldViewProj", ShaderUniform::WORLD_VIEW_PROJ);
		CreateUniform("_WorldView", ShaderUniform::WORLD_VIEW);
		CreateUniform("_World", ShaderUniform::WORLD);
		CreateUniform("_InvWorld", ShaderUniform::INV_WORLD);
		CreateUniform("_View", ShaderUniform::VIEW);
		CreateUniform("_InvView", ShaderUniform::INV_VIEW);
		CreateUniform("_Proj", ShaderUniform::PROJ);
		CreateUniform("_InvProj", ShaderUniform::INV_PROJ);
		CreateUniform("_Ambient", ShaderUniform::AMBIENT);
		CreateUniform("_Diffuse", ShaderUniform::DIFFUSE);
		CreateUniform("_Specular", ShaderUniform::SPECULAR);
		CreateUniform("_SpecComp", ShaderUniform::SPEC_COMP);
		CreateUniform("_LightPos", ShaderUniform::LIGHT_POS);
		CreateUniform("_LightDir", ShaderUniform::LIGHT_DIR);
		CreateUniform("_LightColor", ShaderUniform::LIGHT_COLOR);
		CreateUniform("_LightAttn", ShaderUniform::LIGHT_ATTN);
		CreateUniform("_LightMatrix", ShaderUniform::LIGHT_MATRIX);
		CreateUniform("_LightCubeMatrix", ShaderUniform::LIGHT_CUBE_MATRIX);
		CreateUniform("_CameraPos", ShaderUniform::CAMERA_POS);
		CreateUniform("_Bones", ShaderUniform::BONES);
		CreateUniform("_DeltaTime", ShaderUniform::DELTA_TIME);

		UINT numTextureCube = 0;
		if (CreateUniform("_TextureCube", ShaderUniform::LIGHT_TEXTURE_CUBE))
			++numTextureCube;

		UINT numTexture = 0;
		char texName[16];
		for (int x = 0; x < MAX_TEXTURES; ++x)
		{
			sprintf_s(texName, "_Texture%d", x);

			if (CreateUniform(texName, ShaderUniform::TEXTURE))
				++numTexture;
		}

		mNumSamplers = numTexture + numTextureCube;

		if (mNumSamplers > 0)
		{
			mSampler = new Sampler*[mNumSamplers];

			UINT index = 0;

			for (; index < numTextureCube; ++index)
				mSampler[index] = new SamplerCubeGL();

			for (; index < mNumSamplers; ++index)
				mSampler[index] = new SamplerGL();
		}

		Debug::Log("Shader Created Successfully!");

		return S_OK;
	}