예제 #1
0
파일: map.py 프로젝트: Gato-X/NotYourData
    def loadTextures(self):
        texture_binders = []
        for i,t in enumerate(self._textures):
            if t is not None:
                binder = R.loadTexture(t).getBinder(i,self._shader.getUniformPos("texture%s"%i))
                texture_binders.append(binder)

        # replace the texture name with the binder
        self._textures = texture_binders
예제 #2
0
	def toCompiled(self, shader=None):

		if shader is None:
			shader = self.getShader()

		assert(shader)

		code = ""

		# items made up of 3 floats
		for what in ("diffuse_color","specular_color","ambient_color"):
			loc = shader.getUniformPos(what)
			if loc!=-1:
				code += "\tglUniform3fv(%s, 1, mat._%s)\n"%(loc,what)

		# items made up of 1 float
		for what in ("specular_exp","alpha"):
			loc = shader.getUniformPos(what)
			if loc!=-1:
				code += "\tglUniform1f(%s, mat._%s)\n"%(loc,what)

		# textures
		for i in xrange(3):
			loc = shader.getUniformPos("texture%s"%i)
			if loc!=-1:
				try: # see if the texture is already loaded
					self._texture[i].id()
				except:
					if self._texture[i] is None:
						self._texture[i] = Texture.getNullTexture()
					else:
						self._texture[i] = R.loadTexture(self._texture[i])

				code += "\tmat._texture[%s].bind(%s,%s)\n"%(i,i,loc)

		if not code:
			code = "def binder(): pass"
		else:
			code = "def binder():\n"+code


		c = compile(code, "<compiled material>", "exec")

		ns = dict(mat = self, glUniform3fv=glUniform3fv, glUniform1f=glUniform1f)
	
		exec c in ns

		return ns['binder']
예제 #3
0
        def __init__(self, shader_name, texture_name):
            self._shader_name = shader_name
            self._texture_name = texture_name

            self._shader = R.getShaderProgram(shader_name)

            self._tbinder = None
            self._texture = None

            if texture_name:
                self._texture = R.loadTexture(texture_name) if texture_name else None
                if self._texture:
                    tloc = self._shader.getUniformPos("texture0")
                    self._tbinder = self._texture.getBinder(0, tloc) if tloc>-1 else None

            self._tot_vert_gl = 0
            self._ofs_gl = None

            for uni in self._uniforms:
                setattr(self, "_"+uni+"_uni", self._shader.getUniformPos(uni))

            self.reset()