예제 #1
0
파일: fbo.c 프로젝트: Spontz/VisualsEngine
int fbo_new (int width, int height, int iformat, int format, int ttype) {

	int fbo = fbo_init ();

	// setup texture configuration
	fbo_array[fbo]->width = width;
	fbo_array[fbo]->height = height;
	fbo_array[fbo]->iformat = iformat;
	fbo_array[fbo]->format = format;
	fbo_array[fbo]->ttype = ttype;

	return fbo;
}
예제 #2
0
// Only used by Headless! TODO: Remove
void DirectxInit(HWND window) {
	pD3D = Direct3DCreate9( D3D_SDK_VERSION );

	// Set up the structure used to create the D3DDevice. Most parameters are
	// zeroed out. We set Windowed to TRUE, since we want to do D3D in a
	// window, and then set the SwapEffect to "discard", which is the most
	// efficient method of presenting the back buffer to the display.  And 
	// we request a back buffer format that matches the current desktop display 
	// format.
	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp, sizeof(d3dpp));
	// TODO?
	d3dpp.Windowed = TRUE;
	d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
	d3dpp.MultiSampleQuality = 0;
	d3dpp.BackBufferCount = 1;
	d3dpp.EnableAutoDepthStencil = TRUE;
	d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
	//d3dpp.PresentationInterval = (useVsync == true)?D3DPRESENT_INTERVAL_ONE:D3DPRESENT_INTERVAL_IMMEDIATE;
	//d3dpp.RingBufferParameters = d3dr;

	HRESULT hr = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
                                      D3DCREATE_HARDWARE_VERTEXPROCESSING,
                                      &d3dpp, &pD3Ddevice);
	if (hr != D3D_OK) {
		// TODO
	}

#ifdef _XBOX
	pD3Ddevice->SetRingBufferParameters( &d3dr );
#endif

	std::string errorMessage;
	CompileShaders(errorMessage);

	fbo_init(pD3D);
}
예제 #3
0
파일: board.c 프로젝트: sunaku/knights-tour
void board_init(const GLuint aWidth, const GLuint aKnightRow, const GLuint aKnightCol)
{
  board__width = aWidth;

  // number of cycles it takes to finish the computation:
  //
  //   (3 cycles per knight) * (number of knights)
  //
  // the -1 is because the initial knight is not determined
  // at runtime, so we save one cycle of processing.
  //
  // see EXPORT_DELAY in the "naive.cg.erb" file for details.
  //
  board__numCycles = 3 * board__area;
  printf("\nThe tour should take %lu cycles to complete.\n", board__numCycles);

  // generate the board data
    if((board__data = (float*)malloc(4*board__area*sizeof(float))) == NULL)
    {
      printf("\n*** out of memory allocating board__data ***\n");
      exit(2);
    }

    unsigned addr = 0;
    for(unsigned row = 0; row < board__width; row++) {
      for (unsigned col = 0; col < board__width; col++) {
        // red channel
        board__data[addr++] = (
          // set initial position of knight
          row == aKnightRow &&
          col == aKnightCol
        ) ? 1 : 0;

        // green channel
        board__data[addr++] = 0;

        // blue channel
        board__data[addr++] = 0;

        // alpha channel
        board__data[addr++] = 8; // 8 is MOVE_NONE (see naive.cg.erb for details); all cells should have next move = NONE initially, because only the knight makes the "next move" desicison at *runtime*
      }
    }

  // Generate, set up, and bind the texture
    texture_new(&board__computeTexture, board__width, board__width, GL_TEXTURE_RECTANGLE_ARB, GL_RGBA32F_ARB, NULL);

    // initialize the FBO
    fbo_init(board__width, board__width);

    // Attach the texture to the framebuffer object
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, board__computeTexture, 0);

    // Check the FBO for completeness
    fbo_check();

  // generate texture for board display
    texture_new(&board__displayTexture, board__width, board__width, GL_TEXTURE_2D, GL_RGBA, NULL);

  // generate OpenGL display lists to speed up rendering
    board__gridDisplayList = glGenLists(1);

    glNewList(board__gridDisplayList, GL_COMPILE);
      // draw board outline (grid)
      float step = 2.0 / board__width;
      float cell;

      glBegin(GL_LINES);
        // draw rows
        for (cell = -1 + step; cell < board__width; cell += step) {
          glVertex3f(-1, cell, -1);
          glVertex3f(1, cell, -1);
        }

        // draw columns
        for (cell = -1 + step; cell < board__width; cell += step) {
          glVertex3f(cell, -1, -1);
          glVertex3f(cell, 1, -1);
        }
      glEnd();
    glEndList();
}
예제 #4
0
void DirectxInit(HWND window) {

	pD3D = Direct3DCreate9( D3D_SDK_VERSION );
	
#ifdef _XBOX
	D3DRING_BUFFER_PARAMETERS d3dr = {0};
	d3dr.PrimarySize = 0;  // Direct3D will use the default size of 32KB
    d3dr.SecondarySize = 4 * 1024 * 1024;
    d3dr.SegmentCount = 0; // Direct3D will use the default segment count of 32

    // Setting the pPrimary and pSecondary members to NULL means that Direct3D will
    // allocate the ring buffers itself.  You can optionally provide a buffer that
    // you allocated yourself (it must be write-combined physical memory, aligned to
    // GPU_COMMAND_BUFFER_ALIGNMENT).
    d3dr.pPrimary = NULL;
    d3dr.pSecondary = NULL;
#endif

    // Set up the structure used to create the D3DDevice. Most parameters are
    // zeroed out. We set Windowed to TRUE, since we want to do D3D in a
    // window, and then set the SwapEffect to "discard", which is the most
    // efficient method of presenting the back buffer to the display.  And 
    // we request a back buffer format that matches the current desktop display 
    // format.
    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory( &d3dpp, sizeof( d3dpp ) );
#ifdef _XBOX
    d3dpp.BackBufferWidth = 1280;
    d3dpp.BackBufferHeight = 720;
    d3dpp.BackBufferFormat =  ( D3DFORMAT )( D3DFMT_A8R8G8B8 );

    d3dpp.FrontBufferFormat = ( D3DFORMAT )( D3DFMT_LE_A8R8G8B8 );
#else
	// TODO?
	d3dpp.Windowed = TRUE;
#endif
    d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
    d3dpp.MultiSampleQuality = 0;
    d3dpp.BackBufferCount = 1;
    d3dpp.EnableAutoDepthStencil = TRUE;
    d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
	//d3dpp.PresentationInterval = (useVsync == true)?D3DPRESENT_INTERVAL_ONE:D3DPRESENT_INTERVAL_IMMEDIATE;
	//d3dpp.RingBufferParameters = d3dr;

	HRESULT hr = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, window,
                                      D3DCREATE_HARDWARE_VERTEXPROCESSING,
                                      &d3dpp, &pD3Ddevice);
	if (hr != D3D_OK) {
		// TODO
	}

	
#ifdef _XBOX
	pD3Ddevice->SetRingBufferParameters( &d3dr );
#endif

	CompileShaders();

	fbo_init();
}