⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 oglkernel.cpp

📁 用于GPU通用计算的编程语言BrookGPU 0.4
💻 CPP
📖 第 1 页 / 共 2 页
字号:
  float shiftx = ratiox * 0.5f;  float shifty = ratioy * 0.5f;  f1.x = x1 - shiftx + bias;  f1.y = y1 - shifty + bias;  f2.x = (x1+2*sx) - shiftx + bias;  f2.y = (y1+2*sy) - shifty + bias;  if (h==1) {//    interpolant.vertices[0] = float4(f1.x, f1.y, 0.0f, 1.0f);//    interpolant.vertices[1] = float4(f2.x, f1.y, 0.0f, 1.0f);//    interpolant.vertices[2] = interpolant.vertices[0];    interpolant.vertices[0] = float4(f1.x, y1, 0.0f, 1.0f);    interpolant.vertices[1] = float4(f2.x, y1, 0.0f, 1.0f);    interpolant.vertices[2] = interpolant.vertices[0];    return;  }  if (w==1) {//    interpolant.vertices[0] = float4(f1.x, f1.y, 0.0f, 1.0f);//    interpolant.vertices[1] = interpolant.vertices[0];//    interpolant.vertices[2] = float4(f1.x, f2.y, 0.0f, 1.0f);    interpolant.vertices[0] = float4(x1, f1.y, 0.0f, 1.0f);    interpolant.vertices[1] = interpolant.vertices[0];    interpolant.vertices[2] = float4(x1, f2.y, 0.0f, 1.0f);    return;  }  interpolant.vertices[0] = float4(f1.x, f1.y, 0.0f, 1.0f);  interpolant.vertices[1] = float4(f2.x, f1.y, 0.0f, 1.0f);  interpolant.vertices[2] = float4(f1.x, f2.y, 0.0f, 1.0f);}float4 OGLContext::getStreamIndexofConstant( TextureHandle inTexture ) const {  return float4(1.0f, 1.0f, 0.0f, 0.0f);}float4OGLContext::getStreamGatherConstant(                                    unsigned int inRank, const unsigned int* inDomainMin,                                    const unsigned int* inDomainMax, const unsigned int* inExtents ) const {  float scaleX = 1.0f;  float scaleY = 1.0f;  float offsetX = 0.0f;  float offsetY = 0.0f;  if( inRank == 1 )  {    unsigned int base = inDomainMin[0];    offsetX = base + 0.5f;  }  else  {    unsigned int baseX = inDomainMin[1];    unsigned int baseY = inDomainMin[0];    offsetX = baseX + 0.5f;    offsetY = baseY + 0.5f;  }  return float4( scaleX, scaleY, offsetX, offsetY );//  return float4(1.0f, 1.0f, 0.5f, 0.5f);}voidOGLContext::getStreamInterpolant( const TextureHandle texture,                                  unsigned int rank,                                  const unsigned int* domainMin,                                  const unsigned int* domainMax,                                  unsigned int w,                                  unsigned int h,                                  GPUInterpolant &interpolant) const {  unsigned int minX, minY, maxX, maxY;  if( rank == 1 )  {      minX = domainMin[0];      minY = 0;      maxX = domainMax[0];      maxY = 0;  }  else  {      minX = domainMin[1];      minY = domainMin[0];      maxX = domainMax[1];      maxY = domainMax[0];  }  float2 start(minX + 0.005f, minY + 0.005f);  float2 end(maxX + 0.005f, maxY + 0.005f);  get2DInterpolant(  start, end, w, h, interpolant); }voidOGLContext::getStreamOutputRegion( const TextureHandle texture,                                   unsigned int rank,                                   const unsigned int* domainMin,                                   const unsigned int* domainMax,                                   GPURegion &region) const{  unsigned int minX, minY, maxX, maxY;  if( rank == 1 )  {      minX = domainMin[0];      minY = 0;      maxX = domainMax[0];      maxY = 1;  }  else  {      minX = domainMin[1];      minY = domainMin[0];      maxX = domainMax[1];      maxY = domainMax[0];  }  region.vertices[0].x = -1;  region.vertices[0].y = -1;  region.vertices[1].x = 3;  region.vertices[1].y = -1;  region.vertices[2].x = -1;  region.vertices[2].y = 3;  region.viewport.minX = minX;  region.viewport.minY = minY;  region.viewport.maxX = maxX;  region.viewport.maxY = maxY;}void OGLContext::getStreamReduceInterpolant( const TextureHandle inTexture,                                        const unsigned int outputWidth,                                        const unsigned int outputHeight,                                         const unsigned int minX,                                        const unsigned int maxX,                                         const unsigned int minY,                                        const unsigned int maxY,                                        GPUInterpolant &interpolant) const{    float2 start(0.005f + minX, 0.005f + minY);    float2 end(0.005f + maxX, 0.005f + maxY);    get2DInterpolant( start, end, outputWidth, outputHeight, interpolant); }voidOGLContext::getStreamReduceOutputRegion( const TextureHandle inTexture,                                         const unsigned int minX,                                         const unsigned int maxX,                                          const unsigned int minY,                                         const unsigned int maxY,                                         GPURegion &region) const{  region.vertices[0].x = -1;  region.vertices[0].y = -1;  region.vertices[1].x = 3;  region.vertices[1].y = -1;  region.vertices[2].x = -1;  region.vertices[2].y = 3;  region.viewport.minX = minX;  region.viewport.minY = minY;  region.viewport.maxX = maxX;  region.viewport.maxY = maxY;}void OGLContext::drawRectangle( const GPURegion& outputRegion,                            const GPUInterpolant* interpolants,                            unsigned int numInterpolants ) {  unsigned int w, h, i, v;  unsigned int numOutputs, maxComponent;  static const GLenum outputEnums[] = {GL_FRONT_LEFT, GL_AUX0,                                       GL_AUX1, GL_AUX2};  /* Here we assume that all of the outputs are of the same size */  w = _outputTextures[0]->width();  h = _outputTextures[0]->height();  numOutputs = 0;  maxComponent = 0;  for (i=0; i<4; i++) {    if (_outputTextures[i]) {      numOutputs = i+1;      if (_outputTextures[i]->components() > maxComponent)        maxComponent = _outputTextures[i]->components();    }  }  CHECK_GL();  if (_wnd->bindPbuffer(w, h, numOutputs, maxComponent)) {    // Rebind the shader    GPUAssert(_boundPixelShader, "Missing pixel shader");    bindPixelShader((PixelShaderHandle) _boundPixelShader);        // Rebind the textures    for (i=0; i<32; i++)       if (_boundTextures[i]) {        glActiveTextureARB(GL_TEXTURE0_ARB+i);        glBindTexture(GL_TEXTURE_RECTANGLE_NV, _boundTextures[i]->id());      }    // Rebind the constants    for (i=0; i<_boundPixelShader->largest_constant; i++) {      bindConstant((PixelShaderHandle) _boundPixelShader,                   i, _boundPixelShader->constants[i]);    }          }    CHECK_GL();  // TIM: hacky magic magic  if( _isUsingAddressTranslation && _isUsingOutputDomain )  {    // if we are writing to a domain of an address-translated    // stream, then copy the output textures to the pbuffer    // so that we can overwrite the proper domain    // NOTE: this will fail if we try to optimize domain    // handling by only drawing to a subrectangle - for    // now we render to the whole thing, so copying in    // the whole texture is correct    for( i = 0; i < numOutputs; i++ )    {      OGLTexture* output = _outputTextures[i];      glDrawBuffer(outputEnums[i]);      copy_to_pbuffer(output);    }    // We need to rebind stuff since we messed up the state    // of things    // Rebind the shader    GPUAssert(_boundPixelShader, "Missing pixel shader");    bindPixelShader((PixelShaderHandle) _boundPixelShader);    // Rebind the textures    for (i=0; i<32; i++)     if (_boundTextures[i]) {    glActiveTextureARB(GL_TEXTURE0_ARB+i);    glBindTexture(GL_TEXTURE_RECTANGLE_NV, _boundTextures[i]->id());    }    // Rebind the constants    for (i=0; i<_boundPixelShader->largest_constant; i++) {    bindConstant((PixelShaderHandle) _boundPixelShader,    i, _boundPixelShader->constants[i]);    }  }  if (_maxOutputCount > 1)    glDrawBuffersATI (numOutputs, outputEnums);      if (_maxOutputCount > 1)    glDrawBuffersATI (numOutputs, outputEnums);   CHECK_GL();    /*   * We execute our kernel by using it to texture a triangle that   * has vertices (-1, 3), (-1, -1), and (3, -1) which works out   * nicely to contain the square (-1, -1), (-1, 1), (1, 1), (1, -1).   */  int minX = outputRegion.viewport.minX;  int minY = outputRegion.viewport.minY;  int maxX = outputRegion.viewport.maxX;  int maxY = outputRegion.viewport.maxY;  int width = maxX - minX;  int height = maxY - minY;  CHECK_GL();  glViewport( minX, minY, width, height );  CHECK_GL();  glBegin(GL_TRIANGLES);  for (v=0; v<3; v++ )  {        GPULOG(1) << "vertex " << v;        for (i=0; i<numInterpolants; i++)         {            glMultiTexCoord4fvARB(GL_TEXTURE0_ARB+i,                                (GLfloat *) &(interpolants[i].vertices[v]));            GPULOG(1) << "tex" << i << " : " << interpolants[i].vertices[v].x                << ", " << interpolants[i].vertices[v].y;        }        glVertex2fv((GLfloat *) &(outputRegion.vertices[v]));        GPULOG(1) << "pos : " << outputRegion.vertices[v].x            << ", " << outputRegion.vertices[v].y;  }  glEnd();  CHECK_GL();  /* Copy the output to the texture */  for (i=0; i<numOutputs; i++) {    glActiveTextureARB(GL_TEXTURE0+_slopTextureUnit);    glBindTexture(GL_TEXTURE_RECTANGLE_NV, _outputTextures[i]->id());    glReadBuffer(outputEnums[i]);    glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0,                         minX, minY,                         minX, minY,                         width, height);    CHECK_GL();  }  glReadBuffer(outputEnums[0]);  glDrawBuffer(outputEnums[0]);  for (i=0; i<4; i++)    _outputTextures[i] = NULL;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -