mesa: refactor: move glClear, glClearColor into new clear.c file.
authorBrian Paul <brian.paul@tungstengraphics.com>
Mon, 9 Jun 2008 21:01:02 +0000 (15:01 -0600)
committerKeith Whitwell <keith@tungstengraphics.com>
Mon, 22 Sep 2008 05:13:51 +0000 (22:13 -0700)
src/mesa/main/api_exec.c
src/mesa/main/buffers.c
src/mesa/main/buffers.h
src/mesa/main/clear.c [new file with mode: 0644]
src/mesa/main/clear.h [new file with mode: 0644]
src/mesa/main/sources
src/mesa/sources

index a9696a6842a98952a02dc31a8d17940b2e5dbf9d..382091f580b4e9e17e66654f076e27b61f16463d 100644 (file)
@@ -46,6 +46,7 @@
 #endif
 #include "arrayobj.h"
 #include "buffers.h"
+#include "clear.h"
 #include "clip.h"
 #include "colortab.h"
 #include "context.h"
index 00f6fb3e64ec28f00b18c7cbf4eb89756f72ee01..0c550fd8f156641a7b872ab5885d9c9fc97d04d8 100644 (file)
@@ -25,7 +25,7 @@
 
 /**
  * \file buffers.c
- * General framebuffer-related functions, like glClear, glScissor, etc.
+ * glReadBuffer, DrawBuffer functions.
  */
 
 
 #define BAD_MASK ~0u
 
 
-#if _HAVE_FULL_GL
-void GLAPIENTRY
-_mesa_ClearIndex( GLfloat c )
-{
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   if (ctx->Color.ClearIndex == (GLuint) c)
-      return;
-
-   FLUSH_VERTICES(ctx, _NEW_COLOR);
-   ctx->Color.ClearIndex = (GLuint) c;
-
-   if (!ctx->Visual.rgbMode && ctx->Driver.ClearIndex) {
-      /* it's OK to call glClearIndex in RGBA mode but it should be a NOP */
-      (*ctx->Driver.ClearIndex)( ctx, ctx->Color.ClearIndex );
-   }
-}
-#endif
-
-
-/**
- * Specify the clear values for the color buffers.
- *
- * \param red red color component.
- * \param green green color component.
- * \param blue blue color component.
- * \param alpha alpha component.
- *
- * \sa glClearColor().
- *
- * Clamps the parameters and updates gl_colorbuffer_attrib::ClearColor.  On a
- * change, flushes the vertices and notifies the driver via the
- * dd_function_table::ClearColor callback.
- */
-void GLAPIENTRY
-_mesa_ClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
-{
-   GLfloat tmp[4];
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END(ctx);
-
-   tmp[0] = CLAMP(red,   0.0F, 1.0F);
-   tmp[1] = CLAMP(green, 0.0F, 1.0F);
-   tmp[2] = CLAMP(blue,  0.0F, 1.0F);
-   tmp[3] = CLAMP(alpha, 0.0F, 1.0F);
-
-   if (TEST_EQ_4V(tmp, ctx->Color.ClearColor))
-      return; /* no change */
-
-   FLUSH_VERTICES(ctx, _NEW_COLOR);
-   COPY_4V(ctx->Color.ClearColor, tmp);
-
-   if (ctx->Visual.rgbMode && ctx->Driver.ClearColor) {
-      /* it's OK to call glClearColor in CI mode but it should be a NOP */
-      (*ctx->Driver.ClearColor)(ctx, ctx->Color.ClearColor);
-   }
-}
-
-
-/**
- * Clear buffers.
- * 
- * \param mask bit-mask indicating the buffers to be cleared.
- *
- * Flushes the vertices and verifies the parameter. If __GLcontextRec::NewState
- * is set then calls _mesa_update_state() to update gl_frame_buffer::_Xmin,
- * etc. If the rasterization mode is set to GL_RENDER then requests the driver
- * to clear the buffers, via the dd_function_table::Clear callback.
- */ 
-void GLAPIENTRY
-_mesa_Clear( GLbitfield mask )
-{
-   GET_CURRENT_CONTEXT(ctx);
-   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
-
-   FLUSH_CURRENT(ctx, 0);
-
-   if (MESA_VERBOSE & VERBOSE_API)
-      _mesa_debug(ctx, "glClear 0x%x\n", mask);
-
-   if (mask & ~(GL_COLOR_BUFFER_BIT |
-                GL_DEPTH_BUFFER_BIT |
-                GL_STENCIL_BUFFER_BIT |
-                GL_ACCUM_BUFFER_BIT)) {
-      /* invalid bit set */
-      _mesa_error( ctx, GL_INVALID_VALUE, "glClear(0x%x)", mask);
-      return;
-   }
-
-   if (ctx->NewState) {
-      _mesa_update_state( ctx );       /* update _Xmin, etc */
-   }
-
-   if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
-      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
-                  "glClear(incomplete framebuffer)");
-      return;
-   }
-
-   if (ctx->DrawBuffer->Width == 0 || ctx->DrawBuffer->Height == 0 ||
-       ctx->DrawBuffer->_Xmin >= ctx->DrawBuffer->_Xmax ||
-       ctx->DrawBuffer->_Ymin >= ctx->DrawBuffer->_Ymax)
-      return;
-
-   if (ctx->RenderMode == GL_RENDER) {
-      GLbitfield bufferMask;
-
-      /* don't clear depth buffer if depth writing disabled */
-      if (!ctx->Depth.Mask)
-         mask &= ~GL_DEPTH_BUFFER_BIT;
-
-      /* Build the bitmask to send to device driver's Clear function.
-       * Note that the GL_COLOR_BUFFER_BIT flag will expand to 0, 1, 2 or 4
-       * of the BUFFER_BIT_FRONT/BACK_LEFT/RIGHT flags, or one of the
-       * BUFFER_BIT_COLORn flags.
-       */
-      bufferMask = 0;
-      if (mask & GL_COLOR_BUFFER_BIT) {
-         GLuint i;
-         for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
-            bufferMask |= (1 << ctx->DrawBuffer->_ColorDrawBufferIndexes[i]);
-         }
-      }
-
-      if ((mask & GL_DEPTH_BUFFER_BIT)
-          && ctx->DrawBuffer->Visual.haveDepthBuffer) {
-         bufferMask |= BUFFER_BIT_DEPTH;
-      }
-
-      if ((mask & GL_STENCIL_BUFFER_BIT)
-          && ctx->DrawBuffer->Visual.haveStencilBuffer) {
-         bufferMask |= BUFFER_BIT_STENCIL;
-      }
-
-      if ((mask & GL_ACCUM_BUFFER_BIT)
-          && ctx->DrawBuffer->Visual.haveAccumBuffer) {
-         bufferMask |= BUFFER_BIT_ACCUM;
-      }
-
-      ASSERT(ctx->Driver.Clear);
-      ctx->Driver.Clear(ctx, bufferMask);
-   }
-}
-
-
-
 /**
  * Return bitmask of BUFFER_BIT_* flags indicating which color buffers are
  * available to the rendering context (for drawing or reading).
index 0af34757e036bc0cd0d6d01e25ec21a011f7dd89..914730ab9d4d9de91cbe5b8a6f79ca8ff43eaf46 100644 (file)
 #include "mtypes.h"
 
 
-extern void GLAPIENTRY
-_mesa_ClearIndex( GLfloat c );
-
-extern void GLAPIENTRY
-_mesa_ClearColor( GLclampf red, GLclampf green,
-                  GLclampf blue, GLclampf alpha );
-
-extern void GLAPIENTRY
-_mesa_Clear( GLbitfield mask );
-
 extern void GLAPIENTRY
 _mesa_DrawBuffer( GLenum mode );
 
diff --git a/src/mesa/main/clear.c b/src/mesa/main/clear.c
new file mode 100644 (file)
index 0000000..63388f4
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.1
+ *
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * 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.
+ */
+
+
+/**
+ * \file clear.c
+ * glClearColor, glClearIndex, glClear() functions.
+ */
+
+
+
+#include "glheader.h"
+#include "clear.h"
+#include "context.h"
+#include "colormac.h"
+#include "state.h"
+
+
+
+#if _HAVE_FULL_GL
+void GLAPIENTRY
+_mesa_ClearIndex( GLfloat c )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (ctx->Color.ClearIndex == (GLuint) c)
+      return;
+
+   FLUSH_VERTICES(ctx, _NEW_COLOR);
+   ctx->Color.ClearIndex = (GLuint) c;
+
+   if (!ctx->Visual.rgbMode && ctx->Driver.ClearIndex) {
+      /* it's OK to call glClearIndex in RGBA mode but it should be a NOP */
+      (*ctx->Driver.ClearIndex)( ctx, ctx->Color.ClearIndex );
+   }
+}
+#endif
+
+
+/**
+ * Specify the clear values for the color buffers.
+ *
+ * \param red red color component.
+ * \param green green color component.
+ * \param blue blue color component.
+ * \param alpha alpha component.
+ *
+ * \sa glClearColor().
+ *
+ * Clamps the parameters and updates gl_colorbuffer_attrib::ClearColor.  On a
+ * change, flushes the vertices and notifies the driver via the
+ * dd_function_table::ClearColor callback.
+ */
+void GLAPIENTRY
+_mesa_ClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
+{
+   GLfloat tmp[4];
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   tmp[0] = CLAMP(red,   0.0F, 1.0F);
+   tmp[1] = CLAMP(green, 0.0F, 1.0F);
+   tmp[2] = CLAMP(blue,  0.0F, 1.0F);
+   tmp[3] = CLAMP(alpha, 0.0F, 1.0F);
+
+   if (TEST_EQ_4V(tmp, ctx->Color.ClearColor))
+      return; /* no change */
+
+   FLUSH_VERTICES(ctx, _NEW_COLOR);
+   COPY_4V(ctx->Color.ClearColor, tmp);
+
+   if (ctx->Visual.rgbMode && ctx->Driver.ClearColor) {
+      /* it's OK to call glClearColor in CI mode but it should be a NOP */
+      (*ctx->Driver.ClearColor)(ctx, ctx->Color.ClearColor);
+   }
+}
+
+
+/**
+ * Clear buffers.
+ * 
+ * \param mask bit-mask indicating the buffers to be cleared.
+ *
+ * Flushes the vertices and verifies the parameter. If __GLcontextRec::NewState
+ * is set then calls _mesa_update_state() to update gl_frame_buffer::_Xmin,
+ * etc. If the rasterization mode is set to GL_RENDER then requests the driver
+ * to clear the buffers, via the dd_function_table::Clear callback.
+ */ 
+void GLAPIENTRY
+_mesa_Clear( GLbitfield mask )
+{
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
+
+   FLUSH_CURRENT(ctx, 0);
+
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glClear 0x%x\n", mask);
+
+   if (mask & ~(GL_COLOR_BUFFER_BIT |
+                GL_DEPTH_BUFFER_BIT |
+                GL_STENCIL_BUFFER_BIT |
+                GL_ACCUM_BUFFER_BIT)) {
+      /* invalid bit set */
+      _mesa_error( ctx, GL_INVALID_VALUE, "glClear(0x%x)", mask);
+      return;
+   }
+
+   if (ctx->NewState) {
+      _mesa_update_state( ctx );       /* update _Xmin, etc */
+   }
+
+   if (ctx->DrawBuffer->_Status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+      _mesa_error(ctx, GL_INVALID_FRAMEBUFFER_OPERATION_EXT,
+                  "glClear(incomplete framebuffer)");
+      return;
+   }
+
+   if (ctx->DrawBuffer->Width == 0 || ctx->DrawBuffer->Height == 0 ||
+       ctx->DrawBuffer->_Xmin >= ctx->DrawBuffer->_Xmax ||
+       ctx->DrawBuffer->_Ymin >= ctx->DrawBuffer->_Ymax)
+      return;
+
+   if (ctx->RenderMode == GL_RENDER) {
+      GLbitfield bufferMask;
+
+      /* don't clear depth buffer if depth writing disabled */
+      if (!ctx->Depth.Mask)
+         mask &= ~GL_DEPTH_BUFFER_BIT;
+
+      /* Build the bitmask to send to device driver's Clear function.
+       * Note that the GL_COLOR_BUFFER_BIT flag will expand to 0, 1, 2 or 4
+       * of the BUFFER_BIT_FRONT/BACK_LEFT/RIGHT flags, or one of the
+       * BUFFER_BIT_COLORn flags.
+       */
+      bufferMask = 0;
+      if (mask & GL_COLOR_BUFFER_BIT) {
+         GLuint i;
+         for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
+            bufferMask |= (1 << ctx->DrawBuffer->_ColorDrawBufferIndexes[i]);
+         }
+      }
+
+      if ((mask & GL_DEPTH_BUFFER_BIT)
+          && ctx->DrawBuffer->Visual.haveDepthBuffer) {
+         bufferMask |= BUFFER_BIT_DEPTH;
+      }
+
+      if ((mask & GL_STENCIL_BUFFER_BIT)
+          && ctx->DrawBuffer->Visual.haveStencilBuffer) {
+         bufferMask |= BUFFER_BIT_STENCIL;
+      }
+
+      if ((mask & GL_ACCUM_BUFFER_BIT)
+          && ctx->DrawBuffer->Visual.haveAccumBuffer) {
+         bufferMask |= BUFFER_BIT_ACCUM;
+      }
+
+      ASSERT(ctx->Driver.Clear);
+      ctx->Driver.Clear(ctx, bufferMask);
+   }
+}
diff --git a/src/mesa/main/clear.h b/src/mesa/main/clear.h
new file mode 100644 (file)
index 0000000..9a54ba1
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Mesa 3-D graphics library
+ * Version:  7.1
+ *
+ * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * 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.
+ */
+
+
+#ifndef CLEAR_H
+#define CLEAR_H
+
+
+#include "main/mtypes.h"
+
+
+extern void GLAPIENTRY
+_mesa_ClearIndex( GLfloat c );
+
+extern void GLAPIENTRY
+_mesa_ClearColor( GLclampf red, GLclampf green,
+                  GLclampf blue, GLclampf alpha );
+
+extern void GLAPIENTRY
+_mesa_Clear( GLbitfield mask );
+
+
+#endif
index 60b6b5dc3f07e2d73eae551c248d5a2d7f9c764a..8043f4369e34d00206debaf6bd6555f97817fe4d 100644 (file)
@@ -11,6 +11,7 @@ attrib.c \
 blend.c \
 bufferobj.c \
 buffers.c \
+clear.c \
 clip.c \
 colortab.c \
 context.c \
@@ -84,6 +85,7 @@ bitset.h \
 blend.h \
 bufferobj.h \
 buffers.h \
+clear.h \
 clip.h \
 colormac.h \
 colortab.h \
index ee8753365d73b12cb136b3ddd9f2561a9274634d..af066fd4613f6dbd63316f48b1f3f0c1bb775430 100644 (file)
@@ -12,6 +12,7 @@ MAIN_SOURCES = \
        main/blend.c \
        main/bufferobj.c \
        main/buffers.c \
+       main/clear.c \
        main/clip.c \
        main/colortab.c \
        main/context.c \