mirror of
https://github.com/isledecomp/isle-portable.git
synced 2026-02-03 12:31:15 +00:00
Merge branch 'master' into config-qt
This commit is contained in:
commit
f4c827c833
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -65,7 +65,7 @@ jobs:
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y \
|
||||
libx11-dev libxext-dev libxrandr-dev libxrender-dev libxfixes-dev libxi-dev libxinerama-dev \
|
||||
libxcursor-dev libwayland-dev libxkbcommon-dev wayland-protocols qt6-base-dev
|
||||
libxcursor-dev libwayland-dev libxkbcommon-dev wayland-protocols libgl1-mesa-dev libglew-dev qt6-base-dev
|
||||
|
||||
- name: Install macOS dependencies (brew)
|
||||
if: ${{ matrix.brew }}
|
||||
@ -124,7 +124,7 @@ jobs:
|
||||
run: |
|
||||
action_headers=$(find LEGO1/lego/legoomni/include/actions \
|
||||
-name '*.h' -print0 | xargs -0 echo)
|
||||
|
||||
|
||||
python3 tools/ncc/ncc.py \
|
||||
--clang-lib ${{ env.LLVM_PATH }}/lib/libclang.so \
|
||||
--recurse \
|
||||
|
||||
@ -22,6 +22,18 @@ add_library(miniwin STATIC EXCLUDE_FROM_ALL
|
||||
src/d3drm/backends/sdl3gpu/shaders/generated/ShaderIndex.cpp
|
||||
)
|
||||
|
||||
find_package(OpenGL)
|
||||
find_package(GLEW)
|
||||
if(OpenGL_FOUND AND GLEW_FOUND)
|
||||
target_sources(miniwin PRIVATE src/d3drm/backends/opengl15/renderer.cpp)
|
||||
target_compile_definitions(miniwin PRIVATE USE_OPENGL15)
|
||||
# Find and link OpenGL (1.5)
|
||||
target_link_libraries(miniwin PRIVATE OpenGL::GL)
|
||||
# Glew is used for getting a FBO for off screen rendering
|
||||
target_include_directories(miniwin PRIVATE ${GLEW_INCLUDE_DIRS})
|
||||
target_link_libraries(miniwin PRIVATE ${GLEW_LIBRARIES})
|
||||
endif()
|
||||
|
||||
# Force reported render mods from MiniWin
|
||||
target_compile_definitions(miniwin PRIVATE MINIWIN_PIXELFORMAT=SDL_PIXELFORMAT_RGB565)
|
||||
target_compile_definitions(miniwin PUBLIC MINIWIN)
|
||||
|
||||
257
miniwin/src/d3drm/backends/opengl15/renderer.cpp
Normal file
257
miniwin/src/d3drm/backends/opengl15/renderer.cpp
Normal file
@ -0,0 +1,257 @@
|
||||
#include "d3drmrenderer_opengl15.h"
|
||||
#include "ddraw_impl.h"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
Direct3DRMRenderer* OpenGL15Renderer::Create(DWORD width, DWORD height)
|
||||
{
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
|
||||
|
||||
SDL_Window* window = DDWindow;
|
||||
bool testWindow = false;
|
||||
if (!window) {
|
||||
window = SDL_CreateWindow("OpenGL 1.5 test", width, height, SDL_WINDOW_HIDDEN | SDL_WINDOW_OPENGL);
|
||||
testWindow = true;
|
||||
}
|
||||
|
||||
SDL_GLContext context = SDL_GL_CreateContext(window);
|
||||
if (!context) {
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SDL_GL_MakeCurrent(window, context);
|
||||
GLenum err = glewInit();
|
||||
if (err != GLEW_OK) {
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
|
||||
// Setup FBO
|
||||
GLuint fbo;
|
||||
glGenFramebuffers(1, &fbo);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||
|
||||
// Create color texture
|
||||
GLuint colorTex;
|
||||
glGenTextures(1, &colorTex);
|
||||
glBindTexture(GL_TEXTURE_2D, colorTex);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTex, 0);
|
||||
|
||||
// Create depth renderbuffer
|
||||
GLuint depthRb;
|
||||
glGenRenderbuffers(1, &depthRb);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, depthRb);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, width, height);
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthRb);
|
||||
|
||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
return nullptr;
|
||||
}
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
if (testWindow) {
|
||||
SDL_DestroyWindow(window);
|
||||
}
|
||||
|
||||
return new OpenGL15Renderer(width, height, context, fbo, colorTex, depthRb);
|
||||
}
|
||||
|
||||
OpenGL15Renderer::OpenGL15Renderer(
|
||||
int width,
|
||||
int height,
|
||||
SDL_GLContext context,
|
||||
GLuint fbo,
|
||||
GLuint colorTex,
|
||||
GLuint depthRb
|
||||
)
|
||||
: m_width(width), m_height(height), m_context(context), m_fbo(fbo), m_colorTex(colorTex), m_depthRb(depthRb)
|
||||
{
|
||||
m_renderedImage = SDL_CreateSurface(m_width, m_height, SDL_PIXELFORMAT_ABGR8888);
|
||||
}
|
||||
|
||||
OpenGL15Renderer::~OpenGL15Renderer()
|
||||
{
|
||||
if (m_renderedImage) {
|
||||
SDL_DestroySurface(m_renderedImage);
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGL15Renderer::SetBackbuffer(SDL_Surface* surface)
|
||||
{
|
||||
m_backbuffer = surface;
|
||||
}
|
||||
|
||||
void OpenGL15Renderer::PushVertices(const PositionColorVertex* verts, size_t count)
|
||||
{
|
||||
m_vertices.assign(verts, verts + count);
|
||||
}
|
||||
|
||||
void OpenGL15Renderer::PushLights(const SceneLight* lightsArray, size_t count)
|
||||
{
|
||||
m_lights.assign(lightsArray, lightsArray + count);
|
||||
}
|
||||
|
||||
void OpenGL15Renderer::SetProjection(D3DRMMATRIX4D perspective, D3DVALUE front, D3DVALUE back)
|
||||
{
|
||||
memcpy(&m_projection, perspective, sizeof(D3DRMMATRIX4D));
|
||||
m_projection[1][1] *= -1.0f; // OpenGL is upside down
|
||||
}
|
||||
|
||||
Uint32 OpenGL15Renderer::GetTextureId(IDirect3DRMTexture* texture)
|
||||
{
|
||||
return NO_TEXTURE_ID; // Stub
|
||||
}
|
||||
|
||||
DWORD OpenGL15Renderer::GetWidth()
|
||||
{
|
||||
return m_width;
|
||||
}
|
||||
|
||||
DWORD OpenGL15Renderer::GetHeight()
|
||||
{
|
||||
return m_height;
|
||||
}
|
||||
|
||||
void OpenGL15Renderer::GetDesc(D3DDEVICEDESC* halDesc, D3DDEVICEDESC* helDesc)
|
||||
{
|
||||
halDesc->dcmColorModel = D3DCOLORMODEL::RGB;
|
||||
halDesc->dwFlags = D3DDD_DEVICEZBUFFERBITDEPTH;
|
||||
halDesc->dwDeviceZBufferBitDepth = DDBD_24; // Todo add support for other depths
|
||||
helDesc->dwDeviceRenderBitDepth = DDBD_8 | DDBD_16 | DDBD_24 | DDBD_32;
|
||||
halDesc->dpcTriCaps.dwTextureCaps = D3DPTEXTURECAPS_PERSPECTIVE;
|
||||
halDesc->dpcTriCaps.dwShadeCaps = D3DPSHADECAPS_ALPHAFLATBLEND;
|
||||
halDesc->dpcTriCaps.dwTextureFilterCaps = D3DPTFILTERCAPS_LINEAR;
|
||||
|
||||
memset(helDesc, 0, sizeof(D3DDEVICEDESC));
|
||||
}
|
||||
|
||||
const char* OpenGL15Renderer::GetName()
|
||||
{
|
||||
return "OpenGL 1.5 Renderer";
|
||||
}
|
||||
|
||||
HRESULT OpenGL15Renderer::Render()
|
||||
{
|
||||
if (!m_backbuffer) {
|
||||
return DDERR_GENERIC;
|
||||
}
|
||||
SDL_GL_MakeCurrent(DDWindow, m_context);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
|
||||
glViewport(0, 0, m_width, m_height);
|
||||
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_COLOR_MATERIAL);
|
||||
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Disable all lights and reset global ambient
|
||||
for (int i = 0; i < 8; ++i) {
|
||||
glDisable(GL_LIGHT0 + i);
|
||||
}
|
||||
const GLfloat zeroAmbient[4] = {0.f, 0.f, 0.f, 1.f};
|
||||
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, zeroAmbient);
|
||||
|
||||
// Setup lights
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
|
||||
int lightIdx = 0;
|
||||
for (const auto& l : m_lights) {
|
||||
if (lightIdx > 7) {
|
||||
break;
|
||||
}
|
||||
GLenum lightId = GL_LIGHT0 + lightIdx++;
|
||||
const FColor& c = l.color;
|
||||
GLfloat col[4] = {c.r, c.g, c.b, c.a};
|
||||
GLfloat pos[4];
|
||||
|
||||
if (l.positional == 0.f && l.directional == 0.f) {
|
||||
// Ambient light only
|
||||
glLightfv(lightId, GL_AMBIENT, col);
|
||||
const GLfloat black[4] = {0.f, 0.f, 0.f, 1.f};
|
||||
glLightfv(lightId, GL_DIFFUSE, black);
|
||||
glLightfv(lightId, GL_SPECULAR, black);
|
||||
const GLfloat dummyPos[4] = {0.f, 0.f, 1.f, 0.f};
|
||||
glLightfv(lightId, GL_POSITION, dummyPos);
|
||||
}
|
||||
else {
|
||||
glLightfv(lightId, GL_AMBIENT, zeroAmbient);
|
||||
glLightfv(lightId, GL_DIFFUSE, col);
|
||||
glLightfv(lightId, GL_SPECULAR, col);
|
||||
|
||||
if (l.directional == 1.f) {
|
||||
pos[0] = -l.direction.x;
|
||||
pos[1] = -l.direction.y;
|
||||
pos[2] = -l.direction.z;
|
||||
pos[3] = 0.f;
|
||||
}
|
||||
else {
|
||||
pos[0] = l.position.x;
|
||||
pos[1] = l.position.y;
|
||||
pos[2] = l.position.z;
|
||||
pos[3] = 1.f;
|
||||
}
|
||||
glLightfv(lightId, GL_POSITION, pos);
|
||||
}
|
||||
glEnable(lightId);
|
||||
}
|
||||
glPopMatrix();
|
||||
|
||||
// Projection and view
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadMatrixf(&m_projection[0][0]);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
// Render geometry
|
||||
glBegin(GL_TRIANGLES);
|
||||
for (const auto& v : m_vertices) {
|
||||
glColor4ub(v.colors.r, v.colors.g, v.colors.b, v.colors.a);
|
||||
glNormal3f(v.normals.x, v.normals.y, v.normals.z);
|
||||
glTexCoord2f(v.texCoord.u, v.texCoord.v);
|
||||
|
||||
// Set per-vertex specular material
|
||||
glMaterialf(GL_FRONT, GL_SHININESS, v.shininess);
|
||||
if (v.shininess != 0.0f) {
|
||||
GLfloat whiteSpec[] = {v.shininess, v.shininess, v.shininess, v.shininess};
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, whiteSpec);
|
||||
}
|
||||
else {
|
||||
GLfloat noSpec[] = {0.f, 0.f, 0.f, 1.f};
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, noSpec);
|
||||
}
|
||||
|
||||
glVertex3f(v.position.x, v.position.y, v.position.z);
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glReadPixels(0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, m_renderedImage->pixels);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
// Composite onto SDL backbuffer
|
||||
SDL_BlitSurface(m_renderedImage, nullptr, m_backbuffer, nullptr);
|
||||
|
||||
return DD_OK;
|
||||
}
|
||||
@ -1,9 +1,11 @@
|
||||
#include "ShaderIndex.h"
|
||||
#include "d3drmrenderer.h"
|
||||
#include "d3drmrenderer_sdl3gpu.h"
|
||||
#include "ddraw_impl.h"
|
||||
#include "miniwin.h"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <cstddef>
|
||||
|
||||
static SDL_GPUGraphicsPipeline* InitializeGraphicsPipeline(SDL_GPUDevice* device)
|
||||
{
|
||||
@ -33,21 +35,36 @@ static SDL_GPUGraphicsPipeline* InitializeGraphicsPipeline(SDL_GPUDevice* device
|
||||
vertexBufferDescs[0].input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX;
|
||||
vertexBufferDescs[0].instance_step_rate = 0;
|
||||
|
||||
SDL_GPUVertexAttribute vertexAttrs[3] = {};
|
||||
SDL_GPUVertexAttribute vertexAttrs[6] = {};
|
||||
vertexAttrs[0].location = 0;
|
||||
vertexAttrs[0].buffer_slot = 0;
|
||||
vertexAttrs[0].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3;
|
||||
vertexAttrs[0].offset = 0;
|
||||
vertexAttrs[0].offset = offsetof(PositionColorVertex, position);
|
||||
|
||||
vertexAttrs[1].location = 1;
|
||||
vertexAttrs[1].buffer_slot = 0;
|
||||
vertexAttrs[1].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3;
|
||||
vertexAttrs[1].offset = sizeof(float) * 3;
|
||||
vertexAttrs[1].offset = offsetof(PositionColorVertex, normals);
|
||||
|
||||
vertexAttrs[2].location = 2;
|
||||
vertexAttrs[2].buffer_slot = 0;
|
||||
vertexAttrs[2].format = SDL_GPU_VERTEXELEMENTFORMAT_UBYTE4_NORM;
|
||||
vertexAttrs[2].offset = sizeof(float) * 6;
|
||||
vertexAttrs[2].offset = offsetof(PositionColorVertex, colors);
|
||||
|
||||
vertexAttrs[3].location = 3;
|
||||
vertexAttrs[3].buffer_slot = 0;
|
||||
vertexAttrs[3].format = SDL_GPU_VERTEXELEMENTFORMAT_UINT;
|
||||
vertexAttrs[3].offset = offsetof(PositionColorVertex, texId);
|
||||
|
||||
vertexAttrs[4].location = 4;
|
||||
vertexAttrs[4].buffer_slot = 0;
|
||||
vertexAttrs[4].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2;
|
||||
vertexAttrs[4].offset = offsetof(PositionColorVertex, texCoord);
|
||||
|
||||
vertexAttrs[5].location = 5;
|
||||
vertexAttrs[5].buffer_slot = 0;
|
||||
vertexAttrs[5].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT;
|
||||
vertexAttrs[5].offset = offsetof(PositionColorVertex, shininess);
|
||||
|
||||
SDL_GPUVertexInputState vertexInputState = {};
|
||||
vertexInputState.vertex_buffer_descriptions = vertexBufferDescs;
|
||||
@ -371,36 +388,7 @@ HRESULT Direct3DRMSDL3GPURenderer::Render()
|
||||
SDL_DestroySurface(m_renderedImage);
|
||||
SDL_UnmapGPUTransferBuffer(m_device, m_downloadTransferBuffer);
|
||||
m_renderedImage = convertedRender;
|
||||
return Blit();
|
||||
}
|
||||
SDL_BlitSurface(m_renderedImage, nullptr, m_backbuffer, nullptr);
|
||||
|
||||
HRESULT Direct3DRMSDL3GPURenderer::Blit()
|
||||
{
|
||||
// Blit the render back to our backbuffer
|
||||
SDL_Rect srcRect{0, 0, (int) m_width, (int) m_height};
|
||||
|
||||
const SDL_PixelFormatDetails* details = SDL_GetPixelFormatDetails(m_backbuffer->format);
|
||||
if (details->Amask != 0) {
|
||||
// Backbuffer supports transparnacy
|
||||
SDL_Surface* convertedRender = SDL_ConvertSurface(m_renderedImage, m_backbuffer->format);
|
||||
SDL_DestroySurface(m_renderedImage);
|
||||
m_renderedImage = convertedRender;
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
if (m_renderedImage->format == m_backbuffer->format) {
|
||||
// No conversion needed
|
||||
SDL_BlitSurface(m_renderedImage, &srcRect, m_backbuffer, &srcRect);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
// Convert backbuffer to a format that supports transparancy
|
||||
SDL_Surface* tempBackbuffer = SDL_ConvertSurface(m_backbuffer, m_renderedImage->format);
|
||||
SDL_BlitSurface(m_renderedImage, &srcRect, tempBackbuffer, &srcRect);
|
||||
// Then convert the result back to the backbuffer format and write it back
|
||||
SDL_Surface* newBackBuffer = SDL_ConvertSurface(tempBackbuffer, m_backbuffer->format);
|
||||
SDL_DestroySurface(tempBackbuffer);
|
||||
SDL_BlitSurface(newBackBuffer, &srcRect, m_backbuffer, &srcRect);
|
||||
SDL_DestroySurface(newBackBuffer);
|
||||
return DD_OK;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,21 +1,28 @@
|
||||
struct VS_Input
|
||||
{
|
||||
float3 Position : TEXCOORD0;
|
||||
float3 Normal : TEXCOORD1;
|
||||
float4 Color : TEXCOORD2;
|
||||
float3 Position : POSITION;
|
||||
float3 Normal : NORMAL0;
|
||||
float4 Color : COLOR0;
|
||||
uint TexId : TEXCOORD0;
|
||||
float2 TexCoord : TEXCOORD1;
|
||||
float Shininess : TEXCOORD2;
|
||||
};
|
||||
|
||||
struct FS_Input
|
||||
{
|
||||
float4 Color : TEXCOORD0;
|
||||
float3 Normal : TEXCOORD1;
|
||||
float4 Position : SV_Position;
|
||||
float4 Position : SV_POSITION;
|
||||
float3 Normal : NORMAL0;
|
||||
float4 Color : COLOR0;
|
||||
uint TexId : TEXCOORD0;
|
||||
float2 TexCoord : TEXCOORD1;
|
||||
float Shininess : TEXCOORD2;
|
||||
float3 WorldPosition : TEXCOORD3;
|
||||
};
|
||||
|
||||
struct FS_Output
|
||||
{
|
||||
float4 Color : SV_Target0;
|
||||
float Depth : SV_Depth;
|
||||
float Depth : SV_Depth;
|
||||
};
|
||||
|
||||
struct SceneLight {
|
||||
|
||||
@ -8,8 +8,13 @@ cbuffer ViewportUniforms : register(b0, space1)
|
||||
FS_Input main(VS_Input input)
|
||||
{
|
||||
FS_Input output;
|
||||
output.TexCoord = input.TexCoord;
|
||||
output.Color = input.Color;
|
||||
output.Normal = input.Normal;
|
||||
output.Position = mul(perspective, float4(input.Position, 1.0));
|
||||
output.WorldPosition = input.Position;
|
||||
output.TexId = input.TexId;
|
||||
output.Shininess = input.Shininess;
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@ -9,53 +9,50 @@ cbuffer LightBuffer : register(b0, space3)
|
||||
FS_Output main(FS_Input input)
|
||||
{
|
||||
FS_Output output;
|
||||
float3 normal = normalize(input.Normal);
|
||||
float3 fragPos = input.Position.xyz / input.Position.w;
|
||||
|
||||
float3 viewPos = float3(0, 0, 0);
|
||||
float3 viewDir = normalize(viewPos - fragPos);
|
||||
|
||||
float3 result = float3(0, 0, 0);
|
||||
|
||||
const float shininess = 20.0; // All materials use this in Isle
|
||||
float3 diffuse = float3(0, 0, 0);
|
||||
float3 specular = float3(0, 0, 0);
|
||||
|
||||
for (int i = 0; i < lightCount; ++i) {
|
||||
float3 lightColor = lights[i].color.rgb;
|
||||
|
||||
bool hasPos = lights[i].position.w == 1.0;
|
||||
bool hasDir = lights[i].direction.w == 1.0;
|
||||
|
||||
if (!hasPos && !hasDir) {
|
||||
// D3DRMLIGHT_AMBIENT
|
||||
result += input.Color.rgb * lightColor;
|
||||
if (lights[i].position.w == 0.0 && lights[i].direction.w == 0.0) {
|
||||
diffuse += lightColor;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (hasPos) {
|
||||
// D3DRMLIGHT_POINT
|
||||
float3 lightVec;
|
||||
if (lights[i].direction.w == 1.0) {
|
||||
lightVec = normalize(-lights[i].direction.xyz);
|
||||
}
|
||||
else {
|
||||
float3 lightPos = lights[i].position.xyz;
|
||||
float3 lightDir = normalize(lightPos - fragPos);
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
float distance = length(lightPos - fragPos);
|
||||
float attenuation = 1.0 / (1.0 + 0.09 * distance + 0.032 * distance * distance);
|
||||
float3 halfwayDir = normalize(lightDir + viewDir);
|
||||
float spec = pow(max(dot(normal, halfwayDir), 0.0), shininess);
|
||||
result += (input.Color.rgb * diff + spec) * lightColor * attenuation;
|
||||
continue;
|
||||
lightVec = lightPos - input.WorldPosition;
|
||||
|
||||
float len = length(lightVec);
|
||||
if (len == 0.0f) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lightVec /= len;
|
||||
}
|
||||
|
||||
if (hasDir) {
|
||||
// D3DRMLIGHT_DIRECTIONAL
|
||||
float3 lightDir = normalize(-lights[i].direction.xyz);
|
||||
float diff = max(dot(normal, lightDir), 0.0);
|
||||
float3 halfwayDir = normalize(lightDir + viewDir);
|
||||
float spec = pow(max(dot(normal, halfwayDir), 0.0), shininess);
|
||||
result += (input.Color.rgb * diff + spec) * lightColor;
|
||||
continue;
|
||||
float dotNL = dot(input.Normal, lightVec);
|
||||
if (dotNL > 0.0f) {
|
||||
diffuse += dotNL * lightColor;
|
||||
|
||||
if (input.Shininess != 0.0f) {
|
||||
// Using dotNL ignores view angle, but this matches DirectX 5 behavior.
|
||||
float spec1 = pow(dotNL, input.Shininess);
|
||||
specular += spec1 * lightColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output.Color = float4(result, input.Color.a);
|
||||
float3 baseColor = input.Color.rgb;
|
||||
float3 finalColor = saturate(diffuse * baseColor + specular);
|
||||
|
||||
output.Color = float4(finalColor, input.Color.a);
|
||||
output.Depth = input.Position.w;
|
||||
return output;
|
||||
}
|
||||
|
||||
@ -47,10 +47,10 @@ void Direct3DRMSoftwareRenderer::ClearZBuffer()
|
||||
|
||||
void Direct3DRMSoftwareRenderer::ProjectVertex(const PositionColorVertex& v, D3DRMVECTOR4D& p) const
|
||||
{
|
||||
float px = proj[0][0] * v.x + proj[1][0] * v.y + proj[2][0] * v.z + proj[3][0];
|
||||
float py = proj[0][1] * v.x + proj[1][1] * v.y + proj[2][1] * v.z + proj[3][1];
|
||||
float pz = proj[0][2] * v.x + proj[1][2] * v.y + proj[2][2] * v.z + proj[3][2];
|
||||
float pw = proj[0][3] * v.x + proj[1][3] * v.y + proj[2][3] * v.z + proj[3][3];
|
||||
float px = proj[0][0] * v.position.x + proj[1][0] * v.position.y + proj[2][0] * v.position.z + proj[3][0];
|
||||
float py = proj[0][1] * v.position.x + proj[1][1] * v.position.y + proj[2][1] * v.position.z + proj[3][1];
|
||||
float pz = proj[0][2] * v.position.x + proj[1][2] * v.position.y + proj[2][2] * v.position.z + proj[3][2];
|
||||
float pw = proj[0][3] * v.position.x + proj[1][3] * v.position.y + proj[2][3] * v.position.z + proj[3][3];
|
||||
|
||||
p.w = pw;
|
||||
|
||||
@ -69,23 +69,23 @@ void Direct3DRMSoftwareRenderer::ProjectVertex(const PositionColorVertex& v, D3D
|
||||
|
||||
PositionColorVertex SplitEdge(PositionColorVertex a, const PositionColorVertex& b, float plane)
|
||||
{
|
||||
float t = (plane - a.z) / (b.z - a.z);
|
||||
a.x = a.x + t * (b.x - a.x);
|
||||
a.y = a.y + t * (b.y - a.y);
|
||||
a.z = plane;
|
||||
float t = (plane - a.position.z) / (b.position.z - a.position.z);
|
||||
a.position.x = a.position.x + t * (b.position.x - a.position.x);
|
||||
a.position.y = a.position.y + t * (b.position.y - a.position.y);
|
||||
a.position.z = plane;
|
||||
|
||||
a.u = a.u + t * (b.u - a.u);
|
||||
a.v = a.v + t * (b.v - a.v);
|
||||
a.texCoord.u = a.texCoord.u + t * (b.texCoord.u - a.texCoord.u);
|
||||
a.texCoord.v = a.texCoord.v + t * (b.texCoord.v - a.texCoord.v);
|
||||
|
||||
a.nx = a.nx + t * (b.nx - a.nx);
|
||||
a.ny = a.ny + t * (b.ny - a.ny);
|
||||
a.nz = a.nz + t * (b.nz - a.nz);
|
||||
a.normals.x = a.normals.x + t * (b.normals.x - a.normals.x);
|
||||
a.normals.y = a.normals.y + t * (b.normals.y - a.normals.y);
|
||||
a.normals.z = a.normals.z + t * (b.normals.z - a.normals.z);
|
||||
|
||||
float len = std::sqrt(a.nx * a.nx + a.ny * a.ny + a.nz * a.nz);
|
||||
float len = std::sqrt(a.normals.x * a.normals.x + a.normals.y * a.normals.y + a.normals.z * a.normals.z);
|
||||
if (len > 0.0001f) {
|
||||
a.nx /= len;
|
||||
a.ny /= len;
|
||||
a.nz /= len;
|
||||
a.normals.x /= len;
|
||||
a.normals.y /= len;
|
||||
a.normals.z /= len;
|
||||
}
|
||||
|
||||
return a;
|
||||
@ -97,9 +97,9 @@ void Direct3DRMSoftwareRenderer::DrawTriangleClipped(
|
||||
const PositionColorVertex& v2
|
||||
)
|
||||
{
|
||||
bool in0 = v0.z >= m_front;
|
||||
bool in1 = v1.z >= m_front;
|
||||
bool in2 = v2.z >= m_front;
|
||||
bool in0 = v0.position.z >= m_front;
|
||||
bool in1 = v1.position.z >= m_front;
|
||||
bool in2 = v2.position.z >= m_front;
|
||||
|
||||
int insideCount = in0 + in1 + in2;
|
||||
|
||||
@ -164,52 +164,71 @@ void Direct3DRMSoftwareRenderer::BlendPixel(Uint8* pixelAddr, Uint8 r, Uint8 g,
|
||||
|
||||
SDL_Color Direct3DRMSoftwareRenderer::ApplyLighting(const PositionColorVertex& vertex)
|
||||
{
|
||||
float r = 0, g = 0, b = 0;
|
||||
for (const SceneLight& light : m_lights) {
|
||||
if (light.positional == 0.f && light.directional == 0.f) {
|
||||
FColor specular = {0, 0, 0, 0};
|
||||
FColor diffuse = {0, 0, 0, 0};
|
||||
|
||||
// Position and normal
|
||||
D3DVECTOR position = vertex.position;
|
||||
D3DVECTOR normal = vertex.normals;
|
||||
float normLen = std::sqrt(normal.x * normal.x + normal.y * normal.y + normal.z * normal.z);
|
||||
if (normLen == 0.0f) {
|
||||
return vertex.colors;
|
||||
}
|
||||
|
||||
normal.x /= normLen;
|
||||
normal.y /= normLen;
|
||||
normal.z /= normLen;
|
||||
|
||||
for (const auto& light : m_lights) {
|
||||
FColor lightColor = light.color;
|
||||
|
||||
if (light.positional == 0.0f && light.directional == 0.0f) {
|
||||
// Ambient light
|
||||
r += light.color.r;
|
||||
g += light.color.g;
|
||||
b += light.color.b;
|
||||
diffuse.r += lightColor.r;
|
||||
diffuse.g += lightColor.g;
|
||||
diffuse.b += lightColor.b;
|
||||
continue;
|
||||
}
|
||||
else if (light.directional == 1.f) {
|
||||
// Directional
|
||||
D3DVECTOR L = light.direction;
|
||||
float Llen = std::sqrt(L.x * L.x + L.y * L.y + L.z * L.z);
|
||||
if (Llen > 0.f) {
|
||||
L.x /= Llen;
|
||||
L.y /= Llen;
|
||||
L.z /= Llen;
|
||||
float ndotl = std::max(0.0f, -(vertex.nx * L.x + vertex.ny * L.y + vertex.nz * L.z));
|
||||
r += light.color.r * ndotl;
|
||||
g += light.color.g * ndotl;
|
||||
b += light.color.b * ndotl;
|
||||
}
|
||||
|
||||
// TODO lightVec only has to be calculated once per frame for directional lights
|
||||
D3DVECTOR lightVec;
|
||||
if (light.directional == 1.0f) {
|
||||
lightVec = {-light.direction.x, -light.direction.y, -light.direction.z};
|
||||
}
|
||||
else if (light.positional == 1.f) {
|
||||
// Point
|
||||
D3DVECTOR L = {light.position.x - vertex.x, light.position.y - vertex.y, light.position.z - vertex.z};
|
||||
float Llen = std::sqrt(L.x * L.x + L.y * L.y + L.z * L.z);
|
||||
if (Llen > 0.f) {
|
||||
L.x /= Llen;
|
||||
L.y /= Llen;
|
||||
L.z /= Llen;
|
||||
float ndotl = std::max(0.0f, vertex.nx * L.x + vertex.ny * L.y + vertex.nz * L.z);
|
||||
r += light.color.r * ndotl;
|
||||
g += light.color.g * ndotl;
|
||||
b += light.color.b * ndotl;
|
||||
else if (light.positional == 1.0f) {
|
||||
lightVec = {light.position.x - position.x, light.position.y - position.y, light.position.z - position.z};
|
||||
}
|
||||
|
||||
float len = std::sqrt(lightVec.x * lightVec.x + lightVec.y * lightVec.y + lightVec.z * lightVec.z);
|
||||
if (len == 0.0f) {
|
||||
continue;
|
||||
}
|
||||
lightVec.x /= len;
|
||||
lightVec.y /= len;
|
||||
lightVec.z /= len;
|
||||
|
||||
float dotNL = normal.x * lightVec.x + normal.y * lightVec.y + normal.z * lightVec.z;
|
||||
if (dotNL > 0.0f) {
|
||||
// Diffuse contribution
|
||||
diffuse.r += dotNL * lightColor.r;
|
||||
diffuse.g += dotNL * lightColor.g;
|
||||
diffuse.b += dotNL * lightColor.b;
|
||||
|
||||
if (vertex.shininess != 0.0f) {
|
||||
// Using dotNL ignores view angle, but this matches DirectX 5 behavior.
|
||||
float spec = std::pow(dotNL, vertex.shininess);
|
||||
specular.r += spec * lightColor.r;
|
||||
specular.g += spec * lightColor.g;
|
||||
specular.b += spec * lightColor.b;
|
||||
}
|
||||
}
|
||||
}
|
||||
r = std::min(1.0f, r);
|
||||
g = std::min(1.0f, g);
|
||||
b = std::min(1.0f, b);
|
||||
|
||||
return {
|
||||
static_cast<Uint8>(vertex.r * r),
|
||||
static_cast<Uint8>(vertex.g * g),
|
||||
static_cast<Uint8>(vertex.b * b),
|
||||
vertex.a
|
||||
return SDL_Color{
|
||||
static_cast<Uint8>(std::min(255.0f, diffuse.r * vertex.colors.r + specular.r * 255.0f)),
|
||||
static_cast<Uint8>(std::min(255.0f, diffuse.g * vertex.colors.g + specular.g * 255.0f)),
|
||||
static_cast<Uint8>(std::min(255.0f, diffuse.b * vertex.colors.b + specular.b * 255.0f)),
|
||||
vertex.colors.a
|
||||
};
|
||||
}
|
||||
|
||||
@ -305,7 +324,7 @@ void Direct3DRMSoftwareRenderer::DrawTriangleProjected(
|
||||
Uint8 b = static_cast<Uint8>(w0 * c0.b + w1 * c1.b + w2 * c2.b);
|
||||
Uint8* pixelAddr = pixels + y * pitch + x * m_bytesPerPixel;
|
||||
|
||||
if (v0.a == 255) {
|
||||
if (v0.colors.a == 255) {
|
||||
zref = z;
|
||||
|
||||
if (texels) {
|
||||
@ -315,8 +334,12 @@ void Direct3DRMSoftwareRenderer::DrawTriangleProjected(
|
||||
continue;
|
||||
}
|
||||
invW = 1.0 / invW;
|
||||
float u = static_cast<float>(((w0 * v0.u / p0.w) + (w1 * v1.u / p1.w) + (w2 * v2.u / p2.w)) * invW);
|
||||
float v = static_cast<float>(((w0 * v0.v / p0.w) + (w1 * v1.v / p1.w) + (w2 * v2.v / p2.w)) * invW);
|
||||
float u = static_cast<float>(
|
||||
((w0 * v0.texCoord.u / p0.w) + (w1 * v1.texCoord.u / p1.w) + (w2 * v2.texCoord.u / p2.w)) * invW
|
||||
);
|
||||
float v = static_cast<float>(
|
||||
((w0 * v0.texCoord.v / p0.w) + (w1 * v1.texCoord.v / p1.w) + (w2 * v2.texCoord.v / p2.w)) * invW
|
||||
);
|
||||
|
||||
// Tile textures
|
||||
u = u - std::floor(u);
|
||||
@ -344,7 +367,7 @@ void Direct3DRMSoftwareRenderer::DrawTriangleProjected(
|
||||
}
|
||||
else {
|
||||
// Transparent alpha blending with vertex alpha
|
||||
BlendPixel(pixelAddr, r, g, b, v0.a);
|
||||
BlendPixel(pixelAddr, r, g, b, v0.colors.a);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -403,6 +426,7 @@ Uint32 Direct3DRMSoftwareRenderer::GetTextureId(IDirect3DRMTexture* iTexture)
|
||||
if (texRef.texture == nullptr) {
|
||||
texRef.texture = texture;
|
||||
texRef.cached = convertedRender;
|
||||
texRef.version = texture->m_version;
|
||||
AddTextureDestroyCallback(i, texture);
|
||||
return i;
|
||||
}
|
||||
|
||||
@ -7,6 +7,9 @@
|
||||
#include "d3drmmesh_impl.h"
|
||||
#include "d3drmobject_impl.h"
|
||||
#include "d3drmrenderer.h"
|
||||
#ifdef USE_OPENGL15
|
||||
#include "d3drmrenderer_opengl15.h"
|
||||
#endif
|
||||
#include "d3drmrenderer_sdl3gpu.h"
|
||||
#include "d3drmrenderer_software.h"
|
||||
#include "d3drmtexture_impl.h"
|
||||
@ -141,6 +144,11 @@ HRESULT Direct3DRMImpl::CreateDeviceFromSurface(
|
||||
else if (SDL_memcmp(&guid, &SOFTWARE_GUID, sizeof(GUID)) == 0) {
|
||||
renderer = new Direct3DRMSoftwareRenderer(DDSDesc.dwWidth, DDSDesc.dwHeight);
|
||||
}
|
||||
#ifdef USE_OPENGL15
|
||||
else if (SDL_memcmp(&guid, &OPENGL15_GUID, sizeof(GUID)) == 0) {
|
||||
renderer = OpenGL15Renderer::Create(DDSDesc.dwWidth, DDSDesc.dwHeight);
|
||||
}
|
||||
#endif
|
||||
else {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Device GUID not recognized");
|
||||
return E_NOINTERFACE;
|
||||
|
||||
@ -8,7 +8,6 @@ Direct3DRMTextureImpl::Direct3DRMTextureImpl(D3DRMIMAGE* image)
|
||||
|
||||
Direct3DRMTextureImpl::Direct3DRMTextureImpl(IDirectDrawSurface* surface) : m_surface(surface)
|
||||
{
|
||||
MINIWIN_NOT_IMPLEMENTED();
|
||||
}
|
||||
|
||||
HRESULT Direct3DRMTextureImpl::QueryInterface(const GUID& riid, void** ppvObject)
|
||||
|
||||
@ -31,24 +31,32 @@ static void D3DRMMatrixMultiply(D3DRMMATRIX4D out, const D3DRMMATRIX4D a, const
|
||||
}
|
||||
}
|
||||
|
||||
static D3DVALUE Cofactor3x3(const D3DRMMATRIX4D m, int i, int j)
|
||||
{
|
||||
int i1 = (i + 1) % 3;
|
||||
int i2 = (i + 2) % 3;
|
||||
int j1 = (j + 1) % 3;
|
||||
int j2 = (j + 2) % 3;
|
||||
return m[i1][j1] * m[i2][j2] - m[i2][j1] * m[i1][j2];
|
||||
}
|
||||
|
||||
static void D3DRMMatrixInvertForNormal(Matrix3x3 out, const D3DRMMATRIX4D m)
|
||||
{
|
||||
assert(m[3][3] == 1.f);
|
||||
float detM = m[0][0] * Cofactor3x3(m, 0, 0) - m[0][1] * Cofactor3x3(m, 0, 1) + m[0][2] * Cofactor3x3(m, 0, 2);
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
for (int j = 0; j < 3; ++j) {
|
||||
out[i][j] = (((i + j) % 2) ? -1 : 1) * Cofactor3x3(m, i, j) / detM;
|
||||
}
|
||||
float a = m[0][0], b = m[0][1], c = m[0][2];
|
||||
float d = m[1][0], e = m[1][1], f = m[1][2];
|
||||
float g = m[2][0], h = m[2][1], i = m[2][2];
|
||||
|
||||
float det = a * (e * i - f * h) - b * (d * i - f * g) + c * (d * h - e * g);
|
||||
|
||||
if (fabs(det) < 1e-6f) {
|
||||
memset(out, 0, sizeof(Matrix3x3));
|
||||
return;
|
||||
}
|
||||
|
||||
float invDet = 1.0f / det;
|
||||
|
||||
out[0][0] = (e * i - f * h) * invDet;
|
||||
out[1][0] = (c * h - b * i) * invDet;
|
||||
out[2][0] = (b * f - c * e) * invDet;
|
||||
|
||||
out[0][1] = (f * g - d * i) * invDet;
|
||||
out[1][1] = (a * i - c * g) * invDet;
|
||||
out[2][1] = (c * d - a * f) * invDet;
|
||||
|
||||
out[0][2] = (d * h - e * g) * invDet;
|
||||
out[1][2] = (b * g - a * h) * invDet;
|
||||
out[2][2] = (a * e - b * d) * invDet;
|
||||
}
|
||||
|
||||
static void D3DRMMatrixInvertOrthogonal(D3DRMMATRIX4D out, const D3DRMMATRIX4D m)
|
||||
@ -221,11 +229,18 @@ HRESULT Direct3DRMViewportImpl::CollectSceneData()
|
||||
D3DRMRENDERQUALITY quality = mesh->GetGroupQuality(gi);
|
||||
IDirect3DRMTexture* texture = nullptr;
|
||||
mesh->GetGroupTexture(gi, &texture);
|
||||
IDirect3DRMMaterial* material = nullptr;
|
||||
mesh->GetGroupMaterial(gi, &material);
|
||||
Uint32 texId = NO_TEXTURE_ID;
|
||||
if (texture) {
|
||||
texId = m_renderer->GetTextureId(texture);
|
||||
texture->Release();
|
||||
}
|
||||
float shininess = 0.0f;
|
||||
if (material) {
|
||||
shininess = material->GetPower();
|
||||
material->Release();
|
||||
}
|
||||
|
||||
for (DWORD fi = 0; fi < faceCount; ++fi) {
|
||||
D3DVECTOR norm;
|
||||
@ -271,20 +286,27 @@ HRESULT Direct3DRMViewportImpl::CollectSceneData()
|
||||
viewNorm.z = norm.x * worldMatrixInvert[0][2] + norm.y * worldMatrixInvert[1][2] +
|
||||
norm.z * worldMatrixInvert[2][2];
|
||||
|
||||
float len =
|
||||
sqrtf(viewNorm.x * viewNorm.x + viewNorm.y * viewNorm.y + viewNorm.z * viewNorm.z);
|
||||
if (len > 0.0f) {
|
||||
float invLen = 1.0f / len;
|
||||
viewNorm.x *= invLen;
|
||||
viewNorm.y *= invLen;
|
||||
viewNorm.z *= invLen;
|
||||
}
|
||||
|
||||
PositionColorVertex vtx;
|
||||
vtx.x = viewPos.x;
|
||||
vtx.y = viewPos.y;
|
||||
vtx.z = viewPos.z;
|
||||
vtx.nx = viewNorm.x;
|
||||
vtx.ny = viewNorm.y;
|
||||
vtx.nz = viewNorm.z;
|
||||
vtx.r = (color >> 16) & 0xFF;
|
||||
vtx.g = (color >> 8) & 0xFF;
|
||||
vtx.b = (color >> 0) & 0xFF;
|
||||
vtx.a = (color >> 24) & 0xFF;
|
||||
vtx.position = viewPos;
|
||||
vtx.normals = viewNorm;
|
||||
vtx.colors = {
|
||||
static_cast<Uint8>((color >> 16) & 0xFF),
|
||||
static_cast<Uint8>((color >> 8) & 0xFF),
|
||||
static_cast<Uint8>((color >> 0) & 0xFF),
|
||||
static_cast<Uint8>((color >> 24) & 0xFF)
|
||||
};
|
||||
vtx.shininess = shininess;
|
||||
vtx.texId = texId;
|
||||
vtx.u = dv.tu;
|
||||
vtx.v = dv.tv;
|
||||
vtx.texCoord = {dv.tu, dv.tv};
|
||||
verts.push_back(vtx);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
#ifdef USE_OPENGL15
|
||||
#include "d3drmrenderer_opengl15.h"
|
||||
#endif
|
||||
#include "d3drmrenderer_sdl3gpu.h"
|
||||
#include "d3drmrenderer_software.h"
|
||||
#include "ddpalette_impl.h"
|
||||
@ -223,14 +226,11 @@ void EnumDevice(LPD3DENUMDEVICESCALLBACK cb, void* ctx, Direct3DRMRenderer* devi
|
||||
|
||||
HRESULT DirectDrawImpl::EnumDevices(LPD3DENUMDEVICESCALLBACK cb, void* ctx)
|
||||
{
|
||||
Direct3DRMRenderer* device = Direct3DRMSDL3GPURenderer::Create(640, 480);
|
||||
if (device) {
|
||||
EnumDevice(cb, ctx, device, SDL3_GPU_GUID);
|
||||
delete device;
|
||||
}
|
||||
device = new Direct3DRMSoftwareRenderer(640, 480);
|
||||
EnumDevice(cb, ctx, device, SOFTWARE_GUID);
|
||||
delete device;
|
||||
Direct3DRMSDL3GPU_EnumDevice(cb, ctx);
|
||||
#ifdef USE_OPENGL15
|
||||
OpenGL15Renderer_EnumDevice(cb, ctx);
|
||||
#endif
|
||||
Direct3DRMSoftware_EnumDevice(cb, ctx);
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
@ -321,6 +321,11 @@ HRESULT DirectDrawImpl::CreateDevice(
|
||||
if (SDL_memcmp(&guid, &SDL3_GPU_GUID, sizeof(GUID)) == 0) {
|
||||
renderer = Direct3DRMSDL3GPURenderer::Create(DDSDesc.dwWidth, DDSDesc.dwHeight);
|
||||
}
|
||||
#ifdef USE_OPENGL15
|
||||
else if (SDL_memcmp(&guid, &OPENGL15_GUID, sizeof(GUID)) == 0) {
|
||||
renderer = OpenGL15Renderer::Create(DDSDesc.dwWidth, DDSDesc.dwHeight);
|
||||
}
|
||||
#endif
|
||||
else if (SDL_memcmp(&guid, &SOFTWARE_GUID, sizeof(GUID)) == 0) {
|
||||
renderer = new Direct3DRMSoftwareRenderer(DDSDesc.dwWidth, DDSDesc.dwHeight);
|
||||
}
|
||||
|
||||
@ -6,13 +6,19 @@
|
||||
|
||||
#define NO_TEXTURE_ID 0xffffffff
|
||||
|
||||
typedef struct PositionColorVertex {
|
||||
float x, y, z;
|
||||
float nx, ny, nz;
|
||||
Uint8 r, g, b, a;
|
||||
Uint32 texId = NO_TEXTURE_ID;
|
||||
struct TexCoord {
|
||||
float u, v;
|
||||
} PositionColorVertex;
|
||||
};
|
||||
|
||||
struct PositionColorVertex {
|
||||
D3DVECTOR position;
|
||||
D3DVECTOR normals;
|
||||
SDL_Color colors;
|
||||
Uint32 texId;
|
||||
TexCoord texCoord;
|
||||
float shininess;
|
||||
};
|
||||
static_assert(sizeof(PositionColorVertex) == 44);
|
||||
|
||||
struct FColor {
|
||||
float r, g, b, a;
|
||||
@ -25,6 +31,7 @@ struct SceneLight {
|
||||
D3DVECTOR direction;
|
||||
float directional = 0.f; // direction is valid if 1.f
|
||||
};
|
||||
static_assert(sizeof(SceneLight) == 48);
|
||||
|
||||
class Direct3DRMRenderer : public IDirect3DDevice2 {
|
||||
public:
|
||||
|
||||
49
miniwin/src/internal/d3drmrenderer_opengl15.h
Normal file
49
miniwin/src/internal/d3drmrenderer_opengl15.h
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
|
||||
#include "d3drmrenderer.h"
|
||||
#include "d3drmtexture_impl.h"
|
||||
#include "ddraw_impl.h"
|
||||
|
||||
#include <GL/glew.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <vector>
|
||||
|
||||
DEFINE_GUID(OPENGL15_GUID, 0x682656F3, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03);
|
||||
|
||||
class OpenGL15Renderer : public Direct3DRMRenderer {
|
||||
public:
|
||||
static Direct3DRMRenderer* Create(DWORD width, DWORD height);
|
||||
OpenGL15Renderer(int width, int height, SDL_GLContext context, GLuint fbo, GLuint colorTex, GLuint depthRb);
|
||||
~OpenGL15Renderer() override;
|
||||
void SetBackbuffer(SDL_Surface* surface) override;
|
||||
void PushVertices(const PositionColorVertex* verts, size_t count) override;
|
||||
void PushLights(const SceneLight* lightsArray, size_t count) override;
|
||||
void SetProjection(D3DRMMATRIX4D perspective, D3DVALUE front, D3DVALUE back) override;
|
||||
Uint32 GetTextureId(IDirect3DRMTexture* texture) override;
|
||||
DWORD GetWidth() override;
|
||||
DWORD GetHeight() override;
|
||||
void GetDesc(D3DDEVICEDESC* halDesc, D3DDEVICEDESC* helDesc) override;
|
||||
const char* GetName() override;
|
||||
HRESULT Render() override;
|
||||
|
||||
private:
|
||||
SDL_GLContext m_context;
|
||||
D3DRMMATRIX4D m_projection;
|
||||
SDL_Surface* m_backbuffer = nullptr;
|
||||
SDL_Surface* m_renderedImage;
|
||||
int m_width, m_height;
|
||||
std::vector<PositionColorVertex> m_vertices;
|
||||
std::vector<SceneLight> m_lights;
|
||||
GLuint m_fbo = 0;
|
||||
GLuint m_colorTex = 0;
|
||||
GLuint m_depthRb = 0;
|
||||
};
|
||||
|
||||
inline static void OpenGL15Renderer_EnumDevice(LPD3DENUMDEVICESCALLBACK cb, void* ctx)
|
||||
{
|
||||
Direct3DRMRenderer* device = OpenGL15Renderer::Create(640, 480);
|
||||
if (device) {
|
||||
EnumDevice(cb, ctx, device, OPENGL15_GUID);
|
||||
delete device;
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "d3drmrenderer.h"
|
||||
#include "ddraw_impl.h"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
@ -60,3 +61,12 @@ class Direct3DRMSDL3GPURenderer : public Direct3DRMRenderer {
|
||||
SDL_GPUBuffer* m_vertexBuffer = nullptr;
|
||||
SDL_Surface* m_renderedImage = nullptr;
|
||||
};
|
||||
|
||||
inline static void Direct3DRMSDL3GPU_EnumDevice(LPD3DENUMDEVICESCALLBACK cb, void* ctx)
|
||||
{
|
||||
Direct3DRMRenderer* device = Direct3DRMSDL3GPURenderer::Create(640, 480);
|
||||
if (device) {
|
||||
EnumDevice(cb, ctx, device, SDL3_GPU_GUID);
|
||||
delete device;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include "d3drmrenderer.h"
|
||||
#include "d3drmtexture_impl.h"
|
||||
#include "ddraw_impl.h"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <cstddef>
|
||||
@ -56,3 +57,11 @@ class Direct3DRMSoftwareRenderer : public Direct3DRMRenderer {
|
||||
float proj[4][4] = {0};
|
||||
std::vector<float> m_zBuffer;
|
||||
};
|
||||
|
||||
inline static void Direct3DRMSoftware_EnumDevice(LPD3DENUMDEVICESCALLBACK cb, void* ctx)
|
||||
{
|
||||
Direct3DRMRenderer* device = nullptr;
|
||||
device = new Direct3DRMSoftwareRenderer(640, 480);
|
||||
EnumDevice(cb, ctx, device, SOFTWARE_GUID);
|
||||
delete device;
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "d3drmrenderer.h"
|
||||
#include "miniwin/d3d.h"
|
||||
#include "miniwin/ddraw.h"
|
||||
|
||||
@ -43,3 +44,5 @@ struct DirectDrawImpl : public IDirectDraw2, public IDirect3D2 {
|
||||
HRESULT DirectDrawEnumerate(LPDDENUMCALLBACKA cb, void* context);
|
||||
|
||||
HRESULT DirectDrawCreate(LPGUID lpGuid, LPDIRECTDRAW* lplpDD, IUnknown* pUnkOuter);
|
||||
|
||||
void EnumDevice(LPD3DENUMDEVICESCALLBACK cb, void* ctx, Direct3DRMRenderer* device, GUID deviceGuid);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user