mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-05-08 03:28:12 +03:00
s/fmv: use square power-of-2 sized textures
This commit is contained in:
parent
fd080ea3f6
commit
c79ee7bdd8
2 changed files with 30 additions and 17 deletions
|
@ -10,7 +10,6 @@ namespace ddraw {
|
||||||
Renderer::Renderer()
|
Renderer::Renderer()
|
||||||
: m_surfaceBuffer(GL_ARRAY_BUFFER)
|
: m_surfaceBuffer(GL_ARRAY_BUFFER)
|
||||||
{
|
{
|
||||||
// configure buffer
|
|
||||||
m_surfaceBuffer.bind();
|
m_surfaceBuffer.bind();
|
||||||
GLfloat verts[] = { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0,
|
GLfloat verts[] = { 0.0, 0.0, 1.0, 0.0, 0.0, 1.0,
|
||||||
0.0, 1.0, 1.0, 0.0, 1.0, 1.0 };
|
0.0, 1.0, 1.0, 0.0, 1.0, 1.0 };
|
||||||
|
@ -19,9 +18,7 @@ Renderer::Renderer()
|
||||||
m_surfaceFormat.bind();
|
m_surfaceFormat.bind();
|
||||||
m_surfaceFormat.attribute(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
m_surfaceFormat.attribute(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
|
||||||
|
|
||||||
// configure sampler
|
GLint filterMethodEnum = GL_LINEAR;
|
||||||
// TODO: make me configurable
|
|
||||||
GLint filterMethodEnum = GL_LINEAR; // GL_NEAREST
|
|
||||||
|
|
||||||
m_sampler.bind(0);
|
m_sampler.bind(0);
|
||||||
m_sampler.parameteri(GL_TEXTURE_MAG_FILTER, filterMethodEnum);
|
m_sampler.parameteri(GL_TEXTURE_MAG_FILTER, filterMethodEnum);
|
||||||
|
@ -29,7 +26,6 @@ Renderer::Renderer()
|
||||||
m_sampler.parameteri(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
m_sampler.parameteri(GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
|
||||||
m_sampler.parameteri(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
m_sampler.parameteri(GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
|
||||||
|
|
||||||
// configure shaders
|
|
||||||
std::string basePath = m_context.getBasePath();
|
std::string basePath = m_context.getBasePath();
|
||||||
m_program.attach(gl::Shader(GL_VERTEX_SHADER)
|
m_program.attach(gl::Shader(GL_VERTEX_SHADER)
|
||||||
.fromFile(basePath + "\\shaders\\ddraw.vsh"));
|
.fromFile(basePath + "\\shaders\\ddraw.vsh"));
|
||||||
|
|
|
@ -304,6 +304,16 @@ static int S_FMV_PacketQueuePutPrivate(PacketQueue *q, AVPacket *pkt)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int S_FMV_NextPowerOf2(int dim)
|
||||||
|
{
|
||||||
|
int power = 2;
|
||||||
|
dim--;
|
||||||
|
while (dim >>= 1) {
|
||||||
|
power <<= 1;
|
||||||
|
}
|
||||||
|
return power;
|
||||||
|
}
|
||||||
|
|
||||||
static int S_FMV_PacketQueuePut(PacketQueue *q, AVPacket *pkt)
|
static int S_FMV_PacketQueuePut(PacketQueue *q, AVPacket *pkt)
|
||||||
{
|
{
|
||||||
AVPacket *pkt1;
|
AVPacket *pkt1;
|
||||||
|
@ -695,10 +705,18 @@ static void S_FMV_DecoderAbort(Decoder *d, FrameQueue *fq)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int S_FMV_ReallocPrimarySurface(
|
static int S_FMV_ReallocPrimarySurface(
|
||||||
VideoState *is, int new_width, int new_height, bool clear)
|
VideoState *is, int frame_width, int frame_height, bool clear)
|
||||||
{
|
{
|
||||||
if (is->primary_surface && is->surface_width == new_width
|
int surface_width = S_FMV_NextPowerOf2(frame_width);
|
||||||
&& is->surface_height == new_height) {
|
int surface_height = S_FMV_NextPowerOf2(frame_height);
|
||||||
|
if (surface_width < surface_height) {
|
||||||
|
surface_width = surface_height;
|
||||||
|
} else {
|
||||||
|
surface_height = surface_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is->primary_surface && is->surface_width == surface_width
|
||||||
|
&& is->surface_height == surface_height) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -711,8 +729,8 @@ static int S_FMV_ReallocPrimarySurface(
|
||||||
memset(&surface_desc, 0, sizeof(surface_desc));
|
memset(&surface_desc, 0, sizeof(surface_desc));
|
||||||
surface_desc.dwFlags =
|
surface_desc.dwFlags =
|
||||||
DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
|
DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
|
||||||
surface_desc.dwWidth = new_width;
|
surface_desc.dwWidth = surface_width;
|
||||||
surface_desc.dwHeight = new_height;
|
surface_desc.dwHeight = surface_height;
|
||||||
surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP;
|
surface_desc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP;
|
||||||
surface_desc.dwBackBufferCount = 1;
|
surface_desc.dwBackBufferCount = 1;
|
||||||
HRESULT result = MyIDirectDraw2_CreateSurface(
|
HRESULT result = MyIDirectDraw2_CreateSurface(
|
||||||
|
@ -734,16 +752,15 @@ static int S_FMV_ReallocPrimarySurface(
|
||||||
LOG_ERROR("DirectDraw error code 0x%lx", result);
|
LOG_ERROR("DirectDraw error code 0x%lx", result);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
memset(surface_desc.lpSurface, 0, surface_desc.lPitch * new_height);
|
memset(surface_desc.lpSurface, 0, surface_desc.lPitch * surface_height);
|
||||||
MyIDirectDrawSurface2_Unlock(
|
MyIDirectDrawSurface2_Unlock(
|
||||||
is->primary_surface, surface_desc.lpSurface);
|
is->primary_surface, surface_desc.lpSurface);
|
||||||
}
|
}
|
||||||
|
|
||||||
is->surface_width = new_width;
|
is->surface_width = surface_width;
|
||||||
is->surface_height = new_height;
|
is->surface_height = surface_height;
|
||||||
|
|
||||||
result = MyIDirectDraw_SetDisplayMode(
|
result = MyIDirectDraw_SetDisplayMode(g_DDraw, frame_width, frame_height);
|
||||||
g_DDraw, is->surface_width, is->surface_height);
|
|
||||||
if (result != DD_OK) {
|
if (result != DD_OK) {
|
||||||
LOG_ERROR("DirectDraw error code 0x%lx", result);
|
LOG_ERROR("DirectDraw error code 0x%lx", result);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -790,8 +807,8 @@ static int S_FMV_UploadTexture(VideoState *is, AVFrame *frame)
|
||||||
|
|
||||||
is->img_convert_ctx = sws_getCachedContext(
|
is->img_convert_ctx = sws_getCachedContext(
|
||||||
is->img_convert_ctx, frame->width, frame->height, frame->format,
|
is->img_convert_ctx, frame->width, frame->height, frame->format,
|
||||||
frame->width, frame->height, AV_PIX_FMT_BGRA, SWS_BICUBIC, NULL, NULL,
|
is->surface_width, is->surface_height, AV_PIX_FMT_BGRA, SWS_BICUBIC,
|
||||||
NULL);
|
NULL, NULL, NULL);
|
||||||
|
|
||||||
if (is->img_convert_ctx) {
|
if (is->img_convert_ctx) {
|
||||||
DDSURFACEDESC surface_desc;
|
DDSURFACEDESC surface_desc;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue