瀏覽代碼

Restored skeletal animation functionality, removed CPU-based skinning, added sameple GPU-skinning material, fixed potential Texture binding crash in renderer, defaulted texture filtering mode to linear

Ivan Safrin 9 年之前
父節點
當前提交
3891dfc58f
共有 39 個文件被更改,包括 460 次插入267 次删除
  1. 二進制
      assets/default/default.pak
  2. 59 0
      assets/default/default/GPUSkinning.vert
  3. 13 1
      assets/default/default/default.mat
  4. 2 2
      bindings/javascript/Polycode/Bone.js
  5. 16 1
      bindings/javascript/Polycode/LocalShaderParam.js
  6. 6 0
      bindings/javascript/Polycode/ResourcePool.js
  7. 20 0
      bindings/javascript/Polycode/SDLAudioInterface.js
  8. 0 4
      bindings/javascript/Polycode/SceneMesh.js
  9. 3 3
      bindings/javascript/Polycode/Skeleton.js
  10. 二進制
      bindings/javascript/js_Polycode.pak
  11. 2 2
      bindings/lua/Polycode/Bone.lua
  12. 13 0
      bindings/lua/Polycode/LocalShaderParam.lua
  13. 8 0
      bindings/lua/Polycode/ResourcePool.lua
  14. 32 0
      bindings/lua/Polycode/SDLAudioInterface.lua
  15. 0 4
      bindings/lua/Polycode/SceneMesh.lua
  16. 2 2
      bindings/lua/Polycode/Skeleton.lua
  17. 二進制
      bindings/lua/lua_Polycode.pak
  18. 59 31
      include/polycode/bindings/javascript/PolycodeJSWrappers.h
  19. 76 46
      include/polycode/bindings/lua/PolycodeLuaWrappers.h
  20. 6 6
      include/polycode/core/PolyBone.h
  21. 2 2
      include/polycode/core/PolyImage.h
  22. 3 1
      include/polycode/core/PolyResourceManager.h
  23. 4 10
      include/polycode/core/PolySceneMesh.h
  24. 3 0
      include/polycode/core/PolyShader.h
  25. 8 8
      include/polycode/core/PolySkeleton.h
  26. 3 1
      scripts/create_bindings/BindingsGenerator.py
  27. 1 1
      scripts/create_bindings/bindings.conf
  28. 4 1
      src/bindings/javascript/PolycodeJS.cpp
  29. 4 1
      src/bindings/lua/PolycodeLua.cpp
  30. 2 2
      src/core/PolyBezierCurve.cpp
  31. 4 4
      src/core/PolyBone.cpp
  32. 1 1
      src/core/PolyImage.cpp
  33. 4 3
      src/core/PolyOpenGLGraphicsInterface.cpp
  34. 4 0
      src/core/PolyResourceManager.cpp
  35. 2 2
      src/core/PolyScene.cpp
  36. 39 112
      src/core/PolySceneMesh.cpp
  37. 42 3
      src/core/PolyShader.cpp
  38. 12 12
      src/core/PolySkeleton.cpp
  39. 1 1
      src/core/PolyTexture.cpp

二進制
assets/default/default.pak


+ 59 - 0
assets/default/default/GPUSkinning.vert

@@ -0,0 +1,59 @@
+#ifdef GL_ES
+	precision mediump float;
+#endif
+
+#define MAX_JOINT_COUNT 64
+
+attribute vec4 position;
+attribute vec3 normal;
+attribute vec2 texCoord;
+attribute vec4 boneIndices;
+attribute vec4 boneWeights;
+
+uniform mat4 modelMatrix;
+uniform mat4 viewMatrix;
+uniform mat4 projectionMatrix;
+uniform mat4 skeletonMatrix[MAX_JOINT_COUNT];
+
+varying vec2 texCoordVar;
+varying vec3 varNormal;
+varying vec4 varPosition;
+
+mat3 mat3_emu(mat4 m4) {
+  return mat3(
+      m4[0][0], m4[0][1], m4[0][2],
+      m4[1][0], m4[1][1], m4[1][2],
+      m4[2][0], m4[2][1], m4[2][2]);
+}
+
+void jointInfluence(in mat4 joint_matrix, in float weight, in vec4 position, inout vec4 outPosition, in vec3 normal, inout vec3 outNormal)
+{
+  outPosition += weight * (joint_matrix * position);
+
+  mat3 normalMatrix = mat3_emu(joint_matrix);
+  outNormal += weight * (normalMatrix * normal);
+}
+
+void main() {
+
+	vec4 outVert = vec4(0.0, 0.0, 0.0, 0.0);
+	vec3 outNormal = vec3(0.0, 0.0, 0.0);
+
+	jointInfluence(skeletonMatrix[int(boneIndices.x)], boneWeights.x, position, outVert, normal, outNormal);
+    jointInfluence(skeletonMatrix[int(boneIndices.y)], boneWeights.y, position, outVert, normal, outNormal);
+    jointInfluence(skeletonMatrix[int(boneIndices.z)], boneWeights.z, position, outVert, normal, outNormal);
+    jointInfluence(skeletonMatrix[int(boneIndices.w)], boneWeights.w, position, outVert, normal, outNormal);
+
+	outVert.w = 1.0;
+
+	mat4 modelViewMatrix = viewMatrix * modelMatrix;
+	vec4 p = modelViewMatrix  * outVert;
+
+	mat3 rotN = mat3_emu(modelViewMatrix);
+	varNormal = normalize(rotN * normalize(outNormal));
+
+	varPosition = modelViewMatrix  * outVert;
+	gl_Position = projectionMatrix * p;
+
+	texCoordVar = texCoord;
+}

+ 13 - 1
assets/default/default/default.mat

@@ -5,6 +5,10 @@
 			<vp source="default/DefaultShader.vert"/>
 			<fp source="default/DefaultShader.frag"/>
 		</shader>
+		<shader type="glsl" name="DefaultShaderAnimated" numPointLights="6" numSpotLights="2">
+			<vp source="default/GPUSkinning.vert"/>
+			<fp source="default/DefaultShader.frag"/>
+		</shader>		
 		<shader type="glsl" name="DefaultShaderShadows" numPointLights="6" numSpotLights="2">
 			<vp source="default/DefaultShaderShadows.vert"/>
 			<fp source="default/DefaultShaderShadows.frag"/>
@@ -89,7 +93,15 @@
 					<param name="diffuse_color" value="1.0 1.0 1.0 1.0" />
 				</params>					
 			</shader>
-		</material>				
+		</material>
+		<material name="DefaultTexturedAnimated">
+			<shader name="DefaultShaderAnimated">
+				<params>
+					<param name="entityColor" value="1.0 1.0 1.0 1.0" />
+					<param name="diffuse_color" value="1.0 1.0 1.0 1.0" />
+				</params>					
+			</shader>
+		</material>		
 		<material name="DefaultTextured">
 			<shader name="DefaultShader">
 				<params>

+ 2 - 2
bindings/javascript/Polycode/Bone.js

@@ -117,11 +117,11 @@ Bone.prototype.getName = function() {
 }
 
 Bone.prototype.setParentBone = function(bone) {
-	Polycode.Bone_setParentBone(this.__ptr, bone.__ptr)
+	Polycode.Bone_setParentBone(this.__ptr, bone)
 }
 
 Bone.prototype.addChildBone = function(bone) {
-	Polycode.Bone_addChildBone(this.__ptr, bone.__ptr)
+	Polycode.Bone_addChildBone(this.__ptr, bone)
 }
 
 Bone.prototype.getParentBone = function() {

+ 16 - 1
bindings/javascript/Polycode/LocalShaderParam.js

@@ -7,7 +7,8 @@ function LocalShaderParam() {
 		'type': { enumerable: true, configurable: true, get: LocalShaderParam.prototype.__get_type, set: LocalShaderParam.prototype.__set_type},
 		'ownsPointer': { enumerable: true, configurable: true, get: LocalShaderParam.prototype.__get_ownsPointer, set: LocalShaderParam.prototype.__set_ownsPointer},
 		'arraySize': { enumerable: true, configurable: true, get: LocalShaderParam.prototype.__get_arraySize, set: LocalShaderParam.prototype.__set_arraySize},
-		'param': { enumerable: true, configurable: true, get: LocalShaderParam.prototype.__get_param, set: LocalShaderParam.prototype.__set_param}
+		'param': { enumerable: true, configurable: true, get: LocalShaderParam.prototype.__get_param, set: LocalShaderParam.prototype.__set_param},
+		'accessMutex': { enumerable: true, configurable: true, get: LocalShaderParam.prototype.__get_accessMutex, set: LocalShaderParam.prototype.__set_accessMutex}
 	})
 }
 
@@ -53,6 +54,16 @@ LocalShaderParam.prototype.__set_param = function(val) {
 	Polycode.LocalShaderParam__set_param(this.__ptr, val.__ptr)
 }
 
+LocalShaderParam.prototype.__get_accessMutex = function() {
+	var retVal = new CoreMutex()
+	retVal.__ptr = 	Polycode.LocalShaderParam__get_accessMutex(this.__ptr)
+	return retVal
+}
+
+LocalShaderParam.prototype.__set_accessMutex = function(val) {
+	Polycode.LocalShaderParam__set_accessMutex(this.__ptr, val.__ptr)
+}
+
 Duktape.fin(LocalShaderParam.prototype, function (x) {
 	if (x === LocalShaderParam.prototype) {
 		return;
@@ -110,6 +121,10 @@ LocalShaderParam.prototype.setMatrix4 = function(x) {
 	Polycode.LocalShaderParam_setMatrix4(this.__ptr, x)
 }
 
+LocalShaderParam.prototype.setMatrix4Array = function(x) {
+	Polycode.LocalShaderParam_setMatrix4Array(this.__ptr, x)
+}
+
 LocalShaderParam.prototype.setColor = function(x) {
 	Polycode.LocalShaderParam_setColor(this.__ptr, x)
 }

+ 6 - 0
bindings/javascript/Polycode/ResourcePool.js

@@ -103,6 +103,12 @@ ResourcePool.prototype.setName = function(name) {
 	Polycode.ResourcePool_setName(this.__ptr, name)
 }
 
+ResourcePool.prototype.loadFont = function(name,path) {
+	var retVal = new Font()
+	retVal.__ptr = Polycode.ResourcePool_loadFont(this.__ptr, name, path)
+	return retVal
+}
+
 ResourcePool.prototype.getResourceByPath = function(resourcePath) {
 	var retVal = new Resource()
 	retVal.__ptr = Polycode.ResourcePool_getResourceByPath(this.__ptr, resourcePath)

+ 20 - 0
bindings/javascript/Polycode/SDLAudioInterface.js

@@ -0,0 +1,20 @@
+require('Polycode/Polycode::AudioInterface')
+
+function SDLAudioInterface() {
+	if(arguments[0] != "__skip_ptr__") {
+		this.__ptr = Polycode.SDLAudioInterface()
+	}
+}
+
+SDLAudioInterface.prototype = Object.create(Polycode::AudioInterface.prototype);
+
+Duktape.fin(SDLAudioInterface.prototype, function (x) {
+	if (x === SDLAudioInterface.prototype) {
+		return;
+	}
+	Polycode.SDLAudioInterface__delete(x.__ptr)
+})
+
+SDLAudioInterface.prototype.sdlCallback = function(userData,_stream,_length) {
+	Polycode.SDLAudioInterface_sdlCallback(userData.__ptr, _stream.__ptr, _length)
+}

+ 0 - 4
bindings/javascript/Polycode/SceneMesh.js

@@ -146,10 +146,6 @@ SceneMesh.prototype.getSkeleton = function() {
 	return retVal
 }
 
-SceneMesh.prototype.applySkeletonLocally = function() {
-	Polycode.SceneMesh_applySkeletonLocally(this.__ptr)
-}
-
 SceneMesh.prototype.setLineWidth = function(newWidth) {
 	Polycode.SceneMesh_setLineWidth(this.__ptr, newWidth)
 }

+ 3 - 3
bindings/javascript/Polycode/Skeleton.js

@@ -94,13 +94,13 @@ Skeleton.prototype.getBone = function(index) {
 }
 
 Skeleton.prototype.addBone = function(bone) {
-	Polycode.Skeleton_addBone(this.__ptr, bone.__ptr)
+	Polycode.Skeleton_addBone(this.__ptr, bone)
 }
 
 Skeleton.prototype.removeBone = function(bone) {
-	Polycode.Skeleton_removeBone(this.__ptr, bone.__ptr)
+	Polycode.Skeleton_removeBone(this.__ptr, bone)
 }
 
 Skeleton.prototype.getBoneIndexByBone = function(bone) {
-	return Polycode.Skeleton_getBoneIndexByBone(this.__ptr, bone.__ptr)
+	return Polycode.Skeleton_getBoneIndexByBone(this.__ptr, bone)
 }

二進制
bindings/javascript/js_Polycode.pak


+ 2 - 2
bindings/lua/Polycode/Bone.lua

@@ -127,7 +127,7 @@ end
 function Bone:getParentBone()
 	local retVal =  Polycode.Bone_getParentBone(self.__ptr)
 	if retVal == nil then return nil end
-	local __c = _G["Bone"]("__skip_ptr__")
+	local __c = _G["shared_ptr<Bone>"]("__skip_ptr__")
 	__c.__ptr = retVal
 	return __c
 end
@@ -140,7 +140,7 @@ end
 function Bone:getChildBone(index)
 	local retVal = Polycode.Bone_getChildBone(self.__ptr, index)
 	if retVal == nil then return nil end
-	local __c = _G["Bone"]("__skip_ptr__")
+	local __c = _G["shared_ptr<Bone>"]("__skip_ptr__")
 	__c.__ptr = retVal
 	return __c
 end

+ 13 - 0
bindings/lua/Polycode/LocalShaderParam.lua

@@ -16,6 +16,12 @@ function LocalShaderParam:__getvar(name)
 		local __c = _G["ProgramParam"]("__skip_ptr__")
 		__c.__ptr = retVal
 		return __c
+	elseif name == "accessMutex" then
+		local retVal = Polycode.LocalShaderParam_get_accessMutex(self.__ptr)
+		if retVal == nil then return nil end
+		local __c = _G["CoreMutex"]("__skip_ptr__")
+		__c.__ptr = retVal
+		return __c
 	end
 end
 
@@ -35,6 +41,9 @@ function LocalShaderParam:__setvar(name,value)
 	elseif name == "param" then
 		Polycode.LocalShaderParam_set_param(self.__ptr, value.__ptr)
 		return true
+	elseif name == "accessMutex" then
+		Polycode.LocalShaderParam_set_accessMutex(self.__ptr, value.__ptr)
+		return true
 	end
 	return false
 end
@@ -113,6 +122,10 @@ function LocalShaderParam:setMatrix4(x)
 	local retVal = Polycode.LocalShaderParam_setMatrix4(self.__ptr, x.__ptr)
 end
 
+function LocalShaderParam:setMatrix4Array(x)
+	local retVal = Polycode.LocalShaderParam_setMatrix4Array(self.__ptr, x.__ptr)
+end
+
 function LocalShaderParam:setColor(x)
 	local retVal = Polycode.LocalShaderParam_setColor(self.__ptr, x.__ptr)
 end

+ 8 - 0
bindings/lua/Polycode/ResourcePool.lua

@@ -116,6 +116,14 @@ function ResourcePool:setName(name)
 	local retVal = Polycode.ResourcePool_setName(self.__ptr, name)
 end
 
+function ResourcePool:loadFont(name, path)
+	local retVal = Polycode.ResourcePool_loadFont(self.__ptr, name, path)
+	if retVal == nil then return nil end
+	local __c = _G["shared_ptr<Font>"]("__skip_ptr__")
+	__c.__ptr = retVal
+	return __c
+end
+
 function ResourcePool:getResourceByPath(resourcePath)
 	local retVal = Polycode.ResourcePool_getResourceByPath(self.__ptr, resourcePath)
 	if retVal == nil then return nil end

+ 32 - 0
bindings/lua/Polycode/SDLAudioInterface.lua

@@ -0,0 +1,32 @@
+require "Polycode/Polycode::AudioInterface"
+
+class "SDLAudioInterface" (Polycode::AudioInterface)
+
+
+function SDLAudioInterface:SDLAudioInterface(...)
+	local arg = {...}
+	if type(arg[1]) == "table" and count(arg) == 1 then
+		if ""..arg[1].__classname == "Polycode::AudioInterface" then
+			self.__ptr = arg[1].__ptr
+			return
+		end
+	end
+	for k,v in pairs(arg) do
+		if type(v) == "table" then
+			if v.__ptr ~= nil then
+				arg[k] = v.__ptr
+			end
+		end
+	end
+	if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
+		self.__ptr = Polycode.SDLAudioInterface(unpack(arg))
+	end
+end
+
+function SDLAudioInterface:sdlCallback(userData, _stream, _length)
+	local retVal = Polycode.SDLAudioInterface_sdlCallback(self.__ptr, userData.__ptr, _stream.__ptr, _length)
+end
+
+function SDLAudioInterface:__delete()
+	if self then Polycode.delete_SDLAudioInterface(self.__ptr) end
+end

+ 0 - 4
bindings/lua/Polycode/SceneMesh.lua

@@ -158,10 +158,6 @@ function SceneMesh:getSkeleton()
 	return __c
 end
 
-function SceneMesh:applySkeletonLocally()
-	local retVal =  Polycode.SceneMesh_applySkeletonLocally(self.__ptr)
-end
-
 function SceneMesh:setLineWidth(newWidth)
 	local retVal = Polycode.SceneMesh_setLineWidth(self.__ptr, newWidth)
 end

+ 2 - 2
bindings/lua/Polycode/Skeleton.lua

@@ -90,7 +90,7 @@ end
 function Skeleton:getBoneByName(name)
 	local retVal = Polycode.Skeleton_getBoneByName(self.__ptr, name)
 	if retVal == nil then return nil end
-	local __c = _G["Bone"]("__skip_ptr__")
+	local __c = _G["shared_ptr<Bone>"]("__skip_ptr__")
 	__c.__ptr = retVal
 	return __c
 end
@@ -107,7 +107,7 @@ end
 function Skeleton:getBone(index)
 	local retVal = Polycode.Skeleton_getBone(self.__ptr, index)
 	if retVal == nil then return nil end
-	local __c = _G["Bone"]("__skip_ptr__")
+	local __c = _G["shared_ptr<Bone>"]("__skip_ptr__")
 	__c.__ptr = retVal
 	return __c
 end

二進制
bindings/lua/lua_Polycode.pak


+ 59 - 31
include/polycode/bindings/javascript/PolycodeJSWrappers.h

@@ -455,22 +455,23 @@ namespace Polycode {
 
 	duk_ret_t Polycode_Bone_setParentBone(duk_context *context) {
 		Bone *inst = (Bone*)duk_to_pointer(context, 0);
-		Bone* bone = (Bone*)duk_to_pointer(context, 1);
+		shared_ptr<Bone> bone = *(shared_ptr<Bone>*)duk_to_pointer(context, 1);
 		inst->setParentBone(bone);
 		return 0;
 	}
 
 	duk_ret_t Polycode_Bone_addChildBone(duk_context *context) {
 		Bone *inst = (Bone*)duk_to_pointer(context, 0);
-		Bone* bone = (Bone*)duk_to_pointer(context, 1);
+		shared_ptr<Bone> bone = *(shared_ptr<Bone>*)duk_to_pointer(context, 1);
 		inst->addChildBone(bone);
 		return 0;
 	}
 
 	duk_ret_t Polycode_Bone_getParentBone(duk_context *context) {
 		Bone *inst = (Bone*)duk_to_pointer(context, 0);
-		PolyBase *ptrRetVal = (PolyBase*)inst->getParentBone();
-		duk_push_pointer(context, (void*)ptrRetVal);
+		shared_ptr<Bone> *retInst = new shared_ptr<Bone>();
+		*retInst = inst->getParentBone();
+		duk_push_pointer(context, (void*)retInst);
 		return 1;
 	}
 
@@ -483,8 +484,9 @@ namespace Polycode {
 	duk_ret_t Polycode_Bone_getChildBone(duk_context *context) {
 		Bone *inst = (Bone*)duk_to_pointer(context, 0);
 		int index = duk_to_int(context, 1);
-		PolyBase *ptrRetVal = (PolyBase*)inst->getChildBone(index);
-		duk_push_pointer(context, (void*)ptrRetVal);
+		shared_ptr<Bone> *retInst = new shared_ptr<Bone>();
+		*retInst = inst->getChildBone(index);
+		duk_push_pointer(context, (void*)retInst);
 		return 1;
 	}
 
@@ -847,7 +849,7 @@ namespace Polycode {
 
 	duk_ret_t Polycode_Camera_setViewport(duk_context *context) {
 		Camera *inst = (Camera*)duk_to_pointer(context, 0);
-		Rectangle viewport = *(Rectangle*)duk_to_pointer(context, 1);
+		Polycode::Rectangle viewport = *(Polycode::Rectangle*)duk_to_pointer(context, 1);
 		inst->setViewport(viewport);
 		return 0;
 	}
@@ -881,7 +883,7 @@ namespace Polycode {
 	duk_ret_t Polycode_Camera_projectRayFrom2DCoordinate(duk_context *context) {
 		Camera *inst = (Camera*)duk_to_pointer(context, 0);
 		Vector2 coordinate = *(Vector2*)duk_to_pointer(context, 1);
-		Rectangle viewport = *(Rectangle*)duk_to_pointer(context, 2);
+		Polycode::Rectangle viewport = *(Polycode::Rectangle*)duk_to_pointer(context, 2);
 		Vector3 *retInst = new Vector3();
 		*retInst = inst->projectRayFrom2DCoordinate(coordinate,viewport);
 		duk_push_pointer(context, (void*)retInst);
@@ -2737,7 +2739,7 @@ namespace Polycode {
 
 	duk_ret_t Polycode_CoreServices_Render(duk_context *context) {
 		CoreServices *inst = (CoreServices*)duk_to_pointer(context, 0);
-		Rectangle viewport = *(Rectangle*)duk_to_pointer(context, 1);
+		Polycode::Rectangle viewport = *(Polycode::Rectangle*)duk_to_pointer(context, 1);
 		inst->Render(viewport);
 		return 0;
 	}
@@ -3320,7 +3322,7 @@ namespace Polycode {
 	duk_ret_t Polycode_Entity_transformAndRender(duk_context *context) {
 		Entity *inst = (Entity*)duk_to_pointer(context, 0);
 		GPUDrawBuffer* drawBuffer = (GPUDrawBuffer*)duk_to_pointer(context, 1);
-		Rectangle* parentScissorBox = (Rectangle*)duk_to_pointer(context, 2);
+		Polycode::Rectangle* parentScissorBox = (Polycode::Rectangle*)duk_to_pointer(context, 2);
 		inst->transformAndRender(drawBuffer,parentScissorBox);
 		return 0;
 	}
@@ -3328,7 +3330,7 @@ namespace Polycode {
 	duk_ret_t Polycode_Entity_renderChildren(duk_context *context) {
 		Entity *inst = (Entity*)duk_to_pointer(context, 0);
 		GPUDrawBuffer* buffer = (GPUDrawBuffer*)duk_to_pointer(context, 1);
-		Rectangle* parentScissorBox = (Rectangle*)duk_to_pointer(context, 2);
+		Polycode::Rectangle* parentScissorBox = (Polycode::Rectangle*)duk_to_pointer(context, 2);
 		inst->renderChildren(buffer,parentScissorBox);
 		return 0;
 	}
@@ -4066,7 +4068,7 @@ namespace Polycode {
 		Entity *inst = (Entity*)duk_to_pointer(context, 0);
 		Matrix4 projectionMatrix = *(Matrix4*)duk_to_pointer(context, 1);
 		Matrix4 cameraMatrix = *(Matrix4*)duk_to_pointer(context, 2);
-		Rectangle viewport = *(Rectangle*)duk_to_pointer(context, 3);
+		Polycode::Rectangle viewport = *(Polycode::Rectangle*)duk_to_pointer(context, 3);
 		Vector2 *retInst = new Vector2();
 		*retInst = inst->getScreenPosition(projectionMatrix,cameraMatrix,viewport);
 		duk_push_pointer(context, (void*)retInst);
@@ -5079,7 +5081,7 @@ namespace Polycode {
 
 	duk_ret_t Polycode_Image_getImagePart(duk_context *context) {
 		Image *inst = (Image*)duk_to_pointer(context, 0);
-		Rectangle subRect = *(Rectangle*)duk_to_pointer(context, 1);
+		Polycode::Rectangle subRect = *(Polycode::Rectangle*)duk_to_pointer(context, 1);
 		PolyBase *ptrRetVal = (PolyBase*)inst->getImagePart(subRect);
 		duk_push_pointer(context, (void*)ptrRetVal);
 		return 1;
@@ -8041,7 +8043,7 @@ namespace Polycode {
 
 	duk_ret_t Polycode_Rectangle_Clipped(duk_context *context) {
 		Rectangle *inst = (Rectangle*)duk_to_pointer(context, 0);
-		Rectangle rect = *(Rectangle*)duk_to_pointer(context, 1);
+		Polycode::Rectangle rect = *(Polycode::Rectangle*)duk_to_pointer(context, 1);
 		Polycode::Rectangle *retInst = new Polycode::Rectangle();
 		*retInst = inst->Clipped(rect);
 		duk_push_pointer(context, (void*)retInst);
@@ -8453,7 +8455,7 @@ namespace Polycode {
 		Vector3 position = *(Vector3*)duk_to_pointer(context, 0);
 		Matrix4 modelMatrix = *(Matrix4*)duk_to_pointer(context, 1);
 		Matrix4 projectionMatrix = *(Matrix4*)duk_to_pointer(context, 2);
-		Rectangle viewport = *(Rectangle*)duk_to_pointer(context, 3);
+		Polycode::Rectangle viewport = *(Polycode::Rectangle*)duk_to_pointer(context, 3);
 		Vector3 *retInst = new Vector3();
 		*retInst = Renderer::unProject(position,modelMatrix,projectionMatrix,viewport);
 		duk_push_pointer(context, (void*)retInst);
@@ -8464,7 +8466,7 @@ namespace Polycode {
 		Vector3 position = *(Vector3*)duk_to_pointer(context, 0);
 		Matrix4 modelMatrix = *(Matrix4*)duk_to_pointer(context, 1);
 		Matrix4 projectionMatrix = *(Matrix4*)duk_to_pointer(context, 2);
-		Rectangle viewport = *(Rectangle*)duk_to_pointer(context, 3);
+		Polycode::Rectangle viewport = *(Polycode::Rectangle*)duk_to_pointer(context, 3);
 		Vector3 *retInst = new Vector3();
 		*retInst = Renderer::project(position,modelMatrix,projectionMatrix,viewport);
 		duk_push_pointer(context, (void*)retInst);
@@ -8729,6 +8731,16 @@ namespace Polycode {
 		return 0;
 	}
 
+	duk_ret_t Polycode_ResourcePool_loadFont(duk_context *context) {
+		ResourcePool *inst = (ResourcePool*)duk_to_pointer(context, 0);
+		String name = duk_to_string(context, 1);
+		String path = duk_to_string(context, 2);
+		shared_ptr<Font> *retInst = new shared_ptr<Font>();
+		*retInst = inst->loadFont(name,path);
+		duk_push_pointer(context, (void*)retInst);
+		return 1;
+	}
+
 	duk_ret_t Polycode_ResourcePool_getResourceByPath(duk_context *context) {
 		ResourcePool *inst = (ResourcePool*)duk_to_pointer(context, 0);
 		String resourcePath = duk_to_string(context, 1);
@@ -10134,7 +10146,7 @@ namespace Polycode {
 
 	duk_ret_t Polycode_SceneManager_Render(duk_context *context) {
 		SceneManager *inst = (SceneManager*)duk_to_pointer(context, 0);
-		Rectangle viewport = *(Rectangle*)duk_to_pointer(context, 1);
+		Polycode::Rectangle viewport = *(Polycode::Rectangle*)duk_to_pointer(context, 1);
 		inst->Render(viewport);
 		return 0;
 	}
@@ -10374,12 +10386,6 @@ namespace Polycode {
 		return 1;
 	}
 
-	duk_ret_t Polycode_SceneMesh_applySkeletonLocally(duk_context *context) {
-		SceneMesh *inst = (SceneMesh*)duk_to_pointer(context, 0);
-		inst->applySkeletonLocally();
-		return 0;
-	}
-
 	duk_ret_t Polycode_SceneMesh_setLineWidth(duk_context *context) {
 		SceneMesh *inst = (SceneMesh*)duk_to_pointer(context, 0);
 		Number newWidth = duk_to_number(context, 1);
@@ -11690,6 +11696,19 @@ namespace Polycode {
 		return 0;
 	}
 
+	duk_ret_t Polycode_LocalShaderParam__get_accessMutex(duk_context *context) {
+		LocalShaderParam *inst = (LocalShaderParam*)duk_to_pointer(context, 0);
+		PolyBase *ptrRetVal = (PolyBase*)inst->accessMutex;
+		duk_push_pointer(context, (void*)ptrRetVal);
+		return 1;
+	}
+
+	duk_ret_t Polycode_LocalShaderParam__set_accessMutex(duk_context *context) {
+		LocalShaderParam *inst = (LocalShaderParam*)duk_to_pointer(context, 0);
+		inst->accessMutex = (CoreMutex*)duk_to_pointer(context, 1);
+		return 0;
+	}
+
 	duk_ret_t Polycode_LocalShaderParam__delete(duk_context *context) {
 		LocalShaderParam *inst = (LocalShaderParam*)duk_to_pointer(context, 0);
 		delete inst;
@@ -11770,6 +11789,13 @@ namespace Polycode {
 		return 0;
 	}
 
+	duk_ret_t Polycode_LocalShaderParam_setMatrix4Array(duk_context *context) {
+		LocalShaderParam *inst = (LocalShaderParam*)duk_to_pointer(context, 0);
+		vector<Matrix4> x = *(vector<Matrix4>*)duk_to_pointer(context, 1);
+		inst->setMatrix4Array(x);
+		return 0;
+	}
+
 	duk_ret_t Polycode_LocalShaderParam_setColor(duk_context *context) {
 		LocalShaderParam *inst = (LocalShaderParam*)duk_to_pointer(context, 0);
 		Color x = *(Color*)duk_to_pointer(context, 1);
@@ -12339,8 +12365,9 @@ namespace Polycode {
 	duk_ret_t Polycode_Skeleton_getBoneByName(duk_context *context) {
 		Skeleton *inst = (Skeleton*)duk_to_pointer(context, 0);
 		String name = duk_to_string(context, 1);
-		PolyBase *ptrRetVal = (PolyBase*)inst->getBoneByName(name);
-		duk_push_pointer(context, (void*)ptrRetVal);
+		shared_ptr<Bone> *retInst = new shared_ptr<Bone>();
+		*retInst = inst->getBoneByName(name);
+		duk_push_pointer(context, (void*)retInst);
 		return 1;
 	}
 
@@ -12360,34 +12387,35 @@ namespace Polycode {
 	duk_ret_t Polycode_Skeleton_getBone(duk_context *context) {
 		Skeleton *inst = (Skeleton*)duk_to_pointer(context, 0);
 		int index = duk_to_int(context, 1);
-		PolyBase *ptrRetVal = (PolyBase*)inst->getBone(index);
-		duk_push_pointer(context, (void*)ptrRetVal);
+		shared_ptr<Bone> *retInst = new shared_ptr<Bone>();
+		*retInst = inst->getBone(index);
+		duk_push_pointer(context, (void*)retInst);
 		return 1;
 	}
 
 	duk_ret_t Polycode_Skeleton_addBone(duk_context *context) {
 		Skeleton *inst = (Skeleton*)duk_to_pointer(context, 0);
-		Bone* bone = (Bone*)duk_to_pointer(context, 1);
+		shared_ptr<Bone> bone = *(shared_ptr<Bone>*)duk_to_pointer(context, 1);
 		inst->addBone(bone);
 		return 0;
 	}
 
 	duk_ret_t Polycode_Skeleton_removeBone(duk_context *context) {
 		Skeleton *inst = (Skeleton*)duk_to_pointer(context, 0);
-		Bone* bone = (Bone*)duk_to_pointer(context, 1);
+		shared_ptr<Bone> bone = *(shared_ptr<Bone>*)duk_to_pointer(context, 1);
 		inst->removeBone(bone);
 		return 0;
 	}
 
 	duk_ret_t Polycode_Skeleton_getBoneIndexByBone(duk_context *context) {
 		Skeleton *inst = (Skeleton*)duk_to_pointer(context, 0);
-		Bone* bone = (Bone*)duk_to_pointer(context, 1);
+		shared_ptr<Bone> bone = *(shared_ptr<Bone>*)duk_to_pointer(context, 1);
 		duk_push_int(context, inst->getBoneIndexByBone(bone));
 		return 1;
 	}
 
 	duk_ret_t Polycode_BoneTrack(duk_context *context) {
-		Bone* bone = (Bone*)duk_to_pointer(context, 0);
+		shared_ptr<Bone> bone = *(shared_ptr<Bone>*)duk_to_pointer(context, 0);
 		Number length = duk_to_number(context, 1);
 		BoneTrack *inst = new BoneTrack(bone,length);
 		duk_push_pointer(context, (void*)inst);

+ 76 - 46
include/polycode/bindings/lua/PolycodeLuaWrappers.h

@@ -586,7 +586,7 @@ static int Polycode_Bone_set_disableAnimation(lua_State *L) {
 		luaL_checktype(L, 1, LUA_TUSERDATA);
 		Bone *inst = (Bone*) *((PolyBase**)lua_touserdata(L, 1));
 		luaL_checktype(L, 2, LUA_TUSERDATA);
-		Bone* bone = (Bone*) *((PolyBase**)lua_touserdata(L, 2));
+		shared_ptr<Bone> bone = *(shared_ptr<Bone>*) *((PolyBase**)lua_touserdata(L, 2));
 		inst->setParentBone(bone);
 		return 0;
 	}
@@ -594,20 +594,19 @@ static int Polycode_Bone_set_disableAnimation(lua_State *L) {
 		luaL_checktype(L, 1, LUA_TUSERDATA);
 		Bone *inst = (Bone*) *((PolyBase**)lua_touserdata(L, 1));
 		luaL_checktype(L, 2, LUA_TUSERDATA);
-		Bone* bone = (Bone*) *((PolyBase**)lua_touserdata(L, 2));
+		shared_ptr<Bone> bone = *(shared_ptr<Bone>*) *((PolyBase**)lua_touserdata(L, 2));
 		inst->addChildBone(bone);
 		return 0;
 	}
 	static int Polycode_Bone_getParentBone(lua_State *L) {
 		luaL_checktype(L, 1, LUA_TUSERDATA);
 		Bone *inst = (Bone*) *((PolyBase**)lua_touserdata(L, 1));
-		PolyBase *ptrRetVal = (PolyBase*)inst->getParentBone();
-		if(ptrRetVal == NULL) {
-			lua_pushnil(L);
-		} else {
-			PolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));
-			*userdataPtr = ptrRetVal;
-		}
+		shared_ptr<Bone> *retInst = new shared_ptr<Bone>();
+		*retInst = inst->getParentBone();
+		PolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));
+		luaL_getmetatable(L, "Polycode.shared_ptr<Bone>");
+		lua_setmetatable(L, -2);
+		*userdataPtr = (PolyBase*)retInst;
 		return 1;
 	}
 	static int Polycode_Bone_getNumChildBones(lua_State *L) {
@@ -621,13 +620,12 @@ static int Polycode_Bone_set_disableAnimation(lua_State *L) {
 		Bone *inst = (Bone*) *((PolyBase**)lua_touserdata(L, 1));
 		luaL_checktype(L, 2, LUA_TNUMBER);
 		int index = lua_tointeger(L, 2);
-		PolyBase *ptrRetVal = (PolyBase*)inst->getChildBone(index);
-		if(ptrRetVal == NULL) {
-			lua_pushnil(L);
-		} else {
-			PolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));
-			*userdataPtr = ptrRetVal;
-		}
+		shared_ptr<Bone> *retInst = new shared_ptr<Bone>();
+		*retInst = inst->getChildBone(index);
+		PolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));
+		luaL_getmetatable(L, "Polycode.shared_ptr<Bone>");
+		lua_setmetatable(L, -2);
+		*userdataPtr = (PolyBase*)retInst;
 		return 1;
 	}
 	static int Polycode_Bone_getBoneMatrix(lua_State *L) {
@@ -11077,6 +11075,21 @@ static int Polycode_ResourcePool_set_deleteOnUnsubscribe(lua_State *L) {
 		inst->setName(name);
 		return 0;
 	}
+	static int Polycode_ResourcePool_loadFont(lua_State *L) {
+		luaL_checktype(L, 1, LUA_TUSERDATA);
+		ResourcePool *inst = (ResourcePool*) *((PolyBase**)lua_touserdata(L, 1));
+		luaL_checktype(L, 2, LUA_TSTRING);
+		String name = String(lua_tostring(L, 2));
+		luaL_checktype(L, 3, LUA_TSTRING);
+		String path = String(lua_tostring(L, 3));
+		shared_ptr<Font> *retInst = new shared_ptr<Font>();
+		*retInst = inst->loadFont(name, path);
+		PolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));
+		luaL_getmetatable(L, "Polycode.shared_ptr<Font>");
+		lua_setmetatable(L, -2);
+		*userdataPtr = (PolyBase*)retInst;
+		return 1;
+	}
 	static int Polycode_ResourcePool_getResourceByPath(lua_State *L) {
 		luaL_checktype(L, 1, LUA_TUSERDATA);
 		ResourcePool *inst = (ResourcePool*) *((PolyBase**)lua_touserdata(L, 1));
@@ -12296,12 +12309,8 @@ static int Polycode_SceneLabel_set_positionAtBaseline(lua_State *L) {
 		String text = String(lua_tostring(L, 1));
 		luaL_checktype(L, 2, LUA_TNUMBER);
 		int size = lua_tointeger(L, 2);
-		String fontName;
-		if(lua_isstring(L, 3)) {
-			fontName = lua_tostring(L, 3);
-		} else {
-			fontName = "sans";
-		}
+		luaL_checktype(L, 3, LUA_TSTRING);
+		String fontName = String(lua_tostring(L, 3));
 		int amode;
 		if(lua_isnumber(L, 4)) {
 			amode = lua_tointeger(L, 4);
@@ -13254,12 +13263,6 @@ static int Polycode_SceneMesh_set_sendBoneMatricesToMaterial(lua_State *L) {
 		*userdataPtr = (PolyBase*)retInst;
 		return 1;
 	}
-	static int Polycode_SceneMesh_applySkeletonLocally(lua_State *L) {
-		luaL_checktype(L, 1, LUA_TUSERDATA);
-		SceneMesh *inst = (SceneMesh*) *((PolyBase**)lua_touserdata(L, 1));
-		inst->applySkeletonLocally();
-		return 0;
-	}
 	static int Polycode_SceneMesh_setLineWidth(lua_State *L) {
 		luaL_checktype(L, 1, LUA_TUSERDATA);
 		SceneMesh *inst = (SceneMesh*) *((PolyBase**)lua_touserdata(L, 1));
@@ -14938,6 +14941,18 @@ static int Polycode_LocalShaderParam_get_param(lua_State *L) {
 	return 1;
 }
 
+static int Polycode_LocalShaderParam_get_accessMutex(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TUSERDATA);
+	LocalShaderParam *inst = (LocalShaderParam*) *((PolyBase**)lua_touserdata(L, 1));
+	if(!inst->accessMutex) {
+		lua_pushnil(L);
+	} else {
+		PolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));
+		*userdataPtr = (PolyBase*)inst->accessMutex;
+	}
+	return 1;
+}
+
 static int Polycode_LocalShaderParam_set_name(lua_State *L) {
 	luaL_checktype(L, 1, LUA_TUSERDATA);
 	LocalShaderParam *inst = (LocalShaderParam*) *((PolyBase**)lua_touserdata(L, 1));
@@ -14979,6 +14994,15 @@ static int Polycode_LocalShaderParam_set_param(lua_State *L) {
 	return 0;
 }
 
+static int Polycode_LocalShaderParam_set_accessMutex(lua_State *L) {
+	luaL_checktype(L, 1, LUA_TUSERDATA);
+	LocalShaderParam *inst = (LocalShaderParam*) *((PolyBase**)lua_touserdata(L, 1));
+	luaL_checktype(L, 2, LUA_TUSERDATA);
+	CoreMutex* *argInst = (CoreMutex**) *((PolyBase**)lua_touserdata(L, 2));
+	inst->accessMutex = *argInst;
+	return 0;
+}
+
 	static int Polycode_LocalShaderParam(lua_State *L) {
 		LocalShaderParam *inst = new LocalShaderParam();
 		PolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));
@@ -15080,6 +15104,14 @@ static int Polycode_LocalShaderParam_set_param(lua_State *L) {
 		inst->setMatrix4(x);
 		return 0;
 	}
+	static int Polycode_LocalShaderParam_setMatrix4Array(lua_State *L) {
+		luaL_checktype(L, 1, LUA_TUSERDATA);
+		LocalShaderParam *inst = (LocalShaderParam*) *((PolyBase**)lua_touserdata(L, 1));
+		luaL_checktype(L, 2, LUA_TUSERDATA);
+		vector<Matrix4> x = *(vector<Matrix4>*) *((PolyBase**)lua_touserdata(L, 2));
+		inst->setMatrix4Array(x);
+		return 0;
+	}
 	static int Polycode_LocalShaderParam_setColor(lua_State *L) {
 		luaL_checktype(L, 1, LUA_TUSERDATA);
 		LocalShaderParam *inst = (LocalShaderParam*) *((PolyBase**)lua_touserdata(L, 1));
@@ -15863,13 +15895,12 @@ static int Polycode_ShaderBinding_set_accessMutex(lua_State *L) {
 		Skeleton *inst = (Skeleton*) *((PolyBase**)lua_touserdata(L, 1));
 		luaL_checktype(L, 2, LUA_TSTRING);
 		String name = String(lua_tostring(L, 2));
-		PolyBase *ptrRetVal = (PolyBase*)inst->getBoneByName(name);
-		if(ptrRetVal == NULL) {
-			lua_pushnil(L);
-		} else {
-			PolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));
-			*userdataPtr = ptrRetVal;
-		}
+		shared_ptr<Bone> *retInst = new shared_ptr<Bone>();
+		*retInst = inst->getBoneByName(name);
+		PolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));
+		luaL_getmetatable(L, "Polycode.shared_ptr<Bone>");
+		lua_setmetatable(L, -2);
+		*userdataPtr = (PolyBase*)retInst;
 		return 1;
 	}
 	static int Polycode_Skeleton_bonesVisible(lua_State *L) {
@@ -15891,20 +15922,19 @@ static int Polycode_ShaderBinding_set_accessMutex(lua_State *L) {
 		Skeleton *inst = (Skeleton*) *((PolyBase**)lua_touserdata(L, 1));
 		luaL_checktype(L, 2, LUA_TNUMBER);
 		int index = lua_tointeger(L, 2);
-		PolyBase *ptrRetVal = (PolyBase*)inst->getBone(index);
-		if(ptrRetVal == NULL) {
-			lua_pushnil(L);
-		} else {
-			PolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));
-			*userdataPtr = ptrRetVal;
-		}
+		shared_ptr<Bone> *retInst = new shared_ptr<Bone>();
+		*retInst = inst->getBone(index);
+		PolyBase **userdataPtr = (PolyBase**)lua_newuserdata(L, sizeof(PolyBase*));
+		luaL_getmetatable(L, "Polycode.shared_ptr<Bone>");
+		lua_setmetatable(L, -2);
+		*userdataPtr = (PolyBase*)retInst;
 		return 1;
 	}
 	static int Polycode_Skeleton_addBone(lua_State *L) {
 		luaL_checktype(L, 1, LUA_TUSERDATA);
 		Skeleton *inst = (Skeleton*) *((PolyBase**)lua_touserdata(L, 1));
 		luaL_checktype(L, 2, LUA_TUSERDATA);
-		Bone* bone = (Bone*) *((PolyBase**)lua_touserdata(L, 2));
+		shared_ptr<Bone> bone = *(shared_ptr<Bone>*) *((PolyBase**)lua_touserdata(L, 2));
 		inst->addBone(bone);
 		return 0;
 	}
@@ -15912,7 +15942,7 @@ static int Polycode_ShaderBinding_set_accessMutex(lua_State *L) {
 		luaL_checktype(L, 1, LUA_TUSERDATA);
 		Skeleton *inst = (Skeleton*) *((PolyBase**)lua_touserdata(L, 1));
 		luaL_checktype(L, 2, LUA_TUSERDATA);
-		Bone* bone = (Bone*) *((PolyBase**)lua_touserdata(L, 2));
+		shared_ptr<Bone> bone = *(shared_ptr<Bone>*) *((PolyBase**)lua_touserdata(L, 2));
 		inst->removeBone(bone);
 		return 0;
 	}
@@ -15920,7 +15950,7 @@ static int Polycode_ShaderBinding_set_accessMutex(lua_State *L) {
 		luaL_checktype(L, 1, LUA_TUSERDATA);
 		Skeleton *inst = (Skeleton*) *((PolyBase**)lua_touserdata(L, 1));
 		luaL_checktype(L, 2, LUA_TUSERDATA);
-		Bone* bone = (Bone*) *((PolyBase**)lua_touserdata(L, 2));
+		shared_ptr<Bone> bone = *(shared_ptr<Bone>*) *((PolyBase**)lua_touserdata(L, 2));
 		lua_pushinteger(L, inst->getBoneIndexByBone(bone));
 		return 1;
 	}
@@ -16231,7 +16261,7 @@ static int Polycode_BoneTrack_set_weight(lua_State *L) {
 
 	static int Polycode_BoneTrack(lua_State *L) {
 		luaL_checktype(L, 1, LUA_TUSERDATA);
-		Bone* bone = (Bone*) *((PolyBase**)lua_touserdata(L, 1));
+		shared_ptr<Bone> bone = *(shared_ptr<Bone>*) *((PolyBase**)lua_touserdata(L, 1));
 		luaL_checktype(L, 2, LUA_TNUMBER);
 		Number length = lua_tonumber(L, 2);
 		BoneTrack *inst = new BoneTrack(bone, length);

+ 6 - 6
include/polycode/core/PolyBone.h

@@ -53,19 +53,19 @@ namespace Polycode {
 			* Sets the parent bone of this bone.
 			* @param bone New parent bone.
 			*/
-			void setParentBone(Bone *bone);
+			void setParentBone(std::shared_ptr<Bone> bone);
 			
 			/**
 			* Adds another bone as the child of this bone.
 			* @param bone New parent bone.
 			*/			
-			void addChildBone(Bone *bone);
+			void addChildBone(std::shared_ptr<Bone> bone);
 			
 			/**
 			* Returns the parent bone of this bone.
 			* @return Parent bone of this bone.
 			*/						
-			Bone* getParentBone();
+			std::shared_ptr<Bone> getParentBone();
 			
 			/**
 			* Returns the number of child bones of this bone.
@@ -78,7 +78,7 @@ namespace Polycode {
 			* @param index Index of the child bone to return.
 			* @return Parent bone of this bone.
 			*/									
-			Bone *getChildBone(unsigned int index);
+			std::shared_ptr<Bone> getChildBone(unsigned int index);
 
 			/**
 			* Returns the bone matrix
@@ -162,8 +162,8 @@ namespace Polycode {
 			bool disableAnimation;
 		
 		protected:
-			Bone* parentBone;
-			std::vector<Bone*> childBones;
+			std::shared_ptr<Bone> parentBone;
+			std::vector<std::shared_ptr<Bone> > childBones;
 			String boneName;
 	};
 

+ 2 - 2
include/polycode/core/PolyImage.h

@@ -94,9 +94,9 @@ namespace Polycode {
 			*/			
 			bool loadImage(const String& fileName);
 
-			bool loadFromMemory(const unsigned char *buffer, unsigned int length);
+			bool POLYIGNORE loadFromMemory(const unsigned char *buffer, unsigned int length);
 
-			bool encodeToPNGData(unsigned char **data, unsigned int *size);
+			bool POLYIGNORE encodeToPNGData(unsigned char **data, unsigned int *size);
 		
 			static POLYIGNORE TokenArray readTokens(char *line, const char *tokens);
 			static POLYIGNORE void freeTokens(TokenArray tokens);

+ 3 - 1
include/polycode/core/PolyResourceManager.h

@@ -52,6 +52,7 @@ namespace Polycode {
 	class Shader;
 	class Cubemap;
 	class Material;
+    class Font;
 	
 	class _PolyExport ResourcePool : public EventDispatcher {
 		public:
@@ -69,11 +70,12 @@ namespace Polycode {
 		
 			std::shared_ptr<Resource> loadResource(const String &path);
 			std::shared_ptr<Resource> loadResourceWithName(const String &path, const String &name);
-		
 			std::shared_ptr<Resource> getResource(int resourceType, const String& resourceName) const;
 			String getName();
 			void setName(const String &name);
 		
+            std::shared_ptr<Font> loadFont(const String &name, const String &path);
+        
 			std::shared_ptr<Resource> getResourceByPath(const String& resourcePath) const;
 			void Update(int elapsed);
 		

+ 4 - 10
include/polycode/core/PolySceneMesh.h

@@ -33,9 +33,10 @@ namespace Polycode {
 	class Mesh;
 	class Texture;
 	class Skeleton;
+    class Bone;
 	class Image;
 	class ResourcePool;
-	
+    
 	/**
 	* 3D polygonal mesh instance. The SceneMesh is the base for all polygonal 3d geometry. It can have simple textures or complex materials applied to it.
 	*/
@@ -119,8 +120,6 @@ namespace Polycode {
 			* Returns the skeleton applied to this scene mesh.
 			*/
 			std::shared_ptr<Skeleton> getSkeleton();
-		
-			void applySkeletonLocally();
 			
 			/**
 			 * Sets the line width for line-based meshes.
@@ -186,20 +185,15 @@ namespace Polycode {
 			
 		protected:
 		
+            void createMaterialBoneParams(ShaderBinding *shaderBinding);
 			bool useVertexBuffer;
 			std::shared_ptr<Mesh> mesh;
 			std::shared_ptr<Material> material;
 			std::shared_ptr<Skeleton> skeleton;
-		
 			std::vector<std::shared_ptr<LocalShaderParam> > colorParams;
-
+            std::vector<std::shared_ptr<LocalShaderParam> > boneMatrixParams;        
 			std::vector<ShaderPass> shaderPasses;
-		
 			String fileName;
-			std::vector<Matrix4> materialBoneMatrices;
-
-			VertexDataArray skeletalVertexPositions;
-			VertexDataArray skeletalVertexNormals;
 		
 		
 		

+ 3 - 0
include/polycode/core/PolyShader.h

@@ -170,6 +170,7 @@ namespace Polycode {
 			void setVector2(Vector2 x);
 			void setVector3(Vector3 x);
 			void setMatrix4(Matrix4 x);
+            void setMatrix4Array(std::vector<Matrix4> &x);
 			void setColor(Color x);
 		
 			void setTexture(std::shared_ptr<Texture> texture);
@@ -179,6 +180,8 @@ namespace Polycode {
 			std::shared_ptr<Cubemap> getCubemap();
 		
 			void setParamValueFromString(int type, String pvalue);
+        
+            CoreMutex *accessMutex;
 	};
 	
 	class AttributeBinding : public PolyBase {

+ 8 - 8
include/polycode/core/PolySkeleton.h

@@ -40,7 +40,7 @@ namespace Polycode {
 	
 	class _PolyExport BoneTrack : public PolyBase {
 		public:
-			BoneTrack(Bone *bone, Number length);
+			BoneTrack(std::shared_ptr<Bone> bone, Number length);
 			~BoneTrack();
 		
 			void Play(bool once=false);
@@ -74,7 +74,7 @@ namespace Polycode {
 			Number speed;
 			bool paused;
 			Number time;
-			Bone *targetBone;
+            std::shared_ptr<Bone> targetBone;
 			bool playOnce;
 		
 	};
@@ -202,7 +202,7 @@ namespace Polycode {
 			* Get bone instance by its name
 			* @param name Name of the bone.
 			*/
-			Bone *getBoneByName(const String& name) const;
+			std::shared_ptr<Bone> getBoneByName(const String& name) const;
 			
 			/**
 			* Toggles bone visibility on and off.
@@ -219,12 +219,12 @@ namespace Polycode {
 			* Returns a bone at the specified index.
 			* @param index Bone index.
 			*/
-			Bone *getBone(unsigned int index) const;
+            std::shared_ptr<Bone> getBone(unsigned int index) const;
 		
-			void addBone(Bone *bone);
-			void removeBone(Bone *bone);
+			void addBone(std::shared_ptr<Bone> bone);
+			void removeBone(std::shared_ptr<Bone> bone);
 		
-			unsigned int getBoneIndexByBone(Bone *bone);
+			unsigned int getBoneIndexByBone(std::shared_ptr<Bone> bone);
 		
 		protected:
 		
@@ -232,7 +232,7 @@ namespace Polycode {
 		
 			SkeletonAnimation *baseAnimation;
 			std::vector<SkeletonAnimation*> playingAnimations;
-			std::vector<Bone*> bones;
+            std::vector<std::shared_ptr<Bone> > bones;
 			std::vector<SkeletonAnimation*> animations;
 	};
 

+ 3 - 1
scripts/create_bindings/BindingsGenerator.py

@@ -69,7 +69,9 @@ class BindingsGenerator(object):
 		ty = re.sub(r'^.*\sshort\s*$', 'int', ty)
 		ty = re.sub(r'^.*\sfloat\s*$', 'Number', ty)
 		ty = re.sub(r'^.*\sdouble\s*$', 'Number', ty) # eg "long double"
-		ty = ty.replace("unsigned", "int")
+		ty = ty.replace("unsigned int", "int")
+		ty = ty.replace("unsigned short", "int")
+		ty = ty.replace("unsigned long", "int")
 		ty = ty.replace("long", "int")
 		ty = ty.replace("float", "Number")
 		ty = ty.replace("double", "Number")

+ 1 - 1
scripts/create_bindings/bindings.conf

@@ -7,7 +7,7 @@ TargetDirectory = ../../include/polycode/core
 #include path prefix used when including the header files from generated headers (i.e. bar for #include "bar/Foo.h")
 HeaderIncludeDirectory = polycode/core
 #comma separated list of header files without extensions to ignore (i.e. Foo for Foo.h)
-IgnoreFiles = PolyTween, PolyTweenManager, PolyGLSLProgram, PolyGLSLShader, PolyGLSLShaderModule, PolyWinCore, PolyEmscriptenCore, PolyIOSCore, PolyRPICore, PolyUWPCore, PolyCocoaCore, PolyAGLCore, PolySDLCore, Poly_iPhone, PolyGLES1Renderer, PolyGLRenderer, tinyxml, tinystr, OpenGLCubemap, PolyiPhoneCore, PolyGLES1Texture, PolyGLTexture, PolyGLVertexBuffer, PolyThreaded, PolyGLHeaders, GLee, PolyPeer, PolySocket, PolyClient, PolyServer, PolyServerWorld, OSFILE, OSFileEntry, OSBasics, PolyLogger, PolyFontGlyphSheet, PolyXAudio2AudioInterface, PolyAndroidCore, PolyOpenSLAudioInterface, PolyAAssetFileProvider
+IgnoreFiles = PolyTween, PolyTweenManager, PolyGLSLProgram, PolyGLSLShader, PolyGLSLShaderModule, PolyWinCore, PolyEmscriptenCore, PolyIOSCore, PolyRPICore, PolyUWPCore, PolyCocoaCore, PolyAGLCore, PolySDLCore, Poly_iPhone, PolyGLES1Renderer, PolyGLRenderer, tinyxml, tinystr, OpenGLCubemap, PolyiPhoneCore, PolyGLES1Texture, PolyGLTexture, PolyGLVertexBuffer, PolyThreaded, PolyGLHeaders, GLee, PolyPeer, PolySocket, PolyClient, PolyServer, PolyServerWorld, OSFILE, OSFileEntry, OSBasics, PolyLogger, PolyFontGlyphSheet, PolyXAudio2AudioInterface, PolyAndroidCore, PolyOpenSLAudioInterface, PolyAAssetFileProvider, PolySDLAudioInterface
 #comma separated list of non-standard symbols to strip that might affect header parsing (i.e. __declspec(dllexport))
 StripSymbols = _PolyExport
 #comma separated list of classes to ignore when parsing (i.e. CFoo, CBar)

+ 4 - 1
src/bindings/javascript/PolycodeJS.cpp

@@ -1250,6 +1250,7 @@ int jsopen_Polycode(duk_context *ctx) {
 			{"ResourcePool_getResource", Polycode_ResourcePool_getResource, 3},
 			{"ResourcePool_getName", Polycode_ResourcePool_getName, 1},
 			{"ResourcePool_setName", Polycode_ResourcePool_setName, 2},
+			{"ResourcePool_loadFont", Polycode_ResourcePool_loadFont, 3},
 			{"ResourcePool_getResourceByPath", Polycode_ResourcePool_getResourceByPath, 2},
 			{"ResourcePool_Update", Polycode_ResourcePool_Update, 2},
 			{"ResourcePool_getResources", Polycode_ResourcePool_getResources, 2},
@@ -1487,7 +1488,6 @@ int jsopen_Polycode(duk_context *ctx) {
 			{"SceneMesh_setMesh", Polycode_SceneMesh_setMesh, 2},
 			{"SceneMesh_setSkeleton", Polycode_SceneMesh_setSkeleton, 2},
 			{"SceneMesh_getSkeleton", Polycode_SceneMesh_getSkeleton, 1},
-			{"SceneMesh_applySkeletonLocally", Polycode_SceneMesh_applySkeletonLocally, 1},
 			{"SceneMesh_setLineWidth", Polycode_SceneMesh_setLineWidth, 2},
 			{"SceneMesh_getFilename", Polycode_SceneMesh_getFilename, 1},
 			{"SceneMesh_setFilename", Polycode_SceneMesh_setFilename, 2},
@@ -1681,6 +1681,8 @@ int jsopen_Polycode(duk_context *ctx) {
 			{"LocalShaderParam__set_arraySize", Polycode_LocalShaderParam__set_arraySize, 2},
 			{"LocalShaderParam__get_param", Polycode_LocalShaderParam__get_param, 1},
 			{"LocalShaderParam__set_param", Polycode_LocalShaderParam__set_param, 2},
+			{"LocalShaderParam__get_accessMutex", Polycode_LocalShaderParam__get_accessMutex, 1},
+			{"LocalShaderParam__set_accessMutex", Polycode_LocalShaderParam__set_accessMutex, 2},
 			{"LocalShaderParam__delete", Polycode_LocalShaderParam__delete, 1},
 			{"LocalShaderParam_Copy", Polycode_LocalShaderParam_Copy, 1},
 			{"LocalShaderParam_getNumber", Polycode_LocalShaderParam_getNumber, 1},
@@ -1692,6 +1694,7 @@ int jsopen_Polycode(duk_context *ctx) {
 			{"LocalShaderParam_setVector2", Polycode_LocalShaderParam_setVector2, 2},
 			{"LocalShaderParam_setVector3", Polycode_LocalShaderParam_setVector3, 2},
 			{"LocalShaderParam_setMatrix4", Polycode_LocalShaderParam_setMatrix4, 2},
+			{"LocalShaderParam_setMatrix4Array", Polycode_LocalShaderParam_setMatrix4Array, 2},
 			{"LocalShaderParam_setColor", Polycode_LocalShaderParam_setColor, 2},
 			{"LocalShaderParam_setTexture", Polycode_LocalShaderParam_setTexture, 2},
 			{"LocalShaderParam_getTexture", Polycode_LocalShaderParam_getTexture, 1},

+ 4 - 1
src/bindings/lua/PolycodeLua.cpp

@@ -1234,6 +1234,7 @@ int luaopen_Polycode(lua_State *L) {
 		{"ResourcePool_getResource", Polycode_ResourcePool_getResource},
 		{"ResourcePool_getName", Polycode_ResourcePool_getName},
 		{"ResourcePool_setName", Polycode_ResourcePool_setName},
+		{"ResourcePool_loadFont", Polycode_ResourcePool_loadFont},
 		{"ResourcePool_getResourceByPath", Polycode_ResourcePool_getResourceByPath},
 		{"ResourcePool_Update", Polycode_ResourcePool_Update},
 		{"ResourcePool_getResources", Polycode_ResourcePool_getResources},
@@ -1470,7 +1471,6 @@ int luaopen_Polycode(lua_State *L) {
 		{"SceneMesh_setMesh", Polycode_SceneMesh_setMesh},
 		{"SceneMesh_setSkeleton", Polycode_SceneMesh_setSkeleton},
 		{"SceneMesh_getSkeleton", Polycode_SceneMesh_getSkeleton},
-		{"SceneMesh_applySkeletonLocally", Polycode_SceneMesh_applySkeletonLocally},
 		{"SceneMesh_setLineWidth", Polycode_SceneMesh_setLineWidth},
 		{"SceneMesh_getFilename", Polycode_SceneMesh_getFilename},
 		{"SceneMesh_setFilename", Polycode_SceneMesh_setFilename},
@@ -1656,11 +1656,13 @@ int luaopen_Polycode(lua_State *L) {
 		{"LocalShaderParam_get_ownsPointer", Polycode_LocalShaderParam_get_ownsPointer},
 		{"LocalShaderParam_get_arraySize", Polycode_LocalShaderParam_get_arraySize},
 		{"LocalShaderParam_get_param", Polycode_LocalShaderParam_get_param},
+		{"LocalShaderParam_get_accessMutex", Polycode_LocalShaderParam_get_accessMutex},
 		{"LocalShaderParam_set_name", Polycode_LocalShaderParam_set_name},
 		{"LocalShaderParam_set_type", Polycode_LocalShaderParam_set_type},
 		{"LocalShaderParam_set_ownsPointer", Polycode_LocalShaderParam_set_ownsPointer},
 		{"LocalShaderParam_set_arraySize", Polycode_LocalShaderParam_set_arraySize},
 		{"LocalShaderParam_set_param", Polycode_LocalShaderParam_set_param},
+		{"LocalShaderParam_set_accessMutex", Polycode_LocalShaderParam_set_accessMutex},
 		{"LocalShaderParam", Polycode_LocalShaderParam},
 		{"LocalShaderParam_Copy", Polycode_LocalShaderParam_Copy},
 		{"LocalShaderParam_getNumber", Polycode_LocalShaderParam_getNumber},
@@ -1672,6 +1674,7 @@ int luaopen_Polycode(lua_State *L) {
 		{"LocalShaderParam_setVector2", Polycode_LocalShaderParam_setVector2},
 		{"LocalShaderParam_setVector3", Polycode_LocalShaderParam_setVector3},
 		{"LocalShaderParam_setMatrix4", Polycode_LocalShaderParam_setMatrix4},
+		{"LocalShaderParam_setMatrix4Array", Polycode_LocalShaderParam_setMatrix4Array},
 		{"LocalShaderParam_setColor", Polycode_LocalShaderParam_setColor},
 		{"LocalShaderParam_setTexture", Polycode_LocalShaderParam_setTexture},
 		{"LocalShaderParam_getTexture", Polycode_LocalShaderParam_getTexture},

+ 2 - 2
src/core/PolyBezierCurve.cpp

@@ -24,8 +24,8 @@
 
 using namespace Polycode;
 
-bool BezierCurve::cacheHeightValues = false;
-unsigned int BezierCurve::defaultHeightCacheResolution = 512;
+bool BezierCurve::cacheHeightValues = true;
+unsigned int BezierCurve::defaultHeightCacheResolution = 1024;
 
 BezierPoint::BezierPoint(Number p1x, Number p1y, Number p1z, Number p2x, Number p2y, Number p2z, Number p3x, Number p3y, Number p3z) {
 	p1.x = p1x;

+ 4 - 4
src/core/PolyBone.cpp

@@ -40,15 +40,15 @@ Bone::~Bone() {
 
 }
 
-void Bone::setParentBone(Bone *bone) {
+void Bone::setParentBone(std::shared_ptr<Bone> bone) {
 	parentBone = bone;
 }
 
-void Bone::addChildBone(Bone *bone) {
+void Bone::addChildBone(std::shared_ptr<Bone> bone) {
 	childBones.push_back(bone);
 }
 
-Bone* Bone::getParentBone() {
+std::shared_ptr<Bone> Bone::getParentBone() {
 	return parentBone;
 }
 
@@ -56,7 +56,7 @@ int Bone::getNumChildBones() {
 	return childBones.size();
 }
 
-Bone *Bone::getChildBone(unsigned int index) {
+std::shared_ptr<Bone> Bone::getChildBone(unsigned int index) {
 	if(index > childBones.size()-1)
 		index = childBones.size()-1;
 		

+ 1 - 1
src/core/PolyImage.cpp

@@ -563,7 +563,7 @@ void Image::freeTokens(TokenArray tokens) {
 }
 
 bool Image::encodeToPNGData(unsigned char **data, unsigned int *size) {
-	unsigned int error = lodepng_encode32(data, size, (const unsigned char*)imageData, width, height);
+	unsigned int error = lodepng_encode32(data, (size_t*)size, (const unsigned char*)imageData, width, height);
 	if(error) {
 		return false;
 	}

+ 4 - 3
src/core/PolyOpenGLGraphicsInterface.cpp

@@ -51,6 +51,7 @@ void OpenGLGraphicsInterface::setUniformMatrix(GLint paramLocation, const Polyco
 
 void OpenGLGraphicsInterface::setParamInShader(Shader *shader, ProgramParam *param, LocalShaderParam *localParam) {
 	
+    localParam->accessMutex->lock();
 	GLuint paramLocation = *((GLuint*) param->platformData);
 	
 	switch(param->type) {
@@ -173,11 +174,10 @@ void OpenGLGraphicsInterface::setParamInShader(Shader *shader, ProgramParam *par
 			glActiveTexture(GL_TEXTURE0 + textureIndex);
 			glUniform1i(paramLocation, textureIndex);
 			if(localParam) {
-				Texture* texture = &*localParam->getTexture();
+                std::shared_ptr<Texture> texture = localParam->getTexture();
 				if(texture) {
-					
 					if(!texture->platformData) {
-						createTexture(texture);
+						createTexture(&*texture);
 					}
 					glBindTexture(GL_TEXTURE_2D, *((GLuint*) texture->platformData));
 				} else {
@@ -192,6 +192,7 @@ void OpenGLGraphicsInterface::setParamInShader(Shader *shader, ProgramParam *par
 			// RENDERER_TODO
 		break;
 	}
+    localParam->accessMutex->unlock();
 }
 
 void OpenGLGraphicsInterface::destroyBuffer(RenderDataArray *array) {

+ 4 - 0
src/core/PolyResourceManager.cpp

@@ -492,6 +492,10 @@ void ResourcePool::loadResourcesFromFolderWithLoader(const String &folder, bool
 	}
 }
 
+std::shared_ptr<Font> ResourcePool::loadFont(const String &name, const String &path) {
+    return std::static_pointer_cast<Font>(loadResourceWithName(path, name));
+}
+
 std::shared_ptr<Resource> ResourcePool::loadResource(const String &path) {
 	
 	std::shared_ptr<Resource> newResource = getResourceByPath(path);

+ 2 - 2
src/core/PolyScene.cpp

@@ -268,12 +268,12 @@ void Scene::Render(Camera *targetCamera, std::shared_ptr<RenderBuffer> targetFra
 			drawBuffer->lights[drawBuffer->lights.size()-1].direction = direction;
 		}
 	}
-	
+	/*
 	if(_doVisibilityChecking) {
 		targetCamera->buildFrustumPlanes();
 		setEntityVisibility(&rootEntity, targetCamera);
 	}
-
+*/
 	rootEntity.transformAndRender(drawBuffer, NULL);
 	renderer->processDrawBuffer(drawBuffer);
 }

+ 39 - 112
src/core/PolySceneMesh.cpp

@@ -39,7 +39,7 @@ SceneMesh *SceneMesh::SceneMeshFromMesh(std::shared_ptr<Mesh> mesh) {
 	return new SceneMesh(mesh);
 }
 
-SceneMesh::SceneMesh() : material(NULL), skeleton(NULL), skeletalVertexPositions(3, RenderDataArray::VERTEX_DATA_ARRAY), skeletalVertexNormals(3, RenderDataArray::NORMAL_DATA_ARRAY) { 
+SceneMesh::SceneMesh() : material(NULL), skeleton(NULL) {
 	mesh = std::make_shared<Mesh>();
 	setLocalBoundingBox(mesh->calculateBBox());
 	useVertexBuffer = false;
@@ -53,7 +53,7 @@ SceneMesh::SceneMesh() : material(NULL), skeleton(NULL), skeletalVertexPositions
 }
 
 
-SceneMesh::SceneMesh(const String& fileName) : material(NULL), skeleton(NULL), mesh(NULL), skeletalVertexPositions(3, RenderDataArray::VERTEX_DATA_ARRAY), skeletalVertexNormals(3, RenderDataArray::NORMAL_DATA_ARRAY) {
+SceneMesh::SceneMesh(const String& fileName) : material(NULL), skeleton(NULL), mesh(NULL) {
 	loadFromFile(fileName);
 	useVertexBuffer = false;
 	lineSmooth = false;
@@ -66,7 +66,7 @@ SceneMesh::SceneMesh(const String& fileName) : material(NULL), skeleton(NULL), m
 	setMaterialByName("UnlitUntextured");
 }
 
-SceneMesh::SceneMesh(std::shared_ptr<Mesh> mesh) : material(NULL), skeleton(NULL), skeletalVertexPositions(3, RenderDataArray::VERTEX_DATA_ARRAY), skeletalVertexNormals(3, RenderDataArray::NORMAL_DATA_ARRAY) {
+SceneMesh::SceneMesh(std::shared_ptr<Mesh> mesh) : material(NULL), skeleton(NULL) {
 	this->mesh = mesh;
 	setLocalBoundingBox(mesh->calculateBBox());
 	useVertexBuffer = false;
@@ -146,6 +146,7 @@ std::shared_ptr<Mesh> SceneMesh::getMesh() {
 void SceneMesh::clearMaterial() {
 	shaderPasses.clear();
 	colorParams.clear();
+    boneMatrixParams.clear();
 	this->material = nullptr;
 }
 
@@ -170,11 +171,26 @@ void SceneMesh::setMaterial(std::shared_ptr<Material> material) {
 		std::shared_ptr<LocalShaderParam> colorParam = shaderPass.shaderBinding->addParam(ProgramParam::PARAM_COLOR, "entityColor");
 		colorParams.push_back(colorParam);
 		if(skeleton) {
-		 //	  shaderPass.attributeArrays.push_back(&skeletalVertexPositions);
-		 //	  shaderPass.attributeArrays.push_back(&skeletalVertexNormals);
+            createMaterialBoneParams(&*shaderPass.shaderBinding);
 		}
 		shaderPasses.push_back(shaderPass);
-	}	 
+	}
+}
+
+void SceneMesh::createMaterialBoneParams(ShaderBinding *shaderBinding) {
+    if(!skeleton) {
+        return;
+    }
+    boneMatrixParams.clear();
+    
+    for(int i=0; i < skeleton->getNumBones(); i++) {
+        String paramName = "skeletonMatrix[0]";
+        std::shared_ptr<LocalShaderParam> param = shaderBinding->getLocalParamByName(paramName);
+        if(!param) {
+            param = shaderBinding->addParam(ProgramParam::PARAM_MATRIX, paramName);
+        }
+        boneMatrixParams.push_back(param);
+    }
 }
 
 void SceneMesh::setMaterialByName(const String& materialName, ResourcePool *resourcePool) {
@@ -213,6 +229,11 @@ std::shared_ptr<Skeleton> SceneMesh::loadSkeleton(const String& fileName) {
 
 void SceneMesh::setSkeleton(std::shared_ptr<Skeleton> skeleton) {
 	this->skeleton = skeleton;
+    if(material) {
+        for(auto pass:shaderPasses) {
+            createMaterialBoneParams(&*pass.shaderBinding);
+        }
+    }
 }
 
 void SceneMesh::setLineWidth(Number newWidth) {
@@ -272,46 +293,6 @@ void SceneMesh::removeShaderPass(int shaderIndex) {
 	}
 }
 
-void SceneMesh::applySkeletonLocally() {
-	skeletalVertexPositions.data.clear();
-	skeletalVertexNormals.data.clear();
-	
-	// REDNERER_TODO: appply to submeshes
-	/*
-	for(int i=0; i < mesh->vertexPositionArray.data.size()/3; i++) {
-		
-		Vector3 norm;
-		Vector3 tPos;
-		
-		for(int b=0; b < 4; b++) {
-			
-			PolyRendererVertexType boneWeight = mesh->vertexBoneWeightArray.data[(i*4)+b];
-			if(boneWeight > 0.0) {
-				Bone *bone = skeleton->getBone(mesh->vertexBoneIndexArray.data[(i*4)+b]);
-				if(bone) {
-					Vector3 restVert(mesh->vertexPositionArray.data[i*3], mesh->vertexPositionArray.data[(i*3)+1], mesh->vertexPositionArray.data[(i*3)+2]);
-					tPos += bone->finalMatrix * restVert * (boneWeight);
-					Vector3 nvec(mesh->vertexNormalArray.data[i*3], mesh->vertexNormalArray.data[(i*3)+1], mesh->vertexNormalArray.data[(i*3)+2]);
-					
-					nvec = bone->finalMatrix.rotateVector(nvec);
-					norm += nvec * (boneWeight);
-				}
-			}
-		}
-		
-		skeletalVertexPositions.data.push_back(tPos.x);
-		skeletalVertexPositions.data.push_back(tPos.y);
-		skeletalVertexPositions.data.push_back(tPos.z);
-		
-		norm.Normalize();
-		
-		skeletalVertexNormals.data.push_back(norm.x);
-		skeletalVertexNormals.data.push_back(norm.y);
-		skeletalVertexNormals.data.push_back(norm.z);
-	}
-	 */
-}
-
 void SceneMesh::Render(GPUDrawBuffer *buffer) {
 
 	if(!mesh) {
@@ -321,6 +302,18 @@ void SceneMesh::Render(GPUDrawBuffer *buffer) {
 	for (auto param : colorParams) {
 		param->setColor(color);
 	}
+    
+    if(skeleton) {
+        
+        std::vector<Matrix4> matrices;
+        for(int i =0; i < skeleton->getNumBones(); i++) {
+            matrices.push_back(skeleton->getBone(i)->getFinalMatrix());
+        }
+        
+        for(auto param:boneMatrixParams) {
+            param->setMatrix4Array(matrices);
+        }
+    }
 
 	for(int i=0; i < mesh->getNumSubmeshes(); i++) {
 		drawCall.options.alphaTest = alphaTest;
@@ -331,72 +324,6 @@ void SceneMesh::Render(GPUDrawBuffer *buffer) {
 		drawCall.submesh = mesh->getSubmeshPointer(i);		  
 		drawCall.material = material;
 		drawCall.shaderPasses = shaderPasses;
-		if(skeleton) {
-			applySkeletonLocally();
-		}
-		
 		buffer->drawCalls.push_back(drawCall);
 	}
-	
-	// RENDERERTODO: FIX GPU SKINNING
-	/*
-	if(material) {
-		
-		renderer->applyMaterial(material, localShaderOptions,0, forceMaterial);
-	} else {
-		if(texture)
-			renderer->setTexture(texture);
-		else
-			renderer->setTexture(NULL);
-	}
-	
-	if(sendBoneMatricesToMaterial && localShaderOptions && skeleton) {
-		LocalShaderParam *skeletonMatrix = localShaderOptions->getLocalParamByName("skeletonMatrix[0]");
-		
-		if(skeletonMatrix) {
-			for(int i=0; i < skeleton->getNumBones(); i++) {
-				materialBoneMatrices[i] = skeleton->getBone(i)->getFinalMatrix();
-			}
-		} else {
-			materialBoneMatrices.resize(skeleton->getNumBones());
-			localShaderOptions->addParamPointer(ProgramParam::PARAM_MATRIX, "skeletonMatrix[0]", materialBoneMatrices.data())->arraySize = skeleton->getNumBones();
-		}
-	}
-	
-	bool useVertexBuffer = this->useVertexBuffer;
-
-	if(useVertexBuffer && skeleton && !sendBoneMatricesToMaterial) {
-		useVertexBuffer = false;
-	}
-	
-	if(useVertexBuffer) {
-		VertexBuffer *vb = mesh->getVertexBuffer();
-		if(vb){
-			renderer->drawVertexBuffer(vb, mesh->useVertexColors);
-		}
-	} else {
-		renderMeshLocally();
-	}
-	
-	if(material)  {
-		renderer->clearShader();
-	}
-	
-	renderer->setTexture(NULL);
-	
-	if(overlayWireframe) {
-		bool depthTestVal = depthTest;
-		renderer->enableDepthTest(false);
-		renderer->setWireframePolygonMode(true);
-		renderer->setVertexColor(wireFrameColor.r, wireFrameColor.g, wireFrameColor.b, wireFrameColor.a);
-		
-		if(useVertexBuffer) {
-			renderer->drawVertexBuffer(mesh->getVertexBuffer(), mesh->useVertexColors);
-		} else {
-			renderMeshLocally();
-		}
-		renderer->enableDepthTest(depthTestVal);
-	}	
-	renderer->setWireframePolygonMode(false);	 
-	 */
 }

+ 42 - 3
src/core/PolyShader.cpp

@@ -473,35 +473,64 @@ void LocalShaderParam::setNumber(Number x) {
 	if(type != ProgramParam::PARAM_NUMBER) {
 		return;
 	}
+    accessMutex->lock();
 	memcpy(data, &x, sizeof(x));
+    accessMutex->unlock();
 }
 
 void LocalShaderParam::setVector2(Vector2 x) {
 	if(type != ProgramParam::PARAM_VECTOR2) {
 		return;
 	}
+    accessMutex->lock();
 	memcpy(data, &x, sizeof(x));
+    accessMutex->unlock();
 }
 
 void LocalShaderParam::setVector3(Vector3 x) {
 	if(type != ProgramParam::PARAM_VECTOR3) {
 		return;
 	}
+    accessMutex->lock();
 	memcpy(data, &x, sizeof(x));
+    accessMutex->unlock();
 }
 
 void LocalShaderParam::setMatrix4(Matrix4 x) {
 	if(type != ProgramParam::PARAM_MATRIX) {
 		return;
 	}
+    accessMutex->lock();
 	memcpy(data, &x, sizeof(x));
+    accessMutex->unlock();
+}
+
+void LocalShaderParam::setMatrix4Array(std::vector<Matrix4> &x) {
+    if(type != ProgramParam::PARAM_MATRIX) {
+        return;
+    }
+    accessMutex->lock();
+    if(arraySize > 0) {
+        delete[] ((Matrix4*) data);
+    } else {
+        delete ((Matrix4*) data);
+    }
+    arraySize = x.size();
+    data = new Matrix4[arraySize];
+    for(int i=0; i < x.size(); i++) {
+        ((Matrix4*)data)[i] = x[i];
+    }
+//    memcpy(data, &x[0], sizeof(x));
+    accessMutex->unlock();
 }
 
 void LocalShaderParam::setColor(Color x) {
 	if(type != ProgramParam::PARAM_COLOR) {
 		return;
 	}
+    accessMutex->lock();
 	static_cast<Color*>(data)->setColor(&x);
+    accessMutex->unlock();
 }
 
 const String& Shader::getName() const {
@@ -512,11 +541,13 @@ LocalShaderParam::LocalShaderParam() {
 	data = NULL;
 	arraySize = 0;
 	ownsPointer = true;
+    accessMutex = Services()->getCore()->createMutex();
 }
 
 void LocalShaderParam::setTexture(std::shared_ptr<Texture> texture) {
-	Services()->getRenderer()->setTextureParam(this, &*texture);
+    accessMutex->lock();
 	texturePtr = texture;
+    accessMutex->unlock();
 }
 
 std::shared_ptr<Texture> LocalShaderParam::getTexture() {
@@ -524,8 +555,9 @@ std::shared_ptr<Texture> LocalShaderParam::getTexture() {
 }
 
 void LocalShaderParam::setCubemap(std::shared_ptr<Cubemap> cubemap) {
-	data = (void*) &*cubemap;
+    accessMutex->lock();
 	cubemapPtr = cubemap;
+    accessMutex->unlock();
 }
 
 std::shared_ptr<Cubemap> LocalShaderParam::getCubemap() {
@@ -533,6 +565,7 @@ std::shared_ptr<Cubemap> LocalShaderParam::getCubemap() {
 }
 
 LocalShaderParam::~LocalShaderParam() {
+    accessMutex->lock();
 	if(ownsPointer) {
 		switch(type) {
 			case ProgramParam::PARAM_NUMBER:
@@ -548,10 +581,16 @@ LocalShaderParam::~LocalShaderParam() {
 				delete ((Color*) data);
 			break;
 			case ProgramParam::PARAM_MATRIX:
-				delete ((Matrix4*) data);
+                if(arraySize > 0) {
+                    delete[] ((Matrix4*) data);
+                } else {
+                    delete ((Matrix4*) data);
+                }
 			break;
 		}
 	}
+    accessMutex->unlock();
+    delete accessMutex;
 }
 
 std::shared_ptr<LocalShaderParam> LocalShaderParam::Copy() {

+ 12 - 12
src/core/PolySkeleton.cpp

@@ -57,7 +57,7 @@ int Skeleton::getNumBones() const {
 	return bones.size();
 }
 
-Bone *Skeleton::getBoneByName(const String& name) const {
+std::shared_ptr<Bone> Skeleton::getBoneByName(const String& name) const {
 	for(int i=0; i < bones.size(); i++) {
 		if(bones[i]->getName() == name)
 			return bones[i];
@@ -65,7 +65,7 @@ Bone *Skeleton::getBoneByName(const String& name) const {
 	return NULL;
 }
 
-Bone *Skeleton::getBone(unsigned int index) const {
+std::shared_ptr<Bone> Skeleton::getBone(unsigned int index) const {
 	if(index >= bones.size()) {
 		return NULL;
 	}
@@ -125,7 +125,7 @@ SkeletonAnimation *Skeleton::getAnimation(const String& name) const {
 }
 
 void Skeleton::Update() {
-	
+    
 	for(int i=0; i < bones.size(); i++) {
 		if(!bones[i]->disableAnimation) {
 			bones[i]->setRotationByQuaternion(bones[i]->baseRotation);
@@ -152,11 +152,11 @@ void Skeleton::Update() {
 	}
 }
 
-void Skeleton::addBone(Bone *bone) {
+void Skeleton::addBone(std::shared_ptr<Bone> bone) {
 	bones.push_back(bone);
 }
 
-void Skeleton::removeBone(Bone *bone) {
+void Skeleton::removeBone(std::shared_ptr<Bone> bone) {
 	for(int i=0; i < bones.size(); i++) {
 		if(bones[i] == bone) {
 			bones.erase(bones.begin()+i);
@@ -165,7 +165,7 @@ void Skeleton::removeBone(Bone *bone) {
 	}
 }
 
-unsigned int Skeleton::getBoneIndexByBone(Bone *bone) {
+unsigned int Skeleton::getBoneIndexByBone(std::shared_ptr<Bone> bone) {
 	for(int i=0; i < bones.size(); i++) {
 		if(bones[i] == bone) {
 			return i;
@@ -195,7 +195,7 @@ void Skeleton::loadSkeleton(const String& fileName) {
 		memset(buffer, 0, 1024);
 		inFile->read(buffer, 1, namelen);
 		
-		Bone *newBone = new Bone(String(buffer));
+        std::shared_ptr<Bone> newBone = std::make_shared<Bone>(String(buffer));
 		
 		inFile->read(&hasParent, sizeof(unsigned int), 1);
 		if(hasParent == 1) {
@@ -239,16 +239,16 @@ void Skeleton::loadSkeleton(const String& fileName) {
 		
 	}
 
-	Bone *parentBone;
+	std::shared_ptr<Bone> parentBone;
 	
 	for(int i=0; i < bones.size(); i++) {
 		if(bones[i]->parentBoneId != -1) {
 			parentBone = bones[bones[i]->parentBoneId];
 			parentBone->addChildBone(bones[i]);
 			bones[i]->setParentBone(parentBone);
-			parentBone->addChild(bones[i]);
+			parentBone->addChild(&*bones[i]);
 		} else {
-			bonesEntity->addChild(bones[i]);
+			bonesEntity->addChild(&*bones[i]);
 		}
 	}
 	Services()->getCore()->closeFile(inFile);
@@ -306,7 +306,7 @@ void Skeleton::addAnimation(const String& name, const String& fileName) {
 		inFile->read(boneNameBuffer, 1, boneNameLen);
 		boneNameBuffer[boneNameLen] = '\0';
 		
-		Bone *trackBone = getBoneByName(boneNameBuffer);
+        std::shared_ptr<Bone> trackBone = getBoneByName(boneNameBuffer);
 		if(!trackBone) {
 			printf("WARNING, INVALID BONE NAME: %s\n", boneNameBuffer);
 			continue;
@@ -371,7 +371,7 @@ void Skeleton::bonesVisible(bool val) {
 	bonesEntity->visible = val;
 }
 
-BoneTrack::BoneTrack(Bone *bone, Number length) {
+BoneTrack::BoneTrack(std::shared_ptr<Bone> bone, Number length) {
 	weight = 0.0;
 	this->length = length;
 	targetBone = bone;

+ 1 - 1
src/core/PolyTexture.cpp

@@ -33,7 +33,7 @@ bool Texture::premultiplyAlphaOnLoad = false;
 bool Texture::clampDefault = true;
 bool Texture::mipmapsDefault = true;
 bool Texture::keepTextureData = true;
-int Texture::defaultTextureFiltering = 0;
+int Texture::defaultTextureFiltering = 1;
 
 Texture::Texture() : Resource(Resource::RESOURCE_TEXTURE), width(0), height(0), clamp(false), type(Image::IMAGE_RGBA), createMipmaps(false), filteringMode(defaultTextureFiltering), anisotropy(0), framebufferTexture(false), depthTexture(false) {
 	filteringMode = defaultTextureFiltering;