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

📄 arbprogparse.c

📁 winNT技术操作系统,国外开放的原代码和LIUX一样
💻 C
📖 第 1 页 / 共 5 页
字号:
/*
 * Mesa 3-D graphics library
 * Version:  6.4
 *
 * Copyright (C) 1999-2005  Brian Paul   All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

#define DEBUG_PARSING 0

/**
 * \file arbprogparse.c
 * ARB_*_program parser core
 * \author Karl Rasche
 */

#include "mtypes.h"
#include "glheader.h"
#include "context.h"
#include "hash.h"
#include "imports.h"
#include "macros.h"
#include "program.h"
#include "nvvertprog.h"
#include "nvfragprog.h"
#include "arbprogparse.h"
#include "grammar_mesa.h"

#include "dispatch.h"

#ifndef __extension__
#if !defined(__GNUC__) || (__GNUC__ < 2) || \
    ((__GNUC__ == 2) && (__GNUC_MINOR__ <= 7))
# define __extension__
#endif
#endif

/* TODO:
 *    Fragment Program Stuff:
 *    -----------------------------------------------------
 *
 *    - things from Michal's email
 *       + overflow on atoi
 *       + not-overflowing floats (don't use parse_integer..)
 *       + can remove range checking in arbparse.c
 *
 *    - check all limits of number of various variables
 *      + parameters
 *
 *    - test! test! test!
 *
 *    Vertex Program Stuff:
 *    -----------------------------------------------------
 *    - Optimize param array usage and count limits correctly, see spec,
 *         section 2.14.3.7
 *       + Record if an array is reference absolutly or relatively (or both)
 *       + For absolute arrays, store a bitmap of accesses
 *       + For single parameters, store an access flag
 *       + After parsing, make a parameter cleanup and merging pass, where
 *           relative arrays are layed out first, followed by abs arrays, and
 *           finally single state.
 *       + Remap offsets for param src and dst registers
 *       + Now we can properly count parameter usage
 *
 *    - Multiple state binding errors in param arrays (see spec, just before
 *         section 2.14.3.3)
 *    - grep for XXX
 *
 *    Mesa Stuff
 *    -----------------------------------------------------
 *    - User clipping planes vs. PositionInvariant
 *    - Is it sufficient to just multiply by the mvp to transform in the
 *        PositionInvariant case? Or do we need something more involved?
 *
 *    - vp_src swizzle is GLubyte, fp_src swizzle is GLuint
 *    - fetch state listed in program_parameters list
 *       + WTF should this go???
 *       + currently in nvvertexec.c and s_nvfragprog.c
 *
 *    - allow for multiple address registers (and fetch address regs properly)
 *
 *    Cosmetic Stuff
 *    -----------------------------------------------------
 * 	- remove any leftover unused grammer.c stuff (dict_ ?)
 * 	- fix grammer.c error handling so its not static
 * 	- #ifdef around stuff pertaining to extentions
 *
 *    Outstanding Questions:
 *    -----------------------------------------------------
 *    - ARB_matrix_palette / ARB_vertex_blend -- not supported
 *      what gets hacked off because of this:
 *       + VERTEX_ATTRIB_MATRIXINDEX
 *       + VERTEX_ATTRIB_WEIGHT
 *       + MATRIX_MODELVIEW
 *       + MATRIX_PALETTE
 *
 *    - When can we fetch env/local params from their own register files, and
 *      when to we have to fetch them into the main state register file?
 *      (think arrays)
 *
 *    Grammar Changes:
 *    -----------------------------------------------------
 */

/* Changes since moving the file to shader directory

2004-III-4 ------------------------------------------------------------
- added #include "grammar_mesa.h"
- removed grammar specific code part (it resides now in grammar.c)
- added GL_ARB_fragment_program_shadow tokens
- modified #include "arbparse_syn.h"
- major changes inside _mesa_parse_arb_program()
- check the program string for '\0' characters
- copy the program string to a one-byte-longer location to have
  it null-terminated
- position invariance test (not writing to result.position) moved
  to syntax part
*/

typedef GLubyte *production;

/**
 * This is the text describing the rules to parse the grammar
 */
__extension__ static char arb_grammar_text[] =
#include "arbprogram_syn.h"
;

/**
 * These should match up with the values defined in arbprogram.syn
 */

/*
    Changes:
    - changed and merged V_* and F_* opcode values to OP_*.
    - added GL_ARB_fragment_program_shadow specific tokens (michal)
*/
#define  REVISION                                   0x09

/* program type */
#define  FRAGMENT_PROGRAM                           0x01
#define  VERTEX_PROGRAM                             0x02

