Daniele Bartolini 11 лет назад
Родитель
Сommit
96ffd8a529
4 измененных файлов с 201 добавлено и 17 удалено
  1. 86 0
      engine/renderers/material_manager.cpp
  2. 61 0
      engine/renderers/material_manager.h
  3. 16 10
      makefile
  4. 38 7
      premake/premake4.lua

+ 86 - 0
engine/renderers/material_manager.cpp

@@ -0,0 +1,86 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include "material_manager.h"
+#include "memory.h"
+#include "sort_map.h"
+
+namespace crown
+{
+
+namespace material_manager
+{
+	static MaterialManager* s_mmgr = NULL;
+
+	void init()
+	{
+		s_mmgr = CE_NEW(default_allocator(), MaterialManager)();
+	}
+
+	void shutdown()
+	{
+		CE_DELETE(default_allocator(), s_mmgr);
+	}
+
+	MaterialManager* get()
+	{
+		return s_mmgr;
+	}
+} // namespace material_manager
+
+MaterialManager::MaterialManager()
+	: m_materials(default_allocator())
+{
+}
+
+void MaterialManager::load(StringId64 id, ResourceManager& rm)
+{
+	ResourceId res_id;
+	res_id.type = MATERIAL_TYPE;
+	res_id.name = id;
+
+	Material mat;
+	mat.create((MaterialResource*) rm.get(res_id));
+
+	sort_map::set(m_materials, id, mat);
+	sort_map::sort(m_materials);
+}
+
+void MaterialManager::unload(StringId64 id, ResourceManager& /*rm*/)
+{
+	Material deff;
+	deff.program.idx = BGFX_INVALID_HANDLE;
+	sort_map::get(m_materials, id, deff).destroy();
+}
+
+const Material& MaterialManager::get(StringId64 id)
+{
+	Material deff;
+	deff.program.idx = BGFX_INVALID_HANDLE;
+	return sort_map::get(m_materials, id, deff);
+}
+
+} // namespace crown

+ 61 - 0
engine/renderers/material_manager.h

@@ -0,0 +1,61 @@
+/*
+Copyright (c) 2013 Daniele Bartolini, Michele Rossi
+Copyright (c) 2012 Daniele Bartolini, Simone Boscaratto
+
+Permission is hereby granted, free of charge, to any person
+obtaining a copy of this software and associated documentation
+files (the "Software"), to deal in the Software without
+restriction, including without limitation the rights to use,
+copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following
+conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#pragma once
+
+#include "types.h"
+#include "container_types.h"
+#include "material.h"
+#include "resource_manager.h"
+#include <bgfx.h>
+
+namespace crown
+{
+
+struct MaterialResource;
+
+struct MaterialManager
+{
+	MaterialManager();
+
+	void load(StringId64 id, ResourceManager& rm);
+	void unload(StringId64 id, ResourceManager& rm);
+	const Material& get(StringId64 id);
+
+private:
+
+	SortMap<StringId64, Material> m_materials;
+};
+
+namespace material_manager
+{
+	void init();
+	void shutdown();
+	MaterialManager* get();
+	
+} // namespace material_manager
+
+} // namespace crown

+ 16 - 10
makefile

@@ -23,33 +23,39 @@ luajit-arm:
 luajit-clean:
 	make -R -C third/luajit clean
 
-bgfx-linux32:
+bgfx-linux-debug32:
+	make -R -C third/bgfx linux-debug32
+bgfx-linux-debug64:
+	make -R -C third/bgfx linux-debug64
+bgfx-linux-release32:
 	make -R -C third/bgfx linux-release32
-bgfx-linux64:
+bgfx-linux-release64:
 	make -R -C third/bgfx linux-release64
 bgfx-android-arm:
 	make -R -C third/bgfx android-arm-release
 bgfx-clean:
 	make -R -C third/bgfx clean
 
-deps-linux32: luajit-linux32 bgfx-linux32
-deps-linux64: luajit-linux64 bgfx-linux64
+deps-linux-debug32: luajit-linux32 bgfx-linux-debug32
+deps-linux-debug64: luajit-linux64 bgfx-linux-debug64
+deps-linux-release32: luajit-linux32 bgfx-linux-release32
+deps-linux-release64: luajit-linux64 bgfx-linux-release64
 deps-android-arm: luajit-arm bgfx-android-arm
 deps-clean: luajit-clean bgfx-clean
 
 linux-build:
 	$(PREMAKE) --file=premake/premake4.lua --compiler=linux-gcc gmake
-linux-debug32: deps-linux32 linux-build
+linux-debug32: deps-linux-debug32 linux-build
 	make -R -C .build/linux config=debug32
-linux-development32: deps-linux32 linux-build
+linux-development32: deps-linux-debug32 linux-build
 	make -R -C .build/linux config=development32
-linux-release32: deps-linux32 linux-build
+linux-release32: deps-linux-release32 linux-build
 	make -R -C .build/linux config=release32
-linux-debug64: deps-linux64 linux-build
+linux-debug64: deps-linux-debug64 linux-build
 	make -R -C .build/linux config=debug64
-linux-development64: deps-linux64 linux-build	
+linux-development64: deps-linux-debug64 linux-build	
 	make -R -C .build/linux config=development64
-linux-release64: deps-linux64 linux-build
+linux-release64: deps-linux-release64 linux-build
 	make -R -C .build/linux config=release64
 linux: linux-debug32 linux-development32 linux-release32 linux-debug64 linux-development64 linux-release64
 

+ 38 - 7
premake/premake4.lua

@@ -211,8 +211,7 @@ solution "crown"
 				"GL",
 				"X11",
 				"openal",
-				"luajit",
-				"bgfxRelease"
+				"luajit"
 			}
 
 			includedirs {
@@ -258,7 +257,12 @@ solution "crown"
 				"-O0"
 			}
 
-			linkoptions { 
+			links {
+				"bgfxDebug"
+			}
+
+			linkoptions {
+				"-rdynamic",
 				"-Wl,--start-group $(addprefix -l," ..
 				"	LowLevelClothCHECKED" ..
 				"	PhysX3CHECKED " ..
@@ -282,8 +286,13 @@ solution "crown"
 				"-O2"
 			}
 
+			links {
+				"bgfxDebug"
+			}
+
 			linkoptions
-			{ 
+			{
+				"-rdynamic",
 				"-Wl,--start-group $(addprefix -l," ..
 				"	LowLevelClothPROFILE" ..
 				"	PhysX3PROFILE " ..
@@ -307,7 +316,11 @@ solution "crown"
 				"-O2"
 			}
 
-			linkoptions { 
+			links {
+				"bgfxRelease"
+			}
+
+			linkoptions {
 				"-Wl,--start-group $(addprefix -l," ..
 				"	LowLevelCloth" ..
 				"	PhysX3 " ..
@@ -342,7 +355,6 @@ solution "crown"
 			postbuildcommands {
 				"cp " .. CROWN_THIRD_DIR .. "luajit/src/luajit " .. CROWN_INSTALL_DIR .. "bin/linux32/",
 				"cp " .. CROWN_THIRD_DIR .. "luajit/src/jit " .. CROWN_INSTALL_DIR .. "bin/linux32/" .. " -r",
-				"cp " .. CROWN_THIRD_DIR .. "bgfx/.build/linux32_gcc/bin/shadercRelease " .. CROWN_INSTALL_DIR .. "bin/linux32/shaderc",
 			}
 
 		configuration { "linux-*", "x64" }
@@ -357,7 +369,26 @@ solution "crown"
 			postbuildcommands {
 				"cp " .. CROWN_THIRD_DIR .. "luajit/src/luajit " .. CROWN_INSTALL_DIR .. "bin/linux64/",
 				"cp " .. CROWN_THIRD_DIR .. "luajit/src/jit " .. CROWN_INSTALL_DIR .. "bin/linux64/" .. " -r",
-				"cp " .. CROWN_THIRD_DIR .. "bgfx/.build/linux64_gcc/bin/shadercRelease " .. CROWN_INSTALL_DIR .. "bin/linux64/shaderc",
+			}
+
+		configuration { "debug or development", "x32", "linux-*" }
+			postbuildcommands {
+				"cp " .. CROWN_THIRD_DIR .. "bgfx/.build/linux32_gcc/bin/shadercDebug " .. CROWN_INSTALL_DIR .. "bin/linux32/shaderc"
+			}
+
+		configuration { "release", "x32", "linux-*" }
+			postbuildcommands {
+				"cp " .. CROWN_THIRD_DIR .. "bgfx/.build/linux32_gcc/bin/shadercRelease " .. CROWN_INSTALL_DIR .. "bin/linux32/shaderc"
+			}
+
+		configuration { "debug or development", "x64", "linux-*" }
+			postbuildcommands {
+				"cp " .. CROWN_THIRD_DIR .. "bgfx/.build/linux64_gcc/bin/shadercDebug " .. CROWN_INSTALL_DIR .. "bin/linux64/shaderc"
+			}
+
+		configuration { "release", "x64", "linux-*" }
+			postbuildcommands {
+				"cp " .. CROWN_THIRD_DIR .. "bgfx/.build/linux64_gcc/bin/shadercRelease " .. CROWN_INSTALL_DIR .. "bin/linux64/shaderc"
 			}
 
 		configuration { "android" }