Material.lua 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. end
  14. end
  15. function Material:addShader(shader, shaderBinding)
  16. local retVal = Polycore.Material_addShader(self.__ptr, shader.__ptr, shaderBinding.__ptr)
  17. end
  18. function Material:getNumShaders()
  19. local retVal = Polycore.Material_getNumShaders(self.__ptr)
  20. return retVal
  21. end
  22. function Material:addShaderRenderTarget(newTarget)
  23. local retVal = Polycore.Material_addShaderRenderTarget(self.__ptr, newTarget.__ptr)
  24. end
  25. function Material:getNumShaderRenderTargets()
  26. local retVal = Polycore.Material_getNumShaderRenderTargets(self.__ptr)
  27. return retVal
  28. end
  29. function Material:getShaderRenderTarget(index)
  30. local retVal = Polycore.Material_getShaderRenderTarget(self.__ptr, index)
  31. if Polycore.__ptr_lookup[retVal] ~= nil then
  32. return Polycore.__ptr_lookup[retVal]
  33. else
  34. Polycore.__ptr_lookup[retVal] = ShaderRenderTarget("__skip_ptr__")
  35. Polycore.__ptr_lookup[retVal].__ptr = retVal
  36. return Polycore.__ptr_lookup[retVal]
  37. end
  38. end
  39. function Material:getName()
  40. local retVal = Polycore.Material_getName(self.__ptr)
  41. return retVal
  42. end
  43. function Material:getShader(index)
  44. local retVal = Polycore.Material_getShader(self.__ptr, index)
  45. if Polycore.__ptr_lookup[retVal] ~= nil then
  46. return Polycore.__ptr_lookup[retVal]
  47. else
  48. Polycore.__ptr_lookup[retVal] = Shader("__skip_ptr__")
  49. Polycore.__ptr_lookup[retVal].__ptr = retVal
  50. return Polycore.__ptr_lookup[retVal]
  51. end
  52. end
  53. function Material:getShaderBinding(index)
  54. local retVal = Polycore.Material_getShaderBinding(self.__ptr, index)
  55. if Polycore.__ptr_lookup[retVal] ~= nil then
  56. return Polycore.__ptr_lookup[retVal]
  57. else
  58. Polycore.__ptr_lookup[retVal] = ShaderBinding("__skip_ptr__")
  59. Polycore.__ptr_lookup[retVal].__ptr = retVal
  60. return Polycore.__ptr_lookup[retVal]
  61. end
  62. end
  63. function Material:loadMaterial(fileName)
  64. local retVal = Polycore.Material_loadMaterial(self.__ptr, fileName)
  65. end