//=================================================================
//
// Copyright (c) Microsoft Corporation 1999 - All Rights Reserved.
//
//=================================================================

// NOTE: "int" doesn't seem to be handled properly by h2inc, so use "long" instead.

#ifndef _CHUNK_
#define _CHUNK_

#include "span.h"

// All information required by chunk processors is stored here.
// NOTE span chunk processors should not modify this structure.
struct ChunkData
{
    // working buffer we build RGB pixels in.
    MUNGED3 rgm3WorkingBuffer[MAX_SPAN_BLOCK_LEN];

    // working buffer we store alpha (in range 0-1F) in
    MUNGED3 rgm1WorkingAlphaBuffer[MAX_SPAN_BLOCK_LEN];

    // vector threads through chunk processors
    PSPANFN pspanfnWorking[NUM_SPAN_VECTORS];

    // flat color for whole triangle
    // form used for filling
    MUNGED3 m3FlatRGB;
    MUNGED1 m1FlatA;
    // form used for RGBA texture shading
    MUNGED2X m2xFlatGB;
    MUNGED2X m2xFlatAR;
    // form used for IA texture shading (g_m1FlatA is alpha in this case)
    MUNGED1 m1FlatI;
    unsigned long   dwNativeFlatRGB;
    unsigned long   dwNativeFlatRGB2X;

    unsigned long   fNeedToDoBackendZCompare;

    unsigned short  *pPix_Chunk;
    unsigned short  *pZ_Chunk;
	long            cPixels_Chunk;
    unsigned long   dwZ_Chunk;    // 0.32
    FIX16_16  fix16u_Chunk, fix16v_Chunk;
    FIX16_16  fix16du_Chunk, fix16dv_Chunk;
    unsigned long   ZIncr_Chunk;  // 0.32 format

    GOURAUD_RB  grb_Chunk, grbIncrement_Chunk;
    GOURAUD_AG  gag_Chunk, gagIncrement_Chunk;
    GOURAUD_GB  ggb_Chunk, ggbIncrement_Chunk;
    GOURAUD_AR  gar_Chunk, garIncrement_Chunk;
    GOURAUD_RGB grgb_Chunk, grgbIncrement_Chunk;
    GOURAUD_I   gi_Chunk, giIncrement_Chunk;
    GOURAUD_A   ga_Chunk, gaIncrement_Chunk;

    unsigned long   SaveESP;

    unsigned long   cMunged3ToTargetShift0; // green component shift from MUNGED3 to target format (555 or 565)
    unsigned long   cMunged3ToTargetShift1; // red component shift from MUNGED3 to target format (555 or 565)

    // Texture data.

    unsigned short  *pwTexture;                           // Pointer to texture data.
    unsigned long   cxTextureMask;
    unsigned long   cyTextureShift;                      // Shift used to multiply by texture width and bytes per pixel.
    unsigned long   cyTextureMask;

    unsigned long   cPixDouble;
    unsigned long   cbScanDoubleOffset;
    unsigned long   cDouble;

    unsigned long   cbScreenPitch; // will actually be two scan lines if pixel doubling is enabled
    unsigned char   *pbScreen;

    MUNGED3     m3FogColor, m3FogColorFlattened;
    GOURAUD_I   giFog_Chunk, giFogIncrement_Chunk;
    unsigned long   fSkipLastPixel;
};

typedef struct ChunkData    GRFCHUNKDATA;

#endif // _CHUNK_

