当前位置: 首页>>代码示例>>C++>>正文


C++ CreateProgram函数代码示例

本文整理汇总了C++中CreateProgram函数的典型用法代码示例。如果您正苦于以下问题:C++ CreateProgram函数的具体用法?C++ CreateProgram怎么用?C++ CreateProgram使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CreateProgram函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: PezInitialize

const char* PezInitialize(int width, int height)
{
    BuddhaMesh = CreateMesh("buddha.ctm");
    QuadVbo = CreateQuad(-1, -1, 1, 1);
    
#ifdef LIGHTING
    DepthProgram = CreateProgram("Glass.Vertex", "Glass.Fragment.Lighting" SUFFIX);
    AbsorptionProgram = CreateProgram("Glass.Vertex.Quad", "Glass.Fragment.Blit" SUFFIX);
#else
    DepthProgram = CreateProgram("Glass.Vertex", "Glass.Fragment.Depth" SUFFIX);
    AbsorptionProgram = CreateProgram("Glass.Vertex.Quad", "Glass.Fragment.Absorption" SUFFIX);
#endif

    // Create a floating-point render target:
    GLuint textureHandle;
    glGenTextures(1, &textureHandle);
    glBindTexture(GL_TEXTURE_2D, textureHandle);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    
#ifdef LIGHTING
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 768, 1024, 0, GL_RGB, GL_UNSIGNED_BYTE, 0);
#elif defined(__IPAD__)
    glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 768, 1024, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, 0);
#else
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RG16F, 768, 1024, 0, GL_RG, GL_FLOAT, 0);
#endif
    
    PezCheckCondition(GL_NO_ERROR == glGetError(), "This passes on Mac OS X and iOS.");
    OffscreenTexture = textureHandle;
    
    GLuint fboHandle;
    glGenFramebuffers(1, &fboHandle);
    glBindFramebuffer(GL_FRAMEBUFFER, fboHandle);
    glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureHandle, 0);

#ifdef LIGHTING
    GLuint depthRenderbuffer;
    glGenRenderbuffers(1, &depthRenderbuffer);
    glBindRenderbuffer(GL_RENDERBUFFER, depthRenderbuffer);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRenderbuffer);
#endif

    PezCheckCondition(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER), "This asserts on iOS and passes on Mac OS X.");
    OffscreenFbo = fboHandle;

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
    glBindRenderbuffer(GL_RENDERBUFFER, 0);
    
    // Set up the projection matrix:
    const float HalfWidth = 0.5;
    const float HalfHeight = HalfWidth * PEZ_VIEWPORT_HEIGHT / PEZ_VIEWPORT_WIDTH;
    ProjectionMatrix = M4MakeFrustum(-HalfWidth, +HalfWidth, -HalfHeight, +HalfHeight, 5, 20);

    return "Glass Demo";
}
开发者ID:jsj2008,项目名称:blog-source,代码行数:59,代码来源:Glass.c

示例2: NS_ASSERTION

bool
ShaderProgramOGL::Initialize()
{
  NS_ASSERTION(mProgramState == STATE_NEW, "Shader program has already been initialised");

  if (!CreateProgram(mProfile.mVertexShaderString,
                     mProfile.mFragmentShaderString)) {
    mProgramState = STATE_ERROR;
    return false;
  }

  mProgramState = STATE_OK;

  for (uint32_t i = 0; i < KnownUniform::KnownUniformCount; ++i) {
    mProfile.mUniforms[i].mLocation =
      mGL->fGetUniformLocation(mProgram, mProfile.mUniforms[i].mNameString);
  }

  for (uint32_t i = 0; i < mProfile.mAttributes.Length(); ++i) {
    mProfile.mAttributes[i].mLocation =
      mGL->fGetAttribLocation(mProgram, mProfile.mAttributes[i].mName);
    NS_ASSERTION(mProfile.mAttributes[i].mLocation >= 0, "Bad attribute location.");
  }

  mProfile.mHasMatrixProj = mProfile.mUniforms[KnownUniform::MatrixProj].mLocation != -1;

  return true;
}
开发者ID:siteshwar,项目名称:gecko-dev-1,代码行数:28,代码来源:OGLShaderProgram.cpp

示例3: GetNewShaderProgram

Graphics::ShaderProgram* ShaderManager::GetNewShaderProgram(const istring &filename)
{
    auto strings = Utility::File::ParseToStrings(filename);
    auto shader = new Graphics::ShaderProgram();
    shader->CreateProgram();
    for (auto str : strings)
    {
        auto type = str[0];
        auto sfile = str.substr(2);
        switch (type)
        {
        case 'F':
            shader->CompileShader(sfile.c_str(), GL_FRAGMENT_SHADER, false);
            break;
        case 'V':
            shader->CompileShader(sfile.c_str(), GL_VERTEX_SHADER, false);
            break;
        default:
            std::cout << "Invalid shader Type=[" << type << "] specified in FileName=[" << filename << "]";
            return nullptr;
        }
    }
    shader->LinkProgram();
    shader->SetShaderName(filename);
    return shader;
}
开发者ID:affliction50,项目名称:gfx,代码行数:26,代码来源:ShaderManager.cpp

示例4: buildCachedProgram

cl_int buildCachedProgram(ocl_constructs * occs, char * filebase, const char * options){

  cl_int error = 0;

  if(occs->program != NULL)
    return error;

  char binaryName[256];
  binaryName[0] = '\0';
  strcat(binaryName, filebase);
  strcat(binaryName, ".bin");

  occs->program = CreateProgramFromBinary(occs->context, occs->deviceId, binaryName, options);

  if(occs->program == NULL){

    occs->program = CreateProgram(occs->context, occs->deviceId, filebase, options);

    if(occs->program == NULL){
      //Cleanup(context, commandQueue, program, kernel, memObjects);
      fprintf(stderr, "cachedProgram.c::buildCachedProgram failed to build program\n");
      return 1;
    }

    if(SaveProgramBinary(occs->program, occs->deviceId, binaryName)){
      fprintf(stderr, "cachedProgram.c::buildCachedProgram failed to save program binary\n");
      //CLeanup
      return 2;
    }

  }

  return error;

}
开发者ID:ipanousis,项目名称:Mandelbrot,代码行数:35,代码来源:cachedProgram.c

示例5: SkASSERT

bool GrGLShaderBuilder::finish() {
    SkASSERT(0 == fOutput.fProgramID);
    GL_CALL_RET(fOutput.fProgramID, CreateProgram());
    if (!fOutput.fProgramID) {
        return false;
    }

    SkTDArray<GrGLuint> shadersToDelete;

    if (!this->compileAndAttachShaders(fOutput.fProgramID, &shadersToDelete)) {
        GL_CALL(DeleteProgram(fOutput.fProgramID));
        return false;
    }

    this->bindProgramLocations(fOutput.fProgramID);
    if (fUniformManager->isUsingBindUniform()) {
        fUniformManager->getUniformLocations(fOutput.fProgramID, fUniforms);
    }

    GL_CALL(LinkProgram(fOutput.fProgramID));

    // Calling GetProgramiv is expensive in Chromium. Assume success in release builds.
    bool checkLinked = !fGpu->ctxInfo().isChromium();
#ifdef SK_DEBUG
    checkLinked = true;
#endif
    if (checkLinked) {
        GrGLint linked = GR_GL_INIT_ZERO;
        GL_CALL(GetProgramiv(fOutput.fProgramID, GR_GL_LINK_STATUS, &linked));
        if (!linked) {
            GrGLint infoLen = GR_GL_INIT_ZERO;
            GL_CALL(GetProgramiv(fOutput.fProgramID, GR_GL_INFO_LOG_LENGTH, &infoLen));
            SkAutoMalloc log(sizeof(char)*(infoLen+1));  // outside if for debugger
            if (infoLen > 0) {
                // retrieve length even though we don't need it to workaround
                // bug in chrome cmd buffer param validation.
                GrGLsizei length = GR_GL_INIT_ZERO;
                GL_CALL(GetProgramInfoLog(fOutput.fProgramID,
                                          infoLen+1,
                                          &length,
                                          (char*)log.get()));
                GrPrintf((char*)log.get());
            }
            SkDEBUGFAIL("Error linking program");
            GL_CALL(DeleteProgram(fOutput.fProgramID));
            fOutput.fProgramID = 0;
            return false;
        }
    }

    if (!fUniformManager->isUsingBindUniform()) {
        fUniformManager->getUniformLocations(fOutput.fProgramID, fUniforms);
    }

    for (int i = 0; i < shadersToDelete.count(); ++i) {
      GL_CALL(DeleteShader(shadersToDelete[i]));
    }

    return true;
}
开发者ID:cnh,项目名称:skia,代码行数:60,代码来源:GrGLShaderBuilder.cpp

