def setTextureParameters(textureType, texture, isPowerOfTwoImage): if isPowerOfTwoImage: glTexParameteri(textureType, GL_TEXTURE_WRAP_S, utils.convert(texture.wrapS)) glTexParameteri(textureType, GL_TEXTURE_WRAP_T, utils.convert(texture.wrapT)) glTexParameteri(textureType, GL_TEXTURE_MAG_FILTER, utils.convert(texture.magFilter)) glTexParameteri(textureType, GL_TEXTURE_MIN_FILTER, utils.convert(texture.minFilter)) else: glTexParameteri(textureType, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE) glTexParameteri(textureType, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE) if texture.wrapS != ClampToEdgeWrapping or texture.wrapT != ClampToEdgeWrapping: logging.warning( "THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping. %s" % texture) glTexParameteri(textureType, GL_TEXTURE_MAG_FILTER, filterFallback(texture.magFilter)) glTexParameteri(textureType, GL_TEXTURE_MIN_FILTER, filterFallback(texture.minFilter)) if texture.minFilter != NearestFilter and texture.minFilter != LinearFilter: logging.warning( "THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. %s" % texture) extension = extensions.get("EXT_texture_filter_anisotropic") if extension: if texture.type == FloatType and extensions.get( "OES_texture_float_linear") is None: return if texture.type == HalfFloatType and extensions.get( "OES_texture_half_float_linear") is None: return if texture.anisotropy > 1 or properties.get( texture).__currentAnisotropy: glTexParameterf( textureType, extension.GL_TEXTURE_MAX_ANISOTROPY_EXT, min(texture.anisotropy, capabilities.getMaxAnisotropy())) properties.get(texture).__currentAnisotropy = texture.anisotropy
def setupFrameBufferTexture(framebuffer, renderTarget, attachment, textureTarget): glFormat = utils.convert(renderTarget.texture.format) glType = utils.convert(renderTarget.texture.type) state.texImage2D(textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, None) glBindFramebuffer(GL_FRAMEBUFFER, framebuffer) glFramebufferTexture2D(GL_FRAMEBUFFER, attachment, textureTarget, properties.get(renderTarget.texture)._openglTexture, 0) glBindFramebuffer(GL_FRAMEBUFFER, 0)
def uploadTexture(textureProperties, texture, slot): from ..OpenGLRenderer import _infoMemory as infoMemory if not textureProperties._openglInit: textureProperties._openglInit = True texture.addEventListener("dispose", onTextureDispose) textureProperties._openglTexture = glGenTextures(1) infoMemory.textures += 1 state.activeTexture(GL_TEXTURE0 + slot) state.bindTexture(GL_TEXTURE_2D, textureProperties._openglTexture) # glPixelStorei( GL_UNPACK_FLIP_Y_WEBGL, texture.flipY ) # glPixelStorei( GL_UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha ) glPixelStorei(GL_UNPACK_ALIGNMENT, texture.unpackAlignment) # image = clampToMaxSize( texture.image, capabilities.maxTextureSize ) image = texture.image # if textureNeedsPowerOfTwo( texture ) and isPowerOfTwo( image ) == False: # image = makePowerOfTwo( image ) isPowerOfTwoImage = isPowerOfTwo(image) glFormat = utils.convert(texture.format) glType = utils.convert(texture.type) setTextureParameters(GL_TEXTURE_2D, texture, isPowerOfTwoImage) mipmaps = texture.mipmaps if hasattr(texture, "isDepthTexture"): # TODO pass elif hasattr(texture, "isDataTexture"): # TODO pass elif hasattr(texture, "isCompressedTexture"): # TODO pass else: # regular Texture (pygame.Surface) # use manually created mipmaps if available # if there are no manual mipmaps # set 0 level mipmap and then use GL to generate other mipmap levels if len(mipmaps) and isPowerOfTwoImage: for i in xrange(len(mipmaps)): mipmap = mipmaps[i] state.texImage2D(GL_TEXTURE_2D, i, glFormat, glFormat, glType, mipmap) texture.generateMipmaps = False else: state.texImage2D(GL_TEXTURE_2D, 0, glFormat, image.get_width(), image.get_height(), 0, glFormat, glType, c_void_p(image._pixels_address)) if (textureNeedsGenerateMipmaps(texture, isPowerOfTwoImage)): glGenerateMipmap(GL_TEXTURE_2D) textureProperties._version = texture.version if texture.onUpdate: texture.onUpdate(texture)