Beispiel #1
0
static void Xe_InitTexture(glXeSurface_t *tex)
{
	// slot is empty
	tex->glnum = TEXTURE_SLOT_EMPTY;

	// destroy texture
	if (tex->teximg)
	{
		Xe_DestroyTexture(xe, tex->teximg);
		tex->teximg = NULL;
	}
}
/**
 * Destructor for the GuiText class.
 */
GuiText::~GuiText() {
    if (origText)
        free(origText);
    if (text)
        delete[] text;

    if (textDynNum > 0) {
        for (int i = 0; i < textDynNum; i++)
            if (textDyn[i])
                delete[] textDyn[i];
    }

    if (xe_texture) {
        TR;
        Xe_DestroyTexture(g_pVideoDevice, xe_texture);
    }
}
void GuiText::ResetText() {
    if (!origText)
        return;
    if (text)
        delete[] text;

    text = charToWideChar(gettext(origText));

    for (int i = 0; i < textDynNum; i++) {
        if (textDyn[i]) {
            delete[] textDyn[i];
            textDyn[i] = NULL;
        }
    }

    textDynNum = 0;
    currentSize = 0;

    if (xe_texture) {
        TR;
        Xe_DestroyTexture(g_pVideoDevice, xe_texture);
    }
}
Beispiel #4
0
void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum pixelformat, GLenum type, const GLvoid *pixels)
{
	int format;
	int need_texture = 1;
	struct XenosSurface * surf = NULL;
	
	if (type != GL_UNSIGNED_BYTE) {		
		xe_gl_error("glTexImage2D: Unrecognised pixel format\n");
		
		return;
	}
	if (target != GL_TEXTURE_2D)
		return;
		
	if (!xeTmus[xeCurrentTMU].boundtexture) {
		printf("No texture bound\n");
		return;
	}
	
	if (level > 0)
		return;
		
#if 1
	int srcbytes = src_format_to_bypp(pixelformat);
	int dstbytes = 4;
	
	// validate format
	switch (internalformat)
	{
	case 1:
	case GL_LUMINANCE:
		dstbytes = 1;
		format = XE_FMT_8;
		break;
	case 3:
	case GL_RGB:
		dstbytes = 4;
		format = XE_FMT_ARGB|XE_FMT_8888;
		break;
	case 4:
	case GL_RGB8:
	case GL_RGBA:
		dstbytes = 4;
		format = XE_FMT_ARGB|XE_FMT_8888;
		break;
	default:
		printf("%X internalformat\n" , internalformat);
		xe_gl_error ("invalid texture internal format\n");
		return;
	}
	
	if (xeTmus[xeCurrentTMU].boundtexture->teximg) {
		surf = xeTmus[xeCurrentTMU].boundtexture->teximg;
		if ((surf->width != width) || (surf->height != height) || (surf->format != format)) {
			need_texture = 1;
			// destroy texture
			Xe_DestroyTexture(xe, xeTmus[xeCurrentTMU].boundtexture->teximg);
		}
		else {
			need_texture = 0;
		}
	}
	
	if (need_texture) {	
#ifdef USE_TILED_TEXTURE				
		surf = MyXeCreateTexture(xe, width, height, 0, format, 1);
#else
		surf = MyXeCreateTexture(xe, width, height, 0, format, 0);
#endif
		xeTmus[xeCurrentTMU].boundtexture->teximg = surf;
	}
	
	memset(surf->base, 0xFF, surf->wpitch * surf->hpitch);
	xeTmus[xeCurrentTMU].boundtexture->internalformat = internalformat;
		
	uint8_t * surfbuf = (uint8_t*) MyXeSurfaceLockRect(xe, surf, 0, 0, 0, 0, XE_LOCK_WRITE);
	uint8_t * srcdata = (uint8_t*) pixels;
	uint8_t * dstdata = surfbuf;
	int y, x;
	
	check_format(srcbytes, dstbytes);

	for (y = 0; y <height; y++) {
		dstdata = surfbuf + ((y * width) * dstbytes);
		for (x = 0; x < width; x++) {
			if (srcbytes == 4) {
				if (dstbytes == 4) {
					dstdata[0] = srcdata[3];
					dstdata[3] = srcdata[2];
					dstdata[2] = srcdata[1];
					dstdata[1] = srcdata[0];
				} else if(dstbytes == 1) {
					dstdata[0] = ((int) srcdata[0] + (int) srcdata[1] + (int) srcdata[2] + (int) srcdata[3]) / 3;
				}
					
				srcdata += srcbytes;
				dstdata += dstbytes;
				
			} else if (srcbytes == 3) {
				if (dstbytes == 4) {		
					dstdata[0] = 0xff;
					dstdata[3] = srcdata[2];
					dstdata[2] = srcdata[1];
					dstdata[1] = srcdata[0];
				} else if (dstbytes == 1) {
					dstdata[0] = ((int) srcdata[0] + (int) srcdata[1] + (int) srcdata[2]) / 3;
				}
					
				srcdata += srcbytes;
				dstdata += dstbytes;
			} else if (srcbytes == 1) {
				if (dstbytes == 1) {
					dstdata[0] = srcdata[0];
				} else if (dstbytes == 4) {
					dstdata[0] = srcdata[0];
					dstdata[1] = srcdata[0];
					dstdata[2] = srcdata[0];
					dstdata[3] = srcdata[0];
				}
				srcdata += srcbytes;
				dstdata += dstbytes;
			}
		}
	}
	MyXeSurfaceUnlock(xe, surf);


	xeTmus[xeCurrentTMU].boundtexture->dirty = 1;
#endif	
	handle_small_surface(surf, NULL);
}
/**
 * Destructor for the GuiImage class.
 */
GuiImage::~GuiImage() {
    if (imgType == IMAGE_COLOR && image)
        Xe_DestroyTexture(g_pVideoDevice,image);
}
Beispiel #6
0
void CreateDisplay(void) {

#ifndef LZX_GUI    
    g_pVideoDevice = &_xe;
    Xe_Init(g_pVideoDevice);
#else

    g_pVideoDevice = getLzxVideoDevice();
#endif
    fb = Xe_GetFramebufferSurface(g_pVideoDevice);
    Xe_SetRenderTarget(g_pVideoDevice, fb);

    /*
        mame HLSL
        struct VS_INPUT
        {
            float4 Position : POSITION;
            float4 Color : COLOR0;
            float2 TexCoord : TEXCOORD0;
        };
     */
    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},
        }
    };

#ifdef MAME_SHADER
    g_pPixelTexturedShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xps_ps_main);
#else
    g_pPixelTexturedShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xps_PS);
#endif
    //g_pPixelTexturedShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) draw_t_p_psu);
    Xe_InstantiateShader(g_pVideoDevice, g_pPixelTexturedShader, 0);

#ifdef MAME_SHADER
    g_pVertexShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xvs_vs_main);
#else
    g_pVertexShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xvs_VS);
#endif
    //g_pVertexShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) draw_v_vsu);
    Xe_InstantiateShader(g_pVideoDevice, g_pVertexShader, 0);
    Xe_ShaderApplyVFetchPatches(g_pVideoDevice, g_pVertexShader, 0, &vbf);

    edram_init(g_pVideoDevice);

    // Create the psxScreen texture
    if (g_pTexture)
        Xe_DestroyTexture(g_pVideoDevice, g_pTexture);

    g_pTexture = Xe_CreateTexture(g_pVideoDevice, psxRealW, psxRealH, 1, XE_FMT_8888 | XE_FMT_ARGB, 0);
    psxScreen = (unsigned char*) Xe_Surface_LockRect(g_pVideoDevice, g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE);
    g_pPitch = g_pTexture->wpitch;
    Xe_Surface_Unlock(g_pVideoDevice, g_pTexture);

    memset(psxScreen, 0, 1024 * 512 * 2);

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

    // top left
    Rect[0].x = x;
    Rect[0].y = y + h;
    Rect[0].u = PsxScreenUv[UvBottom];
    Rect[0].v = PsxScreenUv[UvRight];
    Rect[0].color = 0;

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

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

    // top right
    Rect[3].x = x + w;
    Rect[3].y = y + h;
    Rect[3].u = PsxScreenUv[UvTop];
    ;
    Rect[3].v = PsxScreenUv[UvRight];
    Rect[3].color = 0;

    // bottom left
    Rect[4].x = x;
    Rect[4].y = y;
    Rect[4].u = PsxScreenUv[UvBottom];
    Rect[4].v = PsxScreenUv[UvLeft];
    Rect[4].color = 0;

    // bottom right
    Rect[5].x = x + w;
    Rect[5].y = y;
    Rect[5].u = PsxScreenUv[UvTop];
    Rect[5].v = PsxScreenUv[UvLeft];
    Rect[5].color = 0;

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

    CreateTexture(psxRealW, psxRealH);

    Xe_SetClearColor(g_pVideoDevice, 0);
}