IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenGL Discussion :

GLSL/gDebugger problème de linkage


Sujet :

OpenGL

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de AuraHxC
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2006
    Messages
    652
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mai 2006
    Messages : 652
    Par défaut GLSL/gDebugger problème de linkage
    Bonjour,

    Je viens soumettre un problème très sympa que je n'arrive pas a résoudre.
    Alors j'ai une classe Shader pour charger/linker etc... des shaders GLSL.
    Voici le code source :

    shader.hpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
     
    #ifndef SHADER_HPP
    #define SHADER_HPP
     
    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <vector>
    #include <string>
     
    #include <GL/glew.h>
    #include <GL/gl.h>
     
    #define TEXWIDTH 4096
     
    class Shader
    {
    public:
        Shader(std::string vertexFile, std::string fragmentFile);
        virtual ~Shader();
     
        void setUniforms();
        void createTexture(std::vector<float> data);
        bool enable();
        void disable();
        void enableTextures();
        void disableTextures();
        unsigned int getNbTextures() const { return m_nbTexture; }
     
    private:
        GLuint CreateShader(GLenum eShaderType, const std::string &strShaderFile);
        GLuint CreateProgram(const std::vector<GLuint> &shaderList);
        std::string readFileSrc(std::string fileName);
     
    private:
        std::vector<GLuint> m_shaderList;
        GLuint m_shaderprogram;
     
        static std::string m_vertexSource;
        static std::string m_fragmentSource;
     
        GLint m_coeffTex_id;
     
        unsigned int m_nbTexture;
        std::vector<GLuint> m_textureID;
    };
     
    #endif
    shader.cpp
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
     
    #include "shader.hpp"
     
    std::string Shader::m_vertexSource =
    "#version 330\n"
    "in vec3 VertexPosition;\n"
    "in vec3 VertexTangent;\n"
    "in vec3 VertexBinormal;\n"
    "in vec3 VertexNormal;\n"
    "\n"
    "uniform sampler2D coeffTex;\n"
    "\n"
    "uniform mat4 ModelViewProjectionMatrix;\n"
    "uniform mat4 ModelViewMatrix;\n"
    "uniform mat4 NormalMatrix;\n"
    "\n"
    "out vec4 color;\n"
    "\n"
    "#define NBCOEFF 15\n"
    "\n"
    "//Fonction pour calculer la position 2D\n"
    "//dans un tableau à partir de coordonnées\n"
    "//1D dans un tableau\n"
    "ivec2 coord1Dto2D(int position)\n"
    "{\n"
        "ivec2 texSize = textureSize(coeffTex, 0);\n"
        "float x = mod(float(position), float(texSize.x));\n"
        "int y = position / texSize.x;\n"
        "\n"
        "return ivec2(x,y);\n"
    "}\n"
    "\n"
    "void main()\n"
    "{\n"
        "vec3 eye = vec3(NormalMatrix[0].w, NormalMatrix[1].w, NormalMatrix[2].w);\n"
        "vec3 eyeVector = normalize(eye - VertexPosition);\n"
        "\n"
        "float u = dot(eyeVector, VertexTangent);\n"
        "float v = dot(eyeVector, VertexBinormal);\n"
        "\n"
        "//Boucle pour récuperer tous les coefficients\n"
        "//correspondant au vertex courant\n"
        "vec4 coeff[NBCOEFF];\n"
        "for(int i = 0 ; i < coeff.length() ; ++i) {\n"
            "int pos1D = (gl_VertexID * NBCOEFF) + i;\n"
            "ivec2 texPos = coord1Dto2D(pos1D);\n"
            "coeff[i] = texelFetch(coeffTex, texPos, 0);\n"
        "}\n"
     
        "float R = coeff[0].r +\n"
                  "coeff[1].r * v +\n"
                  "coeff[2].r * u +\n"
                  "coeff[3].r * u * v +\n"
                  "coeff[4].r * v * v +\n"
                  "coeff[5].r * u * u +\n"
                  "coeff[6].r * u * v * v +\n"
                  "coeff[7].r * u * u * v +\n"
                  "coeff[8].r * v * v * v +\n"
                  "coeff[9].r * u * u * u +\n"
                  "coeff[10].r * u * u * v * v +\n"
                  "coeff[11].r * u * v * v * v +\n"
                  "coeff[12].r * u * u * u * v +\n"
                  "coeff[13].r * v * v * v * v +\n"
                  "coeff[14].r * u * u * u * u;\n"
    "\n"
        "float G = coeff[0].g +\n"
                  "coeff[1].g * v +\n"
                  "coeff[2].g * u +\n"
                  "coeff[3].g * u * v +\n"
                  "coeff[4].g * v * v +\n"
                  "coeff[5].g * u * u +\n"
                  "coeff[6].g * u * v * v +\n"
                  "coeff[7].g * u * u * v +\n"
                  "coeff[8].g * v * v * v +\n"
                  "coeff[9].g * u * u * u +\n"
                  "coeff[10].g * u * u * v * v +\n"
                  "coeff[11].g * u * v * v * v +\n"
                  "coeff[12].g * u * u * u * v +\n"
                  "coeff[13].g * v * v * v * v +\n"
                  "coeff[14].g * u * u * u * u;\n"
    "\n"
        "float B = coeff[0].b +\n"
                  "coeff[1].b * v +\n"
                  "coeff[2].b * u +\n"
                  "coeff[3].b * u * v +\n"
                  "coeff[4].b * v * v +\n"
                  "coeff[5].b * u * u +\n"
                  "coeff[6].b * u * v * v +\n"
                  "coeff[7].b * u * u * v +\n"
                  "coeff[8].b * v * v * v +\n"
                  "coeff[9].b * u * u * u +\n"
                  "coeff[10].b * u * u * v * v +\n"
                  "coeff[11].b * u * v * v * v +\n"
                  "coeff[12].b * u * u * u * v +\n"
                  "coeff[13].b * v * v * v * v +\n"
                  "coeff[14].b * u * u * u * u;\n"
    "\n"
        "color = vec4(R, G, B, 1.0);\n"
    "\n"
        "gl_Position = ModelViewProjectionMatrix * vec4(VertexPosition, 1.0);\n"
    "}\n";
     
    std::string Shader::m_fragmentSource =
    "#version 330\n"
    "in vec4 color;\n"
    "\n"
    "out vec4 color_out;\n"
    "\n"
    "void main()\n"
    "{\n"
        "color_out = color;\n"
    "}\n";
     
     
    Shader::Shader(std::string vertexFile, std::string fragmentFile)
    {
        m_shaderList.push_back(CreateShader(GL_VERTEX_SHADER, m_vertexSource));
        m_shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, m_fragmentSource));
    //    m_shaderList.push_back(CreateShader(GL_VERTEX_SHADER, readFileSrc(vertexFile)));
    //    m_shaderList.push_back(CreateShader(GL_FRAGMENT_SHADER, readFileSrc(fragmentFile)));
     
        m_shaderprogram = CreateProgram(m_shaderList);
        enable();
        setUniforms();
    }
     
    Shader::~Shader()
    {
        if(m_shaderprogram) {
            disable();
     
            for(unsigned int i = 0 ; i < m_shaderList.size() ; ++i) {
                glDetachShader(m_shaderprogram, m_shaderList.at(i));
                glDeleteShader(m_shaderList.at(i));
            }
     
            glDeleteProgram(m_shaderprogram);
        }
    }
     
    GLuint
    Shader::CreateShader(GLenum eShaderType, const std::string &strShaderFile)
    {
        GLuint shader = glCreateShader(eShaderType);
        const char *strFileData = strShaderFile.c_str();
        glShaderSource(shader, 1, (const GLchar**)&strFileData, NULL);
     
        glCompileShader(shader);
     
        GLint status;
        glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
        if(status == GL_FALSE) {
            GLint infoLogLength;
            glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
     
            GLchar *strInfoLog = new GLchar[infoLogLength + 1];glGetShaderInfoLog
            (shader, infoLogLength, NULL, strInfoLog);
     
            const char *strShaderType = NULL;
            switch(eShaderType) {
                case GL_VERTEX_SHADER:
                    strShaderType = "vertex";
                break;
                case GL_GEOMETRY_SHADER:
                    strShaderType = "geometry";
                break;
                case GL_FRAGMENT_SHADER:
                    strShaderType = "fragment";
                break;
            }
     
            std::cerr << "Compile failure in " << strShaderType << " shader:\n" << strInfoLog
                    << std::endl;
            delete[] strInfoLog;
        }
     
        return shader;
    }
     
    GLuint
    Shader::CreateProgram(const std::vector<GLuint> &shaderList)
    {
        GLuint program = glCreateProgram();
     
        for(unsigned int i = 0 ; i < shaderList.size() ; i++) {
            glAttachShader(program, shaderList[i]);
        }
     
        glLinkProgram(program);
     
        GLint status;
        glGetProgramiv(program, GL_LINK_STATUS, &status);
        if(status == GL_FALSE) {
            GLint infoLogLength;
            glGetProgramiv(program, GL_INFO_LOG_LENGTH, &infoLogLength);
     
            GLchar *strInfoLog = new GLchar[infoLogLength + 1];glGetProgramInfoLog
            (program, infoLogLength, NULL, strInfoLog);
            std::cerr << "Linker failure: " << strInfoLog << std::endl;
            delete[] strInfoLog;
        }
     
        return program;
    }
     
    void
    Shader::setUniforms()
    {
        m_coeffTex_id = glGetUniformLocation(m_shaderprogram, "coeffTex");
    }
     
    void
    Shader::createTexture(std::vector<float> data)
    {
        GLuint id;
        glGenTextures(1, &id);
        m_textureID.push_back(id);
     
        /* calcul de la taille de la texture */
        int height = ((data.size() / 3) + (TEXWIDTH - 1)) / TEXWIDTH;
        /* calcul de la nouvelle taille du tableau contenant les données */
        int dataSize = TEXWIDTH * height * 3;
        data.resize(dataSize);
     
        glActiveTexture(GL_TEXTURE0 + m_nbTexture);
        glBindTexture(GL_TEXTURE_2D, m_textureID.at(m_nbTexture));
     
        /* Paramétrage de la texture : IMPORTANT => RGB32F pour ne pas avoir
         * de valeur clamper dans la texture.
         */
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, TEXWIDTH, height, 0, GL_RGB, GL_FLOAT, &data[0]);
     
        glBindTexture(GL_TEXTURE_2D, 0);
     
        m_nbTexture = m_nbTexture + 1;
    }
     
    bool
    Shader::enable()
    {
        if(m_shaderprogram) {
            glUseProgram(m_shaderprogram);
            return true;
        }
        else return false;
    }
     
    void
    Shader::disable()
    {
        if(m_shaderprogram) {
            glUseProgram(0);
        }
    }
     
    void
    Shader::enableTextures()
    {
        enable();
     
        glUniform1i(m_coeffTex_id, 0);
     
        for(unsigned int i = 0 ; i < m_nbTexture ; ++i) {
            glActiveTexture(GL_TEXTURE0 + i);
            glBindTexture(GL_TEXTURE_2D, m_textureID.at(i));
        }
    }
     
    void
    Shader::disableTextures()
    {
        for(unsigned int i = 0 ; i < m_nbTexture ; ++i) {
            glActiveTexture(GL_TEXTURE0 + i);
            glBindTexture(GL_TEXTURE_2D, 0);
        }
    }
     
    std::string
    Shader::readFileSrc(std::string fileName)
    {
        std::ifstream fichier(fileName.c_str());
        std::stringstream buffer;
     
        if(fichier) {
            buffer << fichier.rdbuf();
            fichier.close();
        }
     
        return std::string(buffer.str());
    }
    Donc quand j'utilise ma méthode readFileSrc j'ai n'ai aucun soucis en exécutant mon code dans un terminal quelconque par contre gDebugger n'apprécie pas du tout la plaisanterie => problème de compilation et linkage avec le message d'erreur suivant
    Shader-Compilation-Log
    (0) : error C0000: syntax error, unexpected $end at token ""

    Alors que si j'utilise deux string static qui sont au début de mon fichier shader.cpp toujours pas de soucis dans le terminal mais plus de soucis non plus dans gDebugger...

    Donc ça doit se situer au niveau du chargement par fichier mais pourquoi ça passe correctement en terminal mais pas en gDebugger...

    Je vais mettre trois images de gDebugger pour illustrer mes propos.

    En espérant que "mon erreur" saute a vos yeux, ça m'arrangerait grandement
    Images attachées Images attachées    

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Code::Blocks sous Linux problème de linkage
    Par Invité dans le forum Code::Blocks
    Réponses: 3
    Dernier message: 22/03/2006, 16h54
  2. [Code::Blocks] Problème de linkage: "msvcrt.lib"
    Par skhay dans le forum Code::Blocks
    Réponses: 8
    Dernier message: 14/03/2006, 19h39
  3. Plusieurs fichiers => Problème de Linkage
    Par loic911 dans le forum C++
    Réponses: 6
    Dernier message: 01/03/2006, 00h11
  4. Problème de linkage avec la librairie DevIl
    Par Drannor dans le forum DevIL
    Réponses: 1
    Dernier message: 18/01/2006, 23h05
  5. Problème de linkage
    Par lvdnono dans le forum Windows
    Réponses: 4
    Dernier message: 15/06/2004, 12h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo