Пример #1
0
    def selectCombiner(self):
        # Check which combiners to use.
        if not self.paperopts.use_opengl_1_1 and (
                GL.hasExtension("GL_NV_register_combiners")
                or GL.hasExtension("GL_ARB_fragment_program")):

            # We have at least a NV10, possibly better.
            # Check the number of general combiners to be sure.
            #maxcomb = GL.getGLFloat("MAX_GENERAL_COMBINERS_NV")[0]
            #if maxcomb < 4:
            if 1:  #XXX NV20 version is broken
                # use NV10 version
                if dbg: print "Using NV10 combiners ", maxcomb
                texcomb = vob.paper.texcomb_NV1X
                # from org.nongnu.libvob.paper.texcomb_NV1X import TransparentCombinerPass,DebugCombinerPass
            else:
                # use NV20 version
                if dbg: print "Using NV20 combiners ", maxcomb
                texcomb = vob.paper.texcomb_NV2X
                #from org.nongnu.libvob.paper.texcomb_NV2X import TransparentCombinerPass,DebugCombinerPass
        else:
            # Must use OpenGL 1.1 specified calls.
            if dbg: print "Using OpenGL 1.1 texenv and blending"
            texcomb = vob.paper.texcomb_GL1_1
            self.paperopts.use_opengl_1_1 = 1

        self.TransparentCombinerPass = texcomb.TransparentCombinerPass
        self.DebugCombinerPass = texcomb.DebugCombinerPass
Пример #2
0
    def __init__(self):
        self.useOpengL11 = None
        self.passMask = None
        self.trueOpenGL11 = None
        self.lastState = None

        # Check which combiners to use.
        if (GL.hasExtension("GL_NV_register_combiners")
                or GL.hasExtension("GL_ARB_fragment_program")):
            self.trueOpenGL11 = 0
            self.useOpenGL11 = 0
        else:
            self.trueOpenGL11 = 1
            self.useOpenGL11 = 1
Пример #3
0
def initBuffers(w, h):
    print "initBuffers(%s,%s)" % (w,h)
    global width, height, depthTexture, tmpTexture, directDepthCopy
    if width == w and height == h: return

    depthTexture = GL.createTexture()
    tmpTexture = GL.createTexture()
	
    if not GL.hasExtension("GL_NV_texture_rectangle"): return

    width,height = w,h

    rect = 1
    targ = "TEXTURE_RECTANGLE_NV"
    if directDepthCopy:
        depthTexture.loadNull2D(targ, 0, "DEPTH_COMPONENT24",
				width, height, 0, "DEPTH_COMPONENT", "INT")
    else:
        depthTexture.loadNull2D(targ, 0, "RGBA8",
				width, height, 0, "BGRA", "INT")

	tmpTexture.loadNull2D(targ, 0, "RGB8",
			      width, height, 0, "RGB",  "INT")
	tmpTexture.setTexParameter(targ, "TEXTURE_MIN_FILTER", "LINEAR")
	tmpTexture.setTexParameter(targ, "TEXTURE_MAG_FILTER", "LINEAR")
	
    depthTexture.setTexParameter(targ, "TEXTURE_MIN_FILTER", "LINEAR")
    depthTexture.setTexParameter(targ, "TEXTURE_MAG_FILTER", "LINEAR")
Пример #4
0
def fancyHalo(paperMill=None):
    paperMill = getPaperMill(paperMill)
    if not GL.hasExtension("GL_NV_register_combiners"):
        print "fancy Halo for text not possible without GL_NV_register_combiners"
        print "Punting to standard blend"
        return fancyBlend(paperMill)
    if paperMill == None:
        paperMill = PaperMill.getInstance()
    return (HaloPaperMaker_2tex, [paperMill])
