1 /* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License 4 * as published by the Free Software Foundation; either version 2 5 * of the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software Foundation, 14 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 15 */ 16 17 /** \file 18 * \ingroup gpu 19 */ 20 21 #pragma once 22 23 #include "BLI_utildefines.h" 24 25 typedef enum eGPUWriteMask { 26 GPU_WRITE_NONE = 0, 27 GPU_WRITE_RED = (1 << 0), 28 GPU_WRITE_GREEN = (1 << 1), 29 GPU_WRITE_BLUE = (1 << 2), 30 GPU_WRITE_ALPHA = (1 << 3), 31 GPU_WRITE_DEPTH = (1 << 4), 32 GPU_WRITE_STENCIL = (1 << 5), 33 GPU_WRITE_COLOR = (GPU_WRITE_RED | GPU_WRITE_GREEN | GPU_WRITE_BLUE | GPU_WRITE_ALPHA), 34 } eGPUWriteMask; 35 36 ENUM_OPERATORS(eGPUWriteMask, GPU_WRITE_COLOR) 37 38 typedef enum eGPUBarrier { 39 GPU_BARRIER_NONE = 0, 40 GPU_BARRIER_SHADER_IMAGE_ACCESS = (1 << 0), 41 GPU_BARRIER_TEXTURE_FETCH = (1 << 1), 42 } eGPUBarrier; 43 44 ENUM_OPERATORS(eGPUBarrier, GPU_BARRIER_TEXTURE_FETCH) 45 46 /** 47 * Defines the fixed pipeline blending equation. 48 * SRC is the output color from the shader. 49 * DST is the color from the framebuffer. 50 * The blending equation is : 51 * (SRC * A) + (DST * B). 52 * The blend mode will modify the A and B parameters. 53 */ 54 typedef enum eGPUBlend { 55 GPU_BLEND_NONE = 0, 56 /** Premult variants will _NOT_ multiply rgb output by alpha. */ 57 GPU_BLEND_ALPHA, 58 GPU_BLEND_ALPHA_PREMULT, 59 GPU_BLEND_ADDITIVE, 60 GPU_BLEND_ADDITIVE_PREMULT, 61 GPU_BLEND_MULTIPLY, 62 GPU_BLEND_SUBTRACT, 63 /** Replace logic op: SRC * (1 - DST) 64 * NOTE: Does not modify alpha. */ 65 GPU_BLEND_INVERT, 66 /** Order independent transparency. 67 * NOTE: Cannot be used as is. Needs special setup (framebuffer, shader ...). */ 68 GPU_BLEND_OIT, 69 /** Special blend to add color under and multiply dst color by src alpha. */ 70 GPU_BLEND_BACKGROUND, 71 /** Custom blend parameters using dual source blending : SRC0 + SRC1 * DST 72 * NOTE: Can only be used with _ONE_ Draw Buffer and shader needs to be specialized. */ 73 GPU_BLEND_CUSTOM, 74 GPU_BLEND_ALPHA_UNDER_PREMUL, 75 } eGPUBlend; 76 77 typedef enum eGPUDepthTest { 78 GPU_DEPTH_NONE = 0, 79 GPU_DEPTH_ALWAYS, /* Used to draw to the depth buffer without really testing. */ 80 GPU_DEPTH_LESS, 81 GPU_DEPTH_LESS_EQUAL, /* Default. */ 82 GPU_DEPTH_EQUAL, 83 GPU_DEPTH_GREATER, 84 GPU_DEPTH_GREATER_EQUAL, 85 } eGPUDepthTest; 86 87 typedef enum eGPUStencilTest { 88 GPU_STENCIL_NONE = 0, 89 GPU_STENCIL_ALWAYS, 90 GPU_STENCIL_EQUAL, 91 GPU_STENCIL_NEQUAL, 92 } eGPUStencilTest; 93 94 typedef enum eGPUStencilOp { 95 GPU_STENCIL_OP_NONE = 0, 96 GPU_STENCIL_OP_REPLACE, 97 /** Special values for stencil shadows. */ 98 GPU_STENCIL_OP_COUNT_DEPTH_PASS, 99 GPU_STENCIL_OP_COUNT_DEPTH_FAIL, 100 } eGPUStencilOp; 101 102 typedef enum eGPUFaceCullTest { 103 GPU_CULL_NONE = 0, /* Culling disabled. */ 104 GPU_CULL_FRONT, 105 GPU_CULL_BACK, 106 } eGPUFaceCullTest; 107 108 typedef enum eGPUProvokingVertex { 109 GPU_VERTEX_LAST = 0, /* Default. */ 110 GPU_VERTEX_FIRST = 1, /* Follow Blender loop order. */ 111 } eGPUProvokingVertex; 112 113 #ifdef __cplusplus 114 extern "C" { 115 #endif 116 117 void GPU_blend(eGPUBlend blend); 118 void GPU_face_culling(eGPUFaceCullTest culling); 119 void GPU_depth_test(eGPUDepthTest test); 120 void GPU_stencil_test(eGPUStencilTest test); 121 void GPU_provoking_vertex(eGPUProvokingVertex vert); 122 void GPU_front_facing(bool invert); 123 void GPU_depth_range(float near, float far); 124 void GPU_scissor_test(bool enable); 125 void GPU_line_smooth(bool enable); 126 void GPU_line_width(float width); 127 void GPU_logic_op_xor_set(bool enable); 128 void GPU_point_size(float size); 129 void GPU_polygon_smooth(bool enable); 130 void GPU_program_point_size(bool enable); 131 void GPU_scissor(int x, int y, int width, int height); 132 void GPU_scissor_get(int coords[4]); 133 void GPU_viewport(int x, int y, int width, int height); 134 void GPU_viewport_size_get_f(float coords[4]); 135 void GPU_viewport_size_get_i(int coords[4]); 136 void GPU_write_mask(eGPUWriteMask mask); 137 void GPU_color_mask(bool r, bool g, bool b, bool a); 138 void GPU_depth_mask(bool depth); 139 bool GPU_depth_mask_get(void); 140 void GPU_shadow_offset(bool enable); 141 void GPU_clip_distances(int distances_enabled); 142 bool GPU_mipmap_enabled(void); 143 void GPU_state_set(eGPUWriteMask write_mask, 144 eGPUBlend blend, 145 eGPUFaceCullTest culling_test, 146 eGPUDepthTest depth_test, 147 eGPUStencilTest stencil_test, 148 eGPUStencilOp stencil_op, 149 eGPUProvokingVertex provoking_vert); 150 151 void GPU_stencil_reference_set(uint reference); 152 void GPU_stencil_write_mask_set(uint write_mask); 153 void GPU_stencil_compare_mask_set(uint compare_mask); 154 155 eGPUBlend GPU_blend_get(void); 156 eGPUDepthTest GPU_depth_test_get(void); 157 eGPUWriteMask GPU_write_mask_get(void); 158 uint GPU_stencil_mask_get(void); 159 eGPUStencilTest GPU_stencil_test_get(void); 160 float GPU_line_width_get(void); 161 162 void GPU_flush(void); 163 void GPU_finish(void); 164 void GPU_apply_state(void); 165 166 void GPU_bgl_start(void); 167 void GPU_bgl_end(void); 168 bool GPU_bgl_get(void); 169 170 void GPU_memory_barrier(eGPUBarrier barrier); 171 172 #ifdef __cplusplus 173 } 174 #endif 175