Material.lua 2.2 KB

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