From: Rene S. <sa...@us...> - 2006-10-31 13:06:39
|
Update of /cvsroot/jake2/jake2/src/jake2/render/common In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv15592/src/jake2/render/common Added Files: Polygon.java Misc.java Surf.java Base.java Model.java Warp.java Anorms.java Draw.java Mesh.java Main.java GenericGL.java Image.java Light.java Log Message: major refactoring of the render module --- NEW FILE: Base.java --- /* Copyright (C) 1997-2001 Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 19.08.2006 by RST. // $Id: Base.java,v 1.1 2006/10/31 13:06:32 salomo Exp $ package jake2.render.common; public class Base { public static GenericGL ggl; // to be initialized! protected int GL_TEXTURE0 = -1; protected int GL_TEXTURE1 = -1; protected int GL_COLOR_INDEX8_EXT = ggl.GL_COLOR_INDEX; public static final String REF_VERSION = "GL 0.01"; // up / down public static final int PITCH = 0; // left / right public static final int YAW = 1; // fall over public static final int ROLL = 2; // enum imagetype_t public static final int it_skin = 0; public static final int it_sprite = 1; public static final int it_wall = 2; public static final int it_pic = 3; public static final int it_sky = 4; // enum modtype_t public static final int mod_bad = 0; public static final int mod_brush = 1; public static final int mod_sprite = 2; public static final int mod_alias = 3; public static final int TEXNUM_LIGHTMAPS = 1024; public static final int TEXNUM_SCRAPS = 1152; public static final int TEXNUM_IMAGES = 1153; public static final int MAX_GLTEXTURES = 1024; public static final int MAX_LBM_HEIGHT = 480; public static final float BACKFACE_EPSILON = 0.01f; /* * * GL config stuff */ public static final int GL_RENDERER_VOODOO = 0x00000001; public static final int GL_RENDERER_VOODOO2 = 0x00000002; public static final int GL_RENDERER_VOODOO_RUSH = 0x00000004; public static final int GL_RENDERER_BANSHEE = 0x00000008; public static final int GL_RENDERER_3DFX = 0x0000000F; public static final int GL_RENDERER_PCX1 = 0x00000010; public static final int GL_RENDERER_PCX2 = 0x00000020; public static final int GL_RENDERER_PMX = 0x00000040; public static final int GL_RENDERER_POWERVR = 0x00000070; public static final int GL_RENDERER_PERMEDIA2 = 0x00000100; public static final int GL_RENDERER_GLINT_MX = 0x00000200; public static final int GL_RENDERER_GLINT_TX = 0x00000400; public static final int GL_RENDERER_3DLABS_MISC = 0x00000800; public static final int GL_RENDERER_3DLABS = 0x00000F00; public static final int GL_RENDERER_REALIZM = 0x00001000; public static final int GL_RENDERER_REALIZM2 = 0x00002000; public static final int GL_RENDERER_INTERGRAPH = 0x00003000; public static final int GL_RENDERER_3DPRO = 0x00004000; public static final int GL_RENDERER_REAL3D = 0x00008000; public static final int GL_RENDERER_RIVA128 = 0x00010000; public static final int GL_RENDERER_DYPIC = 0x00020000; public static final int GL_RENDERER_V1000 = 0x00040000; public static final int GL_RENDERER_V2100 = 0x00080000; public static final int GL_RENDERER_V2200 = 0x00100000; public static final int GL_RENDERER_RENDITION = 0x001C0000; public static final int GL_RENDERER_O2 = 0x00100000; public static final int GL_RENDERER_IMPACT = 0x00200000; public static final int GL_RENDERER_RE = 0x00400000; public static final int GL_RENDERER_IR = 0x00800000; public static final int GL_RENDERER_SGI = 0x00F00000; public static final int GL_RENDERER_MCD = 0x01000000; public static final int GL_RENDERER_OTHER = 0x80000000; } --- NEW FILE: Image.java --- /* Copyright (C) 1997-2001 Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ [...1184 lines suppressed...] protected void Scrap_Upload() { scrap_uploads++; GL_Bind(TEXNUM_SCRAPS); GL_Upload8(scrap_texels[0], BLOCK_WIDTH, BLOCK_HEIGHT, false, false); scrap_dirty = false; } protected void GL_MBind(int target, int texnum) { GL_SelectTexture(target); if (target == GL_TEXTURE0) { if (gl_state.currenttextures[0] == texnum) return; } else { if (gl_state.currenttextures[1] == texnum) return; } GL_Bind(texnum); } } --- NEW FILE: Surf.java --- /* Copyright (C) 1997-2001 Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ [...1173 lines suppressed...] if (!LM_AllocBlock(smax, tmax, lightPos)) { Com.Error(Defines.ERR_FATAL, "Consecutive calls to LM_AllocBlock(" + smax + "," + tmax + ") failed\n"); } } // kopiere die koordinaten zurueck surf.light_s = lightPos.x; surf.light_t = lightPos.y; surf.lightmaptexturenum = gl_lms.current_lightmap_texture; base = gl_lms.lightmap_buffer; base.position(surf.light_t * LM_BLOCK_WIDTH + surf.light_s); R_SetCacheState(surf); R_BuildLightMap(surf, base.slice(), LM_BLOCK_WIDTH); } } --- NEW FILE: GenericGL.java --- /* Copyright (C) 1997-2001 Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 28.10.2006 by RST. // $Id: GenericGL.java,v 1.1 2006/10/31 13:06:32 salomo Exp $ package jake2.render.common; import java.nio.*; /** * This is a class for wrapping lwjgl and jogl GL methods. * It is not known if it performs well, but jit should know what we'Re doing. */ public interface GenericGL { public static final int GL_2_BYTES = 5127; public static final int GL_2D = 1536; public static final int GL_3_BYTES = 5128; public static final int GL_3D = 1537; public static final int GL_3D_COLOR = 1538; public static final int GL_3D_COLOR_TEXTURE = 1539; public static final int GL_4_BYTES = 5129; public static final int GL_4D_COLOR_TEXTURE = 1540; public static final int GL_ACCUM = 256; public static final int GL_ACCUM_ALPHA_BITS = 3419; public static final int GL_ACCUM_BLUE_BITS = 3418; public static final int GL_ACCUM_BUFFER_BIT = 512; public static final int GL_ACCUM_CLEAR_VALUE = 2944; public static final int GL_ACCUM_GREEN_BITS = 3417; public static final int GL_ACCUM_RED_BITS = 3416; public static final int GL_ADD = 260; public static final int GL_ALL_ATTRIB_BITS = 0xfffff; public static final int GL_ALL_CLIENT_ATTRIB_BITS = -1; public static final int GL_ALPHA = 6406; public static final int GL_ALPHA_BIAS = 3357; public static final int GL_ALPHA_BITS = 3413; public static final int GL_ALPHA_SCALE = 3356; public static final int GL_ALPHA_TEST = 3008; public static final int GL_ALPHA_TEST_FUNC = 3009; public static final int GL_ALPHA_TEST_REF = 3010; public static final int GL_ALPHA12 = 32829; public static final int GL_ALPHA16 = 32830; public static final int GL_ALPHA4 = 32827; public static final int GL_ALPHA8 = 32828; public static final int GL_ALWAYS = 519; public static final int GL_AMBIENT = 4608; public static final int GL_AMBIENT_AND_DIFFUSE = 5634; public static final int GL_AND = 5377; public static final int GL_AND_INVERTED = 5380; public static final int GL_AND_REVERSE = 5378; public static final int GL_ATTRIB_STACK_DEPTH = 2992; public static final int GL_AUTO_NORMAL = 3456; public static final int GL_AUX_BUFFERS = 3072; public static final int GL_AUX0 = 1033; public static final int GL_AUX1 = 1034; public static final int GL_AUX2 = 1035; public static final int GL_AUX3 = 1036; public static final int GL_BACK = 1029; public static final int GL_BACK_LEFT = 1026; public static final int GL_BACK_RIGHT = 1027; public static final int GL_BITMAP = 6656; public static final int GL_BITMAP_TOKEN = 1796; public static final int GL_BLEND = 3042; public static final int GL_BLEND_DST = 3040; public static final int GL_BLEND_SRC = 3041; public static final int GL_BLUE = 6405; public static final int GL_BLUE_BIAS = 3355; public static final int GL_BLUE_BITS = 3412; public static final int GL_BLUE_SCALE = 3354; public static final int GL_BYTE = 5120; public static final int GL_C3F_V3F = 10788; public static final int GL_C4F_N3F_V3F = 10790; public static final int GL_C4UB_V2F = 10786; public static final int GL_C4UB_V3F = 10787; public static final int GL_CCW = 2305; public static final int GL_CLAMP = 10496; public static final int GL_CLEAR = 5376; public static final int GL_CLIENT_ATTRIB_STACK_DEPTH = 2993; public static final int GL_CLIENT_PIXEL_STORE_BIT = 1; public static final int GL_CLIENT_VERTEX_ARRAY_BIT = 2; public static final int GL_CLIP_PLANE0 = 12288; public static final int GL_CLIP_PLANE1 = 12289; public static final int GL_CLIP_PLANE2 = 12290; public static final int GL_CLIP_PLANE3 = 12291; public static final int GL_CLIP_PLANE4 = 12292; public static final int GL_CLIP_PLANE5 = 12293; public static final int GL_COEFF = 2560; public static final int GL_COLOR = 6144; public static final int GL_COLOR_ARRAY = 32886; public static final int GL_COLOR_ARRAY_POINTER = 32912; public static final int GL_COLOR_ARRAY_SIZE = 32897; public static final int GL_COLOR_ARRAY_STRIDE = 32899; public static final int GL_COLOR_ARRAY_TYPE = 32898; public static final int GL_COLOR_BUFFER_BIT = 16384; public static final int GL_COLOR_CLEAR_VALUE = 3106; public static final int GL_COLOR_INDEX = 6400; public static final int GL_COLOR_INDEXES = 5635; public static final int GL_COLOR_LOGIC_OP = 3058; public static final int GL_COLOR_MATERIAL = 2903; public static final int GL_COLOR_MATERIAL_FACE = 2901; public static final int GL_COLOR_MATERIAL_PARAMETER = 2902; public static final int GL_COLOR_WRITEMASK = 3107; public static final int GL_COMPILE = 4864; public static final int GL_COMPILE_AND_EXECUTE = 4865; public static final int GL_CONSTANT_ALPHA = 32771; public static final int GL_CONSTANT_ATTENUATION = 4615; public static final int GL_CONSTANT_COLOR = 32769; public static final int GL_COPY = 5379; public static final int GL_COPY_INVERTED = 5388; public static final int GL_COPY_PIXEL_TOKEN = 1798; public static final int GL_CULL_FACE = 2884; public static final int GL_CULL_FACE_MODE = 2885; public static final int GL_CURRENT_BIT = 1; public static final int GL_CURRENT_COLOR = 2816; public static final int GL_CURRENT_INDEX = 2817; public static final int GL_CURRENT_NORMAL = 2818; public static final int GL_CURRENT_RASTER_COLOR = 2820; public static final int GL_CURRENT_RASTER_DISTANCE = 2825; public static final int GL_CURRENT_RASTER_INDEX = 2821; public static final int GL_CURRENT_RASTER_POSITION = 2823; public static final int GL_CURRENT_RASTER_POSITION_VALID = 2824; public static final int GL_CURRENT_RASTER_TEXTURE_COORDS = 2822; public static final int GL_CURRENT_TEXTURE_COORDS = 2819; public static final int GL_CW = 2304; public static final int GL_DECAL = 8449; public static final int GL_DECR = 7683; public static final int GL_DEPTH = 6145; public static final int GL_DEPTH_BIAS = 3359; public static final int GL_DEPTH_BITS = 3414; public static final int GL_DEPTH_BUFFER_BIT = 256; public static final int GL_DEPTH_CLEAR_VALUE = 2931; public static final int GL_DEPTH_COMPONENT = 6402; public static final int GL_DEPTH_FUNC = 2932; public static final int GL_DEPTH_RANGE = 2928; public static final int GL_DEPTH_SCALE = 3358; public static final int GL_DEPTH_TEST = 2929; public static final int GL_DEPTH_WRITEMASK = 2930; public static final int GL_DIFFUSE = 4609; public static final int GL_DITHER = 3024; public static final int GL_DOMAIN = 2562; public static final int GL_DONT_CARE = 4352; public static final int GL_DOUBLE = 5130; public static final int GL_DOUBLEBUFFER = 3122; public static final int GL_DRAW_BUFFER = 3073; public static final int GL_DRAW_PIXEL_TOKEN = 1797; public static final int GL_DST_ALPHA = 772; public static final int GL_DST_COLOR = 774; public static final int GL_EDGE_FLAG = 2883; public static final int GL_EDGE_FLAG_ARRAY = 32889; public static final int GL_EDGE_FLAG_ARRAY_POINTER = 32915; public static final int GL_EDGE_FLAG_ARRAY_STRIDE = 32908; public static final int GL_EMISSION = 5632; public static final int GL_ENABLE_BIT = 8192; public static final int GL_EQUAL = 514; public static final int GL_EQUIV = 5385; public static final int GL_EVAL_BIT = 0x10000; public static final int GL_EXP = 2048; public static final int GL_EXP2 = 2049; public static final int GL_EXTENSIONS = 7939; public static final int GL_EYE_LINEAR = 9216; public static final int GL_EYE_PLANE = 9474; public static final int GL_FALSE = 0; public static final int GL_FASTEST = 4353; public static final int GL_FEEDBACK = 7169; public static final int GL_FEEDBACK_BUFFER_POINTER = 3568; public static final int GL_FEEDBACK_BUFFER_SIZE = 3569; public static final int GL_FEEDBACK_BUFFER_TYPE = 3570; public static final int GL_FILL = 6914; public static final int GL_FLAT = 7424; public static final int GL_FLOAT = 5126; public static final int GL_FOG = 2912; public static final int GL_FOG_BIT = 128; public static final int GL_FOG_COLOR = 2918; public static final int GL_FOG_DENSITY = 2914; public static final int GL_FOG_END = 2916; public static final int GL_FOG_HINT = 3156; public static final int GL_FOG_INDEX = 2913; public static final int GL_FOG_MODE = 2917; public static final int GL_FOG_START = 2915; public static final int GL_FRONT = 1028; public static final int GL_FRONT_AND_BACK = 1032; public static final int GL_FRONT_FACE = 2886; public static final int GL_FRONT_LEFT = 1024; public static final int GL_FRONT_RIGHT = 1025; public static final int GL_GEQUAL = 518; public static final int GL_GREATER = 516; public static final int GL_GREEN = 6404; public static final int GL_GREEN_BIAS = 3353; public static final int GL_GREEN_BITS = 3411; public static final int GL_GREEN_SCALE = 3352; public static final int GL_HINT_BIT = 32768; public static final int GL_INCR = 7682; public static final int GL_INDEX_ARRAY = 32887; public static final int GL_INDEX_ARRAY_POINTER = 32913; public static final int GL_INDEX_ARRAY_STRIDE = 32902; public static final int GL_INDEX_ARRAY_TYPE = 32901; public static final int GL_INDEX_BITS = 3409; public static final int GL_INDEX_CLEAR_VALUE = 3104; public static final int GL_INDEX_LOGIC_OP = 3057; public static final int GL_INDEX_MODE = 3120; public static final int GL_INDEX_OFFSET = 3347; public static final int GL_INDEX_SHIFT = 3346; public static final int GL_INDEX_WRITEMASK = 3105; public static final int GL_INT = 5124; public static final int GL_INTENSITY = 32841; public static final int GL_INTENSITY12 = 32844; public static final int GL_INTENSITY16 = 32845; public static final int GL_INTENSITY4 = 32842; public static final int GL_INTENSITY8 = 32843; public static final int GL_INVALID_ENUM = 1280; public static final int GL_INVALID_OPERATION = 1282; public static final int GL_INVALID_VALUE = 1281; public static final int GL_INVERT = 5386; public static final int GL_KEEP = 7680; public static final int GL_LEFT = 1030; public static final int GL_LEQUAL = 515; public static final int GL_LESS = 513; public static final int GL_LIGHT_MODEL_AMBIENT = 2899; public static final int GL_LIGHT_MODEL_LOCAL_VIEWER = 2897; public static final int GL_LIGHT_MODEL_TWO_SIDE = 2898; public static final int GL_LIGHT0 = 16384; public static final int GL_LIGHT1 = 16385; public static final int GL_LIGHT2 = 16386; public static final int GL_LIGHT3 = 16387; public static final int GL_LIGHT4 = 16388; public static final int GL_LIGHT5 = 16389; public static final int GL_LIGHT6 = 16390; public static final int GL_LIGHT7 = 16391; public static final int GL_LIGHTING = 2896; public static final int GL_LIGHTING_BIT = 64; public static final int GL_LINE = 6913; public static final int GL_LINE_BIT = 4; public static final int GL_LINE_LOOP = 2; public static final int GL_LINE_RESET_TOKEN = 1799; public static final int GL_LINE_SMOOTH = 2848; public static final int GL_LINE_SMOOTH_HINT = 3154; public static final int GL_LINE_STIPPLE = 2852; public static final int GL_LINE_STIPPLE_PATTERN = 2853; public static final int GL_LINE_STIPPLE_REPEAT = 2854; public static final int GL_LINE_STRIP = 3; public static final int GL_LINE_TOKEN = 1794; public static final int GL_LINE_WIDTH = 2849; public static final int GL_LINE_WIDTH_GRANULARITY = 2851; public static final int GL_LINE_WIDTH_RANGE = 2850; public static final int GL_LINEAR = 9729; public static final int GL_LINEAR_ATTENUATION = 4616; public static final int GL_LINEAR_MIPMAP_LINEAR = 9987; public static final int GL_LINEAR_MIPMAP_NEAREST = 9985; public static final int GL_LINES = 1; public static final int GL_LIST_BASE = 2866; public static final int GL_LIST_BIT = 0x20000; public static final int GL_LIST_INDEX = 2867; public static final int GL_LIST_MODE = 2864; public static final int GL_LOAD = 257; public static final int GL_LOGIC_OP = 3057; public static final int GL_LOGIC_OP_MODE = 3056; public static final int GL_LUMINANCE = 6409; public static final int GL_LUMINANCE_ALPHA = 6410; public static final int GL_LUMINANCE12 = 32833; public static final int GL_LUMINANCE12_ALPHA12 = 32839; public static final int GL_LUMINANCE12_ALPHA4 = 32838; public static final int GL_LUMINANCE16 = 32834; public static final int GL_LUMINANCE16_ALPHA16 = 32840; public static final int GL_LUMINANCE4 = 32831; public static final int GL_LUMINANCE4_ALPHA4 = 32835; public static final int GL_LUMINANCE6_ALPHA2 = 32836; public static final int GL_LUMINANCE8 = 32832; public static final int GL_LUMINANCE8_ALPHA8 = 32837; public static final int GL_MAP_COLOR = 3344; public static final int GL_MAP_STENCIL = 3345; public static final int GL_MAP1_COLOR_4 = 3472; public static final int GL_MAP1_GRID_DOMAIN = 3536; public static final int GL_MAP1_GRID_SEGMENTS = 3537; public static final int GL_MAP1_INDEX = 3473; public static final int GL_MAP1_NORMAL = 3474; public static final int GL_MAP1_TEXTURE_COORD_1 = 3475; public static final int GL_MAP1_TEXTURE_COORD_2 = 3476; public static final int GL_MAP1_TEXTURE_COORD_3 = 3477; public static final int GL_MAP1_TEXTURE_COORD_4 = 3478; public static final int GL_MAP1_VERTEX_3 = 3479; public static final int GL_MAP1_VERTEX_4 = 3480; public static final int GL_MAP2_COLOR_4 = 3504; public static final int GL_MAP2_GRID_DOMAIN = 3538; public static final int GL_MAP2_GRID_SEGMENTS = 3539; public static final int GL_MAP2_INDEX = 3505; public static final int GL_MAP2_NORMAL = 3506; public static final int GL_MAP2_TEXTURE_COORD_1 = 3507; public static final int GL_MAP2_TEXTURE_COORD_2 = 3508; public static final int GL_MAP2_TEXTURE_COORD_3 = 3509; public static final int GL_MAP2_TEXTURE_COORD_4 = 3510; public static final int GL_MAP2_VERTEX_3 = 3511; public static final int GL_MAP2_VERTEX_4 = 3512; public static final int GL_MATRIX_MODE = 2976; public static final int GL_MAX_ATTRIB_STACK_DEPTH = 3381; public static final int GL_MAX_CLIENT_ATTRIB_STACK_DEPTH = 3387; public static final int GL_MAX_CLIP_PLANES = 3378; public static final int GL_MAX_EVAL_ORDER = 3376; public static final int GL_MAX_LIGHTS = 3377; public static final int GL_MAX_LIST_NESTING = 2865; public static final int GL_MAX_MODELVIEW_STACK_DEPTH = 3382; public static final int GL_MAX_NAME_STACK_DEPTH = 3383; public static final int GL_MAX_PIXEL_MAP_TABLE = 3380; public static final int GL_MAX_PROJECTION_STACK_DEPTH = 3384; public static final int GL_MAX_TEXTURE_SIZE = 3379; public static final int GL_MAX_TEXTURE_STACK_DEPTH = 3385; public static final int GL_MAX_VIEWPORT_DIMS = 3386; public static final int GL_MODELVIEW = 5888; public static final int GL_MODELVIEW_MATRIX = 2982; public static final int GL_MODELVIEW_STACK_DEPTH = 2979; public static final int GL_MODULATE = 8448; public static final int GL_MULT = 259; public static final int GL_N3F_V3F = 10789; public static final int GL_NAME_STACK_DEPTH = 3440; public static final int GL_NAND = 5390; public static final int GL_NEAREST = 9728; public static final int GL_NEAREST_MIPMAP_LINEAR = 9986; public static final int GL_NEAREST_MIPMAP_NEAREST = 9984; public static final int GL_NEVER = 512; public static final int GL_NICEST = 4354; public static final int GL_NO_ERROR = 0; public static final int GL_NONE = 0; public static final int GL_NOOP = 5381; public static final int GL_NOR = 5384; public static final int GL_NORMAL_ARRAY = 32885; public static final int GL_NORMAL_ARRAY_POINTER = 32911; public static final int GL_NORMAL_ARRAY_STRIDE = 32895; public static final int GL_NORMAL_ARRAY_TYPE = 32894; public static final int GL_NORMALIZE = 2977; public static final int GL_NOTEQUAL = 517; public static final int GL_OBJECT_LINEAR = 9217; public static final int GL_OBJECT_PLANE = 9473; public static final int GL_ONE = 1; public static final int GL_ONE_MINUS_CONSTANT_ALPHA = 32772; public static final int GL_ONE_MINUS_CONSTANT_COLOR = 32770; public static final int GL_ONE_MINUS_DST_ALPHA = 773; public static final int GL_ONE_MINUS_DST_COLOR = 775; public static final int GL_ONE_MINUS_SRC_ALPHA = 771; public static final int GL_ONE_MINUS_SRC_COLOR = 769; public static final int GL_OR = 5383; public static final int GL_OR_INVERTED = 5389; public static final int GL_OR_REVERSE = 5387; public static final int GL_ORDER = 2561; public static final int GL_OUT_OF_MEMORY = 1285; public static final int GL_PACK_ALIGNMENT = 3333; public static final int GL_PACK_LSB_FIRST = 3329; public static final int GL_PACK_ROW_LENGTH = 3330; public static final int GL_PACK_SKIP_PIXELS = 3332; public static final int GL_PACK_SKIP_ROWS = 3331; public static final int GL_PACK_SWAP_BYTES = 3328; public static final int GL_PASS_THROUGH_TOKEN = 1792; public static final int GL_PERSPECTIVE_CORRECTION_HINT = 3152; public static final int GL_PIXEL_MAP_A_TO_A = 3193; public static final int GL_PIXEL_MAP_A_TO_A_SIZE = 3257; public static final int GL_PIXEL_MAP_B_TO_B = 3192; public static final int GL_PIXEL_MAP_B_TO_B_SIZE = 3256; public static final int GL_PIXEL_MAP_G_TO_G = 3191; public static final int GL_PIXEL_MAP_G_TO_G_SIZE = 3255; public static final int GL_PIXEL_MAP_I_TO_A = 3189; public static final int GL_PIXEL_MAP_I_TO_A_SIZE = 3253; public static final int GL_PIXEL_MAP_I_TO_B = 3188; public static final int GL_PIXEL_MAP_I_TO_B_SIZE = 3252; public static final int GL_PIXEL_MAP_I_TO_G = 3187; public static final int GL_PIXEL_MAP_I_TO_G_SIZE = 3251; public static final int GL_PIXEL_MAP_I_TO_I = 3184; public static final int GL_PIXEL_MAP_I_TO_I_SIZE = 3248; public static final int GL_PIXEL_MAP_I_TO_R = 3186; public static final int GL_PIXEL_MAP_I_TO_R_SIZE = 3250; public static final int GL_PIXEL_MAP_R_TO_R = 3190; public static final int GL_PIXEL_MAP_R_TO_R_SIZE = 3254; public static final int GL_PIXEL_MAP_S_TO_S = 3185; public static final int GL_PIXEL_MAP_S_TO_S_SIZE = 3249; public static final int GL_PIXEL_MODE_BIT = 32; public static final int GL_POINT = 6912; public static final int GL_POINT_BIT = 2; public static final int GL_POINT_SIZE = 2833; public static final int GL_POINT_SIZE_GRANULARITY = 2835; public static final int GL_POINT_SIZE_RANGE = 2834; public static final int GL_POINT_SMOOTH = 2832; public static final int GL_POINT_SMOOTH_HINT = 3153; public static final int GL_POINT_TOKEN = 1793; public static final int GL_POINTS = 0; public static final int GL_POLYGON = 9; public static final int GL_POLYGON_BIT = 8; public static final int GL_POLYGON_MODE = 2880; public static final int GL_POLYGON_OFFSET_FACTOR = 32824; public static final int GL_POLYGON_OFFSET_FILL = 32823; public static final int GL_POLYGON_OFFSET_LINE = 10754; public static final int GL_POLYGON_OFFSET_POINT = 10753; public static final int GL_POLYGON_OFFSET_UNITS = 10752; public static final int GL_POLYGON_SMOOTH = 2881; public static final int GL_POLYGON_SMOOTH_HINT = 3155; public static final int GL_POLYGON_STIPPLE = 2882; public static final int GL_POLYGON_STIPPLE_BIT = 16; public static final int GL_POLYGON_TOKEN = 1795; public static final int GL_POSITION = 4611; public static final int GL_PROJECTION = 5889; public static final int GL_PROJECTION_MATRIX = 2983; public static final int GL_PROJECTION_STACK_DEPTH = 2980; public static final int GL_PROXY_TEXTURE_1D = 32867; public static final int GL_PROXY_TEXTURE_2D = 32868; public static final int GL_Q = 8195; public static final int GL_QUAD_STRIP = 8; public static final int GL_QUADRATIC_ATTENUATION = 4617; public static final int GL_QUADS = 7; public static final int GL_R = 8194; public static final int GL_R3_G3_B2 = 10768; public static final int GL_READ_BUFFER = 3074; public static final int GL_RED = 6403; public static final int GL_RED_BIAS = 3349; public static final int GL_RED_BITS = 3410; public static final int GL_RED_SCALE = 3348; public static final int GL_RENDER = 7168; public static final int GL_RENDER_MODE = 3136; public static final int GL_RENDERER = 7937; public static final int GL_REPEAT = 10497; public static final int GL_REPLACE = 7681; public static final int GL_RETURN = 258; public static final int GL_RGB = 6407; public static final int GL_RGB10 = 32850; public static final int GL_RGB10_A2 = 32857; public static final int GL_RGB12 = 32851; public static final int GL_RGB16 = 32852; public static final int GL_RGB4 = 32847; public static final int GL_RGB5 = 32848; public static final int GL_RGB5_A1 = 32855; public static final int GL_RGB8 = 32849; public static final int GL_RGBA = 6408; public static final int GL_RGBA_MODE = 3121; public static final int GL_RGBA12 = 32858; public static final int GL_RGBA16 = 32859; public static final int GL_RGBA2 = 32853; public static final int GL_RGBA4 = 32854; public static final int GL_RGBA8 = 32856; public static final int GL_RIGHT = 1031; public static final int GL_S = 8192; public static final int GL_SCISSOR_BIT = 0x80000; public static final int GL_SCISSOR_BOX = 3088; public static final int GL_SCISSOR_TEST = 3089; public static final int GL_SELECT = 7170; public static final int GL_SELECTION_BUFFER_POINTER = 3571; public static final int GL_SELECTION_BUFFER_SIZE = 3572; public static final int GL_SET = 5391; public static final int GL_SHADE_MODEL = 2900; public static final int GL_SHININESS = 5633; public static final int GL_SHORT = 5122; public static final int GL_SMOOTH = 7425; public static final int GL_SPECULAR = 4610; public static final int GL_SPHERE_MAP = 9218; public static final int GL_SPOT_CUTOFF = 4614; public static final int GL_SPOT_DIRECTION = 4612; public static final int GL_SPOT_EXPONENT = 4613; public static final int GL_SRC_ALPHA = 770; public static final int GL_SRC_ALPHA_SATURATE = 776; public static final int GL_SRC_COLOR = 768; public static final int GL_STACK_OVERFLOW = 1283; public static final int GL_STACK_UNDERFLOW = 1284; public static final int GL_STENCIL = 6146; public static final int GL_STENCIL_BITS = 3415; public static final int GL_STENCIL_BUFFER_BIT = 1024; public static final int GL_STENCIL_CLEAR_VALUE = 2961; public static final int GL_STENCIL_FAIL = 2964; public static final int GL_STENCIL_FUNC = 2962; public static final int GL_STENCIL_INDEX = 6401; public static final int GL_STENCIL_PASS_DEPTH_FAIL = 2965; public static final int GL_STENCIL_PASS_DEPTH_PASS = 2966; public static final int GL_STENCIL_REF = 2967; public static final int GL_STENCIL_TEST = 2960; public static final int GL_STENCIL_VALUE_MASK = 2963; public static final int GL_STENCIL_WRITEMASK = 2968; public static final int GL_STEREO = 3123; public static final int GL_SUBPIXEL_BITS = 3408; public static final int GL_T = 8193; public static final int GL_T2F_C3F_V3F = 10794; public static final int GL_T2F_C4F_N3F_V3F = 10796; public static final int GL_T2F_C4UB_V3F = 10793; public static final int GL_T2F_N3F_V3F = 10795; public static final int GL_T2F_V3F = 10791; public static final int GL_T4F_C4F_N3F_V4F = 10797; public static final int GL_T4F_V4F = 10792; public static final int GL_TEXTURE = 5890; public static final int GL_TEXTURE_1D = 3552; public static final int GL_TEXTURE_2D = 3553; public static final int GL_TEXTURE_ALPHA_SIZE = 32863; public static final int GL_TEXTURE_BINDING_1D = 32872; public static final int GL_TEXTURE_BINDING_2D = 32873; public static final int GL_TEXTURE_BIT = 0x40000; public static final int GL_TEXTURE_BLUE_SIZE = 32862; public static final int GL_TEXTURE_BORDER = 4101; public static final int GL_TEXTURE_BORDER_COLOR = 4100; public static final int GL_TEXTURE_COMPONENTS = 4099; public static final int GL_TEXTURE_COORD_ARRAY = 32888; public static final int GL_TEXTURE_COORD_ARRAY_POINTER = 32914; public static final int GL_TEXTURE_COORD_ARRAY_SIZE = 32904; public static final int GL_TEXTURE_COORD_ARRAY_STRIDE = 32906; public static final int GL_TEXTURE_COORD_ARRAY_TYPE = 32905; public static final int GL_TEXTURE_ENV = 8960; public static final int GL_TEXTURE_ENV_COLOR = 8705; public static final int GL_TEXTURE_ENV_MODE = 8704; public static final int GL_TEXTURE_GEN_MODE = 9472; public static final int GL_TEXTURE_GEN_Q = 3171; public static final int GL_TEXTURE_GEN_R = 3170; public static final int GL_TEXTURE_GEN_S = 3168; public static final int GL_TEXTURE_GEN_T = 3169; public static final int GL_TEXTURE_GREEN_SIZE = 32861; public static final int GL_TEXTURE_HEIGHT = 4097; public static final int GL_TEXTURE_INTENSITY_SIZE = 32865; public static final int GL_TEXTURE_INTERNAL_FORMAT = 4099; public static final int GL_TEXTURE_LUMINANCE_SIZE = 32864; public static final int GL_TEXTURE_MAG_FILTER = 10240; public static final int GL_TEXTURE_MATRIX = 2984; public static final int GL_TEXTURE_MIN_FILTER = 10241; public static final int GL_TEXTURE_PRIORITY = 32870; public static final int GL_TEXTURE_RED_SIZE = 32860; public static final int GL_TEXTURE_RESIDENT = 32871; public static final int GL_TEXTURE_STACK_DEPTH = 2981; public static final int GL_TEXTURE_WIDTH = 4096; public static final int GL_TEXTURE_WRAP_S = 10242; public static final int GL_TEXTURE_WRAP_T = 10243; public static final int GL_TRANSFORM_BIT = 4096; public static final int GL_TRIANGLE_FAN = 6; public static final int GL_TRIANGLE_STRIP = 5; public static final int GL_TRIANGLES = 4; public static final int GL_TRUE = 1; public static final int GL_UNPACK_ALIGNMENT = 3317; public static final int GL_UNPACK_LSB_FIRST = 3313; public static final int GL_UNPACK_ROW_LENGTH = 3314; public static final int GL_UNPACK_SKIP_PIXELS = 3316; public static final int GL_UNPACK_SKIP_ROWS = 3315; public static final int GL_UNPACK_SWAP_BYTES = 3312; public static final int GL_UNSIGNED_BYTE = 5121; public static final int GL_UNSIGNED_INT = 5125; public static final int GL_UNSIGNED_SHORT = 5123; public static final int GL_V2F = 10784; public static final int GL_V3F = 10785; public static final int GL_VENDOR = 7936; public static final int GL_VERSION = 7938; public static final int GL_VERTEX_ARRAY = 32884; public static final int GL_VERTEX_ARRAY_POINTER = 32910; public static final int GL_VERTEX_ARRAY_SIZE = 32890; public static final int GL_VERTEX_ARRAY_STRIDE = 32892; public static final int GL_VERTEX_ARRAY_TYPE = 32891; public static final int GL_VIEWPORT = 2978; public static final int GL_VIEWPORT_BIT = 2048; public static final int GL_XOR = 5382; public static final int GL_ZERO = 0; public static final int GL_ZOOM_X = 3350; public static final int GL_ZOOM_Y = 3351; void glActiveTextureARB(int texture); void glBegin(int gl_triangle_fan2); void glBindTexture(int gl_texture_2d2, int texnum); void glBlendFunc(int gl_src_alpha2, int gl_one_minus_src_alpha2); void glClear(int gl_color_buffer_bit2); void glClearColor(float f, float g, float h, float i); void glClientActiveTextureARB(int texture); void glColor3f(float f, float g, float h); void glColor3ub(byte b, byte c, byte d); void glColor4f(float intens, float intens2, float intens3, float f); void glColor4f(int i, int j, int k, float f); void glColor4ub(byte b, byte c, byte d, byte e); void glColorPointer(int i, int gl_float2, int j, FloatBuffer colorArrayBuf); void glColorPointer(int i, int gl_unsigned_byte2, int j, ByteBuffer bb); void glCullFace(int gl_back2); void glDepthFunc(int gl_lequal2); void glDepthMask(boolean b); void glDepthRange(float gldepthmin, double d); void glDisable(int gl_texture_2d2); void glDisableClientState(int gl_color_array2); void glDrawArrays(int gl_polygon2, int pos, int numverts); void glDrawElements(int mode, int count, int gl_unsigned_int2, IntBuffer srcIndexBuf); void glEnable(int gl_alpha_test2); void glEnableClientState(int gl_color_array2); void glEnd(); void glFrustum(double xmin, double xmax, double ymin, double ymax, double near, double far); void glInterleavedArrays(int gl_t2f_v3f2, int byte_stride, FloatBuffer globalPolygonInterleavedBuf); void glLoadIdentity(); void glLoadMatrixf(float[] r_world_matrix); void glMatrixMode(int gl_projection2); void glOrtho(int i, int width, int height, int j, int k, int l); void glPointSize(float value); void glPopMatrix(); void glPushMatrix(); void glRotatef(float f, float g, float h, float i); void glScalef(int i, int j, int k); void glShadeModel(int gl_smooth2); void glTexCoord2f(float s, float t); void glTexCoordPointer(int i, int gl_float2, int j, FloatBuffer textureArrayBuf); void glTexEnvi(int gl_texture_env2, int gl_texture_env_mode2, int mode); void glTexImage2D(int gl_texture_2d2, int i, int gl_color_index8_ext, int j, int k, int l, int gl_color_index2, int gl_unsigned_byte2, ByteBuffer image8); void glTexImage2D(int gl_texture_2d2, int i, int gl_tex_solid_format, int j, int k, int l, int gl_rgba3, int gl_unsigned_byte2, IntBuffer image32); void glTexParameterf(int gl_texture_2d, int gl_texture_min_filter, int gl_nearest); void glTexParameteri(int gl_texture_2d2, int gl_texture_min_filter2, int gl_filter_min); void glTexSubImage2D(int gl_texture_2d2, int i, int j, int k, int lm_block_width, int height, int gl_lightmap_format, int gl_unsigned_byte2, IntBuffer lightmap_buffer); void glTranslatef(float f, float g, float h); void glVertex2f(int x, int i); void glVertex3f(float f, float g, float h); void glVertexPointer(int i, int gl_float2, int j, FloatBuffer vertexArrayBuf); void glViewport(int i, int j, int width, int height); } --- NEW FILE: Light.java --- /* Copyright (C) 1997-2001 Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 20.08.2006 by RST. // $Id: Light.java,v 1.1 2006/10/31 13:06:32 salomo Exp $ package jake2.render.common; import java.nio.ByteBuffer; import java.nio.IntBuffer; import java.util.Arrays; import jake2.*; import jake2.client.*; import jake2.game.*; import jake2.qcommon.*; import jake2.render.*; import jake2.server.*; import jake2.util.Math3D; import jake2.util.Vec3Cache; public abstract class Light extends Warp { protected float[] pointcolor = { 0, 0, 0 }; // vec3_t protected cplane_t lightplane; // used as shadow plane protected float[] lightspot = { 0, 0, 0 }; // vec3_t protected float[] s_blocklights = new float[34 * 34 * 3]; protected int r_dlightframecount; protected final float[] impact = { 0, 0, 0 }; public static final int DLIGHT_CUTOFF = 64; /** * R_AddDynamicLights */ protected void R_AddDynamicLights(msurface_t surf) { int sd, td; float fdist, frad, fminlight; int s, t; dlight_t dl; float[] pfBL; float fsacc, ftacc; int smax = (surf.extents[0] >> 4) + 1; int tmax = (surf.extents[1] >> 4) + 1; mtexinfo_t tex = surf.texinfo; float local0, local1; for (int lnum = 0; lnum < r_newrefdef.num_dlights; lnum++) { if ((surf.dlightbits & (1 << lnum)) == 0) continue; // not lit by this light dl = r_newrefdef.dlights[lnum]; frad = dl.intensity; fdist = Math3D.DotProduct(dl.origin, surf.plane.normal) - surf.plane.dist; frad -= Math.abs(fdist); // rad is now the highest intensity on the plane fminlight = DLIGHT_CUTOFF; // FIXME: make configurable? if (frad < fminlight) continue; fminlight = frad - fminlight; for (int i = 0; i < 3; i++) { impact[i] = dl.origin[i] - surf.plane.normal[i] * fdist; } local0 = Math3D.DotProduct(impact, tex.vecs[0]) + tex.vecs[0][3] - surf.texturemins[0]; local1 = Math3D.DotProduct(impact, tex.vecs[1]) + tex.vecs[1][3] - surf.texturemins[1]; pfBL = s_blocklights; int pfBLindex = 0; for (t = 0, ftacc = 0; t < tmax; t++, ftacc += 16) { td = (int) (local1 - ftacc); if (td < 0) td = -td; for (s = 0, fsacc = 0; s < smax; s++, fsacc += 16, pfBLindex += 3) { sd = (int) (local0 - fsacc); if (sd < 0) sd = -sd; if (sd > td) fdist = sd + (td >> 1); else fdist = td + (sd >> 1); if (fdist < fminlight) { pfBL[pfBLindex + 0] += (frad - fdist) * dl.color[0]; pfBL[pfBLindex + 1] += (frad - fdist) * dl.color[1]; pfBL[pfBLindex + 2] += (frad - fdist) * dl.color[2]; } } } } } // replaces the goto jump private Throwable gotoStore = new Throwable(); /** * R_BuildLightMap * * Combine and scale multiple lightmaps into the floating format in * blocklights */ protected void R_BuildLightMap(msurface_t surf, IntBuffer dest, int stride) { int r, g, b, a, max; int i, j; int nummaps; float[] bl; // lightstyle_t style; if ((surf.texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33 | Defines.SURF_TRANS66 | Defines.SURF_WARP)) != 0) Com.Error(Defines.ERR_DROP, "R_BuildLightMap called for non-lit surface"); int smax = (surf.extents[0] >> 4) + 1; int tmax = (surf.extents[1] >> 4) + 1; int size = smax * tmax; if (size > ((s_blocklights.length * Defines.SIZE_OF_FLOAT) >> 4)) Com.Error(Defines.ERR_DROP, "Bad s_blocklights size"); try { // set to full bright if no light data if (surf.samples == null) { for (i = 0; i < size * 3; i++) s_blocklights[i] = 255; // goto store; throw gotoStore; } // count the # of maps for (nummaps = 0; nummaps < Defines.MAXLIGHTMAPS && surf.styles[nummaps] != (byte) 255; nummaps++); ByteBuffer lightmap = surf.samples; int lightmapIndex = 0; // add all the lightmaps float scale0; float scale1; float scale2; if (nummaps == 1) { int maps; for (maps = 0; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte) 255; maps++) { bl = s_blocklights; int blp = 0; // for (i = 0; i < 3; i++) // scale[i] = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i]; scale0 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[0]; scale1 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[1]; scale2 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[2]; if (scale0 == 1.0F && scale1 == 1.0F && scale2 == 1.0F) { for (i = 0; i < size; i++) { bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF; bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF; bl[blp++] = lightmap.get(lightmapIndex++) & 0xFF; } } else { for (i = 0; i < size; i++) { bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) * scale0; bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) * scale1; bl[blp++] = (lightmap.get(lightmapIndex++) & 0xFF) * scale2; } } // lightmap += size*3; // skip to next lightmap } } else { int maps; Arrays.fill(s_blocklights, 0, size * 3, 0.0f); for (maps = 0; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte) 255; maps++) { bl = s_blocklights; int blp = 0; // for (i = 0; i < 3; i++) // scale[i] = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[i]; scale0 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[0]; scale1 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[1]; scale2 = gl_modulate.value * r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb[2]; if (scale0 == 1.0F && scale1 == 1.0F && scale2 == 1.0F) { for (i = 0; i < size; i++) { bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF; bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF; bl[blp++] += lightmap.get(lightmapIndex++) & 0xFF; } } else { for (i = 0; i < size; i++) { bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) * scale0; bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) * scale1; bl[blp++] += (lightmap.get(lightmapIndex++) & 0xFF) * scale2; } } // lightmap += size*3; // skip to next lightmap } } // add all the dynamic lights if (surf.dlightframe == r_framecount) R_AddDynamicLights(surf); // label store: } catch (Throwable store) { } // put into texture format stride -= smax; bl = s_blocklights; int blp = 0; int monolightmap = gl_monolightmap.string.charAt(0); int destp = 0; if (monolightmap == '0') { for (i = 0; i < tmax; i++, destp += stride) { // dest.position(destp); for (j = 0; j < smax; j++) { r = (int) bl[blp++]; g = (int) bl[blp++]; b = (int) bl[blp++]; // catch negative lights if (r < 0) r = 0; if (g < 0) g = 0; if (b < 0) b = 0; /* * * determine the brightest of the three color components */ if (r > g) max = r; else max = g; if (b > max) max = b; /* * * alpha is ONLY used for the mono lightmap case. For this * reason * we set it to the brightest of the color * components so that * things don't get too dim. */ a = max; /* * * rescale all the color components if the intensity of * the greatest * channel exceeds 1.0 */ if (max > 255) { float t = 255.0F / max; r = (int) (r * t); g = (int) (g * t); b = (int) (b * t); a = (int) (a * t); } // r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF; dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | r); } } } else { for (i = 0; i < tmax; i++, destp += stride) { // dest.position(destp); for (j = 0; j < smax; j++) { r = (int) bl[blp++]; g = (int) bl[blp++]; b = (int) bl[blp++]; // catch negative lights if (r < 0) r = 0; if (g < 0) g = 0; if (b < 0) b = 0; /* * * determine the brightest of the three color components */ if (r > g) max = r; else max = g; if (b > max) max = b; /* * * alpha is ONLY used for the mono lightmap case. For this * reason * we set it to the brightest of the color * components so that * things don't get too dim. */ a = max; /* * * rescale all the color components if the intensity of * the greatest * channel exceeds 1.0 */ if (max > 255) { float t = 255.0F / max; r = (int) (r * t); g = (int) (g * t); b = (int) (b * t); a = (int) (a * t); } /* * * So if we are doing alpha lightmaps we need to set the * R, G, and B * components to 0 and we need to set alpha to * 1-alpha. */ switch (monolightmap) { case 'L': case 'I': r = a; g = b = 0; break; case 'C': // try faking colored lighting a = 255 - ((r + g + b) / 3); float af = a / 255.0f; r *= af; g *= af; b *= af; break; case 'A': default: r = g = b = 0; a = 255 - a; break; } // r &= 0xFF; g &= 0xFF; b &= 0xFF; a &= 0xFF; dest.put(destp++, (a << 24) | (b << 16) | (g << 8) | r); } } } } // stack variable private final float[] end = { 0, 0, 0 }; /** * R_LightPoint */ protected void R_LightPoint(float[] p, float[] color) { assert (p.length == 3) : "vec3_t bug"; assert (color.length == 3) : "rgb bug"; if (r_worldmodel.lightdata == null) { color[0] = color[1] = color[2] = 1.0f; return; } end[0] = p[0]; end[1] = p[1]; end[2] = p[2] - 2048; float r = RecursiveLightPoint(r_worldmodel.nodes[0], p, end); if (r == -1) { Math3D.VectorCopy(Globals.vec3_origin, color); } else { Math3D.VectorCopy(pointcolor, color); } // // add dynamic lights // dlight_t dl; float add; for (int lnum = 0; lnum < r_newrefdef.num_dlights; lnum++) { dl = r_newrefdef.dlights[lnum]; Math3D.VectorSubtract(currententity.origin, dl.origin, end); add = dl.intensity - Math3D.VectorLength(end); add *= (1.0f / 256); if (add > 0) { Math3D.VectorMA(color, add, dl.color, color); } } Math3D.VectorScale(color, gl_modulate.value, color); } /** * RecursiveLightPoint * * @param node * @param start * @param end * @return */ protected int RecursiveLightPoint(mnode_t node, float[] start, float[] end) { if (node.contents != -1) return -1; // didn't hit anything // calculate mid point // FIXME: optimize for axial cplane_t plane = node.plane; float front = Math3D.DotProduct(start, plane.normal) - plane.dist; float back = Math3D.DotProduct(end, plane.normal) - plane.dist; boolean side = (front < 0); int sideIndex = (side) ? 1 : 0; if ((back < 0) == side) return RecursiveLightPoint(node.children[sideIndex], start, end); float frac = front / (front - back); float[] mid = Vec3Cache.get(); mid[0] = start[0] + (end[0] - start[0]) * frac; mid[1] = start[1] + (end[1] - start[1]) * frac; mid[2] = start[2] + (end[2] - start[2]) * frac; // go down front side int r = RecursiveLightPoint(node.children[sideIndex], start, mid); if (r >= 0) { Vec3Cache.release(); // mid return r; // hit something } if ((back < 0) == side) { Vec3Cache.release(); // mid return -1; // didn't hit anuthing } // check for impact on this node Math3D.VectorCopy(mid, lightspot); lightplane = plane; int surfIndex = node.firstsurface; msurface_t surf; int s, t, ds, dt; mtexinfo_t tex; ByteBuffer lightmap; int maps; for (int i = 0; i < node.numsurfaces; i++, surfIndex++) { surf = r_worldmodel.surfaces[surfIndex]; if ((surf.flags & (Defines.SURF_DRAWTURB | Defines.SURF_DRAWSKY)) != 0) continue; // no lightmaps tex = surf.texinfo; s = (int) (Math3D.DotProduct(mid, tex.vecs[0]) + tex.vecs[0][3]); t = (int) (Math3D.DotProduct(mid, tex.vecs[1]) + tex.vecs[1][3]); if (s < surf.texturemins[0] || t < surf.texturemins[1]) continue; ds = s - surf.texturemins[0]; dt = t - surf.texturemins[1]; if (ds > surf.extents[0] || dt > surf.extents[1]) continue; if (surf.samples == null) return 0; ds >>= 4; dt >>= 4; lightmap = surf.samples; int lightmapIndex = 0; Math3D.VectorCopy(Globals.vec3_origin, pointcolor); if (lightmap != null) { float[] rgb; lightmapIndex += 3 * (dt * ((surf.extents[0] >> 4) + 1) + ds); float scale0, scale1, scale2; for (maps = 0; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte) 255; maps++) { rgb = r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].rgb; scale0 = gl_modulate.value * rgb[0]; scale1 = gl_modulate.value * rgb[1]; scale2 = gl_modulate.value * rgb[2]; pointcolor[0] += (lightmap.get(lightmapIndex + 0) & 0xFF) * scale0 * (1.0f / 255); pointcolor[1] += (lightmap.get(lightmapIndex + 1) & 0xFF) * scale1 * (1.0f / 255); pointcolor[2] += (lightmap.get(lightmapIndex + 2) & 0xFF) * scale2 * (1.0f / 255); lightmapIndex += 3 * ((surf.extents[0] >> 4) + 1) * ((surf.extents[1] >> 4) + 1); } } Vec3Cache.release(); // mid return 1; } // go down back side r = RecursiveLightPoint(node.children[1 - sideIndex], mid, end); Vec3Cache.release(); // mid return r; } /** * R_MarkLights */ protected void R_MarkLights(dlight_t light, int bit, mnode_t node) { if (node.contents != -1) return; cplane_t splitplane = node.plane; float dist = Math3D.DotProduct(light.origin, splitplane.normal) - splitplane.dist; if (dist > light.intensity - DLIGHT_CUTOFF) { R_MarkLights(light, bit, node.children[0]); return; } if (dist < -light.intensity + DLIGHT_CUTOFF) { R_MarkLights(light, bit, node.children[1]); return; } // mark the polygons msurface_t surf; int sidebit; for (int i = 0; i < node.numsurfaces; i++) { surf = r_worldmodel.surfaces[node.firstsurface + i]; /* * cwei bugfix for dlight behind the walls */ dist = Math3D.DotProduct(light.origin, surf.plane.normal) - surf.plane.dist; sidebit = (dist >= 0) ? 0 : Defines.SURF_PLANEBACK; if ((surf.flags & Defines.SURF_PLANEBACK) != sidebit) continue; /* * cwei bugfix end */ if (surf.dlightframe != r_dlightframecount) { surf.dlightbits = 0; surf.dlightframe = r_dlightframecount; } surf.dlightbits |= bit; } R_MarkLights(light, bit, node.children[0]); R_MarkLights(light, bit, node.children[1]); } /** * R_SetCacheState */ protected void R_SetCacheState(msurface_t surf) { for (int maps = 0; maps < Defines.MAXLIGHTMAPS && surf.styles[maps] != (byte) 255; maps++) { surf.cached_light[maps] = r_newrefdef.lightstyles[surf.styles[maps] & 0xFF].white; } } /** * R_PushDlights */ protected void R_PushDlights() { if (gl_flashblend.value != 0) return; r_dlightframecount = r_framecount + 1; // because the count hasn't // advanced yet for this frame dlight_t l; for (int i = 0; i < r_newrefdef.num_dlights; i++) { l = r_newrefdef.dlights[i]; R_MarkLights(l, 1 << i, r_worldmodel.nodes[0]); } } /* * ============================================================================= * * DYNAMIC LIGHTS BLEND RENDERING * * ============================================================================= */ void R_RenderDlight(dlight_t light) { float rad = light.intensity * 0.35f; float[] v = Vec3Cache.get(); Math3D.VectorSubtract(light.origin, r_origin, v); ggl.glBegin(ggl.GL_TRIANGLE_FAN); ggl.glColor3f(light.color[0] * 0.2f, light.color[1] * 0.2f, light.color[2] * 0.2f); for (int i = 0; i < 3; i++) v[i] = light.origin[i] - vpn[i] * rad; ggl.glVertex3f(v[0], v[1], v[2]); ggl.glColor3f(0, 0, 0); float a; for (int i = 16; i >= 0; i--) { a = (float) (i / 16.0f * Math.PI * 2); for (int j = 0; j < 3; j++) v[j] = (float) (light.origin[j] + vright[j] * Math.cos(a) * rad + vup[j] * Math.sin(a) * rad); ggl.glVertex3f(v[0], v[1], v[2]); } ggl.glEnd(); Vec3Cache.release(); } /** * ============= R_RenderDlights ============= */ public void R_RenderDlights() { if (gl_flashblend.value == 0) return; r_dlightframecount = r_framecount + 1; // because the count hasn't // advanced yet for this frame ggl.glDepthMask(false); ggl.glDisable(ggl.GL_TEXTURE_2D); ggl.glShadeModel(ggl.GL_SMOOTH); ggl.glDisable(ggl.GL_BLEND); ggl.glBlendFunc(ggl.GL_ONE, ggl.GL_ONE); for (int i = 0; i < r_newrefdef.num_dlights; i++) { R_RenderDlight(r_newrefdef.dlights[i]); } ggl.glColor3f(1, 1, 1); ggl.glDisable(ggl.GL_BLEND); ggl.glDisable(ggl.GL_TEXTURE_2D); ggl.glBlendFunc(ggl.GL_SRC_ALPHA, ggl.GL_ONE_MINUS_SRC_ALPHA); ggl.glDepthMask(true); } } --- NEW FILE: Mesh.java --- /* Copyright (C) 1997-2001 Id Software, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // Created on 25.08.2006 by RST. // $Id: Mesh.java,v 1.1 2006/10/31 13:06:32 salomo Exp $ package jake2.render.common; import jake2.Defines; import jake2.client.VID; import jake2.client.entity_t; import jake2.qcommon.qfiles; import jake2.render.image_t; import jake2.util.Math3D; import jake2.util.Vec3Cache; import java.nio.FloatBuffer; import java.nio.IntBuffer; import net.java.games.joal.util.BufferUtils; public abstract class Mesh extends Light { protected static final int NUMVERTEXNORMALS = 162; protected float[][] r_avertexnormals = Anorms.VERTEXNORMALS; protected float[] shadevector = { 0, 0, 0 }; protected float[] shadelight = { 0, 0, 0 }; // precalculated dot products for quantized angles protected static final int SHADEDOT_QUANT = 16; protected float[][] r_avertexnormal_dots = Anorms.VERTEXNORMAL_DOTS; protected float[] shadedots = r_avertexnormal_dots[0]; // bounding box protected float[][] bbox = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }; /* * ================== R_InitParticleTexture ================== */ protected byte[][] dottexture = { { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 1, 1, 0, 0, 0, 0 }, { 0, 1, 1, 1, 1, 0, 0, 0 }, { 0, 1, 1, 1, 1, 0, 0, 0 }, { 0, 0, 1, 1, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0 }, }; protected void R_InitParticleTexture() { int x, y; byte[] data = new byte[8 * 8 * 4]; // // particle texture // for (x = 0; x < 8; x++) { for (y = 0; y < 8; y++) { data[y * 32 + x * 4 + 0] = (byte) 255; data[y * 32 + x * 4 + 1] = (byte) 255; data[y * 32 + x * 4 + 2] = (byte) 255; data[y * 32 + x * 4 + 3] = (byte) (dottexture[x][y] * 255); } } r_particletexture = GL_LoadPic("***particle***", data, 8, 8, Base.it_sprite, 32); // // also use this for bad textures, but without alpha // for (x = 0; x < 8; x++) { for (y = 0; y < 8; y++) { data[y * 32 + x * 4 + 0] = (byte) (dottexture[x & 3][y & 3] * 255); data[y * 32 + x * 4 + 1] = 0; // dottexture[x&3][y&3]*255; data[y * 32 + x * 4 + 2] = 0; // dottexture[x&3][y&3]*255; data[y * 32 + x * 4 + 3] = (byte) 255; } } r_notexture = GL_LoadPic("***r_notexture***", data, 8, 8, Base.it_wall, 32); } /** * GL_LerpVerts */ protected void GL_LerpVerts(int nverts, int[] ov, int[] v, float[] move, float[] frontv, float[] backv) { FloatBuffer lerp = vertexArrayBuf; lerp.limit((nverts << 2) - nverts); // nverts * 3 int ovv, vv; // PMM -- added RF_SHELL_DOUBLE, RF_SHELL_HALF_DAM if ((currententity.flags & (Defines.RF_SHELL_RED | Defines.RF_SHELL_GREEN | Defines.RF_SHELL_BLUE | Defines.RF_SHELL_DOUBLE | Defines.RF_SHELL_HALF_DAM)) != 0) { float[] normal; int j = 0; for (int i = 0; i < nverts; i++/* , v++, ov++, lerp+=4 */) { vv = v[i]; normal = r_avertexnormals[(vv >>> 24) & 0xFF]; ovv = ov[i]; lerp.put(j, move[0] + (ovv & 0xFF) * backv[0] + (vv & 0xFF) * frontv[0] + normal[0] * Defines.POWERSUIT_SCALE); lerp.put(j + 1, move[1] + ((ovv >>> 8) & 0xFF) * backv[1] + ((vv >>> 8) & 0xFF) * fro... [truncated message content] |