📄 surf.java
字号:
if (map == 4) map--; // dynamic this frame or dynamic previously if (gotoDynamic || (surf.dlightframe == r_framecount)) { // label dynamic: if (gl_dynamic.value != 0) { if ((surf.texinfo.flags & (Defines.SURF_SKY | Defines.SURF_TRANS33 | Defines.SURF_TRANS66 | Defines.SURF_WARP)) == 0) { is_dynamic = true; } } } if (is_dynamic) { // ist raus gezogen worden int[] temp = new int[128*128]; int smax, tmax; if (((surf.styles[map] & 0xFF) >= 32 || surf.styles[map] == 0) && (surf.dlightframe != r_framecount)) { smax = (surf.extents[0] >> 4) + 1; tmax = (surf.extents[1] >> 4) + 1; R_BuildLightMap(surf, temp, smax); R_SetCacheState(surf); GL_MBind(GL_TEXTURE1, gl_state.lightmap_textures + surf.lightmaptexturenum); lmtex = surf.lightmaptexturenum; gl.glTexSubImage2D(GL.GL_TEXTURE_2D, 0, surf.light_s, surf.light_t, smax, tmax, GL_LIGHTMAP_FORMAT, GL.GL_UNSIGNED_BYTE, temp); } else { smax = (surf.extents[0] >> 4) + 1; tmax = (surf.extents[1] >> 4) + 1; R_BuildLightMap(surf, temp, smax); GL_MBind(GL_TEXTURE1, gl_state.lightmap_textures + 0); lmtex = 0; gl.glTexSubImage2D(GL.GL_TEXTURE_2D, 0, surf.light_s, surf.light_t, smax, tmax, GL_LIGHTMAP_FORMAT, GL.GL_UNSIGNED_BYTE, temp); } c_brush_polys++; GL_MBind(GL_TEXTURE0, image.texnum); GL_MBind(GL_TEXTURE1, gl_state.lightmap_textures + lmtex); // ========== // PGM if ((surf.texinfo.flags & Defines.SURF_FLOWING) != 0) { float scroll; scroll = -64 * ((r_newrefdef.time / 40.0f) - (int) (r_newrefdef.time / 40.0f)); if (scroll == 0.0f) scroll = -64.0f; for (p = surf.polys; p != null; p = p.chain) { p.beginScrolling(scroll); gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); p.endScrolling(); } } else { for (p = surf.polys; p != null; p = p.chain) { gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); } } // PGM // ========== } else { c_brush_polys++; GL_MBind(GL_TEXTURE0, image.texnum); GL_MBind(GL_TEXTURE1, gl_state.lightmap_textures + lmtex); // ========== // PGM if ((surf.texinfo.flags & Defines.SURF_FLOWING) != 0) { float scroll; scroll = -64 * ((r_newrefdef.time / 40.0f) - (int) (r_newrefdef.time / 40.0f)); if (scroll == 0.0) scroll = -64.0f; for (p = surf.polys; p != null; p = p.chain) { p.beginScrolling(scroll); gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); p.endScrolling(); } } else { // PGM // ========== for (p = surf.polys; p != null; p = p.chain) { gl.glDrawArrays(GL.GL_POLYGON, p.pos, p.numverts); } // ========== // PGM } // PGM // ========== } } /* * ================= R_DrawInlineBModel ================= */ void R_DrawInlineBModel() { int i, k; cplane_t pplane; float dot; msurface_t psurf; dlight_t lt; // calculate dynamic lighting for bmodel if (gl_flashblend.value == 0) { for (k = 0; k < r_newrefdef.num_dlights; k++) { lt = r_newrefdef.dlights[k]; R_MarkLights(lt, 1 << k, currentmodel.nodes[currentmodel.firstnode]); } } // psurf = ¤tmodel->surfaces[currentmodel->firstmodelsurface]; int psurfp = currentmodel.firstmodelsurface; msurface_t[] surfaces; surfaces = currentmodel.surfaces; //psurf = surfaces[psurfp]; if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0) { gl.glEnable(GL.GL_BLEND); gl.glColor4f(1, 1, 1, 0.25f); GL_TexEnv(GL.GL_MODULATE); } // // draw texture // for (i = 0; i < currentmodel.nummodelsurfaces; i++) { psurf = surfaces[psurfp++]; // find which side of the node we are on pplane = psurf.plane; dot = Math3D.DotProduct(modelorg, pplane.normal) - pplane.dist; // draw the polygon if (((psurf.flags & Defines.SURF_PLANEBACK) != 0 && (dot < -BACKFACE_EPSILON)) || ((psurf.flags & Defines.SURF_PLANEBACK) == 0 && (dot > BACKFACE_EPSILON))) { if ((psurf.texinfo.flags & (Defines.SURF_TRANS33 | Defines.SURF_TRANS66)) != 0) { // add to the translucent chain psurf.texturechain = r_alpha_surfaces; r_alpha_surfaces = psurf; } else if ((psurf.flags & Defines.SURF_DRAWTURB) == 0) { GL_RenderLightmappedPoly(psurf); } else { GL_EnableMultitexture(false); R_RenderBrushPoly(psurf); GL_EnableMultitexture(true); } } } if ((currententity.flags & Defines.RF_TRANSLUCENT) != 0) { gl.glDisable(GL.GL_BLEND); gl.glColor4f(1, 1, 1, 1); GL_TexEnv(GL.GL_REPLACE); } } /* * ================= R_DrawBrushModel ================= */ void R_DrawBrushModel(entity_t e) { if (currentmodel.nummodelsurfaces == 0) return; currententity = e; gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1; float[] mins = Vec3Cache.get(); float[] maxs = Vec3Cache.get(); boolean rotated; if (e.angles[0] != 0 || e.angles[1] != 0 || e.angles[2] != 0) { rotated = true; for (int i = 0; i < 3; i++) { mins[i] = e.origin[i] - currentmodel.radius; maxs[i] = e.origin[i] + currentmodel.radius; } } else { rotated = false; Math3D.VectorAdd(e.origin, currentmodel.mins, mins); Math3D.VectorAdd(e.origin, currentmodel.maxs, maxs); } if (R_CullBox(mins, maxs)) { Vec3Cache.release(2); // mins, maxs return; } Vec3Cache.release(2); // mins, maxs gl.glColor3f(1, 1, 1); // memset (gl_lms.lightmap_surfaces, 0, // sizeof(gl_lms.lightmap_surfaces)); // TODO wird beim multitexturing nicht gebraucht //gl_lms.clearLightmapSurfaces(); Math3D.VectorSubtract(r_newrefdef.vieworg, e.origin, modelorg); if (rotated) { float[] temp = Vec3Cache.get(); float[] forward = Vec3Cache.get(); float[] right = Vec3Cache.get(); float[] up = Vec3Cache.get(); Math3D.VectorCopy(modelorg, temp); Math3D.AngleVectors(e.angles, forward, right, up); modelorg[0] = Math3D.DotProduct(temp, forward); modelorg[1] = -Math3D.DotProduct(temp, right); modelorg[2] = Math3D.DotProduct(temp, up); Vec3Cache.release(4); // temp, forward, right, up } gl.glPushMatrix(); e.angles[0] = -e.angles[0]; // stupid quake bug e.angles[2] = -e.angles[2]; // stupid quake bug R_RotateForEntity(e); e.angles[0] = -e.angles[0]; // stupid quake bug e.angles[2] = -e.angles[2]; // stupid quake bug GL_EnableMultitexture(true); GL_SelectTexture(GL_TEXTURE0); GL_TexEnv(GL.GL_REPLACE); gl.glInterleavedArrays(GL.GL_T2F_V3F, Polygon.BYTE_STRIDE, globalPolygonInterleavedBuf); GL_SelectTexture(GL_TEXTURE1); GL_TexEnv(GL.GL_MODULATE); gl.glTexCoordPointer(2, GL.GL_FLOAT, Polygon.BYTE_STRIDE, globalPolygonTexCoord1Buf); gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY); R_DrawInlineBModel(); gl.glClientActiveTextureARB(GL_TEXTURE1); gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY); GL_EnableMultitexture(false); gl.glPopMatrix(); } /* * ============================================================= * * WORLD MODEL * * ============================================================= */ /* * ================ R_RecursiveWorldNode ================ */ void R_RecursiveWorldNode(mnode_t node) { int c, side, sidebit; cplane_t plane; msurface_t surf; msurface_t mark; mleaf_t pleaf; float dot = 0; image_t image; if (node.contents == Defines.CONTENTS_SOLID) return; // solid if (node.visframe != r_visframecount) return; if (R_CullBox(node.mins, node.maxs)) return; // if a leaf node, draw stuff if (node.contents != -1) { pleaf = (mleaf_t) node; // check for door connected areas if (r_newrefdef.areabits != null) { if (((r_newrefdef.areabits[pleaf.area >> 3] & 0xFF) & (1 << (pleaf.area & 7))) == 0) return; // not visible } int markp = 0; mark = pleaf.getMarkSurface(markp); // first marked surface c = pleaf.nummarksurfaces; if (c != 0) { do { mark.visframe = r_framecount; mark = pleaf.getMarkSurface(++markp); // next surface } while (--c != 0); } return; } // node is just a decision point, so go down the apropriate sides // find which side of the node we are on plane = node.plane; switch (plane.type) { case Defines.PLANE_X: dot = modelorg[0] - plane.dist; break; case Defines.PLANE_Y: dot = modelorg[1] - plane.dist; break; case Defines.PLANE_Z: dot = modelorg[2] - plane.dist; break; default: dot = Math3D.DotProduct(modelorg, plane.normal) - plane.dist; break; } if (dot >= 0.0f) { side = 0; sidebit = 0; } else { side = 1; sidebit = Defines.SURF_PLANEBACK; } // recurse down the children, front side first R_RecursiveWorldNode(node.children[side]); // draw stuff //for ( c = node.numsurfaces, surf = // r_worldmodel.surfaces[node.firstsurface]; c != 0 ; c--, surf++) for (c = 0; c < node.numsurfaces; c++) { surf = r_worldmodel.surfaces[node.firstsurface + c]; if (surf.visframe != r_framecount) continue; if ((surf.flags & Defines.SURF_PLANEBACK) != sidebit) continue; // wrong side if ((surf.texinfo.flags & Defines.SURF_SKY) != 0) { // just adds to // visible sky // bounds R_AddSkySurface(surf); } else if ((surf.texinfo.flags & (Defines.SURF_TRANS33 | Defines.SURF_TRANS66)) != 0) { // add to the translucent chain surf.texturechain = r_alpha_surfaces; r_alpha_surfaces = surf; } else { if ((surf.flags & Defines.SURF_DRAWTURB) == 0) { GL_RenderLightmappedPoly(surf); } else { // the polygon is visible, so add it to the texture // sorted chain // FIXME: this is a hack for animation image = R_TextureAnimation(surf.texinfo); surf.texturechain = image.texturechain; image.texturechain = surf; } } } // recurse down the back side R_RecursiveWorldNode(node.children[1 - side]); } /* * ============= R_DrawWorld ============= */ private final entity_t worldEnt = new entity_t(); void R_DrawWorld() { if (r_drawworld.value == 0) return; if ((r_newrefdef.rdflags & Defines.RDF_NOWORLDMODEL) != 0) return; currentmodel = r_worldmodel; Math3D.VectorCopy(r_newrefdef.vieworg, modelorg); entity_t ent = worldEnt; // auto cycle the world frame for texture animation ent.clear(); ent.frame = (int) (r_newrefdef.time * 2); currententity = ent; gl_state.currenttextures[0] = gl_state.currenttextures[1] = -1; gl.glColor3f(1, 1, 1); // memset (gl_lms.lightmap_surfaces, 0, // sizeof(gl_lms.lightmap_surfaces)); // TODO wird bei multitexture nicht gebraucht //gl_lms.clearLightmapSurfaces(); R_ClearSkyBox(); GL_EnableMultitexture(true); GL_SelectTexture(GL_TEXTURE0); GL_TexEnv(GL.GL_REPLACE); gl.glInterleavedArrays(GL.GL_T2F_V3F, Polygon.BYTE_STRIDE, globalPolygonInterleavedBuf); GL_SelectTexture(GL_TEXTURE1); gl.glTexCoordPointer(2, GL.GL_FLOAT, Polygon.BYTE_STRIDE, globalPolygonTexCoord1Buf); gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -