/*
* Mesa 3-D graphics library
* Version: 7.2.1
*
* Copyright (C) 1999-2008 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.
*/
#include "main/glheader.h"
#include "main/context.h"
#include "main/formats.h"
#include "main/macros.h"
#include "main/imports.h"
#include "main/fbobject.h"
#include "s_depth.h"
#include "s_context.h"
#include "s_span.h"
/**
* Do depth test for a horizontal span of fragments.
* Input: zbuffer - array of z values in the zbuffer
* z - array of fragment z values
* Return: number of fragments which pass the test.
*/
static GLuint
depth_test_span16( GLcontext *ctx, GLuint n,
GLushort zbuffer[], const GLuint z[], GLubyte mask[] )
{
GLuint passed = 0;
/* switch cases ordered from most frequent to less frequent */
switch (ctx->Depth.Func) {
case GL_LESS:
if (ctx->Depth.Mask) {
/* Update Z buffer */
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
if (z[i] < zbuffer[i]) {
/* pass */
zbuffer[i] = z[i];
passed++;
}
else {
/* fail */
mask[i] = 0;
}
}
}
}
else {
/* Don't update Z buffer */
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
if (z[i] < zbuffer[i]) {
/* pass */
passed++;
}
else {
mask[i] = 0;
}
}
}
}
break;
case GL_LEQUAL:
if (ctx->Depth.Mask) {
/* Update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
if (z[i] <= zbuffer[i]) {
zbuffer[i] = z[i];
passed++;
}
else {
mask[i] = 0;
}
}
}
}
else {
/* Don't update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
if (z[i] <= zbuffer[i]) {
/* pass */
passed++;
}
else {
mask[i] = 0;
}
}
}
}
break;
case GL_GEQUAL:
if (ctx->Depth.Mask) {
/* Update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
if (z[i] >= zbuffer[i]) {
zbuffer[i] = z[i];
passed++;
}
else {
mask[i] = 0;
}
}
}
}
else {
/* Don't update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
if (z[i] >= zbuffer[i]) {
/* pass */
passed++;
}
else {
mask[i] = 0;
}
}
}
}
break;
case GL_GREATER:
if (ctx->Depth.Mask) {
/* Update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
if (z[i] > zbuffer[i]) {
zbuffer[i] = z[i];
passed++;
}
else {
mask[i] = 0;
}
}
}
}
else {
/* Don't update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
if (z[i] > zbuffer[i]) {
/* pass */
passed++;
}
else {
mask[i] = 0;
}
}
}
}
break;
case GL_NOTEQUAL:
if (ctx->Depth.Mask) {
/* Update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
if (z[i] != zbuffer[i]) {
zbuffer[i] = z[i];
passed++;
}
else {
mask[i] = 0;
}
}
}
}
else {
/* Don't update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
if (z[i] != zbuffer[i]) {
/* pass */
passed++;
}
else {
mask[i] = 0;
}
}
}
}
break;
case GL_EQUAL:
if (ctx->Depth.Mask) {
/* Update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
if (z[i] == zbuffer[i]) {
zbuffer[i] = z[i];
passed++;
}
else {
mask[i] = 0;
}
}
}
}
else {
/* Don't update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
if (z[i] == zbuffer[i]) {
/* pass */
passed++;
}
else {
mask[i] = 0;
}
}
}
}
break;
case GL_ALWAYS:
if (ctx->Depth.Mask) {
/* Update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
zbuffer[i] = z[i];
passed++;
}
}
}
else {
/* Don't update Z buffer or mask */
passed = n;
}
break;
case GL_NEVER:
_mesa_bzero(mask, n * sizeof(GLubyte));
break;
default:
_mesa_problem(ctx, "Bad depth func in depth_test_span16");
}
return passed;
}
static GLuint
depth_test_span32( GLcontext *ctx, GLuint n,
GLuint zbuffer[], const GLuint z[], GLubyte mask[] )
{
GLuint passed = 0;
/* switch cases ordered from most frequent to less frequent */
switch (ctx->Depth.Func) {
case GL_LESS:
if (ctx->Depth.Mask) {
/* Update Z buffer */
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
if (z[i] < zbuffer[i]) {
/* pass */
zbuffer[i] = z[i];
passed++;
}
else {
/* fail */
mask[i] = 0;
}
}
}
}
else {
/* Don't update Z buffer */
GLuint i;
for (i=0; i<n; i++) {
if (mask[i]) {
if (z[i] < zbuffer[i]) {
/* pass */
passed++;
}
else {
mask[i] = 0;
}
}
}
}
break;
case GL_LEQUAL:
if (ctx->Depth.Mask) {
/* Update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
if (z[i] <= zbuffer[i]) {
zbuffer[i] = z[i];
passed++;
}
else {
mask[i] = 0;
}
}
}
}
else {
/* Don't update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
if (z[i] <= zbuffer[i]) {
/* pass */
passed++;
}
else {
mask[i] = 0;
}
}
}
}
break;
case GL_GEQUAL:
if (ctx->Depth.Mask) {
/* Update Z buffer */
GLuint i;
for (i=0;i<n;i++) {
if (mask[i]) {
if (z[i] >= zbuffer[i]) {
zbuffer[i] = z[i];
passed++;
|