Пример #5
0
    def setupCode(self, texinputs, texscales, colors, rnd, trans = 0):
	# 4 colors
	colorbase = rnd.nextInt()
	c0, c1, c2, c3 = [ colors.getColorStr(colorbase+i)
				for i in range(0,4) ]

        #print [round( RGBtoLAB(map(float, rgb.split()))[0] ) for rgb in [c0,c1,c2] ]

	r0, r1, r2, r3 = [ colors.getNVDP3VecStr(colorbase+i)
				for i in range(0,4) ]

        # map alpha dot product a \in [0,1] into clamp(1 - (1-a) * alphascale)
        if trans > 0:
            alphascale = 1 - 1.0/trans
        else:
            alphascale = 0
            
        alphascale = alphascale * (1. / 16)

	assert len(texinputs) != 0
	while len(texinputs) < 4:
	    texinputs = texinputs + texinputs
	t0, t1, t2, t3 = texinputs[0:4]

        #c0, c1, c2 = [ "1 1 1", "1 0 1", "0 1 0"]
        
	constantcode = """
            Enable BLEND
            BlendFunc SRC_ALPHA ONE_MINUS_SRC_ALPHA 
	    BlendEquation FUNC_ADD
            Disable ALPHA_TEST

	    Enable REGISTER_COMBINERS_NV
	    CombinerParameterNV NUM_GENERAL_COMBINERS_NV 2
	    
	    CombinerParameterNV CONSTANT_COLOR0_NV %(r0)s
	    CombinerParameterNV CONSTANT_COLOR1_NV %(r1)s
	    Color %(c0)s
	    SecondaryColorEXT %(c1)s
	    Fog FOG_COLOR %(c2)s
	""" 

        type = rnd.nextInt(3)
        # types: 0=BAND-LIKE, 1=3-COL-LERP, 2=FRACTION-LINE
        
        # Random scaling of (dot) products
        if trans > 0:
            # Try to keep the textures non-fuzzy
            rndscale = exp(.3*abs(rnd.nextGaussian()))
        else:
            rndscale = exp(.5*rnd.nextGaussian())

        def avg(*args):
            sum = 0
            for arg in args: sum += arg
            return sum / float(len(args))
        
	# Then, select the combiner path type.
	if type == 0:
            scale = nvcode.combinerscale(avg(*texscales) * 8.0 * rndscale)
            bandscale = nvcode.combinerscale(3.0 * exp(.5 * rnd.nextGaussian()))

	    # Band-like texture.
	    #
	    # A little different from what Tjl and Jvk originally
	    # planned, where the EF product would have been used;
	    # Sadly, we forgot that E and F are not signed(!).

            # Make outside of the bands transparent if trans > 0
            if trans > 0:
                finalG = "SPARE1_NV"
            else:
                finalG = "ZERO"

	    c = ("""
                # Band-like texture
                
                # SPARE0 <- (TEX0 . TEX1)
		CI0 RGB A TEXTURE%(t0)s EXPAND_NORMAL_NV RGB
		CI0 RGB B TEXTURE%(t1)s EXPAND_NORMAL_NV RGB
		CO0 RGB SPARE0_NV DISCARD_NV DISCARD_NV %(bandscale)s NONE TRUE FALSE FALSE

                # SPARE1 <- SPARE0 * SPARE0
                # SPARE0 <- (TEX0 . CONST0)
		CI1 RGB A SPARE0_NV SIGNED_IDENTITY_NV RGB
		CI1 RGB B SPARE0_NV SIGNED_IDENTITY_NV RGB
		CI1 RGB C TEXTURE%(t0)s EXPAND_NORMAL_NV RGB
		CI1 RGB D CONSTANT_COLOR0_NV EXPAND_NORMAL_NV RGB
		CO1 RGB SPARE1_NV SPARE0_NV DISCARD_NV %(scale)s NONE FALSE TRUE FALSE

                # EF <- SPARE0 * SPARE1
		FCI E SPARE1_NV UNSIGNED_INVERT_NV RGB
		FCI F SPARE0_NV UNSIGNED_IDENTITY_NV RGB

                # lerp(EF, PRI_COL, SEC_COL)
		FCI A E_TIMES_F_NV UNSIGNED_INVERT_NV RGB
		FCI B PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
		FCI C SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
		FCI D ZERO UNSIGNED_IDENTITY_NV RGB

		FCI G %(finalG)s UNSIGNED_INVERT_NV BLUE
	    """)
        elif type == 1:
            scale = nvcode.combinerscale(avg(*texscales) * 8.0 * rndscale)
            alphascale = nvcode.combinerscale(exp(.5 * abs(rnd.nextGaussian())))
            
            # Interpolate between three colors:
            # d0 = t0 . r0
            # d1 = t1 . r1
            # lerp(d1, lerp(d0, c0, c1), c2)
            # The alpha value is computed as d0^2 - d1^2

            if trans > 0:
                finalG = "SPARE1_NV UNSIGNED_IDENTITY_NV"
            else:
                finalG = "ZERO UNSIGNED_INVERT_NV"
            
	    c = ("""
                # Interpolate between three colors using two dot products
            
                # SPARE0 <- (TEX0 . CONST0)
                # SPARE1 <- (TEX1 . CONST1)
		CI0 RGB A TEXTURE%(t0)s EXPAND_NORMAL_NV RGB
                CI0 RGB B CONSTANT_COLOR0_NV EXPAND_NORMAL_NV RGB
		CI0 RGB C TEXTURE%(t1)s EXPAND_NORMAL_NV RGB
                CI0 RGB D CONSTANT_COLOR1_NV EXPAND_NORMAL_NV RGB
		CO0 RGB SPARE0_NV SPARE1_NV DISCARD_NV %(scale)s NONE TRUE TRUE FALSE

                # PRI_COL <- lerp(SPARE0, PRI_COL, SEC_COL)
		CI1 RGB A PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
		CI1 RGB B SPARE0_NV UNSIGNED_INVERT_NV RGB
		CI1 RGB C SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
		CI1 RGB D SPARE0_NV UNSIGNED_IDENTITY_NV RGB
		CO1 RGB DISCARD_NV DISCARD_NV PRIMARY_COLOR_NV NONE NONE FALSE FALSE FALSE

                # SPARE1.alpha <- SPARE0^2 - SPARE1^2
                CI1 ALPHA A SPARE0_NV SIGNED_IDENTITY_NV BLUE
                CI1 ALPHA B SPARE0_NV SIGNED_IDENTITY_NV BLUE
                CI1 ALPHA C SPARE1_NV SIGNED_NEGATE_NV BLUE
                CI1 ALPHA D SPARE1_NV SIGNED_IDENTITY_NV BLUE
                CO1 ALPHA DISCARD_NV DISCARD_NV SPARE1_NV %(alphascale)s NONE FALSE FALSE FALSE

                # lerp(SPARE1, PRI_COL, FOG)
                FCI A SPARE1_NV UNSIGNED_INVERT_NV RGB
                FCI B PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
                FCI C FOG UNSIGNED_IDENTITY_NV RGB
                FCI D ZERO UNSIGNED_IDENTITY_NV RGB

		FCI G %(finalG)s ALPHA
	    """)
        else:
            scale = nvcode.combinerscale(avg(*texscales) * 8.0 * rndscale)
            alphascale = nvcode.combinerscale(avg(*texscales) * 8.0 * rndscale)

            # Interpolate on the fraction line c0,c1,c2:
            # d0 = t0 . t1
            # c(d0) =
            #    -1 -> c0
            #     0 -> c1
            #    +1 -> c2

            # lerp(d1, lerp(d0, c0, c1), c2)
            # The alpha value is computed as d0^2 - d1^2

            if trans > 0:
                finalG = "SPARE1_NV UNSIGNED_IDENTITY_NV"
            else:
                finalG = "ZERO UNSIGNED_INVERT_NV"
            
	    c = ("""
                # Fraction-line color interpolate
                
                # SPARE0 <- (TEX0 . TEX1)  
                # SPARE1 <- -(TEX0 . TEX1) 
		CI0 RGB A TEXTURE%(t0)s EXPAND_NORMAL_NV RGB
		CI0 RGB B TEXTURE%(t1)s EXPAND_NORMAL_NV RGB
		CI0 RGB C TEXTURE%(t0)s EXPAND_NEGATE_NV RGB
		CI0 RGB D TEXTURE%(t1)s EXPAND_NORMAL_NV RGB
		CO0 RGB SPARE0_NV SPARE1_NV DISCARD_NV %(scale)s NONE TRUE TRUE FALSE

                # PRI_COL <- lerp(SPARE1, SEC_COL, PRI_COL)
		CI1 RGB A PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
		CI1 RGB B SPARE1_NV UNSIGNED_INVERT_NV RGB
		CI1 RGB C SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
		CI1 RGB D SPARE1_NV UNSIGNED_IDENTITY_NV RGB
		CO1 RGB DISCARD_NV DISCARD_NV PRIMARY_COLOR_NV NONE NONE FALSE FALSE FALSE

                # lerp(SPARE0, PRI_COL, FOG)
                FCI A SPARE0_NV UNSIGNED_INVERT_NV RGB 
                FCI B PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB 
                FCI C FOG UNSIGNED_IDENTITY_NV RGB 
                FCI D ZERO UNSIGNED_IDENTITY_NV RGB 

                # SPARE1.alpha <- TEX0.b * CONST0.b + TEX1.b * CONST1.b
                CI1 ALPHA A TEXTURE%(t0)s EXPAND_NORMAL_NV BLUE
                CI1 ALPHA B CONSTANT_COLOR0_NV EXPAND_NORMAL_NV BLUE
                CI1 ALPHA C TEXTURE%(t1)s EXPAND_NORMAL_NV BLUE
                CI1 ALPHA B CONSTANT_COLOR1_NV EXPAND_NORMAL_NV BLUE
                CO1 ALPHA DISCARD_NV DISCARD_NV SPARE1_NV %(alphascale)s NONE FALSE FALSE FALSE
                
		FCI G %(finalG)s ALPHA 
	    """)
            
            
	c = (constantcode + c) % locals()
	c = nvcode.combinercode(c)
	# print "c: ",c

        if not GL.hasExtension("GL_NV_register_combiners"):
            # Kluge: emulate using fragment program
            c = nvcode.convCombiner(c, GL)
	return c
