Exemple #1
0
static void
nv50_clear_render_target(struct pipe_context *pipe,
                         struct pipe_surface *dst,
			 const union pipe_color_union *color,
                         unsigned dstx, unsigned dsty,
                         unsigned width, unsigned height)
{
   struct nv50_context *nv50 = nv50_context(pipe);
   struct nouveau_pushbuf *push = nv50->base.pushbuf;
   struct nv50_miptree *mt = nv50_miptree(dst->texture);
   struct nv50_surface *sf = nv50_surface(dst);
   struct nouveau_bo *bo = mt->base.bo;

   BEGIN_NV04(push, NV50_3D(CLEAR_COLOR(0)), 4);
   PUSH_DATAf(push, color->f[0]);
   PUSH_DATAf(push, color->f[1]);
   PUSH_DATAf(push, color->f[2]);
   PUSH_DATAf(push, color->f[3]);
#if 0
   if (MARK_RING(chan, 18, 2))
      return;
#endif
   BEGIN_NV04(push, NV50_3D(RT_CONTROL), 1);
   PUSH_DATA (push, 1);
   BEGIN_NV04(push, NV50_3D(RT_ADDRESS_HIGH(0)), 5);
   PUSH_DATAh(push, bo->offset + sf->offset);
   PUSH_DATA (push, bo->offset + sf->offset);
   PUSH_DATA (push, nv50_format_table[dst->format].rt);
   PUSH_DATA (push, mt->level[sf->base.u.tex.level].tile_mode);
   PUSH_DATA (push, 0);
   BEGIN_NV04(push, NV50_3D(RT_HORIZ(0)), 2);
   if (nouveau_bo_memtype(bo))
      PUSH_DATA(push, sf->width);
   else
      PUSH_DATA(push, NV50_3D_RT_HORIZ_LINEAR | mt->level[0].pitch);
   PUSH_DATA (push, sf->height);
   BEGIN_NV04(push, NV50_3D(RT_ARRAY_MODE), 1);
   PUSH_DATA (push, 1);

   if (!nouveau_bo_memtype(bo)) {
      BEGIN_NV04(push, NV50_3D(ZETA_ENABLE), 1);
      PUSH_DATA (push, 0);
   }

   /* NOTE: only works with D3D clear flag (5097/0x143c bit 4) */

   BEGIN_NV04(push, NV50_3D(VIEWPORT_HORIZ(0)), 2);
   PUSH_DATA (push, (width << 16) | dstx);
   PUSH_DATA (push, (height << 16) | dsty);

   BEGIN_NV04(push, NV50_3D(CLEAR_BUFFERS), 1);
   PUSH_DATA (push, 0x3c);

   nv50->dirty |= NV50_NEW_FRAMEBUFFER;
}
Exemple #2
0
void
nv50_clear(struct pipe_context *pipe, unsigned buffers,
           const float *rgba, double depth, unsigned stencil)
{
   struct nv50_context *nv50 = nv50_context(pipe);
   struct nouveau_channel *chan = nv50->screen->base.channel;
   struct pipe_framebuffer_state *fb = &nv50->framebuffer;
   unsigned i;
   const unsigned dirty = nv50->dirty;
   uint32_t mode = 0;

   /* don't need NEW_BLEND, COLOR_MASK doesn't affect CLEAR_BUFFERS */
   nv50->dirty &= NV50_NEW_FRAMEBUFFER;
   if (!nv50_state_validate(nv50, 9 + (fb->nr_cbufs * 2)))
      return;

   if (buffers & PIPE_CLEAR_COLOR && fb->nr_cbufs) {
      BEGIN_RING(chan, RING_3D(CLEAR_COLOR(0)), 4);
      OUT_RINGf (chan, rgba[0]);
      OUT_RINGf (chan, rgba[1]);
      OUT_RINGf (chan, rgba[2]);
      OUT_RINGf (chan, rgba[3]);
      mode =
         NV50_3D_CLEAR_BUFFERS_R | NV50_3D_CLEAR_BUFFERS_G |
         NV50_3D_CLEAR_BUFFERS_B | NV50_3D_CLEAR_BUFFERS_A;
   }

   if (buffers & PIPE_CLEAR_DEPTH) {
      BEGIN_RING(chan, RING_3D(CLEAR_DEPTH), 1);
      OUT_RING  (chan, fui(depth));
      mode |= NV50_3D_CLEAR_BUFFERS_Z;
   }

   if (buffers & PIPE_CLEAR_STENCIL) {
      BEGIN_RING(chan, RING_3D(CLEAR_STENCIL), 1);
      OUT_RING  (chan, stencil & 0xff);
      mode |= NV50_3D_CLEAR_BUFFERS_S;
   }

   BEGIN_RING(chan, RING_3D(CLEAR_BUFFERS), 1);
   OUT_RING  (chan, mode);

   for (i = 1; i < fb->nr_cbufs; i++) {
      BEGIN_RING(chan, RING_3D(CLEAR_BUFFERS), 1);
      OUT_RING  (chan, (i << 6) | 0x3c);
   }

   nv50->dirty = dirty & ~NV50_NEW_FRAMEBUFFER;
}
Exemple #3
0
static void
nv50_clear_render_target(struct pipe_context *pipe,
                         struct pipe_surface *dst,
                         const float *rgba,
                         unsigned dstx, unsigned dsty,
                         unsigned width, unsigned height)
{
   struct nv50_context *nv50 = nv50_context(pipe);
   struct nv50_screen *screen = nv50->screen;
   struct nouveau_channel *chan = screen->base.channel;
   struct nv50_miptree *mt = nv50_miptree(dst->texture);
   struct nv50_surface *sf = nv50_surface(dst);
   struct nouveau_bo *bo = mt->base.bo;

   BEGIN_RING(chan, RING_3D(CLEAR_COLOR(0)), 4);
   OUT_RINGf (chan, rgba[0]);
   OUT_RINGf (chan, rgba[1]);
   OUT_RINGf (chan, rgba[2]);
   OUT_RINGf (chan, rgba[3]);

   if (MARK_RING(chan, 18, 2))
      return;

   BEGIN_RING(chan, RING_3D(RT_CONTROL), 1);
   OUT_RING  (chan, 1);
   BEGIN_RING(chan, RING_3D(RT_ADDRESS_HIGH(0)), 5);
   OUT_RELOCh(chan, bo, sf->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
   OUT_RELOCl(chan, bo, sf->offset, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
   OUT_RING  (chan, nv50_format_table[dst->format].rt);
   OUT_RING  (chan, mt->level[sf->base.u.tex.level].tile_mode << 4);
   OUT_RING  (chan, 0);
   BEGIN_RING(chan, RING_3D(RT_HORIZ(0)), 2);
   OUT_RING  (chan, sf->width);
   OUT_RING  (chan, sf->height);
   BEGIN_RING(chan, RING_3D(RT_ARRAY_MODE), 1);
   OUT_RING  (chan, 1);

   /* NOTE: only works with D3D clear flag (5097/0x143c bit 4) */

   BEGIN_RING(chan, RING_3D(VIEWPORT_HORIZ(0)), 2);
   OUT_RING  (chan, (width << 16) | dstx);
   OUT_RING  (chan, (height << 16) | dsty);

   BEGIN_RING(chan, RING_3D(CLEAR_BUFFERS), 1);
   OUT_RING  (chan, 0x3c);

   nv50->dirty |= NV50_NEW_FRAMEBUFFER;
}
Exemple #4
0
static void
nvc0_clear_render_target(struct pipe_context *pipe,
                         struct pipe_surface *dst,
                         const union pipe_color_union *color,
                         unsigned dstx, unsigned dsty,
                         unsigned width, unsigned height)
{
   struct nvc0_context *nvc0 = nvc0_context(pipe);
   struct nouveau_pushbuf *push = nvc0->base.pushbuf;
   struct nv50_surface *sf = nv50_surface(dst);
   struct nv04_resource *res = nv04_resource(sf->base.texture);
   unsigned z;

   if (!PUSH_SPACE(push, 32 + sf->depth))
      return;

   PUSH_REFN (push, res->bo, res->domain | NOUVEAU_BO_WR);

   BEGIN_NVC0(push, NVC0_3D(CLEAR_COLOR(0)), 4);
   PUSH_DATAf(push, color->f[0]);
   PUSH_DATAf(push, color->f[1]);
   PUSH_DATAf(push, color->f[2]);
   PUSH_DATAf(push, color->f[3]);

   BEGIN_NVC0(push, NVC0_3D(SCREEN_SCISSOR_HORIZ), 2);
   PUSH_DATA (push, ( width << 16) | dstx);
   PUSH_DATA (push, (height << 16) | dsty);

   BEGIN_NVC0(push, NVC0_3D(RT_CONTROL), 1);
   PUSH_DATA (push, 1);
   BEGIN_NVC0(push, NVC0_3D(RT_ADDRESS_HIGH(0)), 9);
   PUSH_DATAh(push, res->address + sf->offset);
   PUSH_DATA (push, res->address + sf->offset);
   if (likely(nouveau_bo_memtype(res->bo))) {
      struct nv50_miptree *mt = nv50_miptree(dst->texture);

      PUSH_DATA(push, sf->width);
      PUSH_DATA(push, sf->height);
      PUSH_DATA(push, nvc0_format_table[dst->format].rt);
      PUSH_DATA(push, (mt->layout_3d << 16) |
               mt->level[sf->base.u.tex.level].tile_mode);
      PUSH_DATA(push, dst->u.tex.first_layer + sf->depth);
      PUSH_DATA(push, mt->layer_stride >> 2);
      PUSH_DATA(push, dst->u.tex.first_layer);
   } else {
      if (res->base.target == PIPE_BUFFER) {
Exemple #5
0
void
nv50_clear(struct pipe_context *pipe, unsigned buffers,
           const union pipe_color_union *color,
           double depth, unsigned stencil)
{
   struct nv50_context *nv50 = nv50_context(pipe);
   struct nouveau_pushbuf *push = nv50->base.pushbuf;
   struct pipe_framebuffer_state *fb = &nv50->framebuffer;
   unsigned i;
   uint32_t mode = 0;

   /* don't need NEW_BLEND, COLOR_MASK doesn't affect CLEAR_BUFFERS */
   if (!nv50_state_validate(nv50, NV50_NEW_FRAMEBUFFER, 9 + (fb->nr_cbufs * 2)))
      return;

   if (buffers & PIPE_CLEAR_COLOR && fb->nr_cbufs) {
      BEGIN_NV04(push, NV50_3D(CLEAR_COLOR(0)), 4);
      PUSH_DATAf(push, color->f[0]);
      PUSH_DATAf(push, color->f[1]);
      PUSH_DATAf(push, color->f[2]);
      PUSH_DATAf(push, color->f[3]);
      mode =
         NV50_3D_CLEAR_BUFFERS_R | NV50_3D_CLEAR_BUFFERS_G |
         NV50_3D_CLEAR_BUFFERS_B | NV50_3D_CLEAR_BUFFERS_A;
   }

   if (buffers & PIPE_CLEAR_DEPTH) {
      BEGIN_NV04(push, NV50_3D(CLEAR_DEPTH), 1);
      PUSH_DATA (push, fui(depth));
      mode |= NV50_3D_CLEAR_BUFFERS_Z;
   }

   if (buffers & PIPE_CLEAR_STENCIL) {
      BEGIN_NV04(push, NV50_3D(CLEAR_STENCIL), 1);
      PUSH_DATA (push, stencil & 0xff);
      mode |= NV50_3D_CLEAR_BUFFERS_S;
   }

   BEGIN_NV04(push, NV50_3D(CLEAR_BUFFERS), 1);
   PUSH_DATA (push, mode);

   for (i = 1; i < fb->nr_cbufs; i++) {
      BEGIN_NV04(push, NV50_3D(CLEAR_BUFFERS), 1);
      PUSH_DATA (push, (i << 6) | 0x3c);
   }
}
Exemple #6
0
int main(int argc, char *argv[])
{
	/* initialize SDL and its subsystems */
	if (SDL_Init(SDL_INIT_EVERYTHING) == -1) die();
	if (TTF_Init() == -1) die();

	/* set the height and width of the main window, as well as the number
	   of bits per pixel; this needs to be done prior to initializing the 
	   main window (*screen, below) */
	initWindowAttributes();

	/* the frame buffer */
	SDL_Surface *screen = SDL_SetVideoMode(W_WIDTH, W_HEIGHT,
			W_COLOR_DEPTH, SDL_HWSURFACE|SDL_FULLSCREEN);
	if (!screen) die();

	/* hide the mouse cursor */
	SDL_ShowCursor(SDL_DISABLE);

	/* the background color of the screen */
	const Uint32 clearColor = CLEAR_COLOR(screen->format);
	clearScreen(screen, clearColor);

	/* clearColor as an SDL_Color, for use with TTF */
	Uint8 r, g, b;
	SDL_GetRGB(clearColor, screen->format, &r, &g, &b);
	SDL_Color bgColor = { r: r, g: g, b: b };

	/* the score font */
	TTF_Font *font = TTF_OpenFont("resources/VeraMono.ttf", FONT_SIZE);
	if (!font) die();
	SDL_Color fontColor = FONT_COLOR;

	/* the score text; we'll allow three digits plus the terminating '\0' */
	char *lScoreStr = malloc(sizeof(char) * 4);
	char *rScoreStr = malloc(sizeof(char) * 4);
	if (!lScoreStr || !rScoreStr) die();
	SDL_Surface *lScore = NULL, *rScore = NULL;
	SDL_Rect lScorePos = { x: C_X+FONT_SIZE, y: C_HEIGHT/5,
		w: F_WIDTH, h: F_HEIGHT };
	SDL_Rect rScorePos = { x: (C_X+C_WIDTH)-3*FONT_SIZE, y: C_HEIGHT/5,
		w: F_WIDTH, h: F_HEIGHT };

	/* set up the playing court */
	Court *court = makeCourt(screen);
	if (!court) die();

	/* set up the players and their paddles */
	Player *lPlayer = makePlayer(screen);
	Player *rPlayer = makePlayer(screen);
	if (!lPlayer || !rPlayer) die();
	rPlayer->paddle.rect.x = C_X + C_WIDTH - P_WIDTH;

	/* add the ball */
	Ball *ball = makeBall(screen);
	if (!ball) die();

	/* because SDL_KEY(UP|DOWN) occurs only once, not continuously while
	   the key is pressed, we need to keep track of whether a key is
	   (still) pressed */
	bool lPlayerShouldMoveUp = false, lPlayerShouldMoveDown = false,
	     rPlayerShouldMoveUp = false, rPlayerShouldMoveDown = false;

	Uint32 startTime;	/* denotes the beginning of each iteration
				   of the main event loop */
	bool running = true;	/* true till the application should exit */
	while (running) {
		startTime = SDL_GetTicks();

		/* clear the previous frame's paddles and ball */
		SDL_FillRect(screen, &lPlayer->paddle.rect, clearColor);
		SDL_FillRect(screen, &rPlayer->paddle.rect, clearColor);
		SDL_FillRect(screen, &ball->rect, clearColor);

		/* clear the previous frame's score */
		SDL_FillRect(screen, &lScorePos, clearColor);
		SDL_FillRect(screen, &rScorePos, clearColor);

		/* redraw the walls in case they were clipped by the ball
		   in a previous frame */
		SDL_FillRect(screen, &court->upperWall, court->color);
		SDL_FillRect(screen, &court->lowerWall, court->color);

		/* get the current state of the players' controls */
		readPlayerInput(&running,
				&lPlayerShouldMoveUp, &lPlayerShouldMoveDown,
				&rPlayerShouldMoveUp, &rPlayerShouldMoveDown);

		/* save the current position of the paddles */
		lPlayer->paddle.prevY = lPlayer->paddle.rect.y;
		rPlayer->paddle.prevY = rPlayer->paddle.rect.y;

		/* move the paddles if appropriate */
		if (lPlayerShouldMoveUp)
			movePaddle(court, &lPlayer->paddle, UP);
		else if (lPlayerShouldMoveDown)
			movePaddle(court, &lPlayer->paddle, DOWN);
		if (rPlayerShouldMoveUp)
			movePaddle(court, &rPlayer->paddle, UP);
		else if (rPlayerShouldMoveDown)
			movePaddle(court, &rPlayer->paddle, DOWN);

		/* move the ball */
		moveBall(court, ball, lPlayer, rPlayer);

		/* update the score */
		updateScore(ball, lPlayer, rPlayer);

		/* update the on-screen score */
		if (lScore) SDL_FreeSurface(lScore);
		snprintf(lScoreStr, 4, "%2d", lPlayer->points);
		lScore = TTF_RenderText_Shaded(font, lScoreStr, fontColor,
				bgColor);
		if (rScore) SDL_FreeSurface(rScore);
		snprintf(rScoreStr, 4, "%2d", rPlayer->points);
		rScore = TTF_RenderText_Shaded(font, rScoreStr, fontColor,
				bgColor);

		/* draw the score */
		SDL_BlitSurface(lScore, NULL, screen, &lScorePos);
		SDL_BlitSurface(rScore, NULL, screen, &rScorePos);

		/* draw the paddles */
		SDL_FillRect(screen, &lPlayer->paddle.rect,
				lPlayer->paddle.color);
		SDL_FillRect(screen, &rPlayer->paddle.rect,
				rPlayer->paddle.color);

		/* draw the ball */
		SDL_FillRect(screen, &ball->rect, ball->color);

		/* render frame to screen */
		SDL_Flip(screen);

		/* keep a steady frame rate */
		Uint8 elapsedTime = SDL_GetTicks() - startTime;
		if (elapsedTime < FRAME_DURATION)
			SDL_Delay(FRAME_DURATION - elapsedTime);
	}

	/* free resources */
	free(lScoreStr);
	free(rScoreStr);
	free(court);
	free(lPlayer);
	free(rPlayer);
	free(ball);

	TTF_CloseFont(font);
	TTF_Quit();
	SDL_FreeSurface(lScore);
	SDL_FreeSurface(rScore);
	SDL_Quit();

	return EXIT_SUCCESS;
}