/* PageSpanPaper.java * * Copyright (c) 2003, : Tuomas J. Lukka * * This file is part of Fenfire. * * Fenfire is free software; you can redistribute it and/or modify it under * the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Fenfire is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General * Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with Fenfire; if not, write to the Free * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * * */ /* * Written by : Tuomas J. Lukka */ package org.fenfire.util; import org.python.util.PythonInterpreter; import org.nongnu.libvob.gl.*; /** Create libpaper papers for PageSpan pages. */ public class PageSpanPaper { public static boolean dbg = false; private static void pa(String s) { System.out.println(s); } // public static gzz.gfx.gl.PaperMill paperMill; // public static gzz.client.GraphicsAPI.RenderingSurface paperMillWindow; /** The page is in the range (0,0)..(w,h) in paper coordinates. */ public final float w, h; /** Return the paper X coordinate for the given full page span coordinate. */ public float getX(float fullPageX) { return w * p.getX(fullPageX) / p.x1; } public float getY(float fullPageY) { return h * p.getY(fullPageY) / p.y1; } GLSpanner.SpanPage p; Paper bg; Paper bgPaper; Paper bgHaloPaper; Paper noBgPaper; /** Return callgl code to bind this page's texture * to the given texunit. */ private String getBindTexture(int i) { return "\n ActiveTexture TEXTURE"+i+" \n"+ "\n BindTexture TEXTURE_2D "+p.getTexture(0,1).getTexId()+"\n"+ filter+ "\n ActiveTexture TEXTURE0\n" ; } private float[] getTexgen() { float x1 = p.getX(w * 72 * 6); float y1 = p.getY(h * 72 * 6); return new float[] { x1 / w, 0, 0, 0, 0, y1 /h, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 }; } /** The code to set filtering on the texture. */ public static String filter = null; /** Set up code for being the only pass. * Simply write out the texture values. */ public static String setupOnlyPass = null; /** Set up code for being the extra pass. * Blend this on top of the current values. */ public static String setupExtraPass = null; /** Set up code for being the extra pass. * Take the value from texunit 0 and blend on top of it texunit 1. */ public static String setupDualPass = null; /** Set up code for being the extra pass. * Take the value from texunit 0 and blend on top of it halo of texunit 1. */ public static String setupHaloDualPass = null; public static boolean withHalo = false; public static String teardown = null; int paperSeed; /** Add a pass where the current page image is the only thing. */ private void addPaperPass(Paper p, String setup) { int pno = p.getNPasses(); p.setNPasses(pno + 1); Paper.Pass pass = p.getPass(pno); pass.setSetupcode(setup + getBindTexture(0)); pass.setTeardowncode(teardown); pass.setNTexGens(1); pass.putNormalTexGen(0, getTexgen()); } /* private Paper getBg() { if(bg == null) { if(paperMill == null) throw new Error("Trying to use bg without papermill"); bg = paperMill.getOptimizedPaper(paperSeed, paperMillWindow); } return bg; } */ public Paper getPaper(boolean withBackground) { return getPaper(withBackground, true); } public Paper getPaper(boolean withBackground, boolean withSpan) { /* if(!withSpan) { if(!withBackground) throw new Error("Can't do without both"); return getBg(); } if(withBackground) { if(withHalo) { if (bgHaloPaper == null) { bgHaloPaper = (Paper)getBg().clone(); if(bgHaloPaper.getNPasses() == 1 && bgHaloPaper.getPass(0).getNTexGens() == 1) { // Draw text-haloed paper Paper.Pass pass = bgHaloPaper.getPass(0); pass.setNTexGens(2); pass.putNormalTexGen(1, getTexgen()); pass.setSetupcode( pass.getSetupcode() + setupHaloDualPass + getBindTexture(1)); pass.setTeardowncode(teardown + pass.getTeardowncode()); // Draw text addPaperPass(bgHaloPaper, setupExtraPass); } else { // We don't have an optimized paper; // add a pass. addPaperPass(bgHaloPaper, setupExtraPass); // FIXME: add halo } } return bgHaloPaper; } else { if(bgPaper == null) { bgPaper = (Paper)getBg().clone(); // Check if we have a single pass and single texture // If yes, *assume*!!! that the right thing // to do is to just put the RGB value out. if(bgPaper.getNPasses() == 1 && bgPaper.getPass(0).getNTexGens() == 1) { Paper.Pass pass = bgPaper.getPass(0); pass.setNTexGens(2); pass.putNormalTexGen(1, getTexgen()); pass.setSetupcode( pass.getSetupcode() + setupDualPass + getBindTexture(1)); pass.setTeardowncode(teardown + pass.getTeardowncode()); } else { // We don't have an optimized paper; // add a pass. addPaperPass(bgPaper, setupExtraPass); } } return bgPaper; } } else { */ if(noBgPaper == null) { noBgPaper = new Paper(); addPaperPass(noBgPaper, setupOnlyPass); } return noBgPaper; // } } public void request(float importance, float pixels) { p.getTexture(importance, pixels); } public PageSpanPaper(GLSpanner.SpanPage p, int paperSeed) { if(filter == null) { PythonInterpreter jython = new PythonInterpreter(); jython.execfile("org/fenfire/util/pagespanpaper.py"); jython.cleanup(); } this.p = p; this.paperSeed = paperSeed; this.w = p.w / 72.0f / 6; this.h = p.h / 72.0f / 6; } }