Ignore:
Timestamp:
Mar 12, 2008 3:48:06 PM (16 years ago)
Author:
gah
Message:

remove warnings from compile

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/vizservers/nanovis/Texture2D.cpp

    r825 r953  
     1
    12/*
    23 * ----------------------------------------------------------------------
     
    2324Texture2D::Texture2D(){}
    2425
    25 Texture2D::Texture2D(int width, int height, GLuint type=GL_FLOAT, GLuint interp=GL_LINEAR, int n=4, float* data = 0)
     26Texture2D::Texture2D(int width, int height, GLuint type=GL_FLOAT,
     27        GLuint interp=GL_LINEAR, int n=4, float* data = 0)
    2628{
    27         assert(type == GL_UNSIGNED_BYTE || type == GL_FLOAT|| type ==GL_UNSIGNED_INT);
    28         assert(interp == GL_LINEAR || interp == GL_NEAREST);
    29        
    30         this->width = width;
    31         this->height = height;
    32         this->type = type;
    33         this->interp_type = interp;
    34         this->n_components = n;
     29    assert(type == GL_UNSIGNED_BYTE ||
     30           type == GL_FLOAT ||
     31           type ==GL_UNSIGNED_INT);
     32    assert(interp == GL_LINEAR || interp == GL_NEAREST);
     33       
     34    this->width = width;
     35    this->height = height;
     36    this->type = type;
     37    this->interp_type = interp;
     38    this->n_components = n;
    3539
    36         this->id = 0;
     40    this->id = 0;
    3741
    38         if(data != 0)
    39           initialize(data);
     42    if(data != 0)
     43        initialize(data);
    4044}
    4145
    42 GLuint Texture2D::initialize(float *data)
     46GLuint
     47Texture2D::initialize(float *data)
    4348{
    44         glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
     49    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    4550
    46         glGenTextures(1, &id);
    47         glBindTexture(GL_TEXTURE_2D, id);
    48         assert(id!=-1);
     51    glGenTextures(1, &id);
     52    glBindTexture(GL_TEXTURE_2D, id);
     53    assert(id!=-1);
    4954
    50         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    51         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    52        
    53         if(interp_type == GL_LINEAR){
    54           glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    55           glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    56         }
    57         else{
    58           glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    59           glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    60         }
    61 
    62         //to do: add handling to more formats
    63         if(type==GL_FLOAT){
    64           switch(n_components){
    65             #ifdef NV40
    66                 case 1:
    67                         glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16F_ARB, width, height,  0, GL_LUMINANCE, GL_FLOAT, data);
    68                         break;
    69                 case 2:
    70                         glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA16F_ARB, width, height, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
    71                         break;
    72                 case 3:
    73                         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F_ARB, width, height, 0, GL_RGB, GL_FLOAT, data);
    74                         break;
    75                 case 4:
    76                         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, width, height, 0, GL_RGBA, GL_FLOAT, data);
    77                         break;
    78             #else
    79                 case 1:
    80                         glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_FLOAT, data);
    81                         break;
    82                 case 2:
    83                         glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, width, height, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
    84                         break;
    85                 case 3:
    86                         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_FLOAT, data);
    87                         break;
    88                 case 4:
    89                         glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, data);
    90                         break;
    91             #endif
    92                 default:
    93                         break;
    94           }
    95         }
    96     else
    97     {
    98         int comp[5] = { -1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA };
    99                 glTexImage2D(GL_TEXTURE_2D, 0, comp[n_components], width, height, 0, GL_RGBA, type, data);
     55    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
     56    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
     57       
     58    if(interp_type == GL_LINEAR){
     59        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     60        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     61    } else {
     62        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     63        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    10064    }
    10165
    102         assert(glGetError()==0);
    103         return id;
     66    //to do: add handling to more formats
     67    if (type==GL_FLOAT) {
     68        switch(n_components){
     69#ifdef NV40
     70        case 1:
     71            glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16F_ARB, width, height,
     72                         0, GL_LUMINANCE, GL_FLOAT, data);
     73            break;
     74        case 2:
     75            glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA16F_ARB, width,
     76                         height, 0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
     77            break;
     78        case 3:
     79            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB16F_ARB, width, height, 0,
     80                         GL_RGB, GL_FLOAT, data);
     81            break;
     82        case 4:
     83            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, width, height, 0,
     84                         GL_RGBA, GL_FLOAT, data);
     85            break;
     86#else
     87        case 1:
     88            glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0,
     89                         GL_LUMINANCE, GL_FLOAT, data);
     90            break;
     91        case 2:
     92            glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE_ALPHA, width, height,
     93                         0, GL_LUMINANCE_ALPHA, GL_FLOAT, data);
     94            break;
     95        case 3:
     96            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,
     97                         GL_FLOAT, data);
     98            break;
     99        case 4:
     100            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA,
     101                         GL_FLOAT, data);
     102            break;
     103#endif
     104        default:
     105            break;
     106        }
     107    } else {
     108        int comp[5] = { -1, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_RGB, GL_RGBA };
     109        glTexImage2D(GL_TEXTURE_2D, 0, comp[n_components], width, height, 0,
     110                     GL_RGBA, type, data);
     111    }
     112    assert(glGetError()==0);
     113    return id;
    104114}
    105115
    106116
    107 void Texture2D::activate()
     117void
     118Texture2D::activate()
    108119{
    109   glBindTexture(GL_TEXTURE_2D, id);
    110   glEnable(GL_TEXTURE_2D);
     120    glBindTexture(GL_TEXTURE_2D, id);
     121    glEnable(GL_TEXTURE_2D);
    111122}
    112123
    113124
    114 void Texture2D::deactivate()
     125void
     126Texture2D::deactivate()
    115127{
    116   glDisable(GL_TEXTURE_2D);             
     128    glDisable(GL_TEXTURE_2D);           
    117129}
    118130
     
    120132Texture2D::~Texture2D()
    121133{
    122   glDeleteTextures(1, &id);
     134    glDeleteTextures(1, &id);
    123135}
    124136
    125137
    126 void Texture2D::check_max_size(){
    127   GLint max = 0;
    128   glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
    129        
    130   fprintf(stderr, "max texture size: %d\n", max);
     138void
     139Texture2D::check_max_size(){
     140    GLint max = 0;
     141    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
     142       
     143    fprintf(stderr, "max texture size: %d\n", max);
    131144}
    132145
    133 void Texture2D::check_max_unit(){
    134   int max;
    135   glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max);
     146void
     147Texture2D::check_max_unit(){
     148    int max;
     149    glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &max);
    136150
    137   fprintf(stderr, "max texture units: %d.\n", max);
     151    fprintf(stderr, "max texture units: %d.\n", max);
    138152}
    139153
Note: See TracChangeset for help on using the changeset viewer.