Beispiel #1
0
// classic way
void XenonGLDisplay()
{    	
	// Reset states and matrices
	XeGlResetDirty();
	xe_state.dirty = 1;
	
	// Set stream
    Xe_SetStreamSource(xe, 0, pVbGL, 0, 10);
	
    // update vb and ib cache !!!
    xe_Vertices = Xe_VB_Lock(xe, pVbGL, 0, xe_NumVerts * sizeof(glVerticesFormat_t), XE_LOCK_WRITE);
	Xe_VB_Unlock(xe, pVbGL);
	
	xe_indices = Xe_IB_Lock(xe, pIbGL, 0, xe_NumIndices * sizeof(short), XE_LOCK_WRITE);
	Xe_IB_Unlock(xe, pIbGL); 
    
    // Resolve
    Xe_Resolve(xe);
    //while(!Xe_IsVBlank(xe));
    
    Xe_Sync(xe);
    
    // Reset states
    Xe_InvalidateState(xe);
    
    
    
    // printf("xe_NumVerts %d xe_NumIndices %d\r\n", xe_NumVerts, xe_NumIndices);
    
    // Reset vertices
    xe_NumVerts = xe_PrevNumVerts = 0;
    xe_NumIndices = xe_PrevNumIndices = 0;
 
	ShowFPS();
}
Beispiel #2
0
static bool xenon360_gfx_frame(void *data, const void *frame, unsigned width, unsigned height,
      uint64_t frame_count, unsigned pitch, const char *msg, video_frame_info_t *video_info)
{
   gl_t *vid = data;

   ScreenUv[UV_TOP]	= ((float) (width) / (float) XE_W)*2;
   ScreenUv[UV_LEFT]	= ((float) (height) / (float) XE_H)*2;

   DrawVerticeFormats * Rect = Xe_VB_Lock(vid->gl_device, vid->vb, 0, 3 * sizeof(DrawVerticeFormats), XE_LOCK_WRITE);

   /* bottom left */
   Rect[1].v = ScreenUv[UV_LEFT];
   Rect[2].u = ScreenUv[UV_TOP];

   Xe_VB_Unlock(vid->gl_device, vid->vb);

   /* Refresh texture cache */
   uint16_t *dst       = Xe_Surface_LockRect(vid->gl_device, vid->g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE);
   const uint16_t *src = frame;
   unsigned stride_in  = pitch >>1;
   unsigned stride_out = vid->g_pTexture->wpitch >> 1;
   unsigned copy_size  = width << 1;

   for (unsigned y = 0; y < height; y++, dst += stride_out, src += stride_in)
      memcpy(dst, src, copy_size);
   Xe_Surface_Unlock(vid->gl_device, vid->g_pTexture);

   /* Reset states */
   Xe_InvalidateState(vid->gl_device);
   Xe_SetClearColor(vid->gl_device, 0);

   /* Select stream */
   Xe_SetTexture(vid->gl_device, 0, vid->g_pTexture);
   Xe_SetCullMode(vid->gl_device, XE_CULL_NONE);
   Xe_SetStreamSource(vid->gl_device, 0, vid->vb, 0, sizeof(DrawVerticeFormats));

   /* Select shaders */
   Xe_SetShader(vid->gl_device, SHADER_TYPE_PIXEL, vid->g_pPixelTexturedShader, 0);
   Xe_SetShader(vid->gl_device, SHADER_TYPE_VERTEX, vid->g_pVertexShader, 0);

#ifdef HAVE_MENU
   menu_driver_frame(video_info);
#endif

   /* Draw */
   Xe_DrawPrimitive(vid->gl_device, XE_PRIMTYPE_TRIANGLELIST, 0, 1);

   /* Resolve */
   Xe_Resolve(vid->gl_device);
   Xe_Sync(vid->gl_device);

   return true;
}
Beispiel #3
0
void XenonGLDisplay()
{
    Xe_SetBlendOp(xe, XE_BLENDOP_ADD);
    Xe_SetSrcBlend(xe, XE_BLEND_SRCALPHA);
    Xe_SetDestBlend(xe, XE_BLEND_INVSRCALPHA);
    
    // update vb cache !!!
    Xe_VB_Lock(xe, pVbGL, 0, XE_MAX_VERTICES, XE_LOCK_WRITE);
	Xe_VB_Unlock(xe, pVbGL);    
    
/*
	// Refresh texture cash
    unsigned int * pBitmap = Xe_Surface_LockRect(xe, pVideoSurface, 0, 0, 0, 0, XE_LOCK_WRITE);
    int i;
    for(i = 0;i<(vid.width*vid.height);i++)
	{
		//Make an ARGB bitmap
		unsigned int c = (pQ2Palette[vid.buffer[i]]) >> 8 | ( 0xFF << 24 );
		pBitmap[i] = c;
	}
    
    Xe_Surface_Unlock(xe, pVideoSurface);

    // Select stream and shaders
    Xe_SetTexture(xe, 0, pVideoSurface);
    Xe_SetCullMode(xe, XE_CULL_NONE);
    Xe_SetStreamSource(xe, 0, pVBSw, 0, 10);
    Xe_SetShader(xe, SHADER_TYPE_PIXEL, pPixelShader, 0);
    Xe_SetShader(xe, SHADER_TYPE_VERTEX, pVertexShader, 0);
   
    // Draw
    Xe_DrawPrimitive(xe, XE_PRIMTYPE_RECTLIST, 0, 1);
*/    
    // Resolve
    Xe_Resolve(xe);
    while(!Xe_IsVBlank(xe));
    Xe_Sync(xe);
    
    // Reset states
    Xe_InvalidateState(xe);
    Xe_SetClearColor(xe, 0);
    
    xe_NumVerts = xe_PrevNumVerts = 0;
 
	ShowFPS();
}
Beispiel #4
0
void XenonGLInit(){
	// init video
	xe=&_xe;
	
	Xe_Init(xe);
	
	edram_init(xe);
	Xe_SetRenderTarget(xe, Xe_GetFramebufferSurface(xe));
	static const struct XenosVBFFormat vbf = {
		4,
		{
			{XE_USAGE_POSITION, 0, XE_TYPE_FLOAT4},
			{XE_USAGE_TEXCOORD, 0, XE_TYPE_FLOAT2},			
			{XE_USAGE_TEXCOORD, 1, XE_TYPE_FLOAT2},
			{XE_USAGE_COLOR, 0, XE_TYPE_UBYTE4},
		}
	};
	
	pPixelShader = Xe_LoadShaderFromMemory(xe, (void*) g_xps_ps_main);
	Xe_InstantiateShader(xe, pPixelShader, 0);

	pVertexShader = Xe_LoadShaderFromMemory(xe, (void*) g_xvs_vs_main);
	Xe_InstantiateShader(xe, pVertexShader, 0);
	Xe_ShaderApplyVFetchPatches(xe, pVertexShader, 0, &vbf);
	
	// Create vb
	pVbGL = Xe_CreateVertexBuffer(xe, XE_MAX_VERTICES);
	xe_Vertices = Xe_VB_Lock(xe, pVbGL, 0, XE_MAX_VERTICES, XE_LOCK_WRITE);
	Xe_VB_Unlock(xe, pVbGL);
	
	// init matrices
	XeGlInitializeMatrix(&projection_matrix);
	XeGlInitializeMatrix(&modelview_matrix);
	
	// init vertices
	xe_NumVerts = 0;
	xe_CurrentColor.u32 = 0xFFFFFFFF;
	
	// init textures
	// not yet ...
	Xe_InvalidateState(xe);
	Xe_SetClearColor(xe, 0);
	
}
void update_texture_viewport() {
    struct XenosSurface * fb = Xe_GetFramebufferSurface(g_pVideoDevice);
    
    // center
    float x, y;
    x = 0;
    y = 0;
    
    float w =0;
    float h =0;

    // fullscreen
    if(useFullScreen()){
        w = 1;
        h = 1;
    }else{
        // 4/3
        w = 3.f/4.f;
        h = 1;
    }
    
    DrawVerticeFormats *Rect = Xe_VB_Lock(g_pVideoDevice, vb, 0, 3 * sizeof (DrawVerticeFormats), XE_LOCK_WRITE);
    {
        // bottom left
        Rect[0].x = x - w;
        Rect[0].y = y - h;
        Rect[0].u = 0;
        Rect[0].v = 1;

        // bottom right
        Rect[1].x = x + w;
        Rect[1].y = y - h;
        Rect[1].u = 1;
        Rect[1].v = 1;

        // top right
        Rect[2].x = x + w;
        Rect[2].y = y + h;
        Rect[2].u = 1;
        Rect[2].v = 0;
    }
    Xe_VB_Unlock(g_pVideoDevice, vb);
}
Beispiel #6
0
void XenonEndGl()
{	
	// update vb cache !!!
    xe_Vertices = Xe_VB_Lock(xe, pVbGL, 0, xe_NumVerts * sizeof(glVerticesFormat_t), XE_LOCK_WRITE);
	Xe_VB_Unlock(xe, pVbGL);
	
	xe_indices = Xe_IB_Lock(xe, pIbGL, 0, xe_NumIndices * sizeof(short), XE_LOCK_WRITE);
	Xe_IB_Unlock(xe, pIbGL); 
	
	// Resolve
    Xe_Resolve(xe);
    
	Xe_Execute(xe);
	
	// Reset vertices
    xe_NumVerts = xe_PrevNumVerts = 0;
    xe_NumIndices = xe_PrevNumIndices = 0;
 
	ShowFPS();
}
Beispiel #7
0
void CreateTexture(int width, int height) {
    // Create display
    static int old_width = 0;
    static int old_height = 0;

    if ((width != old_width) || (old_height != height)) {

        texturesize[1] = width;
        texturesize[0] = height;

        //printf("Old w:%d - h:%d\r\n", old_width, old_height);
        //printf("New w:%d - h:%d\r\n", width, height);

        PsxScreenUv[UvTop] = (float) width / psxRealW;
        PsxScreenUv[UvLeft] = (float) height / psxRealH;

        // top left
        Rect[0].u = PsxScreenUv[UvBottom];
        Rect[0].v = PsxScreenUv[UvRight];

        // bottom left
        Rect[4].u = Rect[1].u = PsxScreenUv[UvBottom];
        Rect[4].v = Rect[1].v = PsxScreenUv[UvLeft];

        // top right
        Rect[3].u = Rect[2].u = PsxScreenUv[UvTop];
        Rect[3].v = Rect[2].v = PsxScreenUv[UvRight];

        // bottom right
        Rect[5].u = PsxScreenUv[UvTop];
        Rect[5].v = PsxScreenUv[UvLeft];

        vb = Xe_CreateVertexBuffer(g_pVideoDevice, 6 * sizeof (DrawVerticeFormats));
        void *v = Xe_VB_Lock(g_pVideoDevice, vb, 0, 6 * sizeof (DrawVerticeFormats), XE_LOCK_WRITE);
        memcpy(v, Rect, 6 * sizeof (DrawVerticeFormats));
        Xe_VB_Unlock(g_pVideoDevice, vb);

        old_width = width;
        old_height = height;
    }
}
Beispiel #8
0
static void *xenon360_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data)
{
   gl_t * gl = calloc(1, sizeof(gl_t));
   if (!gl)
      return NULL;

   gl->gl_device = &gl->real_device;

   Xe_Init(gl->gl_device);

   Xe_SetRenderTarget(gl->gl_device, Xe_GetFramebufferSurface(gl->gl_device));

   static const struct XenosVBFFormat vbf =
   {
      3,
      {
         {XE_USAGE_POSITION, 0, XE_TYPE_FLOAT4},
	 {XE_USAGE_COLOR, 0, XE_TYPE_UBYTE4},
	 {XE_USAGE_TEXCOORD, 0, XE_TYPE_FLOAT2},
      }
   };

   gl->g_pPixelTexturedShader = Xe_LoadShaderFromMemory(gl->gl_device, (void*)g_xps_PS);
   Xe_InstantiateShader(gl->gl_device, gl->g_pPixelTexturedShader, 0);

   gl->g_pVertexShader = Xe_LoadShaderFromMemory(gl->gl_device, (void*)g_xvs_VS);
   Xe_InstantiateShader(gl->gl_device, gl->g_pVertexShader, 0);
   Xe_ShaderApplyVFetchPatches(gl->gl_device, gl->g_pVertexShader, 0, &vbf);

   gl->g_pTexture = Xe_CreateTexture(gl->gl_device, XE_W, XE_H, 1, XE_FMT_5551 | XE_FMT_16BE, 0);
   gl->g_pTexture->use_filtering = 1;

   edram_init(gl->gl_device);


   // enable filtering for now

   float x = -1.0f;
   float y = 1.0f;
   float w = 4.0f;
   float h = 4.0f;

   gl->vb = Xe_CreateVertexBuffer(gl->gl_device, 3 * sizeof(DrawVerticeFormats));
   DrawVerticeFormats *Rect = Xe_VB_Lock(gl->gl_device, gl->vb, 0, 3 * sizeof (DrawVerticeFormats), XE_LOCK_WRITE);

   ScreenUv[UV_TOP] = ScreenUv[UV_TOP] * 2;
   ScreenUv[UV_LEFT] = ScreenUv[UV_LEFT] * 2;

   // top left
   Rect[0].x = x;
   Rect[0].y = y;
   Rect[0].u = ScreenUv[UV_BOTTOM];
   Rect[0].v = ScreenUv[UV_RIGHT];
   Rect[0].color = 0;

   // bottom left
   Rect[1].x = x;
   Rect[1].y = y - h;
   Rect[1].u = ScreenUv[UV_BOTTOM];
   Rect[1].v = ScreenUv[UV_LEFT];
   Rect[1].color = 0;

   // top right
   Rect[2].x = x + w;
   Rect[2].y = y;
   Rect[2].u = ScreenUv[UV_TOP];
   Rect[2].v = ScreenUv[UV_RIGHT];
   Rect[2].color = 0;

   Rect[3].x = x + w;
   Rect[3].y = y;
   Rect[3].u = ScreenUv[UV_TOP];
   Rect[3].v = ScreenUv[UV_RIGHT];
   Rect[3].color = 0;

   int i = 0;
   for (i = 0; i < 3; i++)
   {
      Rect[i].z = 0.0;
      Rect[i].w = 1.0;
   }

   Xe_VB_Unlock(gl->gl_device, gl->vb);

   Xe_SetClearColor(gl->gl_device, 0);

   return gl;
}
Beispiel #9
0
void XenonGLInit(){
	
	// init video
	xe=&_xe;
	
	Xe_Init(xe);
	
	edram_init(xe);
	Xe_SetRenderTarget(xe, Xe_GetFramebufferSurface(xe));
	static const struct XenosVBFFormat vbf = {
		4,
		{
			{XE_USAGE_POSITION, 0, XE_TYPE_FLOAT4},
			{XE_USAGE_TEXCOORD, 0, XE_TYPE_FLOAT2},			
			{XE_USAGE_TEXCOORD, 1, XE_TYPE_FLOAT2},
			{XE_USAGE_COLOR, 0, XE_TYPE_UBYTE4},
		}
	};
	
	struct XenosSurface * fb = Xe_GetFramebufferSurface(xe);
	
	pPixelTextureShader = Xe_LoadShaderFromMemory(xe, (void*) g_xps_ps_texture);
	Xe_InstantiateShader(xe, pPixelTextureShader, 0);
	
	pPixelModulateShader = Xe_LoadShaderFromMemory(xe, (void*) g_xps_ps_modulate);
	Xe_InstantiateShader(xe, pPixelModulateShader, 0);
	
	pPixelModulateShader2 = Xe_LoadShaderFromMemory(xe, (void*) g_xps_ps_modulate_2);
	Xe_InstantiateShader(xe, pPixelModulateShader2, 0);
	
	pPixelColorShader = Xe_LoadShaderFromMemory(xe, (void*) g_xps_ps_color);
	Xe_InstantiateShader(xe, pPixelColorShader, 0);
	
	pCurrentPs = g_xps_ps_color;
	pCurrentTexturedPs = g_xps_ps_texture;

	pVertexShader = Xe_LoadShaderFromMemory(xe, (void*) g_xvs_vs_main);
	Xe_InstantiateShader(xe, pVertexShader, 0);
	Xe_ShaderApplyVFetchPatches(xe, pVertexShader, 0, &vbf);
	
	// Create vb
	pVbGL = Xe_CreateVertexBuffer(xe, XE_MAX_VERTICES * sizeof(glVerticesFormat_t));
	xe_Vertices = Xe_VB_Lock(xe, pVbGL, 0, XE_MAX_VERTICES * sizeof(glVerticesFormat_t), XE_LOCK_WRITE);
	Xe_VB_Unlock(xe, pVbGL);
	
	// Create indices
	pIbGL = Xe_CreateIndexBuffer(xe, XE_MAX_INDICES_PER_DRAW, XE_FMT_INDEX16);
	xe_indices = Xe_IB_Lock(xe, pIbGL, 0, XE_MAX_INDICES_PER_DRAW, XE_LOCK_WRITE);
	Xe_IB_Unlock(xe, pIbGL);
	
	// init matrices
	XeGlInitializeMatrix(&projection_matrix);
	XeGlInitializeMatrix(&modelview_matrix);
	
	// frontbuffer = Xe_CreateTexture(xe, fb->width, fb->height, 0, XE_FMT_8888 | XE_FMT_BGRA, 1);
	
	// init vertices
	xe_NumVerts = 0;
	xe_NumIndices = 0;
	xe_CurrentColor.u32 = 0x0;
	
	// init textures
	XeGLInitTextures();
	
	// init states
	XeInitStates();
	
	// not yet ...
	Xe_InvalidateState(xe);
	Xe_SetClearColor(xe, 0);
	
	GL_InitShaderCache();
	
}
Beispiel #10
0
void SYSVideoInit() {


    g_pVideoDevice = GetVideoDevice();

    Xe_SetRenderTarget(g_pVideoDevice, Xe_GetFramebufferSurface(g_pVideoDevice));

    if (video_initialised == 0) {
        // init 2xsai buffer
        hq_buffer = (unsigned char*) malloc(1024 * 1024 * 4);


        static const struct XenosVBFFormat vbf = {
            3,
            {
                {XE_USAGE_POSITION, 0, XE_TYPE_FLOAT4},
                {XE_USAGE_COLOR, 0, XE_TYPE_UBYTE4},
                {XE_USAGE_TEXCOORD, 0, XE_TYPE_FLOAT2},
            }
        };

        g_pPixelTexturedShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xps_PS);
        Xe_InstantiateShader(g_pVideoDevice, g_pPixelTexturedShader, 0);

        g_pVertexShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xvs_VS);
        Xe_InstantiateShader(g_pVideoDevice, g_pVertexShader, 0);
        Xe_ShaderApplyVFetchPatches(g_pVideoDevice, g_pVertexShader, 0, &vbf);

        if (g_pTexture == NULL)
            g_pTexture = Xe_CreateTexture(g_pVideoDevice, XE_W, XE_H, 1, XE_FMT_8888 | XE_FMT_ARGB, 0);

        texture_buffer = (unsigned char*) Xe_Surface_LockRect(g_pVideoDevice, g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE);
        pitch = g_pTexture->wpitch;
        Xe_Surface_Unlock(g_pVideoDevice, g_pTexture);

    }

    memset(hq_buffer, 0, 1024 * 1024 * 4);

    // disable filtering
