Changeset 828


Ignore:
Timestamp:
Aug 16, 2011, 7:02:17 PM (8 years ago)
Author:
sam
Message:

ps3: if the implementation supports Cg but not GLSL (for instance on the PS3),
use the system's Cg compiler.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/monsterz/ps3/Makefile

    r762 r828  
    2020PPU_LDLIBS := $(GRAPHICS_SAMPLE_CORE_LIBS)
    2121
     22# For the runtime Cg compiler
     23PPU_LDLIBS += -lcgc -lPSGLcgc
     24
    2225include $(CELL_SDK)/samples/sdk/graphics/psgl/MakeRules
    2326
  • trunk/src/shader/shader.cpp

    r818 r828  
    3939
    4040private:
     41#if !defined __CELLOS_LV2__
    4142    GLuint prog_id, vert_id, frag_id;
     43#else
     44    CGprogram vert_id, frag_id;
     45#endif
    4246    uint32_t vert_crc, frag_crc;
    4347
     
    8589  : data(new ShaderData())
    8690{
     91#if !defined __CELLOS_LV2__
    8792    char buf[4096], errbuf[4096];
    8893    char const *shader = buf;
    8994    GLint status;
    9095    GLsizei len;
    91 
    92 #if !defined __CELLOS_LV2__
     96#else
     97    /* Initialise the runtime shader compiler. FIXME: this needs only
     98     * to be done once. */
     99    cgRTCgcInit();
     100#endif
     101
    93102    /* Compile vertex shader */
    94103    data->vert_crc = Hash::Crc32(vert);
     104#if !defined __CELLOS_LV2__
    95105    ShaderData::Patch(buf, vert, NULL);
    96106    data->vert_id = glCreateShader(GL_VERTEX_SHADER);
     
    105115        Log::Error("shader source:\n%s\n", buf);
    106116    }
     117#else
     118    data->vert_id = cgCreateProgram(cgCreateContext(), CG_SOURCE, vert,
     119                                    cgGLGetLatestProfile(CG_GL_VERTEX),
     120                                    NULL, NULL);
     121    if (data->vert_id == NULL)
     122    {
     123        Log::Error("failed to compile vertex shader");
     124        Log::Error("shader source:\n%s\n", vert);
     125    }
     126#endif
    107127
    108128    /* Compile fragment shader */
    109129    data->frag_crc = Hash::Crc32(frag);
     130#if !defined __CELLOS_LV2__
    110131    ShaderData::Patch(buf, NULL, frag);
    111132    data->frag_id = glCreateShader(GL_FRAGMENT_SHADER);
     
    120141        Log::Error("shader source:\n%s\n", buf);
    121142    }
    122 
     143#else
     144    data->frag_id = cgCreateProgram(cgCreateContext(), CG_SOURCE, frag,
     145                                    cgGLGetLatestProfile(CG_GL_FRAGMENT),
     146                                    NULL, NULL);
     147    if (data->frag_id == NULL)
     148    {
     149        Log::Error("failed to compile fragment shader");
     150        Log::Error("shader source:\n%s\n", frag);
     151    }
     152#endif
     153
     154#if !defined __CELLOS_LV2__
    123155    /* Create program */
    124156    data->prog_id = glCreateProgram();
     
    133165int Shader::GetAttribLocation(char const *attr) const
    134166{
    135 #if defined __CELLOS_LV2__
     167#if !defined __CELLOS_LV2__
     168    return glGetAttribLocation(data->prog_id, attr);
     169#else
     170    /* FIXME: need to differentiate between vertex and fragment program */
    136171    return 0;
    137 #else
    138     return glGetAttribLocation(data->prog_id, attr);
    139172#endif
    140173}
     
    142175int Shader::GetUniformLocation(char const *uni) const
    143176{
    144 #if defined __CELLOS_LV2__
    145     return 0;
    146 #else
     177#if !defined __CELLOS_LV2__
    147178    return glGetUniformLocation(data->prog_id, uni);
     179#else
     180    /* FIXME: need to differentiate between vertex and fragment program,
     181     * and replace the ugly cast. */
     182    CGparameter tmp = cgGetNamedParameter(data->vert_id, uni);
     183    if (tmp == NULL)
     184        tmp = cgGetNamedParameter(data->frag_id, uni);
     185    return (int)(intptr_t)tmp;
    148186#endif
    149187}
     
    151189void Shader::Bind() const
    152190{
    153 #if defined __CELLOS_LV2__
    154     ;
    155 #else
     191#if !defined __CELLOS_LV2__
    156192    glUseProgram(data->prog_id);
     193#else
     194    cgGLEnableProfile(cgGLGetLatestProfile(CG_GL_VERTEX));
     195    cgGLBindProgram(data->vert_id);
     196    cgGLEnableProfile(cgGLGetLatestProfile(CG_GL_FRAGMENT));
     197    cgGLBindProgram(data->frag_id);
    157198#endif
    158199}
     
    160201Shader::~Shader()
    161202{
    162 #if defined __CELLOS_LV2__
    163     ;
    164 #else
     203#if !defined __CELLOS_LV2__
    165204    glDetachShader(data->prog_id, data->vert_id);
    166205    glDetachShader(data->prog_id, data->frag_id);
     
    168207    glDeleteShader(data->frag_id);
    169208    glDeleteProgram(data->prog_id);
     209#else
     210    cgDestroyProgram(data->vert_id);
     211    cgDestroyProgram(data->frag_id);
     212#endif
    170213    delete data;
    171 #endif
    172214}
    173215
Note: See TracChangeset for help on using the changeset viewer.