RIM bug #42653

Closed
opened 2014-11-19 19:10:36 +01:00 by Alexey · 10 comments

System Information
Operating system and graphics card

Blender Version
Broken: (example: 2.69.7 4b206af, see splash screen)
Worked: (optional)

Short description of error
Rim1.png
Rim2.png
Exact steps for others to reproduce the error
Rim_bug.blend
look on 3d view solid and textured(multitexture) with edit mode - we will not see RIM and INNER FACE materials
select object or sculpting mode - we will see RIM and INNER FACE materials - all properly

**System Information** Operating system and graphics card **Blender Version** Broken: (example: 2.69.7 4b206af, see splash screen) Worked: (optional) **Short description of error** ![Rim1.png](https://archive.blender.org/developer/F124896/Rim1.png) ![Rim2.png](https://archive.blender.org/developer/F124898/Rim2.png) **Exact steps for others to reproduce the error** [Rim_bug.blend](https://archive.blender.org/developer/F124900/Rim_bug.blend) look on 3d view solid and textured(multitexture) with edit mode - we will not see RIM and INNER FACE materials select object or sculpting mode - we will see RIM and INNER FACE materials - all properly
Author

Changed status to: 'Open'

Changed status to: 'Open'
Author

Added subscriber: @Inwader77

Added subscriber: @Inwader77

Added subscriber: @ThomasDinges

Added subscriber: @ThomasDinges
Antonis Ryakiotakis was assigned by Bastien Montagne 2014-11-21 17:56:45 +01:00

Added subscriber: @mont29

Added subscriber: @mont29

Antony, I’m going to call for your OGL expertise here… Current code is obviously wrong (only setting mat_nr when there is no orig index???).

Spent some hours trying to make following patch work, with no success. Code would seems OK to me, debug printf's shows material is set when expected, and flushing happens too, yet colors do not change… Mayday! :)

P166: #42653

diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index bfc70c9..e1cff61 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -555,6 +555,8 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm,
 	const short (*lnors)- [x]- [x] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL);
 	int a, glmode = -1, shademodel = -1, matnr = -1, drawCurrentMat = 1;
 
+	printf("%s\n", __func__);
+
 	if (cddm->pbvh && cddm->pbvh_draw) {
 		if (dm->numTessFaceData) {
 			float (*face_nors)- [x] = CustomData_get_layer(&dm->faceData, CD_NORMAL);
@@ -689,6 +691,8 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm,
 		index_mp_to_orig = NULL;
 	}
 
+	printf("%s\n", __func__);
+
 	/* TODO: not entirely correct, but currently dynamic topology will
 	 *       destroy UVs anyway, so textured display wouldn't work anyway
 	 *
@@ -926,6 +930,7 @@ static void cdDM_drawFacesTex(DerivedMesh *dm,
                               DMCompareDrawOptions compareDrawOptions,
                               void *userData, DMDrawFlag uvflag)
 {
+	printf("%s\n", __func__);
 	cdDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData, uvflag);
 }
 
@@ -952,6 +957,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
 		index_mp_to_orig = NULL;
 	}
 
+	printf("%s\n", __func__);
 
 	colType = CD_ID_MCOL;
 	mcol = DM_get_tessface_data_layer(dm, colType);
@@ -969,17 +975,27 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
 	/* back-buffer always uses legacy since VBO's would need the
 	 * color array temporarily overwritten for drawing, then reset. */
 	if (GPU_buffer_legacy(dm) || G.f & G_BACKBUFSEL) {
+		int prev_mat_nr = -1;
 		DEBUG_VBO("Using legacy code. cdDM_drawMappedFaces\n");
+
 		for (i = 0; i < dm->numTessFaceData; i++, mf++) {
 			int drawSmooth = ((flag & DM_DRAW_ALWAYS_SMOOTH) || lnors) ? 1 : (mf->flag & ME_SMOOTH);
 			DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
 
 			orig = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, i) : i;
-			
-			if (orig == ORIGINDEX_NONE)
-				draw_option = setMaterial(mf->mat_nr + 1, NULL);
-			else if (setDrawOptions != NULL)
+
+			printf("%p, %p, %d (%d)\n", setMaterial, setDrawOptions, mf->mat_nr, prev_mat_nr);
+
+			if (mf->mat_nr != prev_mat_nr) {
+				if (setMaterial) {
+					printf("setting mat\n");
+					draw_option = setMaterial(mf->mat_nr + 1, NULL);
+				}
+				prev_mat_nr = mf->mat_nr;
+			}
+			if ((setDrawOptions != NULL) && (orig != ORIGINDEX_NONE)) {
 				draw_option = setDrawOptions(userData, orig);
+			}
 
 			if (draw_option != DM_DRAW_OPTION_SKIP) {
 				unsigned char *cp = NULL;
@@ -1089,24 +1105,33 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
 			else {
 				/* we need to check if the next material changes */
 				int next_actualFace = dm->drawObject->triangle_to_mface[0];
-				
+				int prev_mat_nr = -1;
+
 				for (i = 0; i < tottri; i++) {
 					//int actualFace = dm->drawObject->triangle_to_mface[i];
 					int actualFace = next_actualFace;
 					MFace *mface = mf + actualFace;
 					/*int drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : (mface->flag & ME_SMOOTH);*/ /* UNUSED */
 					DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
-					int flush = 0;
+					bool flush = false;
 
 					if (i != tottri - 1)
 						next_actualFace = dm->drawObject->triangle_to_mface[i + 1];
 
 					orig = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, actualFace) : actualFace;
 
-					if (orig == ORIGINDEX_NONE)
-						draw_option = setMaterial(mface->mat_nr + 1, NULL);
-					else if (setDrawOptions != NULL)
+					printf("%p, %p, %d (%d)\n", setMaterial, setDrawOptions, mface->mat_nr, prev_mat_nr);
+
+					if (mface->mat_nr != prev_mat_nr) {
+						if (setMaterial) {
+							printf("setting mat\n");
+							draw_option = setMaterial(mface->mat_nr + 1, NULL);
+						}
+						prev_mat_nr = mface->mat_nr;
+					}
+					if ((setDrawOptions != NULL) && (orig != ORIGINDEX_NONE)) {
 						draw_option = setDrawOptions(userData, orig);
+					}
 
 					if (draw_option == DM_DRAW_OPTION_STIPPLE) {
 						glEnable(GL_POLYGON_STIPPLE);
@@ -1120,7 +1145,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
 					/* flush buffer if current triangle isn't drawable or it's last triangle... */
 					flush = (ELEM(draw_option, DM_DRAW_OPTION_SKIP, DM_DRAW_OPTION_STIPPLE)) || (i == tottri - 1);
 
-					/* ... or when material setting is dissferent  */
+					/* ... or when material setting is different. */
 					flush |= mf[actualFace].mat_nr != mf[next_actualFace].mat_nr;
 
 					if (!flush && compareDrawOptions) {
@@ -1132,6 +1157,8 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm,
 						/* Add one to the length if we're drawing at the end of the array */
 						int count = (i - prevstart + (draw_option != DM_DRAW_OPTION_SKIP ? 1 : 0)) * 3;
 
+						printf("flushing!\n");
+
 						if (count)
 							glDrawArrays(GL_TRIANGLES, first, count);
 
@@ -1154,6 +1181,7 @@ static void cdDM_drawMappedFacesTex(DerivedMesh *dm,
                                     DMCompareDrawOptions compareDrawOptions,
                                     void *userData, DMDrawFlag flag)
 {
+	printf("%s\n", __func__);
 	cdDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData, flag);
 }
 
@@ -1250,6 +1278,8 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
 		index_mp_to_orig = NULL;
 	}
 
+	printf("%s\n", __func__);
+
 	/* TODO: same as for solid draw, not entirely correct, but works fine for now,
 	 *       will skip using textures (dyntopo currently destroys UV anyway) and
 	 *       works fine for matcap
@@ -1560,6 +1590,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm,
 
 static void cdDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial)
 {
+	printf("%s\n", __func__);
 	dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL);
 }
 
@@ -1584,6 +1615,8 @@ static void cdDM_drawMappedFacesMat(DerivedMesh *dm,
 		index_mp_to_orig = NULL;
 	}
 
+	printf("%s\n", __func__);
+
 	/* TODO: same as for solid draw, not entirely correct, but works fine for now,
 	 *       will skip using textures (dyntopo currently destroys UV anyway) and
 	 *       works fine for matcap
@@ -1782,6 +1815,8 @@ static void cdDM_foreachMappedFaceCenter(
 	MLoop *ml;
 	int i, orig, *index;
 
+	printf("%s\n", __func__);
+
 	index = CustomData_get_layer(&dm->polyData, CD_ORIGINDEX);
 	mp = cddm->mpoly;
 	for (i = 0; i < dm->numPolyData; i++, mp++) {

Antony, I’m going to call for your OGL expertise here… Current code is obviously wrong (only setting mat_nr when there is no orig index???). Spent some hours trying to make following patch work, with no success. Code would seems OK to me, debug printf's shows material is set when expected, and flushing happens too, yet colors do not change… Mayday! :) [P166: #42653](https://archive.blender.org/developer/P166.txt) ``` diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c index bfc70c9..e1cff61 100644 --- a/source/blender/blenkernel/intern/cdderivedmesh.c +++ b/source/blender/blenkernel/intern/cdderivedmesh.c @@ -555,6 +555,8 @@ static void cdDM_drawFacesSolid(DerivedMesh *dm, const short (*lnors)- [x]- [x] = dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL); int a, glmode = -1, shademodel = -1, matnr = -1, drawCurrentMat = 1; + printf("%s\n", __func__); + if (cddm->pbvh && cddm->pbvh_draw) { if (dm->numTessFaceData) { float (*face_nors)- [x] = CustomData_get_layer(&dm->faceData, CD_NORMAL); @@ -689,6 +691,8 @@ static void cdDM_drawFacesTex_common(DerivedMesh *dm, index_mp_to_orig = NULL; } + printf("%s\n", __func__); + /* TODO: not entirely correct, but currently dynamic topology will * destroy UVs anyway, so textured display wouldn't work anyway * @@ -926,6 +930,7 @@ static void cdDM_drawFacesTex(DerivedMesh *dm, DMCompareDrawOptions compareDrawOptions, void *userData, DMDrawFlag uvflag) { + printf("%s\n", __func__); cdDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData, uvflag); } @@ -952,6 +957,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, index_mp_to_orig = NULL; } + printf("%s\n", __func__); colType = CD_ID_MCOL; mcol = DM_get_tessface_data_layer(dm, colType); @@ -969,17 +975,27 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, /* back-buffer always uses legacy since VBO's would need the * color array temporarily overwritten for drawing, then reset. */ if (GPU_buffer_legacy(dm) || G.f & G_BACKBUFSEL) { + int prev_mat_nr = -1; DEBUG_VBO("Using legacy code. cdDM_drawMappedFaces\n"); + for (i = 0; i < dm->numTessFaceData; i++, mf++) { int drawSmooth = ((flag & DM_DRAW_ALWAYS_SMOOTH) || lnors) ? 1 : (mf->flag & ME_SMOOTH); DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL; orig = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, i) : i; - - if (orig == ORIGINDEX_NONE) - draw_option = setMaterial(mf->mat_nr + 1, NULL); - else if (setDrawOptions != NULL) + + printf("%p, %p, %d (%d)\n", setMaterial, setDrawOptions, mf->mat_nr, prev_mat_nr); + + if (mf->mat_nr != prev_mat_nr) { + if (setMaterial) { + printf("setting mat\n"); + draw_option = setMaterial(mf->mat_nr + 1, NULL); + } + prev_mat_nr = mf->mat_nr; + } + if ((setDrawOptions != NULL) && (orig != ORIGINDEX_NONE)) { draw_option = setDrawOptions(userData, orig); + } if (draw_option != DM_DRAW_OPTION_SKIP) { unsigned char *cp = NULL; @@ -1089,24 +1105,33 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, else { /* we need to check if the next material changes */ int next_actualFace = dm->drawObject->triangle_to_mface[0]; - + int prev_mat_nr = -1; + for (i = 0; i < tottri; i++) { //int actualFace = dm->drawObject->triangle_to_mface[i]; int actualFace = next_actualFace; MFace *mface = mf + actualFace; /*int drawSmooth = (flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : (mface->flag & ME_SMOOTH);*/ /* UNUSED */ DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL; - int flush = 0; + bool flush = false; if (i != tottri - 1) next_actualFace = dm->drawObject->triangle_to_mface[i + 1]; orig = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, actualFace) : actualFace; - if (orig == ORIGINDEX_NONE) - draw_option = setMaterial(mface->mat_nr + 1, NULL); - else if (setDrawOptions != NULL) + printf("%p, %p, %d (%d)\n", setMaterial, setDrawOptions, mface->mat_nr, prev_mat_nr); + + if (mface->mat_nr != prev_mat_nr) { + if (setMaterial) { + printf("setting mat\n"); + draw_option = setMaterial(mface->mat_nr + 1, NULL); + } + prev_mat_nr = mface->mat_nr; + } + if ((setDrawOptions != NULL) && (orig != ORIGINDEX_NONE)) { draw_option = setDrawOptions(userData, orig); + } if (draw_option == DM_DRAW_OPTION_STIPPLE) { glEnable(GL_POLYGON_STIPPLE); @@ -1120,7 +1145,7 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, /* flush buffer if current triangle isn't drawable or it's last triangle... */ flush = (ELEM(draw_option, DM_DRAW_OPTION_SKIP, DM_DRAW_OPTION_STIPPLE)) || (i == tottri - 1); - /* ... or when material setting is dissferent */ + /* ... or when material setting is different. */ flush |= mf[actualFace].mat_nr != mf[next_actualFace].mat_nr; if (!flush && compareDrawOptions) { @@ -1132,6 +1157,8 @@ static void cdDM_drawMappedFaces(DerivedMesh *dm, /* Add one to the length if we're drawing at the end of the array */ int count = (i - prevstart + (draw_option != DM_DRAW_OPTION_SKIP ? 1 : 0)) * 3; + printf("flushing!\n"); + if (count) glDrawArrays(GL_TRIANGLES, first, count); @@ -1154,6 +1181,7 @@ static void cdDM_drawMappedFacesTex(DerivedMesh *dm, DMCompareDrawOptions compareDrawOptions, void *userData, DMDrawFlag flag) { + printf("%s\n", __func__); cdDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData, flag); } @@ -1250,6 +1278,8 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, index_mp_to_orig = NULL; } + printf("%s\n", __func__); + /* TODO: same as for solid draw, not entirely correct, but works fine for now, * will skip using textures (dyntopo currently destroys UV anyway) and * works fine for matcap @@ -1560,6 +1590,7 @@ static void cdDM_drawMappedFacesGLSL(DerivedMesh *dm, static void cdDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial) { + printf("%s\n", __func__); dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL); } @@ -1584,6 +1615,8 @@ static void cdDM_drawMappedFacesMat(DerivedMesh *dm, index_mp_to_orig = NULL; } + printf("%s\n", __func__); + /* TODO: same as for solid draw, not entirely correct, but works fine for now, * will skip using textures (dyntopo currently destroys UV anyway) and * works fine for matcap @@ -1782,6 +1815,8 @@ static void cdDM_foreachMappedFaceCenter( MLoop *ml; int i, orig, *index; + printf("%s\n", __func__); + index = CustomData_get_layer(&dm->polyData, CD_ORIGINDEX); mp = cddm->mpoly; for (i = 0; i < dm->numPolyData; i++, mp++) { ```

PS: only tackled solid view, would expect similar changes are needed for texmapped as well.

PS: only tackled solid view, would expect similar changes are needed for texmapped as well.

@mont29, I think texmapped handles this already for most cases but I have to double-check.

@mont29, I think texmapped handles this already for most cases but I have to double-check.

This issue was referenced by 2e8ba179f7

This issue was referenced by 2e8ba179f71131779899df5a916252922f029e43

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'

Closed by commit 2e8ba179f7.

Closed by commit 2e8ba179f7.
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#42653
No description provided.