示例#1
0
static GF_Err droid_Resize(GF_VideoOutput *dr, u32 w, u32 h)
{
	RAWCTX;
	LOG( ANDROID_LOG_DEBUG, TAG, "Android Resize: %dx%d", w, h);

	rc->width = w;
	rc->height = h;

	if ( rc->non_power_two )
	{
		rc->tex_width = rc->width;
		rc->tex_height = rc->height;
	}
	else
	{
		rc->tex_width = find_pow_2(rc->width);
		rc->tex_height = find_pow_2(rc->height);
	}

	resizeWindow(rc);

	if ( rc->out_3d_type == 0 )
	{
		createTexture(rc);
#ifdef GLES_FRAMEBUFFER_TEST
		createFrameBuffer(rc);
#endif
	}
        LOG( ANDROID_LOG_VERBOSE, TAG, "Android Resize DONE", w, h);
	return GF_OK;
}
示例#2
0
文件: FBO.cpp 项目: sutuglon/Motor
int FBO::initToTexture(GLuint width, GLuint height) {
    isTexture_= true;
    size_[eWidth]=width;
    size_[eHeight]=width;
    name_=createFrameBuffer();
    return buffers_[eColor]= createTextureBuffer(width,height);
}
示例#3
0
void LayerTextureUpdaterSkPicture::updateTextureRect(LayerTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
{
    if (m_createFrameBuffer) {
        deleteFrameBuffer();
        createFrameBuffer();
        m_createFrameBuffer = false;
    }
    if (!m_fbo)
        return;

    // Bind texture.
    context()->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
    texture->framebufferTexture2D();
    ASSERT(context()->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) == GraphicsContext3D::FRAMEBUFFER_COMPLETE);

    // Notify SKIA to sync its internal GL state.
    m_skiaContext->resetContext();
    m_canvas->save();
    m_canvas->clipRect(SkRect(destRect));
    // Translate the origin of contentRect to that of destRect.
    // Note that destRect is defined relative to sourceRect.
    m_canvas->translate(contentRect().x() - sourceRect.x() + destRect.x(),
                        contentRect().y() - sourceRect.y() + destRect.y());
    m_canvas->drawPicture(m_picture);
    m_canvas->restore();
    // Flush SKIA context so that all the rendered stuff appears on the texture.
    m_skiaContext->flush(GrContext::kForceCurrentRenderTarget_FlushBit);

    // Unbind texture.
    context()->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, 0, 0);
    context()->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0);
}
void WaterFrameBuffer::initializeRefractionFrameBuffer()
{
	refractionFrameBuffer = createFrameBuffer();
	refractionTexture = createTextureAttachment(REFRACTION_WIDTH, REFRACTION_HEIGHT);
	refractionDepthTexture = createDepthTextureAttachment(REFRACTION_WIDTH, REFRACTION_HEIGHT);
	unbindCurrentFrameBuffer();
}
void init ()
{
	
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);	
	glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);	

	srand ( time ( 0x0 ) );

	glClearColor( 0.49, 0.49, 0.49, 1.0 );
	glShadeModel( GL_SMOOTH );

	glEnable ( GL_COLOR_MATERIAL );
	glEnable (GL_DEPTH_TEST);  
	glEnable (GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
	glDepthMask ( 1 );
	glEnable ( GL_TEXTURE_2D );

	// callbacks
	glutDisplayFunc( display );
	glutReshapeFunc( reshape );
	glutKeyboardFunc( keyboard_func );
	glutMouseFunc( mouse_click_func );  
	glutMotionFunc( mouse_move_func );
	glutIdleFunc( idle_func );
	glutSetCursor ( GLUT_CURSOR_NONE );

	cam_angs.x = 29;		cam_angs.y = 75;		cam_angs.z = 80.0;
	cam_to.x = 0;		cam_to.y = 0;		cam_to.z = 5;
	cam_fov = 35.0;

	light[0].x = 39;		light[0].y = -60;	light[0].z = 43;
	light_to[0].x = 0;	light_to[0].y = 0;	light_to[0].z = 0;

	light[1].x = 15;		light[1].y = -5;	light[1].z = 145;	
	light_to[1].x = 0;	light_to[1].y = 0;	light_to[1].z = 0;  

	light_fov = 45;

	#ifdef USE_SHADOWS
		createShadowTextures();
		createFrameBuffer ();
		setShadowLight ( light[0].x, light[0].y, light[0].z, light_to[0].x, light_to[0].y, light_to[0].z, light_fov );
		setShadowLightColor ( .7, .7, .7, 0.2, 0.2, 0.2 );		
	#endif

	obj_from.x = 0;		obj_from.y = 0;		obj_from.z = 20;		// emitter
	obj_angs.x = 118.7;	obj_angs.y = 200;	obj_angs.z = 1.0;
	obj_dang.x = 1;	obj_dang.y = 1;		obj_dang.z = 0;

	psys.Initialize ( BFLUID, psys_nmax );
	psys.SPH_CreateExample ( 0, psys_nmax );
	psys.SetVec ( EMIT_ANG, Vector3DF ( obj_angs.x, obj_angs.y, obj_angs.z ) );
	psys.SetVec ( EMIT_POS, Vector3DF ( obj_from.x, obj_from.y, obj_from.z ) );

	psys.SetParam ( PNT_DRAWMODE, int(bPntDraw ? 1:0) );
	psys.SetParam ( CLR_MODE, iClrMode );	
}
示例#6
0
void GL3LightingManager::resizeFramebuffer(uint32_t width, uint32_t height) {
    // First check if the new size is actually bigger than the old
    if (width <= _framebufferSize.x && height <= _framebufferSize.y) {
        return; // Framebuffer is big enough, no need to change the size
    }

    freeResources();

    createFrameBuffer(width, height);
}
示例#7
0
bool GlesBox::bindFrameBuffer(uint32_t width, uint32_t height) {
  //renew framebuffer
  if (core_->framebuffer_ == 0 || core_->width_ != width || core_->height_ != height) {
    releaseFrameBuffer();
    createFrameBuffer(width, height);
    core_->width_ = width;
    core_->height_ = height;
  }
  glEnable(GL_TEXTURE_2D);
  //glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, core_->texture_render_);
  glBindFramebuffer(GL_FRAMEBUFFER, core_->framebuffer_);
  glViewport(0, 0, core_->width_, core_->height_);
  
  return true;
}
void CCRenderer::setup(const bool lighting, const bool clear)
{
    if( !createContext() || !loadShaders() )
    {
        return;
    }
    
    createFrameBuffer();

    // Screen dimensions
    setupScreenSizeParams();

    lightingEnabled = lighting;
    clearScreenRequired = clear;
    updatingOrientation = 0;
}
示例#9
0
		void WindowsShadowRenderer::setupDraw()
		{
			Core::SmartPtr<Rendering::BufferBase> dynamicBuffer = BufferManager::get()->getDynamicBuffer();
			unsigned int dynamicBufferID = BufferManager::get()->getDynamicBuffer()->getCurrBufferID();
			if (_fbo == 0) createFrameBuffer();
			glViewport(0, 0, _bufferWidth, _bufferHeight);
			DriverInterface::DriverInterfaceBase::checkError(__FILE__, __LINE__);
			glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
			DriverInterface::DriverInterfaceBase::checkError(__FILE__, __LINE__);
			checkFrameBufferStatus();
			//const float one = 1.0f;
			//glClearBufferfv(GL_DEPTH, 0, &one);
			DriverInterface::DriverInterfaceBase::checkError(__FILE__, __LINE__);
			glUseProgram(_program);
			DriverInterface::DriverInterfaceBase::checkError(__FILE__, __LINE__);
			glBindBufferRange(GL_UNIFORM_BUFFER, 13, dynamicBufferID, _sliceMatrixBase, _sliceMatrixSize);
			DriverInterface::DriverInterfaceBase::checkError(__FILE__, __LINE__);
		}
示例#10
0
wyRenderTexture::wyRenderTexture() :
		m_needReleaseTexture(true),
		m_texWidth(wyDevice::realWidth),
		m_texHeight(wyDevice::realHeight),
		m_texture(0),
		m_fbo(0),
		m_old_fbo(0),
		m_blendFunc(wybfDefault),
		m_color(wyc4bWhite) {
	// get texture min size
	int w = wyMath::getNextPOT(m_texWidth);
	int h = wyMath::getNextPOT(m_texHeight);

	// create frame buffer
	createFrameBuffer(w, h);

    // set content size
	setContentSize(wyDevice::winWidth, wyDevice::winHeight);
}
示例#11
0
void init_utterance(utterance_info *utt, int utt_type, int dimen,
                    int buffer_size, int keep_frames, int num_chan, int do_voicing)
/*
**  To setup the utterance structure
*/
{
  /*  Construct frame buffer  and voice buffer here
  */
  ASSERT(utt);
  ASSERT(dimen > 0);
  if (buffer_size < keep_frames)
    SERVICE_ERROR(BAD_ARGUMENT);
  utt->utt_type = utt_type;
  utt->gen_utt.dim = dimen;
  utt->gen_utt.frame = createFrameBuffer(buffer_size,
                                         dimen, keep_frames, do_voicing);
  utt->gen_utt.num_chan = num_chan;

  setup_ambient_estimation(utt->gen_utt.backchan,
                           utt->gen_utt.num_chan, 100);
  return;
}
void LayerTextureUpdaterSkPicture::updateTextureRect(GraphicsContext3D* compositorContext, TextureAllocator* allocator, ManagedTexture* texture, const IntRect& sourceRect, const IntRect& destRect)
{
    ASSERT(!m_context || m_context == compositorContext);
    m_context = compositorContext;

    if (m_createFrameBuffer) {
        deleteFrameBuffer();
        createFrameBuffer();
        m_createFrameBuffer = false;
    }
    if (!m_fbo)
        return;

    // Bind texture.
    context()->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, m_fbo);
    texture->framebufferTexture2D(context(), allocator);
    ASSERT(context()->checkFramebufferStatus(GraphicsContext3D::FRAMEBUFFER) == GraphicsContext3D::FRAMEBUFFER_COMPLETE);

    // Make sure SKIA uses the correct GL context.
    context()->makeContextCurrent();

    GrContext* skiaContext = m_context->grContext();
    // Notify SKIA to sync its internal GL state.
    skiaContext->resetContext();
    m_canvas->save();
    m_canvas->clipRect(SkRect(destRect));
    // Translate the origin of contentRect to that of destRect.
    // Note that destRect is defined relative to sourceRect.
    m_canvas->translate(contentRect().x() - sourceRect.x() + destRect.x(),
                        contentRect().y() - sourceRect.y() + destRect.y());
    m_canvas->drawPicture(m_picture);
    m_canvas->restore();
    // Flush SKIA context so that all the rendered stuff appears on the texture.
    skiaContext->flush();

    // Unbind texture.
    context()->framebufferTexture2D(GraphicsContext3D::FRAMEBUFFER, GraphicsContext3D::COLOR_ATTACHMENT0, GraphicsContext3D::TEXTURE_2D, 0, 0);
    context()->bindFramebuffer(GraphicsContext3D::FRAMEBUFFER, 0);
}
示例#13
0
文件: fluids.cpp 项目: alariq/dev
void Fluids::createBuffers()
{
	int tex_fmt = GL_R32F;
	int tex_int_fmt = GL_RED;
	frambuffer_ = createFrameBuffer();

	//velocity_ = createRenderTexture(128, 128, GL_RGBA8, GL_RGBA);
	density_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	CHECK_GL_ERROR();
	velocity_accum_u_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	CHECK_GL_ERROR();
	velocity_accum_v_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	velocity_accum_ut_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	velocity_accum_vt_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);

	velocity_accum_u0_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);	// 7
	velocity_accum_v0_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT); // 8
	velocity_accum_u0t_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	velocity_accum_v0t_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);

	//velocity_accum_ = createRenderTexture(128, 128, GL_RGBA8, GL_RGBA );
	//velocity_accum2_ = createRenderTexture(128, 128, GL_RGBA8, GL_RGBA );

	density_accum0_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	density_accum0t_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	density_accum_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	density_accum_t_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);

	//tex_fmt = GL_RGBA32F;
	//tex_int_fmt = GL_RGBA;
	p_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);
	p_prev_ = createRenderTexture(128, 128, tex_fmt, tex_int_fmt, GL_FLOAT);


	printf("density_accum: 1: %d 2: %d\n", density_accum0_, density_accum_);

	depth_ = createRenderBuffer(128, 128);
}
示例#14
0
文件: NGLDraw.cpp 项目: NCCA/webgl
NGLDraw::NGLDraw()
{
  // re-size the widget to that of the parent (in this case the GLFrame passed in on construction)
  m_rotate=false;
  // mouse rotation values set to 0
  m_spinXFace=0;
  m_spinYFace=0;
  m_debug=true;
  m_debugMode=0;
  m_rotate=false;
  // mouse rotation values set to 0
  m_spinXFace=0;
  m_spinYFace=0;
  // Now we will create a basic Camera from the graphics library
  // This is a static camera so it only needs to be set once
  // First create Values for the camera position
  ngl::Vec3 from(0,2,5);
  ngl::Vec3 to(0,0,0);
  ngl::Vec3 up(0,1,0);
  // now load to our new camera
  m_cam= new ngl::Camera(from,to,up);
  // set the shape using FOV 45 Aspect Ratio based on Width and Height
  // The final two are near and far clipping planes of 0.5 and 10
  m_cam->setShape(45,(float)float(720/576),0.05,350);

  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);			   // Grey Background
  // enable depth testing for drawing
  glEnable(GL_DEPTH_TEST);
   // now to load the shader and set the values
  // grab an instance of shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  // we are creating a shader for Pass 1
  shader->createShaderProgram("Pass1");
  // now we are going to create empty shaders for Frag and Vert
  shader->attachShader("Pass1Vertex",ngl::VERTEX);
  shader->attachShader("Pass1Fragment",ngl::FRAGMENT);
  // attach the source
  shader->loadShaderSource("Pass1Vertex","shaders/Pass1Vert.glsl");
  shader->loadShaderSource("Pass1Fragment","shaders/Pass1Frag.glsl");
  // compile the shaders
  shader->compileShader("Pass1Vertex");
  shader->compileShader("Pass1Fragment");
  // add them to the program
  shader->attachShaderToProgram("Pass1","Pass1Vertex");
  shader->attachShaderToProgram("Pass1","Pass1Fragment");