Пример #6
0
    def __init__(self,
                 x0,
                 y0,
                 x1,
                 y1,
                 border,
                 ripple,
                 typeInt=0,
                 contentColor=java.awt.Color.white,
                 frameColor=java.awt.Color.black,
                 type="square"):

        self.dbg = 0
        if typeInt == 1:
            type = 'square'
        elif typeInt == 2:
            type = 'ellipse'

        if self.dbg:
            print "Texture id:", self.tex.getTexId()

        def code(color):
            return """
                PushAttrib ENABLE_BIT TEXTURE_BIT CURRENT_BIT
                Enable ALPHA_TEST
                AlphaFunc GREATER 0.0
		Disable BLEND

		Color %(color)s

                ActiveTexture TEXTURE1
                BindTexture TEXTURE_2D %(boxtex)s
                Enable TEXTURE_2D
                TexImage2D TEXTURE_2D 0 ALPHA 4 4 0 ALPHA 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 0
                TexParameter TEXTURE_2D TEXTURE_BASE_LEVEL 0
                TexParameter TEXTURE_2D TEXTURE_MAX_LEVEL 0
		TexParameter TEXTURE_2D TEXTURE_WRAP_S CLAMP
		TexParameter TEXTURE_2D TEXTURE_WRAP_T CLAMP
		TexParameter TEXTURE_2D TEXTURE_MIN_FILTER NEAREST
		TexParameter TEXTURE_2D TEXTURE_MAG_FILTER NEAREST

                #TexGen S TEXTURE_GEN_MODE EYE_LINEAR
                #Enable TEXTURE_GEN_S
                #TexGen T TEXTURE_GEN_MODE EYE_LINEAR
                #Enable TEXTURE_GEN_T

                ActiveTexture TEXTURE0

                BindTexture TEXTURE_2D %(tex)s
                Enable TEXTURE_2D
                %(comb)s REGISTER_COMBINERS_NV
                CombinerParameterNV NUM_GENERAL_COMBINERS_NV 1
                CombinerInputNV COMBINER0_NV ALPHA VARIABLE_A_NV TEXTURE1 UNSIGNED_IDENTITY_NV ALPHA
                CombinerInputNV COMBINER0_NV ALPHA VARIABLE_B_NV TEXTURE0 SIGNED_NEGATE_NV ALPHA
                CombinerInputNV COMBINER0_NV ALPHA VARIABLE_C_NV TEXTURE1 UNSIGNED_IDENTITY_NV ALPHA
                CombinerInputNV COMBINER0_NV ALPHA VARIABLE_D_NV SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV BLUE
                CombinerOutputNV COMBINER0_NV ALPHA DISCARD_NV DISCARD_NV SPARE0_NV NONE NONE FALSE FALSE FALSE

                FinalCombinerInputNV VARIABLE_A_NV ZERO UNSIGNED_IDENTITY_NV RGB
                FinalCombinerInputNV VARIABLE_B_NV ZERO UNSIGNED_IDENTITY_NV RGB
                FinalCombinerInputNV VARIABLE_C_NV ZERO UNSIGNED_IDENTITY_NV RGB
                FinalCombinerInputNV VARIABLE_D_NV PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
                FinalCombinerInputNV VARIABLE_G_NV SPARE0_NV UNSIGNED_IDENTITY_NV ALPHA
        """ % {
                "boxtex": self.boxtex.getTexId(),
                "tex": self.tex.getTexId(),
                "comb": self.combiners,
                "color": vob.util.ColorUtil.colorGLString(color)
            }

        def code2(color):
            return parseCombiner("""
                PushAttrib ENABLE_BIT TEXTURE_BIT COLOR_BUFFER_BIT
                CombinerParameterNV CONSTANT_COLOR0_NV %(color)s 1

                Enable REGISTER_COMBINERS_NV

                SPARE0 = TEX0 . COL0
                SPARE0.alpha = TEX0.alpha * COL0.alpha + COL1.blue

                SPARE0.alpha = SPARE0.blue + SPARE0.alpha

                alpha = SPARE0.alpha
                color = CONST0

                BindTexture TEXTURE_2D %(tex)s
                TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
                TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
                Enable TEXTURE_2D

                Enable ALPHA_TEST
                AlphaFunc GEQUAL 1.0

                Color 0 0 0 1
        """) % {
                "tex": self.tex2.getTexId(),
                "color": vob.util.ColorUtil.colorGLString(color)
            }

        def code3(color):
            return parseCombiner("""
                PushAttrib ENABLE_BIT TEXTURE_BIT CURRENT_BIT COLOR_BUFFER_BIT

                BindTexture TEXTURE_2D %(tex)s
                TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
                TexParameter TEXTURE_2D TEXTURE_MAG_FILTER LINEAR
                Enable TEXTURE_2D
                TexEnv TEXTURE_ENV TEXTURE_ENV_MODE ADD

                Enable ALPHA_TEST
                AlphaFunc GEQUAL 1.0

        """) % {
                "tex": self.tex3.getTexId(),
                "color": vob.util.ColorUtil.colorGLString(color)
            }

        if type == "square":
            self._content = GLRen.createIrregularQuad(x0, y0, x1, y1, border,
                                                      ripple, 0,
                                                      code(contentColor),
                                                      self.dicefactor)
            self._frame = GLRen.createIrregularQuad(x0, y0, x1, y1,
                                                    border, ripple, 1,
                                                    code(frameColor),
                                                    self.dicefactor)
        elif type == "ellipse":
            texscale = ripple
            ripple_scale = border / ripple

            ratio = float(ripple_scale) / self.ripple_scale

            if ratio < 3. / 4 or ratio > 4. / 3:
                if self.dbg:
                    print "WARNING: anisotropy ratio", round(
                        ratio, 2), "is far from one"

            # Irregu flags
            Y_COLOR = 1
            Y_SECCOLOR = 2
            DOTVEC_COLOR = 4
            INTERP_DOTVEC = 8
            SLICE_1D = 16
            SLICE_2D = 32
            SHIFTS = 64
            INSIDE = 128
            SHIFTS8 = 256

            if GL.hasExtension("GL_NV_register_combiners"):
                self._content = GLRen.createIrregularEdge(
                    8, texscale, 2.0, 128, 0, -1 * ripple_scale * texscale,
                    0 * ripple_scale * texscale, 0, "1 1 1 1 0 0 0 0",
                    "", 3, 0, SLICE_1D + Y_SECCOLOR + INSIDE,
                    code2(contentColor), 1.0)

                self._frame = GLRen.createIrregularEdge(
                    8, texscale, 2.0, 128, 0, -1 * ripple_scale * texscale,
                    0 * ripple_scale * texscale, 0, "1 1 1 1 0 0 0 0", "", 3,
                    0, SLICE_1D + Y_SECCOLOR + DOTVEC_COLOR + INTERP_DOTVEC,
                    code2(frameColor), 1.0)
            else:
                self._content = GLRen.createIrregularEdge(
                    8, texscale, 2.0, 128, 0, -1 * ripple_scale * texscale,
                    0 * ripple_scale * texscale, 0, "1 1 1 1 0 0 0 0", "", 0,
                    0, SLICE_1D + Y_COLOR + INSIDE, code3(contentColor), 1.0)

                self._frame = GLRen.createIrregularEdge(
                    8, texscale, 2.0, 128, 0, -1 * ripple_scale * texscale,
                    0 * ripple_scale * texscale, 0, "1 1 1 1 0 0 0 0", "", 0,
                    0, SLICE_1D + Y_COLOR + SHIFTS,
                    code3(frameColor) + """
                    BlendFunc ZERO ZERO
                    Enable BLEND
                    """, 1.0)
Пример #7
0
    def getOptimizedPaper(self,
                          seed,
                          passmask=[1, 1, 1, 1, 1, 1, 1],
                          numcolors=8,
                          minlum=80,
                          blend=0):
        pap = self.getPaper(seed, passmask, numcolors, minlum, blend)

        if not GL.hasExtension("GL_SGIS_generate_mipmap"):
            print "Warning: not returning optimized paper because"
            print "GL_SGIS_generate_mipmap extension is required but not available"
            return pap
        if GL.workaroundStupidBuggyAtiDrivers:
            print "Warning: not returning optimized paper because"
            print "copyTexImage2D has problems on ATI drivers"
            return pap

        # Now, we render a region.
        v = pap.repeat._getSTVectors()

        vs = optimizingWindow.createVobScene()
        vs.map.put(vob.vobs.SolidBackdropVob(java.awt.Color.red))

        cs1 = vs.coords.ortho(0, 0, 0, 0, optimizedPaperSize + 1,
                              optimizedPaperSize + 1)
        cs2 = vs.coords.affine(0, 0, 0, 0, v[0][0], v[0][1], v[1][0], v[1][1])
        vs.map.put(GLRen.createPaperQuad(pap, 0, 0, 1, 1, 1), cs1, cs2)
        optimizingWindow.renderStill(vs, 1)

        tex = GL.createTexture()
        texid = tex.getTexId()
        GL.call("""
	    BindTexture TEXTURE_2D %(texid)s
	    TexParameter TEXTURE_2D TEXTURE_MAX_ANISOTROPY_EXT 2
	    TexParameter TEXTURE_2D  GENERATE_MIPMAP_SGIS TRUE
	    TexParameter TEXTURE_2D  TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
	    TexParameter TEXTURE_2D  TEXTURE_MAG_FILTER LINEAR
	    BindTexture TEXTURE_2D 0
	""" % locals())

        tex.copyTexImage2D(optimizingWindow.getRenderingSurface(), "FRONT",
                           "TEXTURE_2D", 0, "RGB5", 0, 0, optimizedPaperSize,
                           optimizedPaperSize, 0)

        # Apparently, NV drivers 44.96 (maybe others) have some trouble
        # with the 1x1 mipmap getting clobbered.
        # Usually, that wouldn't be a problem, but papers will be viewed
        # 1) at largely different scales
        # 2) blurred for text background
        # so this matters.
        # We shall forbid the use of that mipmap
        tex.setTexParameter("TEXTURE_2D", "TEXTURE_MAX_LEVEL",
                            optimizedPaperMaxLevel)

        if dbg:
            vob.putil.texture.printTex(tex.getTexId())

        npap = PaperHanger()
        npap.setNPasses(1)
        npap.cachedTexture = tex
        npap.addDepend(tex)  # Need this for clones to survive

        ppass = npap.getPass(0)

        ppass.setSetupcode("""
            PushAttrib ENABLE_BIT TEXTURE_BIT DEPTH_BUFFER_BIT COLOR_BUFFER_BIT CURRENT_BIT
            Disable BLEND
	    ActiveTexture TEXTURE1
	    Disable TEXTURE_2D
	    ActiveTexture TEXTURE0
	    Enable DEPTH_TEST
	    DepthFunc LESS
	    BindTexture TEXTURE_2D %(texid)s
	    TexEnv TEXTURE_ENV TEXTURE_ENV_MODE REPLACE
	    Color 0 1 0
	    Enable TEXTURE_2D
	    SecondaryColorEXT 0 0 0
	""" % locals())

        ppass.setNTexGens(1)
        # t = pap.repeat.vecs
        t = v
        if dbg:
            print "T ", t
        ppass.putNormalTexGen(0, [
            t[0][0],
            t[0][1],
            0,
            0,
            -t[1][0],
            -t[1][1],
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
        ])

        ppass.setTeardowncode("""
            PopAttrib
            ActiveTexture TEXTURE0
        """)

        if dbg:
            print "Ret: ", npap.toString(), npap.getPass(0).getNTexGens()

        return npap
Пример #8
0
dbg = 1
# Discriminate between different renderers.
# These are for debug output only.
if dbg:
    vendor = GL.getGLString("VENDOR")
    renderer = GL.getGLString("RENDERER")
    version = GL.getGLString("VERSION")
    print "GL strings: '%s' '%s' '%s'" % (vendor, renderer, version)

#
# Now, go through some questions.
#

# Check which texture operations to use.
if not paperopt.use_opengl_1_1 and GL.hasExtension("GL_NV_texture_shader3"):
    # We can use the general texture shaders.
    # XXX Should check separately for texture_shader2,
    # otherwise it'll be SLOW.
    if dbg: print "Using NV20 texture shaders"
    from vob.paper.texops_NV2X import makeNormalShaderPass, scaleFactor
    numpasses = 2
else:
    if dbg: print "Using unextended OpenGL texture accesses"
    from vob.paper.texops_STD import makeNormalShaderPass, scaleFactor
    numpasses = 3

# Check whether anisotropic filtering is supported
if GL.hasExtension("GL_EXT_texture_filter_anisotropic"):
    if dbg: print "Anisotropic filtering available"
else:
Пример #9
0
# The programs here are best-first
# The following program gives a 30% improvement
# to rendering speeds on a GF FX 5600
# by using a biased texture unit instead of
# calculating the bias explicitly in the program.

# Replacing some of the MULH:s with MULX makes
# it faster but it stops working - the results are
# not accurate enough.
# On the 5900, 5700 this should be a lot faster...
# It's sad that we can't take advantage of the fixed-point
# units at all except at the very end.

nvBlurProgram = None
if GL.hasExtension("GL_NV_fragment_program"):
    nvBlurProgram = GL.createProgram("""!!FP1.0
	# Get the blurred value of the text texture
	# Texture unit 2 is blurred
	TEX H2, f[TEX1], TEX2, 2D;

	# Get the sharp value of the text texture
	TEX H3, f[TEX1], TEX1, 2D;

	# Map blurred 'text' texture intensity to background blur
	# as follows:
	#   1 -> no bias
	#   0 -> large bias
	DP4H H2, {-10,-10,-10,31}, H2;

	# The derivatives of the paper texture