GLSLShader.lua 987 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. require "Polycode/Shader"
  2. class "GLSLShader" (Shader)
  3. function GLSLShader:GLSLShader(...)
  4. if type(arg[1]) == "table" and count(arg) == 1 then
  5. if ""..arg[1]:class() == "Shader" 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.GLSLShader(unpack(arg))
  19. Polycore.__ptr_lookup[self.__ptr] = self
  20. end
  21. end
  22. function GLSLShader:createBinding()
  23. local retVal = Polycore.GLSLShader_createBinding(self.__ptr)
  24. if Polycore.__ptr_lookup[retVal] ~= nil then
  25. return Polycore.__ptr_lookup[retVal]
  26. else
  27. Polycore.__ptr_lookup[retVal] = ShaderBinding("__skip_ptr__")
  28. Polycore.__ptr_lookup[retVal].__ptr = retVal
  29. return Polycore.__ptr_lookup[retVal]
  30. end
  31. end
  32. function GLSLShader:__delete()
  33. Polycore.__ptr_lookup[self.__ptr] = nil
  34. Polycore.delete_GLSLShader(self.__ptr)
  35. end