⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mgcgprenderer.h

📁 《3D游戏引擎设计》的源码
💻 H
字号:
// Magic Software, Inc.
// http://www.magic-software.com
// Copyright (c) 2000, All Rights Reserved
//
// Source code from Magic Software is supplied under the terms of a license
// agreement and may not be copied or disclosed except in accordance with the
// terms of that agreement.  The various license agreements may be found at
// the Magic Software web site.  This file is subject to the license
//
// RESTRICTED USE SOURCE CODE
// http://www.magic-software.com/License/restricted.pdf

#ifndef MGCGPRENDERER_H
#define MGCGPRENDERER_H

#include "MgcRenderer.h"
#include "MgcGPCamera.h"
#include "MgcGPEdgeBuffers.h"
#include "MgcGPRendererMesh.h"


class MgcGPRenderer : public MgcRenderer
{
    MgcDeclareRTTI;
    MgcDeclareStream;

public:
    virtual ~MgcGPRenderer ();

    virtual void Draw (const MgcGPTriMesh& rkTriMesh);

protected:
    // abstract base class for software renderers
    MgcGPRenderer (int iWidth, int iHeight);
    MgcGPRenderer ();

    // clipping
    bool Clip ();
    bool ClipTriMesh ();
    bool ClipNear ();
    bool ClipFar ();
    bool ClipLeft ();
    bool ClipRight ();
    bool ClipTop ();
    bool ClipBottom ();

    // projection
    void ProjectVertices ();

    // rasterization
    virtual void RasterizeEdges () = 0;
    virtual void RasterizeTriangles () = 0;

    void ComputeEdgeBuffer (
        int iX0, int iY0, MgcReal* afLinAttr0, MgcReal* afPerAttr0,
        int iX1, int iY1, MgcReal* afLinAttr1, MgcReal* afPerAttr1,
        int* aiXBuffer, MgcReal** aafLinAttrBuffer,
        MgcReal** aafPerAttrBuffer);

    bool ComputeEdgeBuffers ();

    // renderer state management
    virtual void SetAlphaState (MgcAlphaState* pkState);
    virtual void SetDitherState (MgcDitherState* pkState);
    virtual void SetFogState (MgcFogState* pkState);
    virtual void SetLightState (MgcLightState* pkState);
    virtual void SetMaterialState (MgcMaterialState* pkState);
    virtual void SetShadeState (MgcShadeState* pkState);
    virtual void SetTextureState (MgcTextureState* pkState);
    virtual void SetVertexColorState (MgcVertexColorState* pkState);
    virtual void SetWireframeState (MgcWireframeState* pkState);
    virtual void SetZBufferState (MgcZBufferState* pkState);

    bool AlphaBlendActive ();
    bool ZBufferActive ();

    // window parameters
    MgcReal m_fWidth, m_fHeight, m_fXScale, m_fYScale;

    // upcast MgcCamera to MgcGPCamera
    MgcGPCamera* GetCamera ();

    // renderer's local storage for trimesh (grows to maximum size needed)
    MgcGPRendererMesh m_kMesh;

    // edge buffering for scan line setup
    int m_iYMin, m_iYMax;
    int m_aiX[3], m_aiY[3];
    int* m_aiXMin;
    int* m_aiXMax;
    enum { MAX_ATTRIBUTES = 6 };  // u, v, w, r, g, b
    unsigned int m_uiNumLinAttr;  // in [0..MAX_ATTRIBUTES-1]
    MgcReal** m_aafLinAttrMin;
    MgcReal** m_aafLinAttrMax;
    MgcReal* m_aafLinAttr[3];  // attribute packing
    unsigned int m_uiNumPerAttr;  // in [0..MAX_ATTRIBUTES-1]
    MgcReal** m_aafPerAttrMin;
    MgcReal** m_aafPerAttrMax;
    MgcReal* m_aafPerAttr[3];  // attribute packing

    // current render state
    MgcAlphaState* m_pkAlphaState;
    MgcDitherState* m_pkDitherState;
    MgcFogState* m_pkFogState;
    MgcLightState* m_pkLightState;
    MgcMaterialState* m_pkMaterialState;
    MgcShadeState* m_pkShadeState;
    MgcTextureState* m_pkTextureState;
    MgcVertexColorState* m_pkVertexColorState;
    MgcWireframeState* m_pkWireframeState;
    MgcZBufferState* m_pkZBufferState;
};

MgcSmartPointer(MgcGPRenderer);
MgcRegisterStream(MgcGPRenderer);
#include "MgcGPRenderer.inl"

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -