mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2025-02-23 20:01:20 +00:00
Added texture sampler back in. TODO, looks like it sets the filter every time it bind the texture..
This commit is contained in:
parent
c10fea8894
commit
8bb9f64167
7 changed files with 214 additions and 14 deletions
|
@ -41,6 +41,7 @@
|
||||||
|
|
||||||
#include "gles_framebuffer.h"
|
#include "gles_framebuffer.h"
|
||||||
#include "gles_renderer.h"
|
#include "gles_renderer.h"
|
||||||
|
#include "gles_samplers.h"
|
||||||
#include "gles_renderbuffers.h"
|
#include "gles_renderbuffers.h"
|
||||||
#include "hw_clock.h"
|
#include "hw_clock.h"
|
||||||
#include "hw_vrmodes.h"
|
#include "hw_vrmodes.h"
|
||||||
|
@ -274,7 +275,7 @@ void OpenGLFrameBuffer::SetVSync(bool vsync)
|
||||||
|
|
||||||
void OpenGLFrameBuffer::SetTextureFilterMode()
|
void OpenGLFrameBuffer::SetTextureFilterMode()
|
||||||
{
|
{
|
||||||
//if (GLRenderer != nullptr && GLRenderer->mSamplerManager != nullptr) GLRenderer->mSamplerManager->SetTextureFilterMode();
|
if (GLRenderer != nullptr && GLRenderer->mSamplerManager != nullptr) GLRenderer->mSamplerManager->SetTextureFilterMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture(int numchannels)
|
IHardwareTexture *OpenGLFrameBuffer::CreateHardwareTexture(int numchannels)
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
|
|
||||||
#include "hw_cvars.h"
|
#include "hw_cvars.h"
|
||||||
#include "gles_renderer.h"
|
#include "gles_renderer.h"
|
||||||
|
#include "gles_samplers.h"
|
||||||
#include "gles_renderstate.h"
|
#include "gles_renderstate.h"
|
||||||
#include "gles_hwtexture.h"
|
#include "gles_hwtexture.h"
|
||||||
|
|
||||||
|
@ -146,16 +147,6 @@ unsigned int FHardwareTexture::CreateTexture(unsigned char * buffer, int w, int
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
mipmapped = true;
|
mipmapped = true;
|
||||||
}
|
}
|
||||||
if (mipmapped)
|
|
||||||
{
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (texunit > 0) glActiveTexture(GL_TEXTURE0);
|
if (texunit > 0) glActiveTexture(GL_TEXTURE0);
|
||||||
else if (texunit == -1) glBindTexture(GL_TEXTURE_2D, textureBinding);
|
else if (texunit == -1) glBindTexture(GL_TEXTURE_2D, textureBinding);
|
||||||
|
@ -300,7 +291,7 @@ bool FHardwareTexture::BindOrCreate(FTexture *tex, int texunit, int clampmode, i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (forcenofilter && clampmode <= CLAMP_XY) clampmode += CLAMP_NOFILTER - CLAMP_NONE;
|
if (forcenofilter && clampmode <= CLAMP_XY) clampmode += CLAMP_NOFILTER - CLAMP_NONE;
|
||||||
//GLRenderer->mSamplerManager->Bind(texunit, clampmode, 255);
|
GLRenderer->mSamplerManager->Bind(texunit, clampmode, 255);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
#include "gles_renderer.h"
|
#include "gles_renderer.h"
|
||||||
#include "gles_hwtexture.h"
|
#include "gles_hwtexture.h"
|
||||||
#include "gles_renderstate.h"
|
#include "gles_renderstate.h"
|
||||||
|
#include "gles_samplers.h"
|
||||||
#include "gles_renderbuffers.h"
|
#include "gles_renderbuffers.h"
|
||||||
#include "gles_shaderprogram.h"
|
#include "gles_shaderprogram.h"
|
||||||
#include "flatvertices.h"
|
#include "flatvertices.h"
|
||||||
|
@ -87,6 +88,7 @@ void FGLRenderer::Initialize(int width, int height)
|
||||||
mOldFBID = 0;
|
mOldFBID = 0;
|
||||||
|
|
||||||
mShaderManager = new FShaderManager;
|
mShaderManager = new FShaderManager;
|
||||||
|
mSamplerManager = new FSamplerManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
FGLRenderer::~FGLRenderer()
|
FGLRenderer::~FGLRenderer()
|
||||||
|
|
|
@ -45,6 +45,7 @@ public:
|
||||||
int mMirrorCount = 0;
|
int mMirrorCount = 0;
|
||||||
int mPlaneMirrorCount = 0;
|
int mPlaneMirrorCount = 0;
|
||||||
FShaderManager *mShaderManager = nullptr;
|
FShaderManager *mShaderManager = nullptr;
|
||||||
|
FSamplerManager* mSamplerManager = nullptr;
|
||||||
unsigned int mFBID = 0;
|
unsigned int mFBID = 0;
|
||||||
unsigned int mStencilValue = 0;
|
unsigned int mStencilValue = 0;
|
||||||
|
|
||||||
|
|
178
src/common/rendering/gles/gles_samplers.cpp
Normal file
178
src/common/rendering/gles/gles_samplers.cpp
Normal file
|
@ -0,0 +1,178 @@
|
||||||
|
/*
|
||||||
|
** gl_samplers.cpp
|
||||||
|
**
|
||||||
|
** Texture sampler handling
|
||||||
|
**
|
||||||
|
**---------------------------------------------------------------------------
|
||||||
|
** Copyright 2015-2019 Christoph Oelckers
|
||||||
|
** All rights reserved.
|
||||||
|
**
|
||||||
|
** Redistribution and use in source and binary forms, with or without
|
||||||
|
** modification, are permitted provided that the following conditions
|
||||||
|
** are met:
|
||||||
|
**
|
||||||
|
** 1. Redistributions of source code must retain the above copyright
|
||||||
|
** notice, this list of conditions and the following disclaimer.
|
||||||
|
** 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
** notice, this list of conditions and the following disclaimer in the
|
||||||
|
** documentation and/or other materials provided with the distribution.
|
||||||
|
** 3. The name of the author may not be used to endorse or promote products
|
||||||
|
** derived from this software without specific prior written permission.
|
||||||
|
**
|
||||||
|
** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
**---------------------------------------------------------------------------
|
||||||
|
**
|
||||||
|
*/
|
||||||
|
#include "gles_system.h"
|
||||||
|
#include "c_cvars.h"
|
||||||
|
|
||||||
|
#include "hw_cvars.h"
|
||||||
|
|
||||||
|
#include "gles_renderer.h"
|
||||||
|
#include "gles_samplers.h"
|
||||||
|
#include "hw_material.h"
|
||||||
|
#include "i_interface.h"
|
||||||
|
|
||||||
|
namespace OpenGLESRenderer
|
||||||
|
{
|
||||||
|
|
||||||
|
extern TexFilter_s TexFilter[];
|
||||||
|
|
||||||
|
|
||||||
|
FSamplerManager::FSamplerManager()
|
||||||
|
{
|
||||||
|
SetTextureFilterMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
FSamplerManager::~FSamplerManager()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void FSamplerManager::UnbindAll()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t FSamplerManager::Bind(int texunit, int num, int lastval)
|
||||||
|
{
|
||||||
|
|
||||||
|
int filter = sysCallbacks.DisableTextureFilter && sysCallbacks.DisableTextureFilter() ? 0 : gl_texture_filter;
|
||||||
|
|
||||||
|
glActiveTexture(GL_TEXTURE0 + texunit);
|
||||||
|
switch (num)
|
||||||
|
{
|
||||||
|
case CLAMP_NONE:
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
if (lastval >= CLAMP_XY_NOMIP)
|
||||||
|
{
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[filter].minfilter);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CLAMP_X:
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
if (lastval >= CLAMP_XY_NOMIP)
|
||||||
|
{
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[filter].minfilter);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CLAMP_Y:
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
if (lastval >= CLAMP_XY_NOMIP)
|
||||||
|
{
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[filter].minfilter);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CLAMP_XY:
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
if (lastval >= CLAMP_XY_NOMIP)
|
||||||
|
{
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[filter].minfilter);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CLAMP_XY_NOMIP:
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CLAMP_NOFILTER:
|
||||||
|
case CLAMP_NOFILTER_X:
|
||||||
|
case CLAMP_NOFILTER_Y:
|
||||||
|
case CLAMP_NOFILTER_XY:
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CLAMP_CAMTEX:
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FSamplerManager::SetTextureFilterMode()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
GLRenderer->FlushTextures();
|
||||||
|
|
||||||
|
GLint bounds[IHardwareTexture::MAX_TEXTURES];
|
||||||
|
|
||||||
|
// Unbind all
|
||||||
|
for(int i = IHardwareTexture::MAX_TEXTURES-1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0 + i);
|
||||||
|
glGetIntegerv(GL_SAMPLER_BINDING, &bounds[i]);
|
||||||
|
glBindSampler(i, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int filter = sysCallbacks.DisableTextureFilter && sysCallbacks.DisableTextureFilter() ? 0 : gl_texture_filter;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
glSamplerParameteri(mSamplers[i], GL_TEXTURE_MIN_FILTER, TexFilter[filter].minfilter);
|
||||||
|
glSamplerParameteri(mSamplers[i], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
||||||
|
glSamplerParameterf(mSamplers[i], GL_TEXTURE_MAX_ANISOTROPY_EXT, filter > 0? gl_texture_filter_anisotropic : 1.0);
|
||||||
|
}
|
||||||
|
glSamplerParameteri(mSamplers[CLAMP_XY_NOMIP], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter);
|
||||||
|
glSamplerParameteri(mSamplers[CLAMP_XY_NOMIP], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
||||||
|
glSamplerParameteri(mSamplers[CLAMP_CAMTEX], GL_TEXTURE_MIN_FILTER, TexFilter[filter].magfilter);
|
||||||
|
glSamplerParameteri(mSamplers[CLAMP_CAMTEX], GL_TEXTURE_MAG_FILTER, TexFilter[filter].magfilter);
|
||||||
|
for(int i = 0; i < IHardwareTexture::MAX_TEXTURES; i++)
|
||||||
|
{
|
||||||
|
glBindSampler(i, bounds[i]);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
27
src/common/rendering/gles/gles_samplers.h
Normal file
27
src/common/rendering/gles/gles_samplers.h
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
#ifndef __GLES_SAMPLERS_H
|
||||||
|
#define __GLES_SAMPLERS_H
|
||||||
|
|
||||||
|
#include "gles_hwtexture.h"
|
||||||
|
#include "textures.h"
|
||||||
|
|
||||||
|
namespace OpenGLESRenderer
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
class FSamplerManager
|
||||||
|
{
|
||||||
|
void UnbindAll();
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
FSamplerManager();
|
||||||
|
~FSamplerManager();
|
||||||
|
|
||||||
|
uint8_t Bind(int texunit, int num, int lastval);
|
||||||
|
void SetTextureFilterMode();
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue