ihardwareshader.h

Go to the documentation of this file.
00001 /**********************************************************************
00002  *<
00003     FILE: IHardwareShader.h
00004 
00005     DESCRIPTION: Hardware Shader Extension Interface class
00006 
00007     CREATED BY: Norbert Jeske
00008 
00009     HISTORY:
00010 
00011  *> Copyright (c) 2000 - 2002, All Rights Reserved.
00012  **********************************************************************/
00013 #pragma once
00014 
00015 #include "maxheap.h"
00016 #include "maxtypes.h"
00017 #include "TabTypes.h"
00018 #include "GraphicsConstants.h"
00019 #include "GraphicsTypes.h"
00020 #include "baseinterface.h"
00021 
00022 // forward declarations
00023 class Mesh;
00024 class MNMesh;
00025 class GWFace;
00026 class Point3;
00027 class Material;
00028 class BitArray;
00029 class INode;
00030 
00031 #define HARDWARE_SHADER_INTERFACE_ID Interface_ID(0x7bbd585b, 0x75bb641c)
00032 
00033 #define GFX_MAX_COLORS 2
00034 
00035 // Use of the following four classes, TriStrip, MeshData, WireMeshData, and
00036 // MeshFaceData, has been added in 3ds max 4.2.  These classes were updated
00037 // from their original (unused) definitions and use of the IHardwareShader
00038 // class member functions that use these data classes was added in 3ds max 4.2.
00039 // If your plugin utilizes these new mechanisms, be sure that your clients are
00040 // aware that they must run your plugin with 3ds max version 4.2 or higher.
00041 //
00042 // For documentation on the use of these data classes, see the code of the
00043 // HardwareShader plugin samples or contact Discreet.
00044 
00045 class TriStrip: public MaxHeapOperators {
00046 public:
00047     DWORD   rndMode;
00048     MtlID   mID;
00049     MtlID   maxID;
00050     DWORD   smGrp;
00051     int     clrMode;
00052     int     texMode;
00053     DWTab   v;
00054     DWTab   n;
00055     DWTab   c[GFX_MAX_COLORS];
00056     DWTab   tv[GFX_MAX_TEXTURES];
00057 
00058     void AddVertN(DWORD vtx, DWORD nor) { v.Append(1, &vtx, (v.Count()>>1)); n.Append(1, &nor, n.Count()/2); }
00059     void AddVertNC1(DWORD vtx, DWORD nor, DWORD col) { v.Append(1, &vtx, (v.Count()>>1)); n.Append(1, &nor, n.Count()/2); c[0].Append(1, &col, c[0].Count()/2); }
00060 
00061     void AddVertNT1(DWORD vtx, DWORD nor, DWORD tvtx) {
00062         int alloc = (v.Count()>>1)+1;
00063         v.Append(1, &vtx, alloc); n.Append(1, &nor, alloc);
00064         tv[0].Append(1, &tvtx, alloc);
00065     }
00066     void AddVertNC1T1(DWORD vtx, DWORD nor, DWORD col, DWORD tvtx) {
00067         int alloc = (v.Count()>>1)+1;
00068         v.Append(1, &vtx, alloc); n.Append(1, &nor, alloc); c[0].Append(1, &col, alloc);
00069         tv[0].Append(1, &tvtx, alloc);
00070     }
00071     void AddVertNT2(DWORD vtx, DWORD nor, DWORD tvtx1, DWORD tvtx2) {
00072         int alloc = (v.Count()>>1)+1;
00073         v.Append(1, &vtx, alloc); n.Append(1, &nor, alloc);
00074         tv[0].Append(1, &tvtx1, alloc); tv[1].Append(1, &tvtx2, alloc);
00075     }
00076     void AddVertNC1T2(DWORD vtx, DWORD nor, DWORD col, DWORD tvtx1, DWORD tvtx2) {
00077         int alloc = (v.Count()>>1)+1;
00078         v.Append(1, &vtx, alloc); n.Append(1, &nor, alloc); c[0].Append(1, &col, alloc);
00079         tv[0].Append(1, &tvtx1, alloc); tv[1].Append(1, &tvtx2, alloc);
00080     }
00081     void AddVertNT3(DWORD vtx, DWORD nor, DWORD tvtx1, DWORD tvtx2, DWORD tvtx3) {
00082         int alloc = (v.Count()>>1)+1;
00083         v.Append(1, &vtx, alloc); n.Append(1, &nor, alloc);
00084         tv[0].Append(1, &tvtx1, alloc); tv[1].Append(1, &tvtx2, alloc); tv[2].Append(1, &tvtx3, alloc);
00085     }
00086     void AddVertNC1T3(DWORD vtx, DWORD nor, DWORD col, DWORD tvtx1, DWORD tvtx2, DWORD tvtx3) {
00087         int alloc = (v.Count()>>1)+1;
00088         v.Append(1, &vtx, alloc); n.Append(1, &nor, alloc); c[0].Append(1, &col, alloc);
00089         tv[0].Append(1, &tvtx1, alloc); tv[1].Append(1, &tvtx2, alloc); tv[2].Append(1, &tvtx3, alloc);
00090     }
00091     void AddVertNT4(DWORD vtx, DWORD nor, DWORD tvtx1, DWORD tvtx2, DWORD tvtx3, DWORD tvtx4) {
00092         int alloc = (v.Count()>>1)+1;
00093         v.Append(1, &vtx, alloc); n.Append(1, &nor, alloc);
00094         tv[0].Append(1, &tvtx1, alloc); tv[1].Append(1, &tvtx2, alloc);
00095         tv[2].Append(1, &tvtx3, alloc); tv[3].Append(1, &tvtx4, alloc);
00096     }
00097     void AddVertNC1T4(DWORD vtx, DWORD nor, DWORD col, DWORD tvtx1, DWORD tvtx2, DWORD tvtx3, DWORD tvtx4) {
00098         int alloc = (v.Count()>>1)+1;
00099         v.Append(1, &vtx, alloc); n.Append(1, &nor, alloc); c[0].Append(1, &col, alloc);
00100         tv[0].Append(1, &tvtx1, alloc); tv[1].Append(1, &tvtx2, alloc);
00101         tv[2].Append(1, &tvtx3, alloc); tv[3].Append(1, &tvtx4, alloc);
00102     }
00103 
00109     void AddVertexCol(int i, DWORD col)
00110     {
00111         DbgAssert(i >= 0 && i < GFX_MAX_COLORS);
00112         c[i].Append(1, &col, (v.Count()>>1)+1);
00113     }
00114 
00120     void AddVertexUV(int i, DWORD tx)
00121     {
00122         DbgAssert(i >= 0 && i < GFX_MAX_TEXTURES);
00123         tv[i].Append(1, &tx, (v.Count()>>1)+1);
00124     }
00125 };
00126 
00127 typedef TriStrip *TriStripPtr;
00128 typedef Tab<TriStripPtr> TriStripTab;
00129 
00130 class MeshData: public MaxHeapOperators
00131 {
00132 public:
00133     DWORD_PTR   id;
00134     int         numFaces;
00135     GWFace      *faces;
00136     int         numStrips;
00137     int         startStrip;
00138     int         endStrip;
00139     TriStripTab *strips;
00140     DWORD       mapFlags;
00141     int         numXYZ;
00142     Point3      *xyz;
00143     int         numNor;
00144     Point3      *nor;
00145     DWTab       *norIndex;
00146     Point3      *faceNor;
00147     int         numRGB[GFX_MAX_COLORS];
00148     Point3      *rgb[GFX_MAX_COLORS];
00149     int         numUVW[GFX_MAX_TEXTURES];
00150     Point3      *uvw[GFX_MAX_TEXTURES];
00151     int         numMtl;
00152     Material    *mtlArray;
00153     int         displayFlags;
00154     BitArray    *faceSel;
00155     BitArray    *edgeSel;
00156 
00157     MeshData()
00158       : id(NULL),
00159         numFaces(0),
00160         faces(NULL),
00161         numStrips(0),
00162         startStrip(0),
00163         endStrip(0),
00164         strips(NULL),
00165         mapFlags(0),
00166         numXYZ(0),
00167         xyz(NULL),
00168         numNor(0),
00169         nor(NULL),
00170         norIndex(NULL),
00171         faceNor(NULL),
00172         numMtl(0),
00173         mtlArray(NULL),
00174         displayFlags(0),
00175         faceSel(NULL),
00176         edgeSel(NULL)
00177     {
00178         int kk;
00179         for (kk = 0; kk < GFX_MAX_COLORS; kk++) {
00180             numRGB[kk] = 0;
00181             rgb[kk] = NULL;
00182         }
00183         for (kk = 0; kk < GFX_MAX_TEXTURES; kk++) {
00184             numUVW[kk] = 0;
00185             uvw[kk] = NULL;
00186         }
00187     }
00188 };
00189 
00190 class WireMeshData: public MaxHeapOperators
00191 {
00192 public:
00193     DWORD_PTR   id;
00194     int         numFaces;
00195     GWFace      *faces;
00196     int         numXYZ;
00197     Point3      *xyz;
00198     int         displayFlags;
00199     BitArray    *faceSel;
00200     BitArray    *edgeSel;
00201     int         numMat;
00202     Material    *mtlArray;
00203 
00204     WireMeshData()
00205       : id(NULL),
00206         numFaces(0),
00207         faces(NULL),
00208         numXYZ(0),
00209         xyz(NULL),
00210         displayFlags(0),
00211         faceSel(NULL),
00212         edgeSel(NULL),
00213         numMat(0),
00214         mtlArray(NULL)
00215     {}
00216 };
00217 
00218 class MeshFaceData: public MaxHeapOperators
00219 {
00220 public:
00221     DWORD_PTR   id;
00222     int         numFaces;
00223     GWFace      *faces;
00224     Point3      *faceNor;
00225     GWFace      *norFaces;
00226     DWORD       mapFlags;
00227     int         displayFlags;
00228     BitArray    *faceSel;
00229     BitArray    *edgeSel;
00230     int         numClrFaces[GFX_MAX_COLORS];
00231     GWFace      *clrFaces[GFX_MAX_COLORS];
00232     int         numTexFaces[GFX_MAX_TEXTURES];
00233     GWFace      *texFaces[GFX_MAX_TEXTURES];
00234     int         numXYZ;
00235     Point3      *xyz;
00236     int         numNor;
00237     Point3      *nor;
00238     DWTab       *norIndex;
00239     int         numRGB[GFX_MAX_COLORS];
00240     Point3      *rgb[GFX_MAX_COLORS];
00241     int         numUVW[GFX_MAX_TEXTURES];
00242     Point3      *uvw[GFX_MAX_TEXTURES];
00243     int         numMat;
00244     Material    *mtlArray;
00245 
00246     MeshFaceData()
00247       : id(NULL),
00248         numFaces(0),
00249         faces(NULL),
00250         faceNor(NULL),
00251         norFaces(NULL),
00252         mapFlags(0),
00253         displayFlags(0),
00254         faceSel(NULL),
00255         edgeSel(NULL),
00256         numXYZ(0),
00257         xyz(NULL),
00258         numNor(0),
00259         nor(NULL),
00260         norIndex(NULL),
00261         numMat(0),
00262         mtlArray(NULL)
00263     {
00264         int kk;
00265         for (kk = 0; kk < GFX_MAX_COLORS; kk++) {
00266             numClrFaces[kk] = 0;
00267             clrFaces[kk] = NULL;
00268             numRGB[kk] = 0;
00269             rgb[kk] = NULL;
00270         }
00271         for (kk = 0; kk < GFX_MAX_TEXTURES; kk++) {
00272             numTexFaces[kk] = 0;
00273             texFaces[kk] = NULL;
00274             numUVW[kk] = 0;
00275             uvw[kk] = NULL;
00276         }
00277     }
00278 };
00279 
00280 // End of 3ds max 4.2 Extension
00281 
00282 
00283 class IHardwareShader : public BaseInterface
00284 {
00285 public:
00286     virtual Interface_ID    GetID() { return HARDWARE_SHADER_INTERFACE_ID; }
00287     virtual Interface_ID    GetVSID() = 0;
00288     virtual Interface_ID    GetPSID() = 0;
00289 
00290     // Interface Lifetime
00291     virtual LifetimeType    LifetimeControl() { return noRelease; }
00292 
00293     // Start to draw object
00294     virtual void    StartObject(Mesh *mesh) = 0;
00295     virtual void    StartObject(MNMesh *mnmesh) = 0;
00296 
00297     // Initialize HardwareShader first time or frame-by-frame
00298     virtual void    InitializeShaders(Mesh *mesh, BaseInterface *pbvs, Material *mtlArray, int numMtl, GFX_ESCAPE_FN fn) = 0;
00299     virtual void    InitializeShaders(MNMesh *mnmesh, BaseInterface *pbvs, Material *mtlArray, int numMtl, GFX_ESCAPE_FN fn) = 0;
00300 
00301     // Try to draw as tristrips?
00302     virtual bool    CanTryStrips() = 0;
00303 
00304     // Retrive the current rendering mode
00305     virtual DWORD   GetRndMode() = 0;
00306 
00307     // Retrieve a Material
00308     virtual Material    *GetMaterial(int numMat) = 0;
00309 
00310     // Set a Material
00311     virtual void    SetMaterial(const Material &m, int index=0) = 0;
00312 
00313     // Retrieve number of passes for specified Material in Material array
00314     virtual int     GetNumMultiPass(int numMtl) = 0;
00315 
00316     // Set the number of the current pass
00317     virtual void    SetNumMultiPass(int numPass) = 0;
00318 
00319     // Draw 3D mesh as TriStrips
00320     virtual void    DrawMeshStrips(MeshData *data, GFX_ESCAPE_FN fn) = 0;
00321 
00322     // Draw 3D mesh as wireframe
00323     virtual void    DrawWireMesh(WireMeshData *data, GFX_ESCAPE_FN fn) = 0;
00324 
00325     // Draw 3D lines
00326     virtual void    StartLines(WireMeshData *data) = 0;
00327     virtual void    AddLine(DWORD *vert, int vis) = 0;
00328     virtual void    DrawLines() = 0;
00329     virtual void    EndLines(GFX_ESCAPE_FN fn) = 0;
00330 
00331     // Draw 3D triangles
00332     virtual void    StartTriangles(MeshFaceData *data) = 0;
00333     virtual void    AddTriangle(DWORD index, int *edgeVis) = 0;
00334     virtual void    DrawTriangles() = 0;
00335     virtual void    EndTriangles(GFX_ESCAPE_FN fn) = 0;
00336 
00337     // End of drawing object
00338     virtual void    EndObject(Mesh *mesh) = 0;
00339     virtual void    EndObject(MNMesh *mnmesh) = 0;
00340 };
00341 
00346 class IVertexShader: public MaxHeapOperators
00347 {
00348 public:
00349     // Load VertexShader instructions, create any additional per vertex data on
00350     // a per node basis.  VertexShader instructions should be loaded once and
00351     // shared among all the nodes using this VertexShader.  Additional per
00352     // vertex data should be (re)created only when the associated node data
00353     // changes.  In addition, if there is sufficient memory, VertexBuffers can
00354     // be created and updated only when node data changes in order to improve
00355     // rendering performance.
00368     virtual HRESULT Initialize(Mesh *mesh, INode *node) = 0;
00381     virtual HRESULT Initialize(MNMesh *mnmesh, INode *node) = 0;
00382 };
00383