subrast example

This commit is contained in:
aap
2021-03-03 16:43:20 +01:00
parent d13bd898fe
commit 47487afc04
12 changed files with 1065 additions and 53 deletions

View File

@@ -128,8 +128,16 @@ Charset::flushBuffer(void)
rw::SetRenderState(rw::TEXTUREADDRESS, rw::Texture::WRAP);
rw::SetRenderState(rw::TEXTUREFILTER, rw::Texture::NEAREST);
uint32 cull = rw::GetRenderState(rw::CULLMODE);
uint32 ztest = rw::GetRenderState(rw::ZTESTENABLE);
rw::SetRenderState(rw::CULLMODE, rw::CULLNONE);
rw::SetRenderState(rw::ZTESTENABLE, 0);
im2d::RenderIndexedPrimitive(rw::PRIMTYPETRILIST,
vertices, numChars*4, indices, numChars*6);
rw::SetRenderState(rw::CULLMODE, cull);
rw::SetRenderState(rw::ZTESTENABLE, ztest);
}
numChars = 0;

View File

@@ -18,7 +18,7 @@
namespace rw {
namespace d3d {
bool32 isP8supported = 1;
bool32 isP8supported = 1; // set to 0 when actual d3d device is used
// stolen from d3d8to9
static uint32

View File

@@ -944,6 +944,9 @@ setRenderSurfaces(Camera *cam)
Raster *fbuf = cam->frameBuffer;
assert(fbuf);
{
if(fbuf->parent)
fbuf = fbuf->parent;
D3dRaster *natras = GETD3DRASTEREXT(fbuf);
assert(fbuf->type == Raster::CAMERA || fbuf->type == Raster::CAMERATEXTURE);
if(natras->texture == nil)
@@ -959,6 +962,9 @@ setRenderSurfaces(Camera *cam)
Raster *zbuf = cam->zBuffer;
if(zbuf){
if(zbuf->parent)
zbuf = zbuf->parent;
D3dRaster *natras = GETD3DRASTEREXT(zbuf);
assert(zbuf->type == Raster::ZBUFFER);
setDepthSurface(natras->texture);
@@ -967,6 +973,19 @@ setRenderSurfaces(Camera *cam)
}
static void
setViewport(Raster *fb)
{
D3DVIEWPORT9 vp;
vp.MinZ = 0.0f;
vp.MaxZ = 1.0f;
vp.X = fb->offsetX;
vp.Y = fb->offsetY;
vp.Width = fb->width;
vp.Height = fb->height;
d3ddevice->SetViewport(&vp);
}
static void
beginUpdate(Camera *cam)
{
@@ -1046,23 +1065,14 @@ beginUpdate(Camera *cam)
setRenderSurfaces(cam);
D3DVIEWPORT9 vp;
vp.MinZ = 0.0f;
vp.MaxZ = 1.0f;
vp.X = cam->frameBuffer->offsetX;
vp.Y = cam->frameBuffer->offsetY;
vp.Width = cam->frameBuffer->width;
vp.Height = cam->frameBuffer->height;
d3ddevice->SetViewport(&vp);
setViewport(cam->frameBuffer);
// TODO: figure out when to call this
d3ddevice->BeginScene();
}
static void
endUpdate(Camera *cam)
{
// TODO: figure out when to call this
d3ddevice->EndScene();
}
@@ -1314,7 +1324,6 @@ clearCamera(Camera *cam, RGBA *col, uint32 mode)
RECT r;
GetClientRect(d3d9Globals.window, &r);
BOOL icon = IsIconic(d3d9Globals.window);
Raster *ras = cam->frameBuffer;
if(!icon &&
(r.right != d3d9Globals.present.BackBufferWidth || r.bottom != d3d9Globals.present.BackBufferHeight)){
@@ -1328,7 +1337,8 @@ clearCamera(Camera *cam, RGBA *col, uint32 mode)
setRenderSurfaces(cam);
d3ddevice->Clear(0, 0, mode, c, 1.0f, 0);
setViewport(cam->frameBuffer); // need to set this for the clear to work correctly
d3ddevice->Clear(0, nil, mode, c, 1.0f, 0);
}
static void
@@ -1604,6 +1614,8 @@ startD3D(void)
// d3d9Globals.present.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
d3d9Globals.present.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
rw::d3d::isP8supported = 0;
assert(d3d::d3ddevice == nil);
BOOL icon = IsIconic(d3d9Globals.window);

View File

@@ -1225,6 +1225,50 @@ setFrameBuffer(Camera *cam)
}
}
static Rect
getFramebufferRect(Raster *frameBuffer)
{
Rect r;
Raster *fb = frameBuffer->parent;
if(fb->type == Raster::CAMERA){
#ifdef LIBRW_SDL2
SDL_GetWindowSize(glGlobals.window, &r.w, &r.h);
#else
glfwGetFramebufferSize(glGlobals.window, &r.w, &r.h);
#endif
}else{
r.w = fb->width;
r.h = fb->height;
}
r.x = 0;
r.y = 0;
// Got a subraster
if(frameBuffer != fb){
r.x = frameBuffer->offsetX;
// GL y offset is from bottom
r.y = r.h - frameBuffer->height - frameBuffer->offsetY;
r.w = frameBuffer->width;
r.h = frameBuffer->height;
}
return r;
}
static void
setViewport(Raster *frameBuffer)
{
Rect r = getFramebufferRect(frameBuffer);
if(r.w != glGlobals.presentWidth || r.h != glGlobals.presentHeight ||
r.x != glGlobals.presentOffX || r.y != glGlobals.presentOffY){
glViewport(r.x, r.y, r.w, r.h);
glGlobals.presentWidth = r.w;
glGlobals.presentHeight = r.h;
glGlobals.presentOffX = r.x;
glGlobals.presentOffY = r.y;
}
}
static void
beginUpdate(Camera *cam)
{
@@ -1279,10 +1323,10 @@ beginUpdate(Camera *cam)
proj[14] = -2.0f*cam->nearPlane*cam->farPlane*invz;
proj[15] = 0.0f;
}else{
proj[10] = -(cam->farPlane+cam->nearPlane)*invz;
proj[10] = 2.0f*invz;
proj[11] = 0.0f;
proj[14] = 2.0f*invz;
proj[14] = -(cam->farPlane+cam->nearPlane)*invz;
proj[15] = 1.0f;
}
memcpy(&cam->devProj, &proj, sizeof(RawMatrix));
@@ -1301,39 +1345,7 @@ beginUpdate(Camera *cam)
setFrameBuffer(cam);
int w, h;
int x, y;
Raster *fb = cam->frameBuffer->parent;
if(fb->type == Raster::CAMERA){
#ifdef LIBRW_SDL2
SDL_GetWindowSize(glGlobals.window, &w, &h);
#else
glfwGetFramebufferSize(glGlobals.window, &w, &h);
#endif
}else{
w = fb->width;
h = fb->height;
}
x = 0;
y = 0;
// Got a subraster
if(cam->frameBuffer != fb){
x = cam->frameBuffer->offsetX;
// GL y offset is from bottom
y = h - cam->frameBuffer->height - cam->frameBuffer->offsetY;
w = cam->frameBuffer->width;
h = cam->frameBuffer->height;
}
if(w != glGlobals.presentWidth || h != glGlobals.presentHeight ||
x != glGlobals.presentOffX || y != glGlobals.presentOffY){
glViewport(x, y, w, h);
glGlobals.presentWidth = w;
glGlobals.presentHeight = h;
glGlobals.presentOffX = x;
glGlobals.presentOffY = y;
}
setViewport(cam->frameBuffer);
}
static void
@@ -1349,6 +1361,15 @@ clearCamera(Camera *cam, RGBA *col, uint32 mode)
setFrameBuffer(cam);
// make sure we're only clearing the part of the framebuffer
// that is subrastered
bool setScissor = cam->frameBuffer != cam->frameBuffer->parent;
if(setScissor){
Rect r = getFramebufferRect(cam->frameBuffer);
glScissor(r.x, r.y, r.w, r.h);
glEnable(GL_SCISSOR_TEST);
}
convColor(&colf, col);
glClearColor(colf.red, colf.green, colf.blue, colf.alpha);
mask = 0;
@@ -1361,12 +1382,17 @@ clearCamera(Camera *cam, RGBA *col, uint32 mode)
glDepthMask(GL_TRUE);
glClear(mask);
glDepthMask(rwStateCache.zwrite);
if(setScissor)
glDisable(GL_SCISSOR_TEST);
}
static void
showRaster(Raster *raster, uint32 flags)
{
// TODO: do this properly!
// glViewport(raster->offsetX, raster->offsetY,
// raster->width, raster->height);
#ifdef LIBRW_SDL2
if(flags & Raster::FLIPWAITVSYNCH)
SDL_GL_SetSwapInterval(1);
@@ -1746,8 +1772,8 @@ initOpenGL(void)
// printf("%d %s\n", i, ext);
}
*/
gl3Caps.dxtSupported = GLAD_GL_EXT_texture_compression_s3tc;
gl3Caps.astcSupported = GLAD_GL_KHR_texture_compression_astc_ldr;
gl3Caps.dxtSupported = !!GLAD_GL_EXT_texture_compression_s3tc;
gl3Caps.astcSupported = !!GLAD_GL_KHR_texture_compression_astc_ldr;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl3Caps.maxAnisotropy);

View File

@@ -87,8 +87,8 @@ Raster::subRaster(Raster *parent, Rect *r)
return;
this->width = r->w;
this->height = r->h;
this->offsetX += r->x;
this->offsetY += r->y;
this->offsetX = parent->offsetX + r->x;
this->offsetY = parent->offsetY + r->y;
this->parent = parent->parent;
}