コード例 #1
0
 bool CgGLShader::initialize(const ResourcePtr& resource, const ShaderDesc& desc) {
     CGprofile profile;
     mDesc = desc;
     switch (desc.type) {
     case ukn::ST_FragmentShader:
         profile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
         break;
     case ukn::ST_VertexShader:
         profile = cgGLGetLatestProfile(CG_GL_VERTEX);
         break;
     case ukn::ST_GeometryShader:
         profile = cgGLGetLatestProfile(CG_GL_GEOMETRY);
         
         break;
     }
     StreamPtr stream = resource->readIntoMemory();
     if(!stream)
         return false;
     
     MemoryStream* memStream = ((MemoryStream*)stream.get());
     std::string content(memStream->data(), memStream->data() + memStream->size());
     mProgram = cgCreateProgram(mContext, 
         CG_SOURCE, 
         content.c_str(), 
         profile, 
         desc.entry.c_str(), 
         cgGLGetOptimalOptions(profile));
     if(_check_error(mContext)) {
         cgGLLoadProgram(mProgram);
         mProfile = profile;
         return _check_error(mContext);
     }
     return false;;
 }
コード例 #2
0
 bool CgDxShader::initialize(D3D11GraphicDevice* device, const ResourcePtr& resource, const ShaderDesc& desc) {
     mDesc = desc;
     
     StreamPtr stream = resource->readIntoMemory();
     if(!stream)
         return false;
     MemoryStream* memStream = ((MemoryStream*)stream.get());
     std::string content(memStream->data(), memStream->data() + memStream->size());
     
     CGprofile profile = _d3d_feature_level_to_cgprofile(device->getDeviceFeatureLevel(), desc.type);
     mProgram = cgCreateProgram(mContext, 
         CG_SOURCE, 
         content.c_str(), 
         profile, 
         desc.entry.c_str(), 
         cgD3D11GetOptimalOptions(profile));
     if(_check_error(mContext) &&
         D3D11Debug::CHECK_RESULT( cgD3D11LoadProgram(mProgram, 0))) {
             return true;
     }
     return false;
 }