示例6: CreateProgram

mjSkyboxShaders::mjSkyboxShaders()
{
	// Set up shader
	CreateProgram(skyboxVertexShaderCode, skyboxFragmentShaderCode);
	name = new char[7];
	strncpy(name, "skybox", strnlen("skybox", 10)+1);
    LOGI("%s %d: new %s", __FILE__, __LINE__, "char[] for skybox shader name");

    checkGlError("create glProgram");

    // Get the texture handle location
    maTextureHandle = glGetUniformLocation(glProgramHandle, "uTexture");

    maMVPMatrixHandle = glGetUniformLocation(glProgramHandle, "maMVPMatrix");
    maMMatrixHandle = glGetUniformLocation(glProgramHandle, "maMMatrix");


    checkGlError("getting parameters");

    LOGI("textureHandle %d, mvpMAtrixHandle %d", maTextureHandle, maMVPMatrixHandle);

    enableDepthMask = false;
    enableDepthTest = false;

}
开发者ID:fysiskhund,项目名称:mjEngineCPP,代码行数:25,代码来源:mjSkyboxShaders.cpp

示例7: WebGLContextBoundObject

WebGLProgram::WebGLProgram(WebGLContext* webgl)
    : WebGLContextBoundObject(webgl)
    , mGLName(CreateProgram(webgl->GL()))
    , mTransformFeedbackBufferMode(LOCAL_GL_NONE)
{
    mContext->mPrograms.insertBack(this);
}
开发者ID:Danielzac,项目名称:gecko-dev,代码行数:7,代码来源:WebGLProgram.cpp

示例8: CreateBoundaries

void CreateBoundaries(Surface dest, int width, int height)
{
	glBindFramebuffer(GL_FRAMEBUFFER, dest.FboHandle);
	glViewport(0, 0, width, height);
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);

	GLuint vao;
    glGenVertexArrays(1, &vao);
    glBindVertexArray(vao);
	GLuint program = CreateProgram("Vertex.ver", "Fill.frag");
	glUseProgram(program);

	#define T 0.9999f
    float positions[] = { -T, -T, T, -T, T,  T, -T,  T, -T, -T };
    #undef T
    GLuint vbo;
    GLsizeiptr size = sizeof(positions);
    glGenBuffers(1, &vbo);
    glBindBuffer(GL_ARRAY_BUFFER, vbo);
    glBufferData(GL_ARRAY_BUFFER, size, positions, GL_STATIC_DRAW);
    GLsizeiptr stride = 2 * sizeof(positions[0]);
    glEnableVertexAttribArray(PositionSlot);
    glVertexAttribPointer(PositionSlot, 2, GL_FLOAT, GL_FALSE, stride, 0);
    glDrawArrays(GL_LINE_STRIP, 0, 5);
    glDeleteBuffers(1, &vbo);

	glDeleteProgram(program);
    glDeleteVertexArrays(1, &vao);

}
开发者ID:raghava-sudana,项目名称:FluidSimulation,代码行数:31,代码来源:Implementation.cpp

示例9: InitializeProgram

void InitializeProgram()
{
    std::vector<GLuint> shaderList;
    
    shaderList.push_back(LoadShader(GL_VERTEX_SHADER, "PosColorLocalTransform.vert"));
    shaderList.push_back(LoadShader(GL_FRAGMENT_SHADER, "ColorPassthrough.frag"));

    theProgram = CreateProgram(shaderList);

    positionAttrib = glGetAttribLocation(theProgram, "position");
    colorAttrib = glGetAttribLocation(theProgram, "color");

    modelToCameraMatrixUnif = glGetUniformLocation(theProgram, "modelToCameraMatrix");
    cameraToClipMatrixUnif = glGetUniformLocation(theProgram, "cameraToClipMatrix");

    float zNear = 1.0f;
    float zFar = 100.0f;

    cameraToClipMatrix[0].x = frustumScale;
    cameraToClipMatrix[1].y = frustumScale;
    cameraToClipMatrix[2].z = (zFar + zNear) / (zNear - zFar);
    cameraToClipMatrix[2].w = -1.0f;
    cameraToClipMatrix[3].z = (2 * zFar * zNear) / (zNear - zFar);

    glUseProgram(theProgram);
    glUniformMatrix4fv(cameraToClipMatrixUnif, 1, GL_FALSE, glm::value_ptr(cameraToClipMatrix));
    glUseProgram(0);

    std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
}
开发者ID:captainadamo,项目名称:glfw_gltut,代码行数:30,代码来源:Hierarchy.cpp

示例10: InitializeProgram

void InitializeProgram()
{
    std::vector<GLuint> shaderList;

    shaderList.push_back(LoadShader(GL_VERTEX_SHADER, "Standard.vert"));
    shaderList.push_back(LoadShader(GL_FRAGMENT_SHADER, "Standard.frag"));

    theProgram = CreateProgram(shaderList);

    offsetUniform = glGetUniformLocation(theProgram, "offset");

    perspectiveMatrixUnif = glGetUniformLocation(theProgram, "perspectiveMatrix");

    float zNear = 1.0f;
    float zFar = 3.0f;

    memset(perspectiveMatrix, 0, sizeof(float) * 16);

    perspectiveMatrix[0] = frustumScale;
    perspectiveMatrix[5] = frustumScale;
    perspectiveMatrix[10] = (zFar + zNear) / (zNear - zFar);
    perspectiveMatrix[14] = (2 *zFar * zNear) / (zNear - zFar);
    perspectiveMatrix[11] = -1.0f;

    glUseProgram(theProgram);
    glUniformMatrix4fv(perspectiveMatrixUnif, 1, GL_FALSE, perspectiveMatrix);
    glUseProgram(0);

    std::for_each(shaderList.begin(), shaderList.end(), glDeleteShader);
}
开发者ID:captainadamo,项目名称:glfw_gltut,代码行数:30,代码来源:DepthClamping.cpp

示例11: Load

// load shaders.
bool COGModelShader::Load (OGShaderID _Id, const std::string& _VertShader, const std::string& _FragmentShader)
{
    if(ShaderLoadFromFile(_FragmentShader.c_str(), GL_FRAGMENT_SHADER, &m_uiFragShader) == 0)
        return false;
    if(ShaderLoadFromFile(_VertShader.c_str(), GL_VERTEX_SHADER, &m_uiVertShader) == 0)
        return false;

    const char* pszAttribs[] = { "inVertex", "inNormal", "inTexCoord" };
    if (CreateProgram(&m_uiId, m_uiVertShader, m_uiFragShader, pszAttribs, 3) == 0)
        return false;

    m_uiMVPMatrixLoc = glGetUniformLocation(m_uiId, "MVPMatrix");
    m_uiMVMatrixLoc = glGetUniformLocation(m_uiId, "MVMatrix");
    m_uiLightDirLoc = glGetUniformLocation(m_uiId, "LightDirection");
    m_uiTextureLoc = glGetUniformLocation(m_uiId, "sTexture");

    m_uiFogEndLoc = glGetUniformLocation(m_uiId, "FogEnd");
    m_uiFogRcpDiffLoc = glGetUniformLocation(m_uiId, "FogRcpEndStartDiff");
    m_uiFogColorLoc = glGetUniformLocation(m_uiId, "FogColor");
    m_uiFogEnabled = glGetUniformLocation(m_uiId, "FogEnabled");

    m_uiMaterialAmbient = glGetUniformLocation(m_uiId, "MaterialAmbient");
    m_uiMaterialDiffuse = glGetUniformLocation(m_uiId, "MaterialDiffuse");

    m_Id = _Id;

    return true;
}
开发者ID:AndiSVCorporate,项目名称:orange-grass,代码行数:29,代码来源:ogmodelshader.cpp

示例12: CreateProgram

Program::Program(Shader &Vertex,Shader &Fragment)
{
	GLuint Shaders[2];
	Shaders[0] = Vertex.ReturnShader();
	Shaders[1] = Fragment.ReturnShader();
	pr = CreateProgram(Shaders,2);
}
开发者ID:elf11,项目名称:newRepo,代码行数:7,代码来源:Renderer.cpp

示例13: gles2_init_shaders

void gles2_init_shaders () {
	memset(&shader, 0, sizeof(ShaderInfo));

	// Load custom shaders
   	float input_size[2], output_size[2], texture_size[2];
	
	shader.program = CreateProgram(vertex_shader_custom, fragment_shader_custom_scanlines_16bit);

	if(shader.program)
	{
		shader.u_vp_matrix   = glGetUniformLocation(shader.program, "MVPMatrix");
  	 	shader.a_texcoord    = glGetAttribLocation(shader.program, "TexCoord");
		shader.a_position    = glGetAttribLocation(shader.program, "VertexCoord");
		
		shader.input_size    = glGetUniformLocation(shader.program, "InputSize");
		shader.output_size   = glGetUniformLocation(shader.program, "OutputSize");
		shader.texture_size  = glGetUniformLocation(shader.program, "TextureSize");
	}

	input_size [0]  = _dispvars->texture_width;
   	input_size [1]  = _dispvars->texture_height;
	output_size[0]  = _dispvars->output_width;
	output_size[1]  = _dispvars->output_height;
	texture_size[0] = _dispvars->texture_width;
	texture_size[1] = _dispvars->texture_height;

	if(!shader.program) 
		exit(0);
	
	glUseProgram(shader.program); SHOW_ERROR

	glUniform2fv(shader.input_size, 1, input_size);
	glUniform2fv(shader.output_size, 1, output_size);
	glUniform2fv(shader.texture_size, 1, texture_size);
}
开发者ID:astrofimov,项目名称:LBE_DOCS,代码行数:35,代码来源:gles.c

示例14: LinkShaders3

GLuint LinkShaders3(GLuint vertShader, GLuint geomShader, GLuint fragShader) {
  GLuint program = CreateProgram();

  assert(vertShader || fragShader);

  if (vertShader) AttachShader(program, vertShader);
  if (geomShader) AttachShader(program, geomShader);
  if (fragShader) AttachShader(program, fragShader);

  LinkProgram(program);

  /* check link */
  {
    GLint stat;
    GetProgramiv(program, GL_LINK_STATUS, &stat);
    if (!stat) {
      GLchar log[1000];
      GLsizei len;
      GetProgramInfoLog(program, 1000, &len, log);
      wxLogError(wxT("BR24radar_pi: problem linking program: %s"), log);
      return 0;
    }
  }

  return program;
}
开发者ID:CarCode,项目名称:Cocoa-OCPN,代码行数:26,代码来源:shaderutil.cpp

示例15: NS_ASSERTION

bool
ShaderProgramOGL::Initialize()
{
  NS_ASSERTION(mProgramState == STATE_NEW, "Shader program has already been initialised");

  if (!CreateProgram(mProfile.mVertexShaderString,
                     mProfile.mFragmentShaderString)) {
    mProgramState = STATE_ERROR;
    return false;
  }

  mProgramState = STATE_OK;

  for (uint32_t i = 0; i < mProfile.mUniforms.Length(); ++i) {
    mProfile.mUniforms[i].mLocation =
      mGL->fGetUniformLocation(mProgram, mProfile.mUniforms[i].mName);
    NS_ASSERTION(mProfile.mUniforms[i].mLocation >= 0, "Bad uniform location.");
  }

  for (uint32_t i = 0; i < mProfile.mAttributes.Length(); ++i) {
    mProfile.mAttributes[i].mLocation =
      mGL->fGetAttribLocation(mProgram, mProfile.mAttributes[i].mName);
    NS_ASSERTION(mProfile.mAttributes[i].mLocation >= 0, "Bad attribute location.");
  }

  // this is a one-off that's present in the 2DRect versions of some shaders.
  mTexCoordMultiplierUniformLocation =
    mGL->fGetUniformLocation(mProgram, "uTexCoordMultiplier");

  return true;
}
开发者ID:mshal,项目名称:mozilla-central,代码行数:31,代码来源:LayerManagerOGLProgram.cpp


注:本文中的CreateProgram函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。