<commit_before>#include "Material.h"
#include "Utility.h"

using namespace Rendering;
using namespace Rendering::Buffer;

Material::Color::Color() 
	:diffuse(1.0f, 1.0f, 1.0f), ambient(0.5f, 0.5f, 0.5f),
	specular(1.0f, 1.0f, 1.0f), emissive(0.0f, 0.0f, 0.0f),
	shiness(0.0f), opacity(1.0f)
{
}

Material::Color::~Color()
{
}


Material::Material(const std::string& name)	
	: _vertexShader(nullptr), _pixelShader(nullptr), _name(name), _colorBuffer(nullptr)
{
}

Material::Material(const std::string& name, const Color& color) 
	: _vertexShader(nullptr), _pixelShader(nullptr), _name(name), _color(color), _colorBuffer(nullptr)
{

}

Material::~Material(void)
{
	SAFE_DELETE(_colorBuffer);
}

void Material::InitColorBuffer(ID3D11DeviceContext* context)
{
	Buffer::ConstBuffer* colorBuffer = new Buffer::ConstBuffer;
	colorBuffer->Create(sizeof(Material::Color), 0, ConstBuffer::Usage::PixelShader);
	_constBuffer.push_back(std::make_pair(BasicConstBuffercSlot::MaterialColor, colorBuffer));	
	_colorBuffer = dynamic_cast<Buffer::ConstBuffer*>(_constBuffer[0].second);

	UpdateColorBuffer(context);
}

void Material::UpdateColorBuffer(ID3D11DeviceContext* context)
{
	if(_colorBuffer)
		_colorBuffer->UpdateSubresource(context, &_color);
}

bool Material::UpdateTexture(unsigned int index, const Rendering::Texture::Texture* texture)
{
	_textures.push_back(std::make_pair(index, texture));
	return true;
}

void Material::UpdateDiffuseMap(const Rendering::Texture::Texture* tex)
{
	if(UpdateTexture(TextureType::Diffuse, tex) == false)
		_textures.push_back(std::make_pair(TextureType::Diffuse, tex));
}

void Material::UpdateNormalMap(const Rendering::Texture::Texture* tex)
{
	if(UpdateTexture(TextureType::Normal, tex) == false)
		_textures.push_back(std::make_pair(TextureType::Normal, tex));
}

void Material::UpdateSpecularMap(const Rendering::Texture::Texture* tex)
{
	if(UpdateTexture(TextureType::Specular, tex) == false)
		_textures.push_back(std::make_pair(TextureType::Specular, tex));
}

void Material::UpdateOpacityMap(const Rendering::Texture::Texture* tex)
{
	if(UpdateTexture(TextureType::Opacity, tex) == false)<commit_msg>ConstBuffer 정리 후 Material에 생겼던 버그 수정 (사이즈가 16배수가 아님) #18<commit_after>#include "Material.h"
#include "Utility.h"

using namespace Rendering;
using namespace Rendering::Buffer;

Material::Color::Color() 
	:diffuse(1.0f, 1.0f, 1.0f), ambient(0.5f, 0.5f, 0.5f),
	specular(1.0f, 1.0f, 1.0f), emissive(0.0f, 0.0f, 0.0f),
	shiness(0.0f), opacity(1.0f)
{
}

Material::Color::~Color()
{
}


Material::Material(const std::string& name)	
	: _vertexShader(nullptr), _pixelShader(nullptr), _name(name), _colorBuffer(nullptr)
{
}

Material::Material(const std::string& name, const Color& color) 
	: _vertexShader(nullptr), _pixelShader(nullptr), _name(name), _color(color), _colorBuffer(nullptr)
{

}

Material::~Material(void)
{
	SAFE_DELETE(_colorBuffer);
}

void Material::InitColorBuffer(ID3D11DeviceContext* context)
{
	Buffer::ConstBuffer* colorBuffer = new Buffer::ConstBuffer;

	// const buffer size certainly is 16 multiple
	colorBuffer->Create(sizeof(Material::Color) + 8);

	_constBuffer.push_back(std::make_pair(BasicConstBuffercSlot::MaterialColor, colorBuffer));	
	_colorBuffer = dynamic_cast<Buffer::ConstBuffer*>(_constBuffer[0].second);

	UpdateColorBuffer(context);
}

void Material::UpdateColorBuffer(ID3D11DeviceContext* context)
{
	if(_colorBuffer)
		_colorBuffer->Update(context, &_color);
}

bool Material::UpdateTexture(unsigned int index, const Rendering::Texture::Texture* texture)
{
	_textures.push_back(std::make_pair(index, texture));
	return true;
}

void Material::UpdateDiffuseMap(const Rendering::Texture::Texture* tex)
{
	if(UpdateTexture(TextureType::Diffuse, tex) == false)
		_textures.push_back(std::make_pair(TextureType::Diffuse, tex));
}

void Material::UpdateNormalMap(const Rendering::Texture::Texture* tex)
{
	if(UpdateTexture(TextureType::Normal, tex) == false)
		_textures.push_back(std::make_pair(TextureType::Normal, tex));
}

void Material::UpdateSpecularMap(const Rendering::Texture::Texture* tex)
{
	if(UpdateTexture(TextureType::Specular, tex) == false)
		_textures.push_back(std::make_pair(TextureType::Specular, tex));
}

void Material::UpdateOpacityMap(const Rendering::Texture::Texture* tex)
{
	if(UpdateTexture(TextureType::Opacity, tex) == false)
{'fraction_non_alphanumeric': 0.15423689679057953, 'fraction_numerical': 0.01800969752943893, 'mean_word_length': 8.669642857142858, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2007515', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1522, 'n_words': 239}