With the exception of NVIDIA hardware, these are is the values that all hardware and Gallium want. The remapping is currently implemented in at least 6 places. This starts the process of consolidating to a single place. v2: sed --in-place -e 's/color_logic_ops/gl_logicop_mode/g' $(grep -lr color_logic_ops src/) suggested by Brian. Added some comments about the selection of bit patterns for gl_logicop_mode and the GLenums. Suggested by Nicolai. Folded the GLenum_to_color_logicop macro into its only users. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Brian Paul <brianp@vmware.com> [v1] Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>tags/18.1-branchpoint
| } | } | ||||
| } | } | ||||
| static const enum gl_logicop_mode color_logicop_mapping[16] = { | |||||
| COLOR_LOGICOP_CLEAR, | |||||
| COLOR_LOGICOP_AND, | |||||
| COLOR_LOGICOP_AND_REVERSE, | |||||
| COLOR_LOGICOP_COPY, | |||||
| COLOR_LOGICOP_AND_INVERTED, | |||||
| COLOR_LOGICOP_NOOP, | |||||
| COLOR_LOGICOP_XOR, | |||||
| COLOR_LOGICOP_OR, | |||||
| COLOR_LOGICOP_NOR, | |||||
| COLOR_LOGICOP_EQUIV, | |||||
| COLOR_LOGICOP_INVERT, | |||||
| COLOR_LOGICOP_OR_REVERSE, | |||||
| COLOR_LOGICOP_COPY_INVERTED, | |||||
| COLOR_LOGICOP_OR_INVERTED, | |||||
| COLOR_LOGICOP_NAND, | |||||
| COLOR_LOGICOP_SET | |||||
| }; | |||||
| static ALWAYS_INLINE void | static ALWAYS_INLINE void | ||||
| logic_op(struct gl_context *ctx, GLenum opcode, bool no_error) | logic_op(struct gl_context *ctx, GLenum opcode, bool no_error) | ||||
| FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR); | FLUSH_VERTICES(ctx, ctx->DriverFlags.NewLogicOp ? 0 : _NEW_COLOR); | ||||
| ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp; | ctx->NewDriverState |= ctx->DriverFlags.NewLogicOp; | ||||
| ctx->Color.LogicOp = opcode; | ctx->Color.LogicOp = opcode; | ||||
| ctx->Color._LogicOp = color_logicop_mapping[opcode & 0x0f]; | |||||
| if (ctx->Driver.LogicOpcode) | if (ctx->Driver.LogicOpcode) | ||||
| ctx->Driver.LogicOpcode(ctx, opcode); | ctx->Driver.LogicOpcode(ctx, opcode); | ||||
| ctx->Color.IndexLogicOpEnabled = GL_FALSE; | ctx->Color.IndexLogicOpEnabled = GL_FALSE; | ||||
| ctx->Color.ColorLogicOpEnabled = GL_FALSE; | ctx->Color.ColorLogicOpEnabled = GL_FALSE; | ||||
| ctx->Color.LogicOp = GL_COPY; | ctx->Color.LogicOp = GL_COPY; | ||||
| ctx->Color._LogicOp = COLOR_LOGICOP_COPY; | |||||
| ctx->Color.DitherFlag = GL_TRUE; | ctx->Color.DitherFlag = GL_TRUE; | ||||
| /* GL_FRONT is not possible on GLES. Instead GL_BACK will render to either | /* GL_FRONT is not possible on GLES. Instead GL_BACK will render to either |
| GLuint ui[4]; | GLuint ui[4]; | ||||
| }; | }; | ||||
| /** | |||||
| * Remapped color logical operations | |||||
| * | |||||
| * With the exception of NVIDIA hardware, which consumes the OpenGL enumerants | |||||
| * directly, everything wants this mapping of color logical operations. | |||||
| * | |||||
| * Fun fact: These values are just the bit-reverse of the low-nibble of the GL | |||||
| * enumerant values (i.e., `GL_NOOP & 0x0f` is `b0101' while | |||||
| * \c COLOR_LOGICOP_NOOP is `b1010`). | |||||
| * | |||||
| * Fun fact #2: These values are just an encoding of the operation as a table | |||||
| * of bit values. The result of the logic op is: | |||||
| * | |||||
| * result_bit = (logic_op >> (2 * src_bit + dst_bit)) & 1 | |||||
| * | |||||
| * For the GL enums, the result is: | |||||
| * | |||||
| * result_bit = logic_op & (1 << (2 * src_bit + dst_bit)) | |||||
| */ | |||||
| enum PACKED gl_logicop_mode { | |||||
| COLOR_LOGICOP_CLEAR = 0, | |||||
| COLOR_LOGICOP_NOR = 1, | |||||
| COLOR_LOGICOP_AND_INVERTED = 2, | |||||
| COLOR_LOGICOP_COPY_INVERTED = 3, | |||||
| COLOR_LOGICOP_AND_REVERSE = 4, | |||||
| COLOR_LOGICOP_INVERT = 5, | |||||
| COLOR_LOGICOP_XOR = 6, | |||||
| COLOR_LOGICOP_NAND = 7, | |||||
| COLOR_LOGICOP_AND = 8, | |||||
| COLOR_LOGICOP_EQUIV = 9, | |||||
| COLOR_LOGICOP_NOOP = 10, | |||||
| COLOR_LOGICOP_OR_INVERTED = 11, | |||||
| COLOR_LOGICOP_COPY = 12, | |||||
| COLOR_LOGICOP_OR_REVERSE = 13, | |||||
| COLOR_LOGICOP_OR = 14, | |||||
| COLOR_LOGICOP_SET = 15 | |||||
| }; | |||||
| /** | /** | ||||
| * Color buffer attribute group (GL_COLOR_BUFFER_BIT). | * Color buffer attribute group (GL_COLOR_BUFFER_BIT). | ||||
| GLboolean IndexLogicOpEnabled; /**< Color index logic op enabled flag */ | GLboolean IndexLogicOpEnabled; /**< Color index logic op enabled flag */ | ||||
| GLboolean ColorLogicOpEnabled; /**< RGBA logic op enabled flag */ | GLboolean ColorLogicOpEnabled; /**< RGBA logic op enabled flag */ | ||||
| GLenum LogicOp; /**< Logic operator */ | GLenum LogicOp; /**< Logic operator */ | ||||
| enum gl_logicop_mode _LogicOp; | |||||
| /*@}*/ | /*@}*/ | ||||