void init_select() { /* Initialize matrix and array vector for a select_Draw* */ GLfloat tmp[16]; gl4es_glGetFloatv(GL_PROJECTION_MATRIX, tmp); matrix_transpose(tmp, projection); gl4es_glGetFloatv(GL_MODELVIEW_MATRIX, tmp); matrix_transpose(tmp, modelview); }
void gl4es_glPushAttrib(GLbitfield mask) { //printf("glPushAttrib(0x%04X)\n", mask); noerrorShim(); if ((glstate->list.compiling || glstate->gl_batch) && glstate->list.active) { NewStage(glstate->list.active, STAGE_PUSH); glstate->list.active->pushattribute = mask; return; } if (glstate->stack == NULL) { glstate->stack = (glstack_t *)malloc(STACK_SIZE * sizeof(glstack_t)); glstate->stack->len = 0; glstate->stack->cap = STACK_SIZE; } else if (glstate->stack->len == glstate->stack->cap) { glstate->stack->cap += STACK_SIZE; glstate->stack = (glstack_t *)realloc(glstate->stack, glstate->stack->cap * sizeof(glstack_t)); } glstack_t *cur = glstate->stack + glstate->stack->len; cur->mask = mask; cur->clip_planes_enabled = NULL; cur->clip_planes = NULL; cur->lights_enabled = NULL; cur->lights = NULL; cur->materials = NULL; // TODO: GL_ACCUM_BUFFER_BIT // TODO: will tracking these myself be much faster than glGet? if (mask & GL_COLOR_BUFFER_BIT) { cur->alpha_test = gl4es_glIsEnabled(GL_ALPHA_TEST); gl4es_glGetIntegerv(GL_ALPHA_TEST_FUNC, &cur->alpha_test_func); gl4es_glGetFloatv(GL_ALPHA_TEST_REF, &cur->alpha_test_ref); cur->blend = gl4es_glIsEnabled(GL_BLEND); gl4es_glGetIntegerv(GL_BLEND_SRC, &cur->blend_src_func); gl4es_glGetIntegerv(GL_BLEND_DST, &cur->blend_dst_func); cur->dither = gl4es_glIsEnabled(GL_DITHER); cur->color_logic_op = gl4es_glIsEnabled(GL_COLOR_LOGIC_OP); gl4es_glGetIntegerv(GL_LOGIC_OP_MODE, &cur->logic_op); gl4es_glGetFloatv(GL_COLOR_CLEAR_VALUE, cur->clear_color); gl4es_glGetFloatv(GL_COLOR_WRITEMASK, cur->color_mask); } if (mask & GL_CURRENT_BIT) { gl4es_glGetFloatv(GL_CURRENT_COLOR, cur->color); gl4es_glGetFloatv(GL_CURRENT_NORMAL, cur->normal); gl4es_glGetFloatv(GL_CURRENT_TEXTURE_COORDS, cur->tex); } if (mask & GL_DEPTH_BUFFER_BIT) { cur->depth_test = gl4es_glIsEnabled(GL_DEPTH_TEST); gl4es_glGetIntegerv(GL_DEPTH_FUNC, &cur->depth_func); gl4es_glGetFloatv(GL_DEPTH_CLEAR_VALUE, &cur->clear_depth); gl4es_glGetIntegerv(GL_DEPTH_WRITEMASK, &cur->depth_mask); } if (mask & GL_ENABLE_BIT) { int i; GLint max_clip_planes; cur->alpha_test = gl4es_glIsEnabled(GL_ALPHA_TEST); cur->autonormal = gl4es_glIsEnabled(GL_AUTO_NORMAL); cur->blend = gl4es_glIsEnabled(GL_BLEND); gl4es_glGetIntegerv(GL_MAX_CLIP_PLANES, &max_clip_planes); cur->clip_planes_enabled = (GLboolean *)malloc(max_clip_planes * sizeof(GLboolean)); for (i = 0; i < max_clip_planes; i++) { *(cur->clip_planes_enabled + i) = gl4es_glIsEnabled(GL_CLIP_PLANE0 + i); } cur->colormaterial = gl4es_glIsEnabled(GL_COLOR_MATERIAL); cur->cull_face = gl4es_glIsEnabled(GL_CULL_FACE); cur->depth_test = gl4es_glIsEnabled(GL_DEPTH_TEST); cur->dither = gl4es_glIsEnabled(GL_DITHER); cur->fog = gl4es_glIsEnabled(GL_FOG); cur->lights_enabled = (GLboolean *)malloc(hardext.maxlights * sizeof(GLboolean)); for (i = 0; i < hardext.maxlights; i++) { *(cur->lights_enabled + i) = gl4es_glIsEnabled(GL_LIGHT0 + i); } cur->lighting = gl4es_glIsEnabled(GL_LIGHTING); cur->line_smooth = gl4es_glIsEnabled(GL_LINE_SMOOTH); cur->line_stipple = gl4es_glIsEnabled(GL_LINE_STIPPLE); cur->color_logic_op = gl4es_glIsEnabled(GL_COLOR_LOGIC_OP); //TODO: GL_INDEX_LOGIC_OP //TODO: GL_MAP1_x //TODO: GL_MAP2_x cur->multisample = gl4es_glIsEnabled(GL_MULTISAMPLE); cur->normalize = gl4es_glIsEnabled(GL_NORMALIZE); cur->point_smooth = gl4es_glIsEnabled(GL_POINT_SMOOTH); //TODO: GL_POLYGON_OFFSET_LINE cur->polygon_offset_fill = gl4es_glIsEnabled(GL_POLYGON_OFFSET_FILL); //TODO: GL_POLYGON_OFFSET_POINT //TODO: GL_POLYGON_SMOOTH //TODO: GL_POLYGON_STIPPLE cur->sample_alpha_to_coverage = gl4es_glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE); cur->sample_alpha_to_one = gl4es_glIsEnabled(GL_SAMPLE_ALPHA_TO_ONE); cur->sample_coverage = gl4es_glIsEnabled(GL_SAMPLE_COVERAGE); cur->scissor_test = gl4es_glIsEnabled(GL_SCISSOR_TEST); cur->stencil_test = gl4es_glIsEnabled(GL_STENCIL_TEST); int a; for (a=0; a<hardext.maxtex; a++) { cur->tex_enabled[a] = glstate->enable.texture[a]; cur->texgen_s[a] = glstate->enable.texgen_s[a]; cur->texgen_r[a] = glstate->enable.texgen_r[a]; cur->texgen_t[a] = glstate->enable.texgen_t[a]; cur->texgen_q[a] = glstate->enable.texgen_q[a]; } cur->pointsprite = gl4es_glIsEnabled(GL_POINT_SPRITE); } // TODO: GL_EVAL_BIT if (mask & GL_FOG_BIT) { cur->fog = gl4es_glIsEnabled(GL_FOG); gl4es_glGetFloatv(GL_FOG_COLOR, cur->fog_color); gl4es_glGetFloatv(GL_FOG_DENSITY, &cur->fog_density); gl4es_glGetFloatv(GL_FOG_START, &cur->fog_start); gl4es_glGetFloatv(GL_FOG_END, &cur->fog_end); gl4es_glGetIntegerv(GL_FOG_MODE, &cur->fog_mode); } if (mask & GL_HINT_BIT) { gl4es_glGetIntegerv(GL_PERSPECTIVE_CORRECTION_HINT, &cur->perspective_hint); gl4es_glGetIntegerv(GL_POINT_SMOOTH_HINT, &cur->point_smooth_hint); gl4es_glGetIntegerv(GL_LINE_SMOOTH_HINT, &cur->line_smooth_hint); gl4es_glGetIntegerv(GL_FOG_HINT, &cur->fog_hint); gl4es_glGetIntegerv(GL_GENERATE_MIPMAP_HINT, &cur->mipmap_hint); for (int i=GL4ES_HINT_FIRST; i<GL4ES_HINT_LAST; i++) gl4es_glGetIntegerv(i, &cur->gles4_hint[i-GL4ES_HINT_FIRST]); } if (mask & GL_LIGHTING_BIT) { cur->lighting = gl4es_glIsEnabled(GL_LIGHTING); gl4es_glGetFloatv(GL_LIGHT_MODEL_AMBIENT, cur->light_model_ambient); gl4es_glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE, &cur->light_model_two_side); int i; int j=0; cur->lights_enabled = (GLboolean *)malloc(hardext.maxlights * sizeof(GLboolean)); cur->lights = (GLfloat *)malloc(hardext.maxlights * sizeof(GLfloat)*(10*4)); for (i = 0; i < hardext.maxlights; i++) { *(cur->lights_enabled + i) = gl4es_glIsEnabled(GL_LIGHT0 + i); #define L(A) gl4es_glGetLightfv(GL_LIGHT0 + i, A, cur->lights+j); j+=4 L(GL_AMBIENT); L(GL_DIFFUSE); L(GL_SPECULAR); L(GL_POSITION); L(GL_SPOT_CUTOFF); L(GL_SPOT_DIRECTION); L(GL_SPOT_EXPONENT); L(GL_CONSTANT_ATTENUATION); L(GL_LINEAR_ATTENUATION); L(GL_QUADRATIC_ATTENUATION); #undef L } j=0; cur->materials = (GLfloat *)malloc(1 * sizeof(GLfloat)*(5*4)); #define M(A) gl4es_glGetMaterialfv(GL_FRONT, A, cur->materials+j); j+=4 M(GL_AMBIENT); M(GL_DIFFUSE); M(GL_SPECULAR); M(GL_EMISSION); M(GL_SHININESS); // handle both face at some point? #undef M gl4es_glGetIntegerv(GL_SHADE_MODEL, &cur->shade_model); } if (mask & GL_LINE_BIT) { cur->line_smooth = gl4es_glIsEnabled(GL_LINE_SMOOTH); // TODO: stipple stuff here gl4es_glGetFloatv(GL_LINE_WIDTH, &cur->line_width); } // GL_LIST_BIT if (mask & GL_LIST_BIT) { cur->list_base = glstate->list.base; } if (mask & GL_MULTISAMPLE_BIT) { cur->multisample = gl4es_glIsEnabled(GL_MULTISAMPLE); cur->sample_alpha_to_coverage = gl4es_glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE); cur->sample_alpha_to_one = gl4es_glIsEnabled(GL_SAMPLE_ALPHA_TO_ONE); cur->sample_coverage = gl4es_glIsEnabled(GL_SAMPLE_COVERAGE); } // GL_PIXEL_MODE_BIT if (mask & GL_PIXEL_MODE_BIT) { GLenum pixel_name[] = {GL_RED_BIAS, GL_RED_SCALE, GL_GREEN_BIAS, GL_GREEN_SCALE, GL_BLUE_BIAS, GL_BLUE_SCALE, GL_ALPHA_BIAS, GL_ALPHA_SCALE}; int i; for (i=0; i<8; i++) gl4es_glGetFloatv(pixel_name[i], &cur->pixel_scale_bias[i]); //TODO: GL_DEPTH_BIAS & GL_DEPTH_SCALE (probably difficult) //TODO: GL_INDEX_OFFEST & GL_INDEX_SHIFT //TODO: GL_MAP_COLOR & GL_MAP_STENCIL (probably difficult too) gl4es_glGetFloatv(GL_ZOOM_X, &cur->pixel_zoomx); gl4es_glGetFloatv(GL_ZOOM_Y, &cur->pixel_zoomy); } if (mask & GL_POINT_BIT) { cur->point_smooth = gl4es_glIsEnabled(GL_POINT_SMOOTH); gl4es_glGetFloatv(GL_POINT_SIZE, &cur->point_size); if(hardext.pointsprite) { cur->pointsprite = gl4es_glIsEnabled(GL_POINT_SPRITE); int a; for (a=0; a<hardext.maxtex; a++) { cur->pscoordreplace[a] = glstate->texture.pscoordreplace[a]; } } } // TODO: GL_POLYGON_BIT // TODO: GL_POLYGON_STIPPLE_BIT if (mask & GL_SCISSOR_BIT) { cur->scissor_test = gl4es_glIsEnabled(GL_SCISSOR_TEST); gl4es_glGetFloatv(GL_SCISSOR_BOX, cur->scissor_box); } // TODO: GL_STENCIL_BUFFER_BIT if (mask & GL_STENCIL_BUFFER_BIT) { cur->stencil_test = gl4es_glIsEnabled(GL_STENCIL_TEST); gl4es_glGetIntegerv(GL_STENCIL_FUNC, &cur->stencil_func); gl4es_glGetIntegerv(GL_STENCIL_VALUE_MASK, &cur->stencil_mask); gl4es_glGetIntegerv(GL_STENCIL_REF, &cur->stencil_ref); //TODO: glStencilFuncSeperate //TODO: Stencil value mask gl4es_glGetIntegerv(GL_STENCIL_FAIL, &cur->stencil_sfail); gl4es_glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, &cur->stencil_dpfail); gl4es_glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, &cur->stencil_dppass); //TODO: glStencilOpSeparate gl4es_glGetIntegerv(GL_STENCIL_CLEAR_VALUE, &cur->stencil_clearvalue); //TODO: Stencil buffer writemask } // GL_TEXTURE_BIT - TODO: incomplete if (mask & GL_TEXTURE_BIT) { cur->active=glstate->texture.active; int a; for (a=0; a<hardext.maxtex; a++) { cur->texgen_r[a] = glstate->enable.texgen_r[a]; cur->texgen_s[a] = glstate->enable.texgen_s[a]; cur->texgen_t[a] = glstate->enable.texgen_t[a]; cur->texgen_q[a] = glstate->enable.texgen_q[a]; cur->texgen[a] = glstate->texgen[a]; // all mode and planes per texture in 1 line for (int j=0; j<ENABLED_TEXTURE_LAST; j++) cur->texture[a][j] = (glstate->texture.bound[a][j])?glstate->texture.bound[a][j]->texture:0; } //glActiveTexture(GL_TEXTURE0+cur->active); } // GL_TRANSFORM_BIT if (mask & GL_TRANSFORM_BIT) { if (!(mask & GL_ENABLE_BIT)) { int i; GLint max_clip_planes; gl4es_glGetIntegerv(GL_MAX_CLIP_PLANES, &max_clip_planes); cur->clip_planes_enabled = (GLboolean *)malloc(max_clip_planes * sizeof(GLboolean)); for (i = 0; i < max_clip_planes; i++) { *(cur->clip_planes_enabled + i) = gl4es_glIsEnabled(GL_CLIP_PLANE0 + i); } } gl4es_glGetIntegerv(GL_MATRIX_MODE, &cur->matrix_mode); cur->rescale_normal_flag = gl4es_glIsEnabled(GL_RESCALE_NORMAL); cur->normalize_flag = gl4es_glIsEnabled(GL_NORMALIZE); } // GL_VIEWPORT_BIT if (mask & GL_VIEWPORT_BIT) { gl4es_glGetIntegerv(GL_VIEWPORT, cur->viewport_size); gl4es_glGetFloatv(GL_DEPTH_RANGE, cur->depth_range); } glstate->stack->len++; }