static void materialx(GLenum face, GLenum pname, GLfixed param, ogles_context_t* c) { if (ggl_unlikely(face != GL_FRONT_AND_BACK)) { ogles_error(c, GL_INVALID_ENUM); return; } if (ggl_unlikely(pname != GL_SHININESS)) { ogles_error(c, GL_INVALID_ENUM); return; } c->lighting.front.shininess = param; invalidate_lighting(c); }
void ogles_viewport(ogles_context_t* c, GLint x, GLint y, GLsizei w, GLsizei h) { if ((w|h)<0) { ogles_error(c, GL_INVALID_VALUE); return; } c->viewport.x = x; c->viewport.y = y; c->viewport.w = w; c->viewport.h = h; x += c->viewport.surfaceport.x; y += c->viewport.surfaceport.y; GLint H = c->rasterizer.state.buffers.color.height; GLfloat sx = div2f(w); GLfloat ox = sx + x; GLfloat sy = div2f(h); GLfloat oy = sy - y + (H - h); GLfloat near = c->transforms.vpt.zNear; GLfloat far = c->transforms.vpt.zFar; GLfloat A = div2f(far - near); GLfloat B = div2f(far + near); // compute viewport matrix GLfloat* const f = c->transforms.vpt.matrix.editElements(); f[0] = sx; f[4] = 0; f[ 8] = 0; f[12] = ox; f[1] = 0; f[5] =-sy; f[ 9] = 0; f[13] = oy; f[2] = 0; f[6] = 0; f[10] = A; f[14] = B; f[3] = 0; f[7] = 0; f[11] = 0; f[15] = 1; c->transforms.dirty |= transform_state_t::VIEWPORT; }
static void lightModelx(GLenum pname, GLfixed param, ogles_context_t* c) { if (ggl_unlikely(pname != GL_LIGHT_MODEL_TWO_SIDE)) { ogles_error(c, GL_INVALID_ENUM); return; } c->lighting.lightModel.twoSide = param ? GL_TRUE : GL_FALSE; invalidate_lighting(c); }
static void fogx(GLenum pname, GLfixed param, ogles_context_t* c) { switch (pname) { case GL_FOG_DENSITY: if (param >= 0) { c->fog.density = param; break; } ogles_error(c, GL_INVALID_VALUE); break; case GL_FOG_START: c->fog.start = param; c->fog.invEndMinusStart = gglRecip(c->fog.end - c->fog.start); break; case GL_FOG_END: c->fog.end = param; c->fog.invEndMinusStart = gglRecip(c->fog.end - c->fog.start); break; case GL_FOG_MODE: switch (param) { case GL_LINEAR: c->fog.mode = param; c->fog.fog = fog_linear; break; case GL_EXP: c->fog.mode = param; c->fog.fog = fog_exp; break; case GL_EXP2: c->fog.mode = param; c->fog.fog = fog_exp2; break; default: ogles_error(c, GL_INVALID_ENUM); break; } break; default: ogles_error(c, GL_INVALID_ENUM); break; } }
static void lightx(GLenum i, GLenum pname, GLfixed param, ogles_context_t* c) { if (ggl_unlikely(uint32_t(i-GL_LIGHT0) >= OGLES_MAX_LIGHTS)) { ogles_error(c, GL_INVALID_ENUM); return; } light_t& light = c->lighting.lights[i-GL_LIGHT0]; const GLfixed kDegToRad = GLfixed((M_PI * gglIntToFixed(1)) / 180.0f); switch (pname) { case GL_SPOT_EXPONENT: if (GGLfixed(param) >= gglIntToFixed(128)) { ogles_error(c, GL_INVALID_VALUE); return; } light.spotExp = param; break; case GL_SPOT_CUTOFF: if (param!=gglIntToFixed(180) && GGLfixed(param)>=gglIntToFixed(90)) { ogles_error(c, GL_INVALID_VALUE); return; } light.spotCutoff = param; light.spotCutoffCosine = gglFloatToFixed(cosinef((M_PI/(180.0f*65536.0f))*param)); break; case GL_CONSTANT_ATTENUATION: if (param < 0) { ogles_error(c, GL_INVALID_VALUE); return; } light.attenuation[0] = param; break; case GL_LINEAR_ATTENUATION: if (param < 0) { ogles_error(c, GL_INVALID_VALUE); return; } light.attenuation[1] = param; break; case GL_QUADRATIC_ATTENUATION: if (param < 0) { ogles_error(c, GL_INVALID_VALUE); return; } light.attenuation[2] = param; break; default: ogles_error(c, GL_INVALID_ENUM); return; } invalidate_lighting(c); }
static void lightxv(GLenum i, GLenum pname, const GLfixed *params, ogles_context_t* c) { if (ggl_unlikely(uint32_t(i-GL_LIGHT0) >= OGLES_MAX_LIGHTS)) { ogles_error(c, GL_INVALID_ENUM); return; } GLfixed* what; light_t& light = c->lighting.lights[i-GL_LIGHT0]; switch (pname) { case GL_AMBIENT: what = light.ambient.v; break; case GL_DIFFUSE: what = light.diffuse.v; break; case GL_SPECULAR: what = light.specular.v; break; case GL_POSITION: { ogles_validate_transform(c, transform_state_t::MODELVIEW); transform_t& mv = c->transforms.modelview.transform; memcpy(light.position.v, params, sizeof(light.position.v)); mv.point4(&mv, &light.position, &light.position); invalidate_lighting(c); return; } case GL_SPOT_DIRECTION: { ogles_validate_transform(c, transform_state_t::MVUI); transform_t& mvui = c->transforms.mvui; mvui.point3(&mvui, &light.spotDir, (vec4_t*)params); vnorm3(light.normalizedSpotDir.v, light.spotDir.v); invalidate_lighting(c); return; } default: lightx(i, pname, params[0], c); return; } what[0] = params[0]; what[1] = params[1]; what[2] = params[2]; what[3] = params[3]; invalidate_lighting(c); }
void ogles_scissor(ogles_context_t* c, GLint x, GLint y, GLsizei w, GLsizei h) { if ((w|h) < 0) { ogles_error(c, GL_INVALID_VALUE); return; } c->viewport.scissor.x = x; c->viewport.scissor.y = y; c->viewport.scissor.w = w; c->viewport.scissor.h = h; x += c->viewport.surfaceport.x; y += c->viewport.surfaceport.y; y = c->rasterizer.state.buffers.color.height - (y + h); c->rasterizer.procs.scissor(c, x, y, w, h); }
static void frustumf( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar, ogles_context_t* c) { if (cmpf(left,right) || cmpf(top, bottom) || cmpf(zNear, zFar) || isZeroOrNegativef(zNear) || isZeroOrNegativef(zFar)) { ogles_error(c, GL_INVALID_VALUE); return; } const GLfloat r_width = reciprocalf(right - left); const GLfloat r_height = reciprocalf(top - bottom); const GLfloat r_depth = reciprocalf(zNear - zFar); const GLfloat x = mul2f(zNear * r_width); const GLfloat y = mul2f(zNear * r_height); const GLfloat A = mul2f((right + left) * r_width); const GLfloat B = (top + bottom) * r_height; const GLfloat C = (zFar + zNear) * r_depth; const GLfloat D = mul2f(zFar * zNear * r_depth); GLfloat f[16]; f[ 0] = x; f[ 5] = y; f[ 8] = A; f[ 9] = B; f[10] = C; f[14] = D; f[11] = -1.0f; f[ 1] = f[ 2] = f[ 3] = f[ 4] = f[ 6] = f[ 7] = f[12] = f[13] = f[15] = 0.0f; matrixf_t rhs; rhs.set(f); c->transforms.current->multiply(rhs); c->transforms.invalidate(); }
static void orthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar, ogles_context_t* c) { if (cmpf(left,right) || cmpf(top, bottom) || cmpf(zNear, zFar)) { ogles_error(c, GL_INVALID_VALUE); return; } const GLfloat r_width = reciprocalf(right - left); const GLfloat r_height = reciprocalf(top - bottom); const GLfloat r_depth = reciprocalf(zFar - zNear); const GLfloat x = mul2f(r_width); const GLfloat y = mul2f(r_height); const GLfloat z = -mul2f(r_depth); const GLfloat tx = -(right + left) * r_width; const GLfloat ty = -(top + bottom) * r_height; const GLfloat tz = -(zFar + zNear) * r_depth; GLfloat f[16]; f[ 0] = x; f[ 5] = y; f[10] = z; f[12] = tx; f[13] = ty; f[14] = tz; f[15] = 1.0f; f[ 1] = f[ 2] = f[ 3] = f[ 4] = f[ 6] = f[ 7] = f[ 8] = f[ 9] = f[11] = 0.0f; matrixf_t rhs; rhs.set(f); c->transforms.current->multiply(rhs); c->transforms.invalidate(); }
static void enable_disable(ogles_context_t* c, GLenum cap, int enabled) { if ((cap >= GL_LIGHT0) && (cap<GL_LIGHT0+OGLES_MAX_LIGHTS)) { c->lighting.lights[cap-GL_LIGHT0].enable = enabled; c->lighting.enabledLights &= ~(1<<(cap-GL_LIGHT0)); c->lighting.enabledLights |= (enabled<<(cap-GL_LIGHT0)); return; } switch (cap) { case GL_POINT_SMOOTH: c->point.smooth = enabled; break; case GL_LINE_SMOOTH: c->line.smooth = enabled; break; case GL_POLYGON_OFFSET_FILL: c->polygonOffset.enable = enabled; break; case GL_CULL_FACE: c->cull.enable = enabled; break; case GL_LIGHTING: c->lighting.enable = enabled; break; case GL_COLOR_MATERIAL: c->lighting.colorMaterial.enable = enabled; break; case GL_NORMALIZE: case GL_RESCALE_NORMAL: c->transforms.rescaleNormals = enabled ? cap : 0; // XXX: invalidate mvit break; case GL_CLIP_PLANE0: case GL_CLIP_PLANE1: case GL_CLIP_PLANE2: case GL_CLIP_PLANE3: case GL_CLIP_PLANE4: case GL_CLIP_PLANE5: c->clipPlanes.enable &= ~(1<<(cap-GL_CLIP_PLANE0)); c->clipPlanes.enable |= (enabled<<(cap-GL_CLIP_PLANE0)); ogles_invalidate_perspective(c); break; case GL_FOG: case GL_DEPTH_TEST: ogles_invalidate_perspective(c); // fall-through... case GL_BLEND: case GL_SCISSOR_TEST: case GL_ALPHA_TEST: case GL_COLOR_LOGIC_OP: case GL_DITHER: case GL_STENCIL_TEST: case GL_TEXTURE_2D: // these need to fall through into the rasterizer c->rasterizer.procs.enableDisable(c, cap, enabled); break; case GL_MULTISAMPLE: case GL_SAMPLE_ALPHA_TO_COVERAGE: case GL_SAMPLE_ALPHA_TO_ONE: case GL_SAMPLE_COVERAGE: // not supported in this implementation break; default: ogles_error(c, GL_INVALID_ENUM); return; } }