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 :

Optimisation d'un moteur, traitement au niveau des pixels


Sujet :

OpenGL

  1. #1
    Invité
    Invité(e)
    Par défaut Optimisation d'un moteur, traitement au niveau des pixels
    Salut!

    Cette question s'adresse plutôt à des gens qui ont déjà créer des jeux avec des graphismes fort évolué. (J'entend par là, du traitement par pixel en masse)

    Je suis entrain de réalisé un moteur de jeux et j'en suis arrivé à la phase d'optimisation, mais je ne sais pas de trop comment procéder pour faire du traitement par pixel avec opengl de manière la plus rapide.

    J'ai essayé une première méthode utilisant un shader mais ont m'a dit que c'était assez long de passer des textures à un shader, et c'est vrai que ça saccade un peu j'ai donc recherché une autre technique et je ne savais même pas que les pbo ça existait : (Alors je suis tombé sur ce lien http://www.songho.ca/opengl/gl_pbo.html qui me semble assez intéressant et qui me permettrait de traiter les pixels de mes textures côté CPU et d'éviter de devoir passer mes textures à mon shader à chaque fois que je dessine quelque chose en utilisant des fbo. (J'utilise SFML qui utilise des "rendertexture" qui ne sont rien d'autre qu'une encapsulation des fbo)
    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
     
     if (Shader::isAvailable()) {
            frameBuffer->setView(target.getView());
            depthBuffer->setView(target.getView());
            for (unsigned int i = 0; i < m_vertices.size(); i++) {
                states.texture = const_cast<FastRenderComponent*>(this)->m_vertices[i].first.getMaterial().getTexture();
                for (unsigned int j = 0; j < m_vertices[i].second.size(); j++) {
                    states.shader = frameBufferGenerator;
                    frameBufferGenerator->setParameter("depthBuffer", depthBuffer->getTexture());
                    frameBufferGenerator->setParameter("frameBuffer", frameBuffer->getTexture());
                    frameBufferGenerator->setParameter("texture", Shader::CurrentTexture);
                    frameBuffer->draw(*m_vertices[i].second[j], states);
                    frameBuffer->display();
                    depthBufferGenerator->setParameter("depthBuffer", depthBuffer->getTexture());
                    depthBufferGenerator->setParameter("texture", Shader::CurrentTexture);
                    states.shader = depthBufferGenerator;
                    depthBuffer->draw(*m_vertices[i].second[j], states);
                    depthBuffer->display();
                }
            }
    Le but est de faire un depthtest qui gère la semi-transparence pour les textures qui se croisent sur l'axe z. (Mais pas que ça, plus tard j'aurai besoin aussi de générer une lightmap et une shadowmap)

    J'ai également aussi entendu parlé d'une extension de GLSL qui permet de lire et d'écrire directement dans le framebuffer. (Mais je n'ai jamais trouvé de documentation à ce sujet)

    Je ne sais pas vraiment quel technique est la meilleure, alors là je suis entrain de les essayer toutes..., mais afin d'éviter de perdre du temps et de devoir changé du code parce que je ne connais pas tel fonctionnalité opengl bah j'aimerais avoir des avis de gens qui ont déjà fait des jeux vidéos plus évolués avec opengl.
    Dernière modification par LittleWhite ; 18/04/2014 à 09h48. Motif: Titre précis

  2. #2
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Bonjour,
    J'ai essayé une première méthode utilisant un shader mais ont m'a dit que c'était assez long de passer des textures à un shader, et c'est vrai que ça saccade
    Votre constat est plutôt très étrange, les textures sont la base de presque tous les rendus. Mais, j'ai une hypothèse : pour que les textures marchent bien, il faut qu'elles soient avec des tailles en puissance de 2.

    Pour le reste, je dirai, les meilleures techniques sont à coup de FBO et de shaders traitant les textures générées par les FBO. Plus précisément, si vous voulez faire un post traitement (modification de tous les pixels de l'image, notamment pour équilibrer les couleurs, les changer ou autre), vous faites un rendu dans un FBO, puis vous afficher la texture générée qui sera traitée par un pixel shader, pixel par pixel.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  3. #3
    Invité
    Invité(e)
    Par défaut
    Oui c'est ce que je fais à part que moi je dessine la frame suivante avec des fbos à l'aide d'un thread, et je dessine la frame courante avec le thread principal, mais comme ça saccadais encore, j'ai essayé d'optimiser d'avantage pour que le depthbuffer de mon composant se mette à jour pendant que je dessine sur le framebuffer :

    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
     
    #include "../../../../include/odfaeg/Graphics/2D/fastRenderComponent.h"
    namespace odfaeg {
    namespace g2d {
    FastRenderComponent::FastRenderComponent (RenderWindow& window, int layer) :
        Transformable(Vec3f(window.getView().getPosition().x, window.getView().getPosition().y, layer),
                      Vec3f(window.getView().getSize().x, window.getView().getSize().y, 0),
                      Vec3f(window.getView().getSize().x + window.getView().getSize().x * 0.5f, window.getView().getPosition().y + window.getView().getSize().y * 0.5f, layer)),
        view(window.getView()) {
        sf::Vector3i resolution ((int) window.getSize().x, (int) window.getSize().y, window.getView().getSize().z);
        depthBuffer = new RenderTexture();
        frameBuffer = new RenderTexture();
        depthBuffer->create(resolution.x, resolution.y);
        frameBuffer->create(resolution.x, resolution.y);
        frameBuffer->setView(window.getView());
        depthBuffer->setView(window.getView());
     
        if (Shader::isAvailable()) {
            frameBufferGenerator = new Shader();
            depthBufferGenerator = new Shader();
            const std::string vertexShader =
            "void main () {"
                "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;"
                "gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0;"
                "gl_FrontColor = gl_Color;"
            "}";
            const std::string  depthGenFragShader =
            "uniform sampler2D depthBuffer;"
            "uniform sampler2D texture;"
            "uniform vec3 resolution;"
            "void main () {"
                  "vec2 position = ( gl_FragCoord.xy / resolution.xy );"
                  "vec4 color = texture2D(depthBuffer, position);"
                  "vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);"
                  "if (gl_FragCoord.z >= color.z && pixel.a >= color.a) {"
                     "gl_FragColor = vec4(0, 0,gl_FragCoord.z, pixel.a);"
                  "} else {"
                     "gl_FragColor = color;"
                  "}"
            "}";
            const std::string frameBufferGenFragShader =
            "uniform sampler2D depthBuffer;"
            "uniform sampler2D frameBuffer;"
            "uniform sampler2D texture;"
            "uniform vec3 resolution;"
            "void main () {	"
                "vec2 position = ( gl_FragCoord.xy / resolution.xy );"
                "vec4 depth = texture2D(depthBuffer, position);"
                "vec4 color = texture2D(frameBuffer, position);"
                "vec4 pixel = texture2D(texture, gl_TexCoord[0].xy);"
                "if (gl_FragCoord.z >= depth.z) {"
                    "gl_FragColor = pixel;"
                "} else if (color.a < pixel.a) {"
                    "gl_FragColor = pixel;"
                "} else {"
                    "gl_FragColor = color;"
                "}"
            "}";
            if (!depthBufferGenerator->loadFromMemory(vertexShader, depthGenFragShader))
                throw Erreur(50, "Failed to load depth buffer generator shader", 0);
            if (!frameBufferGenerator->loadFromMemory(vertexShader, frameBufferGenFragShader))
                throw Erreur(51, "Failed to load frame buffer generator shader", 0);
             depthBufferGenerator->setParameter("resolution",resolution.x, resolution.y, resolution.z);
             frameBufferGenerator->setParameter("resolution",resolution.x, resolution.y, resolution.z);
             backgroundColor = sf::Color::Transparent;
             running = updateDepthBuffer = false;
             g_notified = true;
             m_thread = std::thread(&FastRenderComponent::depthBufferUpdater, this);
     
        }
        currentStates.blendMode = sf::BlendAlpha;
    }
    void FastRenderComponent::setBackgroundColor(sf::Color color) {
        this->backgroundColor = color;
    }
    void FastRenderComponent::clearBufferBits() {
        frameBuffer->clear(backgroundColor);
    }
    void FastRenderComponent::clearDepthBits() {
        depthBuffer->clear(sf::Color::Transparent);
    }
    g2d::Tile FastRenderComponent::getFrameBufferTile () const {
        sf::IntRect subRect(0, 0, frameBuffer->getView().getSize().x, frameBuffer->getView().getSize().y);
        g2d::Tile tile (&frameBuffer->getTexture(), Vec2f(0, 0), Vec2f(frameBuffer->getView().getSize().x, frameBuffer->getView().getSize().y), subRect);
        return tile;
    }
    g2d::Tile FastRenderComponent::getDepthBufferTile() const {
        sf::IntRect subRect(0, 0, depthBuffer->getView().getSize().x, depthBuffer->getView().getSize().y);
        g2d::Tile tile (&depthBuffer->getTexture(), Vec2f(0, 0), Vec2f(depthBuffer->getView().getSize().x, depthBuffer->getView().getSize().y), subRect);
        return tile;
    }
    bool FastRenderComponent::loadEntitiesOnComponent(std::vector<Entity*> visibleEntities)
    {
     
        if (Shader::isAvailable()) {
            fg.clear();
            for (unsigned int i = 0; i < visibleEntities.size(); i++) {
     
                if (visibleEntities[i]->isLeaf()) {
                    for (unsigned int j = 0; j < visibleEntities[i]->getFaces().size(); j++) {
     
                        visibleEntities[i]->getFaces()[j]->transform(visibleEntities[i]->getTransform());
     
                        fg.addFace(visibleEntities[i]->getFaces()[j]);
                    }
                }
            }
            m_vertices = fg.getFaces();
        }
        this->visibleEntities = visibleEntities;
    }
    void FastRenderComponent::setView(View &view) {
        this->view = view;
    }
    void FastRenderComponent::updateDBuffer() {
        updateDepthBuffer = true;
        g_notified = false;
        g_signal.notify_one();
    }
    void FastRenderComponent::depthBufferUpdater() {
        running = true;
        while (running) {
            std::unique_lock<std::mutex> locker (g_lock_update);
            g_signal.wait(locker, [&](){return updateDepthBuffer || !running;});
            if (updateDepthBuffer) {
                depthBufferGenerator->setParameter("depthBuffer", depthBuffer->getTexture());
                depthBufferGenerator->setParameter("texture", Shader::CurrentTexture);
                currentStates.shader = depthBufferGenerator;
                depthBuffer->draw(*currentVa, currentStates);
                depthBuffer->display();
            }
     
            updateDepthBuffer = false;
            g_notified = true;
            g_signal.notify_one();
        }
    }
    void FastRenderComponent::drawNextFrame() {
        if (Shader::isAvailable()) {
            frameBuffer->setView(view);
            depthBuffer->setView(view);
            for (unsigned int i = 0; i < m_vertices.size(); i++) {
                currentStates.texture = m_vertices[i].first.getMaterial().getTexture();
                for (unsigned int j = 0; j < m_vertices[i].second.size(); j++) {
                    std::unique_lock<std::mutex> locker(g_lock_update);
                    g_signal.wait(locker, [&](){return g_notified;});
                    currentStates.shader = frameBufferGenerator;
                    frameBufferGenerator->setParameter("depthBuffer", depthBuffer->getTexture());
                    frameBufferGenerator->setParameter("frameBuffer", frameBuffer->getTexture());
                    frameBufferGenerator->setParameter("texture", Shader::CurrentTexture);
                    frameBuffer->draw(*m_vertices[i].second[j], currentStates);
                    frameBuffer->display();
                    currentVa = m_vertices[i].second[j];
                    /*depthBufferGenerator->setParameter("depthBuffer", depthBuffer->getTexture());
                    depthBufferGenerator->setParameter("texture", Shader::CurrentTexture);
                    currentStates.shader = depthBufferGenerator;
                    depthBuffer->draw(*currentVa, currentStates);
                    depthBuffer->display();*/
                    updateDBuffer();
                }
            }
        } else {
            for (unsigned int i = 0; i < visibleEntities.size(); i++) {
                for (unsigned int j = 0; j < visibleEntities[i]->getFaces().size(); j++) {
                    currentStates.texture = visibleEntities[i]->getFaces()[j]->getMaterial().getTexture();
                    currentStates.transform = visibleEntities[i]->getTransform();
                    frameBuffer->draw(visibleEntities[i]->getFaces()[j]->getVertexArray(), currentStates);
                }
            }
        }
     
    }
    void FastRenderComponent::draw(RenderTarget& target, RenderStates states) const {
        g2d::Tile tile = getDepthBufferTile();
        tile.setCenter(frameBuffer->getView().getPosition());
        states.transform = getTransform();
        target.draw(tile, states);
    }
    void FastRenderComponent::init() {
    }
     
    View& FastRenderComponent::getView() {
        return view;
    }
    int FastRenderComponent::getLayer() {
        return getPosition().z;
    }
    FastRenderComponent::~FastRenderComponent() {
        running = false;
        delete frameBuffer;
        delete frameBufferGenerator;
        delete depthBuffer;
        delete depthBufferGenerator;
    }
    }
    }
    Malheureusement ma depthtexture ne se dessine pas correctement et l'appel à clear ne marche pas lorsque j'utilise mon thread pour update la depthtexture, tout ce qui a été dessiné à la frame précédente sur la depthtexture n'est pas effacé.

    Dois je faire quelque chose au niveau du gpu pour la synchronisation ???

    Sinon, voici le code source de mon moteur (si quelqu'un a des idées d'optimisation) : https://github.com/Lolilolight/ODFAEG
    Dernière modification par Invité ; 18/04/2014 à 11h37.

  4. #4
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Je vais surement vous décevoir, mais ... pourquoi/comment dessinez vous deux images avec deux threads ?
    Vous êtes sur qu'une telle chose est possible ? Je veux dire, le GPU, il faut qu'il utilise les même tampons et qu'il arrive à pas écrire l'image 1, dans les tampons de l'image 2 ? On final, vous revenez à faire du séquentiel, si vous utilisez des lock et vous avez une complexité du code accrue.
    Malheureusement ma depthtexture ne se dessine pas correctement et l'appel à clear ne marche pas lorsque j'utilise mon thread pour update la depthtexture, tout ce qui a été dessiné à la frame précédente sur la depthtexture n'est pas effacé.
    Un clear efface tout, en théorie, tant que vous mettez la bonne valeur de nettoyage. Là, il semble que vous avez plus d'un problème. Peut être vous pouvez faire du débogage avec gDEBugger ?
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  5. #5
    Invité
    Invité(e)
    Par défaut
    En effet j'ai d'autres erreurs que opengl m'affiche en console et je ne comprends pas très bien pourquoi :

    texture.cpp ligne 497 : GL_INVALID_VALUE.

    shader.cpp ligne 469 : GL_INVALID_VALUE.

    vertexArray.cpp ligne 187 : GL_INVALID_OPERATION.

    Dans renderTarget.cpp ligne 314 : GL_INVALID_OPERATION.

    Sinon, je ne cherche pas à dessiner deux images dans le même tampon mais deux images dans deux tampons différents à l'aide des fbo.

    Bref je vais esssayer gDEBugger.

    PS : gDEBugger ne fonctionne pas sur mon PC. (lorsque je veux le lancer il m'indique que il y a une erreur et il me propose d'envoyer le rapport d'erreur)

  6. #6
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    texture.cpp ligne 497 : GL_INVALID_VALUE.

    shader.cpp ligne 469 : GL_INVALID_VALUE.

    vertexArray.cpp ligne 187 : GL_INVALID_OPERATION.

    Dans renderTarget.cpp ligne 314 : GL_INVALID_OPERATION.
    Il faut lire la documentation. Pour chaque fonction, les cas d'erreurs sont décrit.

    Pour faire deux rendus dans les FBO, pas besoin de deux threads, il suffit de les faire les un derrières les autres.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  7. #7
    Invité
    Invité(e)
    Par défaut
    Même avec la documentation je ne vois pas je sais juste que lorsque j'utilise les vbo apparemment j'ai une erreur car apparemment j'essaye de changer le viewport quand il ne faut pas. (Chaque composant peut avoir une caméra et un viewport différent)

    Les valeurs passée à glGetIntegerv me semble bonne, pareil pour celles passée à glSourceShaderARB.

    Je me demande si le code dans le fichier glCheck est bon..., et si opengl me donne la bonne ligne.

  8. #8
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    gDEBugger pourra vous ajouter des détails sur les erreurs, j'ose croire. Ou du moins, vous aider à les comprendre.
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  9. #9
    Expert éminent sénior

    Avatar de dragonjoker59
    Homme Profil pro
    Software Developer
    Inscrit en
    Juin 2005
    Messages
    2 031
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Bas Rhin (Alsace)

    Informations professionnelles :
    Activité : Software Developer
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2005
    Messages : 2 031
    Points : 11 379
    Points
    11 379
    Billets dans le blog
    11
    Par défaut
    Tu peux aussi essayer d'activer les extensions de debug (j'ai posté une source là-dessus).
    Ca peut être pratique.
    Si vous ne trouvez plus rien, cherchez autre chose...

    Vous trouverez ici des tutoriels OpenGL moderne.
    Mon moteur 3D: Castor 3D, presque utilisable (venez participer, il y a de la place)!
    Un projet qui ne sert à rien, mais qu'il est joli (des fois) : ProceduralGenerator (Génération procédurale d'images, et post-processing).

  10. #10
    Responsable 2D/3D/Jeux


    Avatar de LittleWhite
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mai 2008
    Messages
    26 859
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

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

    Informations forums :
    Inscription : Mai 2008
    Messages : 26 859
    Points : 218 580
    Points
    218 580
    Billets dans le blog
    120
    Par défaut
    Oui, en effet, il y a le code de dragonjoker59 , et aussi ce billet de blog : http://blog.developpez.com/gpu/?p=6
    Vous souhaitez participer à la rubrique 2D/3D/Jeux ? Contactez-moi

    Ma page sur DVP
    Mon Portfolio

    Qui connaît l'erreur, connaît la solution.

  11. #11
    Invité
    Invité(e)
    Par défaut
    Salut, j'ai essayer de faire ce que vous m'avez en reprenant le code de joker et j'ai modifié ma version personnelle de SFML pour qu'elle aie un meilleur context de débug :

    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
     
     // Protect from concurrent access
     
            #ifdef SFML_DEBUG
            #ifndef DEBUG_FUNCTIONS_LOADED
            std::cout<<"loading internal sfml debug function"<<std::endl;
            OpenGL::LoadDebugFunctions();
            #define  DEBUG_FUNCTIONS_LOADED
            #endif
            #endif
            // If this is the very first resource, trigger the global context initialization
            Lock lock(mutex);
            if (count == 0)
                priv::GlContext::globalInit();
            #ifdef SFML_DEBUG
            #ifndef DEBUG_FUNCTIONS_INITIALIZED
            std::cout<<"initializing internal opengl debug functions"<<std::endl;
            OpenGL::InitialiseDebugFunctions();
            #define DEBUG_FUNCTIONS_INITIALIZED
            #endif
            #endif // DEBUG_FUNCTIONS_INITIALIZED
            // Increment the resources counter
            count++;
    Mais lors de l'appel à la fonction loadDebugFunctions j'ai un crash.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    #0 0045ECE0	__cxa_throw () (??:??)
    #1 0045D21B	std::__throw_logic_error(char const*) () (??:??)
    #2 004B5954	char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) () (??:??)
    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
     
     // Protect from concurrent access
     
            #ifdef SFML_DEBUG
            #ifndef DEBUG_FUNCTIONS_LOADED
            std::cout<<"loading internal sfml debug function"<<std::endl;
            OpenGL::LoadDebugFunctions();
            #define  DEBUG_FUNCTIONS_LOADED
            #endif
            #endif
            // If this is the very first resource, trigger the global context initialization
            Lock lock(mutex);
            if (count == 0)
                priv::GlContext::globalInit();
            #ifdef SFML_DEBUG
            #ifndef DEBUG_FUNCTIONS_INITIALIZED
            std::cout<<"initializing internal opengl debug functions"<<std::endl;
            OpenGL::InitialiseDebugFunctions();
            #define DEBUG_FUNCTIONS_INITIALIZED
            #endif
            #endif // DEBUG_FUNCTIONS_INITIALIZED
            // Increment the resources counter
            count++;
    Ai je fais quelque chose de mauvais, et, dois je quand même faire ceci :

    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
     
    int attribs[] = 
    { 
    #ifdefWIN32 
        WGL_CONTEXT_MAJOR_VERSION_ARB, 4, 
        WGL_CONTEXT_MINOR_VERSION_ARB, 1, 
        WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB, 
        WGL_CONTEXT_PROFILE_MASK, WGL_CONTEXT_CORE_PROFILE_BIT_ARB, 
    #endif 
    #ifdef__linux__ 
        GLX_CONTEXT_MAJOR_VERSION_ARB, 4, 
        GLX_CONTEXT_MINOR_VERSION_ARB, 1, 
        GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, 
        GLX_CONTEXT_PROFILE_MASK, GLX_CONTEXT_CORE_PROFILE_BIT_ARB, 
    #endif 
        0 
    };
    Avant d'appelé les fonctions de chargement et d'initialisation des extensions ???

  12. #12
    Invité
    Invité(e)
    Par défaut
    Aparremment j'avais oublié d'initialisé glew mais, même en essayant de rajouter ça , j'ai un autre crash :
    Code cpp : 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
     
    void WglContext::createContext(WglContext* shared, unsigned int bitsPerPixel, const ContextSettings& settings)
    {
        // Save the creation settings
        m_settings = settings;
     
        // Let's find a suitable pixel format -- first try with antialiasing
        int bestFormat = 0;
        if (m_settings.antialiasingLevel > 0)
        {
            // Get the wglChoosePixelFormatARB function (it is an extension)
            PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = reinterpret_cast<PFNWGLCHOOSEPIXELFORMATARBPROC>(wglGetProcAddress("wglChoosePixelFormatARB"));
            if (wglChoosePixelFormatARB)
            {
                // Define the basic attributes we want for our window
                int intAttributes[] =
                {
                    WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
    		        WGL_SUPPORT_OPENGL_ARB, GL_TRUE,
    		        WGL_ACCELERATION_ARB,   WGL_FULL_ACCELERATION_ARB,
    		        WGL_DOUBLE_BUFFER_ARB,  GL_TRUE,
                    WGL_SAMPLE_BUFFERS_ARB, (m_settings.antialiasingLevel ? GL_TRUE : GL_FALSE),
    		        WGL_SAMPLES_ARB,        static_cast<int>(m_settings.antialiasingLevel),
    		        WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
                    /*WGL_CONTEXT_PROFILE_MASK,*/ WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
    		        0,                      0
                };
     
                // Let's check how many formats are supporting our requirements
                int   formats[128];
    	        UINT  nbFormats;
    	        float floatAttributes[] = {0, 0};
    	        bool  isValid = wglChoosePixelFormatARB(m_deviceContext, intAttributes, floatAttributes, sizeof(formats) / sizeof(*formats), formats, &nbFormats) != 0;
                while ((!isValid || (nbFormats == 0)) && m_settings.antialiasingLevel > 0)
                {
                    // Decrease the antialiasing level until we find a valid one
                    m_settings.antialiasingLevel--;
                    intAttributes[11] = m_settings.antialiasingLevel;
                    isValid = wglChoosePixelFormatARB(m_deviceContext, intAttributes, floatAttributes, sizeof(formats) / sizeof(*formats), formats, &nbFormats) != 0;
                }
     
                // Get the best format among the returned ones
                if (isValid && (nbFormats > 0))
                {
                    int bestScore = 0xFFFF;
                    for (UINT i = 0; i < nbFormats; ++i)
                    {
                        // Get the current format's attributes
                        PIXELFORMATDESCRIPTOR attributes;
                        attributes.nSize    = sizeof(attributes);
                        attributes.nVersion = 1;
                        DescribePixelFormat(m_deviceContext, formats[i], sizeof(attributes), &attributes);
     
                        // Evaluate the current configuration
                        int color = attributes.cRedBits + attributes.cGreenBits + attributes.cBlueBits + attributes.cAlphaBits;
                        int score = evaluateFormat(bitsPerPixel, m_settings, color, attributes.cDepthBits, attributes.cStencilBits, m_settings.antialiasingLevel);
     
                        // Keep it if it's better than the current best
                        if (score < bestScore)
                        {
                            bestScore  = score;
                            bestFormat = formats[i];
                        }
                    }
                }
            }
            else
            {
                // wglChoosePixelFormatARB not supported ; disabling antialiasing
                err() << "Antialiasing is not supported ; it will be disabled" << std::endl;
                m_settings.antialiasingLevel = 0;
            }
        }
     
        // Find a pixel format with no antialiasing, if not needed or not supported
        if (bestFormat == 0)
        {
            // Setup a pixel format descriptor from the rendering settings
            PIXELFORMATDESCRIPTOR descriptor;
            ZeroMemory(&descriptor, sizeof(descriptor));
            descriptor.nSize        = sizeof(descriptor);
            descriptor.nVersion     = 1;
            descriptor.iLayerType   = PFD_MAIN_PLANE;
            descriptor.dwFlags      = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
            descriptor.iPixelType   = PFD_TYPE_RGBA;
            descriptor.cColorBits   = static_cast<BYTE>(bitsPerPixel);
            descriptor.cDepthBits   = static_cast<BYTE>(m_settings.depthBits);
            descriptor.cStencilBits = static_cast<BYTE>(m_settings.stencilBits);
            descriptor.cAlphaBits   = bitsPerPixel == 32 ? 8 : 0;
     
            // Get the pixel format that best matches our requirements
            bestFormat = ChoosePixelFormat(m_deviceContext, &descriptor);
            if (bestFormat == 0)
            {
                err() << "Failed to find a suitable pixel format for device context -- cannot create OpenGL context" << std::endl;
                return;
            }
        }
     
        // Extract the depth and stencil bits from the chosen format
        PIXELFORMATDESCRIPTOR actualFormat;
        actualFormat.nSize    = sizeof(actualFormat);
        actualFormat.nVersion = 1;
        DescribePixelFormat(m_deviceContext, bestFormat, sizeof(actualFormat), &actualFormat);
        m_settings.depthBits   = actualFormat.cDepthBits;
        m_settings.stencilBits = actualFormat.cStencilBits;
     
        // Set the chosen pixel format
        if (!SetPixelFormat(m_deviceContext, bestFormat, &actualFormat))
        {
            err() << "Failed to set pixel format for device context -- cannot create OpenGL context" << std::endl;
            return;
        }
     
        // Get the context to share display lists with
        HGLRC sharedContext = shared ? shared->m_context : NULL;
     
        // Create the OpenGL context -- first try context versions >= 3.0 if it is requested (they require special code)
        while (!m_context && (m_settings.majorVersion >= 3))
        {
            PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = reinterpret_cast<PFNWGLCREATECONTEXTATTRIBSARBPROC>(wglGetProcAddress("wglCreateContextAttribsARB"));
            if (wglCreateContextAttribsARB)
            {
                int attributes[] =
                {
                    WGL_CONTEXT_MAJOR_VERSION_ARB, static_cast<int>(m_settings.majorVersion),
                    WGL_CONTEXT_MINOR_VERSION_ARB, static_cast<int>(m_settings.minorVersion),
                    WGL_CONTEXT_PROFILE_MASK_ARB, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB,
                    WGL_CONTEXT_FLAGS_ARB, WGL_CONTEXT_DEBUG_BIT_ARB,
                    /*WGL_CONTEXT_PROFILE_MASK,*/ WGL_CONTEXT_CORE_PROFILE_BIT_ARB,
                    0, 0
                };
                m_context = wglCreateContextAttribsARB(m_deviceContext, sharedContext, attributes);
            }
     
            // If we couldn't create the context, lower the version number and try again -- stop at 3.0
            // Invalid version numbers will be generated by this algorithm (like 3.9), but we really don't care
            if (!m_context)
            {
                if (m_settings.minorVersion > 0)
                {
                    // If the minor version is not 0, we decrease it and try again
                    m_settings.minorVersion--;
                }
                else
                {
                    // If the minor version is 0, we decrease the major version
                    m_settings.majorVersion--;
                    m_settings.minorVersion = 9;
                }
            }
        }
     
        // If the OpenGL >= 3.0 context failed or if we don't want one, create a regular OpenGL 1.x/2.x context
        if (!m_context)
        {
            // set the context version to 2.0 (arbitrary)
            m_settings.majorVersion = 2;
            m_settings.minorVersion = 0;
     
            m_context = wglCreateContext(m_deviceContext);
            if (!m_context)
            {
                err() << "Failed to create an OpenGL context for this window" << std::endl;
                return;
            }
     
            // Share this context with others
            if (sharedContext)
            {
                // wglShareLists doesn't seem to be thread-safe
                static Mutex mutex;
                Lock lock(mutex);
     
                if (!wglShareLists(sharedContext, m_context))
                    err() << "Failed to share the OpenGL context" << std::endl;
            }
        }
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    #0 0028FBB0	?? () (??:??)
    #1 004E7E54	)::modes () (??:??)
    #2 C02404C7	?? () (??:??)
    #3 E80050C7	?? () (??:??)
    #4 000C85B3	?? () (??:??)
    #5 E8240489	?? () (??:??)
    #6 000C6E9B	?? () (??:??)
    #7 00894AE8	?? () (??:??)
    Il me donne pas plus d'info que ça.

    Et autre chose, il ne me trouve pas WGL_CONTEXT_PROFIL_MASK

  13. #13
    Invité
    Invité(e)
    Par défaut
    Ha non c'est bon j'ai trouvé comment qu'il fallait faire :

    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
     
    GlResource::GlResource(){
     
            // Protect from concurrent access
     
            // If this is the very first resource, trigger the global context initialization
            Lock lock(mutex);
            if (count == 0)
                priv::GlContext::globalInit();
            odfaeg::priv::ensureGlewInit();
            #ifdef SFML_DEBUG
            #ifndef DEBUG_FUNCTIONS_LOADED
            std::cout<<"loading internal sfml debug function"<<std::endl;
            OpenGL::LoadDebugFunctions();
            #define  DEBUG_FUNCTIONS_LOADED
            #endif
            #endif
     
            // Increment the resources counter
            count++;
     
     
        // Now make sure that there is an active OpenGL context in the current thread
        priv::GlContext::ensureContext();
     
        #ifdef SFML_DEBUG
        #ifndef DEBUG_FUNCTIONS_INITIALIZED
        std::cout<<"initializing internal opengl debug functions"<<std::endl;
        OpenGL::InitialiseDebugFunctions();
        #define DEBUG_FUNCTIONS_INITIALIZED
        #endif
        #endif // DEBUG_FUNCTIONS_INITIALIZED
    }
    Mais j'ai du supprimé cette ligne sinon ça crash encore :

    Code cpp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    else if( glDebugMessageCallbackAMD )
        {
             glDebugMessageCallbackAMD( PFNGLDEBUGAMDPROC( &CallbackDebugLogAMD ), NULL );
             //glEnable( gl_api::iGL_DEBUG_OUTPUT_SYNCHRONOUS );
        }


    Voilà ce que ça me donne quand je décommente cette ligne à mon avi je ne possède pas l'extension pour la syncrhonisation :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
     
    #0 5137D3FA	atioglxx!DrvPresentBuffers() (C:\Windows\SysWOW64\atioglxx.dll:??)
    #1 515FC850	atioglxx!DrvPresentBuffers() (C:\Windows\SysWOW64\atioglxx.dll:??)
    #2 0041F5EE	OpenGL::InitialiseDebugFunctions() (D:\Projets\Projets-c++\ODFAEG\src\odfaeg\Graphics\GlDebug.cpp:143)
    #3 00416ABE	odfaeg::GlResource::GlResource(this=<optimized out>) (D:\Projets\Projets-c++\ODFAEG\src\odfaeg\Graphics\GlResource.cpp:74)
    #4 004060B9	odfaeg::Window::Window(this=<optimized out>) (D:\Projets\Projets-c++\ODFAEG\src\odfaeg\Graphics\Window.cpp:48)
    #5 00406A87	odfaeg::RenderWindow::RenderWindow(this=<optimized out>, mode=..., title=..., style=<optimized out>, settings=..., useDepthDepth=<optimized out>) (D:\Projets\Projets-c++\ODFAEG\src\odfaeg\Graphics\renderWindow.cpp:17)
    #6 0048C0B7	Application(settings=..., style=7, g2dAppli=true, nbComponents=2, title=..., vm=..., this=<optimized out>) (C:/ODFAEG/include/odfaeg/Core/application.h:15)
    #7 ??	MyAppli::MyAppli (this=this@entry=0x28fe90, wm=..., title=..., title@entry=...) (D:/Projets/Projets-c++/ODFAEG-DEMO/myApplication.h:44)
    #8 004E1102	main() (D:\Projets\Projets-c++\ODFAEG-DEMO\main.cpp:10)
    Au sinon, les fonctions de callback ne m'affichent pas d'erreur ce qui est bizarre ça saccade quand même.

    Et je ne peux malheureusement pas le profiler si l'extension de sychronisation en fonctionne pas. (Le plugin avec code::block (pour lancé gproof) ne fonctionne pas non plus. (depuis que j'utilise tdm-gcc) :/

    PS : sinon ma version d'opengl est la 4.2.12002

  14. #14
    Invité
    Invité(e)
    Par défaut
    Bon, ça ne marche définitivement pas..., les seuls message que j'arrive à obtenir sont des messages d'erreurs insensé renvoyé par la fonction glGetError.

    Les extensions se chargent bien mais glEnable ne veut pas les activer ont dirait que mon driver ATI n'en veut tout simplement pas. (Pourtant j'ai la version opengl 4.2 et le driver le plus à jour qui ne plante pas)

    Au niveau de l'affichage graphique quand je compile en mode debug ça affiche quelque chose même si ça saccade un peu mais en mode release ça ne m'affiche rien.

  15. #15
    Invité
    Invité(e)
    Par défaut
    Bon finalement j'ai trouvé pour les erreurs il suffisait simplement que je retire la fonction glFustum dans ma classe view.

  16. #16
    Invité
    Invité(e)
    Par défaut
    Bon finalement j'ai trouvé pour les erreurs il suffisait simplement que je retire la fonction glFustum dans ma classe view et je n'ai plus d'erreurs qui s'affichent avec glGetError.

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

Discussions similaires

  1. [AC-2007] optimiser le tps de traitement des calculs
    Par seb7t1 dans le forum VBA Access
    Réponses: 4
    Dernier message: 05/03/2011, 18h02
  2. au niveau des smileys ...
    Par ETI-trian dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 22/10/2005, 22h47
  3. Optimisation PHP4 lorsque l'on utilise presque des classes
    Par ouioui2000 dans le forum Langage
    Réponses: 2
    Dernier message: 11/10/2005, 17h05
  4. optimisation de temps de traitement xml/xslt
    Par Erwy dans le forum XSL/XSLT/XPATH
    Réponses: 2
    Dernier message: 06/05/2004, 16h08

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