MaterialManager.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. class "MaterialManager"
  2. function MaterialManager:MaterialManager(...)
  3. for k,v in pairs(arg) do
  4. if type(v) == "table" then
  5. if v.__ptr ~= nil then
  6. arg[k] = v.__ptr
  7. end
  8. end
  9. end
  10. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  11. self.__ptr = Polycore.MaterialManager(unpack(arg))
  12. Polycore.__ptr_lookup[self.__ptr] = self
  13. end
  14. end
  15. function MaterialManager:Update(elapsed)
  16. local retVal = Polycore.MaterialManager_Update(self.__ptr, elapsed)
  17. end
  18. function MaterialManager:createFramebufferTexture(width, height, type)
  19. local retVal = Polycore.MaterialManager_createFramebufferTexture(self.__ptr, width, height, type)
  20. if retVal == nil then return nil end
  21. if Polycore.__ptr_lookup[retVal] ~= nil then
  22. return Polycore.__ptr_lookup[retVal]
  23. else
  24. Polycore.__ptr_lookup[retVal] = Texture("__skip_ptr__")
  25. Polycore.__ptr_lookup[retVal].__ptr = retVal
  26. return Polycore.__ptr_lookup[retVal]
  27. end
  28. end
  29. function MaterialManager:createTexture(width, height, imageData, clamp, type)
  30. local retVal = Polycore.MaterialManager_createTexture(self.__ptr, width, height, imageData.__ptr, clamp, type)
  31. if retVal == nil then return nil end
  32. if Polycore.__ptr_lookup[retVal] ~= nil then
  33. return Polycore.__ptr_lookup[retVal]
  34. else
  35. Polycore.__ptr_lookup[retVal] = Texture("__skip_ptr__")
  36. Polycore.__ptr_lookup[retVal].__ptr = retVal
  37. return Polycore.__ptr_lookup[retVal]
  38. end
  39. end
  40. function MaterialManager:createNewTexture(width, height, clamp, type)
  41. local retVal = Polycore.MaterialManager_createNewTexture(self.__ptr, width, height, clamp, type)
  42. if retVal == nil then return nil end
  43. if Polycore.__ptr_lookup[retVal] ~= nil then
  44. return Polycore.__ptr_lookup[retVal]
  45. else
  46. Polycore.__ptr_lookup[retVal] = Texture("__skip_ptr__")
  47. Polycore.__ptr_lookup[retVal].__ptr = retVal
  48. return Polycore.__ptr_lookup[retVal]
  49. end
  50. end
  51. function MaterialManager:createTextureFromImage(image, clamp)
  52. local retVal = Polycore.MaterialManager_createTextureFromImage(self.__ptr, image.__ptr, clamp)
  53. if retVal == nil then return nil end
  54. if Polycore.__ptr_lookup[retVal] ~= nil then
  55. return Polycore.__ptr_lookup[retVal]
  56. else
  57. Polycore.__ptr_lookup[retVal] = Texture("__skip_ptr__")
  58. Polycore.__ptr_lookup[retVal].__ptr = retVal
  59. return Polycore.__ptr_lookup[retVal]
  60. end
  61. end
  62. function MaterialManager:createTextureFromFile(fileName, clamp)
  63. local retVal = Polycore.MaterialManager_createTextureFromFile(self.__ptr, fileName.__ptr, clamp)
  64. if retVal == nil then return nil end
  65. if Polycore.__ptr_lookup[retVal] ~= nil then
  66. return Polycore.__ptr_lookup[retVal]
  67. else
  68. Polycore.__ptr_lookup[retVal] = Texture("__skip_ptr__")
  69. Polycore.__ptr_lookup[retVal].__ptr = retVal
  70. return Polycore.__ptr_lookup[retVal]
  71. end
  72. end
  73. function MaterialManager:deleteTexture(texture)
  74. local retVal = Polycore.MaterialManager_deleteTexture(self.__ptr, texture.__ptr)
  75. end
  76. function MaterialManager:reloadTextures()
  77. local retVal = Polycore.MaterialManager_reloadTextures(self.__ptr)
  78. end
  79. function MaterialManager:reloadProgramsAndTextures()
  80. local retVal = Polycore.MaterialManager_reloadProgramsAndTextures(self.__ptr)
  81. end
  82. function MaterialManager:reloadPrograms()
  83. local retVal = Polycore.MaterialManager_reloadPrograms(self.__ptr)
  84. end
  85. function MaterialManager:addShaderModule(module)
  86. local retVal = Polycore.MaterialManager_addShaderModule(self.__ptr, module.__ptr)
  87. end
  88. function MaterialManager:getTextureByResourcePath(resourcePath)
  89. local retVal = Polycore.MaterialManager_getTextureByResourcePath(self.__ptr, resourcePath.__ptr)
  90. if retVal == nil then return nil end
  91. if Polycore.__ptr_lookup[retVal] ~= nil then
  92. return Polycore.__ptr_lookup[retVal]
  93. else
  94. Polycore.__ptr_lookup[retVal] = Texture("__skip_ptr__")
  95. Polycore.__ptr_lookup[retVal].__ptr = retVal
  96. return Polycore.__ptr_lookup[retVal]
  97. end
  98. end
  99. function MaterialManager:cubemapFromXMLNode(node)
  100. local retVal = Polycore.MaterialManager_cubemapFromXMLNode(self.__ptr, node.__ptr)
  101. if retVal == nil then return nil end
  102. if Polycore.__ptr_lookup[retVal] ~= nil then
  103. return Polycore.__ptr_lookup[retVal]
  104. else
  105. Polycore.__ptr_lookup[retVal] = Cubemap("__skip_ptr__")
  106. Polycore.__ptr_lookup[retVal].__ptr = retVal
  107. return Polycore.__ptr_lookup[retVal]
  108. end
  109. end
  110. function MaterialManager:loadMaterialsFromFile(fileName)
  111. local retVal = Polycore.MaterialManager_loadMaterialsFromFile(self.__ptr, fileName)
  112. end
  113. function MaterialManager:materialFromXMLNode(node)
  114. local retVal = Polycore.MaterialManager_materialFromXMLNode(self.__ptr, node.__ptr)
  115. if retVal == nil then return nil end
  116. if Polycore.__ptr_lookup[retVal] ~= nil then
  117. return Polycore.__ptr_lookup[retVal]
  118. else
  119. Polycore.__ptr_lookup[retVal] = Material("__skip_ptr__")
  120. Polycore.__ptr_lookup[retVal].__ptr = retVal
  121. return Polycore.__ptr_lookup[retVal]
  122. end
  123. end
  124. function MaterialManager:setShaderFromXMLNode(node)
  125. local retVal = Polycore.MaterialManager_setShaderFromXMLNode(self.__ptr, node.__ptr)
  126. if retVal == nil then return nil end
  127. if Polycore.__ptr_lookup[retVal] ~= nil then
  128. return Polycore.__ptr_lookup[retVal]
  129. else
  130. Polycore.__ptr_lookup[retVal] = Shader("__skip_ptr__")
  131. Polycore.__ptr_lookup[retVal].__ptr = retVal
  132. return Polycore.__ptr_lookup[retVal]
  133. end
  134. end
  135. function MaterialManager:createShaderFromXMLNode(node)
  136. local retVal = Polycore.MaterialManager_createShaderFromXMLNode(self.__ptr, node.__ptr)
  137. if retVal == nil then return nil end
  138. if Polycore.__ptr_lookup[retVal] ~= nil then
  139. return Polycore.__ptr_lookup[retVal]
  140. else
  141. Polycore.__ptr_lookup[retVal] = Shader("__skip_ptr__")
  142. Polycore.__ptr_lookup[retVal].__ptr = retVal
  143. return Polycore.__ptr_lookup[retVal]
  144. end
  145. end
  146. function MaterialManager:__delete()
  147. Polycore.__ptr_lookup[self.__ptr] = nil
  148. Polycore.delete_MaterialManager(self.__ptr)
  149. end