//  shader->bindFragDataLocation("Pass1",0,"pointDeferred");
//  shader->bindFragDataLocation("Pass1",1,"normalDeferred");
//  shader->bindFragDataLocation("Pass1",2,"colourDeferred");
//  shader->bindFragDataLocation("Pass1",3,"shadingDeferred");

  shader->linkProgramObject("Pass1");
  shader->use("Pass1");

  // we are creating a shader for Pass 2
  shader->createShaderProgram("Pass2");
  // now we are going to create empty shaders for Frag and Vert
  shader->attachShader("Pass2Vertex",ngl::VERTEX);
  shader->attachShader("Pass2Fragment",ngl::FRAGMENT);
  // attach the source
  shader->loadShaderSource("Pass2Vertex","shaders/Pass2Vert.glsl");
  shader->loadShaderSource("Pass2Fragment","shaders/Pass2Frag.glsl");
  // compile the shaders
  shader->compileShader("Pass2Vertex");
  shader->compileShader("Pass2Fragment");
  // add them to the program
  shader->attachShaderToProgram("Pass2","Pass2Vertex");
  shader->attachShaderToProgram("Pass2","Pass2Fragment");
  shader->linkProgramObject("Pass2");
  shader->use("Pass2");
  shader->setShaderParam1i("pointTex",0);
  shader->setShaderParam1i("normalTex",1);
  shader->setShaderParam1i("colourTex",2);
  shader->setShaderParam1i("lightPassTex",3);
  shader->setShaderParam1i("diffusePassTex",4);

  // we are creating a shader for Debug pass
  shader->createShaderProgram("Debug");
  // now we are going to create empty shaders for Frag and Vert
  shader->attachShader("DebugVertex",ngl::VERTEX);
  shader->attachShader("DebugFragment",ngl::FRAGMENT);
  // attach the source
  shader->loadShaderSource("DebugVertex","shaders/DebugVert.glsl");
  shader->loadShaderSource("DebugFragment","shaders/DebugFrag.glsl");
  // compile the shaders
  shader->compileShader("DebugVertex");
  shader->compileShader("DebugFragment");
  // add them to the program
  shader->attachShaderToProgram("Debug","DebugVertex");
  shader->attachShaderToProgram("Debug","DebugFragment");
  shader->linkProgramObject("Debug");
  shader->use("Debug");
  shader->setShaderParam1i("pointTex",0);
  shader->setShaderParam1i("normalTex",1);
  shader->setShaderParam1i("colourTex",2);
  shader->setShaderParam1i("lightPassTex",3);
  shader->setShaderParam1i("diffusePassTex",4);

  shader->setRegisteredUniform1i("mode",1);


  // we are creating a shader for Lighting pass
  shader->createShaderProgram("Lighting");
  // now we are going to create empty shaders for Frag and Vert
  shader->attachShader("LightingVertex",ngl::VERTEX);
  shader->attachShader("LightingFragment",ngl::FRAGMENT);
  // attach the source
  shader->loadShaderSource("LightingVertex","shaders/LightingPassVert.glsl");
  shader->loadShaderSource("LightingFragment","shaders/LightingPassFrag.glsl");
  // compile the shaders
  shader->compileShader("LightingVertex");
  shader->compileShader("LightingFragment");
  // add them to the program
  shader->attachShaderToProgram("Lighting","LightingVertex");
  shader->attachShaderToProgram("Lighting","LightingFragment");
  shader->linkProgramObject("Lighting");
  shader->use("Lighting");
  shader->setShaderParam1i("pointTex",0);
  shader->setShaderParam1i("normalTex",1);
  shader->setShaderParam1i("colourTex",2);
  shader->setShaderParam1i("lightPassTex",3);

  shader->setShaderParam2f("wh",720,576);

  m_text = new ngl::Text("font/arial.ttf",14);
  m_text->setScreenSize(720,576);

  m_screenQuad = new ScreenQuad("Debug");
  // as re-size is not explicitly called we need to do this.
  glViewport(0, 0, 720,576);
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();
  prim->createSphere("sphere",0.5,50);

  prim->createSphere("lightSphere",0.1,10);
  prim->createCylinder("cylinder",0.5,1.4,40,40);

  prim->createCone("cone",0.5,1.4,20,20);

  prim->createDisk("disk",0.8,120);
  prim->createTorus("torus",0.15,0.4,40,40);
  prim->createTrianglePlane("plane",14,14,80,80,ngl::Vec3(0,1,0));

  createFrameBuffer();
  printFrameBufferInfo(m_gbuffer);
  printFrameBufferInfo(m_lightBuffer);
}
示例#15
0
文件: load81.c 项目: r043v/load81
void initScreen(void) {
    l81.fb = createFrameBuffer(l81.width,l81.height,
                               l81.bpp,l81.opt_full_screen);
}
示例#16
0
文件: FBO.cpp 项目: sutuglon/Motor
int FBO::initToFramebuffer() {
    isTexture_=false;
    name_=createFrameBuffer();
    return buffers_[eColor]= createRenderBuffer();
}
void WaterFrameBuffers::initialiseReflectionFrameBuffer() {
    reflectionFrameBuffer = createFrameBuffer();
    reflectionTexture = createTextureAttachment(REFLECTION_WIDTH, REFLECTION_HEIGHT);
    reflectionDepthBuffer = createDepthBufferAttachment(REFLECTION_WIDTH, REFLECTION_HEIGHT);
    unbindCurrentFrameBuffer();
}
示例#18
0
bool RenderSystem::init(void* windowHandle, const InitParams& params)
{
  IDXGIFactory1* factory = 0;
  IDXGIOutput* output = 0;

  DXGI_MODE_DESC modeDesc;
  ::ZeroMemory(&modeDesc, sizeof(DXGI_MODE_DESC));
  modeDesc.Format = params.srgbTarget ? DXGI_FORMAT_R8G8B8A8_UNORM_SRGB : DXGI_FORMAT_R8G8B8A8_UNORM;
  modeDesc.Width = params.width;
  modeDesc.Height = params.height;

  if (SUCCEEDED(CreateDXGIFactory1(__uuidof(IDXGIFactory1), (void**)&factory)))
  {
    IDXGIAdapter1* adapter = 0;
    for (UINT i = 0; factory->EnumAdapters1(i, &adapter) != DXGI_ERROR_NOT_FOUND; ++i)
    {
      if (adapter->CheckInterfaceSupport(__uuidof(ID3D11Device), NULL))
        break;

      adapter->Release();
    }

    D3D_FEATURE_LEVEL supportedFeatureLevels[] =
    {
      D3D_FEATURE_LEVEL_11_0,
    };

    UINT flags = 0;

#if defined (_DEBUG)
    flags |= D3D11_CREATE_DEVICE_DEBUG;
#endif // _DEBUG

    if (adapter)
    {
      if (SUCCEEDED(D3D11CreateDevice(adapter, D3D_DRIVER_TYPE_UNKNOWN, NULL, flags, supportedFeatureLevels, _countof(supportedFeatureLevels),
        D3D11_SDK_VERSION, &m_device, NULL, &m_renderContext)))
      {
        for (UINT i = 0; adapter->EnumOutputs(i, &output) != DXGI_ERROR_NOT_FOUND; ++i)
        {
          if (SUCCEEDED(output->FindClosestMatchingMode(&modeDesc, &modeDesc, m_device)))
          {
            // additional checks??
            break;
          }

          output->Release();
          output = 0;
        }

        /*if (output)
          output->Release();*/
      }

      adapter->Release();
    }

    if (m_device)
    {
      DXGI_SWAP_CHAIN_DESC sd;
      ::ZeroMemory(&sd, sizeof(DXGI_SWAP_CHAIN_DESC));
      sd.BufferCount = 1;
      sd.BufferDesc = modeDesc;
      sd.BufferUsage = D3D11_BIND_RENDER_TARGET;
      sd.Flags = 0;
      sd.OutputWindow = (HWND)windowHandle;
      sd.SampleDesc.Quality = 0;
      sd.SampleDesc.Count = 1;
      sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
      sd.Windowed = TRUE;

      if (params.msaaSamples > 0)
      {
        UINT numLevels = 0;
        if (SUCCEEDED(m_device->CheckMultisampleQualityLevels(modeDesc.Format, params.msaaSamples, &numLevels)) && numLevels > 0)
        {
          sd.SampleDesc.Quality = numLevels-1;
          sd.SampleDesc.Count = params.msaaSamples;
        }
        else
        {
          printf("multisample quality not supported");
        }
      }

      VALIDATE(factory->CreateSwapChain(m_device, &sd, &m_swapChain));
    }

    if (params.fullscreen)
    {
      m_isFullScreen = SUCCEEDED(m_swapChain->SetFullscreenState(TRUE, output));
    }

    // setup debug queue

    factory->MakeWindowAssociation((HWND)windowHandle, DXGI_MWA_NO_ALT_ENTER | DXGI_MWA_NO_WINDOW_CHANGES);

    if (output)
      output->Release();

    factory->Release();
  }

  m_stateCache = new PipelineStateCache(m_renderContext);

  createFrameBuffer();

  initDefaultResources();

  return (m_device && m_swapChain);
}
示例#19
0
void NGLScene::initializeGL()
{
  // we must call this first before any other GL commands to load and link the
  // gl commands from the lib, if this is not done program will crash
  ngl::NGLInit::instance();
  // Now we will create a basic Camera from the graphics library
  // This is a static camera so it only needs to be set once
  // First create Values for the camera position
  ngl::Vec3 from(0.0f,2.0f,5.0f);
  ngl::Vec3 to(0.0f,0.0f,0.0f);
  ngl::Vec3 up(0.0f,1.0f,0.0f);
  // now load to our new camera
  m_cam.set(from,to,up);
  // set the shape using FOV 45 Aspect Ratio based on Width and Height
  // The final two are near and far clipping planes of 0.5 and 10
  m_cam.setShape(45.0f,(float)float(width()/height()),0.05f,350.0f);

  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);			   // Grey Background
  // enable depth testing for drawing
  glEnable(GL_DEPTH_TEST);
  // enable multisampling for smoother drawing
  glEnable(GL_MULTISAMPLE);
   // now to load the shader and set the values
  // grab an instance of shader manager
  ngl::ShaderLib *shader=ngl::ShaderLib::instance();
  // we are creating a shader for Pass 1
  shader->createShaderProgram("Pass1");
  // now we are going to create empty shaders for Frag and Vert
  shader->attachShader("Pass1Vertex",ngl::ShaderType::VERTEX);
  shader->attachShader("Pass1Fragment",ngl::ShaderType::FRAGMENT);
  // attach the source
  shader->loadShaderSource("Pass1Vertex","shaders/Pass1Vert.glsl");
  shader->loadShaderSource("Pass1Fragment","shaders/Pass1Frag.glsl");
  // compile the shaders
  shader->compileShader("Pass1Vertex");
  shader->compileShader("Pass1Fragment");
  // add them to the program
  shader->attachShaderToProgram("Pass1","Pass1Vertex");
  shader->attachShaderToProgram("Pass1","Pass1Fragment");
