30 glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
36 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
37 glPixelStorei(GL_PACK_ALIGNMENT, 1);
38 glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
40 glPrimitiveRestartIndex((GLuint)0xFFFFFFFF);
44 glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
48 glGetFloatv(GL_ALIASED_LINE_WIDTH_RANGE, line_width_range_);
60 this->set_state(this->
state);
62 this->texture_bind_apply();
63 this->image_bind_apply();
73 current_ = ~this->state;
75 current_mutable_ = ~this->mutable_state;
76 this->set_state(this->
state);
84 if (changed.
blend != 0) {
137 void GLStateManager::set_mutable_state(
const GPUStateMutable &
state)
139 GPUStateMutable changed =
state ^ current_mutable_;
143 if (
state.point_size > 0.0f) {
154 glLineWidth(
clamp_f(
state.line_width, line_width_range_[0], line_width_range_[1]));
162 if (changed.stencil_compare_mask != 0 || changed.stencil_reference != 0 ||
163 changed.stencil_write_mask != 0) {
167 current_mutable_ =
state;
176 void GLStateManager::set_write_mask(
const eGPUWriteMask value)
192 void GLStateManager::set_depth_test(
const eGPUDepthTest value)
230 glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
233 glStencilOpSeparate(GL_BACK, GL_KEEP, GL_KEEP, GL_INCR_WRAP);
234 glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_KEEP, GL_DECR_WRAP);
237 glStencilOpSeparate(GL_BACK, GL_KEEP, GL_DECR_WRAP, GL_KEEP);
238 glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
242 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
269 glStencilFunc(GL_ALWAYS, 0x00, 0x00);
273 glStencilMask(
state.stencil_write_mask);
274 glStencilFunc(func,
state.stencil_reference,
state.stencil_compare_mask);
277 void GLStateManager::set_clip_distances(
const int new_dist_len,
const int old_dist_len)
279 for (
int i = 0; i < new_dist_len; i++) {
282 for (
int i = new_dist_len; i < old_dist_len; i++) {
287 void GLStateManager::set_logic_op(
const bool enable)
298 void GLStateManager::set_facing(
const bool invert)
300 glFrontFace((
invert) ? GL_CW : GL_CCW);
317 GL_LAST_VERTEX_CONVENTION;
318 glProvokingVertex(value);
321 void GLStateManager::set_shadow_bias(
const bool enable)
327 glPolygonOffset(2.0f, 1.0f);
335 void GLStateManager::set_blend(
const eGPUBlend value)
344 GLenum src_rgb, src_alpha, dst_rgb, dst_alpha;
348 src_rgb = GL_SRC_ALPHA;
349 dst_rgb = GL_ONE_MINUS_SRC_ALPHA;
351 dst_alpha = GL_ONE_MINUS_SRC_ALPHA;
356 dst_rgb = GL_ONE_MINUS_SRC_ALPHA;
358 dst_alpha = GL_ONE_MINUS_SRC_ALPHA;
363 src_rgb = GL_SRC_ALPHA;
379 src_rgb = GL_DST_COLOR;
381 src_alpha = GL_DST_ALPHA;
386 src_rgb = GL_ONE_MINUS_DST_COLOR;
396 dst_alpha = GL_ONE_MINUS_SRC_ALPHA;
400 src_rgb = GL_ONE_MINUS_DST_ALPHA;
401 dst_rgb = GL_SRC_ALPHA;
403 dst_alpha = GL_SRC_ALPHA;
407 src_rgb = GL_ONE_MINUS_DST_ALPHA;
409 src_alpha = GL_ONE_MINUS_DST_ALPHA;
415 dst_rgb = GL_SRC1_COLOR;
417 dst_alpha = GL_SRC1_ALPHA;
423 glBlendEquation(GL_FUNC_REVERSE_SUBTRACT);
426 glBlendEquation(GL_FUNC_ADD);
432 glBlendFuncSeparate(src_rgb, dst_rgb, src_alpha, dst_alpha);
452 tex->check_feedback_loop();
455 if ((textures_[unit] ==
tex->tex_id_) &&
456 (samplers_[unit] == GLTexture::samplers_[sampler_type])) {
459 targets_[unit] =
tex->target_;
460 textures_[unit] =
tex->tex_id_;
461 samplers_[unit] = GLTexture::samplers_[sampler_type];
462 tex->is_bound_ =
true;
463 dirty_texture_binds_ |= 1ULL << unit;
468 glActiveTexture(GL_TEXTURE0);
469 glBindTexture(
tex->target_,
tex->tex_id_);
471 dirty_texture_binds_ |= 1ULL;
480 if (!
tex->is_bound_) {
484 GLuint tex_id =
tex->tex_id_;
485 for (
int i = 0; i <
ARRAY_SIZE(textures_); i++) {
486 if (textures_[i] == tex_id) {
489 dirty_texture_binds_ |= 1ULL << i;
492 tex->is_bound_ =
false;
497 for (
int i = 0; i <
ARRAY_SIZE(textures_); i++) {
498 if (textures_[i] != 0) {
501 dirty_texture_binds_ |= 1ULL << i;
504 this->texture_bind_apply();
507 void GLStateManager::texture_bind_apply()
509 if (dirty_texture_binds_ == 0) {
512 uint64_t dirty_bind = dirty_texture_binds_;
513 dirty_texture_binds_ = 0;
517 int count = last - first;
520 glBindTextures(first,
count, textures_ + first);
521 glBindSamplers(first,
count, samplers_ + first);
524 for (
int unit = first; unit < last; unit++) {
525 if ((dirty_bind >> unit) & 1UL) {
526 glActiveTexture(GL_TEXTURE0 + unit);
527 glBindTexture(targets_[unit], textures_[unit]);
528 glBindSampler(unit, samplers_[unit]);
536 glPixelStorei(GL_UNPACK_ROW_LENGTH,
len);
542 for (
int i = 0; i <
ARRAY_SIZE(textures_); i++) {
543 if (textures_[i] != 0) {
544 bound_slots |= 1ULL << i;
562 tex->check_feedback_loop();
564 images_[unit] =
tex->tex_id_;
566 tex->is_bound_ =
true;
567 dirty_image_binds_ |= 1ULL << unit;
573 if (!
tex->is_bound_) {
577 GLuint tex_id =
tex->tex_id_;
578 for (
int i = 0; i <
ARRAY_SIZE(images_); i++) {
579 if (images_[i] == tex_id) {
581 dirty_image_binds_ |= 1ULL << i;
584 tex->is_bound_ =
false;
589 for (
int i = 0; i <
ARRAY_SIZE(images_); i++) {
590 if (images_[i] != 0) {
592 dirty_image_binds_ |= 1ULL << i;
595 this->image_bind_apply();
598 void GLStateManager::image_bind_apply()
600 if (dirty_image_binds_ == 0) {
603 uint32_t dirty_bind = dirty_image_binds_;
604 dirty_image_binds_ = 0;
608 int count = last - first;
611 glBindImageTextures(first,
count, images_ + first);
614 for (
int unit = first; unit < last; unit++) {
615 if ((dirty_bind >> unit) & 1UL) {
616 glBindImageTexture(unit, images_[unit], 0, GL_TRUE, 0, GL_READ_WRITE, formats_[unit]);
625 for (
int i = 0; i <
ARRAY_SIZE(images_); i++) {
626 if (images_[i] != 0) {
627 bound_slots |= 1ULL << i;
641 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
void image_bind(Texture *tex, int unit) override
void apply_state() override
void texture_unpack_row_length_set(uint len) override
void issue_barrier(eGPUBarrier barrier_bits) override
void texture_unbind_all() override
uint8_t bound_image_slots()
void texture_bind(Texture *tex, eGPUSamplerState sampler, int unit) override
void force_state() override
uint64_t bound_texture_slots()
void image_unbind_all() override
void texture_unbind(Texture *tex) override
GPUStateMutable mutable_state
CCL_NAMESPACE_BEGIN ccl_device float invert(float color, float factor)
GLenum to_gl_internal_format(eGPUTextureFormat format)
static GLenum to_gl(const GPUAttachmentType type)
unsigned __int64 uint64_t