/* program section */
#define  OPTION                                     0x01
#define  INSTRUCTION                                0x02
#define  DECLARATION                                0x03
#define  END                                        0x04

/* GL_ARB_fragment_program option */
#define  ARB_PRECISION_HINT_FASTEST                 0x00
#define  ARB_PRECISION_HINT_NICEST                  0x01
#define  ARB_FOG_EXP                                0x02
#define  ARB_FOG_EXP2                               0x03
#define  ARB_FOG_LINEAR                             0x04

/* GL_ARB_vertex_program option */
#define  ARB_POSITION_INVARIANT                     0x05

/* GL_ARB_fragment_program_shadow option */
#define  ARB_FRAGMENT_PROGRAM_SHADOW                0x06

/* GL_ARB_draw_buffers option */
#define  ARB_DRAW_BUFFERS                           0x07

/* GL_ARB_fragment_program instruction class */
#define  OP_ALU_INST                                0x00
#define  OP_TEX_INST                                0x01

/* GL_ARB_vertex_program instruction class */
/*       OP_ALU_INST */

/* GL_ARB_fragment_program instruction type */
#define  OP_ALU_VECTOR                               0x00
#define  OP_ALU_SCALAR                               0x01
#define  OP_ALU_BINSC                                0x02
#define  OP_ALU_BIN                                  0x03
#define  OP_ALU_TRI                                  0x04
#define  OP_ALU_SWZ                                  0x05
#define  OP_TEX_SAMPLE                               0x06
#define  OP_TEX_KIL                                  0x07

/* GL_ARB_vertex_program instruction type */
#define  OP_ALU_ARL                                  0x08
/*       OP_ALU_VECTOR */
/*       OP_ALU_SCALAR */
/*       OP_ALU_BINSC */
/*       OP_ALU_BIN */
/*       OP_ALU_TRI */
/*       OP_ALU_SWZ */

/* GL_ARB_fragment_program instruction code */
#define  OP_ABS                                     0x00
#define  OP_ABS_SAT                                 0x1B
#define  OP_FLR                                     0x09
#define  OP_FLR_SAT                                 0x26
#define  OP_FRC                                     0x0A
#define  OP_FRC_SAT                                 0x27
#define  OP_LIT                                     0x0C
#define  OP_LIT_SAT                                 0x2A
#define  OP_MOV                                     0x11
#define  OP_MOV_SAT                                 0x30
#define  OP_COS                                     0x1F
#define  OP_COS_SAT                                 0x20
#define  OP_EX2                                     0x07
#define  OP_EX2_SAT                                 0x25
#define  OP_LG2                                     0x0B
#define  OP_LG2_SAT                                 0x29
#define  OP_RCP                                     0x14
#define  OP_RCP_SAT                                 0x33
#define  OP_RSQ                                     0x15
#define  OP_RSQ_SAT                                 0x34
#define  OP_SIN                                     0x38
#define  OP_SIN_SAT                                 0x39
#define  OP_SCS                                     0x35
#define  OP_SCS_SAT                                 0x36
#define  OP_POW                                     0x13
#define  OP_POW_SAT                                 0x32
#define  OP_ADD                                     0x01
#define  OP_ADD_SAT                                 0x1C
#define  OP_DP3                                     0x03
#define  OP_DP3_SAT                                 0x21
#define  OP_DP4                                     0x04
#define  OP_DP4_SAT                                 0x22
#define  OP_DPH                                     0x05
#define  OP_DPH_SAT                                 0x23
#define  OP_DST                                     0x06
#define  OP_DST_SAT                                 0x24
#define  OP_MAX                                     0x0F
#define  OP_MAX_SAT                                 0x2E
#define  OP_MIN                                     0x10
#define  OP_MIN_SAT                                 0x2F
#define  OP_MUL                                     0x12
#define  OP_MUL_SAT                                 0x31
#define  OP_SGE                                     0x16
#define  OP_SGE_SAT                                 0x37
#define  OP_SLT                                     0x17
#define  OP_SLT_SAT                                 0x3A
#define  OP_SUB                                     0x18
#define  OP_SUB_SAT                                 0x3B
#define  OP_XPD                                     0x1A
#define  OP_XPD_SAT                                 0x43
#define  OP_CMP                                     0x1D
#define  OP_CMP_SAT                                 0x1E
#define  OP_LRP                                     0x2B
#define  OP_LRP_SAT                                 0x2C
#define  OP_MAD                                     0x0E
#define  OP_MAD_SAT                                 0x2D
#define  OP_SWZ                                     0x19
#define  OP_SWZ_SAT                                 0x3C
#define  OP_TEX                                     0x3D
#define  OP_TEX_SAT                                 0x3E
#define  OP_TXB                                     0x3F
#define  OP_TXB_SAT                                 0x40
#define  OP_TXP                                     0x41
#define  OP_TXP_SAT                                 0x42
#define  OP_KIL                                     0x28

