mesa/st: enable carry/borrow lowering pass
[mesa.git] / src / mesa / main / light.c
index a6039353e662c9afab789af51ad176e3dc55882e..d8ef8f258a7f981e89e8da62b157efafa1b3cde9 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  7.5
  *
  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
  * Copyright (C) 2009  VMware, Inc.  All Rights Reserved.
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
@@ -39,7 +39,6 @@ void GLAPIENTRY
 _mesa_ShadeModel( GLenum mode )
 {
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glShadeModel %s\n", _mesa_lookup_enum_by_nr(mode));
@@ -66,10 +65,9 @@ _mesa_ShadeModel( GLenum mode )
  * triangle or line.
  */
 void GLAPIENTRY
-_mesa_ProvokingVertexEXT(GLenum mode)
+_mesa_ProvokingVertex(GLenum mode)
 {
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE&VERBOSE_API)
       _mesa_debug(ctx, "glProvokingVertexEXT 0x%x\n", mode);
@@ -212,7 +210,6 @@ _mesa_Lightfv( GLenum light, GLenum pname, const GLfloat *params )
    GET_CURRENT_CONTEXT(ctx);
    GLint i = (GLint) (light - GL_LIGHT0);
    GLfloat temp[4];
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (i < 0 || i >= (GLint) ctx->Const.MaxLights) {
       _mesa_error( ctx, GL_INVALID_ENUM, "glLight(light=0x%x)", light );
@@ -335,7 +332,6 @@ _mesa_GetLightfv( GLenum light, GLenum pname, GLfloat *params )
 {
    GET_CURRENT_CONTEXT(ctx);
    GLint l = (GLint) (light - GL_LIGHT0);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (l < 0 || l >= (GLint) ctx->Const.MaxLights) {
       _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightfv" );
@@ -385,7 +381,6 @@ _mesa_GetLightiv( GLenum light, GLenum pname, GLint *params )
 {
    GET_CURRENT_CONTEXT(ctx);
    GLint l = (GLint) (light - GL_LIGHT0);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (l < 0 || l >= (GLint) ctx->Const.MaxLights) {
       _mesa_error( ctx, GL_INVALID_ENUM, "glGetLightiv" );
@@ -456,7 +451,6 @@ _mesa_LightModelfv( GLenum pname, const GLfloat *params )
    GLenum newenum;
    GLboolean newbool;
    GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    switch (pname) {
       case GL_LIGHT_MODEL_AMBIENT:
@@ -466,6 +460,8 @@ _mesa_LightModelfv( GLenum pname, const GLfloat *params )
          COPY_4V( ctx->Light.Model.Ambient, params );
          break;
       case GL_LIGHT_MODEL_LOCAL_VIEWER:
+         if (ctx->API != API_OPENGL_COMPAT)
+            goto invalid_pname;
          newbool = (params[0]!=0.0);
         if (ctx->Light.Model.LocalViewer == newbool)
            return;
@@ -478,12 +474,10 @@ _mesa_LightModelfv( GLenum pname, const GLfloat *params )
            return;
         FLUSH_VERTICES(ctx, _NEW_LIGHT);
         ctx->Light.Model.TwoSide = newbool;
-         if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
-            ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
-         else
-            ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
          break;
       case GL_LIGHT_MODEL_COLOR_CONTROL:
+         if (ctx->API != API_OPENGL_COMPAT)
+            goto invalid_pname;
          if (params[0] == (GLfloat) GL_SINGLE_COLOR)
            newenum = GL_SINGLE_COLOR;
          else if (params[0] == (GLfloat) GL_SEPARATE_SPECULAR_COLOR)
@@ -499,12 +493,17 @@ _mesa_LightModelfv( GLenum pname, const GLfloat *params )
         ctx->Light.Model.ColorControl = newenum;
          break;
       default:
-         _mesa_error( ctx, GL_INVALID_ENUM, "glLightModel(pname=0x%x)", pname );
-         break;
+         goto invalid_pname;
    }
 
    if (ctx->Driver.LightModelfv)
       ctx->Driver.LightModelfv( ctx, pname, params );
+
+   return;
+
+invalid_pname:
+   _mesa_error( ctx, GL_INVALID_ENUM, "glLightModel(pname=0x%x)", pname );
+   return;
 }
 
 
@@ -720,7 +719,6 @@ _mesa_ColorMaterial( GLenum face, GLenum mode )
                   MAT_BIT_FRONT_SPECULAR | MAT_BIT_BACK_SPECULAR |
                   MAT_BIT_FRONT_DIFFUSE  | MAT_BIT_BACK_DIFFUSE  |
                   MAT_BIT_FRONT_AMBIENT  | MAT_BIT_BACK_AMBIENT);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE&VERBOSE_API)
       _mesa_debug(ctx, "glColorMaterial %s %s\n",
@@ -757,7 +755,7 @@ _mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params )
    GET_CURRENT_CONTEXT(ctx);
    GLuint f;
    GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */
+   FLUSH_VERTICES(ctx, 0); /* update materials */
 
    FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
 
@@ -789,7 +787,7 @@ _mesa_GetMaterialfv( GLenum face, GLenum pname, GLfloat *params )
         *params = mat[MAT_ATTRIB_SHININESS(f)][0];
         break;
       case GL_COLOR_INDEXES:
-         if (ctx->API != API_OPENGL) {
+         if (ctx->API != API_OPENGL_COMPAT) {
             _mesa_error( ctx, GL_INVALID_ENUM, "glGetMaterialfv(pname)" );
             return;
          }
@@ -809,10 +807,10 @@ _mesa_GetMaterialiv( GLenum face, GLenum pname, GLint *params )
    GET_CURRENT_CONTEXT(ctx);
    GLuint f;
    GLfloat (*mat)[4] = ctx->Light.Material.Attrib;
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* update materials */
 
-   ASSERT(ctx->API == API_OPENGL);
+   ASSERT(ctx->API == API_OPENGL_COMPAT);
 
+   FLUSH_VERTICES(ctx, 0); /* update materials */
    FLUSH_CURRENT(ctx, 0); /* update ctx->Light.Material from vertex buffer */
 
    if (face==GL_FRONT) {
@@ -1029,7 +1027,7 @@ update_modelview_scale( struct gl_context *ctx )
       if (ctx->_NeedEyeCoords)
         ctx->_ModelViewInvScale = (GLfloat) INV_SQRTF(f);
       else
-        ctx->_ModelViewInvScale = (GLfloat) SQRTF(f);
+        ctx->_ModelViewInvScale = (GLfloat) sqrtf(f);
    }
 }
 
@@ -1200,7 +1198,8 @@ _mesa_init_lighting( struct gl_context *ctx )
                                                NULL );
 
    ctx->Light.ColorMaterialEnabled = GL_FALSE;
-   ctx->Light.ClampVertexColor = GL_TRUE;
+   ctx->Light.ClampVertexColor = ctx->API == API_OPENGL_COMPAT;
+   ctx->Light._ClampVertexColor = ctx->API == API_OPENGL_COMPAT;
 
    /* Miscellaneous */
    ctx->Light._NeedEyeCoords = GL_FALSE;