My code for different graphics mode, Shine please look.

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
youresam
Posts: 87
Joined: Sun Nov 06, 2005 1:43 am

My code for different graphics mode, Shine please look.

Post by youresam »

Alright, I have been wanting the low graphics mode for a while now, and I figure if I paste the code I can think of here, you might add it.

Alright, heres the deal... for some reason, my compiler doesnt work well with luaplayer. Although I can compile it, it crashes on exit.

So, heres some sample code:

Add to luasystem.cpp right before the get current directory function.

Code: Select all

static int highGraphicsMode = 1;
Add these functions.

Code: Select all

static int lua_highGraphics(lua_State *L)
{
	if (lua_gettop(L) != 0) return luaL_error(L, "no arguments expected");
	if (highGraphicsMode) return 0;
	highGraphicsMode = 0;
	return 0;
}

static int lua_lowGraphics(lua_State *L)
{
	if (lua_gettop(L) != 0) return luaL_error(L, "no arguments expected");
	if (!highGraphicsMode) return 0;
	highGraphicsMode = 1;
	return 0;
}
Add this to the bottom with the list. (After the sleep function)

Code: Select all

  {"lowGraphicsMode",               lua_lowGraphics},
  {"highGraphicsMode",              lua_highGraphics},
Add this to graphics.cpp.

Code: Select all

void blitImageToScreen(int sx, int sy, int width, int height, Image* source, int dx, int dy)
{
	if (!initialized) return;
	Color* vram = getVramDrawBuffer();
	sceKernelDcacheWritebackInvalidateAll();
	guStart();
	if (highGraphicsMode) sceGuCopyImage(GU_PSM_8888, sx, sy, width, height, source->textureWidth, source->data, dx, dy, PSP_LINE_SIZE, vram);
	if (!highGraphicsMode) sceGuCopyImage(GU_PSM_5551, sx, sy, width, height, source->textureWidth, source->data, dx, dy, PSP_LINE_SIZE, vram);
	sceGuFinish();
	sceGuSync(0,0);
}




However, Im not sure about:
sceGuDrawBuffer(GU_PSM_8888, (void*)FRAMEBUFFER_SIZE, PSP_LINE_SIZE);

...

sceGuTexMode(GU_PSM_8888, 0, 0, 0);

Dont know much about what that does....
So, if someone could test this out, that would be great, thanks!
Dr. Vegetable
Posts: 171
Joined: Mon Nov 14, 2005 1:32 am
Location: Boston, Massachusetts
Contact:

Post by Dr. Vegetable »

No offense, but did you actually test this code?

Code: Select all

static int lua_highGraphics(lua_State *L) 
{ 
   if (lua_gettop(L) != 0) return luaL_error(L, "no arguments expected"); 
   if (highGraphicsMode) return 0; 
   // This point only reached if highGraphicsMode is already zero!
   highGraphicsMode = 0; 
   return 0; 
} 

static int lua_lowGraphics(lua_State *L) 
{ 
   if (lua_gettop(L) != 0) return luaL_error(L, "no arguments expected"); 
   if (!highGraphicsMode) return 0; 
   // This point only reached if highGraphicsMode is already non-zero!
   highGraphicsMode = 1; 
   return 0; 
}
It looks to me like these two functions are backwards. Shouldn't lua_highGraphics() set highGraphicsMode = 1 and lua_lowGraphics() clear highGraphicsMode = 0; ?

Or better yet:

Code: Select all

static int lua_highGraphics(lua_State *L) 
{ 
   if (lua_gettop(L) != 0) return luaL_error(L, "no arguments expected"); 
   highGraphicsMode = 1; 
   return 0; 
} 

static int lua_lowGraphics(lua_State *L) 
{ 
   if (lua_gettop(L) != 0) return luaL_error(L, "no arguments expected"); 
   highGraphicsMode = 0; 
   return 0; 
}
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Re: My code for different graphics mode, Shine please look.

Post by Shine »

youresam wrote:Alright, I have been wanting the low graphics mode for a while now, and I figure if I paste the code I can think of here, you might add it.
For full support of 2 graphics modes you'll need to change nearly every position where "Color" is used. This would be easier with a C++ template class, where the template parameter is the color type and u16 or u32 and some traits class for parametrizing the different code, where needed. But I think it would be better to concentrate on integrating pspgl, like suggested in another thread in this forum by me again, then you'll have every possible pixelformat and existing functions may be faster (beause of multiple graphics buffer pipelines in pspgl and other optimized code).

I've still no time this and next week for Lua Player, so if someone wants to implement it, I can test it and commit to SVN repository.
youresam
Posts: 87
Joined: Sun Nov 06, 2005 1:43 am

Post by youresam »

to dr. vegitable:
Yeah, I got those backwards... like I said, untested.

to Shine:
Alright, well, I dont have time to compile it, either. So, like you said, anyone who can, please test it.

Thanks
Post Reply