/*
    if (config.video_filter)
        g_pTexture->use_filtering = 1;
    else
        g_pTexture->use_filtering = 0;
*/

    
    /*
        screen = texture_buffer;
     * pitch = g_pTexture->wpitch;
     */
    screen = hq_buffer;

    /*
        float w = 2.0f;
        float h = 2.0f;
     */
    if (video_initialised == 0) {

        // move it to ini file
        float x = -1.0f;
        float y = 1.0f;
        float w = 2.0f;
        float h = 2.0f;

        vb = Xe_CreateVertexBuffer(g_pVideoDevice, 3 * sizeof (DrawVerticeFormats));
        DrawVerticeFormats *Rect = Xe_VB_Lock(g_pVideoDevice, vb, 0, 3 * sizeof (DrawVerticeFormats), XE_LOCK_WRITE);
        {
            // top left
            Rect[0].x = x;
            Rect[0].y = y;
            Rect[0].u = ScreenUv[UvBottom];
            Rect[0].v = ScreenUv[UvRight];
            Rect[0].color = 0;

            // bottom left
            Rect[1].x = x;
            Rect[1].y = y - h;
            Rect[1].u = ScreenUv[UvBottom];
            Rect[1].v = ScreenUv[UvLeft];
            Rect[1].color = 0;

            // top right
            Rect[2].x = x + w;
            Rect[2].y = y;
            Rect[2].u = ScreenUv[UvTop];
            Rect[2].v = ScreenUv[UvRight];
            Rect[2].color = 0;

            int i = 0;
            for (i = 0; i < 3; i++) {
                Rect[i].z = 0.0;
                Rect[i].w = 1.0;
            }
        }
        Xe_VB_Unlock(g_pVideoDevice, vb);

    }
    if (video_initialised == 0)
        video_initialised = 1;
}
Beispiel #11
0
void osd_xenon_update_video(render_primitive_list &primlist) {

    //primlist->acquire_lock();
    currList = &primlist;
	pre_render();

	int minwidth, minheight;
	int newwidth, newheight;

	// get the minimum width/height for the current layout
	xenos_target->compute_minimum_size(minwidth, minheight);

//            minwidth = screen_width;
//            minheight = screen_height;

	// make that the size of our target
	xenos_target->set_bounds(minwidth, minheight);

	xenos_target->compute_visible_area(screen_width, screen_height, screen_width / screen_height, xenos_target->orientation(), newwidth, newheight);

	//ShaderEffects.at(2).Render(minwidth, minheight);
	ShaderEffects.at(0).Render(minwidth, minheight);

	Xe_SetStreamSource(g_pVideoDevice, 0, soft_vb, nb_vertices, sizeof (MameVerticeFormats));

	vertices = (MameVerticeFormats *) Xe_VB_Lock(g_pVideoDevice, soft_vb, 0, 3 * sizeof (MameVerticeFormats), XE_LOCK_WRITE);
	//CreateRect(((float) newwidth / (float) screen_width), -((float) newheight / (float) screen_height), vertices);
	CreateRectHlsl(screen_width, screen_height, vertices);
	Xe_VB_Unlock(g_pVideoDevice, soft_vb);

	// update texture
	//draw32_draw_primitives(primlist, screen, minwidth, minheight, g_pTexture->wpitch / 4);

	/* loop over the list and render each element */
	const render_primitive *prim;
	void *dstdata = (void *) screen;
	UINT32 width = minwidth;
	UINT32 height = minheight;
	UINT32 pitch = g_pTexture->wpitch / 4;
	/*
	for (prim = currList->first(); prim != NULL; prim = prim->next()) {
		switch (prim->type) {
			case render_primitive::LINE:
				draw32_draw_line(prim, dstdata, width, height, pitch);
				break;

			case render_primitive::QUAD:
				if (!prim->texture.base)
					draw32_draw_rect(prim, dstdata, width, height, pitch);
				else
					draw32_setup_and_draw_textured_quad(prim, dstdata, width, height, pitch);
				break;

			default:
				throw emu_fatalerror("Unexpected render_primitive type");
		}
	}
	* */
	
	software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(primlist, dstdata, width, height, pitch);

	Xe_Surface_LockRect(g_pVideoDevice, g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE);
	Xe_Surface_Unlock(g_pVideoDevice, g_pTexture);

	// correct texture size
	g_pTexture->width = minwidth;
	g_pTexture->height = minheight;

	// draw
	Xe_SetTexture(g_pVideoDevice, 0, g_pTexture);
	Xe_DrawPrimitive(g_pVideoDevice, XE_PRIMTYPE_RECTLIST, 0, 1);

	render();
}
Beispiel #12
0
void	VID_Init (void)
{
	TR;
    refimport_t	ri;

    viddef.width = 320;
    viddef.height = 240;

    ri.Cmd_AddCommand = Cmd_AddCommand;
    ri.Cmd_RemoveCommand = Cmd_RemoveCommand;
    ri.Cmd_Argc = Cmd_Argc;
    ri.Cmd_Argv = Cmd_Argv;
    ri.Cmd_ExecuteText = Cbuf_ExecuteText;
    ri.Con_Printf = VID_Printf;
    ri.Sys_Error = VID_Error;
    ri.FS_LoadFile = FS_LoadFile;
    ri.FS_FreeFile = FS_FreeFile;
    ri.FS_Gamedir = FS_Gamedir;
    ri.Vid_MenuInit = VID_MenuInit;
	ri.Vid_NewWindow = VID_NewWindow;
    ri.Cvar_Get = Cvar_Get;
    ri.Cvar_Set = Cvar_Set;
    ri.Cvar_SetValue = Cvar_SetValue;
    ri.Vid_GetModeInfo = VID_GetModeInfo;

    re = GetRefAPI(ri);
	xe=&_xe;
	
	Xe_Init(xe);
	
	edram_init(xe);
	Xe_SetRenderTarget(xe, Xe_GetFramebufferSurface(xe));
	static const struct XenosVBFFormat vbf = {
		3,
		{
			{XE_USAGE_POSITION, 0, XE_TYPE_FLOAT4},
			{XE_USAGE_COLOR, 0, XE_TYPE_UBYTE4},
			{XE_USAGE_TEXCOORD, 0, XE_TYPE_FLOAT2},
		}
	};
	
	pPixelShader = Xe_LoadShaderFromMemory(xe, (void*) g_xps_PS);
	Xe_InstantiateShader(xe, pPixelShader, 0);

	pVertexShader = Xe_LoadShaderFromMemory(xe, (void*) g_xvs_VS);
	Xe_InstantiateShader(xe, pVertexShader, 0);
	Xe_ShaderApplyVFetchPatches(xe, pVertexShader, 0, &vbf);
	
	// Create vb
	pVBSw = Xe_CreateVertexBuffer(xe, 3 * sizeof (DrawVerticeFormats));
	
	DrawVerticeFormats *Rect = Xe_VB_Lock(xe, pVBSw, 0, 3 * sizeof (DrawVerticeFormats), XE_LOCK_WRITE);
	{
		// top left
		Rect[0].x = -1;
		Rect[0].y = 1;
		Rect[0].u = 0;
		Rect[0].v = 0;
		Rect[0].color = 0;

		// bottom left
		Rect[1].x = -1;
		Rect[1].y = -1;
		Rect[1].u = 0;
		Rect[1].v = 1;
		Rect[1].color = 0;

		// top right
		Rect[2].x = 1;
		Rect[2].y = 1;
		Rect[2].u = 1;
		Rect[2].v = 0;
		Rect[2].color = 0;

		int i = 0;
		for (i = 0; i < 3; i++) {
			Rect[i].z = 0.0;
			Rect[i].w = 1.0;
		}
	}
	Xe_VB_Unlock(xe, pVBSw);
	
	pVideoSurface = NULL;
		
	if (re.api_version != API_VERSION)
        Com_Error (ERR_FATAL, "Re has incompatible api_version");
    
        // call the init function
    if (re.Init (NULL, NULL) == -1)
		Com_Error (ERR_FATAL, "Couldn't start refresh");
}
Beispiel #13
0
static void draw_quad(render_primitive *prim) {
    void * texture = (prim->texture.base);

    //void Xe_SetBlendControl(struct XenosDevice *xe, int col_src, int col_op, int col_dst, int alpha_src, int alpha_op, int alpha_dst);
    switch (PRIMFLAG_GET_BLENDMODE(prim->flags)) {
        case BLENDMODE_NONE:
            Xe_SetAlphaTestEnable(g_pVideoDevice,0);
            Xe_SetBlendOp(g_pVideoDevice, XE_BLENDOP_ADD);
            Xe_SetSrcBlend(g_pVideoDevice, XE_BLEND_SRCALPHA);
            Xe_SetDestBlend(g_pVideoDevice, XE_BLEND_INVSRCALPHA);
            break;
        case BLENDMODE_ALPHA:
            Xe_SetAlphaTestEnable(g_pVideoDevice,1);
            Xe_SetBlendOp(g_pVideoDevice, XE_BLENDOP_ADD);
            Xe_SetSrcBlend(g_pVideoDevice, XE_BLEND_SRCALPHA);
            Xe_SetDestBlend(g_pVideoDevice, XE_BLEND_INVSRCALPHA);
            break;
        case BLENDMODE_RGB_MULTIPLY:
            Xe_SetAlphaTestEnable(g_pVideoDevice,1);
            Xe_SetBlendOp(g_pVideoDevice, XE_BLENDOP_ADD);
            Xe_SetSrcBlend(g_pVideoDevice, XE_BLEND_DESTCOLOR);
            Xe_SetDestBlend(g_pVideoDevice, XE_BLEND_ZERO);
            break;
        case BLENDMODE_ADD:
            Xe_SetAlphaTestEnable(g_pVideoDevice,1);
            Xe_SetBlendOp(g_pVideoDevice, XE_BLENDOP_ADD);
            Xe_SetSrcBlend(g_pVideoDevice, XE_BLEND_SRCALPHA);
            Xe_SetDestBlend(g_pVideoDevice, XE_BLEND_ONE);
            break;
    }

    DrawVerticeFormats *vertex = (DrawVerticeFormats *) Xe_VB_Lock(g_pVideoDevice, vb, nb_vertices, 3 * sizeof (DrawVerticeFormats), XE_LOCK_WRITE);
    memset(vertex, 0, 3 * sizeof (DrawVerticeFormats));
    {
        vertex[0].x = prim->bounds.x0 - 0.5f;
        vertex[0].y = prim->bounds.y0 - 0.5f;
        vertex[1].x = prim->bounds.x1 - 0.5f;
        vertex[1].y = prim->bounds.y0 - 0.5f;
        vertex[2].x = prim->bounds.x0 - 0.5f;
        vertex[2].y = prim->bounds.y1 - 0.5f;
        vertex[3].x = prim->bounds.x1 - 0.5f;
        vertex[3].y = prim->bounds.y1 - 0.5f;

        // set the texture coordinates
        if (texture != NULL) {
            vertex[0].u = prim->texcoords.tl.u;
            vertex[0].v = prim->texcoords.tl.v;
            vertex[1].u = prim->texcoords.tr.u;
            vertex[1].v = prim->texcoords.tr.v;
            vertex[2].u = prim->texcoords.bl.u;
            vertex[2].v = prim->texcoords.bl.v;
            vertex[3].u = prim->texcoords.br.u;
            vertex[3].v = prim->texcoords.br.v;
            n++;
        }

        XeColor color;
        color.r = (prim->color.r * 255.0f);
        color.g = (prim->color.g * 255.0f);
        color.b = (prim->color.b * 255.0f);
        color.a = (prim->color.a * 255.0f);

        int i = 0;
        for (i = 0; i < 3; i++) {
            vertex[i].z = 0.0;
            vertex[i].w = 1.0;
        }
    }


    Xe_VB_Unlock(g_pVideoDevice, vb);

    Xe_SetStreamSource(g_pVideoDevice, 0, vb, nb_vertices, sizeof (DrawVerticeFormats));
    Xe_DrawPrimitive(g_pVideoDevice, XE_PRIMTYPE_RECTLIST, 0, 1);

    nb_vertices += 256;
}