Material.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. require "Polycode/Resource"
  2. class "Material" (Resource)
  3. function Material:Material(...)
  4. if type(arg[1]) == "table" and count(arg) == 1 then
  5. if ""..arg[1]:class() == "Resource" then
  6. self.__ptr = arg[1].__ptr
  7. return
  8. end
  9. end
  10. for k,v in pairs(arg) do
  11. if type(v) == "table" then
  12. if v.__ptr ~= nil then
  13. arg[k] = v.__ptr
  14. end
  15. end
  16. end
  17. if self.__ptr == nil and arg[1] ~= "__skip_ptr__" then
  18. self.__ptr = Polycore.Material(unpack(arg))
  19. Polycore.__ptr_lookup[self.__ptr] = self
  20. end
  21. end
  22. function Material:addShader(shader, shaderBinding)
  23. local retVal = Polycore.Material_addShader(self.__ptr, shader.__ptr, shaderBinding.__ptr)
  24. end
  25. function Material:getNumShaders()
  26. local retVal = Polycore.Material_getNumShaders(self.__ptr)
  27. return retVal
  28. end
  29. function Material:addShaderRenderTarget(newTarget)
  30. local retVal = Polycore.Material_addShaderRenderTarget(self.__ptr, newTarget.__ptr)
  31. end
  32. function Material:getNumShaderRenderTargets()
  33. local retVal = Polycore.Material_getNumShaderRenderTargets(self.__ptr)
  34. return retVal
  35. end
  36. function Material:getShaderRenderTarget(index)
  37. local retVal = Polycore.Material_getShaderRenderTarget(self.__ptr, index)
  38. if retVal == nil then return nil end
  39. if Polycore.__ptr_lookup[retVal] ~= nil then
  40. return Polycore.__ptr_lookup[retVal]
  41. else
  42. Polycore.__ptr_lookup[retVal] = ShaderRenderTarget("__skip_ptr__")
  43. Polycore.__ptr_lookup[retVal].__ptr = retVal
  44. return Polycore.__ptr_lookup[retVal]
  45. end
  46. end
  47. function Material:getName()
  48. local retVal = Polycore.Material_getName(self.__ptr)
  49. return retVal
  50. end
  51. function Material:getShader(index)
  52. local retVal = Polycore.Material_getShader(self.__ptr, index)
  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] = Shader("__skip_ptr__")
  58. Polycore.__ptr_lookup[retVal].__ptr = retVal
  59. return Polycore.__ptr_lookup[retVal]
  60. end
  61. end
  62. function Material:getShaderBinding(index)
  63. local retVal = Polycore.Material_getShaderBinding(self.__ptr, index)
  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] = ShaderBinding("__skip_ptr__")
  69. Polycore.__ptr_lookup[retVal].__ptr = retVal
  70. return Polycore.__ptr_lookup[retVal]
  71. end
  72. end
  73. function Material:loadMaterial(fileName)
  74. local retVal = Polycore.Material_loadMaterial(self.__ptr, fileName)
  75. end
  76. function Material:__delete()
  77. Polycore.__ptr_lookup[self.__ptr] = nil
  78. Polycore.delete_Material(self.__ptr)
  79. end