📄 renderer.h
字号:
// Camera position/orientation
void setCamera(const Vector3 &pos, const EulerAngles &orient);
const Vector3 &getCameraPos() const { return cameraPos; }
const EulerAngles &getCameraOrient() const { return cameraOrient; }
// Set zoom. A zero zoom value means "compute it for me"
void setZoom(float xZoom, float yZoom = 0.0f);
// Near/far clipping planes
void setNearFarClippingPlanes(float n, float f);
float getNearClippingPlane() const { return nearClipPlane; }
float getFarClippingPlane() const { return farClipPlane; }
// Window definition
// The 2D output window
void setWindow(int x1, int y1, int xSize, int ySize);
void setFullScreenWindow();
void getWindow(int *x1, int *y1, int *xSize, int *ySize);
// Reference frame
// Nested reference frame stack
void instance(const Vector3 &pos, const EulerAngles &orient);
void instancePop();
// Low-level texture cache maintenance functions using names and handles directly
void resetTextureCache();
int findTexture(const char *name);
int allocTexture(const char *name, int xSize, int ySize);
void freeTexture(int handle);
void setTextureImage(int handle, const unsigned *image);
int cacheTexture(const char *filename);
// Slightly simpler texture cache access through the TextureReference class.
// Note that TextureReference structs cannot be used for anonymous textures.
void cacheTexture(TextureReference &texture);
// Rendering context management functions
// Zbuffer mode
void setDepthBufferMode(bool readEnabled, bool writeEnabled);
void setDepthBufferMode() { setDepthBufferMode(true, true); } // no parms - set defaults
bool getDepthBufferRead() const { return depthBufferRead; }
bool getDepthBufferWrite() const { return depthBufferWrite; }
// Alpha blending control
void setBlendEnable(bool blend = false);
bool getBlendEnable() const { return blendEnable; }
void setSourceBlendMode(ESourceBlendMode mode = eSourceBlendModeSrcAlpha);
ESourceBlendMode getSourceBlendMode() const { return sourceBlendMode; }
void setDestBlendMode(EDestBlendMode mode = eDestBlendModeInvSrcAlpha);
EDestBlendMode getDestBlendMode() const { return destBlendMode; }
// Global constant color (used for 2D primitives) and
// global constant opacity
void setRGB(unsigned int rgb); // alpha is ignored
unsigned getARGB() { return constantARGB; } // returns global opacity in the alpha channel
void setARGB(unsigned argb); // sets color and opacity in one call
void setOpacity(float a = 1.0F);
float getOpacity() const { return constantOpacity; }
// Fog. The alpha portion of the fog color is ignored, only the RGB portion
// is relevent
void setFogEnable(bool flag = false);
bool getFogEnable() { return fogEnable; }
void setFogColor(unsigned rgb);
unsigned getFogColor() const { return fogColor; }
void setFogDistance(float nearFog, float farFog);
float getFogNear() const { return fogNear; }
float getFogFar() const { return fogFar; }
// Lighting context. We will assume one single directional light, with ambient
void setAmbientLightColor(unsigned rgb);
unsigned getAmbientLightColor() const { return ambientLightColor; }
void setDirectionalLightVector(const Vector3 &v);
const Vector3 &getDirectionalLightVector() const { return directionalLightVector; }
void setDirectionalLightColor(unsigned rgb);
unsigned getDirectionalLightColor() const { return directionalLightColor; }
// Master switch for lighting enable. If lighting is disabled,
// everything is rendered unlit ("fully bright")
void setLightEnable(bool flag = true);
bool getLightEnable() const { return lightEnable; }
// Culling
void setBackfaceMode(EBackfaceMode mode = eBackfaceModeCCW);
EBackfaceMode getBackfaceMode() const { return backfaceMode; }
// Set current diffuse texture using handle
void selectTexture(int handle);
int getCurrentTexture() const { return currentTextureHandle; }
// Slightly more conveinent interface that uses texture reference
void selectTexture(TextureReference &texture);
// Texture clamping
void setTextureClamp(bool flag = false);
bool getTextureClamp() const { return textureClamp; }
// Rendering primitives
// Clear the frame buffer and/or depth buffer. This clears
// the current 2D window, not the entire screen
// The options are formed from the kClearXxxx constants above
void clear(int options = kClearFrameBuffer | kClearDepthBuffer);
// Render a triangle mesh
void renderTriMesh(const RenderVertex *vertexList, int vertexCount, const RenderTri *triList, int triCount);
void renderTriMesh(const RenderVertexL *vertexList, int vertexCount, const RenderTri *triList, int triCount);
void renderTriMesh(const RenderVertexTL *vertexList, int vertexCount, const RenderTri *triList, int triCount);
// 2D primitives. These use the current constant color
void dot(int x, int y);
void line(int x1, int y1, int x2, int y2);
void boxFill(int x1, int y1, int x2, int y2);
// Software vertex transformations functions. These are primarily useful for
// performing visibility or other manual manipulations.
// Access to various matrices
const Matrix4x3 &getWorldToCameraMatrix() { return worldToCameraMatrix; }
const Matrix4x3 &getModelToCameraMatrix();
const Matrix4x3 &getModelToWorldMatrix();
// Return a vertex outcode given a point in the current reference space.
// Returns a bitfield componsef of the kOutCodeXXX constants
int computeOutCode(const Vector3 &p);
// Compute outcode and project point onto screen space,
// if possible. If the outcode contains any of
// kOutCodeOffScreenMask, then the vertex was not projected.
int projectPoint(const Vector3 &p, Vector3 *result);
private:
// Internal state variables
// Full screen resolution
int screenX;
int screenY;
// Camera specification
Vector3 cameraPos;
EulerAngles cameraOrient;
float zoomX;
float zoomY;
// Near/far clipping planes
float nearClipPlane;
float farClipPlane;
// The 2D output window
int windowX1;
int windowY1;
int windowX2;
int windowY2;
int windowSizeX;
int windowSizeY;
// Zbuffer mode
bool depthBufferRead;
bool depthBufferWrite;
// Alpha blending
bool blendEnable;
ESourceBlendMode sourceBlendMode;
EDestBlendMode destBlendMode;
// Global constant color and opacity.
unsigned constantARGB;
float constantOpacity;
// Fog
bool fogEnable;
unsigned fogColor;
float fogNear;
float fogFar;
// Lighting context.
bool lightEnable;
unsigned ambientLightColor;
Vector3 directionalLightVector;
unsigned directionalLightColor;
// Culling
EBackfaceMode backfaceMode;
// Currently selected texture
int currentTextureHandle;
// Texture clamp
bool textureClamp;
// Current world->camera matrix. This will always be a rigid body
// transform - it does not contain zoom or aspect ratio correction.
Matrix4x3 worldToCameraMatrix;
// Implementation details
void updateModelToWorldMatrix();
void computeClipMatrix();
void getModelToClipMatrix();
void freeAllTextures();
};
// The global class object
extern Renderer gRenderer;
/////////////////////////////////////////////////////////////////////////////
#endif // #ifndef __RENDERER_H_INCLUDED__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -