<commit_before>#include "engine.hpp"
#include "../systeminfo.hpp"

namespace myunif {
	namespace light {
		using GlxId = rs::IEffect::GlxId;
		const rs::IdValue Position = GlxId::GenUnifId("m_vLightPos"),
							Color = GlxId::GenUnifId("m_vLightColor"),
							Dir =	GlxId::GenUnifId("m_vLightDir"),
							Power =	GlxId::GenUnifId("m_fLightPower"),
							Depth = GlxId::GenUnifId("m_texLightDepth"),
							CubeDepth = GlxId::GenUnifId("m_texCubeDepth"),
							DepthRange = GlxId::GenUnifId("m_depthRange"),
							LightMat = GlxId::GenUnifId("m_mLight"),
							LineLength = GlxId::GenUnifId("m_lineLength");
	}
}
DefineDrawGroup(MyDrawGroup)
ImplDrawGroup(MyDrawGroup, 0x0000)
Engine::Engine(const std::string& name):
	rs::util::GLEffect_2D3D(name),
	_gauss(0),
	_drawType(DrawType::Normal)
{
	_hlDg = rs_mgr_obj.makeDrawGroup<MyDrawGroup>(rs::DSortV{rs::cs_dsort_priority_asc}, true). first;
	setLightPosition(spn::Vec3(0,0,0));
	setLightDir(spn::Vec3(0,0,1));
	setDepthRange(spn::Vec2(0, 10));
	setLightDepthSize(spn::Size{256,256});
}
Engine::DrawType::E Engine::getDrawType() const {
	return _drawType;
}
void Engine::_prepareUniforms() {
	rs::util::GLEffect_2D3D::_prepareUniforms();

	#define DEF_SETUNIF(name, func) \
		if(auto idv = getUnifId(myunif::light::name)) \
			setUniform(*idv, func##name(), true);
	DEF_SETUNIF(Position, getLight)
	DEF_SETUNIF(Color, getLight)
	DEF_SETUNIF(Dir, getLight)
	DEF_SETUNIF(Power, getLight)
	DEF_SETUNIF(DepthRange, get)
	#undef DEF_SETUNIF
	if(auto idv = getUnifId(myunif::light::CubeDepth))
		setUniform(*idv, getCubeColorBuff(), true);
	if(auto idv = getUnifId(myunif::light::Depth))
		setUniform(*idv, getLightColorBuff(), true);
	if(auto idv = getUnifId(myunif::light::LightMat))
		setUniform(*idv, getLightMatrix(), true);
	if(auto idv = getUnifId(myunif::light::LineLength))
		setUniform(*idv, 1.f, true);
}
#include "../camera.hpp"
spn::RFlagRet Engine::_refresh(rs::HLRb& rb, LightDepth*) const {
	auto& sz = getLightDepthSize();
	rb = mgr_gl.makeRBuffer(sz.width, sz.height, GL_DEPTH_COMPONENT16);
	return {true, 0};
}
spn::RFlagRet Engine::_refresh(rs::HLTex& tex, CubeColorBuff*) const {
	tex = mgr_gl.createCubeTexture(getLightDepthSize(), GL_RG16, false, false);
	tex->get()->setFilter(true, true);
	return {true, 0};
}
spn::RFlagRet Engine::_refresh(rs::HLCam& c, LightCamera*) const {
	c = mgr_cam.emplace();
	auto& pose = c->refPose();
	pose.setOffset(getLightPosition());
	pose.setRot(spn::AQuat::Rotation({0,0,1}, getLightDir()));
	c->setFov(spn::DegF(90));
	c->setZPlane(0.01f, 500.f);
	return {true, 0};
}
spn::RFlagRet Engine::_refresh(spn::Mat44& m, LightMatrix*) const {
	auto& c = getLightCamera().cref();
	m = c.getViewProj();
	return {true, 0};
}
spn::RFlagRet Engine::_refresh(rs::HLTex& tex, LightColorBuff*) const {
	tex = mgr_gl.createTexture(getLightDepthSize(), GL_RG16, false, false);
	tex->get()->setFilter(true, true);
	return {true, 0};
}
spn::RFlagRet Engine::_refresh(rs::HLFb& fb, LightFB*) const {
	if(!fb)
		fb = mgr_gl.makeFBuffer();
	fb->get()->attachTexture(rs::GLFBuffer::Att::COLOR0, getLightColorBuff());
	fb->get()->attachRBuffer(rs::GLFBuffer::Att::DEPTH, getLightDepth());
	return {true, 0};
}
#include "../util/screen.hpp"
class Engine::DrawScene : public rs::DrawableObjT<DrawScene> {
	private:
		struct St_Default : StateT<St_Default> {
			void onDraw(const DrawScene&, rs::IEffect& e) const override {
				rs::HLFb fb = e.getFramebuffer();

				auto& engine = static_cast<Engine&>(e);
				e.setFramebuffer(engine.getLightFB());
				e.clearFramebuffer(rs::draw::ClearParam{spn::Vec4(0), 1.f, spn::none});<commit_msg>testcode: ライト方向が丁度Z軸と正対する時の不具合を修正<commit_after>#include "engine.hpp"
#include "../systeminfo.hpp"

namespace myunif {
	namespace light {
		using GlxId = rs::IEffect::GlxId;
		const rs::IdValue Position = GlxId::GenUnifId("m_vLightPos"),
							Color = GlxId::GenUnifId("m_vLightColor"),
							Dir =	GlxId::GenUnifId("m_vLightDir"),
							Power =	GlxId::GenUnifId("m_fLightPower"),
							Depth = GlxId::GenUnifId("m_texLightDepth"),
							CubeDepth = GlxId::GenUnifId("m_texCubeDepth"),
							DepthRange = GlxId::GenUnifId("m_depthRange"),
							LightMat = GlxId::GenUnifId("m_mLight"),
							LineLength = GlxId::GenUnifId("m_lineLength");
	}
}
DefineDrawGroup(MyDrawGroup)
ImplDrawGroup(MyDrawGroup, 0x0000)
Engine::Engine(const std::string& name):
	rs::util::GLEffect_2D3D(name),
	_gauss(0),
	_drawType(DrawType::Normal)
{
	_hlDg = rs_mgr_obj.makeDrawGroup<MyDrawGroup>(rs::DSortV{rs::cs_dsort_priority_asc}, true). first;
	setLightPosition(spn::Vec3(0,0,0));
	setLightDir(spn::Vec3(0,0,1));
	setDepthRange(spn::Vec2(0, 10));
	setLightDepthSize(spn::Size{256,256});
}
Engine::DrawType::E Engine::getDrawType() const {
	return _drawType;
}
void Engine::_prepareUniforms() {
	rs::util::GLEffect_2D3D::_prepareUniforms();

	#define DEF_SETUNIF(name, func) \
		if(auto idv = getUnifId(myunif::light::name)) \
			setUniform(*idv, func##name(), true);
	DEF_SETUNIF(Position, getLight)
	DEF_SETUNIF(Color, getLight)
	DEF_SETUNIF(Dir, getLight)
	DEF_SETUNIF(Power, getLight)
	DEF_SETUNIF(DepthRange, get)
	#undef DEF_SETUNIF
	if(auto idv = getUnifId(myunif::light::CubeDepth))
		setUniform(*idv, getCubeColorBuff(), true);
	if(auto idv = getUnifId(myunif::light::Depth))
		setUniform(*idv, getLightColorBuff(), true);
	if(auto idv = getUnifId(myunif::light::LightMat))
		setUniform(*idv, getLightMatrix(), true);
	if(auto idv = getUnifId(myunif::light::LineLength))
		setUniform(*idv, 1.f, true);
}
#include "../camera.hpp"
spn::RFlagRet Engine::_refresh(rs::HLRb& rb, LightDepth*) const {
	auto& sz = getLightDepthSize();
	rb = mgr_gl.makeRBuffer(sz.width, sz.height, GL_DEPTH_COMPONENT16);
	return {true, 0};
}
spn::RFlagRet Engine::_refresh(rs::HLTex& tex, CubeColorBuff*) const {
	tex = mgr_gl.createCubeTexture(getLightDepthSize(), GL_RG16, false, false);
	tex->get()->setFilter(true, true);
	return {true, 0};
}
spn::RFlagRet Engine::_refresh(rs::HLCam& c, LightCamera*) const {
	c = mgr_cam.emplace();
	auto& pose = c->refPose();
	pose.setOffset(getLightPosition());
	spn::AQuat q;
	if(getLightDir().z < -1.f+1e-4f)
		q = spn::AQuat::RotationY(spn::DegF(180.f));
	else
		q = spn::AQuat::Rotation({0,0,1}, getLightDir());
	pose.setRot(q);
	c->setFov(spn::DegF(90));
	c->setZPlane(0.01f, 500.f);
	return {true, 0};
}
spn::RFlagRet Engine::_refresh(spn::Mat44& m, LightMatrix*) const {
	auto& c = getLightCamera().cref();
	m = c.getViewProj();
	return {true, 0};
}
spn::RFlagRet Engine::_refresh(rs::HLTex& tex, LightColorBuff*) const {
	tex = mgr_gl.createTexture(getLightDepthSize(), GL_RG16, false, false);
	tex->get()->setFilter(true, true);
	return {true, 0};
}
spn::RFlagRet Engine::_refresh(rs::HLFb& fb, LightFB*) const {
	if(!fb)
		fb = mgr_gl.makeFBuffer();
	fb->get()->attachTexture(rs::GLFBuffer::Att::COLOR0, getLightColorBuff());
	fb->get()->attachRBuffer(rs::GLFBuffer::Att::DEPTH, getLightDepth());
	return {true, 0};
}
#include "../util/screen.hpp"
class Engine::DrawScene : public rs::DrawableObjT<DrawScene> {
	private:
		struct St_Default : StateT<St_Default> {
			void onDraw(const DrawScene&, rs::IEffect& e) const override {
				rs::HLFb fb = e.getFramebuffer();

				auto& engine = static_cast<Engine&>(e);
				e.setFramebuffer(engine.getLightFB());
				e.clearFramebuffer(rs::draw::ClearParam{spn::Vec4(0), 1.f, spn::none});
{'fraction_non_alphanumeric': 0.1807457627118644, 'fraction_numerical': 0.016542372881355932, 'mean_word_length': 6.604123711340206, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 33, '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': '4576978', 'n_tokens_mistral': 3142, 'n_tokens_neox': 2939, 'n_words': 455}