/* GL_ARB_vertex_program instruction code */
#define  OP_ARL                                     0x02
/*       OP_ABS */
/*       OP_FLR */
/*       OP_FRC */
/*       OP_LIT */
/*       OP_MOV */
/*       OP_EX2 */
#define  OP_EXP                                     0x08
/*       OP_LG2 */
#define  OP_LOG                                     0x0D
/*       OP_RCP */
/*       OP_RSQ */
/*       OP_POW */
/*       OP_ADD */
/*       OP_DP3 */
/*       OP_DP4 */
/*       OP_DPH */
/*       OP_DST */
/*       OP_MAX */
/*       OP_MIN */
/*       OP_MUL */
/*       OP_SGE */
/*       OP_SLT */
/*       OP_SUB */
/*       OP_XPD */
/*       OP_MAD */
/*       OP_SWZ */

/* fragment attribute binding */
#define  FRAGMENT_ATTRIB_COLOR                      0x01
#define  FRAGMENT_ATTRIB_TEXCOORD                   0x02
#define  FRAGMENT_ATTRIB_FOGCOORD                   0x03
#define  FRAGMENT_ATTRIB_POSITION                   0x04

/* vertex attribute binding */
#define  VERTEX_ATTRIB_POSITION                     0x01
#define  VERTEX_ATTRIB_WEIGHT                       0x02
#define  VERTEX_ATTRIB_NORMAL                       0x03
#define  VERTEX_ATTRIB_COLOR                        0x04
#define  VERTEX_ATTRIB_FOGCOORD                     0x05
#define  VERTEX_ATTRIB_TEXCOORD                     0x06
#define  VERTEX_ATTRIB_MATRIXINDEX                  0x07
#define  VERTEX_ATTRIB_GENERIC                      0x08

/* fragment result binding */
#define  FRAGMENT_RESULT_COLOR                      0x01
#define  FRAGMENT_RESULT_DEPTH                      0x02

/* vertex result binding */
#define  VERTEX_RESULT_POSITION                     0x01
#define  VERTEX_RESULT_COLOR                        0x02
#define  VERTEX_RESULT_FOGCOORD                     0x03
#define  VERTEX_RESULT_POINTSIZE                    0x04
#define  VERTEX_RESULT_TEXCOORD                     0x05

/* texture target */
#define  TEXTARGET_1D                               0x01
#define  TEXTARGET_2D                               0x02
#define  TEXTARGET_3D                               0x03
#define  TEXTARGET_RECT                             0x04
#define  TEXTARGET_CUBE                             0x05
/* GL_ARB_fragment_program_shadow */
#define  TEXTARGET_SHADOW1D                         0x06
#define  TEXTARGET_SHADOW2D                         0x07
#define  TEXTARGET_SHADOWRECT                       0x08

/* face type */
#define  FACE_FRONT                                 0x00
#define  FACE_BACK                                  0x01

/* color type */
#define  COLOR_PRIMARY                              0x00
#define  COLOR_SECONDARY                            0x01

/* component */
#define  COMPONENT_X                                0x00
#define  COMPONENT_Y                                0x01
#define  COMPONENT_Z                                0x02
#define  COMPONENT_W                                0x03
#define  COMPONENT_0                                0x04
#define  COMPONENT_1                                0x05

/* array index type */
#define  ARRAY_INDEX_ABSOLUTE                       0x00
#define  ARRAY_INDEX_RELATIVE                       0x01

/* matrix name */
#define  MATRIX_MODELVIEW                           0x01
#define  MATRIX_PROJECTION                          0x02
#define  MATRIX_MVP                                 0x03
#define  MATRIX_TEXTURE                             0x04
#define  MATRIX_PALETTE                             0x05
#define  MATRIX_PROGRAM                             0x06

/* matrix modifier */
#define  MATRIX_MODIFIER_IDENTITY                   0x00
#define  MATRIX_MODIFIER_INVERSE                    0x01
#define  MATRIX_MODIFIER_TRANSPOSE                  0x02
#define  MATRIX_MODIFIER_INVTRANS                   0x03

/* constant type */
#define  CONSTANT_SCALAR                            0x01
#define  CONSTANT_VECTOR                            0x02

/* program param type */
#define  PROGRAM_PARAM_ENV                          0x01
#define  PROGRAM_PARAM_LOCAL                        0x02

/* register type */
#define  REGISTER_ATTRIB                            0x01
#define  REGISTER_PARAM                             0x02
#define  REGISTER_RESULT                            0x03

⌨️ 快捷键说明

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