mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/4jcraft.git
synced 2026-09-23 10:42:46 +00:00
attempt to clean up renderer
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
#include "IPlatformLeaderboard.h"
|
||||
#include "IPlatformNetwork.h"
|
||||
#include "IPlatformProfile.h"
|
||||
#include "IPlatformRenderer.h"
|
||||
#include "platform/renderer/renderer.h"
|
||||
#include "IPlatformSound.h"
|
||||
#include "IPlatformStorage.h"
|
||||
#include "IPlatformUIController.h"
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
#include "PlatformServices.h"
|
||||
#include "StdFileIO.h"
|
||||
|
||||
#include "sdl2/Render.h"
|
||||
|
||||
static StdFileIO s_stdFileIO;
|
||||
|
||||
IPlatformFileIO& PlatformFileIO = s_stdFileIO;
|
||||
IPlatformRenderer& PlatformRender = RenderManager;
|
||||
IPlatformFileIO& PlatformFileIO = s_stdFileIO;
|
||||
@@ -3,11 +3,9 @@
|
||||
#include "IPlatformFileIO.h"
|
||||
#include "IPlatformLeaderboard.h"
|
||||
#include "IPlatformNetwork.h"
|
||||
#include "IPlatformRenderer.h"
|
||||
|
||||
// Interface references to platform services. Game code uses these
|
||||
// instead of concrete globals directly. Bindings are established
|
||||
// by the app layer at startup.
|
||||
|
||||
extern IPlatformFileIO& PlatformFileIO;
|
||||
extern IPlatformRenderer& PlatformRender;
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "../InputConstants.h"
|
||||
#include "../PlatformTypes.h"
|
||||
#include "../../PlatformTypes.h"
|
||||
|
||||
SDL2Input sdl2_input_instance;
|
||||
IPlatformInput& PlatformInput = sdl2_input_instance;
|
||||
|
||||
@@ -28,14 +28,14 @@ sdl2_sources = files(
|
||||
'input/sdl2/SDL2Input.cpp',
|
||||
'profile/stub/StubProfile.cpp',
|
||||
'storage/stub/StubStorage.cpp',
|
||||
'sdl2/Render.cpp',
|
||||
'sdl2/render_stubs.cpp',
|
||||
'renderer/gl/GLRenderer.cpp',
|
||||
'renderer/gl/render_stubs.cpp',
|
||||
)
|
||||
|
||||
lib_platform_sdl2 = static_library('platform_sdl2',
|
||||
sdl2_sources,
|
||||
include_directories: [platform_inc, include_directories('sdl2')],
|
||||
dependencies: [_sdl2, _gl, _threads, glm_dep, stb_dep],
|
||||
include_directories: [platform_inc],
|
||||
dependencies: [_sdl2, _gl, _threads, glm_dep, stb_dep, java_dep],
|
||||
cpp_args: _defs + global_cpp_args + global_cpp_defs,
|
||||
)
|
||||
|
||||
@@ -43,7 +43,7 @@ lib_platform_sdl2 = static_library('platform_sdl2',
|
||||
# Replaces the old render_dep, input_dep, profile_dep, storage_dep
|
||||
render_dep = declare_dependency(
|
||||
link_with: lib_platform_sdl2,
|
||||
include_directories: [platform_inc, include_directories('sdl2')],
|
||||
include_directories: [platform_inc],
|
||||
dependencies: [_sdl2, _gl, _threads, glm_dep],
|
||||
)
|
||||
input_dep = render_dep
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include "../PlatformTypes.h"
|
||||
#include "PlatformTypes.h"
|
||||
|
||||
#include "../IPlatformProfile.h"
|
||||
#include "../PlatformTypes.h"
|
||||
|
||||
class StubProfile : public IPlatformProfile {
|
||||
public:
|
||||
|
||||
@@ -95,6 +95,7 @@ public:
|
||||
virtual void CBuffLockStaticCreations() = 0;
|
||||
[[nodiscard]] virtual int CBuffCreate(int count) = 0;
|
||||
virtual void CBuffDelete(int first, int count) = 0;
|
||||
virtual void CBuffDeleteAll() = 0;
|
||||
virtual void CBuffStart(int index, bool full = false) = 0;
|
||||
virtual void CBuffClear(int index) = 0;
|
||||
[[nodiscard]] virtual int CBuffSize(int index) = 0;
|
||||
@@ -1,12 +1,15 @@
|
||||
#include "Render.h"
|
||||
#include "GLRenderer.h"
|
||||
|
||||
#include "../PlatformTypes.h"
|
||||
#include "PlatformTypes.h"
|
||||
#include "SDL.h"
|
||||
#include "SDL_error.h"
|
||||
#include "SDL_events.h"
|
||||
#include "SDL_stdinc.h"
|
||||
#include "SDL_video.h"
|
||||
#include "gl3_loader.h"
|
||||
|
||||
#include "java/ByteBuffer.h"
|
||||
#include "java/FloatBuffer.h"
|
||||
#include "java/IntBuffer.h"
|
||||
|
||||
// undefine macros from header to avoid argument mismatch
|
||||
#undef glGenTextures
|
||||
@@ -51,7 +54,8 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
C4JRender RenderManager;
|
||||
GLRenderer gl_renderer_instance;
|
||||
IPlatformRenderer& PlatformRenderer = gl_renderer_instance;
|
||||
|
||||
// MARK: Shaders
|
||||
|
||||
@@ -59,20 +63,20 @@ C4JRender RenderManager;
|
||||
|
||||
#ifdef GLES
|
||||
static const char* VERT_SRC =
|
||||
#include "sdl2/shaders/vertex_es.vert"
|
||||
#include "./shaders/vertex_es.vert"
|
||||
|
||||
;
|
||||
static const char* FRAG_SRC =
|
||||
#include "sdl2/shaders/fragment_es.frag"
|
||||
#include "./shaders/fragment_es.frag"
|
||||
|
||||
;
|
||||
#else
|
||||
static const char* VERT_SRC =
|
||||
#include "sdl2/shaders/vertex.vert"
|
||||
#include "./shaders/vertex.vert"
|
||||
|
||||
;
|
||||
static const char* FRAG_SRC =
|
||||
#include "sdl2/shaders/fragment.frag"
|
||||
#include "./shaders/fragment.frag"
|
||||
;
|
||||
#endif
|
||||
|
||||
@@ -593,7 +597,7 @@ static thread_local std::vector<ChunkDrawCall> s_recDraws;
|
||||
// Primitive helpers
|
||||
static bool isQuadPrim(int pt) {
|
||||
return (pt == 0x0007 /*GL_QUADS*/ ||
|
||||
pt == (int)C4JRender::PRIMITIVE_TYPE_QUAD_LIST);
|
||||
pt == (int)GLRenderer::PRIMITIVE_TYPE_QUAD_LIST);
|
||||
}
|
||||
|
||||
static GLenum mapPrim(int pt) {
|
||||
@@ -621,7 +625,7 @@ static GLenum mapPrim(int pt) {
|
||||
// MARK: Renderer impl
|
||||
|
||||
// Initialises the renderer
|
||||
void C4JRender::Initialise() {
|
||||
void GLRenderer::Initialise() {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
|
||||
fprintf(stderr, "[4J_Render] SDL_Init: %s\n", SDL_GetError());
|
||||
return;
|
||||
@@ -712,7 +716,7 @@ void C4JRender::Initialise() {
|
||||
#endif
|
||||
}
|
||||
|
||||
void C4JRender::InitialiseContext() {
|
||||
void GLRenderer::InitialiseContext() {
|
||||
if (!s_window) return;
|
||||
pthread_once(&s_glCtxKeyOnce, makeGLCtxKey);
|
||||
if (s_mainThreadSet && pthread_equal(pthread_self(), s_mainThread)) {
|
||||
@@ -742,7 +746,7 @@ void C4JRender::InitialiseContext() {
|
||||
pthread_setspecific(s_glCtxKey, (void*)shared);
|
||||
}
|
||||
|
||||
void C4JRender::StartFrame() {
|
||||
void GLRenderer::StartFrame() {
|
||||
Set_matrixDirty();
|
||||
int w, h;
|
||||
SDL_GetWindowSize(s_window, &w, &h);
|
||||
@@ -751,7 +755,7 @@ void C4JRender::StartFrame() {
|
||||
glViewport(0, 0, s_windowWidth, s_windowHeight);
|
||||
}
|
||||
|
||||
void C4JRender::Present() {
|
||||
void GLRenderer::Present() {
|
||||
if (!s_window) return;
|
||||
SDL_Event ev;
|
||||
while (SDL_PollEvent(&ev)) {
|
||||
@@ -768,23 +772,23 @@ void C4JRender::Present() {
|
||||
SDL_GL_SwapWindow(s_window);
|
||||
}
|
||||
|
||||
void C4JRender::SetWindowSize(int w, int h) {
|
||||
void GLRenderer::SetWindowSize(int w, int h) {
|
||||
s_reqWidth = w;
|
||||
s_reqHeight = h;
|
||||
}
|
||||
|
||||
void C4JRender::SetFullscreen(bool fs) { s_fullscreen = fs; }
|
||||
void GLRenderer::SetFullscreen(bool fs) { s_fullscreen = fs; }
|
||||
|
||||
bool C4JRender::ShouldClose() { return !s_window || s_shouldClose; }
|
||||
bool GLRenderer::ShouldClose() { return !s_window || s_shouldClose; }
|
||||
|
||||
void C4JRender::GetFramebufferSize(int& w, int& h) {
|
||||
void GLRenderer::GetFramebufferSize(int& w, int& h) {
|
||||
w = s_windowWidth;
|
||||
h = s_windowHeight;
|
||||
}
|
||||
|
||||
void C4JRender::Close() { s_window = nullptr; }
|
||||
void GLRenderer::Close() { s_window = nullptr; }
|
||||
|
||||
void C4JRender::Shutdown() {
|
||||
void GLRenderer::Shutdown() {
|
||||
pthread_mutex_lock(&s_glCallMtx);
|
||||
for (auto& kv : s_chunkPool) kv.second.destroy();
|
||||
s_chunkPool.clear();
|
||||
@@ -807,7 +811,7 @@ void C4JRender::Shutdown() {
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void C4JRender::DrawVertices(ePrimitiveType ptype, int count, void* dataIn,
|
||||
void GLRenderer::DrawVertices(ePrimitiveType ptype, int count, void* dataIn,
|
||||
eVertexType vType, ePixelShaderType) {
|
||||
if (count <= 0 || !dataIn) return;
|
||||
|
||||
@@ -915,14 +919,14 @@ void C4JRender::DrawVertices(ePrimitiveType ptype, int count, void* dataIn,
|
||||
pthread_mutex_unlock(&s_glCallMtx);
|
||||
}
|
||||
|
||||
void C4JRender::ReadPixels(int x, int y, int w, int h, void* buf) {
|
||||
void GLRenderer::ReadPixels(int x, int y, int w, int h, void* buf) {
|
||||
if (!buf) return;
|
||||
pthread_mutex_lock(&s_glCallMtx);
|
||||
glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buf);
|
||||
pthread_mutex_unlock(&s_glCallMtx);
|
||||
}
|
||||
|
||||
int C4JRender::CBuffCreate(int count) {
|
||||
int GLRenderer::CBuffCreate(int count) {
|
||||
pthread_mutex_lock(&s_glCallMtx);
|
||||
int b = s_nextListBase;
|
||||
s_nextListBase += count;
|
||||
@@ -930,7 +934,7 @@ int C4JRender::CBuffCreate(int count) {
|
||||
return b;
|
||||
}
|
||||
|
||||
void C4JRender::CBuffDelete(int first, int count) {
|
||||
void GLRenderer::CBuffDelete(int first, int count) {
|
||||
pthread_mutex_lock(&s_glCallMtx);
|
||||
for (int i = first; i < first + count; i++) {
|
||||
auto it = s_chunkPool.find(i);
|
||||
@@ -942,7 +946,7 @@ void C4JRender::CBuffDelete(int first, int count) {
|
||||
pthread_mutex_unlock(&s_glCallMtx);
|
||||
}
|
||||
|
||||
void C4JRender::CBuffDeleteAll() {
|
||||
void GLRenderer::CBuffDeleteAll() {
|
||||
pthread_mutex_lock(&s_glCallMtx);
|
||||
for (auto& kv : s_chunkPool) {
|
||||
kv.second.destroy();
|
||||
@@ -952,13 +956,13 @@ void C4JRender::CBuffDeleteAll() {
|
||||
pthread_mutex_unlock(&s_glCallMtx);
|
||||
}
|
||||
|
||||
void C4JRender::CBuffStart(int index, bool) {
|
||||
void GLRenderer::CBuffStart(int index, bool) {
|
||||
s_recListId = index;
|
||||
s_recVerts.clear();
|
||||
s_recDraws.clear();
|
||||
}
|
||||
|
||||
void C4JRender::CBuffEnd() {
|
||||
void GLRenderer::CBuffEnd() {
|
||||
if (s_recListId < 0) return;
|
||||
pthread_mutex_lock(&s_glCallMtx);
|
||||
ChunkBuffer& cb = s_chunkPool[s_recListId];
|
||||
@@ -977,7 +981,7 @@ void C4JRender::CBuffEnd() {
|
||||
s_recListId = -1;
|
||||
}
|
||||
|
||||
void C4JRender::CBuffClear(int index) {
|
||||
void GLRenderer::CBuffClear(int index) {
|
||||
pthread_mutex_lock(&s_glCallMtx);
|
||||
auto it = s_chunkPool.find(index);
|
||||
if (it != s_chunkPool.end()) {
|
||||
@@ -987,7 +991,7 @@ void C4JRender::CBuffClear(int index) {
|
||||
pthread_mutex_unlock(&s_glCallMtx);
|
||||
}
|
||||
|
||||
bool C4JRender::CBuffCall(int index, bool) {
|
||||
bool GLRenderer::CBuffCall(int index, bool) {
|
||||
pthread_mutex_lock(&s_glCallMtx);
|
||||
auto it = s_chunkPool.find(index);
|
||||
if (it == s_chunkPool.end() || !it->second.valid) {
|
||||
@@ -1026,7 +1030,7 @@ bool C4JRender::CBuffCall(int index, bool) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void C4JRender::MatrixMode(int t) {
|
||||
void GLRenderer::MatrixMode(int t) {
|
||||
if (t == GL_PROJECTION)
|
||||
s_matMode = 1;
|
||||
else if (t == GL_TEXTURE)
|
||||
@@ -1035,53 +1039,53 @@ void C4JRender::MatrixMode(int t) {
|
||||
s_matMode = 0;
|
||||
}
|
||||
|
||||
void C4JRender::MatrixSetIdentity() {
|
||||
void GLRenderer::MatrixSetIdentity() {
|
||||
activeStack().load(glm::mat4(1.f));
|
||||
markMatrixDirty();
|
||||
if (s_matMode == 0) markNormalDirty();
|
||||
}
|
||||
void C4JRender::MatrixPush() {
|
||||
void GLRenderer::MatrixPush() {
|
||||
activeStack().push();
|
||||
// push doesn't change cur() so no dirty needed but mark anyway to be safe
|
||||
// ;w;
|
||||
markMatrixDirty();
|
||||
if (s_matMode == 0) markNormalDirty();
|
||||
}
|
||||
void C4JRender::MatrixPop() {
|
||||
void GLRenderer::MatrixPop() {
|
||||
activeStack().pop();
|
||||
markMatrixDirty();
|
||||
if (s_matMode == 0) markNormalDirty();
|
||||
}
|
||||
void C4JRender::MatrixTranslate(float x, float y, float z) {
|
||||
void GLRenderer::MatrixTranslate(float x, float y, float z) {
|
||||
activeStack().mul(glm::translate(glm::mat4(1.f), {x, y, z}));
|
||||
markMatrixDirty();
|
||||
if (s_matMode == 0) markNormalDirty();
|
||||
}
|
||||
void C4JRender::MatrixRotate(float a, float x, float y, float z) {
|
||||
void GLRenderer::MatrixRotate(float a, float x, float y, float z) {
|
||||
activeStack().mul(glm::rotate(glm::mat4(1.f), a, {x, y, z}));
|
||||
markMatrixDirty();
|
||||
if (s_matMode == 0) markNormalDirty();
|
||||
}
|
||||
void C4JRender::MatrixScale(float x, float y, float z) {
|
||||
void GLRenderer::MatrixScale(float x, float y, float z) {
|
||||
activeStack().mul(glm::scale(glm::mat4(1.f), {x, y, z}));
|
||||
markMatrixDirty();
|
||||
if (s_matMode == 0) markNormalDirty();
|
||||
}
|
||||
void C4JRender::MatrixPerspective(float fovy, float asp, float zn, float zf) {
|
||||
void GLRenderer::MatrixPerspective(float fovy, float asp, float zn, float zf) {
|
||||
s_proj.cur() = glm::perspective(glm::radians(fovy), asp, zn, zf);
|
||||
markMatrixDirty();
|
||||
}
|
||||
void C4JRender::MatrixOrthogonal(float l, float r, float b, float t, float zn,
|
||||
void GLRenderer::MatrixOrthogonal(float l, float r, float b, float t, float zn,
|
||||
float zf) {
|
||||
s_proj.cur() = glm::ortho(l, r, b, t, zn, zf);
|
||||
markMatrixDirty();
|
||||
}
|
||||
void C4JRender::MatrixMult(float* m) {
|
||||
void GLRenderer::MatrixMult(float* m) {
|
||||
activeStack().mul(glm::make_mat4(m));
|
||||
markMatrixDirty();
|
||||
if (s_matMode == 0) markNormalDirty();
|
||||
}
|
||||
const float* C4JRender::MatrixGet(int t) {
|
||||
const float* GLRenderer::MatrixGet(int t) {
|
||||
static float buf[16];
|
||||
glm::mat4* m = (t == GL_MODELVIEW_MATRIX) ? &s_mv.cur()
|
||||
: (t == GL_PROJECTION_MATRIX) ? &s_proj.cur()
|
||||
@@ -1090,7 +1094,7 @@ const float* C4JRender::MatrixGet(int t) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
void C4JRender::Set_matrixDirty() {
|
||||
void GLRenderer::Set_matrixDirty() {
|
||||
// iggy wipes opengl state
|
||||
s_boundProgram = 0;
|
||||
s_rs_dirty_mask = 0xFFFFFFFF;
|
||||
@@ -1104,20 +1108,20 @@ void C4JRender::Set_matrixDirty() {
|
||||
}
|
||||
}
|
||||
|
||||
void C4JRender::Clear(int f) { glClear(f); }
|
||||
void C4JRender::SetClearColour(const float c[4]) {
|
||||
void GLRenderer::Clear(int f) { glClear(f); }
|
||||
void GLRenderer::SetClearColour(const float c[4]) {
|
||||
glClearColor(c[0], c[1], c[2], c[3]);
|
||||
}
|
||||
bool C4JRender::IsWidescreen() { return true; }
|
||||
bool C4JRender::IsHiDef() { return true; }
|
||||
void C4JRender::StateSetColour(float r, float g, float b, float a) {
|
||||
bool GLRenderer::IsWidescreen() { return true; }
|
||||
bool GLRenderer::IsHiDef() { return true; }
|
||||
void GLRenderer::StateSetColour(float r, float g, float b, float a) {
|
||||
glm::vec4 v = {r, g, b, a};
|
||||
if (s_rs.baseColor != v) {
|
||||
s_rs.baseColor = v;
|
||||
markDirty(DIRTY_BASECOLOR);
|
||||
}
|
||||
}
|
||||
void C4JRender::SetChunkOffset(float x, float y, float z) {
|
||||
void GLRenderer::SetChunkOffset(float x, float y, float z) {
|
||||
if (s_shader.uChunkOffset < 0) return;
|
||||
glm::vec3 v = {x, y, z};
|
||||
if (!s_chunkOffsetValid || s_chunkOffset != v) {
|
||||
@@ -1128,111 +1132,111 @@ void C4JRender::SetChunkOffset(float x, float y, float z) {
|
||||
glUniform3f(s_shader.uChunkOffset, x, y, z);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetDepthMask(bool e) {
|
||||
void GLRenderer::StateSetDepthMask(bool e) {
|
||||
glShadowSetDepthMask(e ? GL_TRUE : GL_FALSE);
|
||||
}
|
||||
void C4JRender::StateSetBlendEnable(bool e) { glShadowSetBlend(e); }
|
||||
void C4JRender::StateSetBlendFunc(int s, int d) {
|
||||
void GLRenderer::StateSetBlendEnable(bool e) { glShadowSetBlend(e); }
|
||||
void GLRenderer::StateSetBlendFunc(int s, int d) {
|
||||
glShadowSetBlendFunc(s, d);
|
||||
}
|
||||
void C4JRender::StateSetDepthFunc(int f) { ::glDepthFunc(f); }
|
||||
void C4JRender::StateSetFaceCull(bool e) { glShadowSetCull(e); }
|
||||
void C4JRender::StateSetFaceCullCW(bool e) {
|
||||
void GLRenderer::StateSetDepthFunc(int f) { ::glDepthFunc(f); }
|
||||
void GLRenderer::StateSetFaceCull(bool e) { glShadowSetCull(e); }
|
||||
void GLRenderer::StateSetFaceCullCW(bool e) {
|
||||
glShadowSetFrontFace(e ? GL_CW : GL_CCW);
|
||||
}
|
||||
void C4JRender::StateSetLineWidth(float w) {
|
||||
void GLRenderer::StateSetLineWidth(float w) {
|
||||
#ifndef GLES
|
||||
glShadowSetLineWidth(w);
|
||||
#else
|
||||
(void)w;
|
||||
#endif
|
||||
}
|
||||
void C4JRender::StateSetWriteEnable(bool r, bool g, bool b, bool a) {
|
||||
void GLRenderer::StateSetWriteEnable(bool r, bool g, bool b, bool a) {
|
||||
glShadowSetColorMask(r, g, b, a);
|
||||
}
|
||||
void C4JRender::StateSetDepthTestEnable(bool e) { glShadowSetDepthTest(e); }
|
||||
void C4JRender::StateSetAlphaTestEnable(bool e) {
|
||||
void GLRenderer::StateSetDepthTestEnable(bool e) { glShadowSetDepthTest(e); }
|
||||
void GLRenderer::StateSetAlphaTestEnable(bool e) {
|
||||
float v = e ? 0.1f : 0.f;
|
||||
if (s_rs.alphaRef != v) {
|
||||
s_rs.alphaRef = v;
|
||||
markDirty(DIRTY_ALPHA);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetAlphaFunc(int, float p) {
|
||||
void GLRenderer::StateSetAlphaFunc(int, float p) {
|
||||
if (s_rs.alphaRef != p) {
|
||||
s_rs.alphaRef = p;
|
||||
markDirty(DIRTY_ALPHA);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetDepthSlopeAndBias(float s, float b) {
|
||||
void GLRenderer::StateSetDepthSlopeAndBias(float s, float b) {
|
||||
glShadowSetPolygonOffset(s, b);
|
||||
}
|
||||
void C4JRender::StateSetBlendFactor(unsigned int col) {
|
||||
void GLRenderer::StateSetBlendFactor(unsigned int col) {
|
||||
float a = ((col >> 24) & 0xFF) / 255.f;
|
||||
float r = ((col >> 16) & 0xFF) / 255.f;
|
||||
float g = ((col >> 8) & 0xFF) / 255.f;
|
||||
float b = (col & 0xFF) / 255.f;
|
||||
glBlendColor(r, g, b, a);
|
||||
}
|
||||
void C4JRender::StateSetFogEnable(bool e) {
|
||||
void GLRenderer::StateSetFogEnable(bool e) {
|
||||
if (s_rs.fogEnable != e) {
|
||||
s_rs.fogEnable = e;
|
||||
markDirty(DIRTY_FOG);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetFogMode(int mode) {
|
||||
void GLRenderer::StateSetFogMode(int mode) {
|
||||
int v = (mode == GL_LINEAR) ? 1 : (mode == GL_EXP) ? 2 : (mode == 0x0801) ? 3 : 0;
|
||||
if (s_rs.fogMode != v) {
|
||||
s_rs.fogMode = v;
|
||||
markDirty(DIRTY_FOG);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetFogNearDistance(float d) {
|
||||
void GLRenderer::StateSetFogNearDistance(float d) {
|
||||
if (s_rs.fogStart != d) {
|
||||
s_rs.fogStart = d;
|
||||
markDirty(DIRTY_FOG);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetFogFarDistance(float d) {
|
||||
void GLRenderer::StateSetFogFarDistance(float d) {
|
||||
if (s_rs.fogEnd != d) {
|
||||
s_rs.fogEnd = d;
|
||||
markDirty(DIRTY_FOG);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetFogDensity(float d) {
|
||||
void GLRenderer::StateSetFogDensity(float d) {
|
||||
if (s_rs.fogDensity != d) {
|
||||
s_rs.fogDensity = d;
|
||||
markDirty(DIRTY_FOG);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetFogColour(float r, float g, float b) {
|
||||
void GLRenderer::StateSetFogColour(float r, float g, float b) {
|
||||
glm::vec4 v = {r, g, b, 1};
|
||||
if (s_rs.fogColor != v) {
|
||||
s_rs.fogColor = v;
|
||||
markDirty(DIRTY_FOG);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetLightingEnable(bool e) {
|
||||
void GLRenderer::StateSetLightingEnable(bool e) {
|
||||
if (s_rs.lighting != e) {
|
||||
s_rs.lighting = e;
|
||||
markDirty(DIRTY_LIGHTING);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetLightColour(int, float r, float g, float b) {
|
||||
void GLRenderer::StateSetLightColour(int, float r, float g, float b) {
|
||||
glm::vec3 v = {r, g, b};
|
||||
if (s_rs.ldiff != v) {
|
||||
s_rs.ldiff = v;
|
||||
markDirty(DIRTY_LIGHTING);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetLightAmbientColour(float r, float g, float b) {
|
||||
void GLRenderer::StateSetLightAmbientColour(float r, float g, float b) {
|
||||
glm::vec3 v = {r, g, b};
|
||||
if (s_rs.lamb != v) {
|
||||
s_rs.lamb = v;
|
||||
markDirty(DIRTY_LIGHTING);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetLightDirection(int light, float x, float y, float z) {
|
||||
void GLRenderer::StateSetLightDirection(int light, float x, float y, float z) {
|
||||
glm::vec3 d = glm::normalize(glm::mat3(s_mv.cur()) * glm::vec3(x, y, z));
|
||||
if (light == 0) {
|
||||
if (s_rs.l0 != d) {
|
||||
@@ -1246,44 +1250,44 @@ void C4JRender::StateSetLightDirection(int light, float x, float y, float z) {
|
||||
}
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetViewport(eViewportType) {
|
||||
void GLRenderer::StateSetViewport(eViewportType) {
|
||||
glViewport(0, 0, s_windowWidth, s_windowHeight);
|
||||
}
|
||||
void C4JRender::StateSetVertexTextureUV(float u, float v) {
|
||||
void GLRenderer::StateSetVertexTextureUV(float u, float v) {
|
||||
glm::vec2 val = {u, v};
|
||||
if (s_rs.globalLM != val) {
|
||||
s_rs.globalLM = val;
|
||||
markDirty(DIRTY_GLOBAL_LM);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetStencil(int fn, uint8_t ref, uint8_t fmask,
|
||||
void GLRenderer::StateSetStencil(int fn, uint8_t ref, uint8_t fmask,
|
||||
uint8_t wmask) {
|
||||
glShadowSetStencil(fn, ref, fmask, wmask);
|
||||
}
|
||||
void C4JRender::StateSetTextureEnable(bool e) {
|
||||
void GLRenderer::StateSetTextureEnable(bool e) {
|
||||
if (s_rs.activeTexture == 0 && s_rs.useTexture != e) {
|
||||
s_rs.useTexture = e;
|
||||
markDirty(DIRTY_TEXTURE);
|
||||
}
|
||||
}
|
||||
void C4JRender::StateSetActiveTexture(int tex) {
|
||||
void GLRenderer::StateSetActiveTexture(int tex) {
|
||||
s_rs.activeTexture = (tex == 0x84C1 /*GL_TEXTURE1*/) ? 1 : 0;
|
||||
}
|
||||
|
||||
int C4JRender::TextureCreate() {
|
||||
int GLRenderer::TextureCreate() {
|
||||
GLuint id;
|
||||
glGenTextures(1, &id);
|
||||
return (int)id;
|
||||
}
|
||||
void C4JRender::TextureFree(int i) {
|
||||
void GLRenderer::TextureFree(int i) {
|
||||
GLuint id = (GLuint)i;
|
||||
glDeleteTextures(1, &id);
|
||||
}
|
||||
void C4JRender::TextureBind(int idx) {
|
||||
void GLRenderer::TextureBind(int idx) {
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, idx < 0 ? 0 : (GLuint)idx);
|
||||
}
|
||||
void C4JRender::TextureBindVertex(int idx, bool scaleLight) {
|
||||
void GLRenderer::TextureBindVertex(int idx, bool scaleLight) {
|
||||
if (idx < 0) {
|
||||
if (s_rs.useLightmap) {
|
||||
s_rs.useLightmap = false;
|
||||
@@ -1311,7 +1315,7 @@ void C4JRender::TextureBindVertex(int idx, bool scaleLight) {
|
||||
markDirty(DIRTY_LMT);
|
||||
}
|
||||
}
|
||||
void C4JRender::TextureSetTextureLevels(int l) {
|
||||
void GLRenderer::TextureSetTextureLevels(int l) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, l > 0 ? l - 1 : 0);
|
||||
if (l > 1)
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
|
||||
@@ -1319,8 +1323,8 @@ void C4JRender::TextureSetTextureLevels(int l) {
|
||||
else
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
int C4JRender::TextureGetTextureLevels() { return 1; }
|
||||
void C4JRender::TextureData(int w, int h, void* d, int lvl, eTextureFormat) {
|
||||
int GLRenderer::TextureGetTextureLevels() { return 1; }
|
||||
void GLRenderer::TextureData(int w, int h, void* d, int lvl, eTextureFormat) {
|
||||
glTexImage2D(GL_TEXTURE_2D, lvl, GL_RGBA, w, h, 0, GL_RGBA,
|
||||
GL_UNSIGNED_BYTE, d);
|
||||
if (lvl == 0) {
|
||||
@@ -1331,12 +1335,12 @@ void C4JRender::TextureData(int w, int h, void* d, int lvl, eTextureFormat) {
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
}
|
||||
}
|
||||
void C4JRender::TextureDataUpdate(int xo, int yo, int w, int h, void* d,
|
||||
void GLRenderer::TextureDataUpdate(int xo, int yo, int w, int h, void* d,
|
||||
int lvl) {
|
||||
glTexSubImage2D(GL_TEXTURE_2D, lvl, xo, yo, w, h, GL_RGBA, GL_UNSIGNED_BYTE,
|
||||
d);
|
||||
}
|
||||
void C4JRender::TextureSetParam(int p, int v) {
|
||||
void GLRenderer::TextureSetParam(int p, int v) {
|
||||
glTexParameteri(GL_TEXTURE_2D, p, v);
|
||||
}
|
||||
|
||||
@@ -1355,7 +1359,7 @@ static int stbLoad(unsigned char* data, int w, int h, D3DXIMAGE_INFO* info,
|
||||
*out = px;
|
||||
return 0; // Success
|
||||
}
|
||||
int C4JRender::LoadTextureData(const char* fn, D3DXIMAGE_INFO* i, int** o) {
|
||||
int GLRenderer::LoadTextureData(const char* fn, D3DXIMAGE_INFO* i, int** o) {
|
||||
int w, h, c;
|
||||
unsigned char* d = stbi_load(fn, &w, &h, &c, 4);
|
||||
if (!d) return -1; // Failure
|
||||
@@ -1363,7 +1367,7 @@ int C4JRender::LoadTextureData(const char* fn, D3DXIMAGE_INFO* i, int** o) {
|
||||
stbi_image_free(d);
|
||||
return hr;
|
||||
}
|
||||
int C4JRender::LoadTextureData(uint8_t* pb, uint32_t nb, D3DXIMAGE_INFO* i,
|
||||
int GLRenderer::LoadTextureData(uint8_t* pb, uint32_t nb, D3DXIMAGE_INFO* i,
|
||||
int** o) {
|
||||
int w, h, c;
|
||||
unsigned char* d = stbi_load_from_memory(pb, (int)nb, &w, &h, &c, 4);
|
||||
@@ -1374,7 +1378,7 @@ int C4JRender::LoadTextureData(uint8_t* pb, uint32_t nb, D3DXIMAGE_INFO* i,
|
||||
}
|
||||
|
||||
// TODO: TO REMOVE SOON.
|
||||
void C4JRender::UpdateGamma(unsigned short usGamma) {
|
||||
void GLRenderer::UpdateGamma(unsigned short usGamma) {
|
||||
constexpr unsigned short GAMMA_MAX = 32768;
|
||||
s_rs.gamma = 0.5f + ((float)(usGamma) * (1.0f / GAMMA_MAX));
|
||||
}
|
||||
@@ -1449,25 +1453,184 @@ void glGetQueryObjectu_4J_Helper(unsigned int id, unsigned int pname,
|
||||
extern "C" {
|
||||
void glFogfv(GLenum pname, const GLfloat* params) {
|
||||
if (pname == 0x0B66)
|
||||
RenderManager.StateSetFogColour(params[0], params[1], params[2]);
|
||||
PlatformRenderer.StateSetFogColour(params[0], params[1], params[2]);
|
||||
}
|
||||
void glLightfv(GLenum light, GLenum pname, const GLfloat* params) {
|
||||
if (pname == 0x1203)
|
||||
RenderManager.StateSetLightDirection(light == 0x4000 ? 0 : 1, params[0],
|
||||
PlatformRenderer.StateSetLightDirection(light == 0x4000 ? 0 : 1, params[0],
|
||||
params[1], params[2]);
|
||||
else if (pname == 0x1200)
|
||||
RenderManager.StateSetLightAmbientColour(params[0], params[1],
|
||||
PlatformRenderer.StateSetLightAmbientColour(params[0], params[1],
|
||||
params[2]);
|
||||
else if (pname == 0x1201)
|
||||
RenderManager.StateSetLightColour(light == 0x4000 ? 0 : 1, params[0],
|
||||
PlatformRenderer.StateSetLightColour(light == 0x4000 ? 0 : 1, params[0],
|
||||
params[1], params[2]);
|
||||
}
|
||||
void glLightModelfv(GLenum pname, const GLfloat* params) {
|
||||
if (pname == 0x0B53)
|
||||
RenderManager.StateSetLightAmbientColour(params[0], params[1],
|
||||
PlatformRenderer.StateSetLightAmbientColour(params[0], params[1],
|
||||
params[2]);
|
||||
}
|
||||
void glShadeModel(GLenum) {}
|
||||
void glColorMaterial(GLenum, GLenum) {}
|
||||
void glNormal3f(GLfloat, GLfloat, GLfloat) {}
|
||||
}
|
||||
|
||||
// MARK: LinuxStubs
|
||||
|
||||
#ifdef GLES
|
||||
extern "C" {
|
||||
extern void glClearDepthf(float depth);
|
||||
void glClearDepth(double depth) { glClearDepthf((float)depth); }
|
||||
void glTexGeni(unsigned int, unsigned int, int) {}
|
||||
void glTexGenfv(unsigned int, unsigned int, const float*) {}
|
||||
void glTexCoordPointer(int, unsigned int, int, const void*) {}
|
||||
void glNormalPointer(unsigned int, int, const void*) {}
|
||||
void glColorPointer(int, unsigned int, int, const void*) {}
|
||||
void glVertexPointer(int, unsigned int, int, const void*) {}
|
||||
void glEndList(void) {}
|
||||
void glCallLists(int, unsigned int, const void*) {}
|
||||
}
|
||||
#endif
|
||||
|
||||
inline int* getIntPtr(IntBuffer* buf) {
|
||||
return buf ? (int*)buf->getBuffer() + buf->position() : nullptr;
|
||||
}
|
||||
inline void* getBytePtr(ByteBuffer* buf) {
|
||||
return buf ? (char*)buf->getBuffer() + buf->position() : nullptr;
|
||||
}
|
||||
|
||||
void glGenTextures_4J(IntBuffer* buf) {
|
||||
if (!buf) return;
|
||||
int n = buf->limit() - buf->position();
|
||||
int* dst = getIntPtr(buf);
|
||||
for (int i = 0; i < n; i++) dst[i] = PlatformRenderer.TextureCreate();
|
||||
}
|
||||
|
||||
void glDeleteTextures_4J(IntBuffer* buf) {
|
||||
if (!buf) return;
|
||||
int n = buf->limit() - buf->position();
|
||||
int* src = getIntPtr(buf);
|
||||
for (int i = 0; i < n; i++) PlatformRenderer.TextureFree(src[i]);
|
||||
}
|
||||
|
||||
void glTexImage2D_4J(int target, int level, int internalformat, int width,
|
||||
int height, int border, int format, int type,
|
||||
ByteBuffer* pixels) {
|
||||
(void)target;
|
||||
(void)internalformat;
|
||||
(void)border;
|
||||
(void)format;
|
||||
(void)type;
|
||||
PlatformRenderer.TextureData(width, height, getBytePtr(pixels), level,
|
||||
IPlatformRenderer::TEXTURE_FORMAT_RxGyBzAw);
|
||||
}
|
||||
|
||||
void glLight_4J(int light, int pname, FloatBuffer* params) {
|
||||
const float* p = params->_getDataPointer();
|
||||
int idx = (light == 0x4001) ? 1 : 0;
|
||||
if (pname == 0x1203)
|
||||
PlatformRenderer.StateSetLightDirection(idx, p[0], p[1], p[2]);
|
||||
else if (pname == 0x1201)
|
||||
PlatformRenderer.StateSetLightColour(idx, p[0], p[1], p[2]);
|
||||
else if (pname == 0x1200)
|
||||
PlatformRenderer.StateSetLightAmbientColour(p[0], p[1], p[2]);
|
||||
}
|
||||
|
||||
void glLightModel_4J(int pname, FloatBuffer* params) {
|
||||
if (pname == 0x0B53) {
|
||||
const float* p = params->_getDataPointer();
|
||||
PlatformRenderer.StateSetLightAmbientColour(p[0], p[1], p[2]);
|
||||
}
|
||||
}
|
||||
|
||||
void glFog_4J(int pname, FloatBuffer* params) {
|
||||
const float* p = params->_getDataPointer();
|
||||
if (pname == 0x0B66) PlatformRenderer.StateSetFogColour(p[0], p[1], p[2]);
|
||||
}
|
||||
|
||||
void glGetFloat_4J(int pname, FloatBuffer* params) {
|
||||
const float* m = PlatformRenderer.MatrixGet(pname);
|
||||
if (m) memcpy(params->_getDataPointer(), m, 16 * sizeof(float));
|
||||
}
|
||||
|
||||
void glCallLists_4J(IntBuffer* lists) {
|
||||
if (!lists) return;
|
||||
int count = lists->limit() - lists->position();
|
||||
int* ids = getIntPtr(lists);
|
||||
for (int i = 0; i < count; i++) PlatformRenderer.CBuffCall(ids[i], false);
|
||||
}
|
||||
|
||||
void glReadPixels_4J(int x, int y, int w, int h, int f, int t, ByteBuffer* p) {
|
||||
(void)f;
|
||||
(void)t;
|
||||
PlatformRenderer.ReadPixels(x, y, w, h, getBytePtr(p));
|
||||
}
|
||||
|
||||
// dead stubs
|
||||
void glTexCoordPointer_4J(int, int, FloatBuffer*) {}
|
||||
void glNormalPointer_4J(int, ByteBuffer*) {}
|
||||
void glColorPointer_4J(int, bool, int, ByteBuffer*) {}
|
||||
void glVertexPointer_4J(int, int, FloatBuffer*) {}
|
||||
void glEndList_4J(int) {}
|
||||
void glTexGen_4J(int, int, FloatBuffer*) {}
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static PFNGLGENQUERIESARBPROC _glGenQueriesARB = nullptr;
|
||||
static PFNGLBEGINQUERYARBPROC _glBeginQueryARB = nullptr;
|
||||
static PFNGLENDQUERYARBPROC _glEndQueryARB = nullptr;
|
||||
static PFNGLGETQUERYOBJECTUIVARBPROC _glGetQueryObjectuivARB = nullptr;
|
||||
static bool _queriesInitialized = false;
|
||||
|
||||
static void initQueryFuncs() {
|
||||
if (_queriesInitialized) return;
|
||||
_queriesInitialized = true;
|
||||
_glGenQueriesARB =
|
||||
(PFNGLGENQUERIESARBPROC)dlsym(RTLD_DEFAULT, "glGenQueriesARB");
|
||||
_glBeginQueryARB =
|
||||
(PFNGLBEGINQUERYARBPROC)dlsym(RTLD_DEFAULT, "glBeginQueryARB");
|
||||
_glEndQueryARB = (PFNGLENDQUERYARBPROC)dlsym(RTLD_DEFAULT, "glEndQueryARB");
|
||||
_glGetQueryObjectuivARB = (PFNGLGETQUERYOBJECTUIVARBPROC)dlsym(
|
||||
RTLD_DEFAULT, "glGetQueryObjectuivARB");
|
||||
}
|
||||
|
||||
void glGenQueriesARB_4J(IntBuffer* buf) {
|
||||
initQueryFuncs();
|
||||
if (_glGenQueriesARB && buf) {
|
||||
int n = buf->limit() - buf->position();
|
||||
if (n > 0) _glGenQueriesARB(n, (GLuint*)getIntPtr(buf));
|
||||
}
|
||||
}
|
||||
|
||||
void glBeginQueryARB_4J(int target, int id) {
|
||||
initQueryFuncs();
|
||||
if (_glBeginQueryARB) _glBeginQueryARB((GLenum)target, (GLuint)id);
|
||||
}
|
||||
|
||||
void glEndQueryARB_4J(int target) {
|
||||
initQueryFuncs();
|
||||
if (_glEndQueryARB) _glEndQueryARB((GLenum)target);
|
||||
}
|
||||
|
||||
void glGetQueryObjectuARB_4J(int id, int pname, IntBuffer* params) {
|
||||
initQueryFuncs();
|
||||
if (_glGetQueryObjectuivARB && params)
|
||||
// LWJGL does not change limits/positions during these calls, it
|
||||
// reads/writes exactly at pointer!!
|
||||
_glGetQueryObjectuivARB((GLuint)id, (GLenum)pname,
|
||||
(GLuint*)getIntPtr(params));
|
||||
}
|
||||
void glGetFloat(int pname, FloatBuffer* params) {
|
||||
glGetFloat_4J(pname, params);
|
||||
}
|
||||
void LinuxGLLogLightmapState(const char* stage, int textureId,
|
||||
bool scaleLight) {
|
||||
static int logCount = 0;
|
||||
if (logCount >= 16) return;
|
||||
++logCount;
|
||||
fprintf(stderr, "[linux-lightmap] %s tex=%d scale=%d\n", stage, textureId,
|
||||
scaleLight ? 1 : 0);
|
||||
}
|
||||
@@ -8,9 +8,11 @@
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "../IPlatformRenderer.h"
|
||||
#include "renderer/IPlatformRenderer.h"
|
||||
|
||||
class C4JRender : public IPlatformRenderer {
|
||||
extern IPlatformRenderer& PlatformRenderer;
|
||||
|
||||
class GLRenderer : public IPlatformRenderer {
|
||||
public:
|
||||
void Tick();
|
||||
void UpdateGamma(unsigned short usGamma);
|
||||
@@ -151,8 +153,6 @@ public:
|
||||
void Shutdown();
|
||||
};
|
||||
|
||||
extern C4JRender RenderManager;
|
||||
|
||||
// OpenGL Interception Macros
|
||||
#ifndef GL_MODELVIEW_MATRIX
|
||||
#define GL_MODELVIEW_MATRIX 0x0BA6
|
||||
@@ -388,17 +388,17 @@ extern C4JRender RenderManager;
|
||||
|
||||
// glCallList / display list macros
|
||||
#undef glNewList
|
||||
#define glNewList(_list, _mode) RenderManager.CBuffStart(_list)
|
||||
#define glNewList(_list, _mode) PlatformRenderer.CBuffStart(_list)
|
||||
#undef glEndList
|
||||
#define glEndList() RenderManager.CBuffEnd()
|
||||
#define glEndList() PlatformRenderer.CBuffEnd()
|
||||
#undef glCallList
|
||||
#define glCallList(_list) RenderManager.CBuffCall(_list)
|
||||
#define glCallList(_list) PlatformRenderer.CBuffCall(_list)
|
||||
|
||||
// glGenLists / glDeleteLists, lists are not supported in core!!!!!
|
||||
#undef glGenLists
|
||||
#define glGenLists(range) RenderManager.CBuffCreate(range)
|
||||
#define glGenLists(range) PlatformRenderer.CBuffCreate(range)
|
||||
#undef glDeleteLists
|
||||
#define glDeleteLists(list, range) RenderManager.CBuffDelete(list, range)
|
||||
#define glDeleteLists(list, range) PlatformRenderer.CBuffDelete(list, range)
|
||||
|
||||
#ifndef GL_SHADEMODEL_IS_FUNCTION
|
||||
#undef glShadeModel
|
||||
@@ -410,97 +410,97 @@ extern C4JRender RenderManager;
|
||||
#undef glTranslatef
|
||||
#define glTranslatef(x, y, z) \
|
||||
do { \
|
||||
RenderManager.MatrixTranslate(x, y, z); \
|
||||
PlatformRenderer.MatrixTranslate(x, y, z); \
|
||||
} while (0)
|
||||
|
||||
#undef glRotatef
|
||||
#define glRotatef(a, x, y, z) \
|
||||
do { \
|
||||
RenderManager.MatrixRotate((a) * (3.14159265358979f / 180.f), x, y, \
|
||||
PlatformRenderer.MatrixRotate((a) * (3.14159265358979f / 180.f), x, y, \
|
||||
z); \
|
||||
} while (0)
|
||||
|
||||
#undef glScalef
|
||||
#define glScalef(x, y, z) \
|
||||
do { \
|
||||
RenderManager.MatrixScale(x, y, z); \
|
||||
PlatformRenderer.MatrixScale(x, y, z); \
|
||||
} while (0)
|
||||
|
||||
#undef glScaled
|
||||
#define glScaled(x, y, z) \
|
||||
do { \
|
||||
RenderManager.MatrixScale((float)(x), (float)(y), (float)(z)); \
|
||||
PlatformRenderer.MatrixScale((float)(x), (float)(y), (float)(z)); \
|
||||
} while (0)
|
||||
|
||||
#undef glPushMatrix
|
||||
#define glPushMatrix() \
|
||||
do { \
|
||||
RenderManager.MatrixPush(); \
|
||||
PlatformRenderer.MatrixPush(); \
|
||||
} while (0)
|
||||
|
||||
#undef glPopMatrix
|
||||
#define glPopMatrix() \
|
||||
do { \
|
||||
RenderManager.MatrixPop(); \
|
||||
PlatformRenderer.MatrixPop(); \
|
||||
} while (0)
|
||||
|
||||
#undef glLoadIdentity
|
||||
#define glLoadIdentity() \
|
||||
do { \
|
||||
RenderManager.MatrixSetIdentity(); \
|
||||
PlatformRenderer.MatrixSetIdentity(); \
|
||||
} while (0)
|
||||
|
||||
#undef glMatrixMode
|
||||
#define glMatrixMode(mode) \
|
||||
do { \
|
||||
RenderManager.MatrixMode(mode); \
|
||||
PlatformRenderer.MatrixMode(mode); \
|
||||
} while (0)
|
||||
|
||||
#undef glMultMatrixf
|
||||
#define glMultMatrixf(m) \
|
||||
do { \
|
||||
RenderManager.MatrixMult(m); \
|
||||
PlatformRenderer.MatrixMult(m); \
|
||||
} while (0)
|
||||
|
||||
#undef glColor4f
|
||||
#define glColor4f(r, g, b, a) \
|
||||
do { \
|
||||
RenderManager.StateSetColour(r, g, b, a); \
|
||||
PlatformRenderer.StateSetColour(r, g, b, a); \
|
||||
} while (0)
|
||||
|
||||
#undef glColor3f
|
||||
#define glColor3f(r, g, b) \
|
||||
do { \
|
||||
RenderManager.StateSetColour(r, g, b, 1.0f); \
|
||||
PlatformRenderer.StateSetColour(r, g, b, 1.0f); \
|
||||
} while (0)
|
||||
|
||||
#undef glAlphaFunc
|
||||
#define glAlphaFunc(func, ref) \
|
||||
do { \
|
||||
RenderManager.StateSetAlphaFunc(func, ref); \
|
||||
PlatformRenderer.StateSetAlphaFunc(func, ref); \
|
||||
} while (0)
|
||||
|
||||
#undef glEnable
|
||||
#define glEnable(cap) \
|
||||
do { \
|
||||
if ((cap) == 0x0B60 /*GL_FOG*/) \
|
||||
RenderManager.StateSetFogEnable(true); \
|
||||
PlatformRenderer.StateSetFogEnable(true); \
|
||||
else if ((cap) == 0x0B50 /*GL_LIGHTING*/) \
|
||||
RenderManager.StateSetLightingEnable(true); \
|
||||
PlatformRenderer.StateSetLightingEnable(true); \
|
||||
else if ((cap) == 0x0BC0 /*GL_ALPHA_TEST*/) \
|
||||
RenderManager.StateSetAlphaTestEnable(true); \
|
||||
PlatformRenderer.StateSetAlphaTestEnable(true); \
|
||||
else if ((cap) == 0x0DE1 /*GL_TEXTURE_2D*/) \
|
||||
RenderManager.StateSetTextureEnable(true); \
|
||||
PlatformRenderer.StateSetTextureEnable(true); \
|
||||
else if ((cap) == 0x0BE2 /*GL_BLEND*/) \
|
||||
RenderManager.StateSetBlendEnable(true); \
|
||||
PlatformRenderer.StateSetBlendEnable(true); \
|
||||
else if ((cap) == 0x0B44 /*GL_CULL_FACE*/) \
|
||||
RenderManager.StateSetFaceCull(true); \
|
||||
PlatformRenderer.StateSetFaceCull(true); \
|
||||
else if ((cap) == 0x0B71 /*GL_DEPTH_TEST*/) \
|
||||
RenderManager.StateSetDepthTestEnable(true); \
|
||||
PlatformRenderer.StateSetDepthTestEnable(true); \
|
||||
else if ((cap) == 0x4000 /*GL_LIGHT0*/) \
|
||||
RenderManager.StateSetLightEnable(0, true); \
|
||||
PlatformRenderer.StateSetLightEnable(0, true); \
|
||||
else if ((cap) == 0x4001 /*GL_LIGHT1*/) \
|
||||
RenderManager.StateSetLightEnable(1, true); \
|
||||
PlatformRenderer.StateSetLightEnable(1, true); \
|
||||
else if ((cap) == 0x0B57 /*GL_COLOR_MATERIAL*/ \
|
||||
|| (cap) == 0x0BA1 /*GL_NORMALIZE*/ \
|
||||
|| (cap) == 0x803A /*GL_RESCALE_NORMAL*/ \
|
||||
@@ -516,23 +516,23 @@ extern C4JRender RenderManager;
|
||||
#define glDisable(cap) \
|
||||
do { \
|
||||
if ((cap) == 0x0B60 /*GL_FOG*/) \
|
||||
RenderManager.StateSetFogEnable(false); \
|
||||
PlatformRenderer.StateSetFogEnable(false); \
|
||||
else if ((cap) == 0x0B50 /*GL_LIGHTING*/) \
|
||||
RenderManager.StateSetLightingEnable(false); \
|
||||
PlatformRenderer.StateSetLightingEnable(false); \
|
||||
else if ((cap) == 0x0BC0 /*GL_ALPHA_TEST*/) \
|
||||
RenderManager.StateSetAlphaTestEnable(false); \
|
||||
PlatformRenderer.StateSetAlphaTestEnable(false); \
|
||||
else if ((cap) == 0x0DE1 /*GL_TEXTURE_2D*/) \
|
||||
RenderManager.StateSetTextureEnable(false); \
|
||||
PlatformRenderer.StateSetTextureEnable(false); \
|
||||
else if ((cap) == 0x0BE2 /*GL_BLEND*/) \
|
||||
RenderManager.StateSetBlendEnable(false); \
|
||||
PlatformRenderer.StateSetBlendEnable(false); \
|
||||
else if ((cap) == 0x0B44 /*GL_CULL_FACE*/) \
|
||||
RenderManager.StateSetFaceCull(false); \
|
||||
PlatformRenderer.StateSetFaceCull(false); \
|
||||
else if ((cap) == 0x0B71 /*GL_DEPTH_TEST*/) \
|
||||
RenderManager.StateSetDepthTestEnable(false); \
|
||||
PlatformRenderer.StateSetDepthTestEnable(false); \
|
||||
else if ((cap) == 0x4000 /*GL_LIGHT0*/) \
|
||||
RenderManager.StateSetLightEnable(0, false); \
|
||||
PlatformRenderer.StateSetLightEnable(0, false); \
|
||||
else if ((cap) == 0x4001 /*GL_LIGHT1*/) \
|
||||
RenderManager.StateSetLightEnable(1, false); \
|
||||
PlatformRenderer.StateSetLightEnable(1, false); \
|
||||
else if ((cap) == 0x0B57 /*GL_COLOR_MATERIAL*/ \
|
||||
|| (cap) == 0x0BA1 /*GL_NORMALIZE*/ \
|
||||
|| (cap) == 0x803A /*GL_RESCALE_NORMAL*/ \
|
||||
@@ -548,50 +548,44 @@ extern C4JRender RenderManager;
|
||||
#define glFogi(pname, param) \
|
||||
do { \
|
||||
if ((pname) == 0x0B65 /*GL_FOG_MODE*/) \
|
||||
RenderManager.StateSetFogMode(param); \
|
||||
PlatformRenderer.StateSetFogMode(param); \
|
||||
} while (0)
|
||||
|
||||
#undef glFogf
|
||||
#define glFogf(pname, param) \
|
||||
do { \
|
||||
if ((pname) == 0x0B63 /*GL_FOG_START*/) \
|
||||
RenderManager.StateSetFogNearDistance(param); \
|
||||
PlatformRenderer.StateSetFogNearDistance(param); \
|
||||
else if ((pname) == 0x0B64 /*GL_FOG_END*/) \
|
||||
RenderManager.StateSetFogFarDistance(param); \
|
||||
PlatformRenderer.StateSetFogFarDistance(param); \
|
||||
else if ((pname) == 0x0B62 /*GL_FOG_DENSITY*/) \
|
||||
RenderManager.StateSetFogDensity(param); \
|
||||
PlatformRenderer.StateSetFogDensity(param); \
|
||||
} while (0)
|
||||
|
||||
#undef glOrtho
|
||||
#define glOrtho(left, right, bottom, top, zNear, zFar) \
|
||||
do { \
|
||||
RenderManager.MatrixOrthogonal(left, right, bottom, top, zNear, zFar); \
|
||||
} while (0)
|
||||
|
||||
#undef gluPerspective
|
||||
#define gluPerspective(fovy, aspect, zNear, zFar) \
|
||||
do { \
|
||||
RenderManager.MatrixPerspective(fovy, aspect, zNear, zFar); \
|
||||
PlatformRenderer.MatrixOrthogonal(left, right, bottom, top, zNear, zFar); \
|
||||
} while (0)
|
||||
|
||||
#undef glMultiTexCoord2f
|
||||
#define glMultiTexCoord2f(tex, u, v) \
|
||||
do { \
|
||||
if ((tex) == 0x84C1 /*GL_TEXTURE1*/) \
|
||||
RenderManager.StateSetVertexTextureUV(u, v); \
|
||||
PlatformRenderer.StateSetVertexTextureUV(u, v); \
|
||||
} while (0)
|
||||
|
||||
#undef glActiveTexture
|
||||
#define glActiveTexture(tex) \
|
||||
do { \
|
||||
RenderManager.StateSetActiveTexture(tex); \
|
||||
PlatformRenderer.StateSetActiveTexture(tex); \
|
||||
::glActiveTexture(tex); \
|
||||
} while (0)
|
||||
|
||||
#undef glClientActiveTexture
|
||||
#define glClientActiveTexture(tex) \
|
||||
do { \
|
||||
RenderManager.StateSetActiveTexture(tex); \
|
||||
PlatformRenderer.StateSetActiveTexture(tex); \
|
||||
} while (0)
|
||||
|
||||
// declarations
|
||||
@@ -644,7 +638,7 @@ inline void glCallLists_4J(T* lists) {
|
||||
int base = lists->position();
|
||||
int count = lists->limit() - base;
|
||||
for (int i = 0; i < count; i++) {
|
||||
RenderManager.CBuffCall(lists->get(base + i));
|
||||
PlatformRenderer.CBuffCall(lists->get(base + i));
|
||||
}
|
||||
}
|
||||
template <typename T>
|
||||
@@ -665,25 +659,25 @@ template <typename T>
|
||||
inline void glFog_4J(int pname, T* params) {
|
||||
float* p = params->_getDataPointer();
|
||||
if (pname == 0x0B66 /* GL_FOG_COLOR */)
|
||||
RenderManager.StateSetFogColour(p[0], p[1], p[2]);
|
||||
PlatformRenderer.StateSetFogColour(p[0], p[1], p[2]);
|
||||
}
|
||||
template <typename T>
|
||||
inline void glLight_4J(int light, int pname, T* params) {
|
||||
float* p = params->_getDataPointer();
|
||||
if (pname == 0x1203 /* GL_POSITION */)
|
||||
RenderManager.StateSetLightDirection(light == 0x4000 ? 0 : 1, p[0],
|
||||
PlatformRenderer.StateSetLightDirection(light == 0x4000 ? 0 : 1, p[0],
|
||||
p[1], p[2]);
|
||||
else if (pname == 0x1200 /* GL_AMBIENT */)
|
||||
RenderManager.StateSetLightAmbientColour(p[0], p[1], p[2]);
|
||||
PlatformRenderer.StateSetLightAmbientColour(p[0], p[1], p[2]);
|
||||
else if (pname == 0x1201 /* GL_DIFFUSE */)
|
||||
RenderManager.StateSetLightColour(light == 0x4000 ? 0 : 1, p[0], p[1],
|
||||
PlatformRenderer.StateSetLightColour(light == 0x4000 ? 0 : 1, p[0], p[1],
|
||||
p[2]);
|
||||
}
|
||||
template <typename T>
|
||||
inline void glLightModel_4J(int pname, T* params) {
|
||||
float* p = params->_getDataPointer();
|
||||
if (pname == 0x0B53 /* GL_LIGHT_MODEL_AMBIENT */)
|
||||
RenderManager.StateSetLightAmbientColour(p[0], p[1], p[2]);
|
||||
PlatformRenderer.StateSetLightAmbientColour(p[0], p[1], p[2]);
|
||||
}
|
||||
template <typename T>
|
||||
inline void glTexGen_4J(int coord, int pname, T* params) {}
|
||||
@@ -709,6 +703,7 @@ void glEndQuery_4J_Helper(unsigned int target);
|
||||
void glGenQueries_4J_Helper(unsigned int* id);
|
||||
void glGetQueryObjectu_4J_Helper(unsigned int id, unsigned int pname,
|
||||
unsigned int* val);
|
||||
|
||||
// redirect the functions to my own implementation, no more 2.1 funcs
|
||||
#define glGenTextures(...) glGenTextures_4J(__VA_ARGS__)
|
||||
#define glDeleteTextures(...) glDeleteTextures_4J(__VA_ARGS__)
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "GLRenderer.h"
|
||||
|
||||
// Command Buffers
|
||||
void GLRenderer::CBuffLockStaticCreations() {}
|
||||
int GLRenderer::CBuffSize(int) { return 0; }
|
||||
void GLRenderer::CBuffTick() {}
|
||||
void GLRenderer::CBuffDeferredModeStart() {}
|
||||
void GLRenderer::CBuffDeferredModeEnd() {}
|
||||
|
||||
// Render States
|
||||
void GLRenderer::StateSetLightEnable(int, bool) {}
|
||||
void GLRenderer::StateSetEnableViewportClipPlanes(bool) {}
|
||||
void GLRenderer::StateSetForceLOD(int) {}
|
||||
void GLRenderer::StateSetTexGenCol(int, float, float, float, float, bool) {}
|
||||
|
||||
// Textures
|
||||
void GLRenderer::TextureDynamicUpdateStart() {}
|
||||
void GLRenderer::TextureDynamicUpdateEnd() {}
|
||||
void GLRenderer::TextureGetStats() {}
|
||||
void* GLRenderer::TextureGetTexture(int) { return nullptr; }
|
||||
|
||||
int GLRenderer::SaveTextureData(const char*, D3DXIMAGE_INFO*, int*) { return 0; }
|
||||
int GLRenderer::SaveTextureDataToMemory(void*, int, int*, int, int, int*) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Screen/Image Capturing
|
||||
void GLRenderer::DoScreenGrabOnNextPresent() {}
|
||||
void GLRenderer::CaptureThumbnail(ImageFileBuffer*) {}
|
||||
void GLRenderer::CaptureScreen(ImageFileBuffer*, XSOCIAL_PREVIEWIMAGE*) {}
|
||||
|
||||
// Conditional Rendering & Events
|
||||
void GLRenderer::BeginConditionalSurvey(int) {}
|
||||
void GLRenderer::EndConditionalSurvey() {}
|
||||
void GLRenderer::BeginConditionalRendering(int) {}
|
||||
void GLRenderer::EndConditionalRendering() {}
|
||||
void GLRenderer::BeginEvent(const wchar_t*) {}
|
||||
void GLRenderer::EndEvent() {}
|
||||
void GLRenderer::Tick() {}
|
||||
|
||||
// Lifecycle
|
||||
void GLRenderer::Suspend() {}
|
||||
bool GLRenderer::Suspended() { return false; }
|
||||
void GLRenderer::Resume() {}
|
||||
@@ -0,0 +1,4 @@
|
||||
#include "IPlatformRenderer.h"
|
||||
#include "./gl/GLRenderer.h"
|
||||
|
||||
extern IPlatformRenderer& PlatformRenderer;
|
||||
@@ -1,44 +0,0 @@
|
||||
#include "Render.h"
|
||||
|
||||
// Command Buffers
|
||||
void C4JRender::CBuffLockStaticCreations() {}
|
||||
int C4JRender::CBuffSize(int) { return 0; }
|
||||
void C4JRender::CBuffTick() {}
|
||||
void C4JRender::CBuffDeferredModeStart() {}
|
||||
void C4JRender::CBuffDeferredModeEnd() {}
|
||||
|
||||
// Render States
|
||||
void C4JRender::StateSetLightEnable(int, bool) {}
|
||||
void C4JRender::StateSetEnableViewportClipPlanes(bool) {}
|
||||
void C4JRender::StateSetForceLOD(int) {}
|
||||
void C4JRender::StateSetTexGenCol(int, float, float, float, float, bool) {}
|
||||
|
||||
// Textures
|
||||
void C4JRender::TextureDynamicUpdateStart() {}
|
||||
void C4JRender::TextureDynamicUpdateEnd() {}
|
||||
void C4JRender::TextureGetStats() {}
|
||||
void* C4JRender::TextureGetTexture(int) { return nullptr; }
|
||||
|
||||
int C4JRender::SaveTextureData(const char*, D3DXIMAGE_INFO*, int*) { return 0; }
|
||||
int C4JRender::SaveTextureDataToMemory(void*, int, int*, int, int, int*) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Screen/Image Capturing
|
||||
void C4JRender::DoScreenGrabOnNextPresent() {}
|
||||
void C4JRender::CaptureThumbnail(ImageFileBuffer*) {}
|
||||
void C4JRender::CaptureScreen(ImageFileBuffer*, XSOCIAL_PREVIEWIMAGE*) {}
|
||||
|
||||
// Conditional Rendering & Events
|
||||
void C4JRender::BeginConditionalSurvey(int) {}
|
||||
void C4JRender::EndConditionalSurvey() {}
|
||||
void C4JRender::BeginConditionalRendering(int) {}
|
||||
void C4JRender::EndConditionalRendering() {}
|
||||
void C4JRender::BeginEvent(const wchar_t*) {}
|
||||
void C4JRender::EndEvent() {}
|
||||
void C4JRender::Tick() {}
|
||||
|
||||
// Lifecycle
|
||||
void C4JRender::Suspend() {}
|
||||
bool C4JRender::Suspended() { return false; }
|
||||
void C4JRender::Resume() {}
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <vector>
|
||||
// #include <xtms.h>
|
||||
|
||||
#include "../PlatformTypes.h"
|
||||
#include "PlatformTypes.h"
|
||||
#include "../IPlatformStorage.h"
|
||||
|
||||
class C4JStringTable;
|
||||
|
||||
Reference in New Issue
Block a user