patch.h

Go to the documentation of this file.
00001 
00005 /* Copyright, 2000 Nevrax Ltd.
00006  *
00007  * This file is part of NEVRAX NEL.
00008  * NEVRAX NEL is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2, or (at your option)
00011  * any later version.
00012 
00013  * NEVRAX NEL is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * General Public License for more details.
00017 
00018  * You should have received a copy of the GNU General Public License
00019  * along with NEVRAX NEL; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00021  * MA 02111-1307, USA.
00022  */
00023 
00024 #ifndef NL_PATCH_H
00025 #define NL_PATCH_H
00026 
00027 #include "nel/misc/types_nl.h"
00028 #include "nel/misc/vector.h"
00029 #include "nel/misc/vector_2f.h"
00030 #include "nel/misc/rgba.h"
00031 #include "nel/3d/tessellation.h"
00032 #include "nel/misc/aabbox.h"
00033 #include "nel/misc/bsphere.h"
00034 #include "nel/misc/triangle.h"
00035 #include "nel/misc/geom_ext.h"
00036 #include "nel/misc/object_vector.h"
00037 #include "nel/3d/tile_element.h"
00038 #include "nel/3d/tile_color.h"
00039 #include "nel/3d/tess_block.h"
00040 #include "nel/3d/tile_light_influence.h"
00041 #include "nel/3d/point_light_influence.h"
00042 
00043 
00044 namespace NL3D {
00045 
00046 #define NL_MAX_TILES_BY_PATCH_EDGE_SHIFT 4                                      // max 16x16 tiles by patch (shift version)
00047 #define NL_MAX_TILES_BY_PATCH_EDGE (1<<NL_MAX_TILES_BY_PATCH_EDGE_SHIFT)        // max 16x16 tiles by patch
00048 #define NL_PATCH_FAR0_ROTATED 0x1                                               // Flags far0 rotated
00049 #define NL_PATCH_FAR1_ROTATED 0x2                                               // Flags far1 rotated
00050 #define NL_PATCH_SMOOTH_FLAG_SHIFT 0x2                                          // Smooth flags shift
00051 #define NL_PATCH_SMOOTH_FLAG_MASK 0x3c                                          // Smooth flags mask
00052 
00053 #define NL_LUMEL_BY_TILE_SHIFT 2                                                // 4 lumels by tile
00054 #define NL_LUMEL_BY_TILE (1<<NL_LUMEL_BY_TILE_SHIFT)                            // 4 lumels by tile
00055 #define NL_BLOCK_LUMEL_COMPRESSED_SIZE 8                                        // Compressed block size 8 bytes
00056 
00057 
00058 #define NL_PATCH_BLOCK_MAX_QUAD 4                                               // Max quad per CPatchQuadBlock.
00059 #define NL_PATCH_BLOCK_MAX_VERTEX (NL_PATCH_BLOCK_MAX_QUAD+1)                   // Max vertex per CPatchQuadBlock.
00060 
00061 
00062 using NLMISC::CVector;
00063 using NLMISC::CPlane;
00064 using NLMISC::CAABBox;
00065 using NLMISC::CBSphere;
00066 using NLMISC::CRGBA;
00067 
00068 
00069 class   CLandscape;
00070 class   CZone;
00071 class   CBezierPatch;
00072 class   ITexture;
00073 class   CVegetableClipBlock;
00074 class   CVegetableManager;
00075 class   CVegetableInstanceGroup;
00076 class   CLandscapeVegetableBlock;
00077 class   CLandscapeVegetableBlockCreateContext;
00078 class   CPatchDLMContext;
00079 class   CPatchDLMPointLight;
00080 
00081 
00082 // ***************************************************************************
00083 #define NL3D_NOISE_MAX  1
00084 
00085 
00086 // ***************************************************************************
00087 /*
00088     NL3D_PATCH_VEGETABLE_NUM_TESSBLOCK_PER_CLIPBLOCK == 2 means that
00089     clipBlocks enclose 2*2 tessBlocks (hence 4*4 tiles).
00090 */
00091 #define NL3D_PATCH_VEGETABLE_NUM_TESSBLOCK_PER_CLIPBLOCK_SHIFT  1
00092 #define NL3D_PATCH_VEGETABLE_NUM_TESSBLOCK_PER_CLIPBLOCK        (1<<NL3D_PATCH_VEGETABLE_NUM_TESSBLOCK_PER_CLIPBLOCK_SHIFT)
00093 
00094 
00095 // ***************************************************************************
00096 class   CVector3s
00097 {
00098 public:
00099     sint16  x,y,z;
00100 
00101 public:
00102     void    pack(const CVector &v, const CVector &bias, float scale)
00103     {
00104         float   xr,yr,zr;
00105         xr= (v.x - bias.x)/scale;
00106         yr= (v.y - bias.y)/scale;
00107         zr= (v.z - bias.z)/scale;
00108         NLMISC::clamp(xr, -32768, 32767);
00109         NLMISC::clamp(yr, -32768, 32767);
00110         NLMISC::clamp(zr, -32768, 32767);
00111         x= (sint16)xr;
00112         y= (sint16)yr;
00113         z= (sint16)zr;
00114     }
00115     void    unpack(CVector &v, const CVector &bias, float scale) const
00116     {
00117         v.x= x*scale + bias.x;
00118         v.y= y*scale + bias.y;
00119         v.z= z*scale + bias.z;
00120     }
00121     void    serial(NLMISC::IStream &f)
00122     {
00123         f.serial(x,y,z);
00124     }
00125 };
00126 
00127 
00128 // ***************************************************************************
00136 struct  CPatchIdent
00137 {
00138     sint32      ZoneId;     // From which zone this patch come from...
00139     uint16      PatchId;    // Id of this patch.
00140 
00141     // default ctor
00142     CPatchIdent() {}
00143     //
00144     CPatchIdent(sint32 zoneId, uint16 patchId) : ZoneId(zoneId), PatchId(patchId) {}
00145 public:
00146     bool            operator<(const CPatchIdent &p) const
00147     {
00148         if(ZoneId!=p.ZoneId) return ZoneId<p.ZoneId;
00149         return PatchId<p.PatchId;
00150     }
00151 
00152     bool            operator==(const CPatchIdent &p) const
00153     {
00154         return ZoneId==p.ZoneId && PatchId==p.PatchId;
00155     }
00156     bool            operator!=(const CPatchIdent &p) const
00157     {
00158         return !(*this==p);
00159     }
00160 
00161 };
00162 
00163 
00164 // ***************************************************************************
00172 struct  CTrianglePatch : public NLMISC::CTriangleUV
00173 {
00175     CPatchIdent     PatchId;
00176 };
00177 
00178 
00179 // ***************************************************************************
00187 class   CPatchBlockIdent
00188 {
00189 public:
00191     CPatchIdent     PatchId;
00193     uint8           OrderS,OrderT;
00195     uint8           S0,S1,T0,T1;
00196 
00197 public:
00199     // @{
00200     bool            operator==(const CPatchBlockIdent &pb) const
00201     {
00202         return PatchId==pb.PatchId &&
00203             S0==pb.S0 && S1==pb.S1 &&
00204             T0==pb.T0 && T1==pb.T1;
00205     }
00206     bool            operator!=(const CPatchBlockIdent &pb) const
00207     {
00208         return !(*this==pb);
00209     }
00210 
00211     bool            operator<(const CPatchBlockIdent &pb) const
00212     {
00213         if(PatchId!=pb.PatchId)
00214             return PatchId<pb.PatchId;
00215         if(S0!=pb.S0)   return S0<pb.S0;
00216         if(S1!=pb.S1)   return S1<pb.S1;
00217         if(T0!=pb.T0)   return T0<pb.T0;
00218         return T1<pb.T1;
00219     }
00220     bool            operator<=(const CPatchBlockIdent &pb) const
00221     {
00222         return (*this<pb) || (*this==pb);
00223     }
00224     bool            operator>(const CPatchBlockIdent &pb) const
00225     {
00226         return !(*this<=pb);
00227     }
00228     bool            operator>=(const CPatchBlockIdent &pb) const
00229     {
00230         return !(*this<pb);
00231     }
00232 
00233     // @}
00234 };
00235 
00236 
00237 // ***************************************************************************
00245 class   CPatchQuadBlock
00246 {
00247 public:
00249     CPatchBlockIdent    PatchBlockId;
00250 
00252     CVector             Vertices[NL_PATCH_BLOCK_MAX_VERTEX*NL_PATCH_BLOCK_MAX_VERTEX];
00253 
00254 public:
00255 
00259     void        buildTileTriangles(uint8 quadId, CTrianglePatch  triangles[2]) const;
00260 };
00261 
00262 
00263 
00264 // ***************************************************************************
00296 class CPatch
00297 {
00298 public:
00299 
00300     struct  CBindInfo
00301     {
00302         // The zone on this edge. NULL if not loaded (or if none).
00303         CZone           *Zone;
00304 
00305         // The number of patchs on this edge. 0,1, 2 or 4. if MultipleBindNum>1, NPatchs==1.
00306         sint            NPatchs;
00307 
00308         // Special case: on this edge, we are a small patch connected to a bigger: this is the X of 1/X (1,2 or 4).
00309         // 0 if this is not the case.
00310         uint8           MultipleBindNum;
00311         // valid only if MultipleBindNum>1. this tells our place in this MultipleBind: 0<=MultipleBindId<MultipleBindNum.
00312         uint8           MultipleBindId;
00313 
00314 
00315         CPatch          *Next[4];   // The neighbor patch i.
00316         sint            Edge[4];    // On which edge of Nexti we are binded.
00317     };
00318 
00319 public:
00321     CVector3s       Vertices[4];
00322     CVector3s       Tangents[8];
00323     CVector3s       Interiors[4];
00324 
00325     // Lumel array compressed.
00326     std::vector<uint8>          CompressedLumels;
00327 
00328     // There is OrderS*OrderT tiles. CZone build it at build() time.
00329     std::vector<CTileElement>   Tiles;
00330 
00331     // There is OrderS*OrderT tiles color. CZone build it at build() time.
00332     std::vector<CTileColor>     TileColors;
00333 
00334     // There is OrderS/2+1 * OrderT/2+1 tiles light influence. CZone build it at build() time.
00335     std::vector<CTileLightInfluence>        TileLightInfluences;
00336 
00337 
00339     // @{
00341     uint8           NoiseRotation;
00342 
00346     void            setCornerSmoothFlag(uint corner, bool smooth);
00347     bool            getCornerSmoothFlag(uint corner) const;
00348 
00349 private:
00351     uint8           _CornerSmoothFlag;
00352 
00353 public:
00354     // @}
00355 
00356 
00357 public:
00358 
00360     CPatch();
00362     ~CPatch();
00363 
00373     void            compile(CZone *z, uint patchId, uint8 orderS, uint8 orderT, CTessVertex *baseVertices[4], float errorSize=0);
00375     void            release();
00376 
00377 
00379     CLandscape      *getLandscape () const;
00380     CZone           *getZone() const {return Zone;}
00381     uint8           getOrderS() const {return OrderS;}
00382     uint8           getOrderT() const {return OrderT;}
00383     uint8           getOrderForEdge(sint8 edge) const;
00384     float           getErrorSize() const {return ErrorSize;}
00385     sint            getFar0() const {return Far0;}
00386     sint            getFar1() const {return Far1;}
00387     uint16          getPatchId () const {return PatchId;}
00389     void            getBindNeighbor(uint edge, CBindInfo &neighborEdge) const;
00390 
00392     CAABBox         buildBBox() const;
00393 
00401     CVector         computeVertex(float s, float t) const;
00402 
00403 
00411     CVector         computeContinousVertex(float s, float t) const;
00412 
00413 
00416     void            unbind();
00417 
00422     void            bind(CBindInfo  Edges[4], bool rebind);
00423 
00425     void            forceMergeAtTileLevel();
00426 
00429     void            averageTesselationVertices();
00430 
00432     void            refineAll();
00433 
00434 
00436 
00437 
00439     void            preRender(const NLMISC::CBSphere &patchSphere);
00440     // like preRender(), but update TextureFar only. (you should call preRender() in this case).
00441     void            updateTextureFarOnly(const NLMISC::CBSphere &patchSphere);
00443     // Global Setup setup it in CLandscape::render().
00444     void            renderFar0();
00445     void            renderFar1();
00446     // NB: renderTile() is now in CTileMaterial.
00447     // For All Far0/Far1/Tile etc..., compute Geomorph and Alpha in software (no VertexShader).
00448     void            computeSoftwareGeomorphAndAlpha();
00449 
00450     // update VB according to new clip state.
00451     void            updateClipPatchVB(bool renderClipped);
00452 
00453     // get the next patch to render in the same RenderPass for Far0.
00454     CPatch          *getNextFar0ToRdr() const {return _NextRdrFar0;}
00455     // get the next patch to render in the same RenderPass for Far1.
00456     CPatch          *getNextFar1ToRdr() const {return _NextRdrFar1;}
00457 
00459 
00460 
00461     // release Far render pass/reset Tile/Far render.
00462     void            resetRenderFar();
00463 
00464 
00465 
00466     // For CZone changePatchTexture only.
00467     void            deleteTileUvs();
00468     void            recreateTileUvs();
00469     // For CZone::refreshTesselationGeometry() only.
00470     void            refreshTesselationGeometry();
00471 
00472 
00473     // Serial just the un-compiled part.
00474     void            serial(NLMISC::IStream &f);
00475 
00476     // unpack the patch into a floating point one.
00477     void            unpack(CBezierPatch &p) const;
00478 
00480 
00490     void            unpackShadowMap (uint8 *pShadow);
00491 
00500     void            packShadowMap (const uint8 *pLumel);
00501 
00507     void            resetCompressedLumels ();
00508 
00517     void setupColorsFromTileFlags(const NLMISC::CRGBA colors[4]);
00518 
00522     void copyTileFlagsFromPatch(const CPatch *src);
00523 
00524     // Count the number of tri needed to draw the patch
00525     uint32 countNumTriFar0() const;
00526     uint32 countNumTriFar1() const;
00527 
00528 private:
00529 
00530     // Methods used internaly to compute shadowmaps
00531 
00537     void            packLumelBlock (uint8 *dest, const uint8 *source, uint8 alpha0, uint8 alpha1);
00538 
00544     uint            evalLumelBlock (const uint8 *original, const uint8 *unCompressed, uint width, uint height);
00545 
00551     void            unpackLumelBlock (uint8 *dest, const uint8 *src);
00552 
00553 public:
00554 
00556 
00560     void setSmoothFlag (uint edge, bool flag)
00561     {
00562         // Erase it
00563         Flags&=~(1<<(edge+NL_PATCH_SMOOTH_FLAG_SHIFT));
00564 
00565         // Set it
00566         Flags|=(((uint)flag)<<(edge+NL_PATCH_SMOOTH_FLAG_SHIFT));
00567     }
00568 
00572     bool getSmoothFlag (uint edge) const
00573     {
00574         // Test it
00575         return ((Flags&(1<<(edge+NL_PATCH_SMOOTH_FLAG_SHIFT)))!=0);
00576     }
00577 
00578 
00580     // @{
00588     void        addTrianglesInBBox(CPatchIdent paId, const CAABBox &bbox, std::vector<CTrianglePatch> &triangles, uint8 tileTessLevel) const;
00589 
00593     void        fillPatchQuadBlock(CPatchQuadBlock &quadBlock) const;
00594 
00601     void        addPatchBlocksInBBox(CPatchIdent paId, const CAABBox &bbox, std::vector<CPatchBlockIdent> &paBlockIds) const;
00602 
00603 
00606     CVector     getTesselatedPos(CUV uv) const;
00607 
00608 
00611     void        appendTessellationLeaves(std::vector<const CTessFace*>  &leaves) const;
00612 
00613 
00614     // @}
00615 
00616 
00618     // @{
00619 
00621     uint8       getLumel(const CUV &uv) const;
00622 
00626     void        appendTileLightInfluences(const CUV &uv,
00627         std::vector<CPointLightInfluence> &pointLightList) const;
00628 
00632     void        computeCurrentTLILightmapDiv2(NLMISC::CRGBA *array) const;
00633 
00634     // @}
00635 
00636 
00638     // @{
00639 
00641     CTileElement    *getTileElement(const CUV &uv);
00642 
00643     // @}
00644 
00645 public:
00646 
00647     // Is the patch clipped? true if not yte compiled
00648     bool            isRenderClipped() const;
00649 
00650 
00651     // get the according vertex for a corner. use wisely
00652     const CTessVertex   *getCornerVertex(uint corner)
00653     {
00654         return BaseVertices[corner];
00655     }
00656 
00657 
00658 public:
00659 
00661     // @{
00662 
00663     // delete all VB allocated in VertexBuffers, according to Far0 and Far1. Do not Test isRenderClipped() state.
00664     // With VB, allocate to he faces array.
00665     void        deleteVBAndFaceVector();
00666 
00667     // allocate all VB, according to Far0 and Far1. Do not Test isRenderClipped() state.
00668     // With VB, allocate to he faces array.
00669     void        allocateVBAndFaceVector();
00670 
00671     // fill all VB, according to Far0, Far1 and CTessFace VBInfos. Do not Test isRenderClipped() state.
00672     // Do not fill a VB if reallocationOccurs().
00673     void        fillVB();
00674 
00675     // if isRenderClipped()==false, fillVB().
00676     void        fillVBIfVisible();
00677 
00678     // delete Far1 VB allocated in VertexBuffers. do it only if Far1==true. Do not Test isRenderClipped() state.
00679     // With VB, allocate to he faces array.
00680     void        deleteVBAndFaceVectorFar1Only();
00681 
00682     // allocate Far1 VB, . do it only if Far1==true. Do not Test isRenderClipped() state.
00683     // With VB, allocate to he faces array.
00684     void        allocateVBAndFaceVectorFar1Only();
00685 
00686     // fill Far0 VB according CTessFace VBInfos and Far0 (do not fill if !Far0). Do not Test isRenderClipped() state.
00687     // Do not fill a VB if reallocationOccurs().
00688     void        fillVBFar0Only();
00689     // same for Far1
00690     void        fillVBFar1Only();
00691 
00692 
00693     // fill DLM Uv (ie UV1) for Far0 and Far1 VB only. NB: do not fill Far0 if !Far0 (idem fro Far1).
00694     // Do not Test isRenderClipped() state. Do not fill a VB if reallocationOccurs().
00695     void        fillVBFarsDLMUvOnly();
00696     void        fillFar0DLMUvOnlyVertexListVB(CTessList<CTessFarVertex>  &vertList);
00697     void        fillFar1DLMUvOnlyVertexListVB(CTessList<CTessFarVertex>  &vertList);
00698 
00699 
00700     // For Debug only.
00701     void        debugAllocationMarkIndices(uint marker);
00702 
00703 
00704     // Because of refine... tessBlock FaceVector may have been deleted, this method do nothing if isRenderClipped().
00705     // If not, recreate FaceVector for this tessBlock only, according to Far0 and Far1.
00706     void        recreateTessBlockFaceVector(CTessBlock &block);
00707 
00708 
00709     // @}
00710 
00711 
00712 public:
00713 
00715     // @{
00716 
00718     void        deleteAllVegetableIgs();
00719 
00721     void        recreateAllVegetableIgs();
00722 
00723     // @}
00724 
00725 
00727     // @{
00731     void        resetTileLightInfluences();
00732     // @}
00733 
00734 
00736     // @{
00737 
00739     void        linkBeforeNearUL(CPatch *patchNext);
00741     void        unlinkNearUL();
00743     CPatch      *getNextNearUL() const {return _ULNearNext;}
00744 
00746     uint        getNumNearTessBlocks() const {return TessBlocks.size();}
00747 
00754     uint        updateTessBlockLighting(uint numTb);
00755 
00756     // @}
00757 
00758 
00760     // @{
00761 
00766     void        beginDLMLighting();
00770     void        processDLMLight(CPatchDLMPointLight &pl);
00775     void        endDLMLighting();
00776 
00777     // @}
00778 
00779 
00781     uint        getTileMaterialRefCount() const {return MasterBlock.TileMaterialRefCount;}
00782 
00783 // Private part.
00784 private:
00785 /*********************************/
00786 
00787     friend  class CTessFace;
00788     friend  class CZone;
00789     friend  class CLandscapeVegetableBlock;
00790     friend  class CPatchRdrPass;
00791 
00792     CZone           *Zone;
00793 
00794     // Number of this patch in the zone. valid at compile Time.
00795     uint16          PatchId;
00796     // Tile Order for the patch.
00797     uint8           OrderS, OrderT;
00798 
00799     // This is especially for Pacs. false by default, and used by CZone::refineAll() and CZone::excludePatchFromRefineAll().
00800     bool            ExcludeFromRefineAll;
00801 
00802     // For this patch, which level is required for a face to be inserted in the secondary TessBlocks (and not the masterblock)??
00803     sint            TessBlockLimitLevel;
00804     // For this patch, which level is required for a face to be a valid Tile??
00805     sint            TileLimitLevel;
00806     // For this patch, which level is required for a face to be a "square" face (not rectangular)??
00807     sint            SquareLimitLevel;
00808     // The Base Size*bumpiness of the patch (/2 at each subdivide).
00809     float           ErrorSize;
00810     // The root for tesselation.
00811     CTessFace       *Son0, *Son1;
00812     // The base vertices.
00813     CTessVertex     *BaseVertices[4];
00814     // The base Far vertices (always here!!).
00815     CTessFarVertex  BaseFarVertices[4];
00816 
00817 
00818     // Local info for CTessFace tiles. CPatch must setup them at the begining at refine()/render().
00819     // For Far Texture coordinates.
00820     float           Far0UScale, Far0VScale, Far0UBias, Far0VBias;
00821     float           Far1UScale, Far1VScale, Far1UBias, Far1VBias;
00822 
00833     uint8           Flags;
00834 
00835 
00836     // Info for alpha transition with Far1.
00837     float           TransitionSqrMin;
00838     float           OOTransitionSqrDelta;
00839 
00840     /*
00841         Cache Optim Note:
00842         NB: for faster Cache Access during preRender(), you must leave those variables packed like this
00843 
00844         Far0
00845         Far1
00846         _PatchRdrPassFar0
00847         _NextRdrFar0
00848         _PatchRdrPassFar1
00849         _NextRdrFar1
00850         NumRenderableFaces
00851         TessBlocks (for size() )
00852         MasterBlock.Far0FaceVector
00853         MasterBlock.Far1FaceVector
00854 
00855         NB: Far0FaceVector and Far1FaceVector are accessed during renderFar*() (not preRender()) but they must be near
00856         to TessBlocks (for size() )
00857     */
00858 
00859     // Current Far Level computed in preRender()
00860     sint            Far0;           // The level of First Far: 0,1,2 or 3. 0 means Tile.
00861     sint            Far1;           // The level of second Far, for transition: 1,2 or 3. 0 means none.
00862 
00863     // The render Pass of Far0 and Far1.
00864     CPatchRdrPass   *_PatchRdrPassFar0;
00865     CPatch          *_NextRdrFar0;
00866     CPatchRdrPass   *_PatchRdrPassFar1;
00867     CPatch          *_NextRdrFar1;
00868 
00870     // @{
00871     // Tells how many Renderable Face this Patch has. updated in append/remove/FaceToRenderList()
00872     sint                        NumRenderableFaces;
00873     // The 2*2 block render. For memory optimisation, none is allocated when no faces need it.
00874     // There is (OrderT/2)*(OrderS/2) TessBlocks.
00875     NLMISC::CObjectVector<CTessBlock>   TessBlocks;
00876     // The block render of far only. Only Far faces bigger than a block are inserted here.
00877 public: // tmp
00878     CTessBlock                  MasterBlock;
00879 private:
00880     // The counter of faces which need TessBlocks (FarFaces, TileMaterial and FarVertices). When 0, the vector is contReset()-ed.
00881     sint                        TessBlockRefCount;
00882     // @}
00883 
00884 
00886     // @{
00888     std::vector<CVegetableClipBlock*>   VegetableClipBlocks;
00889     // @}
00890 
00891 
00895     static uint32   _Version;
00896 
00897 private:
00898     // Guess.
00899     void            computeDefaultErrorSize();
00900     // based on BaseVertices, recompute positions, and Make Face roots Son0 and Son1.
00901     void            makeRoots();
00902     // Guess. For bind() reasons.
00903     CTessFace       *getRootFaceForEdge(sint edge) const;
00904     // Guess. For bind() reasons. return the vertex 0 of edge.
00905     CTessVertex     *getRootVertexForEdge(sint edge) const;
00906     void            changeEdgeNeighbor(sint edge, CTessFace *to);
00907 
00908 
00910     // @{
00911 
00912     // reset all list of MasterBlock.
00913     void            resetMasterBlock();
00914     // simply clear the tessnbloc array and reset cout to 0.
00915     void            clearTessBlocks();
00916     // add a ref to tess blocks, allocate them if necessary.
00917     void            addRefTessBlocks();
00918     // dec a ref to tess blocks, destroy them if necessary.
00919     void            decRefTessBlocks();
00920     // UGLY SIDE EFFECT: when refcount TessBlocks RefCount reach 0, tessblockas are deleted. think of it in tesselation.cpp.
00921 
00922 
00923     // Retrieve the tessblockId, depending on face info.
00924     uint            getNumTessBlock(CTessFace *face);
00925     // FarVertType.
00926     enum            TFarVertType {FVMasterBlock=0, FVTessBlock, FVTessBlockEdge};
00927     // Retrieve the tessblockId, depending on a ParamCoord.
00928     void            getNumTessBlock(CParamCoord pc, TFarVertType &type, uint &numtb);
00929 
00930 
00931     // If pathc is visible, force deletion of this TessBlock.
00932     void            dirtTessBlockFaceVector(CTessBlock &block);
00933 
00934 
00935     // For rdr. Insert in the GOOD TessBlock the face (depending on level, patchcoordinates etc...)
00936     // call appendFaceToTileRenderList() to insert his TileFaces into the good renderList.
00937     void            appendFaceToRenderList(CTessFace *face);
00938     // Remove a face and his tileface from the patch renderlist.
00939     // call removeFaceFromTileRenderList() to insert his TileFaces into the good renderList.
00940     void            removeFaceFromRenderList(CTessFace *face);
00941     // for changePatchTexture, insert just the TileFace into the good render List.
00942     void            appendFaceToTileRenderList(CTessFace *face);
00943     void            removeFaceFromTileRenderList(CTessFace *face);
00944     // For refreshTesselationGeometry() only. enlarge the TessBlock (if any) with face->V*->EndPos.
00945     void            extendTessBlockWithEndPos(CTessFace *face);
00946 
00947     // Set/Unset (to NULL) a TileMaterial from the TessBlocks. Material must exist for both functions.
00948     // And TileS/TileT must be OK.
00949     void            appendTileMaterialToRenderList(CTileMaterial *tm);
00950     void            removeTileMaterialFromRenderList(CTileMaterial *tm);
00951 
00952     // Add/Remove FarVertices. Use fv->PCoord to know where.
00953     void            appendFarVertexToRenderList(CTessFarVertex *fv);
00954     void            removeFarVertexFromRenderList(CTessFarVertex *fv);
00955     // Add/Remove NearVertices. Use tileMat to know where.
00956     void            appendNearVertexToRenderList(CTileMaterial *tileMat, CTessNearVertex *nv);
00957     void            removeNearVertexFromRenderList(CTileMaterial *tileMat, CTessNearVertex *nv);
00958 
00959     // @}
00960 
00961 
00962 
00964     // @{
00965     // For CTessFace::computeMaterial(). Return the render pass for this material, given the number of the tile, and the
00966     // desired pass. NULL may be returned if the pass is not present (eg: no additive for this tile...).
00967     CPatchRdrPass   *getTileRenderPass(sint tileId, sint pass);
00968     // For CTessFace::computeMaterial(). Return the orient/scalebias for the tile in the patchtexture, and the
00969     // desired pass (and the desired stage: RGB/Alpha).
00970     void            getTileUvInfo(sint tileId, sint pass, bool alpha, uint8 &orient, CVector &uvScaleBias, bool &is256x256, uint8 &uvOff);
00971     // @}
00972 
00973     // Tile LightMap mgt.
00974     // @{
00975     // for a given tile (accessed from the (ts,tt) coordinates), compute a lightmap if necessary, and get a RenderPass.
00976     void        getTileLightMap(uint ts, uint tt, CPatchRdrPass *&rdrpass);
00977     // get uvInfo for tile. NB: ts,tt form because simpler.
00978     void        getTileLightMapUvInfo(uint ts, uint tt, CVector &uvScaleBias);
00979     // release the tile lightmap. NB: ts,tt form because simpler.
00980     void        releaseTileLightMap(uint ts, uint tt);
00981 
00982     // Compute the Lightmap for 2x2 tiles. => 10x10 pixels. ts, tt is in [0,OrderS], [0, OrderT].
00983     void        computeNearBlockLightmap(uint ts, uint tt, NLMISC::CRGBA    *lightText);
00984     void        computeTileLightmapPixelAroundCorner(const NLMISC::CVector2f &stIn, NLMISC::CRGBA *dest, bool lookAround);
00985 
00986     // Compute a lightmap for a tile (ts,tt). 4x4 lumels are processed. NB: result= lumel*userColor.
00987     void        computeTileLightmap(uint ts, uint tt, NLMISC::CRGBA *dest, uint stride);
00988     // Compute a lightmap for an edge of a tile. 1x4 lumels. "edge" say what edge of the tile to compute.
00989     // pixels will be written in (dest+i*stride), where i vary from 0 to 3 or 3 to 0 (according to "inverse").
00990     void        computeTileLightmapEdge(uint ts, uint tt, uint edge, NLMISC::CRGBA *dest, uint stride, bool inverse);
00991     // Compute a lightmap just for a pixel (s,t) of a tile (ts,tt). (s,t) E [0;3], [0;3].
00992     void        computeTileLightmapPixel(uint ts, uint tt, uint s, uint t, NLMISC::CRGBA *dest);
00993 
00994 
00995     // Methods for automatic Lighting. NB: result= lumel only (no TileColors).
00996     void        computeTileLightmapAutomatic(uint ts, uint tt, NLMISC::CRGBA *dest, uint stride);
00997     void        computeTileLightmapEdgeAutomatic(uint ts, uint tt, uint edge, NLMISC::CRGBA *dest, uint stride, bool inverse);
00998     void        computeTileLightmapPixelAutomatic(uint ts, uint tt, uint s, uint t, NLMISC::CRGBA *dest);
00999     // Methods for Precomputed Lighting. NB: result= lumel only (no TileColors).
01000     void        computeTileLightmapPrecomputed(uint ts, uint tt, NLMISC::CRGBA *dest, uint stride);
01001     void        computeTileLightmapEdgePrecomputed(uint ts, uint tt, uint edge, NLMISC::CRGBA *dest, uint stride, bool inverse);
01002     void        computeTileLightmapPixelPrecomputed(uint ts, uint tt, uint s, uint t, NLMISC::CRGBA *dest);
01003     // Methods to modulate dest with TileColors. NB: A unmodified.
01004     void        modulateTileLightmapWithTileColors(uint ts, uint tt, NLMISC::CRGBA *dest, uint stride);
01005     void        modulateTileLightmapEdgeWithTileColors(uint ts, uint tt, uint edge, NLMISC::CRGBA *dest, uint stride, bool inverse);
01006     void        modulateTileLightmapPixelWithTileColors(uint ts, uint tt, uint s, uint t, NLMISC::CRGBA *dest);
01007     // get the tileColors at the corners of the tile. corner order: 0,0; 1,0; 0,1; 1,1. NB: A undefined.
01008     void        getTileTileColors(uint ts, uint tt, NLMISC::CRGBA corners[4]);
01009 
01010 
01011     // get the current TLIColor given a TLI coordinate (in (0..OrderS/2+1, 0..OrderT/2+1) )
01012     // NB: returned color is modulated by landscape material and precomputed diffuse factor
01013     CRGBA       getCurrentTLIColor(uint x, uint y) const;
01014     // get the current TLIColors at the corners of the tile (according to pointLights current colors)
01015     // corner order: 0,0; 1,0; 0,1; 1,1. NB: A undefined.
01016     void        getCurrentTileTLIColors(uint ts, uint tt, NLMISC::CRGBA corners[4]);
01017     // Methods to add dest with result of TLI lighting. NB: A unmodified.
01018     void        addTileLightmapWithTLI(uint ts, uint tt, NLMISC::CRGBA *dest, uint stride);
01019     void        addTileLightmapEdgeWithTLI(uint ts, uint tt, uint edge, NLMISC::CRGBA *dest, uint stride, bool inverse);
01020     void        addTileLightmapPixelWithTLI(uint ts, uint tt, uint s, uint t, NLMISC::CRGBA *dest);
01021 
01022     // @}
01023 
01024 
01025     // Recompute of new Far Values, according to globals. Don't erase Far0 and Far1.
01026     void        computeNewFar(const NLMISC::CBSphere &patchSphere, sint &newFar0, sint &newFar1);
01027 
01028 
01029     // For Render. Those methods compute the vertices for Driver (in CTessFace::Current*VB).
01030     void        fillFar0VertexVB(CTessFarVertex *pVert);
01031     void        fillFar1VertexVB(CTessFarVertex *pVert);
01032     void        fillTileVertexVB(CTessNearVertex *pVert);
01033     void        fillFar0VertexListVB(CTessList<CTessFarVertex>  &vertList);
01034     void        fillFar1VertexListVB(CTessList<CTessFarVertex>  &vertList);
01035     void        fillTileVertexListVB(CTessList<CTessNearVertex> &vertList);
01036     // For Render. Those methods allocate/delete vertices in VB.
01037     void        updateFar0VBAlloc(CTessList<CTessFarVertex>  &vertList, bool alloc);
01038     void        updateFar1VBAlloc(CTessList<CTessFarVertex>  &vertList, bool alloc);
01039     void        updateTileVBAlloc(CTessList<CTessNearVertex>  &vertList, bool alloc);
01040     void        updateVBAlloc(bool alloc);
01041     // For Debug Allcoation only.
01042     void        debugAllocationMarkIndicesFarList(CTessList<CTessFarVertex>  &vertList, uint marker);
01043     void        debugAllocationMarkIndicesNearList(CTessList<CTessNearVertex>  &vertList, uint marker);
01044     // For Render. Allocate / Fill FaceVector, according to Far0/Far1.
01045     void        createFaceVectorFar1();
01046     void        deleteFaceVectorFar1();
01047     void        createFaceVectorFar0OrTile();
01048     void        deleteFaceVectorFar0OrTile();
01049 
01050 
01051 
01052     // For Refine. Those methods do all the good job, and test if they can allocate the VB.
01053     void        checkCreateVertexVBFar(CTessFarVertex *pVert);
01054     void        checkCreateVertexVBNear(CTessNearVertex *pVert);
01055     // For Refine. Those methods do all the good job, and test if they can fill the VB.
01056     void        checkFillVertexVBFar(CTessFarVertex *pVert);
01057     void        checkFillVertexVBNear(CTessNearVertex   *pVert);
01058     // For Refine. Those methods do all the good job, and test if they have to delete the VB.
01059     void        checkDeleteVertexVBFar(CTessFarVertex *pVert);
01060     void        checkDeleteVertexVBNear(CTessNearVertex *pVert);
01061 
01062     // For Render, geomorph / Alpha in software.
01063     void        computeGeomorphVertexList(CTessList<CTessFarVertex>  &vertList);
01064     void        computeGeomorphFar0VertexListVB(CTessList<CTessFarVertex>  &vertList);
01065     void        computeGeomorphAlphaFar1VertexListVB(CTessList<CTessFarVertex>  &vertList);
01066     void        computeGeomorphTileVertexListVB(CTessList<CTessNearVertex>  &vertList);
01067 
01069     // @{
01071     void        buildBBoxFromBezierPatch(const CBezierPatch &p, CAABBox &ret) const;
01077     void        addTrianglesInBBoxRecurs(CPatchIdent paId, const CAABBox &bbox, std::vector<CTrianglePatch> &triangles, uint8 tessLevel,
01078         const CBezierPatch &pa, uint8 s0, uint8 s1, uint8 t0, uint8 t1) const;
01083     void        addTileTrianglesInBBox(CPatchIdent paId, const CAABBox &bbox, std::vector<CTrianglePatch> &triangles, uint8 tessLevel,
01084         uint8 s0, uint8 t0) const;
01085 
01088     void        addPatchBlocksInBBoxRecurs(CPatchIdent paId, const CAABBox &bbox, std::vector<CPatchBlockIdent> &paBlockIds,
01089         const CBezierPatch &pa, uint8 s0, uint8 s1, uint8 t0, uint8 t1) const;
01090 
01092     CVector     computeVertexButCorner(float s, float t, bool &onCorner) const;
01093 
01094     // @}
01095 
01096 
01097 private:
01098 
01099 
01100 
01102     // @{
01103 
01105     CZone       *_BindZoneNeighbor[4];
01106 
01110     CTessFace   *linkTessFaceWithEdge(const NLMISC::CVector2f &uv0, const NLMISC::CVector2f &uv1, CTessFace *linkTo);
01111 
01112     // @}
01113 
01114 
01115 
01117     // @{
01118 
01119 
01120     float       computeDisplaceRawInteger(sint ts, sint tt, sint ms, sint mt) const;
01121     void        computeDisplaceRawCoordinates(float sTile, float tTile, float s, float t,
01122     sint &ts, sint &tt, sint &ms, sint &mt) const;
01128     float       computeDisplaceRaw(float sTile, float tTile, float s, float t) const;
01132     float       computeDisplaceRawOnNeighbor(float sTile, float tTile, float s, float t) const;
01133 
01134 
01137     float       computeDisplaceInteriorSmooth(float s, float t) const;
01140     float       computeDisplaceEdgeSmooth(float s, float t, sint8 smoothBorderX, sint8 smoothBorderY) const;
01143     float       computeDisplaceCornerSmooth(float s, float t, sint8 smoothBorderX, sint8 smoothBorderY) const;
01144 
01145 
01148     CVector     computeNormalEdgeSmooth(float s, float t, sint8 smoothBorderX, sint8 smoothBorderY) const;
01151     CVector     computeNormalCornerSmooth(float s, float t, sint8 smoothBorderX, sint8 smoothBorderY) const;
01154     CVector     computeNormalOnNeighbor(float s, float t, uint edgeExclude) const;
01155 
01156 
01160     void        computeNoise(float s, float t, CVector &displace) const;
01161 
01162     // @}
01163 
01164 
01165     // From tile coordinates, return the tessBlockId, and the id of the material in this tessBlock.
01166     void        computeTbTm(uint &numtb, uint &numtm, uint ts, uint tt);
01167 
01168 
01170     // @{
01171 
01173     void        createVegetableBlock(uint numTb, uint ts, uint tt);
01175     void        releaseVegetableBlock(uint numTb);
01176 
01177     /*
01178         generate the vegetables for a given tile in the vegetable manager.
01179         instances are added to vegetIg.
01180         Warning! Use OptFastFloor()! So call must be enclosed with a OptFastFloorBegin()/OptFastFloorEnd().
01181     */
01182     void        generateTileVegetable(CVegetableInstanceGroup *vegetIg, uint distType, uint ts, uint tt,
01183         CLandscapeVegetableBlockCreateContext &vbCreateCtx);
01184 
01185     // same as computeTileLightmapPrecomputed(), but brut result, not modified by colorTable.
01186     void        getTileLumelmapPrecomputed(uint ts, uint tt, uint8 *dest, uint stride);
01190     void        getTileLumelmapPixelPrecomputed(uint ts, uint tt, uint s, uint t, uint8 &dest) const;
01191 
01192     // @}
01193 
01194 
01196     // @{
01197     CPatch      *_ULNearPrec;
01198     CPatch      *_ULNearNext;
01199     // @}
01200 
01201 
01203     // @{
01204 
01209     CPatchDLMContext    *_DLMContext;
01210 
01214     sint                _DLMContextRefCount;
01215 
01217     void                addRefDLMContext();
01219     void                decRefDLMContext(uint count= 1);
01220 
01221     // @}
01222 
01223 
01224 private:
01225     // NB: All global render info are stored in CTessFace class static members....
01226 
01227     // The Patch cache (may be a short list/vector later...).
01228     static  CBezierPatch    CachePatch;
01229     // For cahcing.
01230     static  const CPatch    *LastPatch;
01231 
01232 public:
01233     // unpack the patch into the cache.
01234     CBezierPatch    *unpackIntoCache() const;
01235 
01236 };
01237 
01238 
01239 
01240 } // NL3D
01241 
01242 
01243 #endif // NL_PATCH_H
01244 
01245 /* End of patch.h */

Generated on Thu Jan 7 08:26:19 2010 for NeL by  doxygen 1.6.1