//  shader->bindFragDataLocation("Pass1",0,"pointDeferred");
//  shader->bindFragDataLocation("Pass1",1,"normalDeferred");
//  shader->bindFragDataLocation("Pass1",2,"colourDeferred");
//  shader->bindFragDataLocation("Pass1",3,"shadingDeferred");

  shader->linkProgramObject("Pass1");
  shader->use("Pass1");

  // we are creating a shader for Pass 2
  shader->createShaderProgram("Pass2");
  // now we are going to create empty shaders for Frag and Vert
  shader->attachShader("Pass2Vertex",ngl::ShaderType::VERTEX);
  shader->attachShader("Pass2Fragment",ngl::ShaderType::FRAGMENT);
  // attach the source
  shader->loadShaderSource("Pass2Vertex","shaders/Pass2Vert.glsl");
  shader->loadShaderSource("Pass2Fragment","shaders/Pass2Frag.glsl");
  // compile the shaders
  shader->compileShader("Pass2Vertex");
  shader->compileShader("Pass2Fragment");
  // add them to the program
  shader->attachShaderToProgram("Pass2","Pass2Vertex");
  shader->attachShaderToProgram("Pass2","Pass2Fragment");
  shader->linkProgramObject("Pass2");
  shader->use("Pass2");
  shader->setShaderParam1i("pointTex",0);
  shader->setShaderParam1i("normalTex",1);
  shader->setShaderParam1i("colourTex",2);
  shader->setShaderParam1i("lightPassTex",3);
  shader->setShaderParam1i("diffusePassTex",4);

  // we are creating a shader for Debug pass
  shader->createShaderProgram("Debug");
  // now we are going to create empty shaders for Frag and Vert
  shader->attachShader("DebugVertex",ngl::ShaderType::VERTEX);
  shader->attachShader("DebugFragment",ngl::ShaderType::FRAGMENT);
  // attach the source
  shader->loadShaderSource("DebugVertex","shaders/DebugVert.glsl");
  shader->loadShaderSource("DebugFragment","shaders/DebugFrag.glsl");
  // compile the shaders
  shader->compileShader("DebugVertex");
  shader->compileShader("DebugFragment");
  // add them to the program
  shader->attachShaderToProgram("Debug","DebugVertex");
  shader->attachShaderToProgram("Debug","DebugFragment");
  shader->linkProgramObject("Debug");
  shader->use("Debug");
  shader->setShaderParam1i("pointTex",0);
  shader->setShaderParam1i("normalTex",1);
  shader->setShaderParam1i("colourTex",2);
  shader->setShaderParam1i("lightPassTex",3);
  shader->setShaderParam1i("diffusePassTex",4);

  shader->setRegisteredUniform1i("mode",1);


  // we are creating a shader for Lighting pass
  shader->createShaderProgram("Lighting");
  // now we are going to create empty shaders for Frag and Vert
  shader->attachShader("LightingVertex",ngl::ShaderType::VERTEX);
  shader->attachShader("LightingFragment",ngl::ShaderType::FRAGMENT);
  // attach the source
  shader->loadShaderSource("LightingVertex","shaders/LightingPassVert.glsl");
  shader->loadShaderSource("LightingFragment","shaders/LightingPassFrag.glsl");
  // compile the shaders
  shader->compileShader("LightingVertex");
  shader->compileShader("LightingFragment");
  // add them to the program
  shader->attachShaderToProgram("Lighting","LightingVertex");
  shader->attachShaderToProgram("Lighting","LightingFragment");
  shader->linkProgramObject("Lighting");
  shader->use("Lighting");
  shader->setShaderParam1i("pointTex",0);
  shader->setShaderParam1i("normalTex",1);
  shader->setShaderParam1i("colourTex",2);
  shader->setShaderParam1i("lightPassTex",3);

  shader->setShaderParam2f("wh",width()*devicePixelRatio(),height()*devicePixelRatio());

  m_text.reset(new ngl::Text(QFont("Arial",14)));
  m_text->setScreenSize(width(),height());

  m_screenQuad = new ScreenQuad("Debug");
  ngl::VAOPrimitives *prim=ngl::VAOPrimitives::instance();
  prim->createSphere("sphere",0.5f,50.0f);

  prim->createSphere("lightSphere",0.1f,10.0f);
  prim->createCylinder("cylinder",0.5f,1.4f,40.0f,40.0f);

  prim->createCone("cone",0.5f,1.4f,20.0f,20.0f);

  prim->createDisk("disk",0.8f,120.0f);
  prim->createTorus("torus",0.15f,0.4f,40.0f,40.0f);
  prim->createTrianglePlane("plane",14.0f,14.0f,80.0f,80.0f,ngl::Vec3(0.0f,1.0f,0.0f));

  createFrameBuffer();
  printFrameBufferInfo(m_gbuffer);
  printFrameBufferInfo(m_lightBuffer);
  m_fpsTimer =startTimer(0);

}