48 glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
54 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
55 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
57 glPrimitiveRestartIndex((GLuint)0xFFFFFFFF);
61 glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
65 glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, line_width_range_);
77 this->set_state(this->
state);
79 this->texture_bind_apply();
80 this->image_bind_apply();
91 current_ = ~this->state;
93 current_mutable_ = ~this->mutable_state;
94 this->set_state(this->
state);
102 if (changed.
blend != 0) {
155 void GLStateManager::set_mutable_state(
const GPUStateMutable &
state)
157 GPUStateMutable changed =
state ^ current_mutable_;
161 if (
state.point_size > 0.0f) {
170 if (changed.line_width != 0) {
172 glLineWidth(
clamp_f(
state.line_width, line_width_range_[0], line_width_range_[1]));
175 if (changed.depth_range[0] != 0 || changed.depth_range[1] != 0) {
180 if (changed.stencil_compare_mask != 0 || changed.stencil_reference != 0 ||
181 changed.stencil_write_mask != 0) {
185 current_mutable_ =
state;
194 void GLStateManager::set_write_mask(
const eGPUWriteMask value)
210 void GLStateManager::set_depth_test(
const eGPUDepthTest value)
248 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
251 glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
252 glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR_WRAP);
255 glStencilOpSeparate(GL_BACK, GL_KEEP, GL_DECR_WRAP, GL_KEEP);
256 glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
260 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
287 glStencilFunc(GL_ALWAYS, 0x00, 0x00);
291 glStencilMask(
state.stencil_write_mask);
292 glStencilFunc(func,
state.stencil_reference,
state.stencil_compare_mask);
295 void GLStateManager::set_clip_distances(
const int new_dist_len,
const int old_dist_len)
297 for (
int i = 0; i < new_dist_len; i++) {
300 for (
int i = new_dist_len; i < old_dist_len; i++) {
305 void GLStateManager::set_logic_op(
const bool enable)
316 void GLStateManager::set_facing(
const bool invert)
318 glFrontFace((
invert) ? GL_CW : GL_CCW);
335 GL_LAST_VERTEX_CONVENTION;
336 glProvokingVertex(value);
339 void GLStateManager::set_shadow_bias(
const bool enable)
345 glPolygonOffset(2.0f, 1.0f);
353 void GLStateManager::set_blend(
const eGPUBlend value)
362 GLenum src_rgb, src_alpha, dst_rgb, dst_alpha;
366 src_rgb = GL_SRC_ALPHA;
367 dst_rgb = GL_ONE_MINUS_SRC_ALPHA;
369 dst_alpha = GL_ONE_MINUS_SRC_ALPHA;
374 dst_rgb = GL_ONE_MINUS_SRC_ALPHA;
376 dst_alpha = GL_ONE_MINUS_SRC_ALPHA;
381 src_rgb = GL_SRC_ALPHA;
397 src_rgb = GL_DST_COLOR;
399 src_alpha = GL_DST_ALPHA;
404 src_rgb = GL_ONE_MINUS_DST_COLOR;
414 dst_alpha = GL_ONE_MINUS_SRC_ALPHA;
418 src_rgb = GL_ONE_MINUS_DST_ALPHA;
419 dst_rgb = GL_SRC_ALPHA;
421 dst_alpha = GL_SRC_ALPHA;
425 src_rgb = GL_ONE_MINUS_DST_ALPHA;
427 src_alpha = GL_ONE_MINUS_DST_ALPHA;
433 dst_rgb = GL_SRC1_COLOR;
435 dst_alpha = GL_SRC1_ALPHA;
441 glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
444 glBlendEquation(GL_FUNC_ADD);
450 glBlendFuncSeparate(src_rgb, dst_rgb, src_alpha, dst_alpha);
470 tex->check_feedback_loop();
473 if ((textures_[unit] ==
tex->tex_id_) &&
474 (samplers_[unit] == GLTexture::samplers_[sampler_type])) {
477 targets_[unit] =
tex->target_;
478 textures_[unit] =
tex->tex_id_;
479 samplers_[unit] = GLTexture::samplers_[sampler_type];
480 tex->is_bound_ =
true;
481 dirty_texture_binds_ |= 1ULL << unit;
487 glActiveTexture(GL_TEXTURE0);
488 glBindTexture(
tex->target_,
tex->tex_id_);
490 dirty_texture_binds_ |= 1ULL;
499 if (!
tex->is_bound_) {
503 GLuint tex_id =
tex->tex_id_;
504 for (
int i = 0; i <
ARRAY_SIZE(textures_); i++) {
505 if (textures_[i] == tex_id) {
508 dirty_texture_binds_ |= 1ULL << i;
511 tex->is_bound_ =
false;
516 for (
int i = 0; i <
ARRAY_SIZE(textures_); i++) {
517 if (textures_[i] != 0) {
520 dirty_texture_binds_ |= 1ULL << i;
523 this->texture_bind_apply();
526 void GLStateManager::texture_bind_apply()
528 if (dirty_texture_binds_ == 0) {
531 uint64_t dirty_bind = dirty_texture_binds_;
532 dirty_texture_binds_ = 0;
536 int count = last - first;
539 glBindTextures(first,
count, textures_ + first);
540 glBindSamplers(first,
count, samplers_ + first);
543 for (
int unit = first; unit < last; unit++) {
544 if ((dirty_bind >> unit) & 1UL) {
545 glActiveTexture(GL_TEXTURE0 + unit);
546 glBindTexture(targets_[unit], textures_[unit]);
547 glBindSampler(unit, samplers_[unit]);
555 glPixelStorei(GL_UNPACK_ROW_LENGTH,
len);
561 for (
int i = 0; i <
ARRAY_SIZE(textures_); i++) {
562 if (textures_[i] != 0) {
563 bound_slots |= 1ULL << i;
581 tex->check_feedback_loop();
583 images_[unit] =
tex->tex_id_;
585 tex->is_bound_ =
true;
586 dirty_image_binds_ |= 1ULL << unit;
592 if (!
tex->is_bound_) {
596 GLuint tex_id =
tex->tex_id_;
597 for (
int i = 0; i <
ARRAY_SIZE(images_); i++) {
598 if (images_[i] == tex_id) {
600 dirty_image_binds_ |= 1ULL << i;
603 tex->is_bound_ =
false;
608 for (
int i = 0; i <
ARRAY_SIZE(images_); i++) {
609 if (images_[i] != 0) {
611 dirty_image_binds_ |= 1ULL << i;
614 this->image_bind_apply();
617 void GLStateManager::image_bind_apply()
619 if (dirty_image_binds_ == 0) {
622 uint32_t dirty_bind = dirty_image_binds_;
623 dirty_image_binds_ = 0;
627 int count = last - first;
630 glBindImageTextures(first,
count, images_ + first);
633 for (
int unit = first; unit < last; unit++) {
634 if ((dirty_bind >> unit) & 1UL) {
635 glBindImageTexture(unit, images_[unit], 0, GL_TRUE, 0, GL_READ_WRITE, formats_[unit]);
644 for (
int i = 0; i <
ARRAY_SIZE(images_); i++) {
645 if (images_[i] != 0) {
646 bound_slots |= 1ULL << i;
660 glMemoryBarrier(
to_gl(barrier_bits));
MINLINE float clamp_f(float value, float min, float max)
MINLINE unsigned int bitscan_forward_uint(unsigned int a)
MINLINE unsigned int float_as_uint(float f)
MINLINE unsigned int bitscan_reverse_uint(unsigned int a)
MINLINE unsigned int bitscan_forward_uint64(unsigned long long a)
MINLINE unsigned int bitscan_reverse_uint64(unsigned long long a)
bool GPU_shader_image_load_store_support(void)
int GPU_max_textures(void)
@ GPU_BLEND_ADDITIVE_PREMULT
@ GPU_BLEND_ALPHA_UNDER_PREMUL
@ GPU_BLEND_ALPHA_PREMULT
@ GPU_STENCIL_OP_COUNT_DEPTH_FAIL
@ GPU_STENCIL_OP_COUNT_DEPTH_PASS
@ GPU_DEPTH_GREATER_EQUAL
static bool fixed_restart_index_support
static bool multi_bind_support
void texture_bind_temp(GLTexture *tex)
GLFrameBuffer * active_fb
void image_unbind(Texture *tex) override
uint8_t bound_image_slots(void)
void image_bind(Texture *tex, int unit) override
uint64_t bound_texture_slots(void)
void texture_unpack_row_length_set(uint len) override
void apply_state(void) override
void force_state(void) override
void issue_barrier(eGPUBarrier barrier_bits) override
void texture_bind(Texture *tex, eGPUSamplerState sampler, int unit) override
void texture_unbind_all(void) override
void image_unbind_all(void) override
void texture_unbind(Texture *tex) override
GPUStateMutable mutable_state
GLenum to_gl_internal_format(eGPUTextureFormat format)
static GLenum to_gl(const GPUAttachmentType type)
unsigned __int64 uint64_t
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)