/*
	Stargate Lib for GarrysMod10
	Copyright (C) 2007  aVoN

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
-- It is possible I added this code accidentally to the SVN - It's shit, will get replaced by 100% etc. It was for me testing the crap
--[[
StarGate.Clipping = {};
StarGate.Clipping.__SENTS = {};

require("renderx"); -- Thank's to Jinto, who coded this binary

--################# Adds an entity which should clip on a specific ent@aVoN
function StarGate.Clipping:AddClipping(base,e)
	if(not (base and e)) then return end;
	StarGate.Clipping.__SENTS[base] = StarGate.Clipping.__SENTS[base] or {};
	table.insert(StarGate.Clipping.__SENTS[base],e);
end

--################# Does the clipping @aVoN
function StarGate.Hook.ClippingRenderScreenspaceEffects()
	if(not render.EnableClipping) then
		hook.Remove("RenderScreenspaceEffects","StarGate.Hook.ClippingRenderScreenspaceEffects");
	end
	for e,ents in pairs(StarGate.Clipping.__SENTS) do
		if(ValidEntity(e)) then
			-- Example code taken from Jinto: http://forums.facepunchstudios.com/showpost.php?p=11924781&postcount=12
			local plane = Plane(e:GetForward(),e:GetPos());
			render.EnableClipping(true);
			render.PushCustomClipPlane(plane.Normal,plane.Distance);
				e:DrawModel();
				-- for k,v in pairs(ents) do
					-- if(not ValidEntity(v)) then
						-- ents[k] = nil;
					-- else
						-- v:DrawModel();
					-- end
				-- end
			render.PopCustomClipPlane();
		else
			StarGate.Clipping.__SENTS[e] = nil;
		end
	end
end
hook.Add("RenderScreenspaceEffects","StarGate.Hook.ClippingRenderScreenspaceEffects",StarGate.Hook.ClippingRenderScreenspaceEffects);
--]]