Changeset View
Changeset View
Standalone View
Standalone View
source/blender/gpu/intern/gpu_immediate.c
| Context not available. | |||||
| uint16_t prev_enabled_attr_bits; /* <-- only affects this VAO, so we're ok */ | uint16_t prev_enabled_attr_bits; /* <-- only affects this VAO, so we're ok */ | ||||
| } Immediate; | } Immediate; | ||||
| /* size of internal buffer -- make this adjustable? */ | /* size of internal buffer */ | ||||
| #define IMM_BUFFER_SIZE (4 * 1024 * 1024) | #define DEFAULT_INTERNAL_BUFFER_SIZE (4 * 1024 * 1024) | ||||
| static uint imm_buffer_size = DEFAULT_INTERNAL_BUFFER_SIZE; | |||||
| static bool initialized = false; | static bool initialized = false; | ||||
| static Immediate imm; | static Immediate imm; | ||||
| Context not available. | |||||
| imm.vbo_id = GPU_buf_alloc(); | imm.vbo_id = GPU_buf_alloc(); | ||||
| glBindBuffer(GL_ARRAY_BUFFER, imm.vbo_id); | glBindBuffer(GL_ARRAY_BUFFER, imm.vbo_id); | ||||
| glBufferData(GL_ARRAY_BUFFER, IMM_BUFFER_SIZE, NULL, GL_DYNAMIC_DRAW); | glBufferData(GL_ARRAY_BUFFER, imm_buffer_size, NULL, GL_DYNAMIC_DRAW); | ||||
| imm.prim_type = GPU_PRIM_NONE; | imm.prim_type = GPU_PRIM_NONE; | ||||
| imm.strict_vertex_len = true; | imm.strict_vertex_len = true; | ||||
| Context not available. | |||||
| glUseProgram(0); | glUseProgram(0); | ||||
| #endif | #endif | ||||
| imm.bound_program = 0; | imm.bound_program = 0; | ||||
| /* shrink the internal buffer to default size */ | |||||
| imm_buffer_size = DEFAULT_INTERNAL_BUFFER_SIZE; | |||||
| } | } | ||||
| #if TRUST_NO_ONE | #if TRUST_NO_ONE | ||||
| Context not available. | |||||
| /* how many bytes do we need for this draw call? */ | /* how many bytes do we need for this draw call? */ | ||||
| const uint bytes_needed = vertex_buffer_size(&imm.vertex_format, vertex_len); | const uint bytes_needed = vertex_buffer_size(&imm.vertex_format, vertex_len); | ||||
| #if TRUST_NO_ONE | if (bytes_needed > imm_buffer_size) { | ||||
| assert(bytes_needed <= IMM_BUFFER_SIZE); | imm_buffer_size = bytes_needed; | ||||
| #endif | } | ||||
| glBindBuffer(GL_ARRAY_BUFFER, imm.vbo_id); | glBindBuffer(GL_ARRAY_BUFFER, imm.vbo_id); | ||||
| /* does the current buffer have enough room? */ | /* does the current buffer have enough room? */ | ||||
| const uint available_bytes = IMM_BUFFER_SIZE - imm.buffer_offset; | uint available_bytes; | ||||
| if (imm.buffer_offset > imm_buffer_size) { | |||||
| /* the internal buffer has shrinked */ | |||||
| /* we need a fresh buffer with shrinked size */ | |||||
| available_bytes = 0; | |||||
| } | |||||
| else { | |||||
| available_bytes = imm_buffer_size - imm.buffer_offset; | |||||
| } | |||||
| /* ensure vertex data is aligned */ | /* ensure vertex data is aligned */ | ||||
| /* Might waste a little space, but it's safe. */ | /* Might waste a little space, but it's safe. */ | ||||
| Context not available. | |||||
| else { | else { | ||||
| /* orphan this buffer & start with a fresh one */ | /* orphan this buffer & start with a fresh one */ | ||||
| /* this method works on all platforms, old & new */ | /* this method works on all platforms, old & new */ | ||||
| glBufferData(GL_ARRAY_BUFFER, IMM_BUFFER_SIZE, NULL, GL_DYNAMIC_DRAW); | glBufferData(GL_ARRAY_BUFFER, imm_buffer_size, NULL, GL_DYNAMIC_DRAW); | ||||
| imm.buffer_offset = 0; | imm.buffer_offset = 0; | ||||
| } | } | ||||
| Context not available. | |||||