void Render(int width, int height) { float settings_texture_size[2] = {width, height}; Xe_SetShader(g_pVideoDevice, SHADER_TYPE_PIXEL, ps, 0); Xe_SetShader(g_pVideoDevice, SHADER_TYPE_VERTEX, vs, 0); // Xe_SetVertexShaderConstantF(g_pVideoDevice, 0, settings_texture_size, 1); // Xe_SetPixelShaderConstantF(g_pVideoDevice, 0, settings_texture_size, 1); };
void XeDrawSurface2(struct XenosSurface *txt, float dstx, float dsty, float width, float height, int withalpha) { float uleft = 0, uright = 1, vtop = 0, vbottom = 1; float logo[] = { dstx, dsty + height, uleft, vtop, dstx + width, dsty + height, uright, vtop, dstx, dsty, uleft, vbottom, dstx, dsty, uleft, vbottom, dstx + width, dsty + height, uright, vtop, dstx + width, dsty, uright, vbottom }; Xe_VBBegin(xe, 4); Xe_VBPut(xe, logo, 6 * 4); struct XenosVertexBuffer *vb = Xe_VBEnd(xe); Xe_VBPoolAdd(xe, vb); if (withalpha) { Xe_SetSrcBlend(xe, XE_BLEND_SRCALPHA); Xe_SetDestBlend(xe, XE_BLEND_INVSRCALPHA); Xe_SetBlendOp(xe, XE_BLENDOP_ADD); } else { Xe_SetSrcBlend(xe, XE_BLEND_ONE); Xe_SetDestBlend(xe, XE_BLEND_ZERO); Xe_SetBlendOp(xe, XE_BLENDOP_ADD); } Xe_SetShader(xe, SHADER_TYPE_PIXEL, sh_text_ps, 0); Xe_SetShader(xe, SHADER_TYPE_VERTEX, sh_text_vs, 0); Xe_SetTexture(xe, 0, txt); Xe_Draw(xe, vb, 0); }
// GL_TEXTURE_ENV_MODE defaults to GL_MODULATE void GL_SelectShaders() { int i = 0; pixel_shader_pipeline_t shader; shader.hash = 0; // Create hash for (i=0; i<XE_MAX_TMUS; i++) { // add hash if (xeTmus[i].enabled && xeTmus[i].boundtexture) { switch(xeTmus[i].texture_env_mode) { case GL_REPLACE: shader.states[i].tmu_env_mode = XE_ENV_MODE_REPLACE; break; case GL_BLEND: shader.states[i].tmu_env_mode = XE_ENV_MODE_BLEND; break; case GL_DECAL: shader.states[i].tmu_env_mode = XE_ENV_MODE_DECAL; break; case GL_ADD: shader.states[i].tmu_env_mode = XE_ENV_MODE_ADD; break; default: case GL_MODULATE: shader.states[i].tmu_env_mode = XE_ENV_MODE_MODULATE; break; } } // no more texture used else { break; } } // color only !!! if (shader.hash == 0) { Xe_SetShader(xe, SHADER_TYPE_PIXEL, pPixelColorShader, 0); return; } // look into cache for (i=0; i<XE_ENV_MAX * XE_MAX_TMUS; i++) { if (cache[i].hash) { if (cache[i].hash == shader.hash) { Xe_SetShader(xe, SHADER_TYPE_PIXEL, cache[i].code, 0); return; } } } // create it and add it to cache /* todo */ printf("Unknow hash : %d\n", shader.hash); }
void SYSVideoUpdate() { /* resize uv to viewport */ int vwidth = bitmap.viewport.w + (2 * bitmap.viewport.x); int vheight = bitmap.viewport.h + (2 * bitmap.viewport.y); update_texture_viewport(); int video_filter = getVideoFitler(); // apply video filter switch (video_filter){ case VF_2XSAI: filter_Std2xSaI_ex8(bitmap.data, bitmap.pitch, texture_buffer, vwidth, vheight); g_pTexture->width = vwidth<<1; g_pTexture->height = vheight<<1; break; case VF_BLINEAR: g_pTexture->use_filtering = 0; XeTexSubImage(g_pTexture, bitmap.viewport.x, bitmap.viewport.y, bitmap.viewport.w, bitmap.viewport.h, bitmap.data); g_pTexture->width = vwidth; g_pTexture->height = vheight; break; default: g_pTexture->use_filtering = 1; XeTexSubImage(g_pTexture, bitmap.viewport.x, bitmap.viewport.y, bitmap.viewport.w, bitmap.viewport.h, bitmap.data); g_pTexture->width = vwidth; g_pTexture->height = vheight; break; } // Refresh texture cash Xe_Surface_LockRect(g_pVideoDevice, g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE); Xe_Surface_Unlock(g_pVideoDevice, g_pTexture); // Select stream and shaders Xe_SetTexture(g_pVideoDevice, 0, g_pTexture); Xe_SetCullMode(g_pVideoDevice, XE_CULL_NONE); Xe_SetStreamSource(g_pVideoDevice, 0, vb, 0, sizeof (DrawVerticeFormats)); Xe_SetShader(g_pVideoDevice, SHADER_TYPE_PIXEL, g_pPixelTexturedShader, 0); Xe_SetShader(g_pVideoDevice, SHADER_TYPE_VERTEX, g_pVertexShader, 0); Xe_SetClearColor(g_pVideoDevice, 0xFF000000); // Draw Xe_DrawPrimitive(g_pVideoDevice, XE_PRIMTYPE_RECTLIST, 0, 1); // Resolve Xe_Resolve(g_pVideoDevice); //while (!Xe_IsVBlank(g_pVideoDevice)); Xe_Sync(g_pVideoDevice); // Reset states Xe_InvalidateState(g_pVideoDevice); }
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; }
static void pre_render() { Xe_SetAlphaTestEnable(g_pVideoDevice, 1); Xe_SetCullMode(g_pVideoDevice, XE_CULL_NONE); Xe_InvalidateState(g_pVideoDevice); Xe_SetShader(g_pVideoDevice, SHADER_TYPE_PIXEL, g_pPixelTexturedShader, 0); Xe_SetShader(g_pVideoDevice, SHADER_TYPE_VERTEX, g_pVertexShader, 0); //Xe_SetFillMode(g_pVideoDevice,0x25,0x25); nb_vertices = 0; }
//void xeeSubmit() {} void xeeSubmit() { // never draw this one if (gl_cull_mode == GL_FRONT_AND_BACK) return; // update states if dirty XeUpdateStates(); // update if dirty XeGlCheckDirtyMatrix(&projection_matrix); XeGlCheckDirtyMatrix(&modelview_matrix); // Xe_SetStreamSource(xe, 0, pVbGL, xe_PrevNumVerts * sizeof(glVerticesFormat_t), 10); Xe_SetShader(xe, SHADER_TYPE_VERTEX, pVertexShader, 0); int i = 0; // setup texture for(i=0; i<XE_MAX_TMUS; i++) { // set texture if (xeTmus[i].enabled && xeTmus[i].boundtexture) { Xe_SetTexture(xe, i, xeTmus[i].boundtexture->teximg); } else { Xe_SetTexture(xe, i, NULL); } } // setup shaders GL_SelectShaders(); // draw Xe_DrawPrimitive(xe, Gl_Prim_2_Xe_Prim(xe_PrimitiveMode), xe_PrevNumVerts, Gl_Prim_2_Size(xe_PrimitiveMode, (xe_NumVerts - xe_PrevNumVerts))); //printBlendValue(); }
virtual void Render(int width, int height) { // primary.fx // Registers: // // Name Reg Size // ------------ ----- ---- // TargetWidth c0 1 // TargetHeight c1 1 // PostPass c2 1 XenosSurface * fb = Xe_GetFramebufferSurface(g_pVideoDevice); float TargetWidth = fb->width; float TargetHeight = fb->height; float PostPass = 0.f; Xe_SetShader(g_pVideoDevice, SHADER_TYPE_PIXEL, ps, 0); Xe_SetShader(g_pVideoDevice, SHADER_TYPE_VERTEX, vs, 0); Xe_SetVertexShaderConstantF(g_pVideoDevice, 0, (float*) &TargetWidth, 1); Xe_SetVertexShaderConstantF(g_pVideoDevice, 1, (float*) &TargetHeight, 1); Xe_SetVertexShaderConstantF(g_pVideoDevice, 2, (float*) &PostPass, 1); };
static void GL_SubmitVertexes() { // never draw this one if (gl_cull_mode == GL_FRONT_AND_BACK) return; //Xe_SetFillMode(xe, XE_FILL_WIREFRAME, XE_FILL_WIREFRAME); // update states if dirty XeUpdateStates(); // update if dirty XeGlCheckDirtyMatrix(&projection_matrix); XeGlCheckDirtyMatrix(&modelview_matrix); // Xe_SetStreamSource(xe, 0, pVbGL, xe_PrevNumVerts * sizeof(glVerticesFormat_t), 10); Xe_SetShader(xe, SHADER_TYPE_VERTEX, pVertexShader, 0); // setup shaders and textures GL_SelectShaders(); GL_SelectTextures(); // draw if (use_indice_buffer == 0) { /* Xe_DrawPrimitive(struct XenosDevice *xe, int type, int start, int primitive_count) */ Xe_DrawPrimitive(xe, Gl_Prim_2_Xe_Prim(xe_PrimitiveMode), xe_PrevNumVerts, Gl_Prim_2_Size(xe_PrimitiveMode, (xe_NumVerts - xe_PrevNumVerts))); } else { /* Xe_DrawIndexedPrimitive(struct XenosDevice *xe, int type, int base_index, int min_index, int num_vertices, int start_index, int primitive_count) */ Xe_SetIndices(xe, pIbGL); Xe_DrawIndexedPrimitive(xe, Gl_Prim_2_Xe_Prim(xe_PrimitiveMode), 0, 0, (xe_NumVerts - xe_PrevNumVerts), xe_PrevNumIndices, (xe_NumIndices - xe_PrevNumIndices)); /* Xe_DrawIndexedPrimitive(xe,XE_PRIMTYPE_TRIANGLELIST, 0, 0, (xe_NumVerts - xe_PrevNumVerts), xe_PrevNumIndices, 2); */ } //printBlendValue(); }
/** * mode / type **/ void glDrawElements(GLenum mode, GLsizei numIndexes, GLenum type, const GLvoid * indices) { int i = 0; union { float f; unsigned int u32; } color; // Begin xe_PrevNumVerts = xe_NumVerts; xe_PrevNumIndices = xe_NumIndices; unsigned int * indexes = (unsigned int*)indices; void * vertice_ptr = vertexPointer.pointer; void * color_ptr = colorPointer.pointer; void * texcoords0_ptr = texCoordPointer[0].pointer; void * texcoords1_ptr = texCoordPointer[1].pointer; // vertices for (i = 0 ; i < vertexPointer.count ; i++) { float * v = (float*) vertice_ptr; float * t0 = (float*) texcoords0_ptr; float * t1 = (float*) texcoords1_ptr; unsigned char * c = (unsigned char*) color_ptr; color.u32 = COLOR_ARGB(c[3], c[2], c[1], c[0]); //color.u32 = 0xFFFFFFFF; *xe_Vertices++ = v[0]; *xe_Vertices++ = v[1]; *xe_Vertices++ = v[2]; *xe_Vertices++ = 1; if (texcoords0_ptr) { *xe_Vertices++ = t0[0]; *xe_Vertices++ = t0[1]; } else { *xe_Vertices++ = 0; *xe_Vertices++ = 0; } if (texcoords1_ptr) { *xe_Vertices++ = t1[0]; *xe_Vertices++ = t1[1]; } else { *xe_Vertices++ = 0; *xe_Vertices++ = 0; } *xe_Vertices++ = color.f; vertice_ptr += vertexPointer.stride; if (texcoords0_ptr) { texcoords0_ptr += 2 * sizeof(float); } if (texcoords1_ptr) { texcoords1_ptr += 2 * sizeof(float); } color_ptr += 4 * sizeof(char); xe_NumVerts++; } // indices for (i = 0 ; i < numIndexes ; i++) { *xe_indices++ = indexes[i] + xe_PrevNumVerts; xe_NumIndices++; } XeUpdateStates(); XeGlCheckDirtyMatrix(&projection_matrix); XeGlCheckDirtyMatrix(&modelview_matrix); // setup shaders and textures Xe_SetShader(xe, SHADER_TYPE_VERTEX, pVertexShader, 0); GL_SelectShaders(); GL_SelectTextures(); Xe_SetIndices(xe, pIbGL); Xe_SetStreamSource(xe, 0, pVbGL, 0, 10); Xe_DrawIndexedPrimitive( xe, XE_PRIMTYPE_TRIANGLELIST, 0, 0, vertexPointer.count, xe_PrevNumIndices, numIndexes/3 ); }
//Garde l'aspect ratio :) en function de la texture et non du framebuffer void XeDrawSurface(struct XenosSurface *txt, float dstx, float dsty, float scale, int withalpha,int center) { float scrratio = ((float) xe->tex_fb.width / (float) xe->tex_fb.height); //float txtratio=((float)txt->width/(float)txt->height); float height = scale * scrratio; float width = scale; float uleft = 0, uright = 1, vtop = 0, vbottom = 1; dsty=dsty - ((height/2)*center); float logo[] = { dstx, dsty + height, uleft, vtop, dstx + width, dsty + height, uright, vtop, dstx, dsty, uleft, vbottom, dstx, dsty, uleft, vbottom, dstx + width, dsty + height, uright, vtop, dstx + width, dsty, uright, vbottom }; Xe_VBBegin(xe, 4); Xe_VBPut(xe, logo, 6 * 4); struct XenosVertexBuffer *vb = Xe_VBEnd(xe); Xe_VBPoolAdd(xe, vb); if (withalpha) { Xe_SetSrcBlend(xe, XE_BLEND_SRCALPHA); Xe_SetDestBlend(xe, XE_BLEND_INVSRCALPHA); Xe_SetBlendOp(xe, XE_BLENDOP_ADD); } else { Xe_SetSrcBlend(xe, XE_BLEND_ONE); Xe_SetDestBlend(xe, XE_BLEND_ZERO); Xe_SetBlendOp(xe, XE_BLENDOP_ADD); } Xe_SetShader(xe, SHADER_TYPE_PIXEL, sh_text_ps, 0); Xe_SetShader(xe, SHADER_TYPE_VERTEX, sh_text_vs, 0); Xe_SetTexture(xe, 0, txt); Xe_Draw(xe, vb, 0); }
void XePrintf(float dstx, float dsty, const char *text, float scale, uint32_t icolor) { if (!*text) return 0; Xe_VBBegin(xe, 5); while (*text) { //struct fontentry *f = &fontentries[(unsigned char)*text++]; struct fnt_s *f = &verdana_fnt[(unsigned char) *text++]; if (!f->width) continue; float u = f->x / WH; float v = f->y / WH; float uw = f->width / WH; float vw = f->height / WH; float width = uw * scale, height = vw * scale; float xo = f->xoffset / WH * scale; float yo = f->yoffset / WH* scale; float left = dstx + xo, top = dsty - yo, right = dstx + width, bottom = dsty - yo - height; union { float color; int icolor; } un; un.icolor = icolor; float color = un.color; float letter[] = { left, top, u, v, color, right, top, u + uw, v, color, left, bottom, u, v + vw, color, left, bottom, u, v + vw, color, right, top, u + uw, v, color, right, bottom, u + uw, v + vw, color, }; Xe_VBPut(xe, letter, 6 * 5); dstx += f->xadvance / WH * scale; } struct XenosVertexBuffer *vb = Xe_VBEnd(xe); Xe_VBPoolAdd(xe, vb); Xe_SetSrcBlend(xe, XE_BLEND_SRCALPHA); Xe_SetDestBlend(xe, XE_BLEND_INVSRCALPHA); Xe_SetBlendOp(xe, XE_BLENDOP_ADD); Xe_SetShader(xe, SHADER_TYPE_PIXEL, sh_font_ps, 0); Xe_SetShader(xe, SHADER_TYPE_VERTEX, sh_font_vs, 0); Xe_SetTexture(xe, 0, XeFont); Xe_Draw(xe, vb, 0); return dstx; }