VirtualBox

Ignore:
Timestamp:
Mar 16, 2010 12:43:40 PM (15 years ago)
Author:
vboxsync
Message:

crOpenGL: opengl 2.1 support

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/GuestHost/OpenGL/util/pixel.c

    r23435 r27396  
    1 /* Copyright (c) 2001, Stanford University
     1/* Cop(c) 2001, Stanford University
    22 * All rights reserved
    33 *
     
    1010#include "cr_version.h"
    1111
     12#if defined(WINDOWS)
     13# include <math.h>
     14# include <float.h>
     15# define isnan(x) _isnan(x)
     16#else
     17# include <cmath>
     18#endif
    1219
    1320/**
     
    116123        case GL_LUMINANCE:
    117124        case GL_INTENSITY:
     125#ifdef CR_EXT_texture_sRGB
     126        case GL_SLUMINANCE_EXT:
     127        case GL_SLUMINANCE8_EXT:
     128#endif
    118129            break;
    119130        case GL_LUMINANCE_ALPHA:
     131#ifdef CR_EXT_texture_sRGB
     132        case GL_SLUMINANCE_ALPHA_EXT:
     133        case GL_SLUMINANCE8_ALPHA8_EXT:
     134#endif
    120135            bytes *= 2;
    121136            break;
     
    124139        case GL_BGR:
    125140#endif
     141#ifdef CR_EXT_texture_sRGB
     142        case GL_SRGB_EXT:
     143        case GL_SRGB8_EXT:
     144#endif
    126145            bytes *= 3;
    127146            break;
     
    133152        case GL_BGRA:
    134153#endif
     154#ifdef CR_EXT_texture_sRGB
     155        case GL_SRGB_ALPHA_EXT:
     156        case GL_SRGB8_ALPHA8_EXT:
     157#endif
    135158            bytes *= 4;
    136159            break;
     
    162185#define FLOAT_TO_UINT(f)  ((GLuint) ((f) * 4294967295.0))
    163186
     187
     188static float SRGBF_TO_RGBF(float f)
     189{
     190    if (isnan(f)) return 0.f;
     191
     192    if (f<=0.04045f)
     193    {
     194        return f/12.92f;
     195    }
     196    else
     197    {
     198        return pow((f+0.055f)/1.055f, 2.4f);
     199    }
     200}
     201
     202static float RGBF_TO_SRGBF(float f)
     203{
     204    if (isnan(f)) return 0.f;
     205    if (f>1.f) return 1.f;
     206    if (f<0.f) return 0.f;
     207
     208    if (f<0.0031308f)
     209    {
     210        return f*12.92f;
     211    }
     212    else
     213    {
     214        return 1.055f*pow(f, 0.41666f) - 0.055f;
     215    }
     216}
    164217
    165218#ifdef _MSC_VER
     
    268321    }
    269322    else if (srcFormat == GL_RED || srcFormat == GL_GREEN ||
    270                      srcFormat == GL_BLUE || srcFormat == GL_ALPHA) {
     323             srcFormat == GL_BLUE || srcFormat == GL_ALPHA) {
    271324        int dst;
    272325        if (srcFormat == GL_RED)
     
    321374        }
    322375    }
    323     else if (srcFormat == GL_LUMINANCE) {
     376    else if (srcFormat == GL_LUMINANCE
     377#ifdef CR_EXT_texture_sRGB
     378             || srcFormat == GL_SLUMINANCE_EXT
     379             || srcFormat == GL_SLUMINANCE8_EXT
     380#endif
     381            ) {
    324382        switch (srcType) {
    325383            case GL_BYTE:
     
    427485        }
    428486    }
    429     else if (srcFormat == GL_LUMINANCE_ALPHA) {
     487    else if (srcFormat == GL_LUMINANCE_ALPHA
     488#ifdef CR_EXT_texture_sRGB
     489             || srcFormat == GL_SLUMINANCE_ALPHA_EXT
     490             || srcFormat == GL_SLUMINANCE8_ALPHA8_EXT
     491#endif
     492            ) {
    430493        switch (srcType) {
    431494            case GL_BYTE:
     
    490553    else if (srcFormat == GL_RGB
    491554#ifdef CR_OPENGL_VERSION_1_2
    492                      || srcFormat == GL_BGR
     555             || srcFormat == GL_BGR
     556#endif
     557#ifdef CR_EXT_texture_sRGB
     558             || srcFormat == GL_SRGB_EXT
     559             || srcFormat == GL_SRGB8_EXT
    493560#endif
    494561                     ) {
    495562        int r, b;
    496         if (srcFormat == GL_RGB) {
     563        if (srcFormat == GL_RGB
     564#ifdef CR_EXT_texture_sRGB
     565            || srcFormat == GL_SRGB_EXT
     566            || srcFormat == GL_SRGB8_EXT
     567#endif
     568           ) {
    497569            r = 0; b = 2;
    498570        }
     
    605677    else if (srcFormat == GL_RGBA
    606678#ifdef CR_OPENGL_VERSION_1_2
    607                      || srcFormat == GL_BGRA
    608 #endif
    609                      ) {
     679             || srcFormat == GL_BGRA
     680#endif
     681#ifdef CR_EXT_texture_sRGB
     682             || srcFormat == GL_SRGB_ALPHA_EXT
     683             || srcFormat == GL_SRGB8_ALPHA8_EXT
     684#endif
     685             ) {
    610686        int r, b;
    611         if (srcFormat == GL_RGB) {
     687        if (srcFormat == GL_RGBA
     688#ifdef CR_EXT_texture_sRGB
     689            || srcFormat == GL_SRGB_ALPHA_EXT
     690            || srcFormat == GL_SRGB8_ALPHA8_EXT
     691#endif
     692           )
     693        {
    612694            r = 0; b = 2;
    613695        }
     
    753835        crError("unexpected source format in get_row in pixel.c");
    754836    }
     837
     838#ifdef CR_EXT_texture_sRGB
     839    if (srcFormat == GL_SRGB_EXT
     840        || srcFormat == GL_SRGB8_EXT
     841        || srcFormat == GL_SRGB_ALPHA_EXT
     842        || srcFormat == GL_SRGB8_ALPHA8_EXT
     843        || srcFormat == GL_SLUMINANCE_ALPHA_EXT
     844        || srcFormat == GL_SLUMINANCE8_ALPHA8_EXT
     845        || srcFormat == GL_SLUMINANCE_EXT
     846        || srcFormat == GL_SLUMINANCE8_EXT
     847       )
     848    {
     849        for (i=0; i<width; ++i)
     850        {
     851            tmpRow[i*4+0] = SRGBF_TO_RGBF(tmpRow[i*4+0]);
     852            tmpRow[i*4+1] = SRGBF_TO_RGBF(tmpRow[i*4+1]);
     853            tmpRow[i*4+2] = SRGBF_TO_RGBF(tmpRow[i*4+2]);
     854        }
     855    }
     856#endif
    755857}
    756858
    757859
    758860static void put_row(char *dst, GLenum dstFormat, GLenum dstType,
    759                                         GLsizei width, const GLfloat *tmpRow)
     861                    GLsizei width, GLfloat *tmpRow)
    760862{
    761863    GLbyte *bDst = (GLbyte *) dst;
     
    769871    int i;
    770872
     873#ifdef CR_EXT_texture_sRGB
     874    if (dstFormat == GL_SRGB_EXT
     875        || dstFormat == GL_SRGB8_EXT
     876        || dstFormat == GL_SRGB_ALPHA_EXT
     877        || dstFormat == GL_SRGB8_ALPHA8_EXT
     878        || dstFormat == GL_SLUMINANCE_ALPHA_EXT
     879        || dstFormat == GL_SLUMINANCE8_ALPHA8_EXT
     880        || dstFormat == GL_SLUMINANCE_EXT
     881        || dstFormat == GL_SLUMINANCE8_EXT
     882       )
     883    {
     884        for (i=0; i<width; ++i)
     885        {
     886            tmpRow[i*4+0] = RGBF_TO_SRGBF(tmpRow[i*4+0]);
     887            tmpRow[i*4+1] = RGBF_TO_SRGBF(tmpRow[i*4+1]);
     888            tmpRow[i*4+2] = RGBF_TO_SRGBF(tmpRow[i*4+2]);
     889        }
     890    }
     891#endif
     892
    771893    if (dstFormat == GL_COLOR_INDEX || dstFormat == GL_STENCIL_INDEX) {
    772894        switch (dstType) {
     
    846968    }
    847969    else if (dstFormat == GL_RED || dstFormat == GL_GREEN ||
    848                      dstFormat == GL_BLUE || dstFormat == GL_ALPHA ||
    849                      dstFormat == GL_LUMINANCE || dstFormat == GL_INTENSITY) {
     970             dstFormat == GL_BLUE || dstFormat == GL_ALPHA ||
     971             dstFormat == GL_LUMINANCE || dstFormat == GL_INTENSITY
     972#ifdef CR_EXT_texture_sRGB
     973             || dstFormat == GL_SLUMINANCE_EXT
     974             || dstFormat == GL_SLUMINANCE8_EXT
     975#endif
     976             ) {
    850977        int index;
    851978        if (dstFormat == GL_RED)
    852979            index = 0;
    853         else if (dstFormat == GL_LUMINANCE)
     980        else if (dstFormat == GL_LUMINANCE
     981#ifdef CR_EXT_texture_sRGB
     982                 || dstFormat == GL_SLUMINANCE_EXT
     983                 || dstFormat == GL_SLUMINANCE8_EXT
     984#endif
     985                )
    854986            index = 0;
    855987        else if (dstFormat == GL_INTENSITY)
     
    8981030        }
    8991031    }
    900     else if (dstFormat == GL_LUMINANCE_ALPHA) {
     1032    else if (dstFormat == GL_LUMINANCE_ALPHA
     1033#ifdef CR_EXT_texture_sRGB
     1034             || dstFormat == GL_SLUMINANCE_ALPHA_EXT
     1035             || dstFormat == GL_SLUMINANCE8_ALPHA8_EXT
     1036#endif
     1037            ) {
    9011038        switch (dstType) {
    9021039            case GL_BYTE:
     
    9541091    else if (dstFormat == GL_RGB
    9551092#ifdef CR_OPENGL_VERSION_1_2
    956                      || dstFormat == GL_BGR
     1093             || dstFormat == GL_BGR
     1094#endif
     1095#ifdef CR_EXT_texture_sRGB
     1096             || dstFormat == GL_SRGB_EXT
     1097             || dstFormat == GL_SRGB8_EXT
    9571098#endif
    9581099                     ) {
    9591100        int r, b;
    960         if (dstFormat == GL_RGB) {
     1101        if (dstFormat == GL_RGB
     1102#ifdef CR_EXT_texture_sRGB
     1103            || dstFormat == GL_SRGB_EXT
     1104            || dstFormat == GL_SRGB8_EXT
     1105#endif
     1106           ) {
    9611107            r = 0; b = 2;
    9621108        }
     
    10611207    else if (dstFormat == GL_RGBA
    10621208#ifdef CR_OPENGL_VERSION_1_2
    1063                      || dstFormat == GL_BGRA
     1209             || dstFormat == GL_BGRA
     1210#endif
     1211#ifdef CR_EXT_texture_sRGB
     1212             || dstFormat == GL_SRGB_ALPHA_EXT
     1213             || dstFormat == GL_SRGB8_ALPHA8_EXT
    10641214#endif
    10651215                     ) {
    10661216        int r, b;
    1067         if (dstFormat == GL_RGB) {
     1217        if (dstFormat == GL_RGBA
     1218#ifdef CR_EXT_texture_sRGB
     1219            || dstFormat == GL_SRGB_ALPHA_EXT
     1220            || dstFormat == GL_SRGB8_ALPHA8_EXT
     1221#endif
     1222           ) {
    10681223            r = 0; b = 2;
    